feat(library-web): 恢复入口按真实条件启用并支持签发恢复授权
原来"恢复至该版本"写死 disabled,标题还写"生产恢复未接线"——而 POST /library/restores 与授权接口早已可用,等于把整库还原的唯一入口藏起来。 现在页面按 GET /library/restore-availability 启用:缺授权时管理员可签发 30 分钟 有效期的 restore 授权(固定期限,没有"永久授权"),条件满足才可点恢复;工程师只看到 条件与"仅管理员可发起"。封存不可发起时也不再写死"通道未接线",而是显示接口原因、 执行器身份与观测时间。
This commit is contained in:
@@ -149,6 +149,13 @@ const base: ViewProps = {
|
||||
pendingCapture: false,
|
||||
canCapture: true,
|
||||
canWrite: true,
|
||||
canRestore: false,
|
||||
restore: null,
|
||||
restoreNotice: null,
|
||||
pendingRestore: false,
|
||||
pendingGrant: false,
|
||||
onGrantRestore: vi.fn(),
|
||||
onRestore: vi.fn(),
|
||||
maintenance: null,
|
||||
now: new Date('2026-10-28T03:35:00Z').getTime(),
|
||||
onRefresh: vi.fn(),
|
||||
@@ -239,18 +246,62 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
|
||||
expect(html).toContain('列表只校验清单自身,字节级复核在同步/恢复执行前进行')
|
||||
})
|
||||
|
||||
it('版本与快照抽屉按 scope 列出全部历史并区分测试封存/不可直接恢复', () => {
|
||||
const html = render({ drawerOpen: true, expandedSnapshot: internalSnapshot.snapshot_id })
|
||||
it('版本与快照抽屉按 scope 列出全部历史,并把恢复条件交给接口判定', () => {
|
||||
const html = render({ drawerOpen: true, expandedSnapshot: internalSnapshot.snapshot_id, canRestore: true })
|
||||
expect(html).toContain('版本与快照')
|
||||
expect(html).toContain('封存 f992d64ea45b')
|
||||
expect(html).toContain('测试封存')
|
||||
expect(html).toContain('不可直接恢复')
|
||||
expect(html).toContain('恢复条件见下方')
|
||||
expect(html).toContain('恢复至该版本')
|
||||
expect(html).toMatch(/恢复至该版本[^<]*<\/button>/)
|
||||
expect(html).toContain('分项数量 / 字节 / 摘要(2 项)')
|
||||
expect(html).toContain('不支持只选择 Wiki 或某张数据表恢复')
|
||||
})
|
||||
|
||||
it('管理员在缺授权时看到签发入口,恢复按钮按接口给出的原因禁用', () => {
|
||||
const html = render({
|
||||
drawerOpen: true,
|
||||
expandedSnapshot: internalSnapshot.snapshot_id,
|
||||
canRestore: true,
|
||||
restore: {
|
||||
allowed: false,
|
||||
reasons: ['没有针对该快照的恢复授权:先签发 restore 授权(绑定同一快照)'],
|
||||
scope: 'internal',
|
||||
snapshot_id: internalSnapshot.snapshot_id,
|
||||
authorization: { state: 'none' },
|
||||
},
|
||||
})
|
||||
expect(html).toContain('签发恢复授权(30 分钟)')
|
||||
expect(html).toContain('没有针对该快照的恢复授权')
|
||||
expect(html).toMatch(/rel-danger[^>]*disabled/)
|
||||
// 不能再说"未接线":条件不满足要给出具体原因
|
||||
expect(html).not.toContain('生产恢复未接线')
|
||||
})
|
||||
|
||||
it('条件全满足时恢复按钮可用,并写明授权有效期', () => {
|
||||
const html = render({
|
||||
drawerOpen: true,
|
||||
expandedSnapshot: internalSnapshot.snapshot_id,
|
||||
canRestore: true,
|
||||
restore: {
|
||||
allowed: true,
|
||||
reasons: [],
|
||||
scope: 'internal',
|
||||
snapshot_id: internalSnapshot.snapshot_id,
|
||||
authorization: { state: 'active', authorized_by: 'yaozhanghao', expires_at: '2026-10-28T04:10:00Z' },
|
||||
},
|
||||
})
|
||||
expect(html).toContain('条件已满足')
|
||||
expect(html).toContain('有效至')
|
||||
expect(html).not.toMatch(/rel-danger[^>]*disabled/)
|
||||
})
|
||||
|
||||
it('工程师看不到恢复入口,只看到权限说明', () => {
|
||||
const html = render({ drawerOpen: true, expandedSnapshot: internalSnapshot.snapshot_id, canRestore: false })
|
||||
expect(html).toContain('按版本恢复仅管理员可发起')
|
||||
expect(html).not.toContain('签发恢复授权')
|
||||
})
|
||||
|
||||
it('抽屉只展示当前选中库的历史', () => {
|
||||
const html = render({ drawerOpen: true, scope: 'external' })
|
||||
expect(html).toContain('封存 01343b0b310b')
|
||||
@@ -277,14 +328,30 @@ describe('ReleaseTargetsView(确认稿布局)', () => {
|
||||
expect(html).toContain('主机侧正在暂停写入者、导出并恢复')
|
||||
})
|
||||
|
||||
it('无权限时不给封存入口,未接线时说明通道状态', () => {
|
||||
it('无权限时不给封存入口;不可发起时给出接口返回的真实原因与执行器身份', () => {
|
||||
expect(render({ canCapture: false, canWrite: false })).toContain('封存需要知识工程师及以上权限')
|
||||
const unwired = render({
|
||||
const unavailable = render({
|
||||
canCapture: false,
|
||||
canWrite: true,
|
||||
page: { ...page, capture_available: false, capture_reason: '主机侧封存 agent 未接线' },
|
||||
page: { ...page, capture_available: false },
|
||||
overview: {
|
||||
...overview,
|
||||
capture_available: false,
|
||||
capture_reason: '执行器指向的实例不匹配:agent="weknora071full",期望="kgmaint-weknora"',
|
||||
executor: {
|
||||
available: false,
|
||||
busy: false,
|
||||
project: 'weknora071full',
|
||||
source_app: 'WKNFull-app',
|
||||
observed_at: '2026-10-28T03:34:00Z',
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(unwired).toContain('封存通道未接线')
|
||||
expect(unavailable).toContain('执行器指向的实例不匹配')
|
||||
expect(unavailable).toContain('执行器 weknora071full / WKNFull-app')
|
||||
expect(unavailable).toContain('观测于')
|
||||
// 通道可用/不可用都不许用写死的"未接线"糊过去
|
||||
expect(unavailable).not.toContain('封存通道未接线')
|
||||
})
|
||||
|
||||
it('无封存时给出“尚无封存”而不是空表', () => {
|
||||
|
||||
Reference in New Issue
Block a user