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:
@@ -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')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user