-
-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathcommandResolution.test.ts
More file actions
69 lines (59 loc) · 1.99 KB
/
Copy pathcommandResolution.test.ts
File metadata and controls
69 lines (59 loc) · 1.99 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
59
60
61
62
63
64
65
66
67
68
69
import { afterEach, describe, expect, it, vi } from 'vitest'
const MACOS_CODEX_APP_COMMAND = '/Applications/Codex.app/Contents/Resources/codex'
async function loadWithMocks(options: {
platform: NodeJS.Platform
existingPaths: string[]
runnableCommands: string[]
explicitCommand?: string
}) {
vi.resetModules()
vi.unstubAllEnvs()
if (options.explicitCommand !== undefined) {
vi.stubEnv('CODEXUI_CODEX_COMMAND', options.explicitCommand)
}
vi.doMock('node:fs', () => ({
existsSync: (path: string) => options.existingPaths.includes(path),
}))
vi.doMock('node:os', () => ({
homedir: () => '/Users/tester',
}))
vi.doMock('node:child_process', () => ({
spawnSync: (command: string, args: string[] = []) => ({
error: undefined,
status: options.runnableCommands.includes(command) && args.includes('--version') ? 0 : 1,
}),
}))
vi.stubGlobal('process', {
...process,
platform: options.platform,
env: process.env,
})
return import('./commandResolution')
}
describe('resolveCodexCommand', () => {
afterEach(() => {
vi.resetModules()
vi.unstubAllEnvs()
vi.unstubAllGlobals()
vi.doUnmock('node:fs')
vi.doUnmock('node:os')
vi.doUnmock('node:child_process')
})
it('prefers the bundled Codex.app command on macOS before PATH codex', async () => {
const { resolveCodexCommand } = await loadWithMocks({
platform: 'darwin',
existingPaths: [MACOS_CODEX_APP_COMMAND],
runnableCommands: [MACOS_CODEX_APP_COMMAND, 'codex'],
})
expect(resolveCodexCommand()).toBe(MACOS_CODEX_APP_COMMAND)
})
it('keeps CODEXUI_CODEX_COMMAND as the highest-priority override', async () => {
const { resolveCodexCommand } = await loadWithMocks({
platform: 'darwin',
existingPaths: ['/custom/codex', MACOS_CODEX_APP_COMMAND],
runnableCommands: ['/custom/codex', MACOS_CODEX_APP_COMMAND, 'codex'],
explicitCommand: '/custom/codex',
})
expect(resolveCodexCommand()).toBe('/custom/codex')
})
})