tableState 非 resources 分支恢复直接扫描 text 身份,避免 queryRows 把普通 doc id/UUID/复合键/数字 id 当 JSON canonical 校验而失败;resources 仍使用 F01 精确引用闭包。隔离 PG 覆盖字符串、UUID、复合键与数字 ID。 F11:快照 HTTP 投影补 bindings/wiki_log_entries;作业统计按本作业 target_snapshot_id/snapshot_id 取对应快照,取不到显示未知,不借最新封存; running/pending/failed/unknown 不再在无 detail 时显示完成。 F03:verifications 支持 snapshot_id 精确查询,返回 snapshot_latest 并只按 该快照回答 verified;抽屉“查看校验记录”按选中快照加载,不借用最新记录。 F08:显示主机探测时间;无真实 next-run 时说明尚未核验下一次执行;最近成功 单列未知,不以最近运行冒充。 验证:Go/前端全量、隔离 PG tableState/F01 对拍与 make verify 17 项通过。 实际 Current→Prepare→Verify ES 集成被共享 ES 磁盘 watermark 阻塞,未冒充。
This commit is contained in:
@@ -126,9 +126,20 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
<dt>备份脚本</dt>
|
||||
<dd>{scriptLine}</dd>
|
||||
<dt>主机 cron</dt>
|
||||
<dd>{schedule.host_cron_service ? `服务 ${schedule.host_cron_service}` : '—'}</dd>
|
||||
<dd>
|
||||
{schedule.host_cron_service ? `服务 ${schedule.host_cron_service}` : '—'}
|
||||
{schedule.host_checked_at
|
||||
? ` · 状态读取于 ${formatBackupMoment(schedule.host_checked_at)}`
|
||||
: ' · 状态读取时间未知'}
|
||||
</dd>
|
||||
<dt>下次计划(主机读回)</dt>
|
||||
<dd>{schedule.host_next_run || '未读取(不以历史下发时间推算)'}</dd>
|
||||
<dd>
|
||||
{schedule.host_next_run
|
||||
? schedule.host_next_run
|
||||
: schedule.host_schedule_enabled
|
||||
? `已配置每日 ${schedule.host_schedule_time};尚未核验下一次实际执行(不以历史下发时间推算)`
|
||||
: '未启用定时或未从主机读到计划'}
|
||||
</dd>
|
||||
<dt>最近一次运行</dt>
|
||||
<dd>
|
||||
{schedule.last_run_stamp || '—'}
|
||||
@@ -139,6 +150,8 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
: ' · 有失败/读取错误'
|
||||
: ''}
|
||||
</dd>
|
||||
<dt>最近一次成功</dt>
|
||||
<dd>未从主机读取(不能用最近一次运行代替成功;失败库/读取错误见下方)</dd>
|
||||
<dt>备份耗时 / 体积</dt>
|
||||
<dd>
|
||||
{schedule.last_run_stamp
|
||||
|
||||
@@ -680,6 +680,49 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
|
||||
expect(drawer).toContain('当前筛选下没有已登记版本')
|
||||
})
|
||||
|
||||
it('统计数据只取当前作业快照,并按真实阶段状态展示', () => {
|
||||
const jobSnapshot: LibrarySnapshot = {
|
||||
...internalSnapshot,
|
||||
snapshot_id: 'old-job-snapshot',
|
||||
totals: {
|
||||
documents: 4,
|
||||
chunks: 38,
|
||||
resources: 21,
|
||||
bindings: 4,
|
||||
wiki_pages: 31,
|
||||
wiki_folders: 21,
|
||||
wiki_log_entries: 11,
|
||||
},
|
||||
}
|
||||
const job: LibraryJobRecord = {
|
||||
...persistedSeal,
|
||||
id: 'libsync-old',
|
||||
kind: 'sync',
|
||||
target_snapshot_id: jobSnapshot.snapshot_id,
|
||||
stage: 'database',
|
||||
stages: [
|
||||
{
|
||||
stage: 'database',
|
||||
state: 'running',
|
||||
total: null,
|
||||
completed: null,
|
||||
bytes_total: null,
|
||||
bytes_done: null,
|
||||
detail: '',
|
||||
updated_at: '2026-11-05T01:00:00Z',
|
||||
},
|
||||
],
|
||||
}
|
||||
const html = render({
|
||||
page: { ...page, snapshots: [internalSnapshot, jobSnapshot] },
|
||||
overview: { ...overview, job, jobs: [job], test_sealed: internalSnapshot },
|
||||
})
|
||||
expect(html).toContain('文档 4 · 分块 38 · 资源 21 · 绑定 4')
|
||||
expect(html).toContain('页面 31 · 目录 21 · 日志 11')
|
||||
expect(html).toContain('执行中;执行器尚未提供该分项明细')
|
||||
expect(html).not.toContain('已完成 0 / 0')
|
||||
})
|
||||
|
||||
it('同步中布局显示四类数据卡与明细,且不编造百分比', () => {
|
||||
const html = render({
|
||||
jobs: [runningJob],
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
import { useOptionalAuth } from './auth'
|
||||
import './releaseTargets.css'
|
||||
import { RestoreVerificationSection } from './RestoreVerificationSection'
|
||||
import { fetchSnapshotVerification } from './restoreVerification'
|
||||
|
||||
// 发布管理:按已确认稿实现——顶部两个知识库页签,下面是**一个**作业区。
|
||||
//
|
||||
@@ -1064,9 +1065,20 @@ function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onO
|
||||
const running = job?.state === 'running' || job?.state === 'pending'
|
||||
const stage = (name: string) => dataJob?.stages.find((item) => item.stage === name)
|
||||
|
||||
const sealed = view.overview?.test_sealed
|
||||
// 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.
|
||||
const jobSnapshotID = job?.target_snapshot_id || job?.snapshot_id || ''
|
||||
const sealed = jobSnapshotID
|
||||
? view.history.find((item) => item.snapshot_id === jobSnapshotID)
|
||||
: job
|
||||
? undefined
|
||||
: view.overview?.test_sealed
|
||||
const breakdown = (keys: [string, string][]) =>
|
||||
sealed ? keys.map(([key, label]) => `${label} ${sealed.totals[key] ?? 0}`).join(' · ') : ''
|
||||
sealed
|
||||
? keys
|
||||
.map(([key, label]) => `${label} ${typeof sealed.totals[key] === 'number' ? sealed.totals[key] : '未知'}`)
|
||||
.join(' · ')
|
||||
: ''
|
||||
const cards = [
|
||||
// F11: these totals are storage rows, not business document/page counts.
|
||||
{
|
||||
@@ -1185,9 +1197,17 @@ function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onO
|
||||
{card.row?.detail
|
||||
? card.row.detail
|
||||
: card.row
|
||||
? card.row.total != null
|
||||
? `已完成 ${card.row.completed ?? card.row.total} / ${card.row.total} 条存储行`
|
||||
: '该分项已完成,执行器未提供可核对总量'
|
||||
? card.row.state === 'running'
|
||||
? '执行中;执行器尚未提供该分项明细'
|
||||
: card.row.state === 'pending'
|
||||
? '等待执行;不能按完成展示'
|
||||
: card.row.state === 'failed'
|
||||
? '失败;没有可核对完成量'
|
||||
: card.row.state === 'succeeded'
|
||||
? card.row.total != null
|
||||
? `已完成 ${card.row.completed ?? card.row.total} / ${card.row.total} 条存储行`
|
||||
: '该分项已完成,执行器未提供可核对总量'
|
||||
: '状态未知;不按完成展示'
|
||||
: dataJob
|
||||
? '本次作业没有产生该分项阶段记录'
|
||||
: '目标同步执行链未接通,分项不会产生数据'}
|
||||
@@ -1267,6 +1287,57 @@ function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onO
|
||||
)
|
||||
}
|
||||
|
||||
// F03: exact snapshot evidence. This component deliberately reads
|
||||
// snapshot_latest, not latest: a passed record for another snapshot must not
|
||||
// make this one look verified.
|
||||
function SnapshotVerification({ scope, snapshotID }: { scope: Scope; snapshotID: string }) {
|
||||
const [state, setState] = useState<'loading' | 'loaded' | 'error'>('loading')
|
||||
const [record, setRecord] = useState<Awaited<ReturnType<typeof fetchSnapshotVerification>>['snapshot_latest']>(null)
|
||||
const [error, setError] = useState('')
|
||||
useEffect(() => {
|
||||
const controller = new AbortController()
|
||||
setState('loading')
|
||||
setRecord(null)
|
||||
setError('')
|
||||
fetchSnapshotVerification(scope, snapshotID, controller.signal)
|
||||
.then((value) => {
|
||||
setRecord(value.snapshot_latest ?? null)
|
||||
setState('loaded')
|
||||
})
|
||||
.catch((reason: unknown) => {
|
||||
if ((reason as Error)?.name === 'AbortError') return
|
||||
setError(reason instanceof Error ? reason.message : '读取该快照的恢复验证记录失败')
|
||||
setState('error')
|
||||
})
|
||||
return () => controller.abort()
|
||||
}, [scope, snapshotID])
|
||||
return (
|
||||
<details className="rel-snapshot-verification">
|
||||
<summary>查看校验记录</summary>
|
||||
{state === 'loading' ? <p className="rel-hint">正在读取该快照的恢复验证记录…</p> : null}
|
||||
{state === 'error' ? <p className="rel-warn">{error}</p> : null}
|
||||
{state === 'loaded' && !record ? (
|
||||
<p className="rel-hint">该快照没有真实恢复验证记录;未验证,原因不是加载失败。</p>
|
||||
) : null}
|
||||
{record ? (
|
||||
<div>
|
||||
<p className="rel-hint">
|
||||
该快照最近一次:{record.status === 'passed' ? '通过' : '未通过'} · {record.finished_at} · 作业{' '}
|
||||
{record.job_id}
|
||||
</p>
|
||||
{record.failure ? <p className="rel-warn">原因:{record.failure}</p> : null}
|
||||
{record.report ? (
|
||||
<details>
|
||||
<summary>本次恢复验证报告</summary>
|
||||
<pre>{JSON.stringify(record.report, null, 2)}</pre>
|
||||
</details>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</details>
|
||||
)
|
||||
}
|
||||
|
||||
interface DrawerProps {
|
||||
view: ScopeView
|
||||
page: LibrarySnapshotList | null
|
||||
@@ -1534,9 +1605,7 @@ function Drawer({
|
||||
以上是同一恢复点的配套内容,不支持只选择 Wiki 或某张数据表恢复。恢复速度需实测;“有备份文件”不等于可恢复。
|
||||
</p>
|
||||
<div className="rel-drawer-actions">
|
||||
<button type="button" disabled title="逐项校验证据在同步/恢复执行时产生,作业详情里可见">
|
||||
查看校验记录
|
||||
</button>
|
||||
<SnapshotVerification scope={view.scope} snapshotID={selected.snapshot_id} />
|
||||
{canRestore && restore && restore.authorization.state !== 'active' ? (
|
||||
<button type="button" className="rel-secondary" onClick={onGrantRestore} disabled={pendingGrant}>
|
||||
{pendingGrant ? '签发中…' : '签发恢复授权(30 分钟)'}
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface BackupSchedule {
|
||||
host_schedule_time: string
|
||||
// 主机若没有返回真实 next-run,保持空串;页面不得用历史下发时间推算。
|
||||
host_next_run?: string
|
||||
host_checked_at?: string
|
||||
host_keep_days: number
|
||||
host_keep_months: number
|
||||
host_cron_lines: string[]
|
||||
@@ -80,6 +81,7 @@ function scheduleProjection(item: Record<string, unknown>): BackupSchedule {
|
||||
host_schedule_enabled: item.host_schedule_enabled === true,
|
||||
host_schedule_time: asString(item.host_schedule_time),
|
||||
host_next_run: asString(item.host_next_run),
|
||||
host_checked_at: asString(item.host_checked_at),
|
||||
host_keep_days: asNumber(item.host_keep_days),
|
||||
host_keep_months: asNumber(item.host_keep_months),
|
||||
host_cron_lines: asStringList(item.host_cron_lines),
|
||||
|
||||
@@ -33,6 +33,7 @@ export interface LibraryVerificationView {
|
||||
verified: boolean
|
||||
reason: string
|
||||
latest?: LibraryVerificationRecord | null
|
||||
snapshot_latest?: LibraryVerificationRecord | null
|
||||
history: LibraryVerificationRecord[]
|
||||
running?: boolean
|
||||
job_id?: string
|
||||
@@ -91,6 +92,7 @@ export function parseVerificationView(value: unknown): LibraryVerificationView |
|
||||
? value.history.map(parseVerificationRecord).filter((item): item is LibraryVerificationRecord => item !== null)
|
||||
: []
|
||||
const latest = parseVerificationRecord(value.latest) ?? null
|
||||
const snapshotLatest = parseVerificationRecord(value.snapshot_latest) ?? null
|
||||
return {
|
||||
scope: text(value.scope),
|
||||
target,
|
||||
@@ -98,6 +100,7 @@ export function parseVerificationView(value: unknown): LibraryVerificationView |
|
||||
verified: bool(value.verified),
|
||||
reason: text(value.reason),
|
||||
latest,
|
||||
snapshot_latest: snapshotLatest,
|
||||
history,
|
||||
running: bool(value.running),
|
||||
job_id: text(value.job_id) || undefined,
|
||||
@@ -109,6 +112,26 @@ export function parseVerificationView(value: unknown): LibraryVerificationView |
|
||||
// fetchLibraryVerification 只返回**这份 scope** 的观测:
|
||||
// HTTP 非 2xx、响应不可解析、或响应 scope 与请求不一致都抛错。
|
||||
// 调用方据此把"读失败"和"没有证据"分开显示,不能拿旧绿色遮住失败(审核 B5)。
|
||||
|
||||
// F03: exact snapshot report. Never fall back to the scope's latest record.
|
||||
export async function fetchSnapshotVerification(
|
||||
scope: string,
|
||||
snapshotID: string,
|
||||
signal?: AbortSignal
|
||||
): Promise<LibraryVerificationView> {
|
||||
const query = `scope=${encodeURIComponent(scope)}&snapshot_id=${encodeURIComponent(snapshotID)}`
|
||||
const response = await fetch(`/api/v1/library/verifications?${query}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
signal,
|
||||
})
|
||||
const value = (await response.json().catch(() => null)) as unknown
|
||||
if (!response.ok) throw new Error(`读取该快照的恢复验证记录失败(HTTP ${response.status})`)
|
||||
const parsed = parseVerificationView(value)
|
||||
if (!parsed) throw new Error('读取该快照的恢复验证记录失败:响应不可解析')
|
||||
if (parsed.scope !== scope) throw new Error('读取该快照的恢复验证记录失败:scope 不一致')
|
||||
return parsed
|
||||
}
|
||||
|
||||
export async function fetchLibraryVerification(scope: string, signal?: AbortSignal): Promise<LibraryVerificationView> {
|
||||
const response = await fetch(`/api/v1/library/verifications?scope=${encodeURIComponent(scope)}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
|
||||
Reference in New Issue
Block a user