修复 varchar 状态参数在 AdvanceLibraryJob 的 42P08;worker 开始/终态写入失败 不再吞掉。新增管理员核对路由,仅在 completed capture queue、export succeeded、 精确 test_sealed 版本、来源身份和归档复核一致时,以条件更新修复仍为 pending/running 的同一作业;已有不同快照或并发失败/取消行拒绝覆盖。保留 第一因与历史记录,不重新封存、不产生快照、不写源或目标知识。 验证:真实 varchar DDL PG 路径、handler 负例/幂等、worker 注入、web 组件; umask022 与真实隔离 kg_library_test_* 下 Go 全量与 make verify 17 项通过。
This commit is contained in:
@@ -171,6 +171,9 @@ const base: ViewProps = {
|
||||
pendingCapture: false,
|
||||
canCapture: true,
|
||||
canWrite: true,
|
||||
canReconcileCapture: false,
|
||||
pendingReconcileCapture: '',
|
||||
onReconcileCapture: vi.fn(),
|
||||
canRestore: false,
|
||||
sync: { canSign: false, pendingGrant: false, onGrant: vi.fn(), canStart: false, pending: false, onStart: vi.fn() },
|
||||
baseline: { canStart: false, pending: false, onStart: vi.fn() },
|
||||
@@ -723,6 +726,24 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
|
||||
expect(html).not.toContain('已完成 0 / 0')
|
||||
})
|
||||
|
||||
it('封存已完成但终态未回写时,管理员看到核对入口;工程师不显示', () => {
|
||||
const reconciled: LibraryJobRecord = {
|
||||
...persistedSeal,
|
||||
stages: [{ ...persistedSeal.stages[0], state: 'succeeded', detail: '已封存快照 f992d64ea45b' }],
|
||||
}
|
||||
const admin = render({
|
||||
canReconcileCapture: true,
|
||||
onReconcileCapture: vi.fn(),
|
||||
overview: { ...overview, job: reconciled, jobs: [reconciled] },
|
||||
})
|
||||
expect(admin).toContain('核对封存结果')
|
||||
const engineer = render({
|
||||
canReconcileCapture: false,
|
||||
overview: { ...overview, job: reconciled, jobs: [reconciled] },
|
||||
})
|
||||
expect(engineer).not.toContain('核对封存结果')
|
||||
})
|
||||
|
||||
it('封存作业只显示只读导出步骤,不冒充生产备份/同步/生效或目标维护', () => {
|
||||
const html = render({
|
||||
jobs: [runningJob],
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
fetchLibraryOverview,
|
||||
fetchLibraryRestoreAvailability,
|
||||
fetchLibrarySnapshots,
|
||||
reconcileLibraryCapture,
|
||||
formatBytes,
|
||||
scopeLabel,
|
||||
type LibraryCaptureJob,
|
||||
@@ -117,6 +118,10 @@ interface ViewProps {
|
||||
pendingCapture: boolean
|
||||
canCapture: boolean
|
||||
canWrite: boolean
|
||||
// 管理员核对已完成 queue/精确版本/归档后修复 pending 封存作业终态。
|
||||
canReconcileCapture: boolean
|
||||
pendingReconcileCapture: string
|
||||
onReconcileCapture: (jobID: string) => void
|
||||
// 发布动作:签发授权(管理员)与启动同步是两个独立步骤,页面绝不自动签发。
|
||||
sync: ReleaseSyncActions
|
||||
// 目标非空又没有生效版本时,唯一入口是"建立目标权威基线"(管理员)。
|
||||
@@ -1081,14 +1086,28 @@ function ReadyBody({
|
||||
)
|
||||
}
|
||||
|
||||
function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onOpen: () => void }) {
|
||||
function ProgressBody({
|
||||
view,
|
||||
now,
|
||||
onOpen,
|
||||
canReconcileCapture,
|
||||
pendingReconcileCapture,
|
||||
onReconcileCapture,
|
||||
}: {
|
||||
view: ScopeView
|
||||
now: number
|
||||
onOpen: () => void
|
||||
canReconcileCapture: boolean
|
||||
pendingReconcileCapture: string
|
||||
onReconcileCapture: (jobID: string) => void
|
||||
}) {
|
||||
const job = view.job
|
||||
const sealJob = job?.kind === 'seal' ? job : undefined
|
||||
// 四类数据阶段对同步/恢复/基线都成立:分项读的是这份作业自己的阶段,
|
||||
// 不是"只有 sync 才有"。写死 sync 会让恢复作业的分项全显示"未接入"。
|
||||
const dataJob = job && job.kind !== 'seal' ? job : undefined
|
||||
const running = job?.state === 'running' || job?.state === 'pending'
|
||||
const stage = (name: string) => dataJob?.stages.find((item) => item.stage === name)
|
||||
const stage = (name: string) => (dataJob ?? sealJob)?.stages.find((item) => item.stage === name)
|
||||
|
||||
// F11: counts must belong to the snapshot this job actually used. A newly
|
||||
// sealed test version must not decorate an older sync/restore/verify job.
|
||||
@@ -1176,6 +1195,22 @@ function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onO
|
||||
{job?.recovery ? ` · 恢复:${job.recovery}` : ''}
|
||||
</p>
|
||||
<StageBar view={view} />
|
||||
{sealJob &&
|
||||
canReconcileCapture &&
|
||||
(sealJob.state === 'pending' || sealJob.state === 'running') &&
|
||||
stage('export')?.state === 'succeeded' ? (
|
||||
<div className="rel-between rel-progress-foot" aria-label="核对封存结果">
|
||||
<span>队列已完成、导出阶段已成功,但作业终态尚未回写。</span>
|
||||
<button
|
||||
type="button"
|
||||
className="rel-secondary"
|
||||
onClick={() => onReconcileCapture(sealJob.id)}
|
||||
disabled={pendingReconcileCapture === sealJob.id}
|
||||
>
|
||||
{pendingReconcileCapture === sealJob.id ? '核对中…' : '核对封存结果'}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="rel-between rel-progress-foot">
|
||||
<span>
|
||||
当前:
|
||||
@@ -1806,6 +1841,9 @@ export function ReleaseTargetsView(props: ViewProps) {
|
||||
pendingCapture,
|
||||
canCapture,
|
||||
canWrite,
|
||||
canReconcileCapture,
|
||||
pendingReconcileCapture,
|
||||
onReconcileCapture,
|
||||
sync,
|
||||
baseline,
|
||||
verification,
|
||||
@@ -2046,7 +2084,14 @@ export function ReleaseTargetsView(props: ViewProps) {
|
||||
/>
|
||||
|
||||
{active ? (
|
||||
<ProgressBody view={view} now={now} onOpen={() => onDrawer(true)} />
|
||||
<ProgressBody
|
||||
view={view}
|
||||
now={now}
|
||||
onOpen={() => onDrawer(true)}
|
||||
canReconcileCapture={canReconcileCapture}
|
||||
pendingReconcileCapture={pendingReconcileCapture}
|
||||
onReconcileCapture={onReconcileCapture}
|
||||
/>
|
||||
) : (
|
||||
<ReadyBody
|
||||
view={view}
|
||||
@@ -2117,6 +2162,7 @@ export function ReleaseTargets() {
|
||||
const [drawerOpen, setDrawerOpen] = useState(false)
|
||||
const [expandedSnapshot, setExpandedSnapshot] = useState<string | null>(null)
|
||||
const [pendingCapture, setPendingCapture] = useState(false)
|
||||
const [pendingReconcileCapture, setPendingReconcileCapture] = useState('')
|
||||
const [now, setNow] = useState(() => Date.now())
|
||||
|
||||
const load = useCallback(async (signal?: AbortSignal) => {
|
||||
@@ -2348,6 +2394,24 @@ export function ReleaseTargets() {
|
||||
}
|
||||
}
|
||||
|
||||
const reconcileCapture = async (jobID: string) => {
|
||||
setPendingReconcileCapture(jobID)
|
||||
setNotice(null)
|
||||
try {
|
||||
const result = await reconcileLibraryCapture(jobID)
|
||||
setNotice(
|
||||
result.already_succeeded
|
||||
? `封存作业 ${jobID} 已是成功终态,未重复写入`
|
||||
: `已核对封存结果:${jobID} → ${result.snapshot_id.slice(0, 12)}(审计 ${result.audit_operation_id ?? '已记录'})`
|
||||
)
|
||||
await load()
|
||||
} catch (reconcileError) {
|
||||
setNotice(reconcileError instanceof Error ? reconcileError.message : '核对封存结果失败')
|
||||
} finally {
|
||||
setPendingReconcileCapture('')
|
||||
}
|
||||
}
|
||||
|
||||
const recover = async (windowJobID: string) => {
|
||||
setNotice(null)
|
||||
try {
|
||||
@@ -2400,6 +2464,9 @@ export function ReleaseTargets() {
|
||||
pendingCapture={pendingCapture}
|
||||
canCapture={canCapture}
|
||||
canWrite={canWrite}
|
||||
canReconcileCapture={role === 'admin'}
|
||||
pendingReconcileCapture={pendingReconcileCapture}
|
||||
onReconcileCapture={(jobID) => void reconcileCapture(jobID)}
|
||||
sync={{
|
||||
canSign: canSignSync,
|
||||
pendingGrant: pendingSyncGrant,
|
||||
|
||||
@@ -385,6 +385,37 @@ export async function fetchLibraryCaptures(signal?: AbortSignal): Promise<Librar
|
||||
}))
|
||||
}
|
||||
|
||||
export interface LibraryCaptureReconcileResult {
|
||||
repaired: boolean
|
||||
already_succeeded: boolean
|
||||
job_id: string
|
||||
snapshot_id: string
|
||||
queue_job_id: string
|
||||
audit_operation_id?: string
|
||||
reason?: string
|
||||
}
|
||||
|
||||
/** 只按已完成 capture queue、精确 test_sealed 版本和归档复核修复终态。 */
|
||||
export async function reconcileLibraryCapture(id: string): Promise<LibraryCaptureReconcileResult> {
|
||||
const response = await fetch(`/api/v1/library/jobs/${encodeURIComponent(id)}/reconcile-capture`, {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json' },
|
||||
})
|
||||
const value = (await response.json().catch(() => null)) as unknown
|
||||
const body = record(value) ? value : {}
|
||||
if (!response.ok) {
|
||||
throw new Error(text(body.reason) || text(body.error) || `核对封存结果失败(HTTP ${response.status})`)
|
||||
}
|
||||
return {
|
||||
repaired: body.repaired === true,
|
||||
already_succeeded: body.already_succeeded === true,
|
||||
job_id: text(body.job_id),
|
||||
snapshot_id: text(body.snapshot_id),
|
||||
queue_job_id: text(body.queue_job_id),
|
||||
audit_operation_id: text(body.audit_operation_id),
|
||||
reason: text(body.reason),
|
||||
}
|
||||
}
|
||||
export function formatBytes(bytes: number): string {
|
||||
if (!Number.isFinite(bytes) || bytes <= 0) return '0 B'
|
||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||
|
||||
Reference in New Issue
Block a user