082f77fc18
build / build (push) Successful in 2m28s
白盒补充复核提出的三项: - P1 R6 与 /monitor/overview「需下架」计数口径不一致:R6 原先只在扫描结果里存在 且上游 parse_status=completed 时才生成,上游仍在 processing/finalizing 或单条读取 失败导致扫描缺行时,总览有数、对账无记录(陷阱 15)。改为直接由 removal_candidates 视图行生成,台账细节按 publication 回填,计数与总览同一来源;补单测覆盖 「上游 processing」「扫描未见」两种差异。 - P2 定时批失败后每个 tick 都重建:每日占位只排除 running/succeeded,failed 不占位, 一次失败当天会每分钟刷批。占位条件加入 failed,重跑改为显式手动触发;补 PG 集成用例。 - P2 队列不可用时前端显示 0 等待 · 0 运行:改为按 available 判定并显示不可用文案; 补组件用例。
160 lines
5.0 KiB
TypeScript
160 lines
5.0 KiB
TypeScript
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import { FindingDetail, ReconciliationFindingsView, ServiceStrip } from './ReconciliationFindings'
|
|
import type { MonitorOverview } from './monitor'
|
|
import type { ReconciliationFinding, ReconciliationRun } from './reconciliationApi'
|
|
|
|
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('读取对账批次失败')
|
|
})
|
|
it('links a finding to WeKnora when the backend supplies a URL', () => {
|
|
const html = renderToStaticMarkup(
|
|
<FindingDetail
|
|
finding={{ ...finding, weknora_url: 'https://weknora.test/platform/knowledge-bases/kb-1' }}
|
|
onClose={vi.fn()}
|
|
/>
|
|
)
|
|
expect(html).toContain('href="https://weknora.test/platform/knowledge-bases/kb-1"')
|
|
expect(html).toContain('在 WeKnora 中打开')
|
|
})
|
|
})
|
|
|
|
describe('ServiceStrip queue availability', () => {
|
|
const overview = (queues: MonitorOverview['weknora_queues']) =>
|
|
({ weknora_queues: queues, health: [] }) as unknown as MonitorOverview
|
|
|
|
it('states an unavailable queue instead of rendering 0 waiting · 0 active', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ServiceStrip
|
|
overview={overview({ available: false, queues_error: true, workers_error: false, queues: [], timestamp: 0 })}
|
|
/>
|
|
)
|
|
expect(html).toContain('队列不可用')
|
|
expect(html).not.toContain('0 等待')
|
|
})
|
|
|
|
it('prints queue depth when the queue is available', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ServiceStrip
|
|
overview={overview({
|
|
available: true,
|
|
queues_error: false,
|
|
workers_error: false,
|
|
timestamp: 0,
|
|
queues: [
|
|
{
|
|
name: 'default',
|
|
pool: 'default',
|
|
pending: 2,
|
|
active: 1,
|
|
scheduled: 0,
|
|
retry: 0,
|
|
archived: 0,
|
|
processed: 0,
|
|
failed: 0,
|
|
},
|
|
],
|
|
})}
|
|
/>
|
|
)
|
|
expect(html).toContain('2 等待 · 1 运行')
|
|
})
|
|
})
|