fix(web): 整库页按作业类型与终态显示并补全轮询
- 成功的作业不再写"尚未启动/此时尚未运行",阶段条对恢复/基线也读自己的阶段行; - 基线/恢复不再被写成"生产同步""封存进行中",改为逐类映射; - 抽屉按版本登记标注每份归档,未登记的不冒充候选; - 轮询覆盖投递→终态读回:投递中动作、封存队列、任一 scope 在飞作业都算在跑, 读到终态再读回一次就停,失败作业不会被无限轮询。
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { ReleaseTargetsView } from './ReleaseTargets'
|
||||
import { ReleaseTargetsView, libraryPollingActive } from './ReleaseTargets'
|
||||
import type {
|
||||
LibraryCaptureJob,
|
||||
LibraryJobRecord,
|
||||
LibraryOverview,
|
||||
LibrarySnapshot,
|
||||
LibrarySnapshotList,
|
||||
LibraryStageRow,
|
||||
} from './librarySnapshots'
|
||||
|
||||
const internalSnapshot: LibrarySnapshot = {
|
||||
@@ -306,8 +307,267 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
|
||||
|
||||
it('抽屉只展示当前选中库的历史', () => {
|
||||
const html = render({ drawerOpen: true, scope: 'external' })
|
||||
expect(html).toContain('封存 01343b0b310b')
|
||||
expect(html).not.toContain('封存 f992d64ea45b')
|
||||
expect(html).toContain('快照 01343b0b310b')
|
||||
expect(html).not.toContain('快照 f992d64ea45b')
|
||||
})
|
||||
|
||||
// E3:归档里同时躺着测试封存、目标基线与每次预备份。旧页面把每一行都写"测试封存",
|
||||
// 于是预备份/基线被当成了"可以发布的候选"。类型只能来自版本登记。
|
||||
it('抽屉按版本登记标注每份归档,不把预备份/基线写成测试封存', () => {
|
||||
const html = render({
|
||||
drawerOpen: true,
|
||||
overview: {
|
||||
...overview,
|
||||
versions: [
|
||||
{
|
||||
id: 'libver-sealed',
|
||||
kind: 'test_sealed',
|
||||
snapshot_id: internalSnapshot.snapshot_id,
|
||||
version_label: '',
|
||||
source_job_id: 'libseal-1',
|
||||
created_at: internalSnapshot.created_at,
|
||||
},
|
||||
{
|
||||
id: 'libver-pre',
|
||||
kind: 'production_prebackup',
|
||||
snapshot_id: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
||||
version_label: '',
|
||||
source_job_id: 'librestore-internal-1',
|
||||
created_at: '2026-10-29T16:59:39Z',
|
||||
},
|
||||
],
|
||||
},
|
||||
page: {
|
||||
...page,
|
||||
snapshots: [
|
||||
internalSnapshot,
|
||||
{
|
||||
...internalSnapshot,
|
||||
snapshot_id: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
||||
created_at: '2026-10-29T16:59:39Z',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
expect(html).toContain('测试封存')
|
||||
expect(html).toContain('生产预备份')
|
||||
// 没有被登记过的归档文件也不能冒充测试封存
|
||||
expect(html).not.toContain('<span class="rel-pill green">测试封存</span><small')
|
||||
})
|
||||
|
||||
// E2:恢复作业登记了"恢复前备份",它和测试封存快照本来就不同。旧逻辑只认
|
||||
// "与测试封存同快照的预备份",刚备份完页面还说"尚未创建"。
|
||||
it('已登记的预备份不再显示尚未创建,并写清是哪次作业、是否当前目标', () => {
|
||||
const html = render({
|
||||
drawerOpen: true,
|
||||
overview: {
|
||||
...overview,
|
||||
prebackup: {
|
||||
state: 'known',
|
||||
version: {
|
||||
id: 'libver-pre',
|
||||
kind: 'production_prebackup',
|
||||
snapshot_id: '089676a09107ceab3bf5e88651f443da26e5d9b2d0de380840c5ec24941a07c2',
|
||||
version_label: '',
|
||||
source_job_id: 'librestore-internal-1793293164573204381',
|
||||
evidence: {},
|
||||
created_by: 'worker',
|
||||
created_at: '2026-10-29T16:59:39Z',
|
||||
},
|
||||
bound_to_target: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(html).toContain('已登记预备份')
|
||||
expect(html).not.toContain('尚未创建')
|
||||
expect(html).toContain('作业 librestore-internal-1793293164573204381')
|
||||
expect(html).toContain('不是当前拟发布目标的快照')
|
||||
expect(html).toContain('最近一次生产预备份')
|
||||
expect(html).not.toContain('无记录(尚未为本次目标创建)')
|
||||
})
|
||||
|
||||
// E1:作业已经成功,页面不能还说"尚未启动/此时尚未运行"。
|
||||
it('已完成的同步不再写“尚未启动”,阶段按本次作业打勾', () => {
|
||||
const succeeded: LibraryJobRecord = {
|
||||
...persistedSeal,
|
||||
id: 'libsync-internal-1793292008635856030',
|
||||
kind: 'sync',
|
||||
state: 'succeeded',
|
||||
stage: 'finalize',
|
||||
snapshot_id: '4b720eb42fca75de40aa862f2b53d0751e648d760dafaca309aaee08771f2c73',
|
||||
target_snapshot_id: internalSnapshot.snapshot_id,
|
||||
finished_at: '2026-10-29T16:40:36Z',
|
||||
updated_at: '2026-10-29T16:40:36Z',
|
||||
stages: [
|
||||
{
|
||||
stage: 'prebackup',
|
||||
state: 'succeeded',
|
||||
total: null,
|
||||
completed: null,
|
||||
bytes_total: null,
|
||||
bytes_done: null,
|
||||
detail: '',
|
||||
updated_at: '2026-10-29T16:40:21Z',
|
||||
},
|
||||
{
|
||||
stage: 'database',
|
||||
state: 'succeeded',
|
||||
total: 67,
|
||||
completed: 67,
|
||||
bytes_total: 88086,
|
||||
bytes_done: 88086,
|
||||
detail: '',
|
||||
updated_at: '2026-10-29T16:40:22Z',
|
||||
},
|
||||
{
|
||||
stage: 'verify',
|
||||
state: 'succeeded',
|
||||
total: null,
|
||||
completed: null,
|
||||
bytes_total: null,
|
||||
bytes_done: null,
|
||||
detail: '',
|
||||
updated_at: '2026-10-29T16:40:26Z',
|
||||
},
|
||||
{
|
||||
stage: 'finalize',
|
||||
state: 'succeeded',
|
||||
total: null,
|
||||
completed: null,
|
||||
bytes_total: null,
|
||||
bytes_done: null,
|
||||
detail: '已登记生效版本',
|
||||
updated_at: '2026-10-29T16:40:26Z',
|
||||
},
|
||||
],
|
||||
}
|
||||
const html = render({ overview: { ...overview, job: succeeded, jobs: [succeeded] } })
|
||||
expect(html).not.toContain('尚未启动,不修改生产')
|
||||
expect(html).not.toContain('此时尚未运行')
|
||||
expect(html).toContain('生产同步已完成')
|
||||
expect(html).toContain('生产同步 · 已完成')
|
||||
const stageBar = html.slice(html.indexOf('aria-label="作业阶段"'), html.indexOf('rel-steps-note'))
|
||||
expect(stageBar).toContain('✓')
|
||||
})
|
||||
|
||||
// E4:基线/恢复不是"生产同步",也不是"封存进行中"。
|
||||
it('建立基线进行中不写成同步中,也不写成封存进行中', () => {
|
||||
const baseline: LibraryJobRecord = {
|
||||
...persistedSeal,
|
||||
id: 'libbase-internal-1',
|
||||
kind: 'baseline',
|
||||
state: 'running',
|
||||
stage: 'database',
|
||||
finished_at: null,
|
||||
}
|
||||
const html = render({ overview: { ...overview, job: baseline, jobs: [baseline] } })
|
||||
expect(html).toContain('建立目标基线进行中')
|
||||
expect(html).toContain('建立目标基线作业')
|
||||
expect(html).toContain('建基线中')
|
||||
expect(html).not.toContain('封存进行中')
|
||||
expect(html).not.toContain('生产同步作业')
|
||||
expect(html).not.toContain('同步中')
|
||||
})
|
||||
|
||||
it('恢复作业用“按版本恢复”而不是“生产同步”,并说明已回到该快照', () => {
|
||||
const stages: LibraryStageRow[] = [
|
||||
{
|
||||
stage: 'prebackup',
|
||||
state: 'succeeded',
|
||||
total: null,
|
||||
completed: null,
|
||||
bytes_total: null,
|
||||
bytes_done: null,
|
||||
detail: '',
|
||||
updated_at: '2026-10-29T16:59:39Z',
|
||||
},
|
||||
{
|
||||
stage: 'database',
|
||||
state: 'succeeded',
|
||||
total: 5,
|
||||
completed: 5,
|
||||
bytes_total: 7138,
|
||||
bytes_done: 7138,
|
||||
detail: '',
|
||||
updated_at: '2026-10-29T16:59:40Z',
|
||||
},
|
||||
{
|
||||
stage: 'resources',
|
||||
state: 'succeeded',
|
||||
total: 1,
|
||||
completed: 1,
|
||||
bytes_total: 507,
|
||||
bytes_done: 507,
|
||||
detail: '',
|
||||
updated_at: '2026-10-29T16:59:40Z',
|
||||
},
|
||||
{
|
||||
stage: 'index',
|
||||
state: 'succeeded',
|
||||
total: 2,
|
||||
completed: 2,
|
||||
bytes_total: 28563,
|
||||
bytes_done: 28563,
|
||||
detail: '',
|
||||
updated_at: '2026-10-29T16:59:40Z',
|
||||
},
|
||||
{
|
||||
stage: 'wiki',
|
||||
state: 'succeeded',
|
||||
total: 10,
|
||||
completed: 10,
|
||||
bytes_total: 23144,
|
||||
bytes_done: 23144,
|
||||
detail: '',
|
||||
updated_at: '2026-10-29T16:59:40Z',
|
||||
},
|
||||
{
|
||||
stage: 'verify',
|
||||
state: 'succeeded',
|
||||
total: null,
|
||||
completed: null,
|
||||
bytes_total: null,
|
||||
bytes_done: null,
|
||||
detail: '',
|
||||
updated_at: '2026-10-29T16:59:40Z',
|
||||
},
|
||||
{
|
||||
stage: 'finalize',
|
||||
state: 'succeeded',
|
||||
total: null,
|
||||
completed: null,
|
||||
bytes_total: null,
|
||||
bytes_done: null,
|
||||
detail: '已登记生效版本',
|
||||
updated_at: '2026-10-29T16:59:40Z',
|
||||
},
|
||||
]
|
||||
const restoreRunning: LibraryJobRecord = {
|
||||
...persistedSeal,
|
||||
id: 'librestore-internal-1793293164573204381',
|
||||
kind: 'restore',
|
||||
state: 'running',
|
||||
stage: 'wiki',
|
||||
target_snapshot_id: '4b720eb42fca75de40aa862f2b53d0751e648d760dafaca309aaee08771f2c73',
|
||||
finished_at: null,
|
||||
stages,
|
||||
}
|
||||
const running = render({ overview: { ...overview, job: restoreRunning, jobs: [restoreRunning] } })
|
||||
expect(running).toContain('按版本恢复作业')
|
||||
expect(running).toContain('恢复到 4b720eb42fca')
|
||||
expect(running).toContain('恢复进行中(目标在维护中)')
|
||||
expect(running).not.toContain('生产同步作业')
|
||||
|
||||
const restoreDone: LibraryJobRecord = {
|
||||
...restoreRunning,
|
||||
state: 'succeeded',
|
||||
finished_at: '2026-10-29T16:59:51Z',
|
||||
}
|
||||
const html = render({ overview: { ...overview, job: restoreDone, jobs: [restoreDone] } })
|
||||
expect(html).toContain('按版本恢复')
|
||||
expect(html).toContain('按版本恢复已完成')
|
||||
const stageBar = html.slice(html.indexOf('aria-label="作业阶段"'), html.indexOf('rel-steps-note'))
|
||||
expect(stageBar).toContain('生产已回到该快照')
|
||||
})
|
||||
|
||||
it('同步中布局显示四类数据卡与明细,且不编造百分比', () => {
|
||||
@@ -446,3 +706,40 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
|
||||
expect(unknown).not.toContain('也没有维护能力配置')
|
||||
})
|
||||
})
|
||||
|
||||
// E5:轮询必须覆盖"投递 → 终态读回"。
|
||||
// 旧实现只按封存队列的作业判断,于是点了同步/恢复/建立基线之后页面根本不刷新,
|
||||
// 看上去像"还没启动";要么反过来,一个失败作业被永远轮询下去。
|
||||
describe('libraryPollingActive(轮询范围)', () => {
|
||||
const idle = { internal: null, external: null } as Record<'internal' | 'external', LibraryOverview | null>
|
||||
const withJob = (state: LibraryJobRecord['state'], kind: LibraryJobRecord['kind']) =>
|
||||
({
|
||||
internal: { ...overview, job: { ...persistedSeal, state, kind }, jobs: [] },
|
||||
external: null,
|
||||
}) as Record<'internal' | 'external', LibraryOverview | null>
|
||||
|
||||
it('投递中就已经在轮询,不必等到作业出现在列表里', () => {
|
||||
expect(libraryPollingActive({ captures: [], overviews: idle, pending: true })).toBe(true)
|
||||
})
|
||||
|
||||
it('持久作业在飞(同步/恢复/基线)也轮询', () => {
|
||||
expect(libraryPollingActive({ captures: [], overviews: withJob('running', 'sync'), pending: false })).toBe(true)
|
||||
expect(libraryPollingActive({ captures: [], overviews: withJob('pending', 'restore'), pending: false })).toBe(true)
|
||||
expect(libraryPollingActive({ captures: [], overviews: withJob('running', 'baseline'), pending: false })).toBe(true)
|
||||
})
|
||||
|
||||
it('封存队列里的作业同样算在飞', () => {
|
||||
expect(libraryPollingActive({ captures: [runningJob], overviews: idle, pending: false })).toBe(true)
|
||||
})
|
||||
|
||||
it('终态必须停下来:失败作业不许被无限轮询', () => {
|
||||
expect(libraryPollingActive({ captures: [], overviews: withJob('succeeded', 'sync'), pending: false })).toBe(false)
|
||||
expect(libraryPollingActive({ captures: [], overviews: withJob('failed', 'sync'), pending: false })).toBe(false)
|
||||
expect(libraryPollingActive({ captures: [], overviews: withJob('cancelled', 'restore'), pending: false })).toBe(
|
||||
false
|
||||
)
|
||||
expect(
|
||||
libraryPollingActive({ captures: [{ ...runningJob, state: 'failed' }], overviews: idle, pending: false })
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user