|
| 1 | +package codex |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "io" |
| 6 | + "reflect" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +// TestCodexSpawner_Name asserts the spawner reports the stable registry name. |
| 11 | +func TestCodexSpawner_Name(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + if got := NewSpawner().Name(); got != wantCodexAgentName { |
| 14 | + t.Errorf("Name() = %q, want %q", got, wantCodexAgentName) |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +// TestCodexSpawner_Argv pins the argv + stdin contract: |
| 19 | +// |
| 20 | +// codex exec --skip-git-repo-check --dangerously-bypass-approvals-and-sandbox - |
| 21 | +// |
| 22 | +// Prompt is piped on stdin. The bypass-approvals-and-sandbox flag is |
| 23 | +// codex's documented way to run autonomously: less aggressive options |
| 24 | +// (-s workspace-write, --add-dir) are not sufficient because codex's |
| 25 | +// workspace-write policy excludes anything under `.git/` regardless of |
| 26 | +// --add-dir, which blocks investigate's per-run dir at |
| 27 | +// <git-common-dir>/entire-investigations/<run-id>/. |
| 28 | +func TestCodexSpawner_Argv(t *testing.T) { |
| 29 | + t.Parallel() |
| 30 | + env := []string{"FOO=bar", "BAZ=qux"} |
| 31 | + cmd := NewSpawner().BuildCmd(context.Background(), env, "the-prompt") |
| 32 | + |
| 33 | + wantArgs := []string{ |
| 34 | + wantCodexAgentName, "exec", |
| 35 | + "--skip-git-repo-check", |
| 36 | + "--dangerously-bypass-approvals-and-sandbox", |
| 37 | + "-", |
| 38 | + } |
| 39 | + if !reflect.DeepEqual(cmd.Args, wantArgs) { |
| 40 | + t.Errorf("Args = %v, want %v", cmd.Args, wantArgs) |
| 41 | + } |
| 42 | + |
| 43 | + if !reflect.DeepEqual(cmd.Env, env) { |
| 44 | + t.Errorf("Env = %v, want %v", cmd.Env, env) |
| 45 | + } |
| 46 | + |
| 47 | + if cmd.Stdin == nil { |
| 48 | + t.Fatal("Stdin = nil, want a reader carrying the prompt") |
| 49 | + } |
| 50 | + got, err := io.ReadAll(cmd.Stdin) |
| 51 | + if err != nil { |
| 52 | + t.Fatalf("read stdin: %v", err) |
| 53 | + } |
| 54 | + if string(got) != "the-prompt" { |
| 55 | + t.Errorf("stdin = %q, want %q", string(got), "the-prompt") |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +// TestCodexSpawner_Argv_StableUnderInvestigateEnv pins the contract |
| 60 | +// that the argv does NOT change based on env vars. (A previous |
| 61 | +// implementation appended --add-dir from ENTIRE_INVESTIGATE_FINDINGS_DOC; |
| 62 | +// that approach didn't actually unblock writes under .git/, so we |
| 63 | +// dropped it. This test pins the regression.) |
| 64 | +func TestCodexSpawner_Argv_StableUnderInvestigateEnv(t *testing.T) { |
| 65 | + t.Parallel() |
| 66 | + env := []string{ |
| 67 | + "FOO=bar", |
| 68 | + "ENTIRE_INVESTIGATE_FINDINGS_DOC=/repo/.git/entire-investigations/abcdef012345/findings.md", |
| 69 | + } |
| 70 | + cmd := NewSpawner().BuildCmd(context.Background(), env, "prompt") |
| 71 | + |
| 72 | + wantArgs := []string{ |
| 73 | + wantCodexAgentName, "exec", |
| 74 | + "--skip-git-repo-check", |
| 75 | + "--dangerously-bypass-approvals-and-sandbox", |
| 76 | + "-", |
| 77 | + } |
| 78 | + if !reflect.DeepEqual(cmd.Args, wantArgs) { |
| 79 | + t.Errorf("Args = %v, want %v", cmd.Args, wantArgs) |
| 80 | + } |
| 81 | +} |
0 commit comments