From 6d6fc8968600f86f327568195097f73bd9bd5f5e Mon Sep 17 00:00:00 2001 From: Dudu-0223 Date: Sat, 7 Nov 2026 13:05:01 +0800 Subject: [PATCH] test: cover macOS CUA channel policy forwarding on every platform --- .../cua-macos/tests/provider-channel.spec.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/experimental/cua-macos/tests/provider-channel.spec.ts diff --git a/packages/experimental/cua-macos/tests/provider-channel.spec.ts b/packages/experimental/cua-macos/tests/provider-channel.spec.ts new file mode 100644 index 0000000000..02d9fc0fe6 --- /dev/null +++ b/packages/experimental/cua-macos/tests/provider-channel.spec.ts @@ -0,0 +1,36 @@ +/** Provider configuration reaches the native transport without opening a macOS connection. */ +import { resolve } from 'node:path' +import { PassThrough } from 'node:stream' +import { Context } from '@deepseek-ai/cordis' +import { installCua } from '@deepseek-ai/dsh-cua' +import type { NativeChannel } from '@deepseek-ai/dsh-cua/native-client' +import { expect, it, onTestFinished, vi } from 'vitest' +import { apply, Config } from '../src/index.ts' +import { createSharedNativeChannel } from '../src/shared-native.ts' + +vi.mock('@deepseek-ai/dsh-cua', async importOriginal => ({ + ...await importOriginal(), + installCua: vi.fn(), +})) +vi.mock('../src/shared-native.ts', () => ({ createSharedNativeChannel: vi.fn() })) + +it.each([false, true])('forwards systemPointerHover=%s and native limits to each channel', async (systemPointerHover) => { + const ctx = new Context() + onTestFinished(() => ctx.fiber.dispose()) + const config = Config({ helperPath: resolve('fixture-helper'), systemPointerHover }) + const channel: NativeChannel = { + stdin: new PassThrough(), stdout: new PassThrough(), done: Promise.resolve(), + close() {}, waitForClose: async () => {}, + } + onTestFinished(() => { channel.stdin.destroy(); channel.stdout.destroy() }) + vi.mocked(installCua).mockClear() + vi.mocked(createSharedNativeChannel).mockReset().mockReturnValue(channel) + + await apply(ctx, config) + expect(installCua).toHaveBeenCalledTimes(1) + const backend = vi.mocked(installCua).mock.calls[0]![2] + const owner = { subprocess: { spawn: vi.fn() } } + const native = { ...config, helperPath: resolve('fixture-helper'), cwd: process.cwd() } + expect(backend.createChannel(owner, native)).toBe(channel) + expect(createSharedNativeChannel).toHaveBeenCalledExactlyOnceWith(owner, native, systemPointerHover) +})