Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions electron/__tests__/codex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,34 @@ test('rejects invalid explicit Codex CLI overrides', async () => {
}
});

test('resolves the ChatGPT app CLI without a codex command on PATH', async () => {
await using directory = await createTemporaryDirectory('codiff-chatgpt-cli-');
const bundledCLI = join(directory.path, 'Applications/ChatGPT.app/Contents/Resources/codex');
await mkdir(dirname(bundledCLI), { recursive: true });
await writeFile(bundledCLI, '#!/bin/sh\n');
await chmod(bundledCLI, 0o755);
await using _environment = createTemporaryEnvironment({
CODIFF_CODEX_PATH: undefined,
PATH: directory.path,
});
test.each(['codex', 'codex-cli/bin/codex'])(
'resolves the ChatGPT app CLI at %s without a codex command on PATH',
async (entryPoint) => {
await using directory = await createTemporaryDirectory('codiff-chatgpt-cli-');
const bundledCLI = join(
directory.path,
'Applications/ChatGPT.app/Contents/Resources',
entryPoint,
);
await mkdir(dirname(bundledCLI), { recursive: true });
await writeFile(bundledCLI, '#!/bin/sh\n');
await chmod(bundledCLI, 0o755);
await using _environment = createTemporaryEnvironment({
CODIFF_CODEX_PATH: undefined,
PATH: directory.path,
});

// Keep the test hermetic when a real CLI is installed in /Applications.
const macOSInstallPaths = getCodexInstallPaths('darwin', directory.path);
expect(macOSInstallPaths).toContain('/Applications/ChatGPT.app/Contents/Resources/codex');
const installPaths = macOSInstallPaths.filter((path: string) => path.startsWith(directory.path));
expect(getCodexCommand(installPaths)).toBe(bundledCLI);
});
// Keep the test hermetic when a real CLI is installed in /Applications.
const macOSInstallPaths = getCodexInstallPaths('darwin', directory.path);
expect(macOSInstallPaths).toContain(
join('/Applications/ChatGPT.app/Contents/Resources', entryPoint),
);
const installPaths = macOSInstallPaths.filter((path: string) =>
path.startsWith(directory.path),
);
expect(getCodexCommand(installPaths)).toBe(bundledCLI);
},
);

test.skipIf(process.platform !== 'darwin')(
'explains macOS Codex CLI security blocks through runCodex',
Expand Down
2 changes: 2 additions & 0 deletions electron/codex.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const getCodexInstallPaths = (platform = process.platform, home = homedir()) =>
join(home, 'Applications/Codex.app/Contents/Resources/codex'),
'/Applications/ChatGPT.app/Contents/Resources/codex',
join(home, 'Applications/ChatGPT.app/Contents/Resources/codex'),
'/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex',
join(home, 'Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex'),
]
: []),
];
Expand Down