Codex CLI has a first-class project config layer — `.codex/config.toml` is layer 4 of the loader stack, above the user config at layer 6 (`codex-rs/config/src/loader/README.md` in openai/codex), and it landed in openai/codex#8354 on 2025-12-22. The CodexTarget's "Codex has no project-local config concept" note was therefore never accurate, and `supportsLocation('local') === false` made Codex the one agent that forces a machine-wide MCP install. `mcp_servers` is not on the project layer's denylist (which strips base URLs, model providers, `notify`, profiles and otel — settings repo contents shouldn't choose), so a project-scoped `[mcp_servers.codegraph]` is honored. - Path helpers take a `Location`: global keeps `~/.codex/config.toml` + `~/.codex/AGENTS.md`; local writes `<cwd>/.codex/config.toml` and the project-root `<cwd>/AGENTS.md` — the same split the gemini and opencode targets already use for their local layout. - Drops the five `loc !== 'global'` early returns from detect, install, uninstall, printConfig and describePaths. - Local install returns a note that Codex only applies a project layer in a project marked trusted; untrusted projects load the layer but leave it disabled, so a silent success would be misleading. - Refreshes the two doc comments that used Codex as the example of a global-only target (now the Copilot CLI). Tests: two new cases covering the local write layout, the trust note, global config staying untouched, and local uninstall leaving the global entry intact. Both fail against the previous implementation. The generic per-target contract suite now also exercises codex at location=local.
This commit is contained in:
@@ -240,6 +240,42 @@ describe('Installer targets — partial-state idempotency', () => {
|
||||
expect(mdEntry?.action).toBe('updated');
|
||||
});
|
||||
|
||||
it('codex: local install writes ./.codex/config.toml and the project-root ./AGENTS.md block (#1531)', () => {
|
||||
const codex = getTarget('codex')!;
|
||||
const result = codex.install('local', { autoAllow: false });
|
||||
const paths = result.files.map((f) => f.path.replace(/\\/g, '/'));
|
||||
// macOS realpath shenanigans (/var vs /private/var) — suffix match.
|
||||
expect(paths.some((p) => p.endsWith('/.codex/config.toml'))).toBe(true);
|
||||
// AGENTS.md sits at the project root, NOT under .codex/ — that's the
|
||||
// file Codex reads for repo instructions.
|
||||
expect(paths.some((p) => p.endsWith('/AGENTS.md') && !p.includes('/.codex/'))).toBe(true);
|
||||
|
||||
const toml = fs.readFileSync(path.join(process.cwd(), '.codex', 'config.toml'), 'utf-8');
|
||||
expect(toml).toContain('[mcp_servers.codegraph]');
|
||||
expect(fs.readFileSync(path.join(process.cwd(), 'AGENTS.md'), 'utf-8')).toContain('codegraph explore');
|
||||
|
||||
// The project layer is only applied in a trusted project, so say so
|
||||
// instead of reporting a silent success.
|
||||
expect(result.notes?.join(' ')).toMatch(/trusted/);
|
||||
|
||||
// Global config is untouched by a local install.
|
||||
expect(fs.existsSync(path.join(tmpHome, '.codex', 'config.toml'))).toBe(false);
|
||||
});
|
||||
|
||||
it('codex: local uninstall reverses the local install and leaves the global entry alone (#1531)', () => {
|
||||
const codex = getTarget('codex')!;
|
||||
codex.install('global', { autoAllow: false });
|
||||
codex.install('local', { autoAllow: false });
|
||||
expect(codex.detect('local').alreadyConfigured).toBe(true);
|
||||
|
||||
codex.uninstall('local');
|
||||
|
||||
expect(codex.detect('local').alreadyConfigured).toBe(false);
|
||||
expect(codex.detect('global').alreadyConfigured).toBe(true);
|
||||
expect(fs.readFileSync(path.join(tmpHome, '.codex', 'config.toml'), 'utf-8'))
|
||||
.toContain('[mcp_servers.codegraph]');
|
||||
});
|
||||
|
||||
it('opencode: prefers .jsonc when both .json and .jsonc exist', () => {
|
||||
const opencode = getTarget('opencode')!;
|
||||
const dir = path.join(tmpHome, '.config', 'opencode');
|
||||
|
||||
Reference in New Issue
Block a user