diff --git a/pkg/execution/context_run_test.go b/pkg/execution/context_run_test.go index 52c3988..b1335b4 100644 --- a/pkg/execution/context_run_test.go +++ b/pkg/execution/context_run_test.go @@ -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 diff --git a/pkg/execution/execution.go b/pkg/execution/execution.go index 6ab82ed..4bd0888 100644 --- a/pkg/execution/execution.go +++ b/pkg/execution/execution.go @@ -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,