merge: cover CUA configuration error responses
This commit is contained in:
commit
adde9215aa
1 file changed
+13
-7
@@ -39,7 +39,10 @@ async function fixture(fail = false) {
|
||||
$on(_event: string, listener: (namespace: string, revision: number) => void) { settingsListener = listener; return unsubscribe }
|
||||
}
|
||||
new Remote()
|
||||
const setDefault = vi.fn(async () => true), setPersistent = vi.fn(async () => true)
|
||||
const setDefault = vi.fn(async () => true)
|
||||
const setPersistent = vi.fn<() => Promise<RemoteResult<void>>>().mockResolvedValue({ ok: true, value: undefined })
|
||||
const runtimeConfiguration = vi.fn<() => Promise<RemoteResult<{ persistent: boolean; writable: boolean }>>>()
|
||||
.mockResolvedValue({ ok: true, value: { persistent: false, writable: true } })
|
||||
const preset = createSnapshotStore({ status: 'ready' as const, value: { default: 'standard' },
|
||||
base: {}, user: {}, revision: 1, writable: true })
|
||||
ctx.provide('configForms', { get: (namespace: string) => {
|
||||
@@ -55,8 +58,7 @@ async function fixture(fail = false) {
|
||||
const revoke = vi.fn<() => Promise<RemoteResult<void>>>().mockResolvedValue({ ok: true, value: undefined })
|
||||
const retryApproval = vi.fn<() => Promise<RemoteResult<void>>>().mockResolvedValue({ ok: true, value: undefined })
|
||||
ctx.provide('remote.cuaAccess', {
|
||||
ptcConfiguration: vi.fn(async () => ({ ok: true, value: { persistent: false, writable: true } })),
|
||||
enablePersistentPtc: async () => { await setPersistent(); return { ok: true, value: undefined } },
|
||||
ptcConfiguration: runtimeConfiguration, enablePersistentPtc: setPersistent,
|
||||
applications: status, systemStatus, applicationIcons, requestPermission, openSettings, revoke, retryApproval })
|
||||
ctx.provide('locale', new LocaleRuntime(ctx))
|
||||
await ctx.plugin(SlotRegistry)
|
||||
@@ -67,7 +69,7 @@ async function fixture(fail = false) {
|
||||
} } as never, () => null)
|
||||
if (fail) vi.spyOn(ctx.slots, 'inject').mockImplementationOnce(() => { throw new Error('slot unavailable') })
|
||||
return { ctx, unmount, unsubscribe, status, systemStatus, applicationIcons,
|
||||
requestPermission, openSettings, revoke, retryApproval, setDefault, setPersistent,
|
||||
requestPermission, openSettings, revoke, retryApproval, setDefault, setPersistent, runtimeConfiguration,
|
||||
updateSettings(namespace: string) { settingsListener!(namespace, 1) },
|
||||
}
|
||||
}
|
||||
@@ -98,7 +100,8 @@ it('withdraws the permission Remote and all controls with the optional plugin',
|
||||
await vi.waitFor(() => { expect(actions.hooks.cuaPermissions.getSnapshot().toast?.kind).toBe('retryAllowed') })
|
||||
const failed = { ok: false as const, error: new RemoteError('gateway/internal', 'offline', {}) }
|
||||
for (const [target, invoke] of [
|
||||
[f.status, actions.refresh], [f.systemStatus, actions.refresh], [f.applicationIcons, actions.refresh], [f.requestPermission, () => { actions.request('accessibility') }],
|
||||
[f.runtimeConfiguration, actions.refresh], [f.status, actions.refresh], [f.systemStatus, actions.refresh],
|
||||
[f.applicationIcons, actions.refresh], [f.requestPermission, () => { actions.request('accessibility') }],
|
||||
[f.openSettings, () => { actions.openSettings('accessibility') }],
|
||||
[f.revoke, () => { actions.revoke('a'.repeat(64) as import('@deepseek-ai/dsh-cua/types').CuaApplicationId) }],
|
||||
[f.retryApproval, () => { actions.retryApproval('a'.repeat(64) as import('@deepseek-ai/dsh-cua/types').CuaApplicationId) }],
|
||||
@@ -109,8 +112,9 @@ it('withdraws the permission Remote and all controls with the optional plugin',
|
||||
invoke()
|
||||
await vi.waitFor(() => {
|
||||
const state = actions.hooks.cuaPermissions.getSnapshot()
|
||||
const error = target === f.status ? state.applications.error : target === f.systemStatus ? state.system.error
|
||||
: target === f.applicationIcons ? state.icons.error : state.toast?.kind === 'failed' ? state.toast.message : null
|
||||
const error = target === f.runtimeConfiguration ? state.runtime.error : target === f.status ? state.applications.error
|
||||
: target === f.systemStatus ? state.system.error
|
||||
: target === f.applicationIcons ? state.icons.error : state.toast?.kind === 'failed' ? state.toast.message : null
|
||||
expect(error).toContain('offline')
|
||||
})
|
||||
}
|
||||
@@ -131,6 +135,8 @@ it('withdraws the permission Remote and all controls with the optional plugin',
|
||||
expect(f.setPersistent).not.toHaveBeenCalled()
|
||||
await (settings.setPersistentPtc as () => Promise<boolean>)()
|
||||
expect(f.setPersistent).toHaveBeenCalledExactlyOnceWith()
|
||||
f.setPersistent.mockResolvedValueOnce(failed)
|
||||
await expect((settings.setPersistentPtc as () => Promise<boolean>)()).rejects.toThrow('offline')
|
||||
await fiber.dispose()
|
||||
expect(f.ctx.slots.entries('conversation.composer')).toHaveLength(0)
|
||||
expect(f.ctx.slots.entries('plugins.bundle.config')).toHaveLength(0)
|
||||
|
||||
Reference in new issue
Block a user