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 项,无未运行项)。真实撤销语义验收见交付报告。
296 lines
11 KiB
TypeScript
296 lines
11 KiB
TypeScript
import { renderToStaticMarkup } from 'react-dom/server'
|
||
import { describe, expect, it, vi } from 'vitest'
|
||
import { ReleaseTargetsView } from './ReleaseTargets'
|
||
import type {
|
||
LibraryCaptureJob,
|
||
LibraryJobRecord,
|
||
LibraryOverview,
|
||
LibrarySnapshot,
|
||
LibrarySnapshotList,
|
||
} from './librarySnapshots'
|
||
|
||
const internalSnapshot: LibrarySnapshot = {
|
||
snapshot_id: 'f992d64ea45bf737a0721a465b5aef2b150ef7757157eb84f3aaf8b6972d98f9',
|
||
scope: 'internal',
|
||
knowledge_base_id: '0c84a098-d3ed-4b82-a165-e6de9691d6a8',
|
||
tenant_id: 10000,
|
||
created_at: '2026-10-28T03:34:57.314178223Z',
|
||
validation_policy: 'artifact-acceptance-v1',
|
||
format: 'weknora-library-snapshot/v1',
|
||
compatibility: {
|
||
weknora_version: 'v0.7.1',
|
||
schema_version: 74,
|
||
retriever_engine: 'elasticsearch_v8',
|
||
embedding_model: 'text-embedding-v4',
|
||
embedding_dimension: 1024,
|
||
index_mapping_sha256: 'a'.repeat(64),
|
||
},
|
||
parts: [
|
||
{ kind: 'database', name: 'knowledges', sha256: 'b'.repeat(64), count: 4, bytes: 10654 },
|
||
{ kind: 'index', name: 'chunks', sha256: 'c'.repeat(64), count: 122, bytes: 1624880 },
|
||
],
|
||
logical_bytes: 55309044,
|
||
unique_bytes: 55309040,
|
||
shared_bytes: 2,
|
||
totals: { documents: 4, chunks: 38, index_documents: 122, resources: 21, wiki_pages: 31 },
|
||
}
|
||
|
||
const externalSnapshot: LibrarySnapshot = {
|
||
...internalSnapshot,
|
||
snapshot_id: '01343b0b310b3977c2fdda05f5b8a6272148c4f7bfa124a6c5944123cf0c51c3',
|
||
scope: 'external',
|
||
created_at: '2026-10-28T03:35:53.000000000Z',
|
||
totals: { documents: 0, chunks: 0, index_documents: 0, resources: 0, wiki_pages: 1 },
|
||
}
|
||
|
||
const runningJob: LibraryCaptureJob = {
|
||
job_id: 'library-capture-internal-1',
|
||
capture_job: 'lib-internal-20261028T033457',
|
||
scope: 'internal',
|
||
state: 'running',
|
||
attempt: 1,
|
||
last_error: '',
|
||
requested_by: 'yaozhanghao',
|
||
created_at: '2026-10-28T03:34:50Z',
|
||
updated_at: '2026-10-28T03:34:55Z',
|
||
}
|
||
|
||
const page: LibrarySnapshotList = {
|
||
available: true,
|
||
reason: '',
|
||
archive_root: '/var/lib/knowledge-governance/library',
|
||
snapshots: [internalSnapshot, externalSnapshot],
|
||
versions: 2,
|
||
content_bytes: 55309693,
|
||
blob_file_bytes: 55309693,
|
||
blob_allocated_bytes: 55373824,
|
||
unreferenced_blobs: 0,
|
||
unreferenced_bytes: 0,
|
||
manifest_file_bytes: 7544,
|
||
manifest_allocated_bytes: 12288,
|
||
capture_note: '',
|
||
capture_available: true,
|
||
capture_reason: '',
|
||
}
|
||
|
||
// 真实接口形状:生产段未知、闸口未开、没有持久作业。
|
||
const overview: LibraryOverview = {
|
||
scope: 'internal',
|
||
test_sealed: internalSnapshot,
|
||
production: { state: 'unknown', reason: '还没有生产验证通过的生效版本记录' },
|
||
prebackup: { state: 'unknown', reason: '本次目标快照还没有生产预备份' },
|
||
diff: {
|
||
state: 'unknown',
|
||
reason: '生产与测试的文档级差异读取未接线',
|
||
added: [],
|
||
updated: [],
|
||
removed: [],
|
||
},
|
||
jobs: [],
|
||
gate: {
|
||
sync_allowed: false,
|
||
reasons: [
|
||
'生产写入闸口关闭(PRODUCTION_RELEASE_REQUESTS_ENABLED=false)',
|
||
'没有已核验的生产恢复演练证据(PRODUCTION_BACKUP_RESTORE_VERIFIED=false)',
|
||
'生产当前权威版本未知,不能启动写入',
|
||
'本次目标快照还没有生产预备份',
|
||
],
|
||
},
|
||
authorization: { state: 'none', reason: '没有与目标快照匹配的有效发布授权' },
|
||
capture_available: true,
|
||
now: '2026-10-28T03:40:00Z',
|
||
}
|
||
|
||
const persistedSeal: LibraryJobRecord = {
|
||
id: 'libseal-lib-internal-20261028T033457',
|
||
scope: 'internal',
|
||
kind: 'seal',
|
||
state: 'running',
|
||
stage: 'export',
|
||
request_digest: 'd'.repeat(64),
|
||
queue_job_id: 'library-capture-internal-1',
|
||
snapshot_id: '',
|
||
target_snapshot_id: '',
|
||
actor: 'yaozhanghao',
|
||
error: '',
|
||
recovery: '',
|
||
created_at: '2026-10-28T03:34:50Z',
|
||
updated_at: '2026-10-28T03:34:55Z',
|
||
finished_at: null,
|
||
stages: [
|
||
{
|
||
stage: 'export',
|
||
state: 'running',
|
||
total: null,
|
||
completed: null,
|
||
bytes_total: null,
|
||
bytes_done: null,
|
||
detail: '主机侧正在暂停写入者、导出并恢复',
|
||
updated_at: '2026-10-28T03:34:55Z',
|
||
},
|
||
],
|
||
}
|
||
|
||
type ViewProps = Parameters<typeof ReleaseTargetsView>[0]
|
||
|
||
const base: ViewProps = {
|
||
page,
|
||
jobs: [],
|
||
overview,
|
||
loading: false,
|
||
error: null,
|
||
notice: null,
|
||
scope: 'internal',
|
||
onScope: vi.fn(),
|
||
drawerOpen: false,
|
||
onDrawer: vi.fn(),
|
||
expandedSnapshot: null,
|
||
onExpandSnapshot: vi.fn(),
|
||
pendingCapture: false,
|
||
canCapture: true,
|
||
canWrite: true,
|
||
maintenance: null,
|
||
now: new Date('2026-10-28T03:35:00Z').getTime(),
|
||
onRefresh: vi.fn(),
|
||
onCapture: vi.fn(),
|
||
onRecover: vi.fn(),
|
||
}
|
||
|
||
const render = (overrides: Partial<ViewProps> = {}) =>
|
||
renderToStaticMarkup(<ReleaseTargetsView {...base} {...overrides} />)
|
||
|
||
describe('ReleaseTargetsView(确认稿布局)', () => {
|
||
it('顶部只有两个知识库页签,且一次只显示选中库的作业区', () => {
|
||
const html = render()
|
||
expect(html).toContain('对内知识库')
|
||
expect(html).toContain('对外知识库')
|
||
expect(html).toContain('role="tab"')
|
||
// 只显示一个主作业卡:选中库标题出现一次,另一个库不渲染作业卡
|
||
expect(html.match(/· 已封存,生产同步未接入/g)?.length).toBe(1)
|
||
expect(html).not.toContain('对外知识库 · 尚无')
|
||
})
|
||
|
||
it('未接入项显示“未接入/未知”,不用 0 / 无变化冒充', () => {
|
||
const html = render()
|
||
expect(html).toContain('生产当前')
|
||
// 生产没有权威版本时必须写未知,不能拿测试快照顶替
|
||
expect(html).toContain('未知(尚未建立权威版本)')
|
||
expect(html).toContain('尚无记录 · 生产与测试的文档级差异读取未接线')
|
||
expect(html).toContain('未接入')
|
||
})
|
||
|
||
it('“启动同步”保持禁用并逐条说明缺项,不把封存当成同步', () => {
|
||
const html = render()
|
||
expect(html).toMatch(/<button[^>]*class="rel-primary"[^>]*disabled/)
|
||
expect(html).toContain('生产写入闸口关闭')
|
||
expect(html).toContain('没有已核验的生产恢复演练证据')
|
||
expect(html).toContain('本次目标快照还没有生产预备份')
|
||
// 授权也必须可见:没有授权时说明需要管理员签发
|
||
expect(html).toContain('无有效授权(需管理员按目标+快照签发)')
|
||
expect(html).toContain('封存测试版本')
|
||
})
|
||
|
||
it('没有当前作业时不把历史封存当成阶段完成', () => {
|
||
const html = render()
|
||
// 阶段条第一段必须是 idle(○),"✓" 只允许出现在准备清单,不出现在阶段条
|
||
const stageBar = html.slice(html.indexOf('aria-label="作业阶段"'), html.indexOf('rel-steps-note'))
|
||
expect(stageBar).not.toContain('✓')
|
||
expect(stageBar).toContain('本次作业尚未开始')
|
||
expect(html).toContain('已有测试封存')
|
||
expect(html).toContain('没有当前作业证据时不会把历史封存当作阶段完成')
|
||
})
|
||
|
||
it('差异已计算时按文档身份列增改撤销,并标注比对的两个版本', () => {
|
||
const html = render({
|
||
overview: {
|
||
...overview,
|
||
diff: {
|
||
state: 'computed',
|
||
added: [{ id: 'doc-new-0001', title: '新增的说明', digest: 'a'.repeat(64) }],
|
||
updated: [{ id: 'doc-upd-0002', title: '改过的说明', digest: 'b'.repeat(64) }],
|
||
removed: [{ id: 'doc-del-0003', title: '撤销的说明', digest: 'c'.repeat(64) }],
|
||
base_snapshot: 'prod00000000',
|
||
target_snapshot: 'test00000000',
|
||
wiki: {
|
||
state: 'computed',
|
||
added: 2,
|
||
updated: 1,
|
||
removed: 3,
|
||
sample: [],
|
||
note: '页面级差异',
|
||
},
|
||
},
|
||
},
|
||
})
|
||
expect(html).toContain('3 条')
|
||
expect(html).toContain('新增的说明 · doc-new-')
|
||
expect(html).toContain('改过的说明 · doc-upd-')
|
||
expect(html).toContain('撤销的说明 · doc-del-')
|
||
expect(html).toContain('生产 prod00000000 → 测试 test00000000')
|
||
expect(html).not.toContain('变更清单来自生产与测试版本对比')
|
||
expect(html).toContain('Wiki 页面:新增 2 · 更新 1 · 撤销 3')
|
||
expect(html).toContain('重算发生在源侧')
|
||
})
|
||
|
||
it('准备信息注明快照时间与范围,不声称实时测试库已就绪', () => {
|
||
const html = render()
|
||
expect(html).toContain('依据 10/28 11:34 封存的测试库全库快照,不代表实时测试库已就绪')
|
||
expect(html).toContain('同一份封存快照,不是实时 Wiki 队列状态')
|
||
expect(html).toContain('列表只校验清单自身,字节级复核在同步/恢复执行前进行')
|
||
})
|
||
|
||
it('版本与快照抽屉按 scope 列出全部历史并区分测试封存/不可直接恢复', () => {
|
||
const html = render({ drawerOpen: true, expandedSnapshot: internalSnapshot.snapshot_id })
|
||
expect(html).toContain('版本与快照')
|
||
expect(html).toContain('封存 f992d64ea45b')
|
||
expect(html).toContain('测试封存')
|
||
expect(html).toContain('不可直接恢复')
|
||
expect(html).toContain('恢复至该版本')
|
||
expect(html).toMatch(/恢复至该版本[^<]*<\/button>/)
|
||
expect(html).toContain('分项数量 / 字节 / 摘要(2 项)')
|
||
expect(html).toContain('不支持只选择 Wiki 或某张数据表恢复')
|
||
})
|
||
|
||
it('抽屉只展示当前选中库的历史', () => {
|
||
const html = render({ drawerOpen: true, scope: 'external' })
|
||
expect(html).toContain('封存 01343b0b310b')
|
||
expect(html).not.toContain('封存 f992d64ea45b')
|
||
})
|
||
|
||
it('同步中布局显示四类数据卡与明细,且不编造百分比', () => {
|
||
const html = render({
|
||
jobs: [runningJob],
|
||
overview: { ...overview, job: persistedSeal, jobs: [persistedSeal] },
|
||
})
|
||
expect(html).toContain('测试库封存作业')
|
||
expect(html).toContain('数据库 · 文档与分块')
|
||
expect(html).toContain('原文件 · 图片 · 附件')
|
||
expect(html).toContain('检索索引 · 向量')
|
||
expect(html).toContain('Wiki · 完整快照')
|
||
expect(html).toContain('同步明细')
|
||
// 唯一允许出现的百分比是免责声明里的「100% ≠ 作业完成」,没有任何进度主张
|
||
expect(html.match(/[1-9]\d*%/g) ?? []).toEqual(['100%'])
|
||
expect(html).toContain('文件传输 100% ≠ 作业完成')
|
||
expect(html).toContain('不编造百分比')
|
||
// 没有真实总量时只写"未知总量",不画百分比
|
||
expect(html).toContain('未知总量')
|
||
expect(html).toContain('主机侧正在暂停写入者、导出并恢复')
|
||
})
|
||
|
||
it('无权限时不给封存入口,未接线时说明通道状态', () => {
|
||
expect(render({ canCapture: false, canWrite: false })).toContain('封存需要知识工程师及以上权限')
|
||
const unwired = render({
|
||
canCapture: false,
|
||
canWrite: true,
|
||
page: { ...page, capture_available: false, capture_reason: '主机侧封存 agent 未接线' },
|
||
})
|
||
expect(unwired).toContain('封存通道未接线')
|
||
})
|
||
|
||
it('无封存时给出“尚无封存”而不是空表', () => {
|
||
const html = render({ page: { ...page, snapshots: [] } })
|
||
expect(html).toContain('尚无测试封存')
|
||
expect(html).toContain('还没有测试库封存')
|
||
})
|
||
})
|