fix(web): 未读到目标观测不再误报非空并标注旧观测
build / build (push) Successful in 1m46s

根因:ReleaseTargetsView 在 overview 缺失时自己补 {state:'unknown'},而
productionTargetClass 把"unknown 且没有 empty_baseline"一律当成非空。后端对
"已探测且非空"发的正是这个形状(Go struct 上 omitempty),所以页面本地默认值
与真实观测在 JSON 上无法区分:首次加载、整库状态读取失败、当前范围没有数据
三条路径都会显示"目标非空,尚无权威版本",管理员还会拿到会返回 409 的
"建立目标权威基线"入口。

修法:没有 overview 时 production 保持 null,分类走新的 no-observation 分支;
四类有效响应(known / 已读且为空 / 非空无版本 / 不可读)的判定与入口不变。
刷新失败保留上一份 overview 时标注"上次观测 · 刷新失败,可能已过期",不把旧
结果当成刚验证的状态。后端 gate、权限、预备份与 API 拒绝一律未改。

测试:把旧"三次 SSR 当刷新"的用例撤掉,改为同一挂载 + 可控 fetch 的真实行为
测试(首次读取未返回 / 空→不可读→恢复 / 刷新失败保留旧观测 / 内外切换 /
overview 属于别的范围);缺观测的三条路径另以 SSR 负例复用审核者的反例。
新增 jsdom 仅作为 vitest 的 DOM 环境(商品代码零改动,npm ci 与锁文件已核)。

验证:make verify 16 项 success(tests-web 504 passed、tsc 无错、npm audit 0);
新用例先在原实现上红(断言收到"目标非空"),修后绿。未部署、未合并、未改
候选运行栈。
This commit is contained in:
姚章浩
2026-11-02 12:29:48 +08:00
parent 6827fa922f
commit 47be4ae502
6 changed files with 892 additions and 24 deletions
+35 -9
View File
@@ -801,15 +801,41 @@ describe('生产目标四类状态:known / 空 / 非空 / 不可读', () => {
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('无法读取目标整库状态')
// 真正的一次挂载刷新由 ReleaseTargets.mount.test.tsx 覆盖:三次 renderToStaticMarkup
// 只是三个互不相关的静态输入,不执行 load/effect/fetch,不能算刷新证据。
// F1:没有读到 overview 时,页面自己造的 {state:'unknown'} 与后端"已探测且非空"
// 在 JSON 上长得一模一样。缺观测的三条真实路径都不能落进 nonempty 分支,
// 也不能提供会返回 409 的建基线入口。
it('没有目标观测时不冒充非空:初始加载 / 整体读取失败 / 范围不匹配', () => {
const cases: Array<[string, Partial<ViewProps>, string]> = [
['初始加载中', { loading: true, overview: null }, '正在读取目标状态'],
['初始 overview 请求失败', { error: '发布状态读取失败(HTTP 503)', overview: null }, '不能据此判定空或非空'],
[
'选中对外但只有对内 overview',
{ scope: 'external', overview: { ...overview, scope: 'internal' } },
'还没有读到',
],
]
for (const [name, overrides, expected] of cases) {
const html = render({ baseline, ...overrides })
expect(html, name).toContain(expected)
expect(html, name).not.toContain('目标非空')
expect(html, name).not.toContain('目标已读且为空')
expect(html, name).not.toMatch(/建立目标权威基线(维护隔离)<\/button>/)
}
})
it('刷新失败但保留旧观测时标成上次观测,不冒充刚验证', () => {
const html = render({
baseline,
error: '发布状态读取失败(HTTP 502)',
overview: { ...overview, production: emptyTarget },
})
expect(html).toContain('目标已读且为空')
expect(html).toContain('上次观测 · 刷新失败,可能已过期')
expect(html).not.toContain('正在读取目标状态')
expect(html).not.toMatch(/建立目标权威基线(维护隔离)<\/button>/)
})
it('空目标但没有测试封存:启动同步保持禁用并说明缺候选', () => {