Files
ruflo/v3/@claude-flow/cli/__tests__/init-codex-trust.test.ts
T
randRuFlo a6b563c60f fix(codex): safe default .codex/config.toml, explicit --codex-trust full opt-in
init, init --dual and @claude-flow/codex init wrote a gitignored
.codex/config.toml with sandbox_mode = danger-full-access,
approval_policy = never and web_search = live. Default is now standard
trust (workspace-write, on-request, cached); the permissive file needs
--codex-trust full (or RUFLO_CODEX_TRUST=full). init prints which level
it wrote, an existing .codex/config.toml is never rewritten (not even
with --force) and a kept permissive file is flagged. Unknown levels are
rejected on the CLI and fall back to standard from the environment.

Found by the three-host e2e run (ADR-490). @claude-flow/codex 3.0.4
(bundled: ships with the next train).

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-10-11 14:04:07 -04:00

49 lines
2.3 KiB
TypeScript

/**
* `init --codex-trust <standard|full>`: the generated .codex/config.toml is
* safe by default (workspace-write, on-request approvals); only an explicit
* `full` restores danger-full-access. The adapter owns the file contents
* (see @claude-flow/codex tests/codex-trust-defaults.test.ts); this pins the
* CLI side: the flag exists, both key spellings parse, anything else is
* rejected rather than guessed, and it reaches the adapter.
*/
import { describe, it, expect } from 'vitest';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { initCommand, readCodexTrustFlag } from '../src/commands/init.js';
describe('readCodexTrustFlag', () => {
it('reads the normalised (camelCase) and literal (kebab) keys', () => {
expect(readCodexTrustFlag({ codexTrust: 'full' })).toBe('full');
expect(readCodexTrustFlag({ 'codex-trust': 'standard' })).toBe('standard');
});
it('is undefined when unset, so the adapter default (standard) applies', () => {
expect(readCodexTrustFlag({})).toBeUndefined();
expect(readCodexTrustFlag({ codexTrust: '' })).toBeUndefined();
expect(readCodexTrustFlag({ codexTrust: false })).toBeUndefined();
});
it('rejects anything else with null instead of guessing a level', () => {
expect(readCodexTrustFlag({ codexTrust: 'yolo' })).toBeNull();
expect(readCodexTrustFlag({ codexTrust: 'FULL' })).toBeNull();
expect(readCodexTrustFlag({ codexTrust: true })).toBeNull();
});
});
describe('init command surface', () => {
it('declares --codex-trust as a string option', () => {
const opt = initCommand.options?.find((o) => o.name === 'codex-trust');
expect(opt).toBeDefined();
expect(opt?.type).toBe('string');
expect(opt?.description).toMatch(/never rewritten/);
});
it('forwards the level to the adapter on every Codex path', () => {
const src = readFileSync(fileURLToPath(new URL('../src/commands/init.ts', import.meta.url)), 'utf8');
// npx fallback, in-process initializer, and the auto-detect path
expect(src).toMatch(/\['--codex-trust', options\.codexTrust\]/);
expect(src).toMatch(/dual: dualMode,\s*codexTrust,/);
expect(src).toMatch(/dual: false, \/\/ Claude Code files were already written by the main init flow above\s*codexTrust,/);
});
});