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 (