forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaudeCode.test.ts
More file actions
58 lines (51 loc) · 1.97 KB
/
Copy pathclaudeCode.test.ts
File metadata and controls
58 lines (51 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { spawn } from 'child_process'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ClaudeCodeRuntimeAdapter } from './claudeCode'
import { createMockProcess } from './acp.testkit'
vi.mock('child_process', async () => {
const actual = await vi.importActual<typeof import('child_process')>('child_process')
return {
...actual,
spawn: vi.fn(),
execFile: vi.fn()
}
})
describe('ClaudeCodeRuntimeAdapter spawn contract', () => {
beforeEach(() => {
vi.mocked(spawn).mockReset()
})
it('spawns the bundled ACP entry with the app binary running as Node, no shell', async () => {
const proc = createMockProcess()
vi.mocked(spawn).mockReturnValue(proc as never)
const adapter = new ClaudeCodeRuntimeAdapter()
await adapter.start()
expect(spawn).toHaveBeenCalledTimes(1)
const [bin, args, options] = vi.mocked(spawn).mock.calls[0] as unknown as [
string,
string[],
Record<string, unknown>
]
expect(bin).toBe(process.execPath)
expect(args).toHaveLength(1)
expect(args[0]).toContain('claude-acp-entry.mjs')
expect(options).toMatchObject({
shell: false,
stdio: ['pipe', 'pipe', 'pipe'],
windowsHide: true
})
const env = options.env as NodeJS.ProcessEnv
// Electron's binary must run as plain Node for the entry script to execute.
expect(env.ELECTRON_RUN_AS_NODE).toBe('1')
// Auth is delegated to the Claude Agent SDK's own stored credentials —
// stray env keys must not silently redirect it (including to Vertex AI).
expect(env.ANTHROPIC_API_KEY).toBeUndefined()
expect(env.CLAUDE_CODE_USE_VERTEX).toBeUndefined()
expect(env.CLAUDECODE).toBeUndefined()
await adapter.stop()
})
it('is always activated: constructing without options resolves a bundled entry path', () => {
const adapter = new ClaudeCodeRuntimeAdapter()
expect(adapter.adapterId).toBe('acp')
expect(adapter.capabilities.supportsModelSwitching).toBe(true)
})
})