feat(monitor): 需下架车道可逐条移除测试库知识 —— 补齐最后一个没有页面入口的流程
背景:来源侧被判「禁止导入」后,已建好的测试库知识不会自动消失;此前只有变更集
删除路径会入队 test.remove,页面既列不出条目也没有按钮,运维无法闭环(车道只有按
库计数)。
新增:
- GET /api/v1/test-publications?removal=required:条目级列表,判据与车道计数同源
(superseded_at IS NULL / 有 knowledge_id / completed / retrieval_state NOT IN
(disabling,disabled) / policy_state='blocked'),过滤是叠加而不是替换。
- POST /api/v1/test-publications/{id}/removal:engineer 级写路由,要求 Idempotency-Key,
按条目幂等(operator-remove:<id>);置 disabling 并交既有 test.remove 工作流去删除
远端知识并读回校验。错误映射 404/409(已移除)/409(不可移除)/501(未接线)。
- 界面:需下架车道逐条显示条目 + 「下架(从测试库移除)」,页内二次确认,成功提示,
完成后计数归零。
修掉过程中踩到的两个真问题:
1. 二次确认的确认态原先经容器 props 传给视图,一次容器改动把三个 props 丢了 ——
视图永远渲染原按钮、确认步骤静默消失,而所有静态单元测试仍然通过。改为把确认态
放在视图内部;并把「取消」放在原按钮位置(真实指针连点两下只会落到取消)。
2. jobs 上有部分唯一索引 UNIQUE (business_change_set_id, business_version_id,
business_target_kb_id, business_action) WHERE business_change_set_id IS NOT NULL。
本路径给这三列写空串(非 NULL),('','','','remove') 对所有条目是同一个键 ——
第一条之后每次 INSERT 都撞唯一索引、被 ON CONFLICT DO NOTHING 静默吞掉,留下
「状态已 disabling、没有任务」的永久卡死条目,而车道恰好隐藏 disabling,运维也
看不到。改为写 NULL(语义:无变更集身份)+ 冲突目标收敛到 idempotency_key +
校验 RowsAffected()(0 行回查既有任务;查不到就报错,不提交无任务的 disabling)。
卡死状态在重试时可自愈。
测试:internal/platform/postgres/test_publication_removal_integration_test.go(两条发布
各自入队、business_* 为 NULL、卡死自愈;把修复退回旧写法该测试即 FAIL,已实测)、
internal/httpapi/test_publication_removal_test.go(权限/幂等键/错误映射/未接线 501/列表
过滤)、前端 testPublications.test.ts + WeKnoraMonitor.test.tsx。
验收(纯界面,两条都走完):解析监控 → 需下架(2)→ 逐条「下架」+ 二次确认 →
retrieval_state=disabled(PDF 03:57:03Z、md 04:08:55Z),jobs completed(attempt 2,
首次 test_remove_pending=远端仍在处理,重试通过;工作流以 GetKnowledge 读回 404 判
成功)→ 车道需下架(0)。核验「确认前不执行」:首次点击后仍 unpublished、移除任务数仍 1。
This commit is contained in:
@@ -34,6 +34,8 @@ export interface AcceptanceRecord {
|
||||
}
|
||||
|
||||
export interface TestPublicationQuery {
|
||||
/** removal: 'required' 只取「被禁止导入但仍存活在测试库」的条目(解析监控 → 需下架)。 */
|
||||
removal?: 'required'
|
||||
// A single state, or several at once (joined into a comma list server-side).
|
||||
processing_state: ProcessingState | '' | ProcessingState[]
|
||||
target_scope?: 'internal' | 'external' | ''
|
||||
@@ -96,6 +98,7 @@ export async function fetchTestPublications(query: TestPublicationQuery, signal?
|
||||
const parameters = new URLSearchParams()
|
||||
if (query.processing_state) parameters.set('processing_state', Array.isArray(query.processing_state) ? query.processing_state.join(',') : query.processing_state)
|
||||
if (query.target_scope) parameters.set('target_scope', query.target_scope)
|
||||
if (query.removal) parameters.set('removal', query.removal)
|
||||
parameters.set('limit', String(query.limit))
|
||||
parameters.set('offset', String(query.offset))
|
||||
const response = await fetch(`/api/v1/test-publications?${parameters.toString()}`, { headers: { Accept: 'application/json' }, signal })
|
||||
@@ -103,6 +106,32 @@ export async function fetchTestPublications(query: TestPublicationQuery, signal?
|
||||
return parseTestPublicationsResponse(await response.json())
|
||||
}
|
||||
|
||||
/**
|
||||
* 需下架车道用:列出「来源侧被判禁止导入、但知识仍存活在测试库里」的具体条目。
|
||||
* 此前车道只有按库计数,运维看不到条目、也没有处置入口。
|
||||
*/
|
||||
export async function fetchRemovalRequiredPublications(signal?: AbortSignal): Promise<TestPublicationPage> {
|
||||
return fetchTestPublications({ processing_state: '', removal: 'required', limit: 50, offset: 0 }, signal)
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发移除:把该条目置为下架中,交服务端既有的 test.remove 工作流去删远端知识并读回校验。
|
||||
* 服务端按条目幂等(重复点击不会重复入队),因此这里每次生成新的幂等键是安全的。
|
||||
*/
|
||||
export async function startPublicationRemoval(publicationId: string): Promise<{ job_id: string }> {
|
||||
const response = await fetch(`/api/v1/test-publications/${encodeURIComponent(publicationId)}/removal`, {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json', 'Idempotency-Key': newOperationID() },
|
||||
})
|
||||
if (response.status !== 202) {
|
||||
const body = (await response.json().catch(() => null)) as { error?: string } | null
|
||||
throw new Error(body?.error ?? `触发下架失败(HTTP ${response.status})`)
|
||||
}
|
||||
const value = await response.json() as unknown
|
||||
if (!isRecord(value) || typeof value.job_id !== 'string') throw new Error('下架响应无效')
|
||||
return { job_id: value.job_id }
|
||||
}
|
||||
|
||||
export async function fetchAcceptanceResults(publicationId: string, signal?: AbortSignal): Promise<AcceptanceRecord[]> {
|
||||
const response = await fetch(`/api/v1/test-publications/${encodeURIComponent(publicationId)}/acceptance`, { headers: { Accept: 'application/json' }, signal })
|
||||
if (!response.ok) throw new Error(`加载验收结果失败(HTTP ${response.status})`)
|
||||
|
||||
Reference in New Issue
Block a user