From 4c966c65ea54ba37607b550aabee4801d543948e Mon Sep 17 00:00:00 2001 From: creatixchu Date: Mon, 19 Oct 2026 15:41:44 +0800 Subject: [PATCH] test(cua): cover runtime configuration transport failures --- .../client-ui-cua/tests/mount.client.spec.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/experimental/client-ui-cua/tests/mount.client.spec.ts b/packages/experimental/client-ui-cua/tests/mount.client.spec.ts index 5e9e29cc32..904a8453fc 100644 --- a/packages/experimental/client-ui-cua/tests/mount.client.spec.ts +++ b/packages/experimental/client-ui-cua/tests/mount.client.spec.ts @@ -37,7 +37,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>>().mockResolvedValue({ ok: true, value: undefined }) + const runtimeConfiguration = vi.fn<() => Promise>>() + .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) => { @@ -53,8 +56,7 @@ async function fixture(fail = false) { const revoke = vi.fn<() => Promise>>().mockResolvedValue({ ok: true, value: undefined }) const retryApproval = vi.fn<() => Promise>>().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) @@ -64,7 +66,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) }, } } @@ -90,7 +92,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) }], @@ -101,8 +104,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') }) } @@ -123,6 +127,8 @@ it('withdraws the permission Remote and all controls with the optional plugin', expect(f.setPersistent).not.toHaveBeenCalled() await (settings.setPersistentPtc as () => Promise)() expect(f.setPersistent).toHaveBeenCalledExactlyOnceWith() + f.setPersistent.mockResolvedValueOnce(failed) + await expect((settings.setPersistentPtc as () => Promise)()).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)