fix(api): 执行明细补齐 action 与目标知识库字段
逐项明细 DTO 漏了 action(前端 parseReleaseItemExecution 必需),点 「查看结果」整个明细区报 invalid release item execution。同时把遷移 000044 的 target_knowledge_base_id 读出来透出,页面逐项结果显示「目标库」, 让'目标知识库可选'在界面上可核对。测试:Go 契约用例 + 前端解析回归用例。
This commit is contained in:
@@ -343,7 +343,7 @@ describe('ReleaseManagement', () => {
|
||||
items: [{ id: 'rx-auto', release_batch_id: 'rb-safe', operation: 'rollback', prior_execution_id: 'rx-safe', state: 'running', target_environment: 'production', authorized_by: 'system:auto-rollback', job_id: 'job-auto', item_count: 1, batch_size: 50, current_batch: 1, total_batches: 1, completed_item_count: 0, failed_item_count: 0, error_code: '', created_at: now, started_at: now, completed_at: null }, { id: 'rx-safe', release_batch_id: 'rb-safe', operation: 'publish', prior_execution_id: '', state: 'failed', target_environment: 'production', authorized_by: 'owner', job_id: 'job-safe', item_count: 2, batch_size: 50, current_batch: 1, total_batches: 1, completed_item_count: 1, failed_item_count: 1, error_code: 'release_item_failed', created_at: priorNow, started_at: priorNow, completed_at: priorNow }],
|
||||
total: 2, limit: 20, offset: 0,
|
||||
}
|
||||
const executionDetail: ReleaseExecutionDetail = { ...executionPage.items[0], items: [{ publication_id: 'tp-safe', title: 'Synthetic', action: 'delete', state: 'verified', previous_production_revision: 'prod-v0', production_revision: 'absent', error_code: '', created_at: now, completed_at: now }, { publication_id: 'tp-restored', title: 'Restored', action: 'delete', state: 'rolled_back', previous_production_revision: 'prod-v0', production_revision: 'prod-v0', error_code: '', created_at: now, completed_at: now }] }
|
||||
const executionDetail: ReleaseExecutionDetail = { ...executionPage.items[0], items: [{ publication_id: 'tp-safe', title: 'Synthetic', action: 'delete', state: 'verified', previous_production_revision: 'prod-v0', production_revision: 'absent', error_code: '', created_at: now, completed_at: now, target_knowledge_base_id: '0b217e8a-2a65-40a3-ab8f-34ac5c7a6f05' }, { publication_id: 'tp-restored', title: 'Restored', action: 'delete', state: 'rolled_back', previous_production_revision: 'prod-v0', production_revision: 'prod-v0', error_code: '', created_at: now, completed_at: now, target_knowledge_base_id: '0b217e8a-2a65-40a3-ab8f-34ac5c7a6f05' }] }
|
||||
const releasePlan: ReleasePlan = { items: [{ publication_id: 'tp-safe', title: 'B.pdf', target_scope: 'external', action: 'add', test_state: 'ready', production_state: 'absent', can_release: true, blocker: '' }, { publication_id: 'tp-delete', title: 'C.pdf', target_scope: 'internal', action: 'delete', test_state: 'not_required', production_state: 'present', can_release: true, blocker: '' }, { publication_id: '', title: 'D.pdf', target_scope: 'internal', action: 'blocked', test_state: 'ready', production_state: 'present', can_release: false, blocker: 'source_unavailable' }], summary: { add: 1, update: 0, delete: 1, blocked: 1, unchanged: 11284 } }
|
||||
const html = renderToStaticMarkup(<ReleaseManagement
|
||||
reviewPage={reviewPage} reviewLoading={false} reviewError={null} reviewingId={null}
|
||||
|
||||
+1
-1
@@ -1060,7 +1060,7 @@ export function ReleaseManagement(props: ReleaseManagementProps) {
|
||||
{!props.executionLoading && !props.executionError && props.executionPage.items.length === 0 ? <div className="empty-state">尚无生产发布或回滚执行记录。</div> : null}
|
||||
{props.executionPage.items.length > 0 ? <div className="batch-grid execution-grid"><div className="table-wrap"><table><thead><tr><th>开始时间</th><th>操作</th><th>状态</th><th>批次进度</th><th>完成进度</th><th>授权人</th><th>操作</th></tr></thead><tbody>
|
||||
{props.executionPage.items.map((execution) => <tr key={execution.id}><td>{formatTime(execution.created_at)}</td><td>{execution.operation === 'publish' ? '发布' : '回滚'}</td><td><span className={`status status-${execution.state}`}>{executionLabels[execution.state]}</span>{executionStateDetail(execution, props.executionPage.items) ? <small>{executionStateDetail(execution, props.executionPage.items)}</small> : null}{execution.error_code ? <small>{releaseFailureMessage(execution.error_code)}</small> : null}</td><td>{execution.total_batches>0?`批次 ${execution.current_batch} / ${execution.total_batches}`:'等待开始'}<small>每批最多 {execution.batch_size} 项</small></td><td>{execution.completed_item_count}/{execution.item_count}{execution.failed_item_count ? <small>失败 {execution.failed_item_count}</small> : null}</td><td>{execution.authorized_by}</td><td><div className="row-actions"><button type="button" className="secondary-action" onClick={() => props.onSelectExecution(execution.id)}>查看结果</button>{isAdmin && execution.state === 'failed' ? <button type="button" onClick={() => props.onStartReleaseAction?.('retry', execution.id, `执行 ${execution.id.slice(0, 8)}…`)}>重排</button> : null}{isAdmin && execution.operation === 'publish' && execution.state === 'completed' ? <button type="button" onClick={() => props.onStartReleaseAction?.('rollback', execution.id, `执行 ${execution.id.slice(0, 8)}…`)}>回滚</button> : null}</div></td></tr>)}
|
||||
</tbody></table></div><div className="batch-detail execution-detail"><h3>每项知识的结果</h3>{props.executionDetail ? <>{props.executionDetail.items.map((item) => { const result = releaseItemResult(item); return <div className="batch-detail-row execution-detail-row" key={item.publication_id}><span><strong>{item.title}</strong><small>{result.detail}{item.error_code ? ` · ${releaseFailureMessage(item.error_code)}` : ''}</small></span><span><b>{result.outcome}</b></span></div> })}{props.executionDetail.items.length === 0 ? <div className="empty-state">发布尚无逐项结果。</div> : null}</> : <div className="empty-state">点击“查看结果”核对每项知识。</div>}</div></div> : null}
|
||||
</tbody></table></div><div className="batch-detail execution-detail"><h3>每项知识的结果</h3>{props.executionDetail ? <>{props.executionDetail.items.map((item) => { const result = releaseItemResult(item); return <div className="batch-detail-row execution-detail-row" key={item.publication_id}><span><strong>{item.title}</strong><small>{result.detail}{item.target_knowledge_base_id ? ` · 目标库 ${item.target_knowledge_base_id.slice(0, 8)}…` : ''}{item.error_code ? ` · ${releaseFailureMessage(item.error_code)}` : ''}</small></span><span><b>{result.outcome}</b></span></div> })}{props.executionDetail.items.length === 0 ? <div className="empty-state">发布尚无逐项结果。</div> : null}</> : <div className="empty-state">点击“查看结果”核对每项知识。</div>}</div></div> : null}
|
||||
{props.executionChain ? <div className="release-audit-chain">
|
||||
<h3>发布审计链</h3>
|
||||
<div className="audit-chain-line"><span>批次</span><b>{props.executionChain.release_batch_name || '未绑定批次'}</b><small>{`创建 ${props.executionChain.created_by || '—'} · 锁定 ${props.executionChain.sealed_by || '—'} · 授权 ${props.executionChain.authorized_by || '—'}`}</small></div>
|
||||
|
||||
@@ -114,11 +114,17 @@ describe('release execution audit parsing', () => {
|
||||
expect(page.items[0]).toMatchObject({ batch_size: 50, current_batch: 2, total_batches: 3 })
|
||||
expect(page.items[0]).not.toHaveProperty('authorization_code')
|
||||
expect(page.items[0]).not.toHaveProperty('manifest_sha256')
|
||||
const detail = parseReleaseExecutionDetailResponse({ data: { ...execution, items: [{ publication_id: 'tp-safe', title: 'Synthetic', action: 'delete', state: 'verified', previous_production_revision: 'prod-v0', production_revision: 'absent', error_code: '', created_at: '2026-09-06T10:00:00Z', completed_at: '2026-09-06T10:02:00Z', knowledge_id: 'must-drop' }] } })
|
||||
expect(detail.items[0]).toEqual({ publication_id: 'tp-safe', title: 'Synthetic', action: 'delete', state: 'verified', previous_production_revision: 'prod-v0', production_revision: 'absent', error_code: '', created_at: '2026-09-06T10:00:00Z', completed_at: '2026-09-06T10:02:00Z' })
|
||||
const detail = parseReleaseExecutionDetailResponse({ data: { ...execution, items: [{ publication_id: 'tp-safe', title: 'Synthetic', action: 'delete', state: 'verified', previous_production_revision: 'prod-v0', production_revision: 'absent', error_code: '', created_at: '2026-09-06T10:00:00Z', completed_at: '2026-09-06T10:02:00Z', target_knowledge_base_id: 'kb-target-1', knowledge_id: 'must-drop' }] } })
|
||||
expect(detail.items[0]).toEqual({ publication_id: 'tp-safe', title: 'Synthetic', action: 'delete', state: 'verified', previous_production_revision: 'prod-v0', production_revision: 'absent', error_code: '', created_at: '2026-09-06T10:00:00Z', completed_at: '2026-09-06T10:02:00Z', target_knowledge_base_id: 'kb-target-1' })
|
||||
expect(parseReleaseCapabilitiesResponse({ data: { production_release_requests_enabled: true, production_backup_restore_verified: false, secret: 'drop' } })).toEqual({ production_release_requests_enabled: true, production_backup_restore_verified: false })
|
||||
})
|
||||
|
||||
it('rejects a release item execution the API forgot to describe', () => {
|
||||
// 线上 DTO 曾漏 action:一条明细不合法就让整个明细区报 invalid release item execution。
|
||||
const missingAction = { publication_id: 'tp-safe', title: 'Synthetic', state: 'verified', previous_production_revision: 'prod-v0', production_revision: 'absent', error_code: '', created_at: '2026-09-06T10:00:00Z', completed_at: null }
|
||||
expect(() => parseReleaseExecutionDetailResponse({ data: { ...execution, items: [missingAction] } })).toThrow('invalid release item execution')
|
||||
})
|
||||
|
||||
it('fetches only read-only execution audit endpoints', async () => {
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(new Response(JSON.stringify({ data: [execution], total: 1, limit: 20, offset: 0 }), { status: 200 }))
|
||||
|
||||
@@ -113,6 +113,7 @@ export interface ReleaseItemExecution {
|
||||
error_code: string
|
||||
created_at: string
|
||||
completed_at: string | null
|
||||
target_knowledge_base_id: string
|
||||
}
|
||||
|
||||
export interface ReleaseExecutionDetail extends ReleaseExecution {
|
||||
@@ -450,6 +451,7 @@ function parseReleaseItemExecution(raw: unknown): ReleaseItemExecution {
|
||||
return {
|
||||
publication_id: raw.publication_id, title: raw.title, action: raw.action, state: raw.state as ReleaseItemExecution['state'],
|
||||
previous_production_revision: raw.previous_production_revision, production_revision: raw.production_revision,
|
||||
target_knowledge_base_id: typeof raw.target_knowledge_base_id === 'string' ? raw.target_knowledge_base_id : '',
|
||||
error_code: raw.error_code, created_at: raw.created_at, completed_at: raw.completed_at as string | null,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user