Accept one ChatGPT startup notice before the first Codex turn
Handle the recorded startup notice in the login probe, launcher preflight, and session reader. Keep duplicate, ID-bearing, other-auth-mode and post-turn account notices refused. Direct-live fixtures use the same path. Omit empty TMPDIR and compare prerequisite versions against stdout only. Targeted package tests passed. All nine guard-mutation runs failed at the intended assertions. One full make -k ci passed on the first run; no retries were needed. Reference hashes required no remapping. See CONTROLLER-REPORT-codex-startup-notice.md for commands and results.
Co-Authored-By: Astra <noreply@openai.com>
16 files changed,
+406
−16
docs/superpowers/plans/CONTROLLER-REPORT-codex-startup-notice.md+95 −0internal/directlive/testdata/fake-cli.py+4 −1internal/runner/provider/codex/launcher.go+18 −1internal/runner/provider/codex/launcher_test.go+26 −7internal/runner/provider/codex/readback_test.go+1 −1internal/runner/provider/codex/startup_notice_test.go+109 −0internal/runner/provider/codex_startup.go+10 −0internal/runner/provider/login_probe.go+10 −4internal/runner/provider/login_startup_test.go+96 −0internal/runner/provider/login_terminal.go+4 −1internal/runner/provider/login_test.go+1 −0internal/tryequipo/accounts_test.go+3 −0internal/tryequipo/command.go+8 −0internal/tryequipo/command_test.go+17 −0internal/tryequipo/multiple_accounts_test.go+3 −0internal/tryequipo/prerequisites.go+1 −1
CI passed — run details
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-codex-startup-notice.md b/docs/superpowers/plans/CONTROLLER-REPORT-codex-startup-notice.md| new file mode 100644 |
| index 00000000..01366ac3 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-codex-startup-notice.md |
| @@ -0,0 +1,95 @@ |
| +# Controller report: Codex startup notice |
| + |
| +Brief: CODEX-BRIEF-codex-startup-notice.md. Branch: codex-startup-notice. |
| +Starting revision: a127a14, which contains the brief above main 85d9ea8. |
| + |
| +## Changes and path trace |
| + |
| +R1: The terminal login probe, launcher preflight, and session handler accept |
| +one account/updated notification per process, with no id and authMode equal |
| +to chatgpt. planType is ignored. A shared predicate checks the frame shape; |
| +each process reader owns its allowance. The probe stops at the account/read |
| +response. Preflight never sends turn/start. The session closes its allowance |
| +under its mutex before its first turn/start call and never reopens it, including |
| +after a completed turn. Duplicate notices, other or missing auth modes, and |
| +ID-bearing frames remain refused. |
| + |
| +The session path is reachable: Open starts a preflight process, then a separate |
| +session process whose handler is installed before initialize and account/read. |
| +Both processes receive the recorded startup sequence. The direct-live driver |
| +constructs this same Codex launcher for its exercises and certification, so it |
| +inherits both fixes. Its policy-readback collector only inspects result frames; |
| +its certificate validation does not dispatch account events. There is no second |
| +account-event exception to change. Its fake CLI now emits the recorded sequence. |
| + |
| +R2: LoginEnvironment omits TMPDIR for both providers when unset or empty, and |
| +preserves a nonempty value. The prerequisites version command uses a bounded |
| +stdout-only helper; command failure still fails the check. Other command output |
| +handling is unchanged. |
| + |
| +R3: Fixtures include the recorded disabled remote-control frame with a fake |
| +installation ID, followed by the ChatGPT/promax notice. Coverage includes the |
| +probe, preflight, session, official login, guided account setup, multiple-account |
| +setup, and direct-live fake CLI. Tests cover ID values (including empty and null), |
| +missing/null/other auth modes, duplicates, arbitrary planType, notices before |
| +initialize, duplicates across initialize, notices during config/thread setup, |
| +and notices both during and after a completed turn. TestCodexPreflightNotification |
| +also checks the shared startup predicate. No runtime copy or README changed. |
| + |
| +## Verification |
| + |
| +All Go commands use CGO_ENABLED=0 and the default Go caches. New tests use |
| +`t.TempDir()` and do not require TMPDIR. Environment tests explicitly cover |
| +unset, empty and nonempty values. Scratch is under the on-disk TMPDIR. |
| + |
| +Before implementation, this command exited 1 at the intended assertions: |
| + |
| +```sh |
| +go test ./internal/runner/provider ./internal/runner/provider/codex ./internal/tryequipo -run 'TestCodex(LoginStartupNotice|StartupNotice|SessionStartup|AccountOfficialFlow)|TestLoginEnvironmentTMPDIR|TestOnboardingOfficialLogin$' -count=1 |
| +``` |
| + |
| +The recorded notice was refused in all three readers and the guide; empty and |
| +unset TMPDIR produced an unwanted TMPDIR= entry. The initial test compilation |
| +was corrected to use the concrete terminal driver before recording these failures. |
| + |
| +`go test ./internal/tryequipo -run '^TestVersionStdout$' -count=1` also exited 1 |
| +with the old merged-output behavior: the version contained the stderr warning. |
| + |
| +After implementation: |
| + |
| +- `go test ./internal/runner/provider ./internal/runner/provider/codex ./internal/tryequipo ./internal/directlive -count=1` |
| + exited 0 for all four packages (9.155s, 29.808s, 5.825s and 150.708s). |
| +- `go test ./internal/runner/provider/codex -run '^TestCodex(Startup|SessionStartup|PreflightNotification)' -count=1` |
| + exited 0, including the final first-turn timing tests. |
| +- `go test ./internal/runner/provider ./internal/tryequipo -run 'TestCodexLoginStartupNotice|TestVersionStdout|TestLoginEnvironmentTMPDIR' -count=1` |
| + exited 0, including the final cross-initialize probe tests. |
| +- `git diff --check` and `python3 scripts/runner-dead-references.py` exited 0. |
| + No reference hashes needed remapping. |
| + |
| +Each guard mutation used a Go overlay, leaving working source unchanged. The |
| +command form was `go test -overlay=<scratch>/<mutation>.json <packages> -run <pattern> -count=1`. |
| +Every row below exited 1 at the intended test assertion, with no build failures. |
| + |
| +| Mutation | Packages | Pattern | |
| +| --- | --- | --- | |
| +| notice-id: allow IDs | ./internal/runner/provider | ^TestCodexLoginStartupNotice$/.*id$ | |
| +| notice-id: allow IDs | ./internal/runner/provider/codex | ^TestCodexStartupNotice$/(preflight\|session)/(id\|empty-id)$ | |
| +| notice-mode: allow another nonempty auth mode | ./internal/runner/provider | ^TestCodexLoginStartupNotice$/api-key$ | |
| +| notice-mode: allow another nonempty auth mode | ./internal/runner/provider/codex | ^TestCodexStartupNotice$/(preflight\|session)/api-key$ | |
| +| probe-duplicate: ignore consumed allowance | ./internal/runner/provider | ^TestCodexLoginStartupNotice$/duplicate$ | |
| +| preflight-duplicate: ignore consumed allowance | ./internal/runner/provider/codex | ^TestCodexStartupNotice$/preflight/duplicate$ | |
| +| session-duplicate: ignore consumed allowance | ./internal/runner/provider/codex | ^TestCodexSessionStartupNoticeConsumed$ | |
| +| turn-cutoff: leave allowance open | ./internal/runner/provider/codex | ^TestCodex(SessionStartupBeforeFirstTurn\|StartupAfterCompletedTurn)$ | |
| +| empty-tmpdir: append even when empty | ./internal/runner/provider | ^TestLoginEnvironmentTMPDIR$ | |
| + |
| +The initial shared-predicate mutation commands also selected the launcher |
| +package without matching its nested subtests. The explicit launcher commands |
| +above then verified both preflight and session refusals separately. |
| + |
| +## Full gate and delivery |
| + |
| +R4: Run one full `make -k ci` after staging the complete candidate, including |
| +this report. The result and any permitted retry are recorded in the commit |
| +body and the required three-line summary. Scratch overlays and logs are removed |
| +before handoff. No live gate, real sign-in, deployment, copy-review server, or |
| +access to the live equipo data directory was performed. |
diff --git a/internal/directlive/testdata/fake-cli.py b/internal/directlive/testdata/fake-cli.py| index 66050c76..75a1c883 100644 |
| --- a/internal/directlive/testdata/fake-cli.py |
| +++ b/internal/directlive/testdata/fake-cli.py |
| @@ -45,7 +45,10 @@ for line in sys.stdin: |
| req=json.loads(line) |
| if family=='codex': |
| method=req.get('method') |
| - if method=='initialized':continue |
| + if method=='initialized': |
| + emit({'method':'remoteControl/status/changed','params':{'status':'disabled','serverName':'DOCS-T1','installationId':'fake-installation','environmentId':None}}) |
| + emit({'method':'account/updated','params':{'authMode':'chatgpt','planType':'promax'}}) |
| + continue |
| if not method:continue |
| if method=='initialize': |
| result=next(f['result'] for f in recorded['frames'] if f.get('id')==1) |
diff --git a/internal/runner/provider/codex/launcher.go b/internal/runner/provider/codex/launcher.go| index 9191b0f1..a5ce2d9f 100644 |
| --- a/internal/runner/provider/codex/launcher.go |
| +++ b/internal/runner/provider/codex/launcher.go |
| @@ -36,6 +36,7 @@ type Launcher struct { |
| sessions map[string]*sessionState |
| } |
| type sessionState struct { |
| + startupNoticeSeen, turnStarted bool |
| mcpCalls map[string]json.RawMessage |
| nativeCalls map[string]json.RawMessage |
| requests map[string]provider.Event |
| @@ -405,6 +406,7 @@ func (l *Launcher) preflight(ctx context.Context, b provider.Binding, lease *pro |
| return provider.Identity{}, e |
| } |
| launch := provider.Launch{AttemptKey: "codex-preflight-" + token(), Workspace: in.Workspace, Binding: b, Policy: p, Selection: provider.Selection{Provider: "codex", AccountID: b.AccountID}} |
| + startupNoticeSeen := false |
| proc, _, r, e := l.start(ctx, launch, func(frame provider.Frame) error { |
| raw := frame.Bytes |
| v, _ := parse(raw) |
| @@ -412,6 +414,10 @@ func (l *Launcher) preflight(ctx context.Context, b provider.Binding, lease *pro |
| return nil |
| } |
| if v.Method == "account/updated" { |
| + if !startupNoticeSeen && provider.CodexStartupNotice(v.ID, v.Method, v.Params) { |
| + startupNoticeSeen = true |
| + return nil |
| + } |
| return provider.ErrIdentity |
| } |
| return errProtocol |
| @@ -673,6 +679,9 @@ func (l *Launcher) StartTurn(ctx context.Context, session provider.Session, t pr |
| return s.stop(e) |
| } |
| } |
| + s.mu.Lock() |
| + s.turnStarted = true |
| + s.mu.Unlock() |
| raw, e := s.rpc.Call(ctx, "turn/start", marshal(params)) |
| if e != nil { |
| return s.stop(errUncertain) |
| @@ -747,9 +756,17 @@ func (s *sessionState) handle(frame provider.Frame) error { |
| } |
| s.mu.Lock() |
| defer s.mu.Unlock() |
| + v, _ := parse(frame.Bytes) |
| + if v.Method == "account/updated" { |
| + if !s.turnStarted && !s.startupNoticeSeen && provider.CodexStartupNotice(v.ID, v.Method, v.Params) { |
| + s.startupNoticeSeen = true |
| + return nil |
| + } |
| + return provider.ErrContainment |
| + } |
| for _, ev := range events { |
| ev.Sequence = frame.Sequence |
| - if ev.Kind == "account/updated" || strings.HasPrefix(ev.Kind, "config/") { |
| + if strings.HasPrefix(ev.Kind, "config/") { |
| return provider.ErrContainment |
| } |
| if ev.SessionID != "" && s.session.ID != "" && ev.SessionID != s.session.ID { |
diff --git a/internal/runner/provider/codex/launcher_test.go b/internal/runner/provider/codex/launcher_test.go| index 50278c2a..9321c8d2 100644 |
| --- a/internal/runner/provider/codex/launcher_test.go |
| +++ b/internal/runner/provider/codex/launcher_test.go |
| @@ -42,13 +42,16 @@ func (p *fakeProcess) Wait(ctx context.Context) (provider.Exit, error) { |
| } |
| type fakeHost struct { |
| - sessionID string |
| - mu sync.Mutex |
| - mode string |
| - calls []string |
| - requests []json.RawMessage |
| - launches []provider.Launch |
| - processes []*fakeProcess |
| + sessionID string |
| + startupFrames []json.RawMessage |
| + startupSessionOnly bool |
| + startupMethod string |
| + mu sync.Mutex |
| + mode string |
| + calls []string |
| + requests []json.RawMessage |
| + launches []provider.Launch |
| + processes []*fakeProcess |
| } |
| func (h *fakeHost) set(mode string) { h.mu.Lock(); h.mode = mode; h.mu.Unlock() } |
| @@ -91,6 +94,7 @@ func (h *fakeHost) Start(ctx context.Context, l provider.Launch, args []string) |
| out.Write(append(raw, '\n')) |
| } |
| turn := 0 |
| + startupSent := false |
| for scan.Scan() { |
| var req struct { |
| ID json.RawMessage |
| @@ -105,6 +109,21 @@ func (h *fakeHost) Start(ctx context.Context, l provider.Launch, args []string) |
| h.calls = append(h.calls, req.Method) |
| h.requests = append(h.requests, bytes.Clone(scan.Bytes())) |
| h.mu.Unlock() |
| + noticeMethod := h.startupMethod |
| + if noticeMethod == "" { |
| + noticeMethod = "initialized" |
| + } |
| + if !startupSent && req.Method == noticeMethod && (!h.startupSessionOnly || !strings.HasPrefix(l.AttemptKey, "codex-preflight-")) { |
| + startupSent = true |
| + frames := h.startupFrames |
| + if frames == nil && mode != "account-event" { |
| + frames = []json.RawMessage{json.RawMessage(startupAccountFrame)} |
| + } |
| + send(json.RawMessage(startupRemoteFrame)) |
| + for _, frame := range frames { |
| + send(frame) |
| + } |
| + } |
| if req.Method == "initialized" { |
| continue |
| } |
diff --git a/internal/runner/provider/codex/readback_test.go b/internal/runner/provider/codex/readback_test.go| index bb974a92..68061e9f 100644 |
| --- a/internal/runner/provider/codex/readback_test.go |
| +++ b/internal/runner/provider/codex/readback_test.go |
| @@ -139,7 +139,7 @@ func TestCodexPreflightNotification(t *testing.T) { |
| if e != nil { |
| t.Fatal(e) |
| } |
| - if disabledRemoteControl(v) { |
| + if disabledRemoteControl(v) || provider.CodexStartupNotice(v.ID, v.Method, v.Params) { |
| t.Fatal("unsafe notification ignored", raw) |
| } |
| } |
diff --git a/internal/runner/provider/codex/startup_notice_test.go b/internal/runner/provider/codex/startup_notice_test.go| new file mode 100644 |
| index 00000000..62cc02ba |
| --- /dev/null |
| +++ b/internal/runner/provider/codex/startup_notice_test.go |
| @@ -0,0 +1,109 @@ |
| +package codex |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| +) |
| + |
| +const startupRemoteFrame = `{"method":"remoteControl/status/changed","params":{"status":"disabled","serverName":"DOCS-T1","installationId":"fake-installation","environmentId":null}}` |
| +const startupAccountFrame = `{"method":"account/updated","params":{"authMode":"chatgpt","planType":"promax"}}` |
| + |
| +func TestCodexStartupNotice(t *testing.T) { |
| + cases := []struct { |
| + name string |
| + frames []json.RawMessage |
| + refuse bool |
| + }{ |
| + {"recorded", []json.RawMessage{json.RawMessage(startupAccountFrame)}, false}, |
| + {"plan-ignored", []json.RawMessage{json.RawMessage(`{"method":"account/updated","params":{"authMode":"chatgpt","planType":{"future":true}}}`)}, false}, |
| + {"duplicate", []json.RawMessage{json.RawMessage(startupAccountFrame), json.RawMessage(startupAccountFrame)}, true}, |
| + {"api-key", []json.RawMessage{json.RawMessage(`{"method":"account/updated","params":{"authMode":"apikey"}}`)}, true}, |
| + {"missing-mode", []json.RawMessage{json.RawMessage(`{"method":"account/updated","params":{}}`)}, true}, |
| + {"null-mode", []json.RawMessage{json.RawMessage(`{"method":"account/updated","params":{"authMode":null}}`)}, true}, |
| + {"id", []json.RawMessage{json.RawMessage(`{"id":7,"method":"account/updated","params":{"authMode":"chatgpt"}}`)}, true}, |
| + {"empty-id", []json.RawMessage{json.RawMessage(`{"id":"","method":"account/updated","params":{"authMode":"chatgpt"}}`)}, true}, |
| + {"null-id", []json.RawMessage{json.RawMessage(`{"id":null,"method":"account/updated","params":{"authMode":"chatgpt"}}`)}, true}, |
| + } |
| + for _, session := range []bool{false, true} { |
| + path := "preflight" |
| + if session { |
| + path = "session" |
| + } |
| + for _, tc := range cases { |
| + t.Run(path+"/"+tc.name, func(t *testing.T) { |
| + f := fixtureFor(t) |
| + f.host.startupFrames = tc.frames |
| + f.host.startupSessionOnly = session |
| + if session { |
| + s, err := f.l.Open(context.Background(), f.launch) |
| + if (err != nil) != tc.refuse { |
| + t.Fatalf("Open error=%v, refuse=%v", err, tc.refuse) |
| + } |
| + if err == nil { |
| + f.l.Close(context.Background(), s) |
| + } |
| + } else { |
| + _, err := f.l.preflight(context.Background(), f.launch.Binding, f.lease, f.inputs) |
| + if (err != nil) != tc.refuse { |
| + t.Fatalf("preflight error=%v, refuse=%v", err, tc.refuse) |
| + } |
| + } |
| + }) |
| + } |
| + } |
| +} |
| + |
| +func TestCodexSessionStartupBeforeFirstTurn(t *testing.T) { |
| + for _, method := range []string{"config/read", "thread/start", "turn/start"} { |
| + t.Run(method, func(t *testing.T) { |
| + f := fixtureFor(t) |
| + f.host.startupSessionOnly = true |
| + f.host.startupMethod = method |
| + s, events := openFixture(t, f) |
| + err := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "one", AdmissionID: "a", Prompt: "test"}) |
| + if method == "turn/start" { |
| + if err == nil { |
| + t.Fatal("account change after turn/start accepted") |
| + } |
| + } else { |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + terminal(t, events) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestCodexSessionStartupNoticeConsumed(t *testing.T) { |
| + s := &sessionState{} |
| + for _, raw := range []string{startupRemoteFrame, startupAccountFrame} { |
| + if err := s.handle(provider.Frame{Bytes: []byte(raw)}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if err := s.handle(provider.Frame{Bytes: []byte(startupAccountFrame)}); !errors.Is(err, provider.ErrContainment) { |
| + t.Fatal("second notice accepted", err) |
| + } |
| +} |
| + |
| +func TestCodexStartupAfterCompletedTurn(t *testing.T) { |
| + f := fixtureFor(t) |
| + f.host.startupFrames = []json.RawMessage{} |
| + session, events := openFixture(t, f) |
| + if err := f.l.StartTurn(context.Background(), session, provider.Turn{ID: "one", AdmissionID: "a", Prompt: "test"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + terminal(t, events) |
| + s, err := f.l.state(session) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err = s.handle(provider.Frame{Bytes: []byte(startupAccountFrame)}); !errors.Is(err, provider.ErrContainment) { |
| + t.Fatal("notice after completed turn accepted", err) |
| + } |
| +} |
diff --git a/internal/runner/provider/codex_startup.go b/internal/runner/provider/codex_startup.go| new file mode 100644 |
| index 00000000..60fb0000 |
| --- /dev/null |
| +++ b/internal/runner/provider/codex_startup.go |
| @@ -0,0 +1,10 @@ |
| +package provider |
| + |
| +import "encoding/json" |
| + |
| +func CodexStartupNotice(id json.RawMessage, method string, params json.RawMessage) bool { |
| + var p struct { |
| + AuthMode string `json:"authMode"` |
| + } |
| + return len(id) == 0 && method == "account/updated" && json.Unmarshal(params, &p) == nil && p.AuthMode == "chatgpt" |
| +} |
diff --git a/internal/runner/provider/login_probe.go b/internal/runner/provider/login_probe.go| index f8ed6fbf..3ff19407 100644 |
| --- a/internal/runner/provider/login_probe.go |
| +++ b/internal/runner/provider/login_probe.go |
| @@ -7,6 +7,7 @@ import ( |
| "encoding/json" |
| "io" |
| "os/exec" |
| + "strconv" |
| "strings" |
| "time" |
| ) |
| @@ -65,6 +66,7 @@ func (d *terminalLoginDriver) Probe(ctx context.Context, b Binding) (Identity, e |
| defer func() { cancel(); _ = cmd.Wait() }() |
| scan := bufio.NewScanner(out) |
| scan.Buffer(make([]byte, 4096), 65536) |
| + startupNoticeSeen := false |
| call := func(id, method string, params any) (json.RawMessage, error) { |
| if json.NewEncoder(in).Encode(map[string]any{"id": id, "method": method, "params": params}) != nil { |
| return nil, ErrIdentity |
| @@ -78,17 +80,21 @@ func (d *terminalLoginDriver) Probe(ctx context.Context, b Binding) (Identity, e |
| return nil, ErrIdentity |
| } |
| var r struct { |
| - ID, Method string |
| - Result, Error json.RawMessage |
| + Method string |
| + ID, Params, Result, Error json.RawMessage |
| } |
| if json.Unmarshal(raw, &r) != nil { |
| return nil, ErrIdentity |
| } |
| // Recorded 0.165.0 startup notification can precede initialize. |
| - if r.ID == "" && r.Method == "remoteControl/status/changed" && len(r.Error) == 0 { |
| + if len(r.ID) == 0 && r.Method == "remoteControl/status/changed" && len(r.Error) == 0 { |
| continue |
| } |
| - if r.ID != id || r.Method != "" || len(r.Error) != 0 { |
| + if !startupNoticeSeen && len(r.Error) == 0 && len(r.Result) == 0 && CodexStartupNotice(r.ID, r.Method, r.Params) { |
| + startupNoticeSeen = true |
| + continue |
| + } |
| + if string(r.ID) != strconv.Quote(id) || r.Method != "" || len(r.Error) != 0 { |
| return nil, ErrIdentity |
| } |
| return r.Result, nil |
diff --git a/internal/runner/provider/login_startup_test.go b/internal/runner/provider/login_startup_test.go| new file mode 100644 |
| index 00000000..c7f70b8a |
| --- /dev/null |
| +++ b/internal/runner/provider/login_startup_test.go |
| @@ -0,0 +1,96 @@ |
| +package provider |
| + |
| +import ( |
| + "context" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestLoginEnvironmentTMPDIR(t *testing.T) { |
| + for _, name := range []string{"codex", "claude"} { |
| + for _, value := range []string{"", "unset", "/scratch/test"} { |
| + t.Run(name+"/"+value, func(t *testing.T) { |
| + t.Setenv("TMPDIR", value) |
| + if value == "unset" { |
| + if err := os.Unsetenv("TMPDIR"); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + found := "" |
| + for _, entry := range LoginEnvironment(name, "/home/test") { |
| + if strings.HasPrefix(entry, "TMPDIR=") { |
| + found = entry |
| + } |
| + } |
| + want := "" |
| + if value != "" && value != "unset" { |
| + want = "TMPDIR=" + value |
| + } |
| + if found != want { |
| + t.Fatalf("TMPDIR entry=%q, want %q", found, want) |
| + } |
| + }) |
| + } |
| + } |
| +} |
| + |
| +func TestCodexLoginStartupNotice(t *testing.T) { |
| + notice := `{"method":"account/updated","params":{"authMode":"chatgpt","planType":"promax"}}` |
| + for _, tc := range []struct { |
| + name, frames string |
| + refuse bool |
| + }{ |
| + {"recorded", notice, false}, |
| + {"before-initialize", notice, false}, |
| + {"across-initialize", notice, true}, |
| + {"plan-ignored", `{"method":"account/updated","params":{"authMode":"chatgpt"}}`, false}, |
| + {"duplicate", notice + "\n" + notice, true}, |
| + {"api-key", strings.ReplaceAll(notice, "chatgpt", "apikey"), true}, |
| + {"missing-mode", `{"method":"account/updated","params":{}}`, true}, |
| + {"null-mode", `{"method":"account/updated","params":{"authMode":null}}`, true}, |
| + {"id", `{"id":"2",` + notice[1:], true}, |
| + {"empty-id", `{"id":"",` + notice[1:], true}, |
| + {"null-id", `{"id":null,` + notice[1:], true}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + root := t.TempDir() |
| + binary := filepath.Join(root, "codex") |
| + script := `#!/bin/sh |
| +case "$*" in |
| + '--version') echo 'codex-cli 0.165.0'; exit 0;; |
| + 'login --device-auth --help') exit 0;; |
| +esac |
| +IFS= read -r line |
| +PREINIT |
| +printf '{"id":"1","result":{"userAgent":"equipo/0.165.0 fixture","codexHome":"%s"}}\n' "$CODEX_HOME" |
| +IFS= read -r line |
| +printf '%s\n' '{"method":"remoteControl/status/changed","params":{"status":"disabled","serverName":"DOCS-T1","installationId":"fake-installation","environmentId":null}}' |
| +printf '%s\n' 'FRAMES' |
| +IFS= read -r line |
| +printf '%s\n' '{"id":"2","result":{"account":{"type":"chatgpt","email":"fixture@example.invalid"}}}' |
| +` |
| + preinit := "" |
| + if tc.name == "before-initialize" || tc.name == "across-initialize" { |
| + preinit = "printf '%s\\n' '" + notice + "'" |
| + } |
| + if tc.name == "before-initialize" { |
| + script = strings.ReplaceAll(script, "printf '%s\\n' 'FRAMES'", "") |
| + } |
| + script = strings.ReplaceAll(script, "PREINIT", preinit) |
| + script = strings.ReplaceAll(script, "FRAMES", tc.frames) |
| + if err := os.WriteFile(binary, []byte(script), 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + d := NewLoginDriver(LoginOptions{CodexPath: binary}).(*terminalLoginDriver) |
| + got, err := d.Probe(context.Background(), Binding{Provider: "codex", Home: root}) |
| + if (err != nil) != tc.refuse { |
| + t.Fatalf("Probe error=%v, refuse=%v", err, tc.refuse) |
| + } |
| + if err == nil && got.AccountID != "fixture@example.invalid" { |
| + t.Fatal(got) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/runner/provider/login_terminal.go b/internal/runner/provider/login_terminal.go| index 3a6da5fe..e4a10c5c 100644 |
| --- a/internal/runner/provider/login_terminal.go |
| +++ b/internal/runner/provider/login_terminal.go |
| @@ -52,7 +52,10 @@ func (d *terminalLoginDriver) binary(name string) string { |
| // LoginEnvironment matches the dedicated-home variables in policy.go and |
| // docs/live-gate.md. No inherited API keys, provider homes or user config. |
| func LoginEnvironment(name, home string) []string { |
| - env := []string{"HOME=" + home, "PATH=" + os.Getenv("PATH"), "LANG=C.UTF-8", "TERM=" + os.Getenv("TERM"), "TMPDIR=" + os.Getenv("TMPDIR")} |
| + env := []string{"HOME=" + home, "PATH=" + os.Getenv("PATH"), "LANG=C.UTF-8", "TERM=" + os.Getenv("TERM")} |
| + if tmp := os.Getenv("TMPDIR"); tmp != "" { |
| + env = append(env, "TMPDIR="+tmp) |
| + } |
| if name == "codex" { |
| return append(env, "CODEX_HOME="+home) |
| } |
diff --git a/internal/runner/provider/login_test.go b/internal/runner/provider/login_test.go| index dfc95eb0..75a16e06 100644 |
| --- a/internal/runner/provider/login_test.go |
| +++ b/internal/runner/provider/login_test.go |
| @@ -28,6 +28,7 @@ case "$*" in |
| IFS= read -r line |
| printf '{"id":"1","result":{"userAgent":"equipo/0.165.0 fixture","codexHome":"%s"}}\n' "$CODEX_HOME" |
| IFS= read -r line |
| + printf '%s\n' '{"method":"remoteControl/status/changed","params":{"status":"disabled","serverName":"DOCS-T1","installationId":"fake-installation","environmentId":null}}' '{"method":"account/updated","params":{"authMode":"chatgpt","planType":"promax"}}' |
| IFS= read -r line |
| printf '%s\n' '{"id":"2","result":{"account":{"type":"chatgpt","email":"person@example.test"}}}' |
| exit 0 ;; |
diff --git a/internal/tryequipo/accounts_test.go b/internal/tryequipo/accounts_test.go| index 6b786a5e..558181c4 100644 |
| --- a/internal/tryequipo/accounts_test.go |
| +++ b/internal/tryequipo/accounts_test.go |
| @@ -124,6 +124,9 @@ elif sys.argv[1:] == ['login','--device-auth']: |
| elif sys.argv[1] == 'app-server': |
| for line in sys.stdin: |
| q=json.loads(line) |
| + if q.get('method')=='initialized': |
| + print(json.dumps({'method':'remoteControl/status/changed','params':{'status':'disabled','serverName':'DOCS-T1','installationId':'fake-installation','environmentId':None}}),flush=True) |
| + print(json.dumps({'method':'account/updated','params':{'authMode':'chatgpt','planType':'promax'}}),flush=True) |
| if 'id' not in q: continue |
| if q['method']=='initialize': |
| print(json.dumps({'method':'remoteControl/status/changed','params':{}}),flush=True) |
diff --git a/internal/tryequipo/command.go b/internal/tryequipo/command.go| index b371308b..ee391215 100644 |
| --- a/internal/tryequipo/command.go |
| +++ b/internal/tryequipo/command.go |
| @@ -63,3 +63,11 @@ func (w *Wizard) loginCommand(ctx context.Context, path string, args []string, d |
| func liveGateArgs() []string { |
| return []string{"test", "-timeout=0", "-tags", "direct_live", "./internal/runner/provider", "-run", "^TestDirectLive(Contract|Isolation|Recovery|Calibration)$", "-count=1"} |
| } |
| + |
| +func commandStdout(ctx context.Context, path string, args []string, dir string, env []string) ([]byte, error) { |
| + cmd := childCommand(ctx, path, args, dir, env, false) |
| + out := &boundedOutput{} |
| + cmd.Stdout = out |
| + err := cmd.Run() |
| + return out.Bytes(), err |
| +} |
diff --git a/internal/tryequipo/command_test.go b/internal/tryequipo/command_test.go| new file mode 100644 |
| index 00000000..3ed7c5df |
| --- /dev/null |
| +++ b/internal/tryequipo/command_test.go |
| @@ -0,0 +1,17 @@ |
| +package tryequipo |
| + |
| +import ( |
| + "context" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestVersionStdout(t *testing.T) { |
| + out, err := commandStdout(context.Background(), "/bin/sh", []string{"-c", "printf 'codex-cli 0.165.0\n'; printf 'warning\n' >&2"}, t.TempDir(), nil) |
| + if err != nil || strings.TrimSpace(string(out)) != "codex-cli 0.165.0" { |
| + t.Fatalf("version output=%q, error=%v", out, err) |
| + } |
| + if _, err = commandStdout(context.Background(), "/bin/sh", []string{"-c", "exit 7"}, t.TempDir(), nil); err == nil { |
| + t.Fatal("command failure lost") |
| + } |
| +} |
diff --git a/internal/tryequipo/multiple_accounts_test.go b/internal/tryequipo/multiple_accounts_test.go| index dcdd9b8a..db4a2618 100644 |
| --- a/internal/tryequipo/multiple_accounts_test.go |
| +++ b/internal/tryequipo/multiple_accounts_test.go |
| @@ -48,6 +48,9 @@ elif sys.argv[1:]==['auth','status','--json']: |
| elif sys.argv[1]=='app-server': |
| for line in sys.stdin: |
| q=json.loads(line) |
| + if q.get('method')=='initialized': |
| + print(json.dumps({'method':'remoteControl/status/changed','params':{'status':'disabled','serverName':'DOCS-T1','installationId':'fake-installation','environmentId':None}}),flush=True) |
| + print(json.dumps({'method':'account/updated','params':{'authMode':'chatgpt','planType':'promax'}}),flush=True) |
| if 'id' not in q: continue |
| if q['method']=='initialize': r={'userAgent':'equipo/0.165.0 fixture','codexHome':home} |
| elif q['method']=='account/read': |
diff --git a/internal/tryequipo/prerequisites.go b/internal/tryequipo/prerequisites.go| index 0b85b85e..a8f7a4a0 100644 |
| --- a/internal/tryequipo/prerequisites.go |
| +++ b/internal/tryequipo/prerequisites.go |
| @@ -46,7 +46,7 @@ func (w *Wizard) prerequisites(ctx context.Context) (map[string]string, error) { |
| if good && d.Version != "" { |
| child, cancel := context.WithTimeout(ctx, 5*time.Second) |
| - out, e := command(child, path, []string{"--version"}, scratch, provider.LoginEnvironment(d.Name, scratch), nil) |
| + out, e := commandStdout(child, path, []string{"--version"}, scratch, provider.LoginEnvironment(d.Name, scratch)) |
| cancel() |
| good = e == nil && strings.TrimSpace(string(out)) == d.Version |
| } |