feat(release): 发布到生产一键完成(建批+锁定+授权合成一个动作)
用户的反馈是对的:上一轮只砍掉了"冻结/锁定"两个按钮,但一条文档从"已批准"到"发出"实际仍要
~9 次交互(找条目→勾选→填名→建批→滚到清单→找批次→授权→输语句→提交),因为"批次仪式"本身
还留在路径上。
- 新端点 POST /api/v1/release-batches/publish-now:在同一操作里先建批(SealImmediately,冻结
即锁定)再授权生产发布,返回 {batch, execution}。
- 不放松任何约束:请求门禁(403)、备份恢复验证门禁(412)、管理员身份(401)、固定确认语句(400)、
发布前快照硬门禁(409)、建批门禁(422) 全部沿用既有实现,无旁路;名称可省(服务端固定回退名,
保证重放指纹一致)。
- 界面:审核行上直接「发布到生产」(管理员 + 门禁开启时显示),工具栏支持选中多条一次发布;
复用既有确认弹窗(固定语句)。批次名不再是必经步骤。
- 实测(面板):点行级按钮 → 输 `publish-to-production` → 提交 → 批次 rb-bee80550…(sealed)
+ 执行 rx-3d831129…(completed, 项级 verified) → 页面回滚 rx-43835fac…(rolled_back, absent)。
测试:publish_now_test.go(四道关卡 + 组合调用 + 名称回退)与 reviewRelease.test.ts(请求体/回传/错误原因);
Go 26 包、前端 183 条全过。
This commit is contained in:
+22
-9
@@ -12,7 +12,7 @@ import { fetchSourceAssets } from './assets'
|
||||
import type { LegacyStatus, SourceAssetPage } from './assets'
|
||||
import { fetchJobs } from './jobs'
|
||||
import type { Job, JobState } from './jobs'
|
||||
import { confirmReleaseChangeSet, createReleaseBatch, fetchLatestReleaseChangeSet, fetchReleaseAuditChain, fetchReleaseBatch, fetchReleaseBatches, fetchReleaseCapabilities, fetchReleaseExecution, fetchReleaseExecutions, fetchReleasePlan, fetchReviewCandidates, generateReleaseChangeSet, productionConfirmationPhrases, reviewPublication, runProductionAction, sealReleaseBatch, reviewPublicationsBatch } from './reviewRelease'
|
||||
import { confirmReleaseChangeSet, createReleaseBatch, fetchLatestReleaseChangeSet, fetchReleaseAuditChain, fetchReleaseBatch, fetchReleaseBatches, fetchReleaseCapabilities, fetchReleaseExecution, fetchReleaseExecutions, fetchReleasePlan, fetchReviewCandidates, generateReleaseChangeSet, productionConfirmationPhrases, reviewPublication, runProductionAction, sealReleaseBatch, reviewPublicationsBatch , runPublishNow} from './reviewRelease'
|
||||
import type { ProductionActionKind } from './reviewRelease'
|
||||
import type { ReleaseAuditChain, ReleaseBatchDetail, ReleaseBatchPage, ReleaseCapabilities, ReleaseChangeSetDetail, ReleaseExecutionDetail, ReleaseExecutionPage, ReleasePlan, ReleasePlanItem, ReviewCandidatePage, Visibility } from './reviewRelease'
|
||||
import { fetchSourceConnections, fetchSourceScanDetail, fetchSourceScans, triggerSourceScan } from './sourceConnections'
|
||||
@@ -228,7 +228,7 @@ interface ModulePageProps extends JobDashboardProps {
|
||||
releaseActionBusy?: boolean
|
||||
releaseActionError?: string | null
|
||||
releaseActionMessage?: string | null
|
||||
onStartReleaseAction?: (kind: ProductionActionKind, id: string, label: string) => void
|
||||
onStartReleaseAction?: (kind: ProductionActionKind, id: string, label: string, ids?: string[], deleteIDs?: string[]) => void
|
||||
onReleaseActionPhrase?: (value: string) => void
|
||||
onSubmitReleaseAction?: () => void
|
||||
onCancelReleaseAction?: () => void
|
||||
@@ -239,6 +239,9 @@ export interface PendingReleaseAction {
|
||||
kind: ProductionActionKind
|
||||
id: string
|
||||
label: string
|
||||
/** publish_now 专用:这次要发布哪些条目(含待删除)。 */
|
||||
publicationIDs?: string[]
|
||||
deletePublicationIDs?: string[]
|
||||
}
|
||||
|
||||
const emptyAssetPage: SourceAssetPage = { items: [], summary: { total: 0, completed: 0, content_alias: 0, over_limit: 0 }, limit: 50, offset: 0 }
|
||||
@@ -689,13 +692,13 @@ interface ReleaseManagementProps {
|
||||
releaseActionBusy?: boolean
|
||||
releaseActionError?: string | null
|
||||
releaseActionMessage?: string | null
|
||||
onStartReleaseAction?: (kind: ProductionActionKind, id: string, label: string) => void
|
||||
onStartReleaseAction?: (kind: ProductionActionKind, id: string, label: string, ids?: string[], deleteIDs?: string[]) => void
|
||||
onReleaseActionPhrase?: (value: string) => void
|
||||
onSubmitReleaseAction?: () => void
|
||||
onCancelReleaseAction?: () => void
|
||||
}
|
||||
|
||||
const releaseActionLabels: Record<ProductionActionKind, string> = { authorize: '授权发布', retry: '重排执行', rollback: '回滚发布' }
|
||||
const releaseActionLabels: Record<ProductionActionKind, string> = { authorize: '授权发布', retry: '重排执行', rollback: '回滚发布', publish_now: '发布到生产' }
|
||||
|
||||
const acceptanceLabels: Record<string, string> = {
|
||||
pending: '待验收',
|
||||
@@ -1026,10 +1029,13 @@ export function ReleaseManagement(props: ReleaseManagementProps) {
|
||||
{(() => {
|
||||
// 「可批准」只含尚未决定且门禁通过的条目:已驳回的不能被"全选"顺手翻回来。
|
||||
const batchable = props.reviewPage.items.filter((item) => item.gate_status === 'ready' && item.review_state === 'pending').map((item) => item.publication_id)
|
||||
// 已批准且可发布的选中项:一键"发布到生产"(建批+锁定+授权合成一个动作)。
|
||||
const publishableSelected = selectedIDs.filter((id) => props.reviewPage.items.some((item) => item.publication_id === id && item.review_state === 'approved' && item.gate_status === 'ready'))
|
||||
return <div className="release-toolbar"><div className="release-toolbar-actions">
|
||||
<button type="button" disabled={!batchable.length || props.reviewingId === 'batch'} onClick={() => setSelectedIDs(batchable)}>全选可批准({batchable.length})</button>
|
||||
<button type="button" disabled={!selectedIDs.length || props.reviewingId === 'batch'} onClick={() => void props.onBatchReview?.(selectedIDs, 'approved', 'internal', 'approved_for_release')}>{props.reviewingId === 'batch' ? '正在批量处理…' : `批量批准选中(${selectedIDs.length})`}</button>
|
||||
<button type="button" disabled={!selectedIDs.length || props.reviewingId === 'batch'} onClick={() => void props.onBatchReview?.(selectedIDs, 'rejected', 'internal', 'needs_correction')}>批量驳回选中({selectedIDs.length})</button>
|
||||
{isAdmin && props.releaseCapabilities.production_release_requests_enabled ? <button type="button" className="primary" disabled={!publishableSelected.length} onClick={() => props.onStartReleaseAction?.('publish_now', 'publish-now', `${publishableSelected.length} 项`, publishableSelected)}>发布到生产(选中 {publishableSelected.length} 项)</button> : null}
|
||||
{props.reviewBatchMessage ? <small role="status">{props.reviewBatchMessage}</small> : null}
|
||||
</div></div>
|
||||
})()}
|
||||
@@ -1056,7 +1062,7 @@ export function ReleaseManagement(props: ReleaseManagementProps) {
|
||||
<td><span className={`status status-${item.gate_status === 'ready' ? 'completed' : 'failed'}`}>{reviewGateLabel(item)}</span></td>
|
||||
<td><select value={visibility} onChange={(event) => setVisibilityByID((current) => ({ ...current, [item.publication_id]: event.target.value as Visibility }))}><option value="internal">仅内部员工</option><option value="external">允许外部用户</option></select></td>
|
||||
<td><span className={`status status-${item.review_state === 'approved' ? 'completed' : item.review_state === 'rejected' ? 'failed' : 'pending'}`}>{reviewLabels[item.review_state]}</span>{item.reviewer_ref ? <small>{item.reviewer_ref}</small> : null}</td>
|
||||
<td><div className="row-actions"><button type="button" disabled={item.gate_status !== 'ready' || props.reviewingId === item.publication_id} onClick={() => props.onReview(item.publication_id, 'approved', visibility, 'approved_for_release')}>批准</button><button type="button" className="secondary-action" disabled={props.reviewingId === item.publication_id} onClick={() => props.onReview(item.publication_id, 'rejected', visibility, 'needs_correction')}>驳回</button></div></td>
|
||||
<td><div className="row-actions"><button type="button" disabled={item.gate_status !== 'ready' || props.reviewingId === item.publication_id} onClick={() => props.onReview(item.publication_id, 'approved', visibility, 'approved_for_release')}>批准</button><button type="button" className="secondary-action" disabled={props.reviewingId === item.publication_id} onClick={() => props.onReview(item.publication_id, 'rejected', visibility, 'needs_correction')}>驳回</button>{isAdmin && props.releaseCapabilities.production_release_requests_enabled && item.review_state === 'approved' && item.gate_status === 'ready' ? <button type="button" title="建批(冻结+锁定)并授权生产发布,一个动作完成" onClick={() => props.onStartReleaseAction?.('publish_now', 'publish-now', item.title, [item.publication_id])}>发布到生产</button> : null}</div></td>
|
||||
</tr>
|
||||
})}
|
||||
</tbody></table></div> : null}
|
||||
@@ -1498,8 +1504,8 @@ export default function App() {
|
||||
|
||||
// 页面上的生产动作:点按钮 → 逐字输入固定确认语句 → 提交。服务端同时校验
|
||||
// 管理员会话、请求门禁与确认语句;Bearer 通道留给运维脚本,行为不变。
|
||||
const handleStartReleaseAction = useCallback((kind: ProductionActionKind, id: string, label: string) => {
|
||||
setPendingReleaseAction({ kind, id, label })
|
||||
const handleStartReleaseAction = useCallback((kind: ProductionActionKind, id: string, label: string, ids?: string[], deleteIDs?: string[]) => {
|
||||
setPendingReleaseAction({ kind, id, label, publicationIDs: ids, deletePublicationIDs: deleteIDs })
|
||||
setReleaseActionPhrase('')
|
||||
setReleaseActionError(null)
|
||||
setReleaseActionMessage(null)
|
||||
@@ -1517,8 +1523,15 @@ export default function App() {
|
||||
setReleaseActionError(null)
|
||||
setReleaseActionMessage(null)
|
||||
try {
|
||||
const summary = await runProductionAction(pendingReleaseAction.kind, pendingReleaseAction.id, releaseActionPhrase.trim())
|
||||
setReleaseActionMessage(`${releaseActionLabels[pendingReleaseAction.kind]}已受理:执行 ${summary.id}(${summary.state || 'pending'}) · ${summary.item_count} 项`)
|
||||
if (pendingReleaseAction.kind === 'publish_now') {
|
||||
// 名称留空由服务端兜底;这里给一个可读的默认名(确定性内容,重放指纹一致)。
|
||||
const defaultName = `立即发布 · ${new Date().toLocaleDateString('zh-CN')}`
|
||||
const result = await runPublishNow(pendingReleaseAction.publicationIDs ?? [], pendingReleaseAction.deletePublicationIDs ?? [], defaultName, releaseActionPhrase.trim())
|
||||
setReleaseActionMessage(`已受理发布:批次 ${result.batch_name || result.batch_id} · 执行 ${result.execution_id}`)
|
||||
} else {
|
||||
const summary = await runProductionAction(pendingReleaseAction.kind, pendingReleaseAction.id, releaseActionPhrase.trim())
|
||||
setReleaseActionMessage(`${releaseActionLabels[pendingReleaseAction.kind]}已受理:执行 ${summary.id}(${summary.state || 'pending'}) · ${summary.item_count} 项`)
|
||||
}
|
||||
setPendingReleaseAction(null)
|
||||
setReleaseActionPhrase('')
|
||||
await loadReleaseExecutions()
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
reviewPublication,
|
||||
sealReleaseBatch,
|
||||
reviewPublicationsBatch,
|
||||
runPublishNow,
|
||||
} from './reviewRelease'
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
@@ -222,7 +223,7 @@ describe('production actions', () => {
|
||||
it('surfaces the server reason and keeps the phrases fixed', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify({ error: 'production release authorization required' }), { status: 401 })))
|
||||
await expect(runProductionAction('authorize', 'rb-1', 'publish-to-production')).rejects.toThrow('production release authorization required')
|
||||
expect(productionConfirmationPhrases).toEqual({ authorize: 'publish-to-production', retry: 'retry-production-release', rollback: 'rollback-production-release' })
|
||||
expect(productionConfirmationPhrases).toEqual({ authorize: 'publish-to-production', retry: 'retry-production-release', rollback: 'rollback-production-release', publish_now: 'publish-to-production' })
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
})
|
||||
@@ -286,3 +287,21 @@ describe('批量审核与建批即锁定', () => {
|
||||
expect(JSON.parse(String(init.body)).release_change_set_id).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('发布到生产(建批+锁定+授权合成一个动作)', () => {
|
||||
it('提交条目与固定确认语句,回传批次与执行', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({ ok: true, json: async () => ({ data: { batch: { id: 'rb-now', name: '立即发布 · 2026/10/10' }, execution: { id: 'rx-now' } } }) })
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
const result = await runPublishNow(['tp-a', 'tp-b'], [], '立即发布 · 2026/10/10', 'publish-to-production')
|
||||
expect(result).toEqual({ batch_id: 'rb-now', batch_name: '立即发布 · 2026/10/10', execution_id: 'rx-now' })
|
||||
const [url, init] = fetchMock.mock.calls[0]
|
||||
expect(url).toBe('/api/v1/release-batches/publish-now')
|
||||
expect(JSON.parse(String(init.body))).toEqual({ publication_ids: ['tp-a', 'tp-b'], delete_publication_ids: [], name: '立即发布 · 2026/10/10', confirmation: 'publish-to-production' })
|
||||
})
|
||||
|
||||
it('服务端拒绝时把原因带出来', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({ ok: false, status: 412, json: async () => ({ error: 'production backup restore verification is required' }) })
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
await expect(runPublishNow(['tp-a'], [], 'x', 'publish-to-production')).rejects.toThrow('production backup restore verification is required')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -581,12 +581,15 @@ export async function fetchReleaseAuditChain(executionID: string, signal?: Abort
|
||||
|
||||
// ——— 生产动作(授权发布 / 重排 / 回滚)———
|
||||
// 页面通道:管理员会话 + 服务端逐字核对的固定确认语句。Bearer 通道仍留给运维脚本。
|
||||
export type ProductionActionKind = 'authorize' | 'retry' | 'rollback'
|
||||
export type ProductionActionKind = 'authorize' | 'retry' | 'rollback' | 'publish_now'
|
||||
/** 仍按"批次/执行 id"寻址的三个动作;publish_now 传的是发布条目本身。 */
|
||||
type ConfirmedActionKind = Exclude<ProductionActionKind, 'publish_now'>
|
||||
|
||||
export const productionConfirmationPhrases: Record<ProductionActionKind, string> = {
|
||||
authorize: 'publish-to-production',
|
||||
retry: 'retry-production-release',
|
||||
rollback: 'rollback-production-release',
|
||||
publish_now: 'publish-to-production',
|
||||
}
|
||||
|
||||
export interface ProductionActionSummary {
|
||||
@@ -596,13 +599,44 @@ export interface ProductionActionSummary {
|
||||
item_count: number
|
||||
}
|
||||
|
||||
const productionActionPaths: Record<ProductionActionKind, (id: string) => string> = {
|
||||
const productionActionPaths: Record<ConfirmedActionKind, (id: string) => string> = {
|
||||
authorize: (id) => `/api/v1/release-batches/${encodeURIComponent(id)}/authorize-production`,
|
||||
retry: (id) => `/api/v1/release-executions/${encodeURIComponent(id)}/retry`,
|
||||
rollback: (id) => `/api/v1/release-executions/${encodeURIComponent(id)}/authorize-rollback`,
|
||||
}
|
||||
|
||||
export async function runProductionAction(kind: ProductionActionKind, id: string, confirmation: string): Promise<ProductionActionSummary> {
|
||||
export interface PublishNowResult {
|
||||
batch_id: string
|
||||
batch_name: string
|
||||
execution_id: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 一个动作把「建批(冻结 + 锁定)」和「授权生产发布」走完。
|
||||
* 服务端不放松任何约束:请求门禁、备份恢复验证门禁、管理员身份、固定确认语句、
|
||||
* 发布前快照硬门禁全部照旧;这里只是把操作员的两步点击合成一次带确认的提交。
|
||||
*/
|
||||
export async function runPublishNow(publicationIDs: string[], deletePublicationIDs: string[], name: string, confirmation: string): Promise<PublishNowResult> {
|
||||
const response = await fetch('/api/v1/release-batches/publish-now', {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'Idempotency-Key': newOperationID() },
|
||||
body: JSON.stringify({ publication_ids: publicationIDs, delete_publication_ids: deletePublicationIDs, name, confirmation }),
|
||||
})
|
||||
const payload: unknown = await response.json().catch(() => null)
|
||||
if (!response.ok) {
|
||||
const reason = isRecord(payload) && typeof payload.error === 'string' ? payload.error : `发布到生产失败(HTTP ${response.status})`
|
||||
throw new Error(reason)
|
||||
}
|
||||
if (!isRecord(payload) || !isRecord(payload.data)) throw new Error('发布到生产响应无效')
|
||||
const batch = payload.data.batch
|
||||
const execution = payload.data.execution
|
||||
if (!isRecord(batch) || !isRecord(execution) || typeof batch.id !== 'string' || typeof execution.id !== 'string') {
|
||||
throw new Error('发布到生产响应无效')
|
||||
}
|
||||
return { batch_id: batch.id, batch_name: typeof batch.name === 'string' ? batch.name : '', execution_id: execution.id }
|
||||
}
|
||||
|
||||
export async function runProductionAction(kind: ConfirmedActionKind, id: string, confirmation: string): Promise<ProductionActionSummary> {
|
||||
const response = await fetch(productionActionPaths[kind](id), {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'Idempotency-Key': newOperationID() },
|
||||
|
||||
Reference in New Issue
Block a user