Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3566f208e0 | |||
| 2ea2111420 |
@@ -4,6 +4,8 @@
|
||||
|
||||
### Added
|
||||
|
||||
- 问答记录新增年份与自然周选择,周次展示起止日期,支持跨年及每年实际周数;按北京时间周一至周日填入查询范围,默认本周且仅查询截至当前的数据。保留自定义时间与原查询按钮,浏览器时区不改变查询边界。
|
||||
|
||||
- 问答运营按已确认口径显示知识覆盖率、回答正确率及原始分子/分母、排除数量与构成。使用完整筛选范围和当前有效人工优先结论,精确规则命中的未覆盖可进入覆盖分母;部分覆盖不算完全覆盖,待确认/未评估/失效/不计入按对应指标排除,零分母显示“暂无可计算数据”。返回独立规则版本,AI 模型与绩效范围仍未接入。
|
||||
|
||||
- 问答详情支持治理侧人工复核及不可变审计:覆盖、正确性、产品分类、问题类型、根因与理由由管理员明确填写,操作人取登录身份;保存后独立读回复核历史。保留源端判断和自动规则,输入变化使旧人工结论失效,已观测的内容回退不自动恢复旧结论;并发修改冲突、重复请求不重复留档。
|
||||
@@ -33,6 +35,8 @@
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复通过带端口的 HTTP 地址访问问答运营时,正常同源操作被误报“拒绝跨站配置请求”:网页代理保留原始 Host 及端口,使缺少 Fetch Metadata 的浏览器也能正确执行 Origin 校验。保留后端跨站、异端口、伪造转发头与缺失操作意图的拒绝保护。
|
||||
|
||||
- **登记钉钉知识库失败(HTTP 409 `space_registration_conflict`)的真实原因与修复**:`source_connections.name` 有唯一约束,而早期路径登记的钉钉来源(`base_url` 为空、id 与 dws 现在推导的确定性 id 不同)被**归档后仍占着名字槽位** ⇒ 重新登记时 INSERT 撞唯一约束;处理器又把**所有**存储层错误都翻译成同一个 409,真实原因被吞掉(线上只能看到一个无细节的错误码)。现在:① 同名来源**已归档**时,把它改名腾位(`…(已下架 · <短ID>)`,归档行不显示、数据与审计一行不动);② 同名来源**仍在使用**时返回 `space_name_conflict` + 可行动提示(先「去掉来源」);③ 同一登记键指向别的空间且该行仍在用时返回 `space_identity_conflict`(已归档的行则允许就地改写 —— 这就是"去掉后再用 dws 重新获取");④ 其余内部故障改回 **500** `space_registration_failed`,不再伪装成冲突;前端优先显示后端 `hint`,并为这两个新码补了中文说明。
|
||||
|
||||
- 前端入口与静态资源的缓存语义("新功能看起来没上线"与"页面偶尔裸奔/空白"的根因):
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ server {
|
||||
set $api_upstream http://api:8080;
|
||||
proxy_pass $api_upstream;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ server {
|
||||
location = /health {
|
||||
set $health_upstream http://api:8080;
|
||||
proxy_pass $health_upstream/health;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Host $http_host;
|
||||
}
|
||||
|
||||
# 带内容哈希的构建产物:可以长期缓存(换版本必然换文件名);旧哈希文件已被新构建替换
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// HTTP LAN/tailnet origins may omit Fetch Metadata. nginx must preserve the
|
||||
// external authority including its port so Origin can be checked without it.
|
||||
func TestQAProxyPreservesBrowserAuthority(t *testing.T) {
|
||||
config, err := os.ReadFile("../../deploy/nginx.conf")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hosts := regexp.MustCompile(`(?m)^\s*proxy_set_header\s+Host\s+([^;]+);`).FindAllStringSubmatch(string(config), -1)
|
||||
if len(hosts) < 2 {
|
||||
t.Fatal("API and health proxy Host directives must both be explicit")
|
||||
}
|
||||
for _, host := range hosts {
|
||||
if host[1] != "$http_host" {
|
||||
t.Fatalf("proxy drops browser authority/port: got %q, want $http_host", host[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQAIntentWithoutFetchMetadataChecksExactAuthority(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, host, origin, forwarded, site, intent string
|
||||
allowed bool
|
||||
}{
|
||||
{"LAN same authority", "192.168.50.134:8088", "http://192.168.50.134:8088", "", "", "qa-quality", true},
|
||||
{"tailnet same authority", "100.92.49.78:8088", "http://100.92.49.78:8088", "", "", "qa-quality", true},
|
||||
{"proxy stripped port", "192.168.50.134", "http://192.168.50.134:8088", "", "", "qa-quality", false},
|
||||
{"foreign origin", "192.168.50.134:8088", "http://foreign.invalid:8088", "", "", "qa-quality", false},
|
||||
{"different port", "192.168.50.134:8088", "http://192.168.50.134:8089", "", "", "qa-quality", false},
|
||||
{"forwarded header cannot grant", "192.168.50.134:8088", "http://foreign.invalid:8088", "foreign.invalid:8088", "", "qa-quality", false},
|
||||
{"opaque origin", "192.168.50.134:8088", "null", "", "", "qa-quality", false},
|
||||
{"explicit cross site", "192.168.50.134:8088", "http://192.168.50.134:8088", "", "cross-site", "qa-quality", false},
|
||||
{"missing intent", "192.168.50.134:8088", "http://192.168.50.134:8088", "", "", "", false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
req := httptest.NewRequest("POST", "http://"+tc.host+"/api/v1/qa-ops/quality/query", nil)
|
||||
req.Header.Set("Origin", tc.origin)
|
||||
req.Header.Set("X-Governance-Action", tc.intent)
|
||||
if tc.forwarded != "" {
|
||||
req.Header.Set("X-Forwarded-Host", tc.forwarded)
|
||||
}
|
||||
if tc.site != "" {
|
||||
req.Header.Set("Sec-Fetch-Site", tc.site)
|
||||
}
|
||||
rec := httptest.NewRecorder()
|
||||
if got := authorizeQAIntent(rec, req, "qa-quality"); got != tc.allowed {
|
||||
t.Fatalf("authorized=%v want %v, HTTP=%d", got, tc.allowed, rec.Code)
|
||||
}
|
||||
if !tc.allowed && rec.Code != 403 {
|
||||
t.Fatalf("rejected authority should be 403, got %d", rec.Code)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+29
-15
@@ -10,6 +10,8 @@ import { QAMonthly } from './QAMonthly'
|
||||
import { QAQualityEditor, QAQualityCounts } from './QAQuality'
|
||||
import { qualityLabels } from './qaQuality'
|
||||
import { usageLabels } from './qaUsage'
|
||||
import { QAWeekPicker } from './QAWeekPicker'
|
||||
import { currentQAWeek, qaDateTimeToISO, qaWeekQueryRange } from './qaWeeks'
|
||||
|
||||
interface ViewProps {
|
||||
onQualitySaved?: (record: QARecord) => void
|
||||
@@ -290,12 +292,10 @@ export function QAOperationsView(props: ViewProps) {
|
||||
)
|
||||
}
|
||||
|
||||
function localInput(value: Date): string {
|
||||
return new Date(value.getTime() - value.getTimezoneOffset() * 60_000).toISOString().slice(0, 16)
|
||||
}
|
||||
function initialDraft() {
|
||||
const end = new Date()
|
||||
return { start: localInput(new Date(end.getTime() - 7 * 24 * 3600_000)), end: localInput(end), keyword: '' }
|
||||
const current = currentQAWeek()
|
||||
const { year, week, start, end } = qaWeekQueryRange(current.year, current.week)
|
||||
return { year, week: week as number | null, start, end, keyword: '' }
|
||||
}
|
||||
|
||||
export function QAOperations() {
|
||||
@@ -322,8 +322,8 @@ export function QAOperations() {
|
||||
useEffect(() => {
|
||||
if (!canRead || query) return
|
||||
setQuery({
|
||||
start: new Date(draft.start).toISOString(),
|
||||
end: new Date(draft.end).toISOString(),
|
||||
start: qaDateTimeToISO(draft.start),
|
||||
end: qaDateTimeToISO(draft.end),
|
||||
keyword: draft.keyword,
|
||||
cursor: '',
|
||||
})
|
||||
@@ -377,10 +377,11 @@ export function QAOperations() {
|
||||
const submit = (event: FormEvent) => {
|
||||
event.preventDefault()
|
||||
try {
|
||||
const start = new Date(draft.start),
|
||||
end = new Date(draft.end)
|
||||
if (!(start < end)) throw new Error('开始时间必须早于结束时间')
|
||||
setQuery({ start: start.toISOString(), end: end.toISOString(), keyword: draft.keyword, cursor: '' })
|
||||
const start = qaDateTimeToISO(draft.start),
|
||||
end = qaDateTimeToISO(draft.end)
|
||||
if (!(Date.parse(start) < Date.parse(end))) throw new Error('开始时间必须早于结束时间')
|
||||
if (Date.parse(start) >= Date.now()) throw new Error('所选周或时间尚未开始,请选择已开始的时间范围')
|
||||
setQuery({ start, end, keyword: draft.keyword, cursor: '' })
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : '时间格式无效')
|
||||
}
|
||||
@@ -470,22 +471,35 @@ export function QAOperations() {
|
||||
) : (
|
||||
<>
|
||||
<form className="qa-ops-query" onSubmit={submit}>
|
||||
{view === 'records' ? (
|
||||
<QAWeekPicker
|
||||
year={draft.year}
|
||||
week={draft.week}
|
||||
onChange={(year, week) => {
|
||||
setDraft((old) => {
|
||||
if (week === null) return { ...old, year, week }
|
||||
const { start, end } = qaWeekQueryRange(year, week)
|
||||
return { ...old, year, week, start, end }
|
||||
})
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
<label>
|
||||
开始时间
|
||||
开始时间(北京时间)
|
||||
<input
|
||||
type="datetime-local"
|
||||
required
|
||||
value={draft.start}
|
||||
onChange={(event) => setDraft({ ...draft, start: event.target.value })}
|
||||
onChange={(event) => setDraft({ ...draft, start: event.target.value, week: null })}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
结束时间(不含)
|
||||
结束时间(北京时间,不含)
|
||||
<input
|
||||
type="datetime-local"
|
||||
required
|
||||
value={draft.end}
|
||||
onChange={(event) => setDraft({ ...draft, end: event.target.value })}
|
||||
onChange={(event) => setDraft({ ...draft, end: event.target.value, week: null })}
|
||||
/>
|
||||
</label>
|
||||
<label className="qa-ops-keyword">
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { QAWeekPicker } from './QAWeekPicker'
|
||||
|
||||
describe('QA week picker', () => {
|
||||
it('shows a year and numbered weeks with visible inclusive date ranges', () => {
|
||||
const html = renderToStaticMarkup(<QAWeekPicker year={2026} week={40} onChange={vi.fn()} />)
|
||||
expect(html).toContain('aria-label="年份"')
|
||||
expect(html).toContain('2026年')
|
||||
expect(html).toContain('aria-label="周次"')
|
||||
expect(html).toContain('value="40" selected=""')
|
||||
expect(html).toContain('第40周(09-28 到 10-04)')
|
||||
expect(html).toContain('第53周(2026-12-28 到 2027-01-03)')
|
||||
expect(html).toContain('北京时间')
|
||||
expect(html).toContain('周一至周日')
|
||||
})
|
||||
it('preserves custom range mode and does not offer invalid week 53', () => {
|
||||
const html = renderToStaticMarkup(<QAWeekPicker year={2027} week={null} onChange={vi.fn()} />)
|
||||
expect(html).toContain('value="" selected=""')
|
||||
expect(html).toContain('自定义时间')
|
||||
expect(html).not.toContain('第53周')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,52 @@
|
||||
import { currentQAWeek, qaWeek, qaWeeksInYear } from './qaWeeks'
|
||||
|
||||
interface Props {
|
||||
year: number
|
||||
week: number | null
|
||||
onChange: (year: number, week: number | null) => void
|
||||
}
|
||||
|
||||
export function QAWeekPicker({ year, week, onChange }: Props) {
|
||||
const currentYear = currentQAWeek().year
|
||||
const firstYear = Math.min(currentYear - 5, year)
|
||||
const lastYear = Math.max(currentYear + 1, year)
|
||||
return (
|
||||
<div className="qa-week-picker" role="group" aria-label="按周选择">
|
||||
<label>
|
||||
年份
|
||||
<select
|
||||
aria-label="年份"
|
||||
value={year}
|
||||
onChange={(event) => {
|
||||
const nextYear = Number(event.target.value)
|
||||
onChange(nextYear, Math.min(week ?? 1, qaWeeksInYear(nextYear)))
|
||||
}}
|
||||
>
|
||||
{Array.from({ length: lastYear - firstYear + 1 }, (_, i) => firstYear + i)
|
||||
.reverse()
|
||||
.map((value) => (
|
||||
<option key={value} value={value}>
|
||||
{value}年
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
周次
|
||||
<select
|
||||
aria-label="周次"
|
||||
value={week ?? ''}
|
||||
onChange={(event) => onChange(year, event.target.value === '' ? null : Number(event.target.value))}
|
||||
>
|
||||
<option value="">自定义时间</option>
|
||||
{Array.from({ length: qaWeeksInYear(year) }, (_, i) => i + 1).map((value) => (
|
||||
<option key={value} value={value}>
|
||||
{qaWeek(year, value).label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<span className="qa-ops-muted">北京时间 · 周一至周日 · 本周截至当前</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+21
-1
@@ -163,7 +163,8 @@
|
||||
color: var(--ink-mute);
|
||||
font-size: 12px;
|
||||
}
|
||||
.qa-ops-query input {
|
||||
.qa-ops-query input,
|
||||
.qa-week-picker select {
|
||||
min-height: 36px;
|
||||
min-width: 0;
|
||||
padding: 7px 10px;
|
||||
@@ -172,6 +173,24 @@
|
||||
border-radius: var(--r-sm);
|
||||
background: var(--bg-panel);
|
||||
}
|
||||
.qa-week-picker {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: end;
|
||||
flex-basis: 100%;
|
||||
min-width: 0;
|
||||
gap: 12px;
|
||||
}
|
||||
.qa-week-picker label {
|
||||
min-width: 0;
|
||||
}
|
||||
.qa-week-picker select {
|
||||
max-width: 100%;
|
||||
font: inherit;
|
||||
}
|
||||
.qa-week-picker > span {
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
.qa-ops-keyword {
|
||||
flex: 1;
|
||||
min-width: 170px;
|
||||
@@ -185,6 +204,7 @@
|
||||
}
|
||||
.qa-ops button:focus-visible,
|
||||
.qa-ops input:focus-visible,
|
||||
.qa-ops select:focus-visible,
|
||||
.qa-ops-table-scroll:focus-visible {
|
||||
outline: 2px solid var(--c-run);
|
||||
outline-offset: 2px;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { currentQAWeek, qaDateTimeToISO, qaWeek, qaWeeksInYear, qaWeekQueryRange } from './qaWeeks'
|
||||
|
||||
describe('QA natural-week query ranges', () => {
|
||||
it('caps the in-progress week at now but leaves completed weeks intact', () => {
|
||||
const now = new Date('2026-10-18T06:00:00Z')
|
||||
expect(qaWeekQueryRange(2026, 42, now).end).toBe('2026-10-18T14:00')
|
||||
expect(qaWeekQueryRange(2026, 40, now).end).toBe('2026-10-05T00:00')
|
||||
expect(qaWeekQueryRange(2026, 53, now).start).toBe('2026-12-28T00:00')
|
||||
})
|
||||
it('resolves the current ISO week at the Beijing midnight boundary', () => {
|
||||
expect(currentQAWeek(new Date('2026-10-18T15:59:00Z'))).toMatchObject({ year: 2026, week: 42 })
|
||||
expect(currentQAWeek(new Date('2026-10-18T16:01:00Z'))).toMatchObject({ year: 2026, week: 43 })
|
||||
expect(currentQAWeek(new Date('2027-01-01T12:00:00Z'))).toMatchObject({ year: 2026, week: 53 })
|
||||
})
|
||||
it('converts Beijing form input to UTC without relying on the browser timezone', () => {
|
||||
expect(qaDateTimeToISO('2026-09-28T00:00')).toBe('2026-09-27T16:00:00.000Z')
|
||||
expect(qaDateTimeToISO('2026-10-05T00:00')).toBe('2026-10-04T16:00:00.000Z')
|
||||
for (const input of ['', '2026-02-30T00:00', '2026-10-04', '2026-10-04T24:00', 'invalid']) {
|
||||
expect(() => qaDateTimeToISO(input)).toThrow()
|
||||
}
|
||||
})
|
||||
it('counts only the valid weeks for each year', () => {
|
||||
expect(qaWeeksInYear(2026)).toBe(53)
|
||||
expect(qaWeeksInYear(2027)).toBe(52)
|
||||
expect(qaWeeksInYear(2020)).toBe(53)
|
||||
expect(qaWeeksInYear(2021)).toBe(52)
|
||||
})
|
||||
|
||||
it('shows week dates inclusively and queries through the exclusive next Monday', () => {
|
||||
expect(qaWeek(2026, 40)).toEqual({
|
||||
year: 2026,
|
||||
week: 40,
|
||||
start: '2026-09-28T00:00',
|
||||
end: '2026-10-05T00:00',
|
||||
label: '第40周(09-28 到 10-04)',
|
||||
})
|
||||
})
|
||||
it('rejects nonexistent weeks instead of spilling into the next year', () => {
|
||||
expect(() => qaWeek(2027, 53)).toThrow()
|
||||
for (const week of [0, -1, 54, 1.5, Number.NaN]) expect(() => qaWeek(2026, week)).toThrow()
|
||||
for (const year of [0, 2026.5, Number.NaN]) expect(() => qaWeek(year, 1)).toThrow()
|
||||
})
|
||||
it('keeps the ISO week-year and shows years on crossing ranges', () => {
|
||||
expect(qaWeek(2026, 1)).toMatchObject({
|
||||
start: '2025-12-29T00:00',
|
||||
end: '2026-01-05T00:00',
|
||||
label: '第1周(2025-12-29 到 2026-01-04)',
|
||||
})
|
||||
expect(qaWeek(2026, 53)).toMatchObject({
|
||||
start: '2026-12-28T00:00',
|
||||
end: '2027-01-04T00:00',
|
||||
label: '第53周(2026-12-28 到 2027-01-03)',
|
||||
})
|
||||
expect(qaWeek(2024, 9)).toMatchObject({ start: '2024-02-26T00:00', end: '2024-03-04T00:00' })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,67 @@
|
||||
export interface QAWeek {
|
||||
year: number
|
||||
week: number
|
||||
start: string
|
||||
end: string
|
||||
label: string
|
||||
}
|
||||
|
||||
const day = 86_400_000
|
||||
const dateOnly = (value: number) => new Date(value).toISOString().slice(0, 10)
|
||||
|
||||
export function currentQAWeek(now = new Date()): QAWeek {
|
||||
const beijing = new Date(now.getTime() + 8 * 3_600_000)
|
||||
beijing.setUTCHours(0, 0, 0, 0)
|
||||
beijing.setUTCDate(beijing.getUTCDate() + 3 - ((beijing.getUTCDay() + 6) % 7))
|
||||
const year = beijing.getUTCFullYear()
|
||||
const week = Math.floor((beijing.getTime() - firstMonday(year)) / (7 * day)) + 1
|
||||
return qaWeek(year, week)
|
||||
}
|
||||
|
||||
export function qaDateTimeToISO(value: string): string {
|
||||
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/.test(value)) throw new Error('时间格式无效')
|
||||
const parsed = new Date(`${value}:00+08:00`)
|
||||
if (
|
||||
!Number.isFinite(parsed.getTime()) ||
|
||||
new Date(parsed.getTime() + 8 * 3_600_000).toISOString().slice(0, 16) !== value
|
||||
) {
|
||||
throw new Error('时间格式无效')
|
||||
}
|
||||
return parsed.toISOString()
|
||||
}
|
||||
|
||||
export function qaWeekQueryRange(year: number, week: number, now = new Date()): QAWeek {
|
||||
const range = qaWeek(year, week)
|
||||
if (
|
||||
Date.parse(qaDateTimeToISO(range.start)) < now.getTime() &&
|
||||
now.getTime() < Date.parse(qaDateTimeToISO(range.end))
|
||||
) {
|
||||
return { ...range, end: new Date(now.getTime() + 8 * 3_600_000).toISOString().slice(0, 16) }
|
||||
}
|
||||
return range
|
||||
}
|
||||
|
||||
const firstMonday = (year: number) => {
|
||||
const jan4 = new Date(Date.UTC(year, 0, 4))
|
||||
return jan4.getTime() - ((jan4.getUTCDay() + 6) % 7) * day
|
||||
}
|
||||
|
||||
export function qaWeeksInYear(year: number): number {
|
||||
if (!Number.isInteger(year) || year < 1900 || year > 9998) throw new Error('年份无效')
|
||||
return (firstMonday(year + 1) - firstMonday(year)) / (7 * day)
|
||||
}
|
||||
|
||||
export function qaWeek(year: number, week: number): QAWeek {
|
||||
if (!Number.isInteger(week) || week < 1 || week > qaWeeksInYear(year)) throw new Error('周次无效')
|
||||
const start = firstMonday(year) + (week - 1) * 7 * day
|
||||
const first = dateOnly(start)
|
||||
const last = dateOnly(start + 6 * day)
|
||||
const crossYear = first.slice(0, 4) !== String(year) || last.slice(0, 4) !== String(year)
|
||||
return {
|
||||
year,
|
||||
week,
|
||||
start: `${first}T00:00`,
|
||||
end: `${dateOnly(start + 7 * day)}T00:00`,
|
||||
label: `第${week}周(${crossYear ? first : first.slice(5)} 到 ${crossYear ? last : last.slice(5)})`,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user