fix(web): 整库页按作业类型与终态显示并补全轮询

- 成功的作业不再写"尚未启动/此时尚未运行",阶段条对恢复/基线也读自己的阶段行;
- 基线/恢复不再被写成"生产同步""封存进行中",改为逐类映射;
- 抽屉按版本登记标注每份归档,未登记的不冒充候选;
- 轮询覆盖投递→终态读回:投递中动作、封存队列、任一 scope 在飞作业都算在跑,
  读到终态再读回一次就停,失败作业不会被无限轮询。
This commit is contained in:
姚章浩
2026-10-30 01:33:51 +08:00
parent 402173263e
commit 74fb04b2d1
3 changed files with 498 additions and 51 deletions
+300 -3
View File
@@ -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)
})
})
+178 -47
View File
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import {
createLibraryRestoreAuthorization,
createLibrarySyncAuthorization,
@@ -22,6 +22,7 @@ import {
type LibrarySnapshot,
type LibrarySnapshotList,
type LibraryStageRow,
type LibraryVersionRef,
} from './librarySnapshots'
import { useOptionalAuth } from './auth'
import './releaseTargets.css'
@@ -174,7 +175,17 @@ function captureHint(view: ScopeView, canWrite: boolean): string {
function statusOf(view: ScopeView) {
const job = view.job
if (job && (job.state === 'running' || job.state === 'pending')) {
return { text: job.kind === 'seal' ? '封存中' : '同步中', tone: 'blue' as const }
// 页签徽标也要说清是哪一类作业在跑:把"建立基线"写成"同步中"会让人
// 以为生产正在被写入。
const text =
job.kind === 'seal'
? '封存中'
: job.kind === 'restore'
? '恢复中'
: job.kind === 'baseline'
? '建基线中'
: '同步中'
return { text, tone: 'blue' as const }
}
if (view.overview?.production.state === 'known') return { text: '生产已记录版本', tone: 'green' as const }
if (view.overview?.test_sealed || view.snapshot) return { text: '已有封存', tone: 'green' as const }
@@ -215,6 +226,57 @@ function jobStateText(job: LibraryJobRecord): string {
return map[job.state] ?? job.state
}
// 作业类型必须逐类写清:基线不是同步,恢复也不是同步。混写会让人以为
// "建立基线"正在把测试内容写进生产,或者把恢复当成一次正式发布。
export function jobKindText(kind?: string): string {
if (kind === 'seal') return '测试封存'
if (kind === 'sync') return '生产同步'
if (kind === 'restore') return '按版本恢复'
if (kind === 'baseline') return '建立目标基线'
return kind ? kind : '—'
}
// 归档里的每一份快照属于哪一类版本:只能来自版本登记,不能一律写"测试封存"。
export function snapshotVersionLabel(refs: LibraryVersionRef[] | undefined, snapshotID: string): string {
const kinds = new Set((refs ?? []).filter((item) => item.snapshot_id === snapshotID).map((item) => item.kind))
const labels: string[] = []
if (kinds.has('test_sealed')) labels.push('测试封存')
if (kinds.has('production_effective')) labels.push('生产生效')
if (kinds.has('production_prebackup')) labels.push('生产预备份')
return labels.length > 0 ? labels.join(' · ') : '未登记(归档文件,不作为发布候选)'
}
// 生产写入的当前状态:不能用一句写死的"尚未启动"顶替已经完成的作业。
export function publishStateText(job?: LibraryJobRecord): string {
if (!job) return '尚未启动,不修改生产'
if (job.state === 'pending' || job.state === 'running') {
return job.kind === 'restore'
? '恢复进行中(目标在维护中)'
: job.kind === 'baseline'
? '建立基线进行中(只读捕获目标,不写内容)'
: '同步进行中(目标在维护中)'
}
if (job.state === 'succeeded') return `${jobKindText(job.kind)}已完成 · ${stamp(job.finished_at ?? job.updated_at)}`
if (job.state === 'failed') return `${jobKindText(job.kind)}失败 · ${stamp(job.finished_at ?? job.updated_at)}`
return `${jobKindText(job.kind)}已取消 · ${stamp(job.finished_at ?? job.updated_at)}`
}
// 轮询范围 = 投递中 + 有在飞作业(封存队列与持久作业都算)。
// 终态(成功/失败/取消)必须停下来:无限轮询一个失败作业既没意义,
// 也会把"作业已经结束"这个事实淹没在不停刷新的页面里。
export function libraryPollingActive(input: {
captures: LibraryCaptureJob[]
overviews: Record<Scope, LibraryOverview | null>
pending: boolean
}): boolean {
if (input.pending) return true
if (input.captures.some((job) => ACTIVE_STATES.includes(job.state))) return true
return (['internal', 'external'] as Scope[]).some((scope) => {
const job = input.overviews[scope]?.job
return Boolean(job && ACTIVE_STATES.includes(job.state))
})
}
// ---- 目标维护窗口:级别 / 进度 / 恢复错误 ----
//
// 维护窗口有两种级别:实例级(跨 scope 共用一把锁,真正挡住写入者)和库级。
@@ -403,7 +465,9 @@ export function wikiContributionLines(diff: LibraryOverview['diff'] | undefined)
function StageBar({ view }: { view: ScopeView }) {
const job = view.job
const sealJob = job?.kind === 'seal' ? job : undefined
const syncJob = job?.kind === 'sync' ? job : undefined
// 同步、恢复、建立基线共用同一串阶段(预备份 → 数据四类 → 校验 → 登记版本)。
// 只按"sync"找阶段会让刚跑完的恢复/基线在页面上显示成"本次作业尚未开始"。
const writeJob = job && job.kind !== 'seal' ? job : undefined
let first: { state: StepState; hint: string }
if (sealJob) {
@@ -419,19 +483,24 @@ function StageBar({ view }: { view: ScopeView }) {
? '已排队,等待 worker'
: '本次封存未完成',
}
} else if (syncJob) {
first = { state: 'done', hint: '已绑定的测试版本' }
} else if (writeJob) {
first =
writeJob.kind === 'restore'
? { state: 'done', hint: '恢复到选定快照(不经过测试封存)' }
: writeJob.kind === 'baseline'
? { state: 'done', hint: '目标自身内容,非测试封存' }
: { state: 'done', hint: '已绑定的测试版本' }
} else {
first = { state: 'idle', hint: '本次作业尚未开始' }
}
const prebackup = syncJob ? stageOf(syncJob, 'prebackup') : undefined
const dataStages = syncJob
const prebackup = writeJob ? stageOf(writeJob, 'prebackup') : undefined
const dataStages = writeJob
? ['database', 'resources', 'index', 'wiki']
.map((name) => stageOf(syncJob, name))
.map((name) => stageOf(writeJob, name))
.filter((row): row is LibraryStageRow => Boolean(row))
: []
const verifyStage = syncJob ? stageOf(syncJob, 'verify') : undefined
const verifyStage = writeJob ? stageOf(writeJob, 'verify') : undefined
const stages: { label: string; state: StepState; hint: string }[] = [
{ label: '固定测试版本', ...first },
@@ -460,8 +529,15 @@ function StageBar({ view }: { view: ScopeView }) {
},
{
label: '新版本生效',
state: syncJob && syncJob.state === 'succeeded' ? 'done' : 'idle',
hint: syncJob && syncJob.state === 'succeeded' ? '生产已生效' : '未接入',
state: writeJob && writeJob.state === 'succeeded' ? 'done' : 'idle',
hint:
writeJob && writeJob.state === 'succeeded'
? writeJob.kind === 'restore'
? '生产已回到该快照'
: writeJob.kind === 'baseline'
? '目标基线已登记(目标内容未改)'
: '生产已生效'
: '未接入',
},
]
return (
@@ -480,9 +556,7 @@ function StageBar({ view }: { view: ScopeView }) {
</ol>
<p className="rel-steps-note">
{job
? `作业 ${job.id} · ${job.kind === 'seal' ? '测试封存' : '生产同步'} · ${jobStateText(job)}${
job.error ? ` · ${job.error}` : ''
}`
? `作业 ${job.id} · ${jobKindText(job.kind)} · ${jobStateText(job)}${job.error ? ` · ${job.error}` : ''}`
: view.snapshot
? `已有测试封存 ${stamp(view.snapshot.created_at)}(历史记录),但本次作业尚未开始;没有当前作业证据时不会把历史封存当作阶段完成。`
: '本次作业尚未开始。'}
@@ -603,14 +677,30 @@ function ProtectionCard({
<aside className="rel-panel rel-protection">
<header className="rel-panel-head">
<h2>生产保护与恢复</h2>
<span className={`rel-pill ${backupKnown ? 'green' : 'gray'}`}>{backupKnown ? '已有预备份' : '尚未创建'}</span>
<span className={`rel-pill ${backupKnown ? 'green' : 'gray'}`}>
{backupKnown ? '已登记预备份' : '尚未创建'}
</span>
</header>
<dl>
<dt>本次同步前备份</dt>
<dt>最近一次生产写入前备份</dt>
<dd>
{backupKnown
? `${stamp(prebackup.version!.created_at)} · ${prebackup.version!.version_label || prebackup.version!.snapshot_id.slice(0, 12)}`
: '未接入(还没有与目标快照绑定的预备份)'}
{backupKnown ? (
<>
{stamp(prebackup.version!.created_at)} ·{' '}
{prebackup.version!.version_label || prebackup.version!.snapshot_id.slice(0, 12)}
{prebackup.version!.source_job_id ? ` · 作业 ${prebackup.version!.source_job_id}` : ''}
<br />
<small>
{prebackup.bound_to_target
? '与当前拟发布目标是同一份快照'
: targetSealed
? '不是当前拟发布目标的快照(是那次生产写入前的状态)'
: '归档里没有拟发布目标,无法比对'}
</small>
</>
) : (
'未登记(这个范围还没有任何生产预备份)'
)}
</dd>
<dt>生产当前版本</dt>
<dd>
@@ -710,7 +800,12 @@ function ReadyBody({
<div className="rel-panel rel-jobbar">
<header className="rel-panel-head">
<h2>启动后的作业进度</h2>
<span className="rel-pill gray">此时尚未运行</span>
{/* 作业跑完/失败后不能还说"此时尚未运行":这个徽标说的是**最近一次作业**的终态。 */}
<span className={`rel-pill ${view.job ? (view.job.state === 'failed' ? 'red' : 'green') : 'gray'}`}>
{view.job
? `${jobKindText(view.job.kind)} · ${jobStateText(view.job)} · ${stamp(view.job.finished_at ?? view.job.updated_at)}`
: '此时尚未运行'}
</span>
</header>
<StageBar view={view} />
</div>
@@ -743,9 +838,11 @@ function ReadyBody({
function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onOpen: () => void }) {
const job = view.job
const sealJob = job?.kind === 'seal' ? job : undefined
const syncJob = job?.kind === 'sync' ? job : undefined
// 四类数据阶段对同步/恢复/基线都成立:分项读的是这份作业自己的阶段,
// 不是"只有 sync 才有"。写死 sync 会让恢复作业的分项全显示"未接入"。
const dataJob = job && job.kind !== 'seal' ? job : undefined
const running = job?.state === 'running' || job?.state === 'pending'
const stage = (name: string) => syncJob?.stages.find((item) => item.stage === name)
const stage = (name: string) => dataJob?.stages.find((item) => item.stage === name)
const cards = [
{ title: '数据库 · 文档与分块', row: stage('database'), axis: '文档 / 分块' },
@@ -767,9 +864,14 @@ function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onO
<div className="rel-panel rel-progress-head">
<div className="rel-between">
<h2>
{sealJob ? '测试库封存作业' : syncJob ? '生产同步作业' : '本次作业'}
{sealJob ? '测试库封存作业' : dataJob ? `${jobKindText(dataJob.kind)}作业` : '本次作业'}
<span className="rel-version">
测试封存 <b>{view.overview?.test_sealed?.snapshot_id.slice(0, 12) ?? '未接入'}</b> → 生产当前{' '}
{dataJob?.kind === 'restore'
? `恢复到 ${dataJob.target_snapshot_id.slice(0, 12) || '—'}`
: dataJob?.kind === 'baseline'
? `目标基线 ${dataJob.target_snapshot_id.slice(0, 12) || '(本次捕获后登记)'}`
: `测试封存 ${view.overview?.test_sealed?.snapshot_id.slice(0, 12) ?? '未接入'}`}{' '}
→ 生产当前{' '}
<b>
{view.overview?.production.state === 'known' && view.overview.production.version
? view.overview.production.version.version_label ||
@@ -783,8 +885,8 @@ function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onO
</span>
</div>
<p className="rel-jobmeta">
作业 <code>{job?.id ?? '未接入'}</code> · 类型 {job ? (job.kind === 'seal' ? '测试封存' : '生产同步') : '—'} ·
操作人 {job?.actor || '—'} · 最近进展 {job ? stamp(job.updated_at) : '—'}
作业 <code>{job?.id ?? '未接入'}</code> · 类型 {job ? jobKindText(job.kind) : '—'} · 操作人{' '}
{job?.actor || '—'} · 最近进展 {job ? stamp(job.updated_at) : '—'}
{job?.recovery ? ` · 恢复:${job.recovery}` : ''}
</p>
<StageBar view={view} />
@@ -838,7 +940,7 @@ function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onO
<p className="rel-datadetail">
{card.row?.detail
? card.row.detail
: syncJob
: dataJob
? '该分项还没有上报数据'
: '生产同步执行链未接通,分项不会产生数据'}
</p>
@@ -966,7 +1068,7 @@ function Drawer({
<header className="rel-drawer-head">
<div>
<h2>版本与快照</h2>
<p>{scopeName(view.scope)} · 已封存记录</p>
<p>{scopeName(view.scope)} · 归档里的全部快照,类型按版本登记标注</p>
</div>
<button type="button" className="rel-close" onClick={onClose}>
关闭 ✕
@@ -982,11 +1084,15 @@ function Drawer({
</dd>
</div>
<div>
<dt>本次生产预备份</dt>
<dt>最近一次生产预备份</dt>
<dd>
{view.overview?.prebackup.state === 'known' && view.overview.prebackup.version
? `${view.overview.prebackup.version.version_label || view.overview.prebackup.version.snapshot_id.slice(0, 12)} · ${stamp(view.overview.prebackup.version.created_at)}`
: '无记录(尚未为本次目标创建)'}
? `${view.overview.prebackup.version.version_label || view.overview.prebackup.version.snapshot_id.slice(0, 12)} · ${stamp(view.overview.prebackup.version.created_at)}${
view.overview.prebackup.version.source_job_id
? ` · 作业 ${view.overview.prebackup.version.source_job_id}`
: ''
}${view.overview.prebackup.bound_to_target ? ' · 与拟发布目标同快照' : ''}`
: '无记录(这个范围还没有任何生产预备份)'}
</dd>
</div>
<div>
@@ -1018,14 +1124,17 @@ function Drawer({
) : (
listing.map((snapshot) => {
const isSelected = expanded === snapshot.snapshot_id
// 类型只能来自版本登记:归档里的目标基线与预备份也在同一个根下。
const versionLabel = snapshotVersionLabel(view.overview?.versions, snapshot.snapshot_id)
const sealed = versionLabel.includes('测试封存')
return (
<tr key={snapshot.snapshot_id} className={isSelected ? 'selected' : ''}>
<td>
<strong>封存 {snapshot.snapshot_id.slice(0, 12)}</strong>
<strong>快照 {snapshot.snapshot_id.slice(0, 12)}</strong>
<small>{stamp(snapshot.created_at)}</small>
</td>
<td>
<span className="rel-pill green">测试封存</span>
<span className={`rel-pill ${sealed ? 'green' : 'gray'}`}>{versionLabel}</span>
</td>
<td>
<span className="rel-pill gray">分项完整 · 未做生产恢复验证</span>
@@ -1057,7 +1166,9 @@ function Drawer({
<section className="rel-snapshot">
<header>
<h3>封存 {selected.snapshot_id.slice(0, 12)} · 恢复资料</h3>
<span className="rel-pill green">读取时逐项校验通过</span>
<span className="rel-pill green">
{snapshotVersionLabel(view.overview?.versions, selected.snapshot_id)}
</span>
</header>
<p className="rel-hint">
完整快照 <code>{selected.snapshot_id}</code> · 封存于 {stamp(selected.created_at)} · 模型{' '}
@@ -1292,7 +1403,12 @@ export function ReleaseTargetsView(props: ViewProps) {
<div className="rel-panel rel-jobhead">
<div className="rel-between">
<h2>
{scopeName(scope)} · {active ? '封存进行中' : view.snapshot ? '已封存,同步按条件放行' : '尚无测试封存'}
{scopeName(scope)} ·{' '}
{active
? `${jobKindText(view.job?.kind)}进行中`
: view.snapshot
? '已封存,同步按条件放行'
: '尚无测试封存'}
</h2>
<div className="rel-head-actions">
<button type="button" className="rel-secondary" onClick={() => onDrawer(true)}>
@@ -1321,8 +1437,8 @@ export function ReleaseTargetsView(props: ViewProps) {
<b className="rel-unknown">未知(尚未建立权威版本)</b>
)}{' '}
→ 拟发布{' '}
<b>{target ? `封存 ${target.snapshot_id.slice(0, 12)} · ${stamp(target.created_at)}` : '还没有测试封存'}</b> ·
尚未启动,不修改生产
<b>{target ? `封存 ${target.snapshot_id.slice(0, 12)} · ${stamp(target.created_at)}` : '还没有测试封存'}</b> ·{' '}
{publishStateText(view.job)}
</p>
<dl className="rel-metrics">
<div>
@@ -1478,16 +1594,6 @@ export function ReleaseTargets() {
return () => controller.abort()
}, [load])
const busy = jobs.some((job) => ACTIVE_STATES.includes(job.state))
useEffect(() => {
if (!busy) return
const timer = window.setInterval(() => {
setNow(Date.now())
void load().catch(() => undefined)
}, 3000)
return () => window.clearInterval(timer)
}, [busy, load])
const role = auth?.identity?.role
const canWrite = role === 'engineer' || role === 'admin'
// 恢复写的是整套生产知识状态,接口只认管理员;页面必须与它一致。
@@ -1559,6 +1665,31 @@ export function ReleaseTargets() {
const [restoreNotice, setRestoreNotice] = useState<string | null>(null)
const [pendingRestore, setPendingRestore] = useState(false)
const [pendingGrant, setPendingGrant] = useState(false)
// 轮询覆盖"投递 → 终态读回":投递中的动作也算在跑(点完到 worker 落库之间
// 有一次空窗,只看已有作业会让页面停在"尚未启动")。终态(成功/失败/取消)
// 再做一次读回就停,不会无限轮询失败作业。
const polling = libraryPollingActive({
captures: jobs,
overviews,
pending: pendingCapture || pendingSync || pendingBaseline || pendingRestore || pendingSyncGrant || pendingGrant,
})
const wasPolling = useRef(false)
useEffect(() => {
if (polling) {
wasPolling.current = true
const timer = window.setInterval(() => {
setNow(Date.now())
void load().catch(() => undefined)
}, 3000)
return () => window.clearInterval(timer)
}
if (wasPolling.current) {
wasPolling.current = false
// 终态读回:拿最后一次的 finished_at / 阶段终值,然后停下。
void load().catch(() => undefined)
}
return undefined
}, [polling, load])
const [restoreRound, setRestoreRound] = useState(0)
const restoreSnapshot = expandedSnapshot ?? ''
useEffect(() => {
+20 -1
View File
@@ -403,6 +403,8 @@ export interface LibraryKnown {
state: 'known' | 'unknown'
version?: LibraryVersionRecord
reason?: string
/** 只在预备份上有意义:这份备份的内容是否就是当前拟发布目标。 */
bound_to_target?: boolean
}
export interface LibraryDiff {
@@ -539,7 +541,7 @@ export interface LibraryStageRow {
export interface LibraryJobRecord {
id: string
scope: string
kind: 'seal' | 'sync' | 'restore'
kind: 'seal' | 'sync' | 'restore' | 'baseline'
state: 'pending' | 'running' | 'succeeded' | 'failed' | 'cancelled'
stage: string
request_digest: string
@@ -555,6 +557,21 @@ export interface LibraryJobRecord {
stages: LibraryStageRow[]
}
/**
* 已登记版本的轻量清单(不含 evidence)。
* 归档里不止"测试封存":目标基线与每次生产预备份也在同一个归档根下,
* 页面必须按登记过的 kind 给每份快照写类型,不能一律写"测试封存"。
*/
export interface LibraryVersionRef {
id: string
kind: 'test_sealed' | 'production_effective' | 'production_prebackup' | string
snapshot_id: string
version_label: string
source_job_id: string
created_at: string
superseded_at?: string | null
}
export interface LibraryAuthorizationView {
state: 'active' | 'none'
authorized_by?: string
@@ -585,6 +602,8 @@ export interface LibraryOverview {
test_sealed_reason?: string
production: LibraryKnown
prebackup: LibraryKnown
/** 已登记版本(轻量):页面据此给归档里的每份快照标类型。 */
versions?: LibraryVersionRef[]
diff: LibraryDiff
job?: LibraryJobRecord
jobs: LibraryJobRecord[]