feat(library): 整库版本/作业持久化与状态读取契约,生产同步默认拒绝
build / build (push) Failing after 17s

- 新增 library_versions:测试封存、生产生效、生产预备份三类分开登记,
  生产生效版本唯一(旧版本必须先 supersede),测试快照不能顶替生产版本
- 新增 library_jobs + library_job_stages:业务作业身份、阶段、错误与恢复说明,
  分项计数用 NULL 表示"总量未知";互斥与幂等由数据库唯一索引保证
- 新增 GET /api/v1/library/overview、/jobs、/jobs/{id};POST /syncs 闸口未齐
  返回 503 缺项且不建作业
- 封存作业落库:先建业务作业再入队,worker 推进 export 阶段并登记 test_sealed
- 发布管理读真实状态:生产未知不再顶替、差异 unknown、启动同步按缺项禁用、
  同步明细/四类分项来自持久阶段;阶段勾选只认当前作业证据
- 准备信息标注封存时间与范围,不声称实时测试库已就绪
This commit is contained in:
姚章浩
2026-10-28 13:58:51 +08:00
parent 58d0483d44
commit dc9e827656
14 changed files with 1902 additions and 126 deletions
+98 -7
View File
@@ -1,7 +1,13 @@
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { ReleaseTargetsView } from './ReleaseTargets'
import type { LibraryCaptureJob, LibrarySnapshot, LibrarySnapshotList } from './librarySnapshots'
import type {
LibraryCaptureJob,
LibraryJobRecord,
LibraryOverview,
LibrarySnapshot,
LibrarySnapshotList,
} from './librarySnapshots'
const internalSnapshot: LibrarySnapshot = {
snapshot_id: 'f992d64ea45bf737a0721a465b5aef2b150ef7757157eb84f3aaf8b6972d98f9',
@@ -67,11 +73,69 @@ const page: LibrarySnapshotList = {
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)',
'生产当前权威版本未知,不能启动写入',
'本次目标快照还没有生产预备份',
],
},
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,
@@ -102,20 +166,41 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
expect(html).not.toContain('对外知识库 · 尚无')
})
it('未接入项显示“未接入”,不用 0 / 无变化冒充', () => {
it('未接入项显示“未接入/未知”,不用 0 / 无变化冒充', () => {
const html = render()
expect(html).toContain('生产当前')
// 生产没有权威版本时必须写未知,不能拿测试快照顶替
expect(html).toContain('未知(尚未建立权威版本)')
expect(html).toContain('尚无记录 · 生产与测试的文档级差异读取未接线')
expect(html).toContain('未接入')
expect(html).toContain('尚无记录 · 变更清单来自生产与测试版本对比')
})
it('“启动同步”保持禁用并说明原因,不把封存当成同步', () => {
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()
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('版本与快照')
@@ -135,8 +220,11 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
})
it('同步中布局显示四类数据卡与明细,且不编造百分比', () => {
const html = render({ jobs: [runningJob] })
expect(html).toContain('正在封存测试版本')
const html = render({
jobs: [runningJob],
overview: { ...overview, job: persistedSeal, jobs: [persistedSeal] },
})
expect(html).toContain('测试库封存作业')
expect(html).toContain('数据库 · 文档与分块')
expect(html).toContain('原文件 · 图片 · 附件')
expect(html).toContain('检索索引 · 向量')
@@ -146,6 +234,9 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
expect(html.match(/[1-9]\d*%/g) ?? []).toEqual(['100%'])
expect(html).toContain('文件传输 100% ≠ 作业完成')
expect(html).toContain('不编造百分比')
// 没有真实总量时只写"未知总量",不画百分比
expect(html).toContain('未知总量')
expect(html).toContain('主机侧正在暂停写入者、导出并恢复')
})
it('无权限时不给封存入口,未接线时说明通道状态', () => {