feat(release): 生产授权支持页面通道(管理员会话 + 固定确认语句)
页面原本没有任何生产入口,授权/重排/回滚只能带 Bearer 调接口,实际还要 admin 会话。 现在三个端点支持两条通道,门禁语义不变: - 运维通道:Authorization: Bearer <token>,审计记 PRODUCTION_RELEASE_AUTHORIZER_REF - 页面通道:已认证 admin 会话 + 固定确认语句,审计记该管理员用户名 - 请求门禁 / 备份恢复门禁 / Release Worker 执行门禁三者不受影响 - 发布管理第 6–8 步加「授权发布 / 重排 / 回滚」按钮,点击需逐字输入确认语句, 仅 admin 可见;重排沿用原执行授权人,不改写历史 - openapi 与 P6 契约同步;测试:双通道各一条 + 非 admin/错短语拒绝 + 前端按钮与确认门禁
This commit is contained in:
@@ -2,6 +2,7 @@ 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'
|
||||
@@ -482,3 +483,45 @@ describe('R4 rollback levels in the execution timeline', () => {
|
||||
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 }}
|
||||
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')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user