acf053faf3
背景:发布管理把"逐条核验"的仪式强加给每一份文档。实测一份文档要 9~11 次交互,
且有两处顺序陷阱(冻结后批准 → 建批 422;生成即固化 → 批准被永久钉住)。
P0-1 建批时冻结:
- CreateReleaseBatch 在未指定版本时,自己把当前实时计划冻结成一份**已确认**版本并绑定
(同一事务;同摘要复用最近版本,planned 或 confirmed 都可复用,因此同一份计划不堆版本)。
- 语义不变:批一旦建立,清单/摘要/验收轮次/目标库绑定全部不可变、回滚按它走;变的只是
"谁在什么时候按固化键"——从操作员的手动两步变成建批这一下。
- 效果:去掉「生成新版本」「确认冻结」两步;消灭"批准晚于冻结 → 422"这类顺序陷阱;
前端不再传版本 id,也不再有"所选知识不在冻结清单里"的阻断。
- 计划→清单项的映射抽成 ChangeSetItemsFromPlan 供两处共用,否则两处算出的摘要不同,
"同一计划复用同一版本"永远不命中。
P0-2 验收通过自动批准:
- 验收三项结论达发布门槛(knowledge_exists/chunks_present=passed,retrieval_hit 与门槛同
口径)时,由 worker 写入 reviewer_ref='system:auto' 的批准记录,替代"每份文档点一次批准"。
- 策略 TEST_AUTO_REVIEW_POLICY = off | internal(默认,仅对内)| all;值不认识拒绝启动。
只影响审核这一步:生产授权、双闸与发布前快照门禁不受影响。界面上只读展示当前策略。
- 安全边界(写死在审核 SQL 里):系统只允许写"第一条"审核——人工一旦表过态,机器不得用一条
更晚的 approved 把人工结论翻回去;人工随时可再审。集成测试去掉该约束即 FAIL(已实测)。
- 自动批准自身的任何失败都不影响验收结论,只上报。
顺带(P1-1 前半,已被 P0-1 取代的部分已删除):
- 写操作失败把服务端 {"error": ...} 的原因带出来,并对已知原因给出下一步(不再只给 HTTP 状态码)。
- 当前的"不在已冻结清单里"标注与就地修复按钮随 P0-1 一起移除(该失败模式已不存在)。
测试:bind_time_freeze_integration_test.go(绑定已确认版本/同计划复用/冻结后不可变/
动作不符仍 NotEligible)、auto_review_integration_test.go(系统只写第一条、人工可再审)、
validate_test.go(对内自动/对外不自动/策略关闭/验收未过不批/自身失败不影响验收)、
auto_review_test.go、config_test 及前端能力解析测试。
实测耗时:本机 Go 全量 26 包通过、前端 178 条通过。
528 lines
31 KiB
TypeScript
528 lines
31 KiB
TypeScript
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import App, { JobDashboard, KnowledgeInventory, ModulePage, ReleaseManagement, SourceConnections, WorkspaceShell, reviewGateLabel } from './App'
|
|
import { AuthContext } from './auth'
|
|
import type { SourceAssetPage } from './assets'
|
|
import type { Job } from './jobs'
|
|
import type { ReleaseBatchDetail, ReleaseBatchPage, ReleaseExecutionDetail, ReleaseExecutionPage, ReleasePlan, ReviewCandidatePage } from './reviewRelease'
|
|
import type { SourceConnectionPage, SourceScanDetail, SourceScanPage } from './sourceConnections'
|
|
|
|
const baseJob: Job = {
|
|
id: 'job-1',
|
|
type: 'demo',
|
|
payload: {},
|
|
state: 'pending',
|
|
priority: 0,
|
|
available_at: '2026-09-03T13:00:00Z',
|
|
attempt: 0,
|
|
max_attempts: 5,
|
|
idempotency_key: 'demo:1',
|
|
created_at: '2026-09-03T13:00:00Z',
|
|
updated_at: '2026-09-03T13:00:00Z',
|
|
}
|
|
|
|
describe('WorkspaceShell', () => {
|
|
it('renders the approved modules in the left navigation', () => {
|
|
const html = renderToStaticMarkup(
|
|
<WorkspaceShell
|
|
workspace={{ openTabs: ['dashboard'], activeTab: 'dashboard' }}
|
|
onOpen={vi.fn()}
|
|
onClose={vi.fn()}
|
|
>
|
|
<div>工作区内容</div>
|
|
</WorkspaceShell>,
|
|
)
|
|
|
|
expect(html).toContain('aria-label="功能导航"')
|
|
for (const label of ['来源与目录', '解析监控', '发布管理', '系统设置']) {
|
|
expect(html).toContain(label)
|
|
}
|
|
expect(html).not.toContain('来源链接')
|
|
expect(html).not.toContain('待处理文件')
|
|
expect(html).toContain('本地治理环境')
|
|
expect(html).not.toContain('P2 本地治理环境')
|
|
})
|
|
|
|
it('renders open tabs and marks the active tab', () => {
|
|
const html = renderToStaticMarkup(
|
|
<WorkspaceShell
|
|
workspace={{ openTabs: ['dashboard', 'tasks', 'releases'], activeTab: 'tasks' }}
|
|
onOpen={vi.fn()}
|
|
onClose={vi.fn()}
|
|
>
|
|
<div>工作区内容</div>
|
|
</WorkspaceShell>,
|
|
)
|
|
|
|
expect(html).toContain('aria-label="已打开页面"')
|
|
expect(html).toContain('来源与目录')
|
|
expect(html).toContain('解析监控')
|
|
expect(html).toContain('发布管理')
|
|
expect(html).toContain('aria-current="page"')
|
|
})
|
|
|
|
it('offers close controls only for unpinned tabs', () => {
|
|
const html = renderToStaticMarkup(
|
|
<WorkspaceShell
|
|
workspace={{ openTabs: ['dashboard', 'tasks'], activeTab: 'tasks' }}
|
|
onOpen={vi.fn()}
|
|
onClose={vi.fn()}
|
|
>
|
|
<div>工作区内容</div>
|
|
</WorkspaceShell>,
|
|
)
|
|
|
|
expect(html).toContain('aria-label="关闭解析监控标签"')
|
|
expect(html).not.toContain('aria-label="关闭来源与目录标签"')
|
|
})
|
|
|
|
it('renders a collapsed mobile navigation control', () => {
|
|
const html = renderToStaticMarkup(
|
|
<WorkspaceShell
|
|
workspace={{ openTabs: ['dashboard'], activeTab: 'dashboard' }}
|
|
onOpen={vi.fn()}
|
|
onClose={vi.fn()}
|
|
>
|
|
<div>工作区内容</div>
|
|
</WorkspaceShell>,
|
|
)
|
|
|
|
expect(html).toContain('aria-label="切换功能导航"')
|
|
expect(html).toContain('aria-expanded="false"')
|
|
})
|
|
})
|
|
|
|
describe('App', () => {
|
|
it('renders the dashboard inside the multi-tab workspace by default', () => {
|
|
const html = renderToStaticMarkup(<App />)
|
|
|
|
expect(html).toContain('aria-label="功能导航"')
|
|
expect(html).toContain('aria-label="已打开页面"')
|
|
expect(html).toContain('<h1>来源与目录</h1>')
|
|
expect(html).not.toContain('最近任务')
|
|
})
|
|
})
|
|
|
|
describe('ModulePage', () => {
|
|
it('renders the governance overview for the dashboard module', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ModulePage
|
|
moduleId="dashboard"
|
|
jobs={[baseJob, { ...baseJob, id: 'job-2', state: 'completed' }]}
|
|
loading={false}
|
|
error={null}
|
|
onRefresh={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
expect(html).toContain('治理工作台')
|
|
expect(html).toContain('P2 · 知识治理总览')
|
|
expect(html).toContain('PP历史来源清单已接管')
|
|
expect(html).toContain('生产写入:关闭')
|
|
expect(html).toContain('以「系统设置 → 服务配置」的实时探测为准')
|
|
expect(html).not.toContain('本地测试WeKnora已连接')
|
|
expect(html).not.toContain('生产WeKnora仍未连接')
|
|
expect(html).not.toContain('尚未连接测试或生产WeKnora')
|
|
expect(html).toContain('任务概览')
|
|
expect(html).toContain('Release Worker 默认关闭')
|
|
expect(html).toContain('最近任务')
|
|
expect(html).toContain('job-2')
|
|
})
|
|
|
|
it('renders the test publication table for the tasks module', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ModulePage
|
|
moduleId="tasks"
|
|
jobs={[]}
|
|
loading={false}
|
|
error={null}
|
|
onRefresh={vi.fn()}
|
|
publicationPage={{
|
|
items: [{
|
|
id: 'pub-1', title: 'Safe title', ingest_state: 'failed', processing_state: 'failed',
|
|
retrieval_state: 'unpublished', target_scope: 'internal', change_set_id: 'cs-1', change_type: 'added', can_start: false,
|
|
retry_count: 2, last_error: 'remote_parse_failed',
|
|
can_retry: true, updated_at: '2026-09-04T05:00:00Z',
|
|
}],
|
|
total: 1,
|
|
limit: 50,
|
|
offset: 0,
|
|
}}
|
|
publicationLoading={false}
|
|
publicationError={null}
|
|
publicationState=""
|
|
onPublicationStateChange={vi.fn()}
|
|
onPublicationPageChange={vi.fn()}
|
|
onPublicationRefresh={vi.fn()}
|
|
onRetry={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
expect(html).toContain('<h1>解析监控</h1>')
|
|
expect(html).toContain('总体概览')
|
|
expect(html).toContain('失败或停滞')
|
|
expect(html).toContain('pub-1')
|
|
expect(html).toContain('remote_parse_failed')
|
|
expect(html).toContain('重试')
|
|
})
|
|
|
|
it('renders the real inventory for the knowledge module', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ModulePage
|
|
moduleId="knowledge"
|
|
jobs={[]}
|
|
loading={false}
|
|
error={null}
|
|
onRefresh={vi.fn()}
|
|
assetPage={{ items: [], summary: { total: 613, completed: 530, content_alias: 29, over_limit: 54 }, limit: 50, offset: 0 }}
|
|
assetLoading={false}
|
|
assetError={null}
|
|
assetState=""
|
|
onAssetStateChange={vi.fn()}
|
|
onAssetPageChange={vi.fn()}
|
|
onAssetRefresh={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
expect(html).toContain('统一治理清单')
|
|
expect(html).toContain('613')
|
|
expect(html).not.toContain('功能将在后续阶段接入')
|
|
})
|
|
|
|
it('renders the real source connection workbench', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ModulePage
|
|
moduleId="sources"
|
|
jobs={[]}
|
|
loading={false}
|
|
error={null}
|
|
onRefresh={vi.fn()}
|
|
connectionPage={{
|
|
items: [
|
|
{
|
|
id: 'conn-pp', source_type: 'pp', name: 'PP历史公开知识', enabled: false,
|
|
schedule_configured: false, health_status: 'healthy', item_count: 613, updated_at: '2026-09-06T01:00:00Z',
|
|
last_scan: {
|
|
id: 'scan-1', state: 'completed', observed_items: 613, unchanged_items: 559,
|
|
added_items: 0, updated_items: 0, over_limit_items: 54, missing_items: 0,
|
|
planned_uploads: 0, error_code: '', created_at: '2026-09-06T00:59:00Z', completed_at: '2026-09-06T01:00:00Z',
|
|
},
|
|
},
|
|
{ id: 'conn-alist', source_type: 'alist', name: 'AList只读源', enabled: true, schedule_configured: true, health_status: 'healthy', item_count: 42, updated_at: '2026-09-06T01:00:00Z' },
|
|
],
|
|
summary: { total: 2, enabled: 1, disabled: 1, healthy: 1, degraded: 0, unhealthy: 0, unknown: 1 },
|
|
}}
|
|
connectionLoading={false}
|
|
connectionError={null}
|
|
onConnectionRefresh={vi.fn()}
|
|
scanningConnectionId={null}
|
|
onTriggerSourceScan={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
expect(html).toContain('<h1>来源连接</h1>')
|
|
expect(html).not.toContain('<code>conn-pp</code>')
|
|
for (const text of ['来源连接', 'PP历史公开知识', 'AList只读源', '613', '已配置', '健康', '最近扫描', '未变化 559', '超过上限 54', '检查快照变化']) {
|
|
expect(html).toContain(text)
|
|
}
|
|
expect(html).toContain('class="source-connections-table"')
|
|
expect(html).not.toContain('将在后续阶段接入')
|
|
})
|
|
})
|
|
|
|
describe('KnowledgeInventory', () => {
|
|
it('renders real source summary and safe paginated asset fields', () => {
|
|
const page: SourceAssetPage = {
|
|
items: [{
|
|
id: 'si-safe', source_type: 'pp', connection_name: 'PP历史公开知识', size_bytes: 52428801,
|
|
visibility: 'external', source_change: 'unchanged', content_state: 'over_limit', legacy_status: 'over_limit',
|
|
has_publication: false, processing_state: '', retrieval_state: '', updated_at: '2026-09-04T00:00:00Z',
|
|
}, {
|
|
id: 'si-manual', source_type: 'manual' as never, connection_name: '本地验收', size_bytes: 128,
|
|
visibility: 'internal', source_change: 'added', content_state: 'verified', legacy_status: '',
|
|
has_publication: true, processing_state: 'pending', retrieval_state: 'unpublished', updated_at: '2026-09-05T00:00:00Z',
|
|
}],
|
|
summary: { total: 613, completed: 530, content_alias: 29, over_limit: 54 },
|
|
limit: 50,
|
|
offset: 0,
|
|
}
|
|
const html = renderToStaticMarkup(
|
|
<KnowledgeInventory page={page} loading={false} error={null} state="" onStateChange={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />,
|
|
)
|
|
|
|
for (const text of ['知识资产', '613', '530', '29', '54', 'PP', '手工验收', '50.0 MiB', '超过旧同步上限']) {
|
|
expect(html).toContain(text)
|
|
}
|
|
expect(html).toContain('统一来源清单')
|
|
expect(html).not.toContain('当前展示PP历史公开来源')
|
|
})
|
|
})
|
|
|
|
describe('SourceConnections scan workbench', () => {
|
|
it('renders scan history and selected safe change records', () => {
|
|
const now = '2026-09-06T06:00:00Z'
|
|
const page: SourceConnectionPage = {
|
|
items: [{ id: 'conn-pp', source_type: 'pp', name: 'PP历史公开知识', enabled: false, schedule_configured: false, health_status: 'healthy', item_count: 613, updated_at: now }],
|
|
summary: { total: 1, enabled: 0, disabled: 1, healthy: 1, degraded: 0, unhealthy: 0, unknown: 0 },
|
|
}
|
|
const scanPage: SourceScanPage = {
|
|
items: [{ id: 'scan-1', state: 'completed', observed_items: 613, unchanged_items: 558, added_items: 0, updated_items: 1, over_limit_items: 54, missing_items: 0, planned_uploads: 1, error_code: '', created_at: now, completed_at: now }],
|
|
total: 1, limit: 20, offset: 0,
|
|
}
|
|
const detail: SourceScanDetail = {
|
|
...scanPage.items[0], changes: [{ id: 'chg-1', source_item_id: 'si-safe', change_type: 'updated', observed_size_bytes: 2048, created_at: now }],
|
|
}
|
|
const html = renderToStaticMarkup(<SourceConnections
|
|
page={page} loading={false} error={null} scanningConnectionId={null}
|
|
scanPage={scanPage} scanDetail={detail} scanLoading={false} scanError={null}
|
|
selectedScanId="scan-1" onRefresh={vi.fn()} onTriggerScan={vi.fn()} onSelectScan={vi.fn()}
|
|
/>)
|
|
for (const text of ['扫描历史与变化记录', 'scan-1', '已选择', '变化记录', '内容更新', 'si-safe', '2.0 KiB']) {
|
|
expect(html).toContain(text)
|
|
}
|
|
expect(html).not.toContain('stable_external_id')
|
|
expect(html).not.toContain('observed_revision')
|
|
})
|
|
|
|
it('states explicitly when a selected scan has no changes', () => {
|
|
const now = '2026-09-06T06:00:00Z'
|
|
const scan = { id: 'scan-1', state: 'completed' as const, observed_items: 613, unchanged_items: 559, added_items: 0, updated_items: 0, over_limit_items: 54, missing_items: 0, planned_uploads: 0, error_code: '', created_at: now, completed_at: now }
|
|
const html = renderToStaticMarkup(<SourceConnections
|
|
page={{ items: [], summary: { total: 0, enabled: 0, disabled: 0, healthy: 0, degraded: 0, unhealthy: 0, unknown: 0 } }}
|
|
loading={false} error={null} scanningConnectionId={null}
|
|
scanPage={{ items: [scan], total: 1, limit: 20, offset: 0 }} scanDetail={{ ...scan, changes: [] }} scanLoading={false} scanError={null}
|
|
selectedScanId="scan-1" onRefresh={vi.fn()} onTriggerScan={vi.fn()} onSelectScan={vi.fn()}
|
|
/>)
|
|
expect(html).toContain('本次扫描未发现新增、更新或不可用变化')
|
|
})
|
|
})
|
|
|
|
describe('JobDashboard', () => {
|
|
it('renders summary counts and task states', () => {
|
|
const html = renderToStaticMarkup(
|
|
<JobDashboard
|
|
jobs={[
|
|
baseJob,
|
|
{ ...baseJob, id: 'job-2', state: 'running', attempt: 1 },
|
|
{ ...baseJob, id: 'job-3', state: 'completed', attempt: 1 },
|
|
]}
|
|
loading={false}
|
|
error={null}
|
|
onRefresh={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
expect(html).toContain('同步任务')
|
|
expect(html).toContain('任务总数')
|
|
expect(html).toContain('>3<')
|
|
expect(html).toContain('运行中')
|
|
expect(html).toContain('已完成')
|
|
expect(html).toContain('job-2')
|
|
})
|
|
})
|
|
|
|
describe('ReleaseManagement', () => {
|
|
it('renders human review, draft and seal gates without implying production release', () => {
|
|
const now = '2026-09-06T10:00:00Z'
|
|
const priorNow = '2026-09-06T09:00:00Z'
|
|
const reviewPage: ReviewCandidatePage = {
|
|
items: [{
|
|
publication_id: 'tp-safe', title: 'Synthetic', source_type: 'manual', current_visibility: 'internal',
|
|
knowledge_exists: 'passed', chunks_present: 'passed', retrieval_hit: 'manual_required',
|
|
gate_status: 'ready', gate_code: 'ready', review_state: 'pending', decided_visibility: '', decision_code: '',
|
|
reviewer_ref: '', reviewed_at: null, updated_at: now,
|
|
}], total: 1, limit: 20, offset: 0,
|
|
}
|
|
const batchPage: ReleaseBatchPage = {
|
|
items: [{ id: 'rb-safe', name: 'Synthetic batch', state: 'draft', policy_version: 'release-gate-v1', created_by: 'engineer-1', sealed_by: '', item_count: 1, created_at: now, sealed_at: null }],
|
|
total: 1, limit: 20, offset: 0,
|
|
}
|
|
const batchDetail: ReleaseBatchDetail = { ...batchPage.items[0], items: [{ publication_id: 'tp-safe', title: 'Synthetic', decided_visibility: 'internal', action: 'delete' }] }
|
|
const executionPage: ReleaseExecutionPage = {
|
|
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, 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}
|
|
batchPage={batchPage} batchDetail={batchDetail} batchLoading={false} batchError={null} mutatingBatchId={null}
|
|
onReview={vi.fn()} onReviewRefresh={vi.fn()} onCreateBatch={vi.fn()} onSealBatch={vi.fn()} onSelectBatch={vi.fn()} onBatchRefresh={vi.fn()}
|
|
releaseCapabilities={{ production_release_requests_enabled: true, production_backup_restore_verified: false, test_auto_review_policy: '' }} executionPage={executionPage} executionDetail={executionDetail} executionLoading={false} executionError={null} onSelectExecution={vi.fn()} onExecutionRefresh={vi.fn()}
|
|
releasePlan={releasePlan}
|
|
selectedDeleteIDs={['tp-delete']} onToggleDelete={vi.fn()}
|
|
/>)
|
|
for (const text of ['来源与目录 → 测试知识库 → 生产知识库','自动发布计划','新增 1','更新 0','删除 1','未变化 11284','B.pdf','C.pdf','D.pdf','将从生产检索中移除','我确认所选删除项会停止生产检索','已选择删除:1(待确认)','已选 1 项(删除待确认)','为什么按钮不能点:请确认所选删除项会停止生产检索;至少 1 项动作通过确认;请填写批次名称','至少 1 项动作通过确认','来源当前不可用,保留生产知识','正在执行自动回滚','批次 1 / 1','每批最多 50 项','Snapshot #20260906-090000Z','审核要发布的知识', '需人工确认', '批准', '驳回', '创建草稿批次', '锁定清单(不会上线)', 'Synthetic batch', '删除生产知识', '已从生产检索中移除', '已恢复生产知识', '仍可检查调整', 'Release Worker保持关闭', '锁定清单 ≠ 上线', '生产确认、发布验证与回滚', '生产操作权限:已阻断', '生产请求门禁已开启', '快照恢复验证未通过', '生产发布已阻断']) {
|
|
expect(html).toContain(text)
|
|
}
|
|
for (const text of [
|
|
'从检查到发布,只走这 8 步',
|
|
'1. 查看来源变化',
|
|
'2. 确认测试结果',
|
|
'3. 审核发布内容',
|
|
'4. 创建发布批次',
|
|
'5. 锁定发布清单',
|
|
'6. 生产负责人确认',
|
|
'7. 发布并验证',
|
|
'8. 必要时回滚',
|
|
'当前在第 3 步,共 8 步',
|
|
'现在要做:审核 1 项知识',
|
|
'还有 1 项等待审核;已批准文件可先创建批次',
|
|
'完成本步的 3 件事',
|
|
'只审核本次准备发布的文件',
|
|
'勾选要发布的已批准知识',
|
|
'填写批次名称并创建草稿',
|
|
'现在先做:逐条选择“批准”或“驳回”(操作自动记在当前登录人名下)',
|
|
'完成后进入:第 4 步,创建发布批次',
|
|
'为什么按钮不能点:请确认所选删除项会停止生产检索',
|
|
'如何决定批准或驳回',
|
|
'可以批准:基础测试通过,你已确认搜索结果相关,而且发布范围正确',
|
|
'应该驳回:内容错误、过期、敏感、搜索结果不相关,或者你无法确认',
|
|
'创建批次还需要',
|
|
'确认所选发布动作',
|
|
'查看审核与发布说明',
|
|
'至少 1 项动作通过确认',
|
|
'填写批次名称',
|
|
'普通业务操作,不会影响生产',
|
|
'生产危险操作',
|
|
]) {
|
|
expect(html).toContain(text)
|
|
}
|
|
expect(html).not.toContain('>授权生产发布</button>')
|
|
expect(html).not.toContain('knowledge_id')
|
|
expect(html).not.toContain('acceptance_run_id')
|
|
expect(html).toContain('aria-label="选择删除C.pdf"')
|
|
expect(html).toContain('筛选 3 / 全部 3')
|
|
expect(html).toContain('aria-label="确认删除生产知识"')
|
|
expect(html).toContain('class="plan-delete"')
|
|
expect(html).toContain('<span class="unmet">至少 1 项动作通过确认</span>')
|
|
expect(reviewGateLabel({ review_state: 'approved', gate_status: 'ready' })).toBe('测试已通过')
|
|
expect(reviewGateLabel({ review_state: 'pending', gate_status: 'ready' })).toBe('可以审核')
|
|
for (const technicalValue of ['tp-safe', 'rb-safe', 'rx-safe', 'job-safe', 'release-gate-v1', 'prod-v0', 'prod-v1', '>verified<']) {
|
|
expect(html).not.toContain(technicalValue)
|
|
}
|
|
expect(html).not.toContain('工程师标识')
|
|
})
|
|
})
|
|
|
|
describe('release plan pagination (R3)', () => {
|
|
const baseProps = {
|
|
reviewPage: { items: [], total: 0, limit: 20, offset: 0 } as any,
|
|
reviewLoading: false, reviewError: null, reviewingId: null,
|
|
batchPage: { items: [], total: 0, limit: 20, offset: 0 } as any,
|
|
batchDetail: null, batchLoading: false, batchError: null, mutatingBatchId: null,
|
|
onReview: vi.fn(), onReviewRefresh: vi.fn(), onCreateBatch: vi.fn(), onSealBatch: vi.fn(), onSelectBatch: vi.fn(), onBatchRefresh: vi.fn(),
|
|
releaseCapabilities: { production_release_requests_enabled: false, production_backup_restore_verified: false, test_auto_review_policy: '' },
|
|
executionPage: { items: [], total: 0, limit: 20, offset: 0 } as any,
|
|
executionDetail: null, executionLoading: false, executionError: null, onSelectExecution: vi.fn(), onExecutionRefresh: vi.fn(),
|
|
selectedDeleteIDs: [] as string[], onToggleDelete: vi.fn(),
|
|
}
|
|
const planWith = (count: number): ReleasePlan => ({
|
|
items: Array.from({ length: count }, (_, i) => ({ publication_id: `tp-${i}`, title: `文档${i}.pdf`, target_scope: 'internal' as const, action: 'add' as const, test_state: 'ready', production_state: 'absent', can_release: true, blocker: '' })),
|
|
summary: { add: count, update: 0, delete: 0, blocked: 0, unchanged: 0 },
|
|
})
|
|
it('renders at most one page (25 rows) instead of the full 618-row plan', () => {
|
|
const html = renderToStaticMarkup(<ReleaseManagement {...baseProps} releasePlan={planWith(618)} />)
|
|
expect(html).toContain('筛选 618 / 全部 618')
|
|
expect(html).toContain('第 1 / 25 页 · 每页 25 条')
|
|
expect(html.match(/class="release-plan-table"/g)?.length ?? 0).toBeLessThanOrEqual(1)
|
|
// Only page-1 titles render; a page-2 row and a late row are absent from the DOM.
|
|
expect(html).toContain('文档0.pdf')
|
|
expect(html).not.toContain('文档25.pdf')
|
|
expect(html).not.toContain('文档617.pdf')
|
|
expect(html).toContain('仅可发布')
|
|
expect(html).toContain('下一页')
|
|
})
|
|
it('keeps small plans pagination-free and pages exactly at the 25-item boundary', () => {
|
|
const small = renderToStaticMarkup(<ReleaseManagement {...baseProps} releasePlan={planWith(3)} />)
|
|
expect(small).toContain('筛选 3 / 全部 3')
|
|
expect(small).not.toContain('上一页')
|
|
const exact = renderToStaticMarkup(<ReleaseManagement {...baseProps} releasePlan={planWith(25)} />)
|
|
expect(exact).not.toContain('上一页')
|
|
expect(exact).toContain('文档24.pdf')
|
|
const over = renderToStaticMarkup(<ReleaseManagement {...baseProps} releasePlan={planWith(26)} />)
|
|
expect(over).toContain('第 1 / 2 页 · 每页 25 条')
|
|
expect(over).not.toContain('文档25.pdf')
|
|
const huge = renderToStaticMarkup(<ReleaseManagement {...baseProps} releasePlan={planWith(5000)} />)
|
|
expect(huge.match(/<tr /g)?.length ?? 0).toBeLessThanOrEqual(60)
|
|
expect(huge).toContain('第 1 / 200 页')
|
|
})
|
|
})
|
|
|
|
describe('R4 rollback levels in the execution timeline', () => {
|
|
const baseProps = {
|
|
reviewPage: { items: [], total: 0, limit: 20, offset: 0 } as any,
|
|
reviewLoading: false, reviewError: null, reviewingId: null,
|
|
batchPage: { items: [], total: 0, limit: 20, offset: 0 } as any,
|
|
batchDetail: null, batchLoading: false, batchError: null, mutatingBatchId: null,
|
|
onReview: vi.fn(), onReviewRefresh: vi.fn(), onCreateBatch: vi.fn(), onSealBatch: vi.fn(), onSelectBatch: vi.fn(), onBatchRefresh: vi.fn(),
|
|
releaseCapabilities: { production_release_requests_enabled: true, production_backup_restore_verified: false, test_auto_review_policy: '' },
|
|
releasePlan: { items: [], summary: { add: 0, update: 0, delete: 0, blocked: 0, unchanged: 0 } } as ReleasePlan,
|
|
executionDetail: null, executionLoading: false, executionError: null, onSelectExecution: vi.fn(), onExecutionRefresh: vi.fn(),
|
|
selectedDeleteIDs: [] as string[], onToggleDelete: vi.fn(),
|
|
}
|
|
const exec = (over: Record<string, unknown>) => ({
|
|
id: 'rx-1', release_batch_id: 'rb-1', operation: 'rollback', prior_execution_id: 'rx-0',
|
|
state: 'rolling_back', target_environment: 'production', authorized_by: 'system:auto-rollback', job_id: 'job-1',
|
|
item_count: 2, batch_size: 50, current_batch: 1, total_batches: 1, completed_item_count: 1, failed_item_count: 0,
|
|
error_code: '', failure_level: '', restore_trigger: 'auto_rollback_after_failure',
|
|
created_at: '2026-09-12T09:00:00Z', started_at: '2026-09-12T09:01:00Z', completed_at: null, ...over,
|
|
}) as any
|
|
it('labels the compensating stage and the escalation after a failed rollback', () => {
|
|
const html = renderToStaticMarkup(<ReleaseManagement {...baseProps} executionPage={{ items: [exec({})], total: 1, limit: 20, offset: 0 }} />)
|
|
expect(html).toContain('正在回滚')
|
|
expect(html).toContain('正在执行自动回滚')
|
|
const failed = renderToStaticMarkup(<ReleaseManagement {...baseProps} executionPage={{ items: [exec({ state: 'rollback_failed', failed_item_count: 1 })], total: 1, limit: 20, offset: 0 }} />)
|
|
expect(failed).toContain('回滚失败')
|
|
expect(failed).toContain('整体恢复')
|
|
const done = renderToStaticMarkup(<ReleaseManagement {...baseProps} executionPage={{ items: [exec({ state: 'rolled_back', completed_item_count: 2 })], total: 1, limit: 20, offset: 0 }} />)
|
|
expect(done).toContain('已回滚')
|
|
expect(done).toContain('已恢复')
|
|
const graded = renderToStaticMarkup(<ReleaseManagement {...baseProps} executionPage={{ items: [exec({ operation: 'publish', state: 'failed', failure_level: 'batch' })], total: 1, limit: 20, offset: 0 }} />)
|
|
expect(graded).toContain('本批后续已停止')
|
|
})
|
|
})
|
|
|
|
// 生产动作(授权发布 / 重排 / 回滚):页面按钮只对管理员出现,且必须逐字输入固定确认语句。
|
|
describe('ReleaseManagement production actions', () => {
|
|
const authValue = (role: 'admin' | 'engineer') => ({ identity: { id: `${role}-1`, username: role, display_name: role, role, must_change_password: false }, ready: true, login: async () => null, logout: async () => {}, changePassword: async () => null, signedOut: 0, notifySignedOut: () => {} })
|
|
const now = '2026-10-08T08:00:00Z'
|
|
const batchPage: ReleaseBatchPage = { items: [{ id: 'rb-sealed', name: '单文档首发', state: 'sealed', policy_version: 'release-gate-v1', created_by: 'admin', sealed_by: 'admin', item_count: 1, created_at: now, sealed_at: now }], total: 1, limit: 20, offset: 0 }
|
|
const executionPage: ReleaseExecutionPage = { items: [{ id: 'rx-done', release_batch_id: 'rb-sealed', operation: 'publish', prior_execution_id: '', state: 'completed', target_environment: 'production', authorized_by: 'admin', job_id: 'job-1', item_count: 1, batch_size: 50, current_batch: 1, total_batches: 1, completed_item_count: 1, failed_item_count: 0, error_code: '', created_at: now, started_at: now, completed_at: now }, { id: 'rx-bad', release_batch_id: 'rb-sealed', operation: 'publish', prior_execution_id: '', state: 'failed', target_environment: 'production', authorized_by: 'admin', job_id: 'job-2', item_count: 1, batch_size: 50, current_batch: 1, total_batches: 1, completed_item_count: 0, failed_item_count: 1, error_code: 'release_item_failed', created_at: now, started_at: now, completed_at: now }], total: 2, limit: 20, offset: 0 }
|
|
const base = (extra: Record<string, unknown> = {}) => <ReleaseManagement
|
|
reviewPage={{ items: [], total: 0, limit: 20, offset: 0 }} reviewLoading={false} reviewError={null} reviewingId={null}
|
|
batchPage={batchPage} batchDetail={null} batchLoading={false} batchError={null} mutatingBatchId={null}
|
|
onReview={vi.fn()} onReviewRefresh={vi.fn()} onCreateBatch={vi.fn()} onSealBatch={vi.fn()} onSelectBatch={vi.fn()} onBatchRefresh={vi.fn()}
|
|
releaseCapabilities={{ production_release_requests_enabled: true, production_backup_restore_verified: true, test_auto_review_policy: '' }}
|
|
executionPage={executionPage} executionDetail={null} executionLoading={false} executionError={null} onSelectExecution={vi.fn()} onExecutionRefresh={vi.fn()}
|
|
releasePlan={{ items: [], summary: { add: 0, update: 0, delete: 0, blocked: 0, unchanged: 0 } }}
|
|
selectedDeleteIDs={[]} onToggleDelete={vi.fn()} {...extra} />
|
|
|
|
it('offers 授权发布 / 重排 / 回滚 to admins only', () => {
|
|
const admin = renderToStaticMarkup(<AuthContext.Provider value={authValue('admin')}>{base()}</AuthContext.Provider>)
|
|
expect(admin).toContain('授权发布')
|
|
expect(admin).toContain('重排')
|
|
expect(admin).toContain('回滚')
|
|
expect(admin).toContain('生产操作可执行(待确认)')
|
|
const engineer = renderToStaticMarkup(<AuthContext.Provider value={authValue('engineer')}>{base()}</AuthContext.Provider>)
|
|
expect(engineer).not.toContain('授权发布')
|
|
expect(engineer).not.toContain('<button type="button">回滚</button>')
|
|
expect(engineer).not.toContain('<button type="button">重排</button>')
|
|
})
|
|
|
|
it('requires the exact confirmation phrase before the action can be submitted', () => {
|
|
const pending = { kind: 'authorize' as const, id: 'rb-sealed', label: '单文档首发' }
|
|
const wrong = renderToStaticMarkup(<AuthContext.Provider value={authValue('admin')}>{base({ pendingReleaseAction: pending, releaseActionPhrase: 'publish', onStartReleaseAction: vi.fn(), onReleaseActionPhrase: vi.fn(), onSubmitReleaseAction: vi.fn(), onCancelReleaseAction: vi.fn() })}</AuthContext.Provider>)
|
|
expect(wrong).toContain('publish-to-production')
|
|
expect(wrong).toMatch(/<button type="button" disabled=""[^>]*>确认执行<\/button>/)
|
|
const right = renderToStaticMarkup(<AuthContext.Provider value={authValue('admin')}>{base({ pendingReleaseAction: pending, releaseActionPhrase: 'publish-to-production', onStartReleaseAction: vi.fn(), onReleaseActionPhrase: vi.fn(), onSubmitReleaseAction: vi.fn(), onCancelReleaseAction: vi.fn() })}</AuthContext.Provider>)
|
|
expect(right).toMatch(/<button type="button">确认执行<\/button>/)
|
|
})
|
|
|
|
it('surfaces the server reason when the action is refused', () => {
|
|
const html = renderToStaticMarkup(<AuthContext.Provider value={authValue('admin')}>{base({ pendingReleaseAction: null, releaseActionError: 'production release authorization required', releaseActionMessage: null, onStartReleaseAction: vi.fn(), onReleaseActionPhrase: vi.fn(), onSubmitReleaseAction: vi.fn(), onCancelReleaseAction: vi.fn() })}</AuthContext.Provider>)
|
|
expect(html).toContain('production release authorization required')
|
|
})
|
|
})
|