feat(library): 生产发布授权与同步/恢复编排,worker 接线
build / build (push) Successful in 1m19s

为什么:同步入口此前只会拒绝;授权、预备份、四类写入、验证与失败恢复都没有代码。
本轮把编排与授权实现出来,真实生产执行仍按授权闸口关闭。

- internal/libraryrelease:预备份 → 数据库/资源/索引/Wiki → 验证 → 失败恢复;
  授权过期/目标不符/快照不符/参数变化在动生产前拒绝;恢复失败单独上报。
- 迁移 000067 library_release_authorizations(目标+快照+参数摘要+有效期,可撤销)。
- POST/GET /api/v1/library/authorizations 与 /{id}/revoke,仅管理员签发,5–1440 分钟。
- worker library.sync 接编排:先闸口再授权,阶段落库,只有编排成功才标成功。
- 生产目标适配器未配置时显式失败(不返回零值状态),预备份存储同。
- overview 返回授权状态,页面"生产保护与恢复"显示签发人与有效期。
- 验收矩阵区分"已实现·隔离测试通过"与"真实执行未授权"。
This commit is contained in:
姚章浩
2026-10-28 15:11:27 +08:00
parent f91359f881
commit 7b8cc0384b
22 changed files with 1288 additions and 46 deletions
+3
View File
@@ -96,6 +96,7 @@ const overview: LibraryOverview = {
'本次目标快照还没有生产预备份',
],
},
authorization: { state: 'none', reason: '没有与目标快照匹配的有效发布授权' },
capture_available: true,
now: '2026-10-28T03:40:00Z',
}
@@ -182,6 +183,8 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
expect(html).toContain('生产写入闸口关闭')
expect(html).toContain('没有已核验的生产恢复演练证据')
expect(html).toContain('本次目标快照还没有生产预备份')
// 授权也必须可见:没有授权时说明需要管理员签发
expect(html).toContain('无有效授权(需管理员按目标+快照签发)')
expect(html).toContain('封存测试版本')
})
+19 -1
View File
@@ -319,11 +319,13 @@ function ProtectionCard({
production,
prebackup,
gate,
authorization,
onOpen,
}: {
production: LibraryOverview['production']
prebackup: LibraryOverview['prebackup']
gate: LibraryOverview['gate']
authorization: LibraryOverview['authorization']
onOpen: () => void
}) {
const backupKnown = prebackup.state === 'known' && prebackup.version
@@ -348,6 +350,12 @@ function ProtectionCard({
</dd>
<dt>备份范围</dt>
<dd>数据库 / 资源 / 索引 / Wiki</dd>
<dt>发布授权</dt>
<dd>
{authorization.state === 'active'
? `${authorization.authorized_by || '管理员'} 签发 · 有效至 ${stamp(authorization.expires_at ?? '')}`
: '无有效授权(需管理员按目标+快照签发)'}
</dd>
<dt>恢复条件</dt>
<dd>{gate.reasons.length === 0 ? '已满足' : `缺 ${gate.reasons.length} 项`}</dd>
</dl>
@@ -373,6 +381,7 @@ interface ReadyProps {
production: LibraryOverview['production']
prebackup: LibraryOverview['prebackup']
gate: LibraryOverview['gate']
authorization: LibraryOverview['authorization']
canCapture: boolean
canWrite: boolean
pendingCapture: boolean
@@ -386,6 +395,7 @@ function ReadyBody({
production,
prebackup,
gate,
authorization,
canCapture,
canWrite,
pendingCapture,
@@ -397,7 +407,13 @@ function ReadyBody({
<>
<div className="rel-grid">
<ChangeTable diff={diff} />
<ProtectionCard production={production} prebackup={prebackup} gate={gate} onOpen={onOpen} />
<ProtectionCard
production={production}
prebackup={prebackup}
gate={gate}
authorization={authorization}
onOpen={onOpen}
/>
</div>
<div className="rel-panel rel-jobbar">
<header className="rel-panel-head">
@@ -863,6 +879,7 @@ export function ReleaseTargetsView(props: ViewProps) {
removed: [],
}
const gate = view.overview?.gate ?? { sync_allowed: false, reasons: ['整库状态接口不可用'] }
const authorization = view.overview?.authorization ?? { state: 'none' as const, reason: '整库状态接口不可用' }
return (
<section className="release-targets" aria-label="发布管理">
@@ -1012,6 +1029,7 @@ export function ReleaseTargetsView(props: ViewProps) {
production={production}
prebackup={prebackup}
gate={gate}
authorization={authorization}
canCapture={canCapture}
canWrite={canWrite}
pendingCapture={pendingCapture}
+8
View File
@@ -282,6 +282,13 @@ export interface LibraryJobRecord {
stages: LibraryStageRow[]
}
export interface LibraryAuthorizationView {
state: 'active' | 'none'
authorized_by?: string
expires_at?: string
reason?: string
}
export interface LibraryGate {
sync_allowed: boolean
reasons: string[]
@@ -297,6 +304,7 @@ export interface LibraryOverview {
job?: LibraryJobRecord
jobs: LibraryJobRecord[]
gate: LibraryGate
authorization: LibraryAuthorizationView
capture_available: boolean
capture_reason?: string
now: string