1f482e4b49
build / build (push) Successful in 1m18s
为什么:删除一篇与别人共同贡献同一 Wiki 页的文档后,页面还在、名字也在, 只有那篇文档的正文与引用被摘掉。原来的页面级差异会把这种语义重算显示成 "无变化",操作员据此会误判撤销没有生效。 怎么改:librarydiff 新增 CompareWiki,以 slug 为身份把正文/来源文档/引用分块/ 出入边/目录分别取集合比较,输出 sources_removed、citations 变化与具体类别; overview 的 diff.wiki 增加逐页明细(最多 50 页,超出置 pages_truncated), 说明文字明确"重算发生在源侧,本平台只如实比对与保留结果"。 页面:新增目标维护面板(实例级/库级、持有、入口开关、阶段、进度、恢复错误), 只有窗口仍持有且作业失败时才给"按预备份恢复";没有维护记录时写未接入 + fail closed。 变更页把 Wiki 逐页差异列出来源/引用怎么变。kind 补上 restore。 验过:go test ./internal/librarydiff ./internal/httpapi;web vitest 453 项; make verify 全绿(15 项,无未运行项)。真实撤销语义验收见交付报告。
140 lines
4.4 KiB
TypeScript
140 lines
4.4 KiB
TypeScript
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { MaintenanceCard, maintenanceSummary, wikiContributionLines } from './ReleaseTargets'
|
|
import type { LibraryDiff, LibraryJobRecord, LibraryMaintenanceView } from './librarySnapshots'
|
|
|
|
const job: LibraryJobRecord = {
|
|
id: 'libsync-internal-1',
|
|
scope: 'internal',
|
|
kind: 'sync',
|
|
state: 'failed',
|
|
stage: 'rollback',
|
|
request_digest: 'x',
|
|
queue_job_id: 'q1',
|
|
snapshot_id: '',
|
|
target_snapshot_id: '',
|
|
actor: 'admin',
|
|
error: '写入生产 chunks 失败:连接被拒绝',
|
|
recovery: '已按预备份回滚并校验',
|
|
created_at: '2026-10-29T04:00:00Z',
|
|
updated_at: '2026-10-29T04:02:00Z',
|
|
finished_at: '2026-10-29T04:02:00Z',
|
|
stages: [],
|
|
}
|
|
|
|
const heldInstance: LibraryMaintenanceView = {
|
|
held: true,
|
|
instance: 'kgmaint-weknora',
|
|
instance_maintenance: {
|
|
instance: 'kgmaint-weknora',
|
|
owner_scope: 'internal',
|
|
scope: 'internal',
|
|
owner_job_id: 'libsync-internal-1',
|
|
level: 'instance',
|
|
services: ['app'],
|
|
ingress_state: 'closed',
|
|
state: 'held',
|
|
acquired_at: '2026-10-29T04:00:00Z',
|
|
updated_at: '2026-10-29T04:02:00Z',
|
|
released_at: null,
|
|
},
|
|
}
|
|
|
|
describe('维护级别/进度/恢复错误', () => {
|
|
it('实例级持有:显示级别、入口状态、进度与恢复错误,并允许按预备份恢复', () => {
|
|
const summary = maintenanceSummary(heldInstance, job)
|
|
expect(summary.level).toBe('实例级')
|
|
expect(summary.held).toBe(true)
|
|
expect(summary.ingress).toContain('已关闭')
|
|
expect(summary.progress).toContain('回滚')
|
|
expect(summary.progress).toContain('失败')
|
|
expect(summary.recoveryError).toContain('写入生产 chunks 失败')
|
|
expect(summary.recoveryNote).toContain('按预备份回滚')
|
|
expect(summary.canRecover).toBe(true)
|
|
|
|
const html = renderToStaticMarkup(
|
|
<MaintenanceCard maintenance={heldInstance} job={job} canWrite onRecover={() => undefined} />
|
|
)
|
|
for (const text of ['目标维护', '实例级', '入口 已关闭', '按预备份恢复', '写入生产 chunks 失败']) {
|
|
expect(html).toContain(text)
|
|
}
|
|
})
|
|
|
|
it('没有窗口时如实说没有,不画成"已就绪"', () => {
|
|
const summary = maintenanceSummary(null, undefined)
|
|
expect(summary.level).toBe('未接入')
|
|
expect(summary.held).toBe(false)
|
|
expect(summary.canRecover).toBe(false)
|
|
const html = renderToStaticMarkup(
|
|
<MaintenanceCard maintenance={null} job={undefined} canWrite onRecover={() => undefined} />
|
|
)
|
|
expect(html).toContain('暂无维护窗口')
|
|
expect(html).not.toContain('按预备份恢复')
|
|
})
|
|
|
|
it('已释放的窗口不再提供恢复入口', () => {
|
|
const released: LibraryMaintenanceView = {
|
|
held: false,
|
|
instance_maintenance: {
|
|
...heldInstance.instance_maintenance!,
|
|
released_at: '2026-10-29T04:05:00Z',
|
|
state: 'recovered',
|
|
},
|
|
}
|
|
const summary = maintenanceSummary(released, job)
|
|
expect(summary.held).toBe(false)
|
|
expect(summary.canRecover).toBe(false)
|
|
expect(summary.releasedAt).not.toBe('')
|
|
})
|
|
})
|
|
|
|
describe('Wiki 贡献级差异展示', () => {
|
|
const diff: LibraryDiff = {
|
|
state: 'computed',
|
|
added: [],
|
|
updated: [],
|
|
removed: [],
|
|
wiki: {
|
|
state: 'computed',
|
|
added: 0,
|
|
updated: 1,
|
|
removed: 1,
|
|
sample: [],
|
|
note: '逐页比对',
|
|
sources_removed: 2,
|
|
pages: [
|
|
{
|
|
slug: 'entity/fa-bu-zha-men',
|
|
title: '发布闸门',
|
|
status: 'updated',
|
|
changed: ['正文', '来源文档', '引用分块'],
|
|
sources_removed: ['doc-a'],
|
|
citations_before: 2,
|
|
citations_after: 1,
|
|
},
|
|
{
|
|
slug: 'entity/tu-pu-hui-tian-fu-wu',
|
|
title: '图谱回填服务',
|
|
status: 'removed',
|
|
changed: ['整页撤销'],
|
|
citations_before: 1,
|
|
citations_after: 0,
|
|
},
|
|
],
|
|
},
|
|
}
|
|
|
|
it('共享页被更新时列出来源减少与引用变化,而不是只说"更新 1 页"', () => {
|
|
const lines = wikiContributionLines(diff)
|
|
expect(lines[0]).toContain('发布闸门')
|
|
expect(lines[0]).toContain('来源 -1')
|
|
expect(lines[0]).toContain('引用 2→1')
|
|
expect(lines[1]).toContain('整页撤销')
|
|
})
|
|
|
|
it('没有逐页明细时不编造明细', () => {
|
|
expect(wikiContributionLines({ state: 'unknown', added: [], updated: [], removed: [] })).toEqual([])
|
|
})
|
|
})
|