fix(reconciliation): 修复僵死回收 SQL 并补齐验收缺口
build / build (push) Has been cancelled

- 回收 SQL 占位符改为 $1/$2,消除 pgx 扩展协议 42P18(手动/定时对账 500)
- 直接写入 finding 时归一空 confirmation_state,避免 23514
- 修正 R6/overview 同谓词用例夹具,两条台账各自持有 source version
- 页面顶部统一服务与队列单行状态条,删除 Embedding/LLM 常量卡
- 平台阶段筛选合并为「WeKnora 处理中」,后端支持 stage=weknora
- weknora_url 由测试 WeKnora 源构造,详情与 503 提供跳转链接
- 补 1000/页线上查询、R8 合法收养、weknora 阶段筛选用例
This commit is contained in:
Zhero & Rin
2026-12-01 14:22:06 +08:00
committed by 姚章浩
parent 629694546c
commit e855261b4d
19 changed files with 211 additions and 143 deletions
+11 -1
View File
@@ -1,6 +1,6 @@
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { ReconciliationFindingsView } from './ReconciliationFindings'
import { FindingDetail, ReconciliationFindingsView } from './ReconciliationFindings'
import type { ReconciliationFinding, ReconciliationRun } from './reconciliationApi'
const run: ReconciliationRun = {
@@ -103,4 +103,14 @@ describe('reconciliation findings', () => {
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 中打开')
})
})
+65 -21
View File
@@ -62,11 +62,42 @@ interface FindingsProps {
onDetail: (finding: ReconciliationFinding) => void
}
// ServiceStrip is the page-top one-line status required by §8: the service and
// dependency area collapses into a row on both tabs. Queue truth comes from
// weknora_queues; an unavailable queue is stated, never rendered as a zero.
export function ServiceStrip({ overview }: { overview: MonitorOverview | null }) {
const queue = overview?.weknora_queues
const ready = overview?.health.filter((item) => item.readiness === 'ready').length
const attention = overview?.health.filter(
(item) => item.applicable && item.configured && item.readiness !== 'ready'
).length
return (
<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>{ready == null ? '等待运行快照' : `${ready} 可接单`}</b>
{attention ? <b className="monitor-bad"> · {attention} 项需关注</b> : null}
</span>
<span className="monitor-muted">一期只对测试库;生产下架依赖测试移除 + 下一轮整库发布</span>
</section>
)
}
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">
@@ -92,23 +123,7 @@ export function ReconciliationFindingsView(p: FindingsProps) {
{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>
<ServiceStrip overview={p.overview} />
<section className="monitor-recon-overview" aria-label="最近一次对账">
<div className="monitor-recon-controls">
<label>
@@ -327,7 +342,15 @@ export function ReconciliationFindingsView(p: FindingsProps) {
)
}
export function WeKnoraProgress({ documentID, compact = false }: { documentID: string; compact?: boolean }) {
export function WeKnoraProgress({
documentID,
weknoraURL,
compact = false,
}: {
documentID: string
weknoraURL?: string
compact?: boolean
}) {
const [progress, setProgress] = useState<ReconciliationProgress | null>(null)
const [error, setError] = useState('')
const [loading, setLoading] = useState(true)
@@ -364,7 +387,19 @@ export function WeKnoraProgress({ documentID, compact = false }: { documentID: s
<small>实时读取,不落库</small>
</div>
{loading ? <p className="monitor-muted">正在读取…</p> : null}
{error ? <p className="monitor-alert">{error}</p> : null}
{error ? (
<p className="monitor-alert">
{error}
{weknoraURL ? (
<>
{' '}
<a href={weknoraURL} target="_blank" rel="noreferrer">
在 WeKnora 中打开
</a>
</>
) : null}
</p>
) : null}
{progress ? (
<>
<p className="monitor-muted">
@@ -438,7 +473,16 @@ export function FindingDetail({ finding, onClose }: { finding: ReconciliationFin
</div>
))}
</dl>
{finding.document_id ? <WeKnoraProgress documentID={finding.document_id} compact /> : null}
{finding.weknora_url ? (
<p>
<a href={finding.weknora_url} target="_blank" rel="noreferrer">
在 WeKnora 中打开
</a>
</p>
) : null}
{finding.document_id ? (
<WeKnoraProgress documentID={finding.document_id} weknoraURL={finding.weknora_url} compact />
) : null}
</dialog>
)
}
+8 -5
View File
@@ -92,18 +92,21 @@ describe('unified monitor', () => {
'状态说明',
'共 145',
'重试所选',
'服务与依赖',
'monitor-service-strip',
'WeKnora 队列:',
])
expect(html).toContain(s)
expect(html).not.toContain('开始处理')
expect(html).not.toContain('role="tab"')
expect(html).not.toContain('monitor-service-grid')
expect(html).toContain('value="active" selected=""')
})
it('does not claim healthy zeroes or 100% when metrics are unavailable', () => {
const html = renderToStaticMarkup(<WeKnoraMonitorView {...props} error="无法读取运行指标" />)
expect(html).toContain('无法读取运行指标')
expect(html).not.toContain('100%')
expect(html).toContain('尚未取得服务状态')
expect(html).toContain('等待运行快照')
expect(html).not.toContain('0 可接单')
})
it('keeps removal semantics and does not offer retry for completed rows', () => {
const html = renderToStaticMarkup(<WeKnoraMonitorView {...props} />)
@@ -135,7 +138,7 @@ describe('target identity and probe attribution', () => {
expect(html).toContain('历史')
expect(html).toContain('产品/维护')
})
it('shows liveness and the sanitized probe target separately from readiness', () => {
it('surfaces a blocked service in the one-line strip without claiming readiness', () => {
const overview = {
mode: 'real',
simulated: false,
@@ -170,7 +173,7 @@ describe('target identity and probe attribution', () => {
],
}
const html = renderToStaticMarkup(<WeKnoraMonitorView {...props} overview={overview} />)
expect(html).toContain('存活 up')
expect(html).toContain('探测对象 实例 weknora.test · 知识库 1b52c140')
expect(html).toContain('0 可接单')
expect(html).toContain('1 项需关注')
})
})
+4 -37
View File
@@ -7,6 +7,7 @@ import {
canRetryTask,
actionLabels,
stageLabels,
stageFilterLabels,
taskStatusLabels,
targetLabel,
} from './monitorTasks'
@@ -15,7 +16,7 @@ import { requeueJobFailure, retryPublicationsBatch, startPublicationRemoval } fr
import { fetchActiveUISettings, settingsRefreshDelays } from './uiSettings'
import { useOptionalAuth } from './auth'
import { WorkspaceContextTabsSetter } from './workspaceContext'
import { ReconciliationFindingsView, FindingDetail, WeKnoraProgress } from './ReconciliationFindings'
import { ReconciliationFindingsView, FindingDetail, ServiceStrip, WeKnoraProgress } from './ReconciliationFindings'
import type { FindingFilters } from './ReconciliationFindings'
import {
createReconciliationRun,
@@ -196,41 +197,7 @@ export function WeKnoraMonitorView(p: ViewProps) {
</div>
</article>
</section>
<section className="monitor-service-panel">
<div className="monitor-section-heading">
<h2>服务与依赖</h2>
<span>展开查看状态原因</span>
</div>
<div className="monitor-service-grid">
{overview?.health.length ? (
overview.health.map((s) => (
<details key={s.key} className="monitor-service">
<summary>
<span>{s.name}</span>
<b
className={
healthLabel(s) === '可接单'
? 'monitor-good'
: ['阻断', '不可达'].includes(healthLabel(s))
? 'monitor-bad'
: ''
}
>
● {healthLabel(s)}
</b>
</summary>
<p>{s.reason || '未提供状态说明'}</p>
<small>
检测:{time(s.observed_at)} · {s.latency_ms} ms · 存活 {s.liveness || '未确认'}
{s.probe_target ? ` · 探测对象 ${s.probe_target}` : ''}
</small>
</details>
))
) : (
<p className="monitor-muted">尚未取得服务状态</p>
)}
</div>
</section>
<ServiceStrip overview={overview} />
<section className="monitor-files">
<div className="monitor-section-heading">
<div className="monitor-heading-group">
@@ -333,7 +300,7 @@ export function WeKnoraMonitorView(p: ViewProps) {
onChange={(e) => patchFilter('stage', e.target.value)}
>
<option value="">全部阶段</option>
{Object.entries(stageLabels).map(([key, label]) => (
{Object.entries(stageFilterLabels).map(([key, label]) => (
<option key={key} value={key}>
{label}
</option>
+10
View File
@@ -74,6 +74,16 @@ export const stageLabels: Record<string, string> = {
removal: '测试库移除',
finished: '结束',
}
// 阶段筛选按需求 §8 合并「解析」「索引增强」为「WeKnora 处理中」;行内展示仍用
// stageLabels 的细粒度阶段,两者不要互相替代。
export const stageFilterLabels: Record<string, string> = {
waiting: '等待调度',
fetch: '取件',
upload: '上传',
weknora: 'WeKnora 处理中',
removal: '测试库移除',
finished: '结束',
}
export const taskStatusLabels: Record<string, string> = {
waiting: '等待中',
running: '执行中',
-67
View File
@@ -77,25 +77,14 @@
.monitor-numbers .monitor-memory {
font-size: 24px;
}
.monitor-good {
color: var(--c-done) !important;
}
.monitor-bad {
color: var(--c-fail) !important;
}
.monitor-service-panel,
.monitor-files {
border: 1px solid var(--border-base);
border-radius: var(--r-lg);
background: var(--bg-panel);
box-shadow: var(--shadow-card);
overflow: hidden;
}
.monitor-service-panel {
padding: 18px 20px;
margin-bottom: 16px;
}
.monitor-files {
/* 时间范围浮层要能溢出卡片;圆角由表头/分页各自裁切 */
overflow: visible;
}
@@ -125,56 +114,6 @@
font-size: 11px;
color: var(--ink-mute);
}
.monitor-service-grid {
display: grid;
grid-template-columns: repeat(6, minmax(0, 1fr));
gap: 9px;
margin-top: 13px;
align-items: start;
}
.monitor-service {
border: 1px solid var(--border-soft);
border-radius: var(--r-md);
background: var(--bg-soft);
padding: 10px 12px;
transition:
border-color 120ms ease,
background 120ms ease;
}
.monitor-service:hover,
.monitor-service[open] {
border-color: var(--border-base);
background: var(--bg-panel);
font-size: 12px;
min-width: 0;
}
.monitor-service summary {
list-style: none;
cursor: pointer;
display: flex;
flex-direction: column;
gap: 6px;
}
.monitor-service summary::-webkit-details-marker {
display: none;
}
.monitor-service summary > span {
overflow-wrap: anywhere;
color: var(--ink-base);
font-weight: 500;
}
.monitor-service b {
font-size: 11px;
font-weight: 500;
color: var(--ink-mute);
}
.monitor-service p,
.monitor-service small {
font-size: 11px;
color: var(--ink-mute);
overflow-wrap: anywhere;
line-height: 1.6;
}
.monitor-files > .monitor-section-heading {
padding: 18px 20px 14px;
}
@@ -542,9 +481,6 @@
.monitor-metric-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.monitor-service-grid {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
}
@media (max-width: 760px) {
.monitor-heading {
@@ -553,9 +489,6 @@
.monitor-heading > span {
margin-left: 0;
}
.monitor-service-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.monitor-metric-grid {
gap: 8px;
}