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
41 changes: 41 additions & 0 deletions pkg/execution/context_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,47 @@ func TestContextDispatchHandoffAndLeaseReceipt(t *testing.T) {
}
}

func TestContextCodexRedactsAPIKeyWithProfileToken(t *testing.T) {
f := newContextFixture(t)
state := t.TempDir()
t.Setenv("XDG_STATE_HOME", state)
// An unused profile token must not cause partial masking of the API key.
const tokenPrefix = "synthetic-provider"
keySuffix := strings.TrimPrefix(fixtureAPIKey, tokenPrefix)
config := f.clients["codex"].cfg
config.Profile.Token = tokenPrefix
client, err := New(config)
if err != nil {
t.Fatal(err)
}
req := f.request(t, "codex", "redaction")
req.RecordHistory = true
var events []string
req.OnEvent = func(event RawEvent) error {
events = append(events, string(event.Data))
return nil
}
result, err := client.Run(context.Background(), req)
if err != nil || !f.observe(t, "codex").ExplicitProviderAuth {
t.Fatalf("Codex did not run with the expected provider credential: %v", err)
}
if !result.HistoryRecorded {
t.Fatalf("history not recorded: %v", result.HistoryError)
}
history, err := os.ReadFile(filepath.Join(state, "offload", "runs.jsonl"))
if err != nil {
t.Fatal(err)
}
for surface, output := range map[string]string{
"report": result.Report, "raw record": string(result.RawRecord),
"raw events": strings.Join(events, "\n"), "history": string(history),
} {
if !strings.Contains(output, "fixture done [REDACTED]") || strings.Contains(output, keySuffix) {
t.Errorf("provider API key was not fully redacted in %s", surface)
}
}
}

func checkFixtureDispatch(t *testing.T, f contextFixture, req Request, result Result, seen contextFixtureObservation, broker *fixtureBroker) {
t.Helper()
receipt := result.ContextReceipt
Expand Down
3 changes: 2 additions & 1 deletion pkg/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ func (c *Client) run(ctx context.Context, req Request, managed *activeContextRun
envSet = map[string]string{"OPENAI_API_KEY": managed.codexAPIKey}
}
redact := envSet
if managed != nil && c.profile.Token != "" {
// Only the Claude adapter passes the profile token to the child.
if managed != nil && c.profile.BackendName() == "claude" && c.profile.Token != "" {
redact = map[string]string{"ANTHROPIC_AUTH_TOKEN": c.profile.Token}
}
o := worker.Opts{EnvSet: envSet, EnvUnset: envUnset, ProfileName: c.cfg.ProfileName, Profile: c.profile, Model: req.Model,
Expand Down
Loading