From c256f2985cadf1ce7617bbc86312b9a8e21e79b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Mon, 2 Nov 2026 10:56:29 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix(web):=20=E7=A9=BA/=E9=9D=9E=E7=A9=BA/?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E8=AF=BB=E7=9B=AE=E6=A0=87=E5=88=86=E5=BC=80?= =?UTF-8?q?=E5=91=88=E7=8E=B0=E5=B9=B6=E6=94=B6=E7=AA=84=E5=BB=BA=E5=9F=BA?= =?UTF-8?q?=E7=BA=BF=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端 overview 早已区分 known / unknown+empty_baseline / unknown 非空 / unreachable, 页面只判断 state === 'known',把"已证空"和"读不到"都写成"未知",并在两种情况下 都给出"建立目标权威基线"入口——而该接口对空目标返回 409 library_baseline_target_empty、对读不到的目标返回 503 library_baseline_unprobeable。 按后端真实契约做最小分类: - LibraryKnown 补 empty_baseline 与 unreachable 两个已存在的字段/状态; - 页面按四类分别呈现:known 显示生效版本+快照摘要;空目标写明"已读且为空/首次发布/ 写前仍生成完整预备份";非空缺权威版本才指向基线入口;不可读照实说读取失败; - baselineNeeded 从"非 known"收窄为"非空且无权威版本",不动授权、写闸、预备份、 容量与 worker 执行准入等任何后端检查,也不放宽后端的 409。 行为测试新增四类状态、空→不可读→空刷新不残留旧状态、空目标无候选时按钮禁用; 原"非 known 一律未知"的断言随文案更正。本地门禁 16 项 success (tests-web 498 passed,tsc -b 无错)。 --- web/src/ReleaseTargets.test.tsx | 123 +++++++++++++++++++++++++++++++- web/src/ReleaseTargets.tsx | 51 ++++++++++--- web/src/librarySnapshots.ts | 12 +++- 3 files changed, 175 insertions(+), 11 deletions(-) diff --git a/web/src/ReleaseTargets.test.tsx b/web/src/ReleaseTargets.test.tsx index b6ae8fe..d840c8c 100644 --- a/web/src/ReleaseTargets.test.tsx +++ b/web/src/ReleaseTargets.test.tsx @@ -184,8 +184,9 @@ describe('ReleaseTargetsView(确认稿布局)', () => { it('未接入项显示“未接入/未知”,不用 0 / 无变化冒充', () => { const html = render() expect(html).toContain('生产当前') - // 生产没有权威版本时必须写未知,不能拿测试快照顶替 - expect(html).toContain('未知(尚未建立权威版本)') + // 生产没有权威版本时必须写"非空且尚无权威版本",不能拿测试快照顶替, + // 也不能把所有非 known 一律写成"未知"(空目标与读不到是另外两类)。 + expect(html).toContain('目标非空,尚无权威版本') expect(html).toContain('尚无记录 · 生产与测试的文档级差异读取未接线') expect(html).toContain('未接入') }) @@ -708,6 +709,124 @@ describe('ReleaseTargetsView(确认稿布局)', () => { }) }) +// 后端 /api/v1/library/overview 已经区分四类生产目标状态(library_flow.go unknownLibraryTarget、 +// library_baseline.go:81 的空目标 409)。页面此前只判断 state === 'known',于是"已证空"和 +// "读不到"都被写成"未知"、并给出必然 409 的"建立目标权威基线"入口。 +describe('生产目标四类状态:known / 空 / 非空 / 不可读', () => { + const baseline = { canStart: true, pending: false, onStart: vi.fn() } + const emptyTarget: LibraryOverview['production'] = { + state: 'unknown', + empty_baseline: true, + reason: '生产目标可读且为空:本次是首次发布,写入前仍会生成完整预备份', + } + const nonEmptyTarget: LibraryOverview['production'] = { + state: 'unknown', + reason: '目标非空且尚无权威版本', + } + const unreadableTarget: LibraryOverview['production'] = { + state: 'unreachable', + reason: '无法读取目标整库状态:请检查目标连接后重试,不能据此判定空库或建立基线', + } + const knownTarget: LibraryOverview['production'] = { + state: 'known', + version: { + id: 'v-known', + kind: 'production_effective', + snapshot_id: 'c'.repeat(64), + version_label: '生效 20261030-01', + source_job_id: 'libsync-known', + evidence: {}, + created_by: 'admin', + created_at: '2026-10-30T09:00:00Z', + }, + } + + it('空目标:写明"已读且为空/首次发布/写前仍预备份",且不给会 409 的建基线入口', () => { + const html = render({ + baseline, + overview: { + ...overview, + production: emptyTarget, + // 接口在空基线上不再给"建立基线"缺项(librarySyncGateWithGrant:657-661) + gate: { sync_allowed: false, reasons: ['没有与目标快照匹配的有效发布授权'] }, + }, + }) + expect(html).toContain('目标已读且为空') + expect(html).toContain('首次发布') + expect(html).toContain('写前仍会生成完整预备份') + // 页面不能把"已证空"写成未知,也不能引导去建一个必然被 409 拒绝的基线。 + expect(html).not.toContain('未知(尚未建立权威版本)') + expect(html).not.toMatch(/建立目标权威基线(维护隔离)<\/button>/) + }) + + it('非空且无生效版本:仍指向既有基线入口,不谎称空库', () => { + const html = render({ + baseline, + overview: { + ...overview, + production: nonEmptyTarget, + gate: { + sync_allowed: false, + reasons: [ + '目标非空且没有生效版本记录:先建立目标权威基线(维护隔离下捕获整库并逐类校验),或确认目标确实是空库', + ], + }, + }, + }) + expect(html).toContain('目标非空') + expect(html).toMatch(/建立目标权威基线(维护隔离)<\/button>/) + expect(html).not.toContain('目标已读且为空') + }) + + it('不可读:照实说读取失败,既不认定空也不认定非空,更不引导建基线', () => { + const html = render({ + baseline, + overview: { + ...overview, + production: unreadableTarget, + gate: { sync_allowed: false, reasons: [unreadableTarget.reason!] }, + }, + }) + expect(html).toContain('无法读取目标整库状态') + expect(html).not.toContain('目标已读且为空') + expect(html).not.toContain('目标非空') + expect(html).not.toMatch(/建立目标权威基线(维护隔离)<\/button>/) + }) + + it('known:显示权威生效版本与快照摘要,不再写未知', () => { + const html = render({ baseline, overview: { ...overview, production: knownTarget } }) + expect(html).toContain('生效 20261030-01') + expect(html).toContain(knownTarget.version!.snapshot_id.slice(0, 12)) + expect(html).not.toContain('未知(尚未建立权威版本)') + expect(html).not.toMatch(/建立目标权威基线(维护隔离)<\/button>/) + }) + + it('刷新后分类只由当前 overview 决定:空 → 不可读 → 空 不残留旧状态', () => { + const seenEmpty = render({ baseline, overview: { ...overview, production: emptyTarget } }) + const seenUnreadable = render({ baseline, overview: { ...overview, production: unreadableTarget } }) + const recovered = render({ baseline, overview: { ...overview, production: emptyTarget } }) + expect(seenEmpty).toContain('目标已读且为空') + expect(seenUnreadable).not.toContain('目标已读且为空') + expect(seenUnreadable).toContain('无法读取目标整库状态') + expect(recovered).toContain('目标已读且为空') + expect(recovered).not.toContain('无法读取目标整库状态') + }) + + it('空目标但没有测试封存:启动同步保持禁用并说明缺候选', () => { + const html = render({ + baseline, + overview: { + ...overview, + production: emptyTarget, + test_sealed: undefined, + test_sealed_reason: '还没有该目标的测试封存', + }, + }) + expect(html).toMatch(/]*class="rel-primary"[^>]*disabled/) + expect(html).toContain('尚无测试封存') + }) +}) + // E5:轮询必须覆盖"投递 → 终态读回"。 // 旧实现只按封存队列的作业判断,于是点了同步/恢复/建立基线之后页面根本不刷新, // 看上去像"还没启动";要么反过来,一个失败作业被永远轮询下去。 diff --git a/web/src/ReleaseTargets.tsx b/web/src/ReleaseTargets.tsx index 6b32525..f2e0aae 100644 --- a/web/src/ReleaseTargets.tsx +++ b/web/src/ReleaseTargets.tsx @@ -159,6 +159,18 @@ function scopeView( const scopeName = (scope: Scope) => (scope === 'internal' ? '对内知识库' : '对外知识库') +// 生产目标必须按接口的四类状态原样呈现:把"已读且为空"和"读不到"都写成"未知", +// 会让人去点一个必然被拒绝的"建立基线"(后端对空目标返回 409 library_baseline_target_empty, +// 对读不到的目标返回 503 library_baseline_unprobeable)。 +type ProductionTargetClass = 'known' | 'empty' | 'nonempty' | 'unreachable' + +function productionTargetClass(production: LibraryOverview['production']): ProductionTargetClass { + if (production.state === 'known' && production.version) return 'known' + if (production.state === 'unreachable') return 'unreachable' + // unknown 有两种:可读且空(空基线,首次发布合法起点)与可读但非空(缺权威版本)。 + return production.empty_baseline ? 'empty' : 'nonempty' +} + // 不可发起时必须说清是哪一条不满足:读的是接口给出的真实原因(执行器不可达、 // 指向别的实例、降级、观测过期),不是一句写死的"通道未接线"。 function captureHint(view: ScopeView, canWrite: boolean): string { @@ -702,8 +714,10 @@ function ProtectionCard({ onOpen: () => void }) { const backupKnown = prebackup.state === 'known' && prebackup.version - // 基线入口只在"目标非空、却没有生效版本"时才是答案;空库走首次同步(预备份+登记)。 - const baselineNeeded = production.state !== 'known' && targetSealed + // 基线入口只在"目标非空、却没有生效版本"时才是答案;空库走首次同步(预备份+登记), + // 读不到时必须先修连接,两者都不能被引导到会 409/503 的基线入口。 + const productionTarget = productionTargetClass(production) + const baselineNeeded = productionTarget === 'nonempty' && targetSealed return (