feat: 开放扩展安装确认与原生启用

This commit is contained in:
2026-09-12 02:21:05 +08:00
parent 864a2e75fd
commit d33ec79ec7
3 changed files with 61 additions and 7 deletions
@@ -24,9 +24,9 @@ it('uses themed surfaces for the section, empty state, and staged package rows',
expect(populated.get('.package-list > li').classes()).toContain('item-card')
populated.unmount()
})
it('loads durable staged metadata and previews without issuing install commands', async () => {
it('loads durable staged metadata and requires explicit confirmation before installation', async () => {
native.invoke.mockImplementation(async command => command === 'extension_staged' ? [item] : {
fingerprint: 'fingerprint', dependencies: { packages: [{ ...item, permissions: ['notes.read'] }] }, changes: [{ target: { configuration: {} }, expected_revision: null }],
fingerprint: 'fingerprint', dependencies: { packages: [{ ...item, kind: 'plugin', permissions: ['notes.read'] }] }, changes: [{ target: { slot: 'slot', package_key: 'package-key', configuration: {} }, expected_revision: null }],
})
const wrapper = component(); await flushPromises()
expect(native.invoke).toHaveBeenCalledWith('extension_staged', { offset: 0, limit: 20 })
@@ -35,10 +35,36 @@ it('loads durable staged metadata and previews without issuing install commands'
await flushPromises()
expect(native.invoke).toHaveBeenLastCalledWith('extension_install_preview', { request: { root_key: 'package-key', vault_id: 'vault-one', configurations: { 'package-key': {} } } })
expect(wrapper.text()).toContain('notes.read')
expect(wrapper.text()).toContain('安装执行暂未开放')
expect(wrapper.text()).toContain('确认安装并启用')
expect(native.invoke.mock.calls.every(call => ['extension_staged', 'extension_install_preview'].includes(call[0]))).toBe(true)
wrapper.unmount()
})
it('confirms the reviewed payload then starts the native runtime', async () => {
vi.stubGlobal('crypto', { randomUUID: () => 'operation-id' })
native.invoke.mockImplementation(async (command) => {
if (command === 'extension_staged') return [item]
if (command === 'extension_install_preview') return {
fingerprint: 'fingerprint',
dependencies: { packages: [{ ...item, kind: 'plugin', permissions: [] }] },
changes: [{ target: { slot: 'slot', package_key: 'package-key', configuration: {} }, expected_revision: null }],
}
if (command === 'extension_stage_prepare') return 'request-id'
return { status: 'ready' }
})
const wrapper = component(); await flushPromises()
await wrapper.findAll('button').find(button => button.text() === '查看安装预览')!.trigger('click')
await wrapper.findAll('button').find(button => button.text() === '检查依赖、权限与配置')!.trigger('click')
await flushPromises()
await wrapper.findAll('button').find(button => button.text() === '确认安装并启用')!.trigger('click')
await flushPromises()
expect(native.invoke).toHaveBeenCalledWith('extension_install_confirm', { request: {
request_id: 'request-id', operation_id: 'operation-id', fingerprint: 'fingerprint',
root_key: 'package-key', vault_id: 'vault-one', configurations: { 'package-key': {} },
} })
expect(native.invoke).toHaveBeenCalledWith('extension_enable', { slot: 'slot', vaultId: 'vault-one', installOperationId: 'operation-id' })
expect(wrapper.text()).toContain('安装和运行健康检查已完成')
wrapper.unmount(); vi.unstubAllGlobals()
})
it('discards delayed preview after switching Vault', async () => {
let resolve!: (value: unknown) => void
native.invoke.mockImplementation(command => command === 'extension_staged' ? Promise.resolve([item]) : new Promise(done => { resolve = done }))