feat(reconciliation): 前端导入对账工作台
为什么:T6b 需要把「解析监控」改成「导入对账」,让差异、证据、待确认与处置在同一页闭环,同时保留平台侧流水。 做什么:新增对账 API 客户端;差异清单(R1-R8、证据等级、待确认徽标、处置按钮);批次概览与队列状态条;平台侧流水页签沿用原表;详情抽屉实时读取 WeKnora 阶段与失败,503 降级;导航改名但保留 tasks 模块 id。 边界:只读角色不显示触发/处置;1440/1024/768 用现有表格滚动与新增响应式规则;不伪造 URL 路由。 验证:npx tsc --noEmit、npm test(646+)、npm run build、make verify 全绿。
This commit is contained in:
@@ -28,6 +28,7 @@ type MonitorTask struct {
|
|||||||
SourceName string `json:"source_name"`
|
SourceName string `json:"source_name"`
|
||||||
TargetScope string `json:"target_scope"`
|
TargetScope string `json:"target_scope"`
|
||||||
TargetKB string `json:"target_kb"`
|
TargetKB string `json:"target_kb"`
|
||||||
|
DocumentID string `json:"document_id"`
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
Stage string `json:"stage"`
|
Stage string `json:"stage"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
@@ -124,7 +125,7 @@ const monitorTasksCTE = `WITH history_publications AS (
|
|||||||
ELSE 'waiting' END AS stage
|
ELSE 'waiting' END AS stage
|
||||||
FROM base
|
FROM base
|
||||||
), projected AS (
|
), projected AS (
|
||||||
SELECT id,title,path,parent_node_id,node_id,source_id,source_name,target_scope,target_kb,version_id,retry_count,updated_at,action,stage,status,failure_id,
|
SELECT id,title,path,parent_node_id,node_id,source_id,source_name,target_scope,target_kb,knowledge_id AS document_id,version_id,retry_count,updated_at,action,stage,status,failure_id,
|
||||||
CASE WHEN status<>'attention' THEN ''
|
CASE WHEN status<>'attention' THEN ''
|
||||||
WHEN action='remove' THEN CASE WHEN job_type='test.remove' AND job_state='failed' AND retrieval_state IN ('failed','disabling') AND policy_state='blocked' THEN 'remove' ELSE '' END
|
WHEN action='remove' THEN CASE WHEN job_type='test.remove' AND job_state='failed' AND retrieval_state IN ('failed','disabling') AND policy_state='blocked' THEN 'remove' ELSE '' END
|
||||||
WHEN failure_type='artifact.fetch' THEN 'fetch'
|
WHEN failure_type='artifact.fetch' THEN 'fetch'
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ describe('WorkspaceShell', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(html).toContain('aria-label="功能导航"')
|
expect(html).toContain('aria-label="功能导航"')
|
||||||
for (const label of ['来源与目录', '解析监控', '发布管理', '系统设置']) {
|
for (const label of ['来源与目录', '导入对账', '发布管理', '系统设置']) {
|
||||||
expect(html).toContain(label)
|
expect(html).toContain(label)
|
||||||
}
|
}
|
||||||
expect(html).not.toContain('来源链接')
|
expect(html).not.toContain('来源链接')
|
||||||
@@ -66,10 +66,10 @@ describe('WorkspaceShell', () => {
|
|||||||
expect(html).not.toContain('class="tab-list"')
|
expect(html).not.toContain('class="tab-list"')
|
||||||
expect(html).not.toContain('class="workspace-tab')
|
expect(html).not.toContain('class="workspace-tab')
|
||||||
expect(html).toContain('来源与目录')
|
expect(html).toContain('来源与目录')
|
||||||
expect(html).toContain('解析监控')
|
expect(html).toContain('导入对账')
|
||||||
expect(html).toContain('发布管理')
|
expect(html).toContain('发布管理')
|
||||||
expect(html).toContain('aria-label="当前位置"')
|
expect(html).toContain('aria-label="当前位置"')
|
||||||
expect(html).toContain('<b>解析监控</b>')
|
expect(html).toContain('<b>导入对账</b>')
|
||||||
expect(html).toContain('class="nav-item active"')
|
expect(html).toContain('class="nav-item active"')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -60,7 +60,7 @@ const workspaceStorageKey = 'knowledge-governance.workspace.v1'
|
|||||||
|
|
||||||
const modules: ReadonlyArray<{ id: ModuleId; label: string; icon: string }> = [
|
const modules: ReadonlyArray<{ id: ModuleId; label: string; icon: string }> = [
|
||||||
{ id: 'dashboard', label: '来源与目录', icon: '◫' },
|
{ id: 'dashboard', label: '来源与目录', icon: '◫' },
|
||||||
{ id: 'tasks', label: '解析监控', icon: '↻' },
|
{ id: 'tasks', label: '导入对账', icon: '↻' },
|
||||||
{ id: 'qaops', label: '问答运营', icon: '▤' },
|
{ id: 'qaops', label: '问答运营', icon: '▤' },
|
||||||
{ id: 'releases', label: '发布管理', icon: '⇧' },
|
{ id: 'releases', label: '发布管理', icon: '⇧' },
|
||||||
{ id: 'settings', label: '系统设置', icon: '⚙' },
|
{ id: 'settings', label: '系统设置', icon: '⚙' },
|
||||||
@@ -1330,7 +1330,7 @@ function releaseGuidance(props: ReleaseManagementProps, pending: number) {
|
|||||||
step: 2,
|
step: 2,
|
||||||
title: '现在要做:确认测试结果',
|
title: '现在要做:确认测试结果',
|
||||||
reason: '暂时不能继续:目前没有可以审核的已通过知识',
|
reason: '暂时不能继续:目前没有可以审核的已通过知识',
|
||||||
action: '前往“解析监控”查看处理结果,并核对搜索效果',
|
action: '前往“导入对账”查看处理结果,并核对搜索效果',
|
||||||
after: '第 3 步,审核发布内容',
|
after: '第 3 步,审核发布内容',
|
||||||
impact: '只读查看,不会影响生产',
|
impact: '只读查看,不会影响生产',
|
||||||
href: '#review-actions',
|
href: '#review-actions',
|
||||||
@@ -1512,7 +1512,7 @@ export function ReleaseManagement(props: ReleaseManagementProps) {
|
|||||||
) : null}
|
) : null}
|
||||||
{!props.reviewLoading && publishReady.length === 0 ? (
|
{!props.reviewLoading && publishReady.length === 0 ? (
|
||||||
<div className="empty-state">
|
<div className="empty-state">
|
||||||
没有待发布的已批准知识。到「来源与目录」标注后,在「解析监控」处理完成即可发布。
|
没有待发布的已批准知识。到「来源与目录」标注后,在「导入对账」处理完成即可发布。
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
{publishReady.length > 0 ? (
|
{publishReady.length > 0 ? (
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import { renderToStaticMarkup } from 'react-dom/server'
|
||||||
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
|
import { ReconciliationFindingsView } from './ReconciliationFindings'
|
||||||
|
import type { ReconciliationFinding, ReconciliationRun } from './reconciliation'
|
||||||
|
|
||||||
|
const run: ReconciliationRun = {
|
||||||
|
id: 'run-1',
|
||||||
|
kb_id: 'kb-1',
|
||||||
|
state: 'succeeded',
|
||||||
|
trigger: 'manual',
|
||||||
|
started_at: '2026-12-01T02:00:00Z',
|
||||||
|
finished_at: '2026-12-01T02:01:00Z',
|
||||||
|
ledger_count: 12,
|
||||||
|
kb_count: 11,
|
||||||
|
counts: { R1: 1, R2: 0, R3: 2, R4: 0, R5: 0, R6: 0, R7: 0, R8: 0 },
|
||||||
|
previous_counts: { R1: 0, R2: 0, R3: 2, R4: 0, R5: 0, R6: 0, R7: 0, R8: 0 },
|
||||||
|
window_overlapped: true,
|
||||||
|
error_code: '',
|
||||||
|
}
|
||||||
|
const finding: ReconciliationFinding = {
|
||||||
|
id: 'f1',
|
||||||
|
run_id: 'run-1',
|
||||||
|
type: 'R1',
|
||||||
|
publication_id: 'pub-1',
|
||||||
|
document_id: 'doc-1',
|
||||||
|
title: '缺失文件.pdf',
|
||||||
|
path: '产品/缺失文件.pdf',
|
||||||
|
source: '技术资料',
|
||||||
|
target_scope: 'internal',
|
||||||
|
ledger_state: 'completed',
|
||||||
|
weknora_parse_status: '',
|
||||||
|
normalized_state: '',
|
||||||
|
ledger_sha256: '',
|
||||||
|
declared_sha256: '',
|
||||||
|
weknora_file_md5: '',
|
||||||
|
evidence_level: 'none',
|
||||||
|
confirmation_state: 'pending',
|
||||||
|
detail: '台账认为应在库,单条读取返回 404',
|
||||||
|
suggested_action: 'requeue_upload',
|
||||||
|
action_state: 'open',
|
||||||
|
weknora_url: '',
|
||||||
|
}
|
||||||
|
const props = {
|
||||||
|
overview: null,
|
||||||
|
runs: { items: [run], total: 1, limit: 20, offset: 0 },
|
||||||
|
findings: { items: [finding], total: 1, limit: 20, offset: 0 },
|
||||||
|
filters: { type: '', q: '' },
|
||||||
|
selectedRunID: 'run-1',
|
||||||
|
selectedKB: 'kb-1',
|
||||||
|
kbOptions: [{ id: 'kb-1', name: '测试知识库' }],
|
||||||
|
loading: false,
|
||||||
|
busy: false,
|
||||||
|
canOperate: true,
|
||||||
|
canRemove: true,
|
||||||
|
error: '',
|
||||||
|
message: '',
|
||||||
|
onTab: vi.fn(),
|
||||||
|
onSelectRun: vi.fn(),
|
||||||
|
onSelectKB: vi.fn(),
|
||||||
|
onFilters: vi.fn(),
|
||||||
|
onPage: vi.fn(),
|
||||||
|
onRefresh: vi.fn(),
|
||||||
|
onCreate: vi.fn(),
|
||||||
|
onAction: vi.fn(),
|
||||||
|
onDetail: vi.fn(),
|
||||||
|
}
|
||||||
|
describe('reconciliation findings', () => {
|
||||||
|
it('shows batch counts, pending confirmation, evidence and actions', () => {
|
||||||
|
const html = renderToStaticMarkup(<ReconciliationFindingsView {...props} />)
|
||||||
|
for (const text of [
|
||||||
|
'导入对账',
|
||||||
|
'差异清单',
|
||||||
|
'平台侧流水',
|
||||||
|
'立即对账',
|
||||||
|
'R1 丢失',
|
||||||
|
'待确认',
|
||||||
|
'无',
|
||||||
|
'重排上传',
|
||||||
|
'缺失文件.pdf',
|
||||||
|
])
|
||||||
|
expect(html).toContain(text)
|
||||||
|
expect(html).toContain('当前筛选 1 项')
|
||||||
|
expect(html).toContain('保留最近 30 批')
|
||||||
|
})
|
||||||
|
it('hides trigger and actions from a read-only role', () => {
|
||||||
|
const html = renderToStaticMarkup(<ReconciliationFindingsView {...props} canOperate={false} canRemove={false} />)
|
||||||
|
expect(html).not.toContain('立即对账')
|
||||||
|
expect(html).not.toContain('>重排上传</button>')
|
||||||
|
expect(html).toContain('只读角色')
|
||||||
|
})
|
||||||
|
it('renders loading, empty and error states', () => {
|
||||||
|
const loading = renderToStaticMarkup(
|
||||||
|
<ReconciliationFindingsView
|
||||||
|
{...props}
|
||||||
|
runs={{ items: [], total: 0, limit: 20, offset: 0 }}
|
||||||
|
findings={{ items: [], total: 0, limit: 20, offset: 0 }}
|
||||||
|
selectedRunID=""
|
||||||
|
loading={true}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
expect(loading).toContain('正在读取差异')
|
||||||
|
expect(loading).toContain('还没有对账批次')
|
||||||
|
const failed = renderToStaticMarkup(<ReconciliationFindingsView {...props} error="读取对账批次失败" />)
|
||||||
|
expect(failed).toContain('读取对账批次失败')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,444 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
import type { MonitorOverview } from './monitor'
|
||||||
|
import type {
|
||||||
|
ReconciliationFinding,
|
||||||
|
ReconciliationFindingPage,
|
||||||
|
ReconciliationFindingType,
|
||||||
|
ReconciliationProgress,
|
||||||
|
ReconciliationRunPage,
|
||||||
|
} from './reconciliation'
|
||||||
|
import { fetchReconciliationProgress, ReconciliationRequestError } from './reconciliation'
|
||||||
|
import './monitorWorkbench.css'
|
||||||
|
|
||||||
|
const time = (value: string | null | undefined) =>
|
||||||
|
value ? new Date(value).toLocaleString('zh-CN', { hour12: false }) : '—'
|
||||||
|
const typeLabels: Record<ReconciliationFindingType, string> = {
|
||||||
|
R1: 'R1 丢失',
|
||||||
|
R2: 'R2 孤儿',
|
||||||
|
R3: 'R3 非平台导入',
|
||||||
|
R4: 'R4 内容过期',
|
||||||
|
R5: 'R5 状态不一致',
|
||||||
|
R6: 'R6 应下架仍在',
|
||||||
|
R7: 'R7 卡住',
|
||||||
|
R8: 'R8 一对多',
|
||||||
|
}
|
||||||
|
const evidenceLabels = { independent: '独立证据', declared_only: '仅声明', none: '无' }
|
||||||
|
const actionLabels: Record<string, string> = {
|
||||||
|
requeue_upload: '重排上传',
|
||||||
|
remove_from_test: '从测试库移除',
|
||||||
|
writeback_state: '以 WeKnora 为准回写',
|
||||||
|
enter_removal: '进入需下架流程',
|
||||||
|
none: '不处置',
|
||||||
|
}
|
||||||
|
const countKeys = ['R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8']
|
||||||
|
|
||||||
|
export interface FindingFilters {
|
||||||
|
type: string
|
||||||
|
q: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FindingsProps {
|
||||||
|
overview: MonitorOverview | null
|
||||||
|
runs: ReconciliationRunPage
|
||||||
|
findings: ReconciliationFindingPage
|
||||||
|
filters: FindingFilters
|
||||||
|
selectedRunID: string
|
||||||
|
selectedKB: string
|
||||||
|
kbOptions: { id: string; name: string }[]
|
||||||
|
loading: boolean
|
||||||
|
busy: boolean
|
||||||
|
canOperate: boolean
|
||||||
|
canRemove: boolean
|
||||||
|
error: string
|
||||||
|
message: string
|
||||||
|
onTab: (tab: 'findings' | 'platform') => void
|
||||||
|
onSelectRun: (id: string) => void
|
||||||
|
onSelectKB: (id: string) => void
|
||||||
|
onFilters: (value: FindingFilters) => void
|
||||||
|
onPage: (offset: number) => void
|
||||||
|
onRefresh: () => void
|
||||||
|
onCreate: () => void
|
||||||
|
onAction: (finding: ReconciliationFinding) => void
|
||||||
|
onDetail: (finding: ReconciliationFinding) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ReconciliationFindingsView(p: FindingsProps) {
|
||||||
|
const run = p.runs.items.find((item) => item.id === p.selectedRunID) || p.runs.items[0] || null
|
||||||
|
const previous = run?.previous_counts || null
|
||||||
|
const pageCount = Math.max(1, Math.ceil(p.findings.total / p.findings.limit))
|
||||||
|
const queue = p.overview?.weknora_queues
|
||||||
|
return (
|
||||||
|
<main className="page-shell monitor-workbench">
|
||||||
|
<header className="monitor-heading page-header">
|
||||||
|
<div>
|
||||||
|
<h1 className="page-title">导入对账</h1>
|
||||||
|
<p className="page-subtitle">台账与测试 WeKnora 知识库的差异、证据与处置</p>
|
||||||
|
</div>
|
||||||
|
<span>{p.overview ? `快照 ${time(p.overview.observed_at)}` : '等待运行快照'}</span>
|
||||||
|
<button disabled={p.busy || p.loading} onClick={p.onRefresh}>
|
||||||
|
{p.loading ? '刷新中…' : '刷新'}
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
<nav className="monitor-tabs" aria-label="导入对账分区">
|
||||||
|
<button className="active" type="button" onClick={() => p.onTab('findings')}>
|
||||||
|
差异清单
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={() => p.onTab('platform')}>
|
||||||
|
平台侧流水
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
{p.error ? (
|
||||||
|
<div className="monitor-alert" role="alert">
|
||||||
|
{p.error}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<section className="monitor-service-strip" aria-label="服务与队列">
|
||||||
|
<span>
|
||||||
|
WeKnora 队列:
|
||||||
|
{queue ? (
|
||||||
|
<b>
|
||||||
|
{queue.queues.reduce((sum, item) => sum + item.pending, 0)} 等待 ·{' '}
|
||||||
|
{queue.queues.reduce((sum, item) => sum + item.active, 0)} 运行
|
||||||
|
</b>
|
||||||
|
) : (
|
||||||
|
<b className="monitor-muted">未配置只读 Key 或队列不可用</b>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
服务:<b>{p.overview?.health.filter((item) => item.readiness === 'ready').length ?? 0} 可接单</b>
|
||||||
|
</span>
|
||||||
|
<span className="monitor-muted">一期只对测试库;生产下架依赖测试移除 + 下一轮整库发布</span>
|
||||||
|
</section>
|
||||||
|
<section className="monitor-recon-overview" aria-label="最近一次对账">
|
||||||
|
<div className="monitor-recon-controls">
|
||||||
|
<label>
|
||||||
|
测试知识库
|
||||||
|
<select value={p.selectedKB} disabled={p.busy} onChange={(e) => p.onSelectKB(e.target.value)}>
|
||||||
|
<option value="">全部测试库</option>
|
||||||
|
{p.kbOptions.map((option) => (
|
||||||
|
<option key={option.id} value={option.id}>
|
||||||
|
{option.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
批次
|
||||||
|
<select
|
||||||
|
value={run?.id || ''}
|
||||||
|
disabled={p.busy || !p.runs.items.length}
|
||||||
|
onChange={(e) => p.onSelectRun(e.target.value)}
|
||||||
|
>
|
||||||
|
{p.runs.items.map((item) => (
|
||||||
|
<option key={item.id} value={item.id}>
|
||||||
|
{time(item.started_at)} · {item.state}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
{p.canOperate ? (
|
||||||
|
<button className="primary" disabled={p.busy || !p.selectedKB} onClick={p.onCreate}>
|
||||||
|
{p.busy ? '提交中…' : '立即对账'}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<span className="monitor-muted">只读角色:可查看差异,不能触发或处置</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{run ? (
|
||||||
|
<>
|
||||||
|
<p className="monitor-muted">
|
||||||
|
{time(run.started_at)} · {run.trigger === 'schedule' ? '定时' : '手动'} · 台账 {run.ledger_count} 条 ·
|
||||||
|
库内 {run.kb_count} 条{run.window_overlapped ? ' · 与整库作业重叠,R1/R2 待确认' : ''}
|
||||||
|
{run.error_code ? ` · 失败:${run.error_code}` : ''}
|
||||||
|
</p>
|
||||||
|
<div className="monitor-diff-counts">
|
||||||
|
{countKeys.map((key) => (
|
||||||
|
<span key={key} className={run.counts[key] ? 'has-diff' : ''}>
|
||||||
|
<b>{run.counts[key] ?? 0}</b>
|
||||||
|
<small>{key}</small>
|
||||||
|
{previous ? (
|
||||||
|
<em>
|
||||||
|
{run.counts[key] === previous[key]
|
||||||
|
? '持平'
|
||||||
|
: `${run.counts[key] > (previous[key] || 0) ? '+' : ''}${run.counts[key] - (previous[key] || 0)}`}
|
||||||
|
</em>
|
||||||
|
) : null}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<p className="monitor-muted">还没有对账批次。选择测试知识库后点「立即对账」。</p>
|
||||||
|
)}
|
||||||
|
{p.message ? (
|
||||||
|
<div className="monitor-result" role="status">
|
||||||
|
{p.message}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
<section className="monitor-files">
|
||||||
|
<div className="monitor-section-heading">
|
||||||
|
<div className="monitor-heading-group">
|
||||||
|
<h2>差异清单</h2>
|
||||||
|
<small className="monitor-scope-note">
|
||||||
|
当前筛选 {p.findings.total} 项 · 本页 {p.findings.items.length} 项
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
<span>明细保留最近 30 批且不超过 90 天</span>
|
||||||
|
</div>
|
||||||
|
<div className="monitor-filters">
|
||||||
|
<input
|
||||||
|
aria-label="搜索差异文件或说明"
|
||||||
|
placeholder="搜索文件名称、目录或说明"
|
||||||
|
value={p.filters.q}
|
||||||
|
disabled={p.busy}
|
||||||
|
onChange={(e) => p.onFilters({ ...p.filters, q: e.target.value })}
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
aria-label="差异类型"
|
||||||
|
value={p.filters.type}
|
||||||
|
disabled={p.busy}
|
||||||
|
onChange={(e) => p.onFilters({ ...p.filters, type: e.target.value })}
|
||||||
|
>
|
||||||
|
<option value="">全部类型</option>
|
||||||
|
{Object.entries(typeLabels).map(([key, label]) => (
|
||||||
|
<option key={key} value={key}>
|
||||||
|
{label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
className="monitor-link"
|
||||||
|
disabled={p.busy || (!p.filters.q && !p.filters.type)}
|
||||||
|
onClick={() => p.onFilters({ type: '', q: '' })}
|
||||||
|
>
|
||||||
|
清除筛选
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="monitor-table-scroll" aria-busy={p.loading}>
|
||||||
|
<table className="monitor-unified-table monitor-finding-table">
|
||||||
|
<colgroup>
|
||||||
|
<col style={{ width: '9%' }} />
|
||||||
|
<col style={{ width: '22%' }} />
|
||||||
|
<col style={{ width: '10%' }} />
|
||||||
|
<col style={{ width: '13%' }} />
|
||||||
|
<col style={{ width: '13%' }} />
|
||||||
|
<col style={{ width: '9%' }} />
|
||||||
|
<col style={{ width: '16%' }} />
|
||||||
|
<col style={{ width: '8%' }} />
|
||||||
|
</colgroup>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>类型</th>
|
||||||
|
<th>文件名称 / 目录</th>
|
||||||
|
<th>来源</th>
|
||||||
|
<th>台账 / WeKnora</th>
|
||||||
|
<th>证据 / 建议</th>
|
||||||
|
<th>确认</th>
|
||||||
|
<th>说明</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{p.findings.items.map((finding) => (
|
||||||
|
<tr key={finding.id}>
|
||||||
|
<td>
|
||||||
|
<span className={`monitor-finding-type ${finding.type.toLowerCase()}`}>
|
||||||
|
{typeLabels[finding.type]}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b className="monitor-file-name">{finding.title || '未命名文件'}</b>
|
||||||
|
<small title={finding.path}>{finding.path || '未提供目录'}</small>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span className="monitor-clamp">{finding.source || '—'}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<small>
|
||||||
|
台账 {finding.ledger_state || '—'} → WeKnora {finding.normalized_state || '—'}
|
||||||
|
</small>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<small>{evidenceLabels[finding.evidence_level]}</small>
|
||||||
|
<small>{actionLabels[finding.suggested_action]}</small>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{finding.confirmation_state === 'pending' ? (
|
||||||
|
<span className="monitor-badge-pending">待确认</span>
|
||||||
|
) : (
|
||||||
|
<span className="monitor-muted">已确认</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="monitor-detail-cell" title={finding.detail}>
|
||||||
|
{finding.detail}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button className="monitor-link" onClick={() => p.onDetail(finding)}>
|
||||||
|
详情
|
||||||
|
</button>
|
||||||
|
{p.canOperate && finding.action_state === 'open' && finding.suggested_action !== 'none' ? (
|
||||||
|
<button
|
||||||
|
className="monitor-link"
|
||||||
|
disabled={p.busy || (finding.suggested_action === 'remove_from_test' && !p.canRemove)}
|
||||||
|
onClick={() => p.onAction(finding)}
|
||||||
|
>
|
||||||
|
{actionLabels[finding.suggested_action]}
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
{finding.action_state === 'done' ? <span className="monitor-muted">已处置</span> : null}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{!p.findings.items.length ? (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={8} className="monitor-empty">
|
||||||
|
{p.loading ? '正在读取差异…' : run ? '该批次没有差异。' : '先选择一个对账批次。'}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : null}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<footer className="monitor-pagination">
|
||||||
|
<span>
|
||||||
|
当前筛选共 {p.findings.total} 项 · 每页 {p.findings.limit} 项
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
disabled={p.busy || p.loading || p.findings.offset === 0}
|
||||||
|
onClick={() => p.onPage(Math.max(0, p.findings.offset - p.findings.limit))}
|
||||||
|
>
|
||||||
|
上一页
|
||||||
|
</button>
|
||||||
|
<span>
|
||||||
|
第 {Math.floor(p.findings.offset / p.findings.limit) + 1} / {pageCount} 页
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
disabled={p.busy || p.loading || p.findings.offset + p.findings.limit >= p.findings.total}
|
||||||
|
onClick={() => p.onPage(p.findings.offset + p.findings.limit)}
|
||||||
|
>
|
||||||
|
下一页
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function WeKnoraProgress({ documentID, compact = false }: { documentID: string; compact?: boolean }) {
|
||||||
|
const [progress, setProgress] = useState<ReconciliationProgress | null>(null)
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
useEffect(() => {
|
||||||
|
if (!documentID) {
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const controller = new AbortController()
|
||||||
|
setLoading(true)
|
||||||
|
setError('')
|
||||||
|
void fetchReconciliationProgress(documentID, controller.signal)
|
||||||
|
.then((value) => {
|
||||||
|
if (!controller.signal.aborted) setProgress(value)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (controller.signal.aborted) return
|
||||||
|
setProgress(null)
|
||||||
|
if (err instanceof ReconciliationRequestError && err.code === 'runtime_read_unavailable') {
|
||||||
|
setError('未配置 WeKnora 只读 Key,无法读取实时处理详情。')
|
||||||
|
} else {
|
||||||
|
setError(err instanceof Error ? err.message : '读取 WeKnora 处理详情失败')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
if (!controller.signal.aborted) setLoading(false)
|
||||||
|
})
|
||||||
|
return () => controller.abort()
|
||||||
|
}, [documentID])
|
||||||
|
return (
|
||||||
|
<section className={compact ? 'monitor-progress compact' : 'monitor-progress'}>
|
||||||
|
<div className="monitor-section-heading">
|
||||||
|
<h3>WeKnora 处理详情</h3>
|
||||||
|
<small>实时读取,不落库</small>
|
||||||
|
</div>
|
||||||
|
{loading ? <p className="monitor-muted">正在读取…</p> : null}
|
||||||
|
{error ? <p className="monitor-alert">{error}</p> : null}
|
||||||
|
{progress ? (
|
||||||
|
<>
|
||||||
|
<p className="monitor-muted">
|
||||||
|
{progress.parse_status || '—'} · 入库 {progress.ingestion_status || '—'} · Wiki{' '}
|
||||||
|
{progress.wiki_status || '—'} · 读取 {time(progress.observed_at)}
|
||||||
|
</p>
|
||||||
|
{progress.stages.length ? (
|
||||||
|
<ol className="monitor-stages">
|
||||||
|
{progress.stages.map((stage) => (
|
||||||
|
<li key={`${stage.name}-${stage.status}`}>
|
||||||
|
<b>{stage.name}</b> {stage.status}
|
||||||
|
{stage.error_code ? ` · ${stage.error_code}` : ''}
|
||||||
|
{stage.finished_at ? ` · ${time(stage.finished_at)}` : ''}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ol>
|
||||||
|
) : (
|
||||||
|
<p className="monitor-muted">还没有阶段记录。</p>
|
||||||
|
)}
|
||||||
|
{progress.failures.length ? (
|
||||||
|
<div className="monitor-failures">
|
||||||
|
<b>历史失败</b>
|
||||||
|
{progress.failures.map((failure) => (
|
||||||
|
<p key={`${failure.task_type}-${failure.failed_at}`}>
|
||||||
|
{failure.task_type} · 尝试 {failure.fail_count} · {time(failure.failed_at)} · {failure.last_error}
|
||||||
|
</p>
|
||||||
|
))}
|
||||||
|
{progress.has_more_failures ? <small>仅显示最近 50 条失败。</small> : null}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FindingDetail({ finding, onClose }: { finding: ReconciliationFinding; onClose: () => void }) {
|
||||||
|
const ref = useRef<HTMLDialogElement>(null)
|
||||||
|
useEffect(() => {
|
||||||
|
ref.current?.showModal()
|
||||||
|
}, [])
|
||||||
|
return (
|
||||||
|
<dialog className="monitor-drawer" ref={ref} onCancel={onClose}>
|
||||||
|
<header>
|
||||||
|
<h2>{typeLabels[finding.type]} · 处理详情</h2>
|
||||||
|
<button onClick={onClose} autoFocus>
|
||||||
|
关闭
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
<h3>{finding.title || '未命名文件'}</h3>
|
||||||
|
<dl>
|
||||||
|
{[
|
||||||
|
['目录', finding.path],
|
||||||
|
['来源', finding.source],
|
||||||
|
['发布标识', finding.publication_id],
|
||||||
|
['远端文档', finding.document_id],
|
||||||
|
['台账状态', finding.ledger_state],
|
||||||
|
['WeKnora 状态', finding.weknora_parse_status],
|
||||||
|
['归一状态', finding.normalized_state],
|
||||||
|
['台账 SHA256', finding.ledger_sha256],
|
||||||
|
['声明 SHA256', finding.declared_sha256],
|
||||||
|
['WeKnora MD5', finding.weknora_file_md5],
|
||||||
|
['证据等级', evidenceLabels[finding.evidence_level]],
|
||||||
|
['确认状态', finding.confirmation_state === 'pending' ? '待确认' : '已确认'],
|
||||||
|
['处置建议', actionLabels[finding.suggested_action]],
|
||||||
|
['说明', finding.detail],
|
||||||
|
].map(([label, value]) => (
|
||||||
|
<div key={label}>
|
||||||
|
<dt>{label}</dt>
|
||||||
|
<dd>{value || '—'}</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
{finding.document_id ? <WeKnoraProgress documentID={finding.document_id} compact /> : null}
|
||||||
|
</dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
// @vitest-environment jsdom
|
||||||
|
import { act } from 'react'
|
||||||
|
import { createRoot } from 'react-dom/client'
|
||||||
|
import type { Root } from 'react-dom/client'
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import { WeKnoraProgress } from './ReconciliationFindings'
|
||||||
|
|
||||||
|
let container: HTMLDivElement
|
||||||
|
let root: Root
|
||||||
|
beforeEach(() => {
|
||||||
|
;(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
||||||
|
container = document.createElement('div')
|
||||||
|
document.body.appendChild(container)
|
||||||
|
root = createRoot(container)
|
||||||
|
})
|
||||||
|
afterEach(() => {
|
||||||
|
act(() => root.unmount())
|
||||||
|
container.remove()
|
||||||
|
vi.unstubAllGlobals()
|
||||||
|
})
|
||||||
|
describe('WeKnora progress drawer block', () => {
|
||||||
|
it('degrades to a read-only key message on 503', async () => {
|
||||||
|
vi.stubGlobal(
|
||||||
|
'fetch',
|
||||||
|
vi.fn().mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({ error: 'runtime_read_unavailable', code: 'runtime_read_unavailable' }), {
|
||||||
|
status: 503,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await act(async () => root.render(<WeKnoraProgress documentID="doc-1" />))
|
||||||
|
await act(async () => await Promise.resolve())
|
||||||
|
expect(container.textContent).toContain('未配置 WeKnora 只读 Key')
|
||||||
|
})
|
||||||
|
it('shows stages and failures when available', async () => {
|
||||||
|
vi.stubGlobal(
|
||||||
|
'fetch',
|
||||||
|
vi.fn().mockResolvedValue(
|
||||||
|
new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
data: {
|
||||||
|
document_id: 'doc-1',
|
||||||
|
parse_status: 'failed',
|
||||||
|
ingestion_status: 'failed',
|
||||||
|
wiki_status: 'none',
|
||||||
|
stages: [{ name: 'parse', status: 'failed', error_code: 'E1', finished_at: '2026-12-01T00:00:00Z' }],
|
||||||
|
failures: [
|
||||||
|
{ task_type: 'parse', fail_count: 2, failed_at: '2026-12-01T00:00:00Z', last_error: '解析失败' },
|
||||||
|
],
|
||||||
|
has_more_failures: false,
|
||||||
|
observed_at: '2026-12-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{ status: 200 }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await act(async () => root.render(<WeKnoraProgress documentID="doc-1" />))
|
||||||
|
await act(async () => await Promise.resolve())
|
||||||
|
expect(container.textContent).toContain('parse')
|
||||||
|
expect(container.textContent).toContain('解析失败')
|
||||||
|
expect(container.textContent).toContain('failed')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -15,6 +15,7 @@ const page: MonitorTaskPage = {
|
|||||||
source_name: '技术资料',
|
source_name: '技术资料',
|
||||||
target_scope: 'internal',
|
target_scope: 'internal',
|
||||||
target_kb: 'test-kb',
|
target_kb: 'test-kb',
|
||||||
|
document_id: 'doc-1',
|
||||||
action: 'update',
|
action: 'update',
|
||||||
stage: 'parsing',
|
stage: 'parsing',
|
||||||
status: 'attention',
|
status: 'attention',
|
||||||
@@ -35,6 +36,7 @@ const page: MonitorTaskPage = {
|
|||||||
source_name: '技术资料',
|
source_name: '技术资料',
|
||||||
target_scope: 'external',
|
target_scope: 'external',
|
||||||
target_kb: 'test-public',
|
target_kb: 'test-public',
|
||||||
|
document_id: 'doc-2',
|
||||||
action: 'remove',
|
action: 'remove',
|
||||||
stage: 'finished',
|
stage: 'finished',
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
@@ -65,6 +67,8 @@ const props = {
|
|||||||
selected: [],
|
selected: [],
|
||||||
busy: false,
|
busy: false,
|
||||||
canOperate: true,
|
canOperate: true,
|
||||||
|
tab: 'platform' as const,
|
||||||
|
onTab: vi.fn(),
|
||||||
onFilters: vi.fn(),
|
onFilters: vi.fn(),
|
||||||
onPage: vi.fn(),
|
onPage: vi.fn(),
|
||||||
onSelection: vi.fn(),
|
onSelection: vi.fn(),
|
||||||
|
|||||||
+223
-37
@@ -11,12 +11,25 @@ import {
|
|||||||
targetLabel,
|
targetLabel,
|
||||||
} from './monitorTasks'
|
} from './monitorTasks'
|
||||||
import type { MonitorFilters, MonitorTask, MonitorTaskPage } from './monitorTasks'
|
import type { MonitorFilters, MonitorTask, MonitorTaskPage } from './monitorTasks'
|
||||||
import { requeueJobFailure, retryPublicationsBatch } from './testPublications'
|
import { requeueJobFailure, retryPublicationsBatch, startPublicationRemoval } from './testPublications'
|
||||||
import { fetchActiveUISettings, settingsRefreshDelays } from './uiSettings'
|
import { fetchActiveUISettings, settingsRefreshDelays } from './uiSettings'
|
||||||
import { useOptionalAuth } from './auth'
|
import { useOptionalAuth } from './auth'
|
||||||
import { WorkspaceContextTabsSetter } from './workspaceContext'
|
import { WorkspaceContextTabsSetter } from './workspaceContext'
|
||||||
|
import { ReconciliationFindingsView, FindingDetail, WeKnoraProgress } from './ReconciliationFindings'
|
||||||
|
import type { FindingFilters } from './ReconciliationFindings'
|
||||||
|
import {
|
||||||
|
createReconciliationRun,
|
||||||
|
fetchReconciliationFindings,
|
||||||
|
fetchReconciliationRuns,
|
||||||
|
removeFinding,
|
||||||
|
requeueFinding,
|
||||||
|
writebackFinding,
|
||||||
|
} from './reconciliation'
|
||||||
|
import type { ReconciliationFinding, ReconciliationFindingPage, ReconciliationRunPage } from './reconciliation'
|
||||||
import './monitorWorkbench.css'
|
import './monitorWorkbench.css'
|
||||||
|
|
||||||
|
const emptyRuns: ReconciliationRunPage = { items: [], total: 0, limit: 20, offset: 0 }
|
||||||
|
const emptyFindings: ReconciliationFindingPage = { items: [], total: 0, limit: 20, offset: 0 }
|
||||||
const emptyPage: MonitorTaskPage = {
|
const emptyPage: MonitorTaskPage = {
|
||||||
items: [],
|
items: [],
|
||||||
total: 0,
|
total: 0,
|
||||||
@@ -54,6 +67,10 @@ interface ViewProps {
|
|||||||
error: string
|
error: string
|
||||||
message: string
|
message: string
|
||||||
canOperate: boolean
|
canOperate: boolean
|
||||||
|
tab: 'findings' | 'platform'
|
||||||
|
onTab: (tab: 'findings' | 'platform') => void
|
||||||
|
title?: string
|
||||||
|
subtitle?: string
|
||||||
onFilters: (value: MonitorFilters) => void
|
onFilters: (value: MonitorFilters) => void
|
||||||
onPage: (offset: number) => void
|
onPage: (offset: number) => void
|
||||||
onSelection: (rows: MonitorTask[]) => void
|
onSelection: (rows: MonitorTask[]) => void
|
||||||
@@ -83,14 +100,22 @@ export function WeKnoraMonitorView(p: ViewProps) {
|
|||||||
<main className="page-shell monitor-workbench">
|
<main className="page-shell monitor-workbench">
|
||||||
<header className="monitor-heading page-header">
|
<header className="monitor-heading page-header">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="page-title">解析监控</h1>
|
<h1 className="page-title">{p.title || '平台侧流水'}</h1>
|
||||||
<p className="page-subtitle">运行概况与文件处理进度</p>
|
<p className="page-subtitle">{p.subtitle || '上传、解析、移除与重试记录;不按对账口径过滤被顶替行'}</p>
|
||||||
</div>
|
</div>
|
||||||
<span>{overview ? `快照 ${time(overview.observed_at)}` : '等待运行快照'}</span>
|
<span>{overview ? `快照 ${time(overview.observed_at)}` : '等待运行快照'}</span>
|
||||||
<button disabled={busy || loading} onClick={p.onRefresh}>
|
<button disabled={busy || loading} onClick={p.onRefresh}>
|
||||||
{loading ? '刷新中…' : '刷新'}
|
{loading ? '刷新中…' : '刷新'}
|
||||||
</button>
|
</button>
|
||||||
</header>
|
</header>
|
||||||
|
<nav className="monitor-tabs" aria-label="导入对账分区">
|
||||||
|
<button type="button" onClick={() => p.onTab('findings')}>
|
||||||
|
差异清单
|
||||||
|
</button>
|
||||||
|
<button className="active" type="button" onClick={() => p.onTab('platform')}>
|
||||||
|
平台侧流水
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
{p.error ? (
|
{p.error ? (
|
||||||
<div className="monitor-alert" role="alert">
|
<div className="monitor-alert" role="alert">
|
||||||
{p.error}
|
{p.error}
|
||||||
@@ -580,6 +605,7 @@ function TaskDetail({
|
|||||||
))}
|
))}
|
||||||
</section>
|
</section>
|
||||||
) : null}
|
) : null}
|
||||||
|
{item.document_id ? <WeKnoraProgress documentID={item.document_id} compact /> : null}
|
||||||
<p className="monitor-muted">新增、更新完成表示测试库处理完成;移除完成表示测试库内容移除,不代表生产发布。</p>
|
<p className="monitor-muted">新增、更新完成表示测试库处理完成;移除完成表示测试库内容移除,不代表生产发布。</p>
|
||||||
{item.status === 'attention' ? (
|
{item.status === 'attention' ? (
|
||||||
<p className="monitor-alert">
|
<p className="monitor-alert">
|
||||||
@@ -601,6 +627,20 @@ export function WeKnoraMonitor({
|
|||||||
} = {}) {
|
} = {}) {
|
||||||
const auth = useOptionalAuth()
|
const auth = useOptionalAuth()
|
||||||
const canOperate = auth?.identity?.role === 'admin' || auth?.identity?.role === 'engineer'
|
const canOperate = auth?.identity?.role === 'admin' || auth?.identity?.role === 'engineer'
|
||||||
|
const canRemove = auth?.identity?.role === 'admin'
|
||||||
|
const [tab, setTab] = useState<'findings' | 'platform'>(focus ? 'platform' : 'findings')
|
||||||
|
const [runs, setRuns] = useState<ReconciliationRunPage>(emptyRuns)
|
||||||
|
const [selectedRunID, setSelectedRunID] = useState('')
|
||||||
|
const [findings, setFindings] = useState<ReconciliationFindingPage>(emptyFindings)
|
||||||
|
const [findingFilters, setFindingFilters] = useState<FindingFilters>({ type: '', q: '' })
|
||||||
|
const [findingOffset, setFindingOffset] = useState(0)
|
||||||
|
const [selectedKB, setSelectedKB] = useState('')
|
||||||
|
const [findingDetail, setFindingDetail] = useState<ReconciliationFinding | null>(null)
|
||||||
|
const [reconLoading, setReconLoading] = useState(true)
|
||||||
|
const [reconBusy, setReconBusy] = useState(false)
|
||||||
|
const [reconError, setReconError] = useState('')
|
||||||
|
const [reconMessage, setReconMessage] = useState('')
|
||||||
|
const [reconRev, setReconRev] = useState(0)
|
||||||
const [overview, setOverview] = useState<MonitorOverview | null>(null),
|
const [overview, setOverview] = useState<MonitorOverview | null>(null),
|
||||||
[metrics, setMetrics] = useState<RunMetrics | null>(null)
|
[metrics, setMetrics] = useState<RunMetrics | null>(null)
|
||||||
const [page, setPage] = useState(emptyPage),
|
const [page, setPage] = useState(emptyPage),
|
||||||
@@ -624,6 +664,7 @@ export function WeKnoraMonitor({
|
|||||||
// 会遮蔽已完成文件的筛选;应用后由父消费掉,避免重挂载时旧请求再次覆盖手工筛选。
|
// 会遮蔽已完成文件的筛选;应用后由父消费掉,避免重挂载时旧请求再次覆盖手工筛选。
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!focus) return
|
if (!focus) return
|
||||||
|
setTab('platform')
|
||||||
setFilters({ ...defaultMonitorFilters, q: focus.q, source: focus.source, status: '' })
|
setFilters({ ...defaultMonitorFilters, q: focus.q, source: focus.source, status: '' })
|
||||||
setOffset(0)
|
setOffset(0)
|
||||||
setSelected([])
|
setSelected([])
|
||||||
@@ -649,6 +690,10 @@ export function WeKnoraMonitor({
|
|||||||
return () => clearTimeout(t)
|
return () => clearTimeout(t)
|
||||||
}, [resRev, delays.resourceMs])
|
}, [resRev, delays.resourceMs])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (tab !== 'platform') {
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
const c = new AbortController()
|
const c = new AbortController()
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const timer = window.setTimeout(() => {
|
const timer = window.setTimeout(() => {
|
||||||
@@ -678,7 +723,7 @@ export function WeKnoraMonitor({
|
|||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
c.abort()
|
c.abort()
|
||||||
}
|
}
|
||||||
}, [filters, offset, docRev])
|
}, [tab, filters, offset, docRev])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const c = new AbortController()
|
const c = new AbortController()
|
||||||
void fetchMonitorOverview(c.signal)
|
void fetchMonitorOverview(c.signal)
|
||||||
@@ -709,9 +754,110 @@ export function WeKnoraMonitor({
|
|||||||
})
|
})
|
||||||
return () => c.abort()
|
return () => c.abort()
|
||||||
}, [resRev])
|
}, [resRev])
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedKB || !overview?.knowledge_bases.length) return
|
||||||
|
setSelectedKB(overview.knowledge_bases[0].id)
|
||||||
|
}, [overview, selectedKB])
|
||||||
|
useEffect(() => {
|
||||||
|
if (tab !== 'findings') return
|
||||||
|
const c = new AbortController()
|
||||||
|
setReconLoading(true)
|
||||||
|
void fetchReconciliationRuns(20, 0, selectedKB, c.signal)
|
||||||
|
.then((page) => {
|
||||||
|
if (c.signal.aborted) return
|
||||||
|
setRuns(page)
|
||||||
|
setReconError('')
|
||||||
|
const current = page.items.find((item) => item.id === selectedRunID)
|
||||||
|
if (!current && page.items[0]) setSelectedRunID(page.items[0].id)
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
if (!c.signal.aborted) {
|
||||||
|
setRuns(emptyRuns)
|
||||||
|
setReconError(e instanceof Error ? e.message : '读取对账批次失败')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
if (!c.signal.aborted) setReconLoading(false)
|
||||||
|
})
|
||||||
|
return () => c.abort()
|
||||||
|
}, [tab, selectedKB, reconRev, selectedRunID])
|
||||||
|
useEffect(() => {
|
||||||
|
if (tab !== 'findings' || !selectedRunID) {
|
||||||
|
setFindings(emptyFindings)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const c = new AbortController()
|
||||||
|
setReconLoading(true)
|
||||||
|
void fetchReconciliationFindings(selectedRunID, findingFilters.type, findingFilters.q, 20, findingOffset, c.signal)
|
||||||
|
.then((page) => {
|
||||||
|
if (!c.signal.aborted) {
|
||||||
|
setFindings(page)
|
||||||
|
setReconError('')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
if (!c.signal.aborted) {
|
||||||
|
setFindings(emptyFindings)
|
||||||
|
setReconError(e instanceof Error ? e.message : '读取差异清单失败')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
if (!c.signal.aborted) setReconLoading(false)
|
||||||
|
})
|
||||||
|
return () => c.abort()
|
||||||
|
}, [tab, selectedRunID, findingFilters, findingOffset, reconRev])
|
||||||
|
const createRun = async () => {
|
||||||
|
if (reconBusy) return
|
||||||
|
const kbID = selectedKB || overview?.knowledge_bases[0]?.id || ''
|
||||||
|
if (!kbID) {
|
||||||
|
setReconMessage('请先选择测试知识库')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setReconBusy(true)
|
||||||
|
setReconMessage('')
|
||||||
|
try {
|
||||||
|
const run = await createReconciliationRun(kbID)
|
||||||
|
setSelectedRunID(run.id)
|
||||||
|
setReconMessage('已提交对账;扫描在后台执行,完成后刷新可见。')
|
||||||
|
setReconRev((x) => x + 1)
|
||||||
|
} catch (e) {
|
||||||
|
setReconMessage(e instanceof Error ? e.message : '触发对账失败')
|
||||||
|
} finally {
|
||||||
|
setReconBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const actOnFinding = async (finding: ReconciliationFinding) => {
|
||||||
|
if (reconBusy) return
|
||||||
|
if (
|
||||||
|
finding.suggested_action === 'remove_from_test' &&
|
||||||
|
!window.confirm('从测试库删除该孤儿条目?不会删除来源文件或生产内容。')
|
||||||
|
)
|
||||||
|
return
|
||||||
|
setReconBusy(true)
|
||||||
|
setReconMessage('')
|
||||||
|
try {
|
||||||
|
if (finding.suggested_action === 'enter_removal') {
|
||||||
|
if (!finding.publication_id) throw new Error('缺少发布标识,无法进入移除流程')
|
||||||
|
await startPublicationRemoval(finding.publication_id)
|
||||||
|
} else if (finding.suggested_action === 'writeback_state') {
|
||||||
|
await writebackFinding(finding.id)
|
||||||
|
} else if (finding.suggested_action === 'requeue_upload') {
|
||||||
|
await requeueFinding(finding.id)
|
||||||
|
} else if (finding.suggested_action === 'remove_from_test') {
|
||||||
|
await removeFinding(finding.id)
|
||||||
|
}
|
||||||
|
setReconMessage('处置已受理;状态以服务端读回为准。')
|
||||||
|
setReconRev((x) => x + 1)
|
||||||
|
} catch (e) {
|
||||||
|
setReconMessage(e instanceof Error ? e.message : '处置失败')
|
||||||
|
} finally {
|
||||||
|
setReconBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
const refresh = () => {
|
const refresh = () => {
|
||||||
setDocRev((x) => x + 1)
|
setDocRev((x) => x + 1)
|
||||||
setResRev((x) => x + 1)
|
setResRev((x) => x + 1)
|
||||||
|
setReconRev((x) => x + 1)
|
||||||
}
|
}
|
||||||
const selectAll = async () => {
|
const selectAll = async () => {
|
||||||
if (busy) return
|
if (busy) return
|
||||||
@@ -796,40 +942,80 @@ export function WeKnoraMonitor({
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WeKnoraMonitorView
|
{tab === 'findings' ? (
|
||||||
overview={overview}
|
<ReconciliationFindingsView
|
||||||
metrics={metrics}
|
overview={overview}
|
||||||
page={page}
|
runs={runs}
|
||||||
filters={filters}
|
findings={findings}
|
||||||
selected={selected}
|
filters={findingFilters}
|
||||||
loading={loading}
|
selectedRunID={selectedRunID}
|
||||||
busy={busy}
|
selectedKB={selectedKB}
|
||||||
error={Object.values(errors).filter(Boolean).join(';')}
|
kbOptions={(overview?.knowledge_bases || []).map((item) => ({ id: item.id, name: item.name }))}
|
||||||
message={message}
|
loading={reconLoading}
|
||||||
canOperate={canOperate}
|
busy={reconBusy}
|
||||||
onFilters={(v) => {
|
canOperate={canOperate}
|
||||||
setFilters(v)
|
canRemove={canRemove}
|
||||||
setOffset(0)
|
error={reconError}
|
||||||
setSelected([])
|
message={reconMessage}
|
||||||
setMessage('')
|
onTab={setTab}
|
||||||
setLoading(true)
|
onSelectRun={(id) => {
|
||||||
}}
|
setSelectedRunID(id)
|
||||||
onPage={setOffset}
|
setFindingOffset(0)
|
||||||
onSelection={setSelected}
|
}}
|
||||||
onSelectAll={() => void selectAll()}
|
onSelectKB={(id) => {
|
||||||
onRetry={(r) => void retry(r)}
|
setSelectedKB(id)
|
||||||
onDetail={(row) => {
|
setSelectedRunID('')
|
||||||
void fetchMonitorTasks({ id: row.id }, 0, 1)
|
setFindingOffset(0)
|
||||||
.then((p) => {
|
}}
|
||||||
if (p.items[0]) setDetail(p.items[0])
|
onFilters={(value) => {
|
||||||
else setMessage('该条记录已被新版本替换,请刷新列表')
|
setFindingFilters(value)
|
||||||
})
|
setFindingOffset(0)
|
||||||
.catch((e) => setMessage(e instanceof Error ? e.message : '读取详情失败'))
|
}}
|
||||||
}}
|
onPage={setFindingOffset}
|
||||||
onRefresh={refresh}
|
onRefresh={refresh}
|
||||||
onLocateSource={onLocateSource}
|
onCreate={() => void createRun()}
|
||||||
/>
|
onAction={(finding) => void actOnFinding(finding)}
|
||||||
|
onDetail={setFindingDetail}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<WeKnoraMonitorView
|
||||||
|
overview={overview}
|
||||||
|
metrics={metrics}
|
||||||
|
page={page}
|
||||||
|
filters={filters}
|
||||||
|
selected={selected}
|
||||||
|
loading={loading}
|
||||||
|
busy={busy}
|
||||||
|
error={Object.values(errors).filter(Boolean).join(';')}
|
||||||
|
message={message}
|
||||||
|
canOperate={canOperate}
|
||||||
|
tab={tab}
|
||||||
|
onTab={setTab}
|
||||||
|
onFilters={(v) => {
|
||||||
|
setFilters(v)
|
||||||
|
setOffset(0)
|
||||||
|
setSelected([])
|
||||||
|
setMessage('')
|
||||||
|
setLoading(true)
|
||||||
|
}}
|
||||||
|
onPage={setOffset}
|
||||||
|
onSelection={setSelected}
|
||||||
|
onSelectAll={() => void selectAll()}
|
||||||
|
onRetry={(r) => void retry(r)}
|
||||||
|
onDetail={(row) => {
|
||||||
|
void fetchMonitorTasks({ id: row.id }, 0, 1)
|
||||||
|
.then((p) => {
|
||||||
|
if (p.items[0]) setDetail(p.items[0])
|
||||||
|
else setMessage('该条记录已被新版本替换,请刷新列表')
|
||||||
|
})
|
||||||
|
.catch((e) => setMessage(e instanceof Error ? e.message : '读取详情失败'))
|
||||||
|
}}
|
||||||
|
onRefresh={refresh}
|
||||||
|
onLocateSource={onLocateSource}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{detail ? <TaskDetail item={detail} onClose={() => setDetail(null)} onLocateSource={onLocateSource} /> : null}
|
{detail ? <TaskDetail item={detail} onClose={() => setDetail(null)} onLocateSource={onLocateSource} /> : null}
|
||||||
|
{findingDetail ? <FindingDetail finding={findingDetail} onClose={() => setFindingDetail(null)} /> : null}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,24 @@ export interface IngestionPipeline {
|
|||||||
fetch_missing: number
|
fetch_missing: number
|
||||||
concurrency: number
|
concurrency: number
|
||||||
}
|
}
|
||||||
|
export interface WeKnoraQueue {
|
||||||
|
name: string
|
||||||
|
pool: string
|
||||||
|
pending: number
|
||||||
|
active: number
|
||||||
|
scheduled: number
|
||||||
|
retry: number
|
||||||
|
archived: number
|
||||||
|
processed: number
|
||||||
|
failed: number
|
||||||
|
}
|
||||||
|
export interface WeKnoraQueues {
|
||||||
|
available: boolean
|
||||||
|
queues_error: boolean
|
||||||
|
workers_error: boolean
|
||||||
|
queues: WeKnoraQueue[]
|
||||||
|
timestamp: number
|
||||||
|
}
|
||||||
export interface MonitorOverview {
|
export interface MonitorOverview {
|
||||||
mode: string
|
mode: string
|
||||||
simulated: boolean
|
simulated: boolean
|
||||||
@@ -66,6 +84,7 @@ export interface MonitorOverview {
|
|||||||
knowledge_bases: KnowledgeProgress[]
|
knowledge_bases: KnowledgeProgress[]
|
||||||
pipeline?: IngestionPipeline
|
pipeline?: IngestionPipeline
|
||||||
health: ServiceHealth[]
|
health: ServiceHealth[]
|
||||||
|
weknora_queues?: WeKnoraQueues | null
|
||||||
}
|
}
|
||||||
export interface MonitorFile {
|
export interface MonitorFile {
|
||||||
name: string
|
name: string
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export interface MonitorTask {
|
|||||||
source_name: string
|
source_name: string
|
||||||
target_scope: string
|
target_scope: string
|
||||||
target_kb: string
|
target_kb: string
|
||||||
|
document_id?: string
|
||||||
action: string
|
action: string
|
||||||
stage: string
|
stage: string
|
||||||
status: string
|
status: string
|
||||||
|
|||||||
@@ -593,3 +593,194 @@
|
|||||||
padding: 18px;
|
padding: 18px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* T6 导入对账:页签、批次概览、差异表与实时处理详情。沿用钴蓝/中性灰,不引入紫色。 */
|
||||||
|
.monitor-tabs {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin: 0 0 14px;
|
||||||
|
padding: 4px;
|
||||||
|
width: fit-content;
|
||||||
|
border: 1px solid var(--border-base);
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--bg-soft);
|
||||||
|
}
|
||||||
|
.monitor-tabs button {
|
||||||
|
min-height: 32px;
|
||||||
|
padding: 0 16px;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--ink-mute);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.monitor-tabs button.active {
|
||||||
|
background: var(--bg-panel);
|
||||||
|
color: var(--ink-strong);
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
}
|
||||||
|
.monitor-service-strip {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px 22px;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
padding: 10px 14px;
|
||||||
|
border: 1px solid var(--border-base);
|
||||||
|
border-radius: var(--r-lg);
|
||||||
|
background: var(--bg-panel);
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--ink-mute);
|
||||||
|
}
|
||||||
|
.monitor-service-strip b {
|
||||||
|
color: var(--ink-strong);
|
||||||
|
}
|
||||||
|
.monitor-recon-overview {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
padding: 16px 18px;
|
||||||
|
border: 1px solid var(--border-base);
|
||||||
|
border-radius: var(--r-lg);
|
||||||
|
background: var(--bg-panel);
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
}
|
||||||
|
.monitor-recon-controls {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
.monitor-recon-controls label {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--ink-mute);
|
||||||
|
}
|
||||||
|
.monitor-recon-controls select {
|
||||||
|
min-width: 180px;
|
||||||
|
max-width: 280px;
|
||||||
|
}
|
||||||
|
.monitor-diff-counts {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(8, minmax(0, 1fr));
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 14px;
|
||||||
|
}
|
||||||
|
.monitor-diff-counts > span {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 8px 10px;
|
||||||
|
border: 1px solid var(--border-base);
|
||||||
|
border-radius: var(--r-md);
|
||||||
|
background: var(--bg-soft);
|
||||||
|
}
|
||||||
|
.monitor-diff-counts b {
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 1.2;
|
||||||
|
color: var(--ink-strong);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
.monitor-diff-counts small,
|
||||||
|
.monitor-diff-counts em {
|
||||||
|
font-size: 10px;
|
||||||
|
font-style: normal;
|
||||||
|
color: var(--ink-mute);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.monitor-diff-counts .has-diff {
|
||||||
|
border-color: color-mix(in srgb, var(--c-fail) 45%, var(--border-base));
|
||||||
|
}
|
||||||
|
.monitor-diff-counts .has-diff b {
|
||||||
|
color: var(--c-fail);
|
||||||
|
}
|
||||||
|
.monitor-finding-type {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--bg-soft);
|
||||||
|
border: 1px solid var(--border-base);
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.monitor-finding-type.r1,
|
||||||
|
.monitor-finding-type.r2,
|
||||||
|
.monitor-finding-type.r4,
|
||||||
|
.monitor-finding-type.r7 {
|
||||||
|
border-color: color-mix(in srgb, var(--c-fail) 45%, var(--border-base));
|
||||||
|
color: var(--c-fail);
|
||||||
|
}
|
||||||
|
.monitor-finding-type.r5,
|
||||||
|
.monitor-finding-type.r6 {
|
||||||
|
border-color: color-mix(in srgb, var(--c-warn, #b7791f) 45%, var(--border-base));
|
||||||
|
}
|
||||||
|
.monitor-badge-pending {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: #fff7e6;
|
||||||
|
border: 1px solid #e6b450;
|
||||||
|
color: #8a5a00;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.monitor-progress {
|
||||||
|
margin-top: 16px;
|
||||||
|
padding-top: 14px;
|
||||||
|
border-top: 1px solid var(--border-base);
|
||||||
|
}
|
||||||
|
.monitor-progress.compact {
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
.monitor-progress h3 {
|
||||||
|
font-size: 13px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.monitor-stages {
|
||||||
|
margin: 10px 0 0;
|
||||||
|
padding-left: 18px;
|
||||||
|
display: grid;
|
||||||
|
gap: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--ink-base);
|
||||||
|
}
|
||||||
|
.monitor-failures {
|
||||||
|
margin-top: 12px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: 1px solid var(--border-base);
|
||||||
|
border-radius: var(--r-md);
|
||||||
|
background: var(--bg-soft);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.monitor-failures p {
|
||||||
|
margin: 6px 0 0;
|
||||||
|
color: var(--ink-mute);
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
.monitor-diff-counts {
|
||||||
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
.monitor-address-grid,
|
||||||
|
.monitor-metric-grid {
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.monitor-diff-counts {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
.monitor-recon-controls select {
|
||||||
|
min-width: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.monitor-service-strip {
|
||||||
|
display: grid;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import {
|
||||||
|
createReconciliationRun,
|
||||||
|
fetchReconciliationFindings,
|
||||||
|
fetchReconciliationProgress,
|
||||||
|
ReconciliationRequestError,
|
||||||
|
} from './reconciliation'
|
||||||
|
|
||||||
|
afterEach(() => vi.unstubAllGlobals())
|
||||||
|
const run = {
|
||||||
|
id: 'run-1',
|
||||||
|
kb_id: 'kb-1',
|
||||||
|
state: 'running',
|
||||||
|
trigger: 'manual',
|
||||||
|
started_at: '2026-12-01T02:00:00Z',
|
||||||
|
finished_at: null,
|
||||||
|
ledger_count: 0,
|
||||||
|
kb_count: 0,
|
||||||
|
counts: {},
|
||||||
|
previous_counts: null,
|
||||||
|
window_overlapped: false,
|
||||||
|
error_code: '',
|
||||||
|
}
|
||||||
|
describe('reconciliation API client', () => {
|
||||||
|
it('sends the write intent and kb_id when creating a run', async () => {
|
||||||
|
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ data: run }), { status: 202 }))
|
||||||
|
vi.stubGlobal('fetch', fetchMock)
|
||||||
|
const created = await createReconciliationRun('kb-1')
|
||||||
|
expect(created.id).toBe('run-1')
|
||||||
|
const [, init] = fetchMock.mock.calls[0]
|
||||||
|
expect(init.headers['X-Governance-Action']).toBe('reconciliation-action')
|
||||||
|
expect(JSON.parse(String(init.body))).toEqual({ kb_id: 'kb-1' })
|
||||||
|
})
|
||||||
|
it('surfaces 409 run-in-progress code', async () => {
|
||||||
|
vi.stubGlobal(
|
||||||
|
'fetch',
|
||||||
|
vi.fn().mockResolvedValue(
|
||||||
|
new Response(
|
||||||
|
JSON.stringify({ error: 'reconciliation_run_in_progress', code: 'reconciliation_run_in_progress' }),
|
||||||
|
{
|
||||||
|
status: 409,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
await createReconciliationRun('kb-1')
|
||||||
|
throw new Error('expected 409')
|
||||||
|
} catch (error) {
|
||||||
|
expect(error).toBeInstanceOf(ReconciliationRequestError)
|
||||||
|
expect((error as ReconciliationRequestError).status).toBe(409)
|
||||||
|
expect((error as ReconciliationRequestError).code).toBe('reconciliation_run_in_progress')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
it('marks 503 progress as runtime_read_unavailable', async () => {
|
||||||
|
vi.stubGlobal(
|
||||||
|
'fetch',
|
||||||
|
vi.fn().mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({ error: 'runtime_read_unavailable', code: 'runtime_read_unavailable' }), {
|
||||||
|
status: 503,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await expect(fetchReconciliationProgress('doc-1')).rejects.toMatchObject({
|
||||||
|
code: 'runtime_read_unavailable',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
it('parses findings and rejects an unknown type', async () => {
|
||||||
|
const finding = {
|
||||||
|
id: 'f1',
|
||||||
|
run_id: 'run-1',
|
||||||
|
type: 'R1',
|
||||||
|
publication_id: 'pub-1',
|
||||||
|
document_id: 'doc-1',
|
||||||
|
title: 't',
|
||||||
|
path: 'p',
|
||||||
|
source: 's',
|
||||||
|
target_scope: 'internal',
|
||||||
|
ledger_state: 'completed',
|
||||||
|
weknora_parse_status: '',
|
||||||
|
normalized_state: '',
|
||||||
|
ledger_sha256: '',
|
||||||
|
declared_sha256: '',
|
||||||
|
weknora_file_md5: '',
|
||||||
|
evidence_level: 'none',
|
||||||
|
confirmation_state: 'pending',
|
||||||
|
detail: 'd',
|
||||||
|
suggested_action: 'requeue_upload',
|
||||||
|
action_state: 'open',
|
||||||
|
weknora_url: '',
|
||||||
|
}
|
||||||
|
vi.stubGlobal(
|
||||||
|
'fetch',
|
||||||
|
vi
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({ data: { items: [finding], total: 1, limit: 20, offset: 0 } }), { status: 200 })
|
||||||
|
)
|
||||||
|
)
|
||||||
|
const page = await fetchReconciliationFindings('run-1')
|
||||||
|
expect(page.items[0].confirmation_state).toBe('pending')
|
||||||
|
vi.stubGlobal(
|
||||||
|
'fetch',
|
||||||
|
vi.fn().mockResolvedValue(
|
||||||
|
new Response(
|
||||||
|
JSON.stringify({ data: { items: [{ ...finding, type: 'R9' }], total: 1, limit: 20, offset: 0 } }),
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await expect(fetchReconciliationFindings('run-1')).rejects.toThrow('对账差异响应无效')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
export type ReconciliationFindingType = 'R1' | 'R2' | 'R3' | 'R4' | 'R5' | 'R6' | 'R7' | 'R8'
|
||||||
|
export type ReconciliationEvidence = 'independent' | 'declared_only' | 'none'
|
||||||
|
export type ReconciliationConfirmation = 'confirmed' | 'pending'
|
||||||
|
export type ReconciliationAction = 'requeue_upload' | 'remove_from_test' | 'writeback_state' | 'enter_removal' | 'none'
|
||||||
|
|
||||||
|
export interface ReconciliationRun {
|
||||||
|
id: string
|
||||||
|
kb_id: string
|
||||||
|
state: 'running' | 'succeeded' | 'failed'
|
||||||
|
trigger: 'schedule' | 'manual'
|
||||||
|
started_at: string
|
||||||
|
finished_at: string | null
|
||||||
|
ledger_count: number
|
||||||
|
kb_count: number
|
||||||
|
counts: Record<string, number>
|
||||||
|
previous_counts: Record<string, number> | null
|
||||||
|
window_overlapped: boolean
|
||||||
|
error_code: string
|
||||||
|
}
|
||||||
|
export interface ReconciliationRunPage {
|
||||||
|
items: ReconciliationRun[]
|
||||||
|
total: number
|
||||||
|
limit: number
|
||||||
|
offset: number
|
||||||
|
}
|
||||||
|
export interface ReconciliationFinding {
|
||||||
|
id: string
|
||||||
|
run_id: string
|
||||||
|
type: ReconciliationFindingType
|
||||||
|
publication_id: string
|
||||||
|
document_id: string
|
||||||
|
title: string
|
||||||
|
path: string
|
||||||
|
source: string
|
||||||
|
target_scope: string
|
||||||
|
ledger_state: string
|
||||||
|
weknora_parse_status: string
|
||||||
|
normalized_state: string
|
||||||
|
ledger_sha256: string
|
||||||
|
declared_sha256: string
|
||||||
|
weknora_file_md5: string
|
||||||
|
evidence_level: ReconciliationEvidence
|
||||||
|
confirmation_state: ReconciliationConfirmation
|
||||||
|
detail: string
|
||||||
|
suggested_action: ReconciliationAction
|
||||||
|
action_state: 'open' | 'done'
|
||||||
|
weknora_url: string
|
||||||
|
}
|
||||||
|
export interface ReconciliationFindingPage {
|
||||||
|
items: ReconciliationFinding[]
|
||||||
|
total: number
|
||||||
|
limit: number
|
||||||
|
offset: number
|
||||||
|
}
|
||||||
|
export interface ReconciliationStage {
|
||||||
|
name: string
|
||||||
|
status: string
|
||||||
|
error_code: string
|
||||||
|
finished_at: string | null
|
||||||
|
}
|
||||||
|
export interface ReconciliationFailure {
|
||||||
|
task_type: string
|
||||||
|
fail_count: number
|
||||||
|
failed_at: string
|
||||||
|
last_error: string
|
||||||
|
}
|
||||||
|
export interface ReconciliationProgress {
|
||||||
|
document_id: string
|
||||||
|
parse_status: string
|
||||||
|
ingestion_status: string
|
||||||
|
wiki_status: string
|
||||||
|
stages: ReconciliationStage[]
|
||||||
|
failures: ReconciliationFailure[]
|
||||||
|
has_more_failures: boolean
|
||||||
|
observed_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const record = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null
|
||||||
|
const count = (value: unknown) => typeof value === 'number' && Number.isInteger(value) && value >= 0
|
||||||
|
const text = (value: unknown) => (typeof value === 'string' ? value : '')
|
||||||
|
|
||||||
|
export class ReconciliationRequestError extends Error {
|
||||||
|
status: number
|
||||||
|
code: string
|
||||||
|
constructor(message: string, status: number, code: string) {
|
||||||
|
super(message)
|
||||||
|
this.status = status
|
||||||
|
this.code = code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function request(path: string, init: RequestInit, signal?: AbortSignal): Promise<unknown> {
|
||||||
|
const response = await fetch(path, {
|
||||||
|
...init,
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
...(init.body ? { 'Content-Type': 'application/json' } : {}),
|
||||||
|
...(init.headers || {}),
|
||||||
|
},
|
||||||
|
signal,
|
||||||
|
})
|
||||||
|
const payload = await response.json().catch(() => null)
|
||||||
|
if (!response.ok) {
|
||||||
|
const body = record(payload) ? payload : {}
|
||||||
|
throw new ReconciliationRequestError(
|
||||||
|
text(body.error) || `请求失败(HTTP ${response.status})`,
|
||||||
|
response.status,
|
||||||
|
text(body.code)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseRun(value: unknown): ReconciliationRun {
|
||||||
|
if (
|
||||||
|
!record(value) ||
|
||||||
|
typeof value.id !== 'string' ||
|
||||||
|
typeof value.kb_id !== 'string' ||
|
||||||
|
!['running', 'succeeded', 'failed'].includes(String(value.state)) ||
|
||||||
|
!['schedule', 'manual'].includes(String(value.trigger)) ||
|
||||||
|
typeof value.started_at !== 'string' ||
|
||||||
|
!count(value.ledger_count) ||
|
||||||
|
!count(value.kb_count) ||
|
||||||
|
!record(value.counts) ||
|
||||||
|
typeof value.window_overlapped !== 'boolean'
|
||||||
|
)
|
||||||
|
throw new Error('对账批次响应无效')
|
||||||
|
return value as unknown as ReconciliationRun
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseFinding(value: unknown): ReconciliationFinding {
|
||||||
|
if (
|
||||||
|
!record(value) ||
|
||||||
|
typeof value.id !== 'string' ||
|
||||||
|
!['R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8'].includes(String(value.type)) ||
|
||||||
|
!['independent', 'declared_only', 'none'].includes(String(value.evidence_level)) ||
|
||||||
|
!['confirmed', 'pending'].includes(String(value.confirmation_state)) ||
|
||||||
|
!['requeue_upload', 'remove_from_test', 'writeback_state', 'enter_removal', 'none'].includes(
|
||||||
|
String(value.suggested_action)
|
||||||
|
) ||
|
||||||
|
!['open', 'done'].includes(String(value.action_state))
|
||||||
|
)
|
||||||
|
throw new Error('对账差异响应无效')
|
||||||
|
return value as unknown as ReconciliationFinding
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchReconciliationRuns(
|
||||||
|
limit = 20,
|
||||||
|
offset = 0,
|
||||||
|
kbID = '',
|
||||||
|
signal?: AbortSignal
|
||||||
|
): Promise<ReconciliationRunPage> {
|
||||||
|
const query = new URLSearchParams({ limit: String(limit), offset: String(offset) })
|
||||||
|
if (kbID) query.set('kb_id', kbID)
|
||||||
|
const payload = await request(`/api/v1/reconciliation/runs?${query}`, { method: 'GET' }, signal)
|
||||||
|
if (!record(payload) || !record(payload.data) || !Array.isArray(payload.data.items))
|
||||||
|
throw new Error('对账批次列表响应无效')
|
||||||
|
return {
|
||||||
|
items: payload.data.items.map(parseRun),
|
||||||
|
total: Number(payload.data.total) || 0,
|
||||||
|
limit: Number(payload.data.limit) || limit,
|
||||||
|
offset: Number(payload.data.offset) || offset,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchReconciliationFindings(
|
||||||
|
runID: string,
|
||||||
|
type = '',
|
||||||
|
q = '',
|
||||||
|
limit = 20,
|
||||||
|
offset = 0,
|
||||||
|
signal?: AbortSignal
|
||||||
|
): Promise<ReconciliationFindingPage> {
|
||||||
|
const query = new URLSearchParams({ limit: String(limit), offset: String(offset) })
|
||||||
|
if (type) query.set('type', type)
|
||||||
|
if (q) query.set('q', q)
|
||||||
|
const payload = await request(
|
||||||
|
`/api/v1/reconciliation/runs/${encodeURIComponent(runID)}/findings?${query}`,
|
||||||
|
{ method: 'GET' },
|
||||||
|
signal
|
||||||
|
)
|
||||||
|
if (!record(payload) || !record(payload.data) || !Array.isArray(payload.data.items))
|
||||||
|
throw new Error('对账差异列表响应无效')
|
||||||
|
return {
|
||||||
|
items: payload.data.items.map(parseFinding),
|
||||||
|
total: Number(payload.data.total) || 0,
|
||||||
|
limit: Number(payload.data.limit) || limit,
|
||||||
|
offset: Number(payload.data.offset) || offset,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createReconciliationRun(kbID: string): Promise<ReconciliationRun> {
|
||||||
|
const payload = await request('/api/v1/reconciliation/runs', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'X-Governance-Action': 'reconciliation-action' },
|
||||||
|
body: JSON.stringify({ kb_id: kbID }),
|
||||||
|
})
|
||||||
|
if (!record(payload) || !record(payload.data)) throw new Error('触发对账响应无效')
|
||||||
|
return parseRun(payload.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function findingAction(id: string, action: 'writeback' | 'requeue' | 'remove'): Promise<ReconciliationFinding> {
|
||||||
|
const payload = await request(`/api/v1/reconciliation/findings/${encodeURIComponent(id)}/${action}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'X-Governance-Action': 'reconciliation-action' },
|
||||||
|
})
|
||||||
|
if (!record(payload) || !record(payload.data)) throw new Error('对账处置响应无效')
|
||||||
|
return parseFinding(payload.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const writebackFinding = (id: string) => findingAction(id, 'writeback')
|
||||||
|
export const requeueFinding = (id: string) => findingAction(id, 'requeue')
|
||||||
|
export const removeFinding = (id: string) => findingAction(id, 'remove')
|
||||||
|
|
||||||
|
export async function fetchReconciliationProgress(
|
||||||
|
documentID: string,
|
||||||
|
signal?: AbortSignal
|
||||||
|
): Promise<ReconciliationProgress> {
|
||||||
|
const payload = await request(
|
||||||
|
`/api/v1/reconciliation/documents/${encodeURIComponent(documentID)}/progress`,
|
||||||
|
{ method: 'GET' },
|
||||||
|
signal
|
||||||
|
)
|
||||||
|
if (!record(payload) || !record(payload.data) || typeof payload.data.document_id !== 'string')
|
||||||
|
throw new Error('WeKnora 处理详情响应无效')
|
||||||
|
return payload.data as unknown as ReconciliationProgress
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user