fix: wire runner account login end to end through the official CLI
28 files changed,
+1,402
−181
.rastrillo/budgets.txt+1 −1cmd/equipo-runner/account_environment.go+11 −31cmd/equipo-runner/account_login.go+34 −4cmd/equipo-runner/account_login_test.go+105 −11cmd/equipo-runner/main.go+1 −1docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+134 −0docs/superpowers/plans/LIVE-GATE-plan-3.md+88 −34internal/equipo/copy.go+16 −2internal/equipo/setup/account_connection.go+1 −1internal/equipo/setup/accounts.go+1 −1internal/equipo/templates/onboarding.html+4 −3internal/plan3test/onboarding_accounts_test.go+63 −8internal/runner/account_login.go+27 −6internal/runner/config.go+2 −1internal/runner/http.go+1 −1internal/runner/provider/claude/launcher.go+1 −10internal/runner/provider/codex/launcher.go+1 −6internal/runner/provider/login.go+0 −15internal/runner/provider/login_probe.go+122 −0internal/runner/provider/login_terminal.go+177 −0internal/runner/provider/login_test.go+159 −0internal/runner/setup/account_command.go+53 −0internal/runner/setup/account_login.go+106 −21internal/runner/setup/account_login_test.go+211 −0internal/runner/setup/account_resume.go+51 −0internal/runner/setup/account_terminal_test.go+1 −1internal/runner/setup/service.go+28 −14internal/runnerproto/account_setup.go+3 −9
CI failed — run details
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 9b66b530..0e445204 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -21,7 +21,7 @@ time internal/runner 330s Final corrected package rerun measured 152.897s; revie |
| perf GET /live skip Authorized notification stream, bounded to 30 seconds; not a GET screen. |
| perf GET /api/runner/v2/artifacts/{assignment}/{artifact} skip Authenticated runner artifact download, not a browser GET screen. Runner long-poll and blob downloads use POST and are outside the screen inventory. |
| -size internal/runner 9400 8800 Task 16 fix round 1 retains machine-key enrolment, retry validation and idle service reporting beside the runner state lock and journal. Measured 9368 source and 8719 test lines; the 119-line test overflow adds label retry and no-account startup guards. Source and 330s time ceilings are unchanged. |
| +size internal/runner 9500 8800 Task 17 fix round 1 adds authenticated terminal-login composition and saved-report recovery beside the existing runner journal and state lock. Measured 9421 source and 8719 test lines. Login lifecycle, subprocess handling and environment parsing stay in setup/provider; the 100-line source raise retains only production HTTP/config wiring here. Existing test and 330s time ceilings are unchanged. |
| time internal/runner/provider/claude 45s Task 5 measured 32.430s for fake CLI sessions and fsynced account, policy, capture and refresh checks; 45s gives 38 percent headroom on the shared runner. |
| time internal/runner/provider/codex 15s Task 11a full branch gate measured 11.659s (prior attempt 11.464s) for schema, native approval and fsynced capture fixtures; 15s gives 29 percent headroom under shared-runner load. |
diff --git a/cmd/equipo-runner/account_environment.go b/cmd/equipo-runner/account_environment.go| index c8bc222d..a1b7a5a9 100644 |
| --- a/cmd/equipo-runner/account_environment.go |
| +++ b/cmd/equipo-runner/account_environment.go |
| @@ -2,10 +2,8 @@ package main |
| import ( |
| "amadan.net/oficina/equipo/internal/runner/provider" |
| - "os" |
| + runnersetup "amadan.net/oficina/equipo/internal/runner/setup" |
| "path/filepath" |
| - "strconv" |
| - "strings" |
| ) |
| func accountEnvironment(getenv func(string) string) (func(string) string, error) { |
| @@ -16,36 +14,18 @@ func accountEnvironment(getenv func(string) string) (func(string) string, error) |
| if !filepath.IsAbs(home) { |
| return nil, provider.ErrContract |
| } |
| - path := filepath.Join(home, ".local/share/equipo-runner/runner.env") |
| - real, e := filepath.EvalSymlinks(path) |
| - if e != nil || real != path { |
| - return nil, provider.ErrPolicy |
| + root := getenv("EQUIPO_RUNNER_ROOT") |
| + if root == "" { |
| + root = filepath.Join(home, ".local/share/equipo-runner") |
| } |
| - st, e := os.Lstat(path) |
| - if e != nil || !st.Mode().IsRegular() || st.Mode().Perm() != 0600 || st.Size() > 65536 { |
| - return nil, provider.ErrPolicy |
| - } |
| - raw, e := os.ReadFile(path) |
| + values, e := runnersetup.ReadServiceEnvironment(root) |
| if e != nil { |
| - return nil, provider.ErrPolicy |
| + return nil, e |
| } |
| - values := map[string]string{} |
| - for _, line := range strings.Split(string(raw), "\n") { |
| - if line == "" || strings.HasPrefix(line, "#") { |
| - continue |
| - } |
| - key, value, ok := strings.Cut(line, "=") |
| - if !ok || !strings.HasPrefix(key, "EQUIPO_") { |
| - return nil, provider.ErrContract |
| - } |
| - if _, ok = values[key]; ok { |
| - return nil, provider.ErrContract |
| + return func(k string) string { |
| + if v := getenv(k); v != "" { |
| + return v |
| } |
| - v, e := strconv.Unquote(value) |
| - if e != nil { |
| - return nil, provider.ErrContract |
| - } |
| - values[key] = v |
| - } |
| - return func(k string) string { return values[k] }, nil |
| + return values[k] |
| + }, nil |
| } |
diff --git a/cmd/equipo-runner/account_login.go b/cmd/equipo-runner/account_login.go| index 268fe16d..66bdf9a7 100644 |
| --- a/cmd/equipo-runner/account_login.go |
| +++ b/cmd/equipo-runner/account_login.go |
| @@ -3,27 +3,57 @@ package main |
| import ( |
| "amadan.net/oficina/equipo/internal/equipo" |
| "amadan.net/oficina/equipo/internal/runner" |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| "context" |
| + "errors" |
| "fmt" |
| "io" |
| ) |
| -func accountLogin(ctx context.Context, args []string, output io.Writer, getenv func(string) string) int { |
| +func accountLogin(ctx context.Context, args []string, input io.Reader, output, errorOutput io.Writer, getenv func(string) string) int { |
| if len(args) != 3 || args[0] != "login" || args[1] != "--setup" || args[2] == "" { |
| return 1 |
| } |
| env, err := accountEnvironment(getenv) |
| if err != nil { |
| - _, _ = fmt.Fprintln(output, equipo.RunnerText("account_setup.unavailable")) |
| + _, _ = fmt.Fprintln(errorOutput, equipo.RunnerText("account_setup.config")) |
| return 1 |
| } |
| cfg, err := runner.LoadConfig(env) |
| if err == nil { |
| - err = runner.LoginAccount(ctx, cfg, args[2]) |
| + err = runner.LoginAccount(ctx, cfg, args[2], newAccountLoginDriver(provider.LoginOptions{ClaudePath: cfg.ClaudePath, CodexPath: cfg.CodexPath, Input: input, Output: output, ErrorOutput: errorOutput})) |
| } |
| if err != nil { |
| - _, _ = fmt.Fprintln(output, equipo.RunnerText("account_setup.unavailable")) |
| + _, _ = fmt.Fprintln(errorOutput, equipo.RunnerText(accountLoginFailure(err))) |
| return 1 |
| } |
| return 0 |
| } |
| + |
| +var newAccountLoginDriver = provider.NewLoginDriver |
| + |
| +func accountLoginFailure(err error) string { |
| + var refusal *runner.RefusalError |
| + switch { |
| + case errors.Is(err, context.Canceled): |
| + return "account_setup.cancelled" |
| + case errors.Is(err, runner.ErrTransient): |
| + return "account_setup.network" |
| + case errors.As(err, &refusal), errors.Is(err, provider.Error("account_setup.invalid")): |
| + return "account_setup.invalid" |
| + case errors.Is(err, provider.ErrIdentity): |
| + return "account_setup.identity_failed" |
| + case errors.Is(err, provider.ErrLoginUnavailable): |
| + return "account_setup.unavailable" |
| + case errors.Is(err, provider.Error("account_setup.expired")): |
| + return "account_setup.expired" |
| + case errors.Is(err, provider.Error("account_setup.denied")): |
| + return "account_setup.denied" |
| + case errors.Is(err, provider.ErrUncertain): |
| + return "account_setup.interrupted" |
| + case errors.Is(err, provider.ErrAccountMaintenance): |
| + return "account_setup.save_failed" |
| + default: |
| + return "account_setup.config" |
| + } |
| +} |
diff --git a/cmd/equipo-runner/account_login_test.go b/cmd/equipo-runner/account_login_test.go| index bf5fc74d..15eccfb7 100644 |
| --- a/cmd/equipo-runner/account_login_test.go |
| +++ b/cmd/equipo-runner/account_login_test.go |
| @@ -4,6 +4,8 @@ import ( |
| "bytes" |
| "context" |
| "encoding/json" |
| + "errors" |
| + "fmt" |
| "io" |
| "net/http" |
| "os" |
| @@ -12,6 +14,8 @@ import ( |
| "testing" |
| "time" |
| + "amadan.net/oficina/equipo/internal/runner" |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| "amadan.net/oficina/equipo/internal/runnerproto" |
| ) |
| @@ -19,9 +23,33 @@ type accountTransport func(*http.Request) (*http.Response, error) |
| func (f accountTransport) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) } |
| func TestOnboardingClaudeHeadlessBrowserLogin(t *testing.T) { |
| + for _, supported := range []bool{false, true} { |
| + t.Run(fmt.Sprint(supported), func(t *testing.T) { testAccountCommand(t, supported) }) |
| + } |
| +} |
| +func testAccountCommand(t *testing.T, supported bool) { |
| root := t.TempDir() |
| fake := filepath.Join(root, "fake") |
| - if e := os.WriteFile(fake, []byte("#!/bin/sh\nexit 99\n"), 0700); e != nil { |
| + script := "#!/bin/sh\nexit 99\n" |
| + if supported { |
| + script = `#!/bin/sh |
| +set -eu |
| +umask 077 |
| +case "$*" in |
| + '--version') echo '2.1.312 (Claude Code)' ;; |
| + 'auth login --help') exit 0 ;; |
| + 'auth login') |
| + test "$HOME" = "$CLAUDE_CONFIG_DIR" |
| + test "$HOME" = "$CLAUDE_SECURESTORAGE_CONFIG_DIR" |
| + IFS= read -r code |
| + test "$code" = TERMINAL-RETURN-SECRET |
| + printf '%s' '{"token":"NATIVE-SECRET"}' > "$HOME/.credentials.json" ;; |
| + 'auth status --json') printf '%s' '{"loggedIn":true,"authMethod":"claude.ai","email":"person@example.test"}' ;; |
| + *) exit 3 ;; |
| +esac |
| +` |
| + } |
| + if e := os.WriteFile(fake, []byte(script), 0700); e != nil { |
| t.Fatal(e) |
| } |
| state := filepath.Join(root, "state") |
| @@ -37,40 +65,85 @@ func TestOnboardingClaudeHeadlessBrowserLogin(t *testing.T) { |
| for _, key := range []string{"EQUIPO_CLAUDE_PATH", "EQUIPO_CODEX_PATH", "EQUIPO_AMADAN_PATH", "EQUIPO_BWRAP_PATH", "EQUIPO_CODEX_CODE_MODE_HOST_PATH", "EQUIPO_ACCOUNT_BINDINGS_PATH", "EQUIPO_AMADAN_CREDENTIAL_PATH", "EQUIPO_GO_ROOT", "EQUIPO_GO_BINARY", "EQUIPO_GIT_PATH"} { |
| values[key] = fake |
| } |
| + values["EQUIPO_CLAUDE_MODEL"] = "fixture-model" |
| + values["EQUIPO_ACCOUNT_BINDINGS_PATH"] = filepath.Join(state, "accounts.json") |
| prior := http.DefaultTransport |
| t.Cleanup(func() { http.DefaultTransport = prior }) |
| calls := 0 |
| + lostReport := false |
| + setup := runnerproto.AccountSetup{ID: "pending-setup", RunnerID: "runner", Provider: "claude", State: "pending", Mode: "browser", Revision: 1} |
| http.DefaultTransport = accountTransport(func(r *http.Request) (*http.Response, error) { |
| calls++ |
| if r.URL.Path != "/api/runner/v2/account-setups" || r.Header.Get("Authorization") != "Bearer fixture-bearer" { |
| t.Fatal("wrong authenticated channel", r.URL) |
| } |
| var q runnerproto.AccountSetupRequest |
| - if e := runnerproto.Decode(r.Body, &q); e != nil { |
| + rawRequest, e := io.ReadAll(r.Body) |
| + if e != nil || bytes.Contains(rawRequest, []byte("SECRET")) || bytes.Contains(rawRequest, []byte(root)) { |
| + t.Fatal("terminal data entered request") |
| + } |
| + if e := runnerproto.Decode(bytes.NewReader(rawRequest), &q); e != nil { |
| t.Fatal(e) |
| } |
| if q.ID != "pending-setup" { |
| t.Fatal("wrong setup ID") |
| } |
| - s := runnerproto.AccountSetup{ID: q.ID, RunnerID: "runner", Provider: "claude", State: "pending", Mode: "browser", Revision: 1} |
| - if calls == 2 { |
| - if q.Result == nil || q.Result.State != "unavailable" || q.Result.Challenge != nil { |
| - t.Fatal("unconfirmed contract accepted", q) |
| + if q.Result != nil { |
| + if q.Result.Challenge != nil { |
| + t.Fatal("display left terminal") |
| + } |
| + if q.Result.State == "connected" && (q.Result.AccountID != "person@example.test" || q.Result.ProviderVersion != "2.1.312") { |
| + t.Fatal("missing verified identity") |
| + } |
| + setup.State = q.Result.State |
| + setup.Revision++ |
| + if supported && q.Result.State == "connected" && !lostReport { |
| + lostReport = true |
| + return nil, errors.New("fixture dropped successful report response") |
| } |
| - s.State = "unavailable" |
| - s.Revision = 2 |
| } |
| - raw, _ := runnerproto.Marshal(runnerproto.WorkResponse{Version: 2, Result: s}) |
| + raw, _ := runnerproto.Marshal(runnerproto.WorkResponse{Version: 2, Result: setup}) |
| return &http.Response{StatusCode: 200, Body: io.NopCloser(bytes.NewReader(raw)), Header: make(http.Header)}, nil |
| }) |
| + journal, e := runner.OpenJournal(context.Background(), filepath.Join(state, "journal.db")) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + t.Cleanup(func() { _ = journal.Close() }) |
| var out, logs bytes.Buffer |
| code := run(context.Background(), []string{"account", "login", "--setup", "pending-setup"}, strings.NewReader("TERMINAL-RETURN-SECRET\n"), &out, &logs, func(k string) string { return values[k] }) |
| - if code != 1 || calls != 2 || strings.Contains(logs.String(), "SECRET") || strings.Contains(logs.String(), "fixture-bearer") || strings.Contains(logs.String(), root) { |
| + wantCode, wantState := 1, "unavailable" |
| + if supported { |
| + wantCode, wantState = 0, "connected" |
| + } |
| + if code != wantCode || calls < 3 || setup.State != wantState || strings.Contains(logs.String(), "SECRET") || strings.Contains(logs.String(), "fixture-bearer") || strings.Contains(logs.String(), root) { |
| t.Fatal("unsafe terminal command", code, calls, logs.String()) |
| } |
| - if _, e := os.Stat(filepath.Join(state, "accounts")); !os.IsNotExist(e) { |
| + if _, e := os.Stat(filepath.Join(state, "accounts")); !supported && !os.IsNotExist(e) { |
| t.Fatal("unavailable flow allocated a credential home") |
| } |
| + if supported { |
| + if !lostReport { |
| + t.Fatal("lost report not exercised") |
| + } |
| + raw, e := os.ReadFile(values["EQUIPO_ACCOUNT_BINDINGS_PATH"]) |
| + if e != nil || !bytes.Contains(raw, []byte("person@example.test")) || bytes.Contains(raw, []byte("SECRET")) { |
| + t.Fatal("binding was not saved safely", e) |
| + } |
| + // This command has no journal: terminal streams never enter captures/events. |
| + paths, e := filepath.Glob(filepath.Join(state, "*.jsonl")) |
| + if e != nil || len(paths) != 0 { |
| + t.Fatal("login created journal events") |
| + } |
| + } |
| + events, e := journal.Pending(context.Background(), 10) |
| + if e != nil || len(events) != 0 { |
| + t.Fatal("login leaked journal events", e) |
| + } |
| + rawJournal, e := os.ReadFile(filepath.Join(state, "journal.db")) |
| + if e != nil || bytes.Contains(rawJournal, []byte("SECRET")) { |
| + t.Fatal("login secret entered journal", e) |
| + } |
| calls = 0 |
| for _, args := range [][]string{{"account", "login"}, {"account", "login", "--setup", "id", "--code", "SECRET"}, {"account", "login", "--setup", ""}} { |
| if run(context.Background(), args, strings.NewReader(""), &out, &logs, func(k string) string { return values[k] }) != 1 { |
| @@ -119,3 +192,24 @@ func TestOnboardingAccountEnvironment(t *testing.T) { |
| t.Fatal("duplicate environment accepted") |
| } |
| } |
| + |
| +func TestOnboardingAccountFailureMessages(t *testing.T) { |
| + cases := map[error]string{context.Canceled: "account_setup.cancelled", runner.ErrTransient: "account_setup.network", provider.ErrIdentity: "account_setup.identity_failed", provider.ErrLoginUnavailable: "account_setup.unavailable", provider.ErrUncertain: "account_setup.interrupted", provider.ErrAccountMaintenance: "account_setup.save_failed", provider.ErrContract: "account_setup.config"} |
| + for err, want := range cases { |
| + if got := accountLoginFailure(err); got != want { |
| + t.Fatal("failure kind hidden", err, got) |
| + } |
| + } |
| +} |
| + |
| +func TestOnboardingAccountCustomEnvironment(t *testing.T) { |
| + root := t.TempDir() |
| + if e := os.WriteFile(filepath.Join(root, "runner.env"), []byte("EQUIPO_ORIGIN=https://fixture.test\nEQUIPO_INSTANCE_ID=fixture\n"), 0600); e != nil { |
| + t.Fatal(e) |
| + } |
| + values := map[string]string{"HOME": t.TempDir(), "EQUIPO_RUNNER_ROOT": root} |
| + env, e := accountEnvironment(func(k string) string { return values[k] }) |
| + if e != nil || env("EQUIPO_INSTANCE_ID") != "fixture" { |
| + t.Fatal("custom root or unquoted environment rejected", e) |
| + } |
| +} |
diff --git a/cmd/equipo-runner/main.go b/cmd/equipo-runner/main.go| index e6573249..3f3b903e 100644 |
| --- a/cmd/equipo-runner/main.go |
| +++ b/cmd/equipo-runner/main.go |
| @@ -30,7 +30,7 @@ func run(ctx context.Context, args []string, input io.Reader, output, errorOutpu |
| return 0 |
| } |
| if len(args) > 0 && args[0] == "account" { |
| - return accountLogin(ctx, args[1:], errorOutput, getenv) |
| + return accountLogin(ctx, args[1:], input, output, errorOutput, getenv) |
| } |
| if len(args) > 0 && args[0] == "install" { |
| return installRunner(ctx, args[1:], input, output, errorOutput, getenv) |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index b60190db..491f4a30 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -4292,3 +4292,137 @@ Authority and audit share the write transaction. Result replay rechecks current |
| | onboarding.first_instructions | Read the project material and recommend what to work on next. Cite the sources for each recommendation. Do not edit files, create a branch or publish changes. | |
| Full report: `.superpowers/sdd/2026-11-04-equipo-plan-3-coordinator/task-17-report.md` (local, ignored). |
| + |
| +## Fix round 1 |
| + |
| +Status: DONE_WITH_CONCERNS. This section supersedes the original report's unavailable-only production-driver description. The end-to-end terminal login path is implemented for both providers. No push, merge, deployment, real provider run, sign-in or enrolment occurred. No subagent or copy-review server was started, no README was changed and no `.claude/HANDOFF.md` was created. |
| + |
| +Commit subject: `fix: wire runner account login end to end through the official CLI`. |
| +Author: `codex <codex~paul@keymail.dev>`. Branch: `plan-3`. |
| + |
| +### Implementation and review findings |
| + |
| +- **Important 1 / controller ruling:** The command passes its actual input, output and error streams into an injectable production LoginDriver, checks the setup against the authenticated runner/person/generation, checks the CLI version and login subcommand, allocates a fresh private home, starts the official CLI, polls until terminal state, verifies identity, saves the binding and reports the safe result. `SaveAccountBinding` now has a production caller. The runner service never waits on terminal input. The explicit model source is `EQUIPO_CLAUDE_MODEL` or `EQUIPO_CODEX_MODEL`, read from the environment or private installed runner.env; missing model configuration fails before allocating a home. |
| +- **Offline command sources:** Claude `auth login` is recorded in `docs/live-gate.md:75`. Codex `login --device-auth` is required by the Plan 3 supported-setup ruling and this fix-round dispatch. Dedicated-home variables reuse `provider/policy.go` and `docs/live-gate.md`: `CLAUDE_CONFIG_DIR`, `CLAUDE_SECURESTORAGE_CONFIG_DIR`, and `CODEX_HOME`. HOME and cwd also point at the new home. Provider API keys and interactive configuration are not inherited. CLI login stdout/stderr and input are passed through, never parsed or captured by Equipo. |
| +- **Identity:** After exit 0, Claude `auth status --json` and Codex app-server `account/read` use the Plan 2b response contracts. The existing adapters and login path now share their identity decoders. The local HomeID is generated by Equipo. `OpenAccount` stages the credential and a second identity probe applies the existing same-identity preflight rules. Probe errors leave setup unavailable, never connected. The version capability is checked again on identity probes, including saved-binding recovery. |
| +- **Important 2:** LIVE-GATE-plan-3.md section 3b now gives the exact per-provider Equipo commands, explicit model/root configuration, evidence to collect, and both pins: Claude Code 2.1.312 and Codex 0.165.0. It names the connected-result pin check in `internal/equipo/setup/accounts.go` (review line 286). It no longer asks for implementation of a driver. Real headless flow and official callback behavior remain live evidence, not invented contracts. |
| +- **Minor 1:** A successful Save retains the exact completion report. Poll retries it without recreating the identity marker or saving again. The command retries three times; a later invocation can recognize a saved binding, recheck identity and retry only its report while the setup remains pending. A pre-Save crash remains uncertain. The command fixture drops a successful report response and still reaches connected without duplicate Save. |
| +- **Minor 2:** Failed Begin, invalid challenge, expiry, cancellation and failed identity checks remove unsaved homes and their allocation markers. Saved homes are retained. SIGINT is forwarded to the CLI, with a two-second grace before forced termination. Cancel reports use a fresh bounded context even when interruption races Begin, identity probing or the roster recheck. The official CLI owns any browser listener; Equipo creates none. |
| +- **Minor 3:** Invalid setup, configuration, network, interrupted setup, identity failure, binding-save failure, expiry, denial, cancellation and missing CLI capability have distinct diagnostic keys. Account-setup HTTP 4xx refusals are classified as setup refusals rather than version errors. New entries are individually marked COPY REVIEW REQUIRED. |
| +- **Minor 4:** The command and installer use `ReadServiceEnvironment` in runner/setup/service.go. It accepts the existing quoted and unquoted formats, rejects duplicate keys and nonprivate/symlinked files, limits size, and supports `EQUIPO_RUNNER_ROOT` for custom installations. Explicit terminal environment values can override installed configuration. |
| +- **Minor 5/6/7:** Codex gets browser device-code instructions; Claude gets terminal return-code instructions. The library action is inside the specialists stage. An already reported unavailable setup is shown before the account form, and has no pending login command. A fresh setup remains available so a person can retry after correcting the CLI installation; a failed setup is not treated as a permanent machine capability claim. |
| +- **Minor 8:** Removed the unused waiting_runner setup state branch. The seeded connection still waits for its ordinary runner report, under the separate `account_setup.waiting_report` reason/key. |
| +- **Minor 9:** Removed top-level Test calls from TestOnboardingSafeFirstTask. Recommendation delivery and independent-family tests run as independent named tests. Added HTTP first-task and cancellation tests, including authority/CSRF/form boundaries; the first-task test checks its persisted recommendation/person plan and idempotent redirect. |
| +- **Minor 10:** The dedicated-home test now performs identity readback. The command fixture opens a real runner journal, checks no login events were appended and no secret appears in its database. It also inspects instance request bodies, diagnostic output and the saved binding. Added wall-clock expiry, failed Begin cleanup, saved-report recovery and interruption tests. Existing pseudo-terminal fixtures remain; production-driver tests use fake binaries on PATH and pipe terminal input under TMPDIR. |
| +- **Display contract:** Removed the unverified Codex URI and code regexp from production. LoginDisplay is optional and remains nil; nonnil display data is rejected for both providers. No device secret, code, home path or provider challenge ID can be sent by this path. |
| + |
| +### Tests first and iterative failures |
| + |
| +1. `CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner/setup -run '^TestOnboarding(OfficialLogin|AccountReportRetry|AccountClockExpiry)$' -count=1` exited 1 before implementation. Provider failed to build because LoginOptions and the injectable constructor were absent. The lifecycle tests failed with `saved account report not retryable` and `expired home retained`. The same command passed after implementation (provider 0.012s, setup 0.090s). |
| +2. `CGO_ENABLED=0 go test ./internal/runner/setup -run '^TestOnboardingAccountInterruptDuringBegin$' -count=1` exited 1 with `interrupt during Begin not reported`; after the fresh-context cancellation report it passed (0.011s). |
| +3. `CGO_ENABLED=0 go test ./internal/runner/setup -run '^TestOnboardingAccountInterruptDuringProbe$' -count=1` exited 1 with `probe interrupt not cancelled`; after cancellation was handled at each pre-Save boundary it passed in the final lifecycle command below. |
| +4. An early integration run failed because the old command test expected unavailable before the new explicit model configuration and because a library-link assertion matched sidebar navigation. The command fixture now supplies a model and covers both supported and unsupported CLIs; the stage assertion matches the action's copy. An initial version mutation was masked by a fixture that also lacked the login subcommand. That fixture was corrected so only version differs; the repeated mutation failed behaviorally. The masked run is not counted as guard evidence. |
| + |
| +### Verification |
| + |
| +All final checks below exited 0. Only named/targeted tests ran; no full suite or make ci was used. Go caches stayed at their defaults. |
| + |
| +- `CGO_ENABLED=0 go test ./cmd/equipo-runner ./internal/runner/... ./internal/equipo/setup ./internal/plan3test -run '^Test(Onboarding(Account|Device|Claude|NoDevice|Safe|Specialists|Official|InstallPrerequisites)|PlanWorkflowRecommendation|PlanModelChoiceReviewFamily)' -count=1`: command 0.607s, runner 20.417s, provider 0.024s, runner/setup 1.007s, equipo/setup 0.689s, plan3test 2.891s. Other runner packages compiled with no matching tests. |
| +- After all guard restorations: `CGO_ENABLED=0 go test ./cmd/equipo-runner ./internal/runner/setup ./internal/runner/provider ./internal/equipo/setup ./internal/plan3test -run '^Test(Onboarding(Account|Device|Claude|NoDevice|Safe|Specialists|Official|InstallPrerequisites)|PlanWorkflowRecommendation|PlanModelChoiceReviewFamily)' -count=1`: command 0.539s, setup 1.009s, provider 0.026s, equipo/setup 0.671s, plan3test 2.611s. |
| +- After cancellation-race fixes: `CGO_ENABLED=0 go test ./internal/runner/setup ./internal/runner/provider ./cmd/equipo-runner -run '^TestOnboarding(Account|Claude|Official|Device|NoDevice)' -count=1`: setup 0.626s, provider 0.026s, command 0.345s. |
| +- `CGO_ENABLED=0 go test ./internal/equipotest -run '^Test(ConnectionsBelongToPersonAndMachine|ConnectionsHTTPAuthority|ConnectionsAtomicWrites|ConnectionSelectionModelAndAllowance|ReviewWaitsForOtherFamily|EnrolmentAudience|RunnerRemovalRevokes|SpecialistsSeedOnce|SpecialistSettingsCurrentOwner|RunnerAppCSRF|RunnerWireAndJournal)$' -count=1`: 6.075s. |
| +- `CGO_ENABLED=0 go test ./internal/runner/provider/claude ./internal/runner/provider/codex -run '^Test(ClaudeObservedIdentity|ClaudeNativeIdentityMetadata|CodexIdentityWithoutHomeEcho|CodexRefreshRejectsChangedIdentity)$' -count=1`: Claude 1.404s; Codex 0.436s. |
| +- `CGO_ENABLED=0 go test ./internal/runner ./internal/runner/provider ./internal/runnerproto -run '^Test(AccountHomeBinding|AccountHomeConfigured|AccountHomeRefresh|RunnerConfig|RunnerServiceLifecycle|OnboardingServiceWithoutAccounts|DirectBinding|Wire|Decode)' -count=1`: runner 0.403s; provider 0.090s; runnerproto compiled with no matching tests. |
| +- `CGO_ENABLED=0 go test ./internal/equipo -run '^Test(TemplateCopyKeys|MigrationModels|ConversationMigrationSnapshot)$' -count=1`: 2.757s. No migration or schema change was needed for this fix round. |
| +- `CGO_ENABLED=0 go test ./cmd/equipo-runner -run '^TestOnboardingClaudeHeadlessBrowserLogin$' -count=1`: lost-successful-response command fixture passed, 0.425s. |
| +- `CGO_ENABLED=0 go test ./internal/plan3test -run '^TestOnboardingSafeFirstTaskHTTP$' -count=1`: persisted plan and idempotent HTTP response passed. |
| +- `CGO_ENABLED=0 go vet ./cmd/equipo-runner ./internal/equipo ./internal/equipo/setup ./internal/runner ./internal/runner/setup ./internal/runner/provider ./internal/runner/provider/claude ./internal/runner/provider/codex ./internal/runnerproto ./internal/plan3test`. |
| +- `CGO_ENABLED=0 go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./cmd/equipo-runner ./internal/equipo ./internal/equipo/setup ./internal/runner ./internal/runner/setup ./internal/runner/provider ./internal/runner/provider/claude ./internal/runner/provider/codex ./internal/runnerproto ./internal/plan3test`. |
| +- Vet and staticcheck were repeated on runner/setup, provider and the command after the last cancellation changes, and passed. |
| +- `CGO_ENABLED=0 make budget`: 34 directories within budget. `gofmt -l` on changed/new Go files and `git diff --check`: no output. |
| + |
| +### Guard mutations |
| + |
| +Each mutation below was applied alone, failed behaviorally with exit 1, and was restored immediately. The commands above passed with all guards restored. None of the counted failures was a compilation failure. |
| + |
| +- **version pin**: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestOnboardingOfficialLoginCapability/wrong-version$ -count=1`. Exit 1: `unsupported CLI accepted`. Restored. |
| +- **login subcommand capability**: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestOnboardingOfficialLoginCapability/missing-subcommand$ -count=1`. Exit 1: `unsupported CLI accepted`. Restored. |
| +- **private dedicated home**: `CGO_ENABLED=0 go test ./internal/runner/setup -run ^TestOnboardingAccountDedicatedHome$ -count=1`. Exit 1: `interactive home accepted`. Restored. |
| +- **identity readback**: `CGO_ENABLED=0 go test ./internal/runner/setup -run ^TestOnboardingAccountIdentityReadback$ -count=1`. Exit 1: `identity readback bypassed`. Restored. |
| +- **display secrecy**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestOnboardingAccountRunnerGuards$ -count=1`. Exit 1: `browser challenge stored <nil>`. Restored. |
| +- **saved report retry**: `CGO_ENABLED=0 go test ./internal/runner/setup -run ^TestOnboardingAccountReportRetry$ -count=1`. Exit 1: `saved account report not retryable { <nil> 0} provider_identity_mismatch 1`. Restored. |
| +- **Begin cleanup**: `CGO_ENABLED=0 go test ./internal/runner/setup -run ^TestOnboardingAccountBeginCleanup$ -count=1`. Exit 1: `failed Begin leaked home or marker [d account-2286102465/ - setup-29469f19afeae740e5d6f9dfa04f00267b21bd19947e6dc778698e1cf17492cf.json] <nil>`. Restored. |
| +- **clock expiry**: `CGO_ENABLED=0 go test ./internal/runner/setup -run ^TestOnboardingAccountClockExpiry$ -count=1`. Exit 1: `clock expiry ignored {setup-one runner codex pending device <nil> 2} <nil>`. Restored. |
| +- **SIGINT forwarding**: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestOnboardingOfficialLoginInterrupt$ -count=1`. Exit 1: `SIGINT did not reach CLI stat /home/paulca/.cache/tmp/TestOnboardingOfficialLoginInterrupt1724342432/001/accounts/account-2061360429/interrupted: no such fil...`. Restored. |
| +- **provider instructions**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestOnboardingAccountInstructions$ -count=1`. Exit 1: `wrong provider instructions`. Restored. |
| +- **saved binding owner**: `CGO_ENABLED=0 go test ./internal/runner/setup -run ^TestOnboardingAccountResumeSavedReport$ -count=1`. Exit 1: `saved binding changed owner`. Restored. |
| +- **read-only recommendation**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPlanWorkflowRecommendation$ -count=1`. Exit 1: `research gained write authority: {RequestKey:task/plan/1 Project:1 Account:team Parent:0 Requester:owner@example.com GrantRef:eyJ2ZXJzaW9uIjoxLCJwcm9qZWN0X2l...`. Restored. |
| +- **independent review family**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPlanModelChoiceReviewFamily$ -count=1`. Exit 1: `The information is unavailable. Try again in a minute.`. Restored. |
| + |
| +### Budgets and self-review |
| + |
| +The first size check failed at 9,418 runner source lines against 9,400. Final runner wiring totals 9,421 source / 8,719 test lines. The existing exception is now 9,500 source / 8,800 test, with the measured totals and reason recorded in `.rastrillo/budgets.txt`. The extra 100 source lines cover only command composition, configuration and HTTP refusal handling; lifecycle, subprocess and parser code remains in setup/provider. No new default-valued exception or time raise was added. plan3test stays inside its existing 8,600 test-line exception. Full-package timing was not measured under the targeted-only dispatch. |
| + |
| +Final physical Go line totals (source / test): |
| + |
| +- `internal/equipo`: 10,794 / 437. |
| +- `internal/runner`: 9,421 / 8,719. |
| +- `internal/runner/setup`: 1,036 / 991. |
| +- `internal/runner/provider`: 3,086 / 1,952. |
| +- `internal/runner/provider/claude`: 1,121 / 1,443. |
| +- `internal/runner/provider/codex`: 1,739 / 2,267. |
| +- `internal/plan3test`: 741 / 8,386. |
| +- `cmd/equipo-runner`: 397 / 311. |
| +- `internal/runnerproto`: 2,376 / 60. |
| +- `internal/equipo/setup`: 1,950 / 318. |
| + |
| +Authority and audit still share the instance write transaction. Before Save, the runner rechecks the live setup; result replay rechecks runner credentials, roster and generations on the instance. Saved-report recovery verifies the saved person, provider and identity rather than treating a leftover allocation marker as success. Sign-in alone does not make a connection executable: the seeded report remains unavailable until ordinary runner reporting/certification. Existing same-identity refresh rules are unchanged. |
| + |
| +The remaining concerns are live evidence and unreviewed copy. No claim is made that synthetic fixtures certify real headless login, CLI listener behavior or real-provider refresh. These are explicit checks in LIVE-GATE section 3b, not missing driver code. A network outage during cancellation can prevent the instance from receiving the cancelled report; the local child still stops and its unsaved home is removed, and the instance's setup expires. A process crash before Save remains uncertain and needs a new setup. Scratch created for this task is removed before handoff; no server or background process is retained. |
| + |
| +### Pending copy |
| + |
| +All new or renamed runtime entries below are individually marked `COPY REVIEW REQUIRED` in `internal/equipo/copy.go`. Existing setup status strings retain their pending markers. The unused `account_setup.waiting_runner` key was replaced by `account_setup.waiting_report`. LIVE-GATE section 3b is also flagged draft copy. No copy-review server was run, per dispatch. |
| + |
| +| Key | Draft text | |
| +| --- | --- | |
| +| account_setup.device | Run this command on the paired machine. Follow the official CLI instructions to enter its device code in your browser. | |
| +| account_setup.config | Check the runner configuration and the selected provider model. | |
| +| account_setup.network | The instance could not be reached. Try again. | |
| +| account_setup.invalid | This setup ID is missing, expired, cancelled or belongs to another runner. Start a new setup. | |
| +| account_setup.interrupted | This sign-in was interrupted. Start a new setup. | |
| +| account_setup.save_failed | The account binding could not be saved. Check the runner configuration and start again. | |
| +| account_setup.identity_failed | The signed-in account could not be verified. Start a new setup. | |
| +| account_setup.waiting_report | Waiting for the runner to report this account. | |
| + |
| +### Files changed |
| + |
| +- `internal/runner/provider/login_probe.go` |
| +- `internal/runner/provider/login_terminal.go` |
| +- `internal/runner/provider/login_test.go` |
| +- `internal/runner/setup/account_command.go` |
| +- `internal/runner/setup/account_resume.go` |
| +- `.rastrillo/budgets.txt` |
| +- `cmd/equipo-runner/account_environment.go` |
| +- `cmd/equipo-runner/account_login.go` |
| +- `cmd/equipo-runner/account_login_test.go` |
| +- `cmd/equipo-runner/main.go` |
| +- `docs/superpowers/plans/LIVE-GATE-plan-3.md` |
| +- `internal/equipo/copy.go` |
| +- `internal/equipo/setup/account_connection.go` |
| +- `internal/equipo/setup/accounts.go` |
| +- `internal/equipo/templates/onboarding.html` |
| +- `internal/plan3test/onboarding_accounts_test.go` |
| +- `internal/runner/account_login.go` |
| +- `internal/runner/config.go` |
| +- `internal/runner/http.go` |
| +- `internal/runner/provider/claude/launcher.go` |
| +- `internal/runner/provider/codex/launcher.go` |
| +- `internal/runner/provider/login.go` |
| +- `internal/runner/setup/account_login.go` |
| +- `internal/runner/setup/account_login_test.go` |
| +- `internal/runner/setup/account_terminal_test.go` |
| +- `internal/runner/setup/service.go` |
| +- `internal/runnerproto/account_setup.go` |
| +- `docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md` (this appended fix-round report). |
| +- `.superpowers/sdd/2026-11-04-equipo-plan-3-coordinator/task-17-report.md` (full local report, ignored by git). |
diff --git a/docs/superpowers/plans/LIVE-GATE-plan-3.md b/docs/superpowers/plans/LIVE-GATE-plan-3.md| index 9e18eda0..2ad7a3b9 100644 |
| --- a/docs/superpowers/plans/LIVE-GATE-plan-3.md |
| +++ b/docs/superpowers/plans/LIVE-GATE-plan-3.md |
| @@ -141,37 +141,91 @@ report. Stop the disposable instance and runner, verify that their children have |
| exited, and remove only scratch created for this run. Preserve the private evidence |
| bundle and the dedicated homes. Do not publish secrets or sign-in links. |
| -## 3b: account login contracts |
| - |
| -Task 17 keeps production account login unavailable. The offline Plan 2b guide, |
| -`docs/live-gate.md`, records `claude auth login` and `codex login` with dedicated |
| -homes. The provider fixtures record session and account readback protocols, but |
| -contain no device-login transcript or headless browser return-code transcript. |
| -They do not confirm `codex login --device-auth` for 0.165.0, the device display |
| -format, cancellation and expiry signals, or Claude 2.1.312's headless exchange |
| -and callback listener behavior. No provider was invoked to fill these gaps. |
| - |
| -Before enabling either production driver, Paul must explicitly authorize a |
| -separate exercise with new dedicated accounts. Record the pinned binary's |
| -supported login commands and the complete terminal flow, then sanitize the |
| -recording. Confirm that Codex supports the official device flow and that Claude |
| -supports opening its official link on another device with the returned code |
| -entered only at the runner terminal. Any callback listener must bind loopback, |
| -belong to the setup process and close on success, cancellation and expiry. |
| -Do not infer a verification address or use private OAuth endpoints. |
| - |
| -Implement the driver against those recordings, including identity readback, |
| -terminal process cancellation and expiry. Wire its verified binding into the |
| -runner's account file and ordinary connection reports. The current production |
| -constructor deliberately cannot launch either CLI; the terminal and device |
| -fixtures test the local boundary only and are not provider certification. |
| -Exercise the complete command, instance correlation and restarted runner with |
| -two labeled accounts from one provider. Verify that a repeated result does not |
| -create another connection, unknown allowance stays unknown, and a new login |
| -never replaces an existing home. Retain the existing same-identity refresh |
| -rules. Confirm that credentials, polling secrets and browser return codes are |
| -absent from instance traffic, browser forms, logs, journals and audit records. |
| - |
| -The synthetic terminal fixture uses a pseudo-terminal and fake binaries under |
| -TMPDIR. It establishes no claim about a real provider's browser exchange. |
| -App copy added for these states remains marked COPY REVIEW REQUIRED in copy.go. |
| +## 3b: terminal account login |
| + |
| +Draft instructions, COPY REVIEW REQUIRED. Paul runs this gate only after explicitly |
| +choosing to use dedicated accounts. Task 17 now supplies the production terminal |
| +driver and binding/report wiring. No implementation flag or login-output parser |
| +is needed to enable it. Missing CLI capability or a version mismatch returns |
| +unavailable. These offline tests do not certify real sign-in or callback behavior. |
| + |
| +The pins must agree in `internal/runner/provider/login_terminal.go`, the existing |
| +Claude/Codex adapters, and the connected-result check in |
| +`internal/equipo/setup/accounts.go` (the review's line 286): Claude Code **2.1.312** |
| +and Codex **0.165.0**. Changing a pin needs a new reviewed release and certification. |
| +Claude's exact login argv is `claude auth login`, recorded in |
| +`docs/live-gate.md:75`. Codex's `codex login --device-auth` comes from the Plan 3 |
| +supported-setup ruling and the Task 17 fix-round dispatch. The driver checks |
| +`--version` and the selected login command with `--help` before login. It does not |
| +parse the login output, assume a sign-in address or extract a code. |
| + |
| +On the paired Linux/amd64 runner, use the installed private `runner.env`. For a |
| +custom install root, set `EQUIPO_RUNNER_ROOT` to that root. Keep the configured |
| +`EQUIPO_CLAUDE_PATH`, `EQUIPO_CODEX_PATH` and `EQUIPO_ACCOUNT_BINDINGS_PATH` values. |
| +Set an exact model for each new binding using `EQUIPO_CLAUDE_MODEL` or |
| +`EQUIPO_CODEX_MODEL`; these are explicit configuration, not inferred from login. |
| +Choose the same model intended for the later certified connection report. |
| + |
| +For Claude, choose Claude and the paired machine on `/onboarding`, label the |
| +account, then copy the setup ID into this terminal command: |
| + |
| +```sh |
| +EQUIPO_RUNNER_ROOT=/ABSOLUTE/INSTALL/ROOT EQUIPO_CLAUDE_MODEL=EXACT_CLAUDE_MODEL equipo-runner account login --setup CLAUDE_SETUP_ID |
| +``` |
| + |
| +For Codex, request a separate Codex setup and run: |
| + |
| +```sh |
| +EQUIPO_RUNNER_ROOT=/ABSOLUTE/INSTALL/ROOT EQUIPO_CODEX_MODEL=EXACT_CODEX_MODEL equipo-runner account login --setup CODEX_SETUP_ID |
| +``` |
| + |
| +Replace the uppercase placeholders before running. Each command allocates a |
| +fresh 0700 home. Claude receives `CLAUDE_CONFIG_DIR` and |
| +`CLAUDE_SECURESTORAGE_CONFIG_DIR`; Codex receives `CODEX_HOME`. These match the |
| +Plan 2b dedicated-home environment in `provider/policy.go` and `docs/live-gate.md`. |
| +`HOME` and the working directory also point at the new home. Provider API keys |
| +and interactive configuration are not inherited. |
| + |
| +Follow the official CLI's instructions on the terminal. For Codex, enter its |
| +device code in its official browser page. For headless Claude, open the official |
| +link on another device and enter any returned code only in the same runner |
| +terminal. Equipo passes stdin/stdout/stderr directly through and never receives |
| +that code as a form, argument, event or instance challenge. Confirm the provider's |
| +browser account yourself. Identity readback is trust on first use, not remote |
| +identity attestation. |
| + |
| +Check this evidence for each provider: |
| + |
| +1. The browser shows the matching setup ID and changes from pending to connected |
| + only after CLI exit 0, local identity readback, `OpenAccount` preflight and a |
| + saved account binding. Claude uses `auth status --json`; Codex uses app-server |
| + `account/read`, reusing the Plan 2b identity checks. Verify the observed account |
| + and model in the private bindings file. Do not publish the file or home path. |
| +2. Repeat with a second labeled account of the same provider. Homes and home IDs |
| + differ. Neither login replaces the first binding. The service later discovers |
| + both bindings; execution still needs ordinary certification and connection |
| + reports. Unknown allowance remains unknown. |
| +3. Cancel with Ctrl-C while the CLI waits. It receives SIGINT, exits, the setup is |
| + cancelled and its unsaved home is removed. Also test instance-side cancel, |
| + expiry, nonzero CLI exit, wrong setup ID and a failed identity readback. None |
| + may connect. A CLI that ignores SIGINT is killed after the two-second grace. |
| +4. Interrupt the connection after local Save. The command retries the same report |
| + three times without repeating identity-marker creation or Save. If still |
| + pending, rerun the same command before setup expiry: it verifies the saved |
| + binding and retries only the report. It must not start another CLI login. |
| + A crash before Save remains uncertain and requires a new setup. |
| +5. Confirm that any listener opened by the official CLI binds loopback and closes |
| + on success, cancellation and expiry. Equipo starts no callback listener. A |
| + non-loopback or surviving listener is a release blocker; record the observed |
| + pinned behavior rather than inventing a callback contract. |
| +6. Inspect sanitized instance requests/responses, forms, logs, runner journal and |
| + audit records. They must contain no credentials, return codes, device links or |
| + codes, provider polling IDs or credential-home paths. Retain only versions, |
| + setup state, verified account identity and the sanitized check outcomes. |
| + |
| +The production driver is covered by fake CLIs on PATH and pipe terminal fixtures; |
| +the existing pseudo-terminal tests remain. Real headless exchange, listener |
| +ownership and same-provider live refresh remain Paul's live-gate evidence. Copy |
| +still requires review before release. Stop the disposable gate processes and |
| +remove only scratch created for the exercise, retaining the chosen dedicated |
| +account homes and private evidence. |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 109215b2..af735be0 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -60,14 +60,28 @@ var pageCopy = map[string]string{ |
| "account_setup.dedicated": "Each account uses a new private home on your runner.", |
| // COPY REVIEW REQUIRED: account_setup.browser |
| "account_setup.browser": "Run this command on the paired machine. Open the official sign-in link there and paste the returned code only into that terminal.", |
| + // COPY REVIEW REQUIRED: account_setup.device |
| + "account_setup.device": "Run this command on the paired machine. Follow the official CLI instructions to enter its device code in your browser.", |
| + // COPY REVIEW REQUIRED: account_setup.config |
| + "account_setup.config": "Check the runner configuration and the selected provider model.", |
| + // COPY REVIEW REQUIRED: account_setup.network |
| + "account_setup.network": "The instance could not be reached. Try again.", |
| + // COPY REVIEW REQUIRED: account_setup.invalid |
| + "account_setup.invalid": "This setup ID is missing, expired, cancelled or belongs to another runner. Start a new setup.", |
| + // COPY REVIEW REQUIRED: account_setup.interrupted |
| + "account_setup.interrupted": "This sign-in was interrupted. Start a new setup.", |
| + // COPY REVIEW REQUIRED: account_setup.save_failed |
| + "account_setup.save_failed": "The account binding could not be saved. Check the runner configuration and start again.", |
| + // COPY REVIEW REQUIRED: account_setup.identity_failed |
| + "account_setup.identity_failed": "The signed-in account could not be verified. Start a new setup.", |
| // COPY REVIEW REQUIRED: account_setup.command |
| "account_setup.command": "equipo-runner account login --setup %s", |
| // COPY REVIEW REQUIRED: account_setup.cancel |
| "account_setup.cancel": "Cancel sign-in", |
| // COPY REVIEW REQUIRED: account_setup.pending |
| "account_setup.pending": "Waiting for sign-in on your runner.", |
| - // COPY REVIEW REQUIRED: account_setup.waiting_runner |
| - "account_setup.waiting_runner": "Waiting for the runner to report this account.", |
| + // COPY REVIEW REQUIRED: account_setup.waiting_report |
| + "account_setup.waiting_report": "Waiting for the runner to report this account.", |
| // COPY REVIEW REQUIRED: account_setup.connected |
| "account_setup.connected": "Account connected.", |
| // COPY REVIEW REQUIRED: account_setup.expired |
diff --git a/internal/equipo/setup/account_connection.go b/internal/equipo/setup/account_connection.go| index 1d95a953..51acf1ef 100644 |
| --- a/internal/equipo/setup/account_connection.go |
| +++ b/internal/equipo/setup/account_connection.go |
| @@ -9,7 +9,7 @@ import ( |
| func ConnectAccount(tx *gorm.DB, p runnerproto.RunnerPrincipal, a AccountSetup, q runnerproto.AccountSetupResult) (string, error) { |
| // Sign-in alone grants no model availability or containment certification. |
| - report := runnerproto.ConnectionReport{LocalID: a.ID, Provider: a.Provider, ProviderVersion: q.ProviderVersion, Family: map[string]string{"codex": "gpt", "claude": "claude"}[a.Provider], Model: "pending", AccountLabel: a.Label, Kind: "subscription", UnavailableReason: "account_setup.waiting_runner", Routing: runnerproto.ConnectionRouting{BindingID: a.ID, AccountID: q.AccountID}} |
| + report := runnerproto.ConnectionReport{LocalID: a.ID, Provider: a.Provider, ProviderVersion: q.ProviderVersion, Family: map[string]string{"codex": "gpt", "claude": "claude"}[a.Provider], Model: "pending", AccountLabel: a.Label, Kind: "subscription", UnavailableReason: "account_setup.waiting_report", Routing: runnerproto.ConnectionRouting{BindingID: a.ID, AccountID: q.AccountID}} |
| raw, err := json.Marshal([]runnerproto.ConnectionReport{report}) |
| if err != nil { |
| return "", err |
diff --git a/internal/equipo/setup/accounts.go b/internal/equipo/setup/accounts.go| index e5451ce4..c92181a2 100644 |
| --- a/internal/equipo/setup/accounts.go |
| +++ b/internal/equipo/setup/accounts.go |
| @@ -60,7 +60,7 @@ func (s *Store) account(a Actor, id string) (AccountSetupRecord, error) { |
| if err != nil { |
| return row, err |
| } |
| - if row.State == "pending" || row.State == "waiting_runner" { |
| + if row.State == "pending" { |
| if !s.deps.Now.Before(row.ExpiresAt) { |
| row.State = "expired" |
| row.Challenge = nil |
diff --git a/internal/equipo/templates/onboarding.html b/internal/equipo/templates/onboarding.html| index 181c4b0f..e2b57b04 100644 |
| --- a/internal/equipo/templates/onboarding.html |
| +++ b/internal/equipo/templates/onboarding.html |
| @@ -17,8 +17,8 @@ |
| <p>{{copy "onboarding.pair"}}</p><a href="/runners/enrol">{{copy "runner.title"}}</a> |
| <p>{{copy "onboarding.account_pending"}}</p> |
| {{end}} |
| -{{if eq .Onboarding.State.CurrentStep "specialists"}}<ul data-onboarding-specialists>{{range .Onboarding.Specialists}}<li><a href="/specialists/{{.Key}}">{{.Name}}</a>{{if .Required}} <span equipo-value>{{copy "specialists.required"}}</span>{{end}}</li>{{end}}</ul>{{end}} |
| -<a href="/templates">{{copy "onboarding.library"}}</a> |
| +{{if eq .Onboarding.State.CurrentStep "specialists"}}<ul data-onboarding-specialists>{{range .Onboarding.Specialists}}<li><a href="/specialists/{{.Key}}">{{.Name}}</a>{{if .Required}} <span equipo-value>{{copy "specialists.required"}}</span>{{end}}</li>{{end}}</ul> |
| +<a href="/templates">{{copy "onboarding.library"}}</a>{{end}} |
| {{if eq .Onboarding.State.CurrentStep "first_task"}}<p>{{copy "onboarding.safe_first_task"}}</p> |
| <form method="post" action="/onboarding/first-task" equipo-form><input type="hidden" name="request_id" value="{{.Onboarding.RequestID}}-task"> |
| <label>{{copy "plan.project"}}<select name="project_id" rst-select>{{range .Onboarding.Projects}}<option value="{{.ID}}">{{.Name}}</option>{{end}}</select></label> |
| @@ -33,13 +33,14 @@ |
| {{else}}<a href="/conversation">{{copy "conversation.title"}}</a>{{end}} |
| </section> |
| <section equipo-card><h2>{{copy "account_setup.title"}}</h2><p>{{copy "account_setup.dedicated"}}</p> |
| +{{range .Onboarding.Accounts}}{{if eq .State "unavailable"}}<p data-login-unavailable>{{.Label}} ({{.Provider}}): {{copy "account_setup.unavailable"}}</p>{{end}}{{end}} |
| {{if .Onboarding.Runners}}<form method="post" action="/onboarding/accounts" equipo-form> |
| <input type="hidden" name="request_id" value="{{.Onboarding.RequestID}}-account"> |
| <label>{{copy "account_setup.runner"}}<select name="runner_id" rst-select>{{range .Onboarding.Runners}}<option value="{{.ID}}">{{.Label}}</option>{{end}}</select></label> |
| <label>{{copy "onboarding.account"}}<select name="provider" rst-select><option value="codex">{{copy "onboarding.codex"}}</option><option value="claude">{{copy "onboarding.claude"}}</option></select></label> |
| <label>{{copy "account_setup.label"}}<input name="label" maxlength="80" required rst-input></label><button rst-btn type="submit">{{copy "account_setup.add"}}</button></form>{{end}} |
| {{$request:=.Onboarding.RequestID}}{{range .Onboarding.Accounts}}<section equipo-card><h3>{{.Label}}</h3><p>{{copy (printf "account_setup.%s" .State)}}</p><code>{{.ID}}</code> |
| -{{if eq .State "pending"}}<p>{{copy "account_setup.browser"}}</p><pre>{{printf (copy "account_setup.command") .ID}}</pre> |
| +{{if eq .State "pending"}}<p>{{if eq .Provider "claude"}}{{copy "account_setup.browser"}}{{else}}{{copy "account_setup.device"}}{{end}}</p><pre>{{printf (copy "account_setup.command") .ID}}</pre> |
| {{with .Challenge}}<a href="{{.VerificationURI}}" rel="noreferrer">{{.VerificationURI}}</a><code>{{.UserCode}}</code>{{end}} |
| <form method="post" action="/onboarding/accounts/cancel"><input type="hidden" name="id" value="{{.ID}}"><input type="hidden" name="revision" value="{{.Revision}}"><input type="hidden" name="request_id" value="{{$request}}-{{.ID}}"><button rst-btn type="submit">{{copy "account_setup.cancel"}}</button></form>{{end}}</section>{{end}}</section> |
| <section equipo-card><h2>{{copy "onboarding.hosted"}}</h2><p>{{copy "onboarding.later"}}</p></section> |
diff --git a/internal/plan3test/onboarding_accounts_test.go b/internal/plan3test/onboarding_accounts_test.go| index c6f7641b..0af786fe 100644 |
| --- a/internal/plan3test/onboarding_accounts_test.go |
| +++ b/internal/plan3test/onboarding_accounts_test.go |
| @@ -100,9 +100,6 @@ func TestOnboardingSafeFirstTask(t *testing.T) { |
| t.Fatal("change path in first task") |
| } |
| } |
| - TestPlanWorkflowRecommendation(t) |
| - TestPlanWorkflowRecommendationDelivery(t) |
| - TestPlanModelChoiceReviewFamily(t) |
| } |
| func TestOnboardingSpecialists(t *testing.T) { |
| @@ -129,8 +126,8 @@ func TestOnboardingSpecialists(t *testing.T) { |
| } |
| w := f.get(t, owner, "/onboarding") |
| expectHTTP(t, w, 200) |
| - if !strings.Contains(w.Body.String(), "/templates") { |
| - t.Fatal("onboarding library link missing") |
| + if strings.Contains(w.Body.String(), ">"+equipo.RunnerText("onboarding.library")+"</a>") { |
| + t.Fatal("library link outside specialists stage") |
| } |
| f.exec(t, `INSERT INTO onboarding_states(person,revision,completed) VALUES(?,1,'{"welcome":true,"account":true,"runner":true}')`, owner.Address) |
| w = f.get(t, owner, "/onboarding") |
| @@ -201,11 +198,11 @@ func TestOnboardingAccountRunnerGuards(t *testing.T) { |
| t.Fatal("unsafe device link accepted", e) |
| } |
| } |
| - q.Challenge = display |
| + q.Challenge = nil |
| s, e = f.Store.ReportAccountSetup(ctx, p, q) |
| must(t, e) |
| - if s.Challenge == nil { |
| - t.Fatal("safe device display dropped") |
| + if s.Challenge != nil { |
| + t.Fatal("terminal sign-in exposed display") |
| } |
| q = runnerproto.AccountSetupResult{ID: s.ID, Revision: s.Revision, State: "connected", AccountID: "observed-account", ProviderVersion: "0.165.0"} |
| f.exec(t, "CREATE TRIGGER setup_audit_failure BEFORE INSERT ON audit_events WHEN NEW.kind='account_setup.connected' BEGIN SELECT RAISE(ABORT,'fixture'); END") |
| @@ -281,3 +278,61 @@ func TestOnboardingAccountForms(t *testing.T) { |
| t.Fatal("secret audited") |
| } |
| } |
| + |
| +func TestOnboardingSafeFirstTaskHTTP(t *testing.T) { |
| + f := newFixture(t) |
| + task := f.createTask(t) |
| + values := url.Values{"project_id": {fmt.Sprint(task.ProjectID)}, "request_id": {"first-http"}} |
| + w := inviteRequest(t, f, owner, "POST", "/onboarding/first-task", values, nil) |
| + expectHTTP(t, w, 303) |
| + if !strings.HasPrefix(w.Header().Get("Location"), "/tasks/") { |
| + t.Fatal("missing first task redirect") |
| + } |
| + p, e := f.Store.TaskPlan(ctx, owner, strings.TrimPrefix(w.Header().Get("Location"), "/tasks/")) |
| + must(t, e) |
| + if p.Kind != "recommendation" || len(p.Steps) != 2 || p.Steps[0].Action != "recommend" || p.Steps[1].Action != "person" { |
| + t.Fatal("HTTP first task gained changes", p) |
| + } |
| + again := inviteRequest(t, f, owner, "POST", "/onboarding/first-task", values, nil) |
| + expectHTTP(t, again, 303) |
| + if again.Header().Get("Location") != w.Header().Get("Location") { |
| + t.Fatal("HTTP first task duplicated") |
| + } |
| + |
| + values.Set("instructions", "publish changes") |
| + expectHTTP(t, inviteRequest(t, f, owner, "POST", "/onboarding/first-task", values, nil), 422) |
| + values.Del("instructions") |
| + expectHTTP(t, inviteRequest(t, f, owner, "POST", "/onboarding/first-task", values, nil, "https://foreign.test"), 403) |
| +} |
| + |
| +func TestOnboardingAccountCancelHTTP(t *testing.T) { |
| + f := newFixture(t) |
| + accountRunner(t, f) |
| + s, e := f.Store.RequestAccountSetup(ctx, owner, "account-runner", "codex", "Personal", equipo.Mutation{RequestID: "cancel-http"}) |
| + must(t, e) |
| + values := url.Values{"id": {s.ID}, "revision": {fmt.Sprint(s.Revision)}, "request_id": {"cancel-post"}} |
| + expectHTTP(t, inviteRequest(t, f, owner, "POST", "/onboarding/accounts/cancel", values, nil, "https://foreign.test"), 403) |
| + expectHTTP(t, inviteRequest(t, f, owner, "POST", "/onboarding/accounts/cancel", values, nil), 303) |
| + s, e = f.Store.AccountSetup(ctx, owner, s.ID) |
| + must(t, e) |
| + if s.State != "cancelled" { |
| + t.Fatal("HTTP cancellation was not persisted") |
| + } |
| +} |
| + |
| +func TestOnboardingAccountInstructions(t *testing.T) { |
| + f := newFixture(t) |
| + accountRunner(t, f) |
| + s, e := f.Store.RequestAccountSetup(ctx, owner, "account-runner", "codex", "Personal", equipo.Mutation{RequestID: "instructions"}) |
| + must(t, e) |
| + body := f.get(t, owner, "/onboarding").Body.String() |
| + if !strings.Contains(body, equipo.RunnerText("account_setup.device")) || strings.Contains(body, equipo.RunnerText("account_setup.browser")) { |
| + t.Fatal("wrong provider instructions") |
| + } |
| + f.exec(t, "UPDATE account_setups SET state='unavailable' WHERE id=?", s.ID) |
| + body = f.get(t, owner, "/onboarding").Body.String() |
| + warning, form := strings.Index(body, "data-login-unavailable"), strings.Index(body, `action="/onboarding/accounts"`) |
| + if warning < 0 || warning > form || strings.Contains(body, "equipo-runner account login --setup "+s.ID) { |
| + t.Fatal("known unavailable login offered as pending") |
| + } |
| +} |
diff --git a/internal/runner/account_login.go b/internal/runner/account_login.go| index d47e1ec2..775ab02e 100644 |
| --- a/internal/runner/account_login.go |
| +++ b/internal/runner/account_login.go |
| @@ -25,17 +25,38 @@ func (c *HTTPInstance) ReportAccountSetup(ctx context.Context, q runnerproto.Acc |
| err = c.post(ctx, "account-setups", runnerproto.AccountSetupRequest{Version: 2, ID: q.ID, Result: &q}, token, &out) |
| return |
| } |
| -func LoginAccount(ctx context.Context, c Config, id string) error { |
| +func LoginAccount(ctx context.Context, c Config, id string, driver provider.LoginDriver) error { |
| if id == "" || len(id) > 128 { |
| return provider.ErrContract |
| } |
| cred, err := readCredentials(filepath.Join(c.StateDir, "credentials.json")) |
| if err != nil { |
| - return provider.ErrIdentity |
| + return provider.Error("account_setup.config") |
| } |
| instance := &HTTPInstance{origin: c.Origin + "/api/runner/v2", client: outboundClient(), bearer: cred.Bearer} |
| - login := runnersetup.AccountLogin{Root: filepath.Join(c.StateDir, "accounts"), RunnerID: cred.Bearer.RunnerID, Instance: instance, Driver: provider.NewLoginDriver()} |
| - // No terminal process or credential home is created while contracts are gated. |
| - _, err = login.Begin(ctx, id) |
| - return err |
| + setup, err := instance.AccountSetup(ctx, id) |
| + if err != nil { |
| + return err |
| + } |
| + if setup.ID != id || setup.RunnerID != cred.Bearer.RunnerID || setup.State != "pending" { |
| + return provider.Error("account_setup.invalid") |
| + } |
| + probe, ok := driver.(interface { |
| + Probe(context.Context, provider.Binding) (provider.Identity, error) |
| + }) |
| + if !ok { |
| + return provider.ErrLoginUnavailable |
| + } |
| + if handled, err := runnersetup.ResumeSavedAccount(ctx, c.AccountBindingsPath, cred.Bearer.Person, setup, instance, probe.Probe); handled || err != nil { |
| + return err |
| + } |
| + model := map[string]string{"claude": c.ClaudeModel, "codex": c.CodexModel}[setup.Provider] |
| + if model == "" { |
| + return provider.Error("account_setup.config") |
| + } |
| + login := runnersetup.AccountLogin{Root: filepath.Join(c.StateDir, "accounts"), RunnerID: cred.Bearer.RunnerID, Instance: instance, Driver: driver, Probe: probe.Probe, |
| + Save: func(ctx context.Context, s runnerproto.AccountSetup, b provider.Binding) error { |
| + return runnersetup.SaveAccountBinding(ctx, c.AccountBindingsPath, cred.Bearer.Person, model, s, b) |
| + }} |
| + return runnersetup.RunAccountLogin(ctx, &login, id) |
| } |
diff --git a/internal/runner/config.go b/internal/runner/config.go| index 2ee30917..cfb76022 100644 |
| --- a/internal/runner/config.go |
| +++ b/internal/runner/config.go |
| @@ -13,6 +13,7 @@ import ( |
| type Config struct { |
| MachineLabel string |
| + ClaudeModel, CodexModel string |
| ToolProxyPath, BwrapPath, ModuleCache string |
| ClaudePath, CodexCodeModeHostPath string |
| Report func(string) |
| @@ -23,7 +24,7 @@ type Config struct { |
| } |
| func LoadConfig(getenv func(string) string) (Config, error) { |
| - c := Config{MachineLabel: getenv("EQUIPO_MACHINE_LABEL"), ToolProxyPath: getenv("EQUIPO_TOOL_PROXY_PATH"), CodexCodeModeHostPath: getenv("EQUIPO_CODEX_CODE_MODE_HOST_PATH"), BwrapPath: getenv("EQUIPO_BWRAP_PATH"), ModuleCache: getenv("EQUIPO_GO_MODULE_CACHE"), ClaudePath: getenv("EQUIPO_CLAUDE_PATH"), Origin: getenv("EQUIPO_ORIGIN"), StateDir: getenv("EQUIPO_RUNNER_STATE_DIR"), AmadanCredentialPath: getenv("EQUIPO_AMADAN_CREDENTIAL_PATH"), AccountBindingsPath: getenv("EQUIPO_ACCOUNT_BINDINGS_PATH"), CodexPath: getenv("EQUIPO_CODEX_PATH"), GoRoot: getenv("EQUIPO_GO_ROOT"), GoBinary: getenv("EQUIPO_GO_BINARY"), WorkspaceRoot: getenv("EQUIPO_WORKSPACE_ROOT"), ScratchRoot: getenv("EQUIPO_SCRATCH_ROOT"), GitPath: getenv("EQUIPO_GIT_PATH"), AmadanPath: getenv("EQUIPO_AMADAN_PATH"), InstanceID: getenv("EQUIPO_INSTANCE_ID")} |
| + c := Config{ClaudeModel: getenv("EQUIPO_CLAUDE_MODEL"), CodexModel: getenv("EQUIPO_CODEX_MODEL"), MachineLabel: getenv("EQUIPO_MACHINE_LABEL"), ToolProxyPath: getenv("EQUIPO_TOOL_PROXY_PATH"), CodexCodeModeHostPath: getenv("EQUIPO_CODEX_CODE_MODE_HOST_PATH"), BwrapPath: getenv("EQUIPO_BWRAP_PATH"), ModuleCache: getenv("EQUIPO_GO_MODULE_CACHE"), ClaudePath: getenv("EQUIPO_CLAUDE_PATH"), Origin: getenv("EQUIPO_ORIGIN"), StateDir: getenv("EQUIPO_RUNNER_STATE_DIR"), AmadanCredentialPath: getenv("EQUIPO_AMADAN_CREDENTIAL_PATH"), AccountBindingsPath: getenv("EQUIPO_ACCOUNT_BINDINGS_PATH"), CodexPath: getenv("EQUIPO_CODEX_PATH"), GoRoot: getenv("EQUIPO_GO_ROOT"), GoBinary: getenv("EQUIPO_GO_BINARY"), WorkspaceRoot: getenv("EQUIPO_WORKSPACE_ROOT"), ScratchRoot: getenv("EQUIPO_SCRATCH_ROOT"), GitPath: getenv("EQUIPO_GIT_PATH"), AmadanPath: getenv("EQUIPO_AMADAN_PATH"), InstanceID: getenv("EQUIPO_INSTANCE_ID")} |
| var err error |
| c.Executable, err = os.Executable() |
| if err != nil { |
diff --git a/internal/runner/http.go b/internal/runner/http.go| index 1aa91e71..3ea7e4e8 100644 |
| --- a/internal/runner/http.go |
| +++ b/internal/runner/http.go |
| @@ -49,7 +49,7 @@ func (c *HTTPInstance) post(ctx context.Context, op string, body any, token stri |
| } |
| defer response.Body.Close() |
| if response.StatusCode != http.StatusOK { |
| - if response.StatusCode == 403 || response.StatusCode == 401 || response.StatusCode == 409 || response.StatusCode == 422 || strings.HasPrefix(op, "coordinator/") && response.StatusCode >= 400 && response.StatusCode < 500 { |
| + if response.StatusCode == 403 || response.StatusCode == 401 || response.StatusCode == 409 || response.StatusCode == 422 || (strings.HasPrefix(op, "coordinator/") || op == "account-setups") && response.StatusCode >= 400 && response.StatusCode < 500 { |
| var body runnerproto.ErrorResponse |
| _ = runnerproto.DecodeLimit(io.LimitReader(response.Body, 4096), &body, 4096) |
| return &RefusalError{Reason: refusalReason(body.Error), Status: response.StatusCode, Claim: op == "claim"} |
diff --git a/internal/runner/provider/claude/launcher.go b/internal/runner/provider/claude/launcher.go| index 8c4dbcb6..ab71e3a3 100644 |
| --- a/internal/runner/provider/claude/launcher.go |
| +++ b/internal/runner/provider/claude/launcher.go |
| @@ -340,16 +340,7 @@ func (l *Launcher) probeIdentity(ctx context.Context, b provider.Binding, in pro |
| if len(frames) != 1 { |
| return provider.Identity{}, provider.ErrIdentity |
| } |
| - var status struct { |
| - LoggedIn bool `json:"loggedIn"` |
| - Method string `json:"authMethod"` |
| - Email string `json:"email"` |
| - } |
| - if !uniqueJSON(frames[0]) || json.Unmarshal(frames[0], &status) != nil || !status.LoggedIn || status.Method != "claude.ai" || status.Email == "" { |
| - return provider.Identity{}, provider.ErrIdentity |
| - } |
| - // HomeID belongs to Equipo and is deliberately absent from CLI observations. |
| - return provider.Identity{AccountID: status.Email, ProviderVersion: Version}, nil |
| + return provider.ClaudeLoginIdentity(frames[0]) |
| } |
| func (l *Launcher) probe(ctx context.Context, b provider.Binding, in provider.PolicyInputs, args []string) ([][]byte, error) { |
| ctx, cancel := context.WithTimeout(ctx, 10*time.Second) |
diff --git a/internal/runner/provider/codex/launcher.go b/internal/runner/provider/codex/launcher.go| index e9042cdc..0d949461 100644 |
| --- a/internal/runner/provider/codex/launcher.go |
| +++ b/internal/runner/provider/codex/launcher.go |
| @@ -320,12 +320,7 @@ func readIdentity(ctx context.Context, r *RPC) (provider.Identity, error) { |
| if e != nil { |
| return provider.Identity{}, e |
| } |
| - var v struct{ Account *struct{ Type, Email string } } |
| - if json.Unmarshal(raw, &v) != nil || v.Account == nil || v.Account.Type != "chatgpt" || v.Account.Email == "" { |
| - return provider.Identity{}, provider.ErrIdentity |
| - } |
| - // HomeID is assigned by Equipo. The provider never observes it. |
| - return provider.Identity{AccountID: v.Account.Email, ProviderVersion: Version}, nil |
| + return provider.CodexLoginIdentity(raw) |
| } |
| func readConfig(ctx context.Context, r *RPC, p provider.Policy) error { |
| raw, e := r.Call(ctx, "config/read", json.RawMessage(`{"cwd":"/workspace","includeLayers":true}`)) |
diff --git a/internal/runner/provider/login.go b/internal/runner/provider/login.go| index d6475642..2dd8c969 100644 |
| --- a/internal/runner/provider/login.go |
| +++ b/internal/runner/provider/login.go |
| @@ -22,21 +22,6 @@ type LoginResult struct { |
| const ErrLoginUnavailable Error = "account_setup.unavailable" |
| -// The recorded Plan 2b material establishes ordinary login commands only. It |
| -// does not establish device output, headless exchange or callback ownership. |
| -// Keep production disabled until those contracts have recorded evidence. |
| -type unavailableLogin struct{} |
| - |
| -func NewLoginDriver() LoginDriver { return unavailableLogin{} } |
| -func (unavailableLogin) Supported(string) bool { return false } |
| -func (unavailableLogin) Begin(context.Context, string, string) (LoginChallenge, error) { |
| - return LoginChallenge{}, ErrLoginUnavailable |
| -} |
| -func (unavailableLogin) Poll(context.Context, string) (LoginResult, error) { |
| - return LoginResult{State: "unavailable"}, ErrLoginUnavailable |
| -} |
| -func (unavailableLogin) Cancel(context.Context, string) error { return nil } |
| - |
| // NewLoginHome allocates an empty private home. Existing accounts are never |
| // adopted, refreshed or overwritten by the new-account path. |
| func NewLoginHome(root string) (string, error) { |
diff --git a/internal/runner/provider/login_probe.go b/internal/runner/provider/login_probe.go| new file mode 100644 |
| index 00000000..56ae2ae0 |
| --- /dev/null |
| +++ b/internal/runner/provider/login_probe.go |
| @@ -0,0 +1,122 @@ |
| +package provider |
| + |
| +import ( |
| + "bufio" |
| + "bytes" |
| + "context" |
| + "encoding/json" |
| + "io" |
| + "os/exec" |
| + "strings" |
| + "time" |
| +) |
| + |
| +type limitedLoginOutput struct{ bytes.Buffer } |
| + |
| +func (b *limitedLoginOutput) Write(p []byte) (int, error) { |
| + if b.Len()+len(p) > 65536 { |
| + return 0, ErrIdentity |
| + } |
| + return b.Buffer.Write(p) |
| +} |
| + |
| +// Probe uses the Plan 2b identity readback contracts, never login output. |
| +// The same function is used again on the OpenAccount lease's staged home. |
| +func (d *terminalLoginDriver) Probe(ctx context.Context, b Binding) (Identity, error) { |
| + if ctx.Err() != nil { |
| + return Identity{}, ctx.Err() |
| + } |
| + if !d.Supported(b.Provider) { |
| + return Identity{}, ErrLoginUnavailable |
| + } |
| + ctx, cancel := context.WithTimeout(ctx, 10*time.Second) |
| + defer cancel() |
| + if b.Provider == "claude" { |
| + cmd := exec.CommandContext(ctx, d.binary(b.Provider), "auth", "status", "--json") |
| + cmd.Env = LoginEnvironment(b.Provider, b.Home) |
| + cmd.Dir = b.Home |
| + out := &limitedLoginOutput{} |
| + cmd.Stdout = out |
| + if cmd.Run() != nil { |
| + return Identity{}, ErrIdentity |
| + } |
| + return ClaudeLoginIdentity(out.Bytes()) |
| + } |
| + if b.Provider != "codex" { |
| + return Identity{}, ErrIdentity |
| + } |
| + cmd := exec.CommandContext(ctx, d.binary(b.Provider), "app-server", "--strict-config", "--listen", "stdio://") |
| + cmd.Env = LoginEnvironment(b.Provider, b.Home) |
| + cmd.Dir = b.Home |
| + in, err := cmd.StdinPipe() |
| + if err != nil { |
| + return Identity{}, ErrIdentity |
| + } |
| + defer in.Close() |
| + out, err := cmd.StdoutPipe() |
| + if err != nil { |
| + return Identity{}, ErrIdentity |
| + } |
| + if err = cmd.Start(); err != nil { |
| + return Identity{}, ErrIdentity |
| + } |
| + stopPipes := context.AfterFunc(ctx, func() { _ = in.Close(); _ = out.Close() }) |
| + defer stopPipes() |
| + defer func() { cancel(); _ = cmd.Wait() }() |
| + scan := bufio.NewScanner(out) |
| + scan.Buffer(make([]byte, 4096), 65536) |
| + 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 |
| + } |
| + if !scan.Scan() { |
| + return nil, ErrIdentity |
| + } |
| + raw, err := canonical(scan.Bytes()) |
| + if err != nil { |
| + return nil, ErrIdentity |
| + } |
| + var r struct { |
| + ID string |
| + Result json.RawMessage |
| + Error json.RawMessage |
| + } |
| + if json.Unmarshal(raw, &r) != nil || r.ID != id || len(r.Error) != 0 { |
| + return nil, ErrIdentity |
| + } |
| + return r.Result, nil |
| + } |
| + raw, err := call("1", "initialize", map[string]any{"clientInfo": map[string]string{"name": "equipo", "version": "2"}, "capabilities": map[string]bool{"experimentalApi": true}}) |
| + var init struct{ UserAgent, CodexHome string } |
| + if err != nil || json.Unmarshal(raw, &init) != nil || !strings.HasPrefix(init.UserAgent, "equipo/"+LoginVersion("codex")+" ") || init.CodexHome != b.Home { |
| + return Identity{}, ErrIdentity |
| + } |
| + if _, err = io.WriteString(in, "{\"method\":\"initialized\",\"params\":{}}\n"); err != nil { |
| + return Identity{}, ErrIdentity |
| + } |
| + raw, err = call("2", "account/read", map[string]bool{"refreshToken": false}) |
| + if err != nil { |
| + return Identity{}, err |
| + } |
| + return CodexLoginIdentity(raw) |
| +} |
| + |
| +func ClaudeLoginIdentity(raw []byte) (Identity, error) { |
| + raw, err := canonical(raw) |
| + var status struct { |
| + LoggedIn bool |
| + AuthMethod, Email string |
| + } |
| + if err != nil || json.Unmarshal(raw, &status) != nil || !status.LoggedIn || status.AuthMethod != "claude.ai" || status.Email == "" { |
| + return Identity{}, ErrIdentity |
| + } |
| + return Identity{AccountID: status.Email, ProviderVersion: LoginVersion("claude")}, nil |
| +} |
| +func CodexLoginIdentity(raw []byte) (Identity, error) { |
| + raw, err := canonical(raw) |
| + var v struct{ Account *struct{ Type, Email string } } |
| + if err != nil || json.Unmarshal(raw, &v) != nil || v.Account == nil || v.Account.Type != "chatgpt" || v.Account.Email == "" { |
| + return Identity{}, ErrIdentity |
| + } |
| + return Identity{AccountID: v.Account.Email, ProviderVersion: LoginVersion("codex")}, nil |
| +} |
diff --git a/internal/runner/provider/login_terminal.go b/internal/runner/provider/login_terminal.go| new file mode 100644 |
| index 00000000..3a6da5fe |
| --- /dev/null |
| +++ b/internal/runner/provider/login_terminal.go |
| @@ -0,0 +1,177 @@ |
| +package provider |
| + |
| +import ( |
| + "context" |
| + "crypto/rand" |
| + "io" |
| + "os" |
| + "os/exec" |
| + "strings" |
| + "time" |
| +) |
| + |
| +// LoginOptions is supplied by the terminal command, never by the runner service. |
| +// Paths are explicit so a test or an installation cannot fall back to another CLI. |
| +type LoginOptions struct { |
| + ClaudePath, CodexPath string |
| + Input io.Reader |
| + Output, ErrorOutput io.Writer |
| +} |
| + |
| +type terminalLoginDriver struct { |
| + options LoginOptions |
| + cmd *exec.Cmd |
| + done chan error |
| + cancel context.CancelFunc |
| + challenge LoginChallenge |
| + name, home string |
| + result *LoginResult |
| +} |
| + |
| +func NewLoginDriver(options ...LoginOptions) LoginDriver { |
| + d := &terminalLoginDriver{} |
| + if len(options) == 1 { |
| + d.options = options[0] |
| + } |
| + return d |
| +} |
| + |
| +func LoginVersion(name string) string { |
| + return map[string]string{"claude": "2.1.312", "codex": "0.165.0"}[name] |
| +} |
| +func (d *terminalLoginDriver) binary(name string) string { |
| + if name == "claude" { |
| + return d.options.ClaudePath |
| + } |
| + if name == "codex" { |
| + return d.options.CodexPath |
| + } |
| + return "" |
| +} |
| + |
| +// 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")} |
| + if name == "codex" { |
| + return append(env, "CODEX_HOME="+home) |
| + } |
| + return append(env, "CLAUDE_CONFIG_DIR="+home, "CLAUDE_SECURESTORAGE_CONFIG_DIR="+home, "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1", "DISABLE_AUTOUPDATER=1") |
| +} |
| +func loginArgs(name string) []string { |
| + // Claude argv is recorded in docs/live-gate.md:75. Codex device auth is |
| + // mandated by the Task 17 fix-round controller ruling. |
| + if name == "claude" { |
| + return []string{"auth", "login"} |
| + } |
| + return []string{"login", "--device-auth"} |
| +} |
| +func (d *terminalLoginDriver) Supported(name string) bool { |
| + if d.binary(name) == "" || LoginVersion(name) == "" { |
| + return false |
| + } |
| + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| + defer cancel() |
| + // Probe in disposable empty config, never the person's interactive home. |
| + home, err := os.MkdirTemp(os.Getenv("TMPDIR"), "equipo-login-probe-") |
| + if err != nil { |
| + return false |
| + } |
| + defer os.RemoveAll(home) |
| + cmd := exec.CommandContext(ctx, d.binary(name), "--version") |
| + cmd.Env = LoginEnvironment(name, home) |
| + cmd.Dir = home |
| + out := &limitedLoginOutput{} |
| + cmd.Stdout = out |
| + if cmd.Run() != nil { |
| + return false |
| + } |
| + version := strings.TrimSpace(out.String()) |
| + if name == "claude" && version != LoginVersion(name)+" (Claude Code)" { |
| + return false |
| + } |
| + if name == "codex" && version != "codex-cli "+LoginVersion(name) && version != LoginVersion(name) { |
| + return false |
| + } |
| + args := append(loginArgs(name), "--help") |
| + cmd = exec.CommandContext(ctx, d.binary(name), args...) |
| + cmd.Env = LoginEnvironment(name, home) |
| + cmd.Dir = home |
| + return cmd.Run() == nil |
| +} |
| +func (d *terminalLoginDriver) Begin(ctx context.Context, name, home string) (LoginChallenge, error) { |
| + if d.cmd != nil { |
| + return LoginChallenge{}, ErrAccountBusy |
| + } |
| + if !d.Supported(name) || d.options.Input == nil || d.options.Output == nil || d.options.ErrorOutput == nil { |
| + return LoginChallenge{}, ErrLoginUnavailable |
| + } |
| + if DefaultHomeRules().RefusesPath(home) { |
| + return LoginChallenge{}, ErrPolicy |
| + } |
| + dir, err := pinDirectory(home) |
| + if err != nil { |
| + return LoginChallenge{}, err |
| + } |
| + if !privateDirectory(dir) { |
| + dir.Close() |
| + return LoginChallenge{}, ErrPolicy |
| + } |
| + dir.Close() |
| + child, cancel := context.WithCancel(ctx) |
| + cmd := exec.CommandContext(child, d.binary(name), loginArgs(name)...) |
| + cmd.Env = LoginEnvironment(name, home) |
| + cmd.Dir = home |
| + cmd.Stdin, cmd.Stdout, cmd.Stderr = d.options.Input, d.options.Output, d.options.ErrorOutput |
| + // Forward interrupt and allow the official CLI to close its browser listener. |
| + cmd.Cancel = func() error { return cmd.Process.Signal(os.Interrupt) } |
| + cmd.WaitDelay = 2 * time.Second |
| + if err := cmd.Start(); err != nil { |
| + cancel() |
| + return LoginChallenge{}, ErrLoginUnavailable |
| + } |
| + d.cmd, d.cancel, d.name, d.home = cmd, cancel, name, home |
| + d.challenge = LoginChallenge{ID: rand.Text(), Mode: map[string]string{"claude": "browser", "codex": "device"}[name], ExpiresAt: time.Now().Add(10 * time.Minute)} |
| + d.done = make(chan error, 1) |
| + go func() { d.done <- cmd.Wait(); close(d.done) }() |
| + return d.challenge, nil |
| +} |
| +func (d *terminalLoginDriver) Poll(ctx context.Context, id string) (LoginResult, error) { |
| + if d.cmd == nil || id != d.challenge.ID { |
| + return LoginResult{}, ErrIdentity |
| + } |
| + if d.result != nil { |
| + return *d.result, nil |
| + } |
| + select { |
| + case err := <-d.done: |
| + d.cancel() |
| + r := LoginResult{State: "denied"} |
| + if err == nil { |
| + identity, e := d.Probe(ctx, Binding{Provider: d.name, Home: d.home}) |
| + if e == nil { |
| + identity.HomeID = rand.Text() |
| + r = LoginResult{State: "connected", Identity: identity} |
| + } else { |
| + r.State = "unavailable" |
| + d.result = &r |
| + return r, ErrIdentity |
| + } |
| + } |
| + d.result = &r |
| + return r, nil |
| + default: |
| + return LoginResult{State: "pending"}, nil |
| + } |
| +} |
| +func (d *terminalLoginDriver) Cancel(_ context.Context, id string) error { |
| + if d.cmd == nil || id != d.challenge.ID { |
| + return ErrIdentity |
| + } |
| + d.cancel() |
| + <-d.done |
| + if d.result == nil { |
| + d.result = &LoginResult{State: "cancelled"} |
| + } |
| + return nil |
| +} |
diff --git a/internal/runner/provider/login_test.go b/internal/runner/provider/login_test.go| new file mode 100644 |
| index 00000000..dfc95eb0 |
| --- /dev/null |
| +++ b/internal/runner/provider/login_test.go |
| @@ -0,0 +1,159 @@ |
| +package provider |
| + |
| +import ( |
| + "context" |
| + "io" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +func TestOnboardingOfficialLogin(t *testing.T) { |
| + for _, name := range []string{"claude", "codex"} { |
| + t.Run(name, func(t *testing.T) { |
| + root := t.TempDir() |
| + binary := filepath.Join(root, name) |
| + script := `#!/bin/sh |
| +set -eu |
| +umask 077 |
| +case "$1" in |
| + --version) echo 'VERSION'; exit 0 ;; |
| +esac |
| +case "$*" in |
| + 'auth login --help'|'login --device-auth --help') exit 0 ;; |
| + 'auth status --json') printf '%s' '{"loggedIn":true,"authMethod":"claude.ai","email":"person@example.test"}'; exit 0 ;; |
| + 'app-server --strict-config --listen stdio://') |
| + IFS= read -r line |
| + printf '{"id":"1","result":{"userAgent":"equipo/0.165.0 fixture","codexHome":"%s"}}\n' "$CODEX_HOME" |
| + IFS= read -r line |
| + IFS= read -r line |
| + printf '%s\n' '{"id":"2","result":{"account":{"type":"chatgpt","email":"person@example.test"}}}' |
| + exit 0 ;; |
| + 'auth login') test "$HOME" = "$CLAUDE_CONFIG_DIR"; test "$HOME" = "$CLAUDE_SECURESTORAGE_CONFIG_DIR"; file=.credentials.json ;; |
| + 'login --device-auth') test "$HOME" = "$CODEX_HOME"; file=auth.json ;; |
| + *) exit 9 ;; |
| +esac |
| +IFS= read -r code |
| +test "$code" = RETURN-SECRET |
| +printf '%s' '{"token":"CREDENTIAL-SECRET"}' > "$HOME/$file" |
| +` |
| + version := "0.165.0" |
| + if name == "claude" { |
| + version = "2.1.312 (Claude Code)" |
| + } |
| + script = strings.ReplaceAll(script, "VERSION", version) |
| + if err := os.WriteFile(binary, []byte(script), 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Setenv("PATH", root) |
| + d := NewLoginDriver(LoginOptions{ClaudePath: "claude", CodexPath: "codex", Input: strings.NewReader("RETURN-SECRET\n"), Output: io.Discard, ErrorOutput: io.Discard}) |
| + if !d.(interface{ Supported(string) bool }).Supported(name) { |
| + t.Fatal("supported pinned CLI rejected") |
| + } |
| + home, err := NewLoginHome(filepath.Join(root, "accounts")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + c, err := d.Begin(context.Background(), name, home) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer d.Cancel(context.Background(), c.ID) |
| + if c.VerificationURI != "" || c.UserCode != "" { |
| + t.Fatal("terminal display was parsed") |
| + } |
| + deadline := time.Now().Add(3 * time.Second) |
| + for time.Now().Before(deadline) { |
| + r, err := d.Poll(context.Background(), c.ID) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if r.State == "pending" { |
| + time.Sleep(time.Millisecond) |
| + continue |
| + } |
| + if r.State != "connected" || r.Identity.AccountID != "person@example.test" || r.Identity.HomeID == "" { |
| + t.Fatal("login missing verified identity", r) |
| + } |
| + return |
| + } |
| + t.Fatal("login did not finish") |
| + }) |
| + } |
| +} |
| + |
| +func TestOnboardingOfficialLoginCapability(t *testing.T) { |
| + for _, mode := range []string{"wrong-version", "missing-subcommand"} { |
| + t.Run(mode, func(t *testing.T) { |
| + root := t.TempDir() |
| + binary := filepath.Join(root, "codex") |
| + script := "#!/bin/sh\nif [ \"$1\" = --version ]; then echo codex-cli 0.165.0; exit 0; fi\nexit 2\n" |
| + if mode == "wrong-version" { |
| + script = strings.ReplaceAll(script, "0.165.0", "0.1.0") |
| + script = strings.ReplaceAll(script, "exit 2\n", "exit 0\n") |
| + } |
| + if e := os.WriteFile(binary, []byte(script), 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + d := NewLoginDriver(LoginOptions{CodexPath: binary, Input: strings.NewReader(""), Output: io.Discard, ErrorOutput: io.Discard}) |
| + if d.(interface{ Supported(string) bool }).Supported("codex") { |
| + t.Fatal("unsupported CLI accepted") |
| + } |
| + if _, e := d.Begin(context.Background(), "codex", filepath.Join(root, "absent")); e != ErrLoginUnavailable { |
| + t.Fatal("unsupported login began", e) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestOnboardingOfficialLoginInterrupt(t *testing.T) { |
| + root := t.TempDir() |
| + binary := filepath.Join(root, "claude") |
| + script := `#!/bin/sh |
| +set -eu |
| +case "$*" in |
| + '--version') echo '2.1.312 (Claude Code)'; exit 0 ;; |
| + 'auth login --help') exit 0 ;; |
| + 'auth login') |
| + trap 'echo interrupted > "$HOME/interrupted"; exit 130' INT |
| + echo ready > "$HOME/ready" |
| + while :; do :; done ;; |
| + *) exit 2 ;; |
| +esac |
| +` |
| + if e := os.WriteFile(binary, []byte(script), 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + home, e := NewLoginHome(filepath.Join(root, "accounts")) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + d := NewLoginDriver(LoginOptions{ClaudePath: binary, Input: strings.NewReader(""), Output: io.Discard, ErrorOutput: io.Discard}) |
| + c, e := d.Begin(context.Background(), "claude", home) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + defer d.Cancel(context.Background(), c.ID) |
| + deadline := time.Now().Add(time.Second) |
| + for { |
| + if _, e := os.Stat(filepath.Join(home, "ready")); e == nil { |
| + break |
| + } |
| + if time.Now().After(deadline) { |
| + t.Fatal("CLI not ready") |
| + } |
| + time.Sleep(time.Millisecond) |
| + } |
| + if e := d.Cancel(context.Background(), c.ID); e != nil { |
| + t.Fatal(e) |
| + } |
| + if _, e := os.Stat(filepath.Join(home, "interrupted")); e != nil { |
| + t.Fatal("SIGINT did not reach CLI", e) |
| + } |
| + r, e := d.Poll(context.Background(), c.ID) |
| + if e != nil || r.State != "cancelled" { |
| + t.Fatal("interrupt connected account", r, e) |
| + } |
| +} |
diff --git a/internal/runner/setup/account_command.go b/internal/runner/setup/account_command.go| new file mode 100644 |
| index 00000000..54dbae3a |
| --- /dev/null |
| +++ b/internal/runner/setup/account_command.go |
| @@ -0,0 +1,53 @@ |
| +package runnersetup |
| + |
| +import ( |
| + "context" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| +) |
| + |
| +// RunAccountLogin belongs to the interactive subcommand only. |
| +func RunAccountLogin(ctx context.Context, l *AccountLogin, id string) error { |
| + if _, err := l.Begin(ctx, id); err != nil { |
| + return err |
| + } |
| + defer func() { |
| + if l.active != nil && !l.Saved() { |
| + cleanup, stop := context.WithTimeout(context.Background(), 5*time.Second) |
| + defer stop() |
| + _ = l.Cancel(cleanup) |
| + } |
| + }() |
| + ticker := time.NewTicker(100 * time.Millisecond) |
| + defer ticker.Stop() |
| + retries := 0 |
| + for { |
| + select { |
| + case <-ctx.Done(): |
| + return context.Canceled |
| + case <-ticker.C: |
| + out, err := l.Poll(ctx) |
| + if err != nil { |
| + if l.Saved() && retries < 3 { |
| + retries++ |
| + continue |
| + } |
| + return err |
| + } |
| + switch out.State { |
| + case "pending": |
| + case "connected": |
| + return nil |
| + case "expired": |
| + return provider.Error("account_setup.expired") |
| + case "cancelled": |
| + return context.Canceled |
| + case "denied": |
| + return provider.Error("account_setup.denied") |
| + default: |
| + return provider.ErrLoginUnavailable |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/runner/setup/account_login.go b/internal/runner/setup/account_login.go| index 4149db48..6b2add32 100644 |
| --- a/internal/runner/setup/account_login.go |
| +++ b/internal/runner/setup/account_login.go |
| @@ -21,6 +21,8 @@ type accountLogin struct { |
| setup runnerproto.AccountSetup |
| challenge provider.LoginChallenge |
| home string |
| + marker string |
| + saved *runnerproto.AccountSetupResult |
| } |
| type AccountLogin struct { |
| Root, RunnerID string |
| @@ -36,8 +38,11 @@ func (l *AccountLogin) Begin(ctx context.Context, id string) (provider.LoginChal |
| return provider.LoginChallenge{}, provider.ErrAccountBusy |
| } |
| s, err := l.Instance.AccountSetup(ctx, id) |
| - if err != nil || s.ID != id || s.RunnerID != l.RunnerID || s.State != "pending" || s.Revision < 1 { |
| - return provider.LoginChallenge{}, provider.ErrIdentity |
| + if err != nil { |
| + return provider.LoginChallenge{}, err |
| + } |
| + if s.ID != id || s.RunnerID != l.RunnerID || s.State != "pending" || s.Revision < 1 { |
| + return provider.LoginChallenge{}, provider.Error("account_setup.invalid") |
| } |
| if capability, ok := l.Driver.(interface{ Supported(string) bool }); ok && !capability.Supported(s.Provider) { |
| _, err = l.Instance.ReportAccountSetup(ctx, runnerproto.AccountSetupResult{ID: s.ID, Revision: s.Revision, State: "unavailable"}) |
| @@ -59,6 +64,13 @@ func (l *AccountLogin) Begin(ctx context.Context, id string) (provider.LoginChal |
| os.Remove(home) |
| return provider.LoginChallenge{}, provider.ErrUncertain |
| } |
| + keep := false |
| + defer func() { |
| + if !keep { |
| + _ = os.RemoveAll(home) |
| + _ = os.Remove(marker) |
| + } |
| + }() |
| raw, _ := json.Marshal(struct{ ID, Home string }{id, home}) |
| _, err = f.Write(raw) |
| if err == nil { |
| @@ -70,31 +82,40 @@ func (l *AccountLogin) Begin(ctx context.Context, id string) (provider.LoginChal |
| } |
| c, err := l.Driver.Begin(ctx, s.Provider, home) |
| if err != nil { |
| - _, _ = l.Instance.ReportAccountSetup(ctx, runnerproto.AccountSetupResult{ID: s.ID, Revision: s.Revision, State: "unavailable"}) |
| + state := "unavailable" |
| + reportCtx := ctx |
| + if ctx.Err() != nil { |
| + state = "cancelled" |
| + var stop context.CancelFunc |
| + reportCtx, stop = context.WithTimeout(context.Background(), 5*time.Second) |
| + defer stop() |
| + } |
| + _, _ = l.Instance.ReportAccountSetup(reportCtx, runnerproto.AccountSetupResult{ID: s.ID, Revision: s.Revision, State: state}) |
| + if ctx.Err() != nil { |
| + return provider.LoginChallenge{}, ctx.Err() |
| + } |
| return provider.LoginChallenge{}, provider.ErrLoginUnavailable |
| } |
| - l.active = &accountLogin{setup: s, challenge: c, home: home} |
| + l.active = &accountLogin{setup: s, challenge: c, home: home, marker: marker} |
| if c.ID == "" || !time.Now().Before(c.ExpiresAt) || c.Mode != s.Mode { |
| _ = l.Driver.Cancel(ctx, c.ID) |
| l.active = nil |
| return provider.LoginChallenge{}, provider.ErrContract |
| } |
| - var display *runnerproto.LoginDisplay |
| - if c.Mode == "device" { |
| - display = &runnerproto.LoginDisplay{VerificationURI: c.VerificationURI, UserCode: c.UserCode, ExpiresAt: c.ExpiresAt} |
| - } |
| - if !runnerproto.ValidLoginDisplay(s.Provider, s.Mode, display, time.Now()) { |
| - _ = l.Driver.Cancel(ctx, c.ID) |
| - l.active = nil |
| - return provider.LoginChallenge{}, provider.ErrContract |
| - } |
| - s, err = l.Instance.ReportAccountSetup(ctx, runnerproto.AccountSetupResult{ID: s.ID, Revision: s.Revision, State: "pending", Challenge: display}) |
| + s, err = l.Instance.ReportAccountSetup(ctx, runnerproto.AccountSetupResult{ID: s.ID, Revision: s.Revision, State: "pending"}) |
| if err != nil { |
| + if ctx.Err() != nil { |
| + cleanup, stop := context.WithTimeout(context.Background(), 5*time.Second) |
| + defer stop() |
| + _ = l.Cancel(cleanup) |
| + return provider.LoginChallenge{}, ctx.Err() |
| + } |
| _ = l.Driver.Cancel(ctx, c.ID) |
| l.active = nil |
| return provider.LoginChallenge{}, err |
| } |
| l.active.setup = s |
| + keep = true |
| return c, nil |
| } |
| func (l *AccountLogin) current(ctx context.Context) error { |
| @@ -102,14 +123,25 @@ func (l *AccountLogin) current(ctx context.Context) error { |
| return provider.ErrUncertain |
| } |
| s, e := l.Instance.AccountSetup(ctx, l.active.setup.ID) |
| - if e != nil || s.State != "pending" || s.RunnerID != l.RunnerID || s.Revision != l.active.setup.Revision { |
| + if e != nil { |
| _ = l.Driver.Cancel(ctx, l.active.challenge.ID) |
| - return provider.ErrIdentity |
| + return e |
| + } |
| + if s.State != "pending" || s.RunnerID != l.RunnerID || s.Revision != l.active.setup.Revision { |
| + _ = l.Driver.Cancel(ctx, l.active.challenge.ID) |
| + return provider.Error("account_setup.invalid") |
| } |
| return nil |
| } |
| func (l *AccountLogin) Poll(ctx context.Context) (runnerproto.AccountSetup, error) { |
| + if l.active != nil && l.active.saved != nil { |
| + return l.reportSaved(ctx) |
| + } |
| if err := l.current(ctx); err != nil { |
| + if l.interrupted(ctx) { |
| + return runnerproto.AccountSetup{}, ctx.Err() |
| + } |
| + l.cleanup() |
| return runnerproto.AccountSetup{}, err |
| } |
| a := l.active |
| @@ -121,7 +153,13 @@ func (l *AccountLogin) Poll(ctx context.Context) (runnerproto.AccountSetup, erro |
| _ = l.Driver.Cancel(ctx, a.challenge.ID) |
| } |
| if err != nil { |
| - return runnerproto.AccountSetup{}, provider.ErrLoginUnavailable |
| + if l.interrupted(ctx) { |
| + return runnerproto.AccountSetup{}, ctx.Err() |
| + } |
| + _ = l.Driver.Cancel(ctx, a.challenge.ID) |
| + _, _ = l.Instance.ReportAccountSetup(ctx, runnerproto.AccountSetupResult{ID: a.setup.ID, Revision: a.setup.Revision, State: "unavailable"}) |
| + l.cleanup() |
| + return runnerproto.AccountSetup{}, err |
| } |
| if r.State == "pending" { |
| return a.setup, nil |
| @@ -135,25 +173,38 @@ func (l *AccountLogin) Poll(ctx context.Context) (runnerproto.AccountSetup, erro |
| if r.State == "connected" { |
| b, err := l.verify(ctx, r.Identity) |
| if err != nil { |
| + if l.interrupted(ctx) { |
| + return runnerproto.AccountSetup{}, ctx.Err() |
| + } |
| _ = l.Driver.Cancel(ctx, a.challenge.ID) |
| + _, _ = l.Instance.ReportAccountSetup(ctx, runnerproto.AccountSetupResult{ID: a.setup.ID, Revision: a.setup.Revision, State: "unavailable"}) |
| + l.cleanup() |
| return runnerproto.AccountSetup{}, err |
| } |
| if err = l.current(ctx); err != nil { |
| + if l.interrupted(ctx) { |
| + return runnerproto.AccountSetup{}, ctx.Err() |
| + } |
| + l.cleanup() |
| return runnerproto.AccountSetup{}, err |
| } |
| if l.Save == nil { |
| return runnerproto.AccountSetup{}, provider.ErrContract |
| } |
| if err = l.Save(ctx, a.setup, b); err != nil { |
| + if l.interrupted(ctx) { |
| + return runnerproto.AccountSetup{}, ctx.Err() |
| + } |
| + _ = l.Cancel(ctx) |
| return runnerproto.AccountSetup{}, provider.ErrAccountMaintenance |
| } |
| q.AccountID = r.Identity.AccountID |
| q.ProviderVersion = r.Identity.ProviderVersion |
| + a.saved = &q |
| + return l.reportSaved(ctx) |
| } |
| out, err := l.Instance.ReportAccountSetup(ctx, q) |
| - if err == nil { |
| - l.active = nil |
| - } |
| + l.cleanup() |
| return out, err |
| } |
| func (l *AccountLogin) verify(ctx context.Context, id provider.Identity) (provider.Binding, error) { |
| @@ -190,10 +241,44 @@ func (l *AccountLogin) Cancel(ctx context.Context) error { |
| return provider.ErrUncertain |
| } |
| a := l.active |
| + if a.saved != nil { |
| + _, err := l.reportSaved(ctx) |
| + return err |
| + } |
| if err := l.Driver.Cancel(ctx, a.challenge.ID); err != nil { |
| return provider.ErrAccountMaintenance |
| } |
| _, err := l.Instance.ReportAccountSetup(ctx, runnerproto.AccountSetupResult{ID: a.setup.ID, Revision: a.setup.Revision, State: "cancelled"}) |
| - l.active = nil |
| + l.cleanup() |
| return err |
| } |
| + |
| +func (l *AccountLogin) reportSaved(ctx context.Context) (runnerproto.AccountSetup, error) { |
| + // The authenticated endpoint rechecks roster and generations even on replay. |
| + out, err := l.Instance.ReportAccountSetup(ctx, *l.active.saved) |
| + if err == nil { |
| + l.cleanup() |
| + } |
| + return out, err |
| +} |
| +func (l *AccountLogin) cleanup() { |
| + if l.active == nil { |
| + return |
| + } |
| + if l.active.saved == nil { |
| + _ = os.RemoveAll(l.active.home) |
| + } |
| + _ = os.Remove(l.active.marker) |
| + l.active = nil |
| +} |
| +func (l *AccountLogin) Saved() bool { return l.active != nil && l.active.saved != nil } |
| + |
| +func (l *AccountLogin) interrupted(ctx context.Context) bool { |
| + if ctx.Err() == nil { |
| + return false |
| + } |
| + cleanup, stop := context.WithTimeout(context.Background(), 5*time.Second) |
| + defer stop() |
| + _ = l.Cancel(cleanup) |
| + return true |
| +} |
diff --git a/internal/runner/setup/account_login_test.go b/internal/runner/setup/account_login_test.go| index 2f62b612..b78d9423 100644 |
| --- a/internal/runner/setup/account_login_test.go |
| +++ b/internal/runner/setup/account_login_test.go |
| @@ -4,6 +4,7 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "fmt" |
| "os" |
| "path/filepath" |
| "strings" |
| @@ -83,7 +84,29 @@ func TestOnboardingAccountDedicatedHome(t *testing.T) { |
| if first == d.home { |
| t.Fatal("same-provider homes shared") |
| } |
| + if err := os.WriteFile(filepath.Join(d.home, "auth.json"), []byte(`{"token":"NATIVE-SECRET"}`), 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + d.state = "connected" |
| + probes := 0 |
| + l.Probe = func(context.Context, provider.Binding) (provider.Identity, error) { probes++; return d.identity, nil } |
| + out, err := l.Poll(ctx) |
| + if err != nil || out.State != "connected" || probes != 1 || i.result.AccountID != d.identity.AccountID { |
| + t.Fatal("dedicated home missing identity readback", out, err) |
| + } |
| + entries, err := os.ReadDir(l.Root) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, entry := range entries { |
| + if strings.Contains(entry.Name(), "journal") || strings.HasSuffix(entry.Name(), ".jsonl") { |
| + t.Fatal("login emitted journal events") |
| + } |
| + } |
| raw, _ := json.Marshal(i.result) |
| + if strings.Contains(string(raw), "NATIVE-SECRET") { |
| + t.Fatal("credential left runner") |
| + } |
| if strings.Contains(string(raw), "provider-secret") || strings.Contains(string(raw), l.Root) { |
| t.Fatal("secret left runner") |
| } |
| @@ -185,3 +208,191 @@ func TestOnboardingAccountBindings(t *testing.T) { |
| t.Fatal("labeled accounts lost", e) |
| } |
| } |
| + |
| +func TestOnboardingAccountReportRetry(t *testing.T) { |
| + l, d, i := loginHarness(t, "codex") |
| + ctx := context.Background() |
| + if _, e := l.Begin(ctx, i.setup.ID); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e := os.WriteFile(filepath.Join(d.home, "auth.json"), []byte(`{"token":"fixture"}`), 0600); e != nil { |
| + t.Fatal(e) |
| + } |
| + saves := 0 |
| + l.Save = func(context.Context, runnerproto.AccountSetup, provider.Binding) error { |
| + saves++ |
| + i.err = errors.New("lost response") |
| + return nil |
| + } |
| + d.state = "connected" |
| + if _, e := l.Poll(ctx); e == nil { |
| + t.Fatal("expected report failure") |
| + } |
| + i.err = nil |
| + out, e := l.Poll(ctx) |
| + if e != nil || out.State != "connected" || saves != 1 { |
| + t.Fatal("saved account report not retryable", out, e, saves) |
| + } |
| +} |
| + |
| +func TestOnboardingAccountClockExpiry(t *testing.T) { |
| + l, d, i := loginHarness(t, "codex") |
| + if _, e := l.Begin(context.Background(), i.setup.ID); e != nil { |
| + t.Fatal(e) |
| + } |
| + l.active.challenge.ExpiresAt = time.Now().Add(-time.Second) |
| + out, e := l.Poll(context.Background()) |
| + if e != nil || out.State != "expired" || !d.cancelled { |
| + t.Fatal("clock expiry ignored", out, e) |
| + } |
| + if _, e = os.Stat(d.home); !os.IsNotExist(e) { |
| + t.Fatal("expired home retained") |
| + } |
| +} |
| + |
| +type beginFailure struct { |
| + loginFixture |
| + invalid bool |
| +} |
| + |
| +func (d *beginFailure) Begin(ctx context.Context, name, home string) (provider.LoginChallenge, error) { |
| + c, e := d.loginFixture.Begin(ctx, name, home) |
| + if d.invalid { |
| + c.Mode = "wrong" |
| + return c, e |
| + } |
| + return c, provider.ErrLoginUnavailable |
| +} |
| +func TestOnboardingAccountBeginCleanup(t *testing.T) { |
| + for _, invalid := range []bool{false, true} { |
| + t.Run(fmt.Sprint(invalid), func(t *testing.T) { |
| + l, base, i := loginHarness(t, "claude") |
| + d := &beginFailure{loginFixture: *base, invalid: invalid} |
| + l.Driver = d |
| + if _, e := l.Begin(context.Background(), i.setup.ID); e == nil { |
| + t.Fatal("bad Begin accepted") |
| + } |
| + entries, e := os.ReadDir(l.Root) |
| + if e != nil || len(entries) != 0 { |
| + t.Fatal("failed Begin leaked home or marker", entries, e) |
| + } |
| + if invalid && !d.cancelled { |
| + t.Fatal("invalid challenge left CLI running") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestOnboardingAccountResumeSavedReport(t *testing.T) { |
| + l, d, i := loginHarness(t, "codex") |
| + ctx := context.Background() |
| + if _, e := l.Begin(ctx, i.setup.ID); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e := os.WriteFile(filepath.Join(d.home, "auth.json"), []byte(`{"token":"fixture"}`), 0600); e != nil { |
| + t.Fatal(e) |
| + } |
| + path := filepath.Join(l.Root, "bindings.json") |
| + l.Save = func(ctx context.Context, s runnerproto.AccountSetup, b provider.Binding) error { |
| + if e := SaveAccountBinding(ctx, path, "person", "model", s, b); e != nil { |
| + return e |
| + } |
| + i.err = errors.New("offline after save") |
| + return nil |
| + } |
| + d.state = "connected" |
| + if _, e := l.Poll(ctx); e == nil { |
| + t.Fatal("expected report loss") |
| + } |
| + i.err = nil |
| + handled, e := ResumeSavedAccount(ctx, path, "person", i.setup, i, l.Probe) |
| + if e != nil || !handled || i.setup.State != "connected" { |
| + t.Fatal("restart could not report saved binding", handled, e) |
| + } |
| + if _, e = os.Stat(d.home); e != nil { |
| + t.Fatal("saved home removed", e) |
| + } |
| + i.setup.State = "pending" |
| + _, e = ResumeSavedAccount(ctx, path, "other-person", i.setup, i, l.Probe) |
| + if e == nil { |
| + t.Fatal("saved binding changed owner") |
| + } |
| +} |
| + |
| +type cancelOnBegin struct { |
| + loginFixture |
| + stop context.CancelFunc |
| +} |
| + |
| +func (d *cancelOnBegin) Begin(ctx context.Context, name, home string) (provider.LoginChallenge, error) { |
| + c, e := d.loginFixture.Begin(ctx, name, home) |
| + d.stop() |
| + return c, e |
| +} |
| +func TestOnboardingAccountCommandCancel(t *testing.T) { |
| + l, base, i := loginHarness(t, "claude") |
| + ctx, stop := context.WithCancel(context.Background()) |
| + defer stop() |
| + d := &cancelOnBegin{loginFixture: *base, stop: stop} |
| + l.Driver = d |
| + if e := RunAccountLogin(ctx, l, i.setup.ID); !errors.Is(e, context.Canceled) { |
| + t.Fatal("interrupt not returned", e) |
| + } |
| + if !d.cancelled || i.setup.State != "cancelled" { |
| + t.Fatal("interrupt not reported", i.setup) |
| + } |
| + if _, e := os.Stat(d.home); !os.IsNotExist(e) { |
| + t.Fatal("cancelled home retained") |
| + } |
| +} |
| + |
| +type contextAccountInstance struct{ *loginInstance } |
| + |
| +func (i contextAccountInstance) ReportAccountSetup(ctx context.Context, q runnerproto.AccountSetupResult) (runnerproto.AccountSetup, error) { |
| + if e := ctx.Err(); e != nil { |
| + return runnerproto.AccountSetup{}, e |
| + } |
| + return i.loginInstance.ReportAccountSetup(ctx, q) |
| +} |
| +func TestOnboardingAccountInterruptDuringBegin(t *testing.T) { |
| + l, base, i := loginHarness(t, "claude") |
| + l.Instance = contextAccountInstance{i} |
| + ctx, stop := context.WithCancel(context.Background()) |
| + defer stop() |
| + d := &cancelOnBegin{loginFixture: *base, stop: stop} |
| + l.Driver = d |
| + if e := RunAccountLogin(ctx, l, i.setup.ID); !errors.Is(e, context.Canceled) { |
| + t.Fatal("interrupt not returned", e) |
| + } |
| + if !d.cancelled || i.setup.State != "cancelled" { |
| + t.Fatal("interrupt during Begin not reported", i.setup) |
| + } |
| + if _, e := os.Stat(d.home); !os.IsNotExist(e) { |
| + t.Fatal("cancelled home retained") |
| + } |
| +} |
| + |
| +func TestOnboardingAccountInterruptDuringProbe(t *testing.T) { |
| + l, d, i := loginHarness(t, "codex") |
| + l.Instance = contextAccountInstance{i} |
| + ctx, stop := context.WithCancel(context.Background()) |
| + defer stop() |
| + if _, e := l.Begin(ctx, i.setup.ID); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e := os.WriteFile(filepath.Join(d.home, "auth.json"), []byte(`{"token":"fixture"}`), 0600); e != nil { |
| + t.Fatal(e) |
| + } |
| + d.state = "connected" |
| + l.Probe = func(context.Context, provider.Binding) (provider.Identity, error) { |
| + stop() |
| + return provider.Identity{}, context.Canceled |
| + } |
| + _, e := l.Poll(ctx) |
| + if !errors.Is(e, context.Canceled) || i.setup.State != "cancelled" || !d.cancelled { |
| + t.Fatal("probe interrupt not cancelled", e, i.setup) |
| + } |
| + if _, e = os.Stat(d.home); !os.IsNotExist(e) { |
| + t.Fatal("interrupted probe retained home") |
| + } |
| +} |
diff --git a/internal/runner/setup/account_resume.go b/internal/runner/setup/account_resume.go| new file mode 100644 |
| index 00000000..ee9449ed |
| --- /dev/null |
| +++ b/internal/runner/setup/account_resume.go |
| @@ -0,0 +1,51 @@ |
| +package runnersetup |
| + |
| +import ( |
| + "context" |
| + "os" |
| + "path/filepath" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| + "amadan.net/oficina/equipo/internal/runnerproto" |
| +) |
| + |
| +// ResumeSavedAccount retries only the report of an already saved binding. It |
| +// never resumes a provider login or adopts an uncertain allocated home. |
| +func ResumeSavedAccount(ctx context.Context, path, person string, s runnerproto.AccountSetup, instance AccountInstance, probe func(context.Context, provider.Binding) (provider.Identity, error)) (bool, error) { |
| + st, err := os.Lstat(path) |
| + if os.IsNotExist(err) { |
| + return false, nil |
| + } |
| + if err != nil || !st.Mode().IsRegular() || st.Mode().Perm() != 0600 || st.Size() > 1<<20 { |
| + return false, provider.ErrPolicy |
| + } |
| + f, err := os.Open(path) |
| + if err != nil { |
| + return false, provider.ErrPolicy |
| + } |
| + defer f.Close() |
| + var rows []AccountBinding |
| + if runnerproto.DecodeLimit(f, &rows, 1<<20) != nil { |
| + return false, provider.ErrIdentity |
| + } |
| + for _, row := range rows { |
| + if row.LocalID != s.ID { |
| + continue |
| + } |
| + if row.ID != s.ID || row.Provider != s.Provider || row.PersonID != person { |
| + return true, provider.ErrIdentity |
| + } |
| + b := provider.Binding{ID: row.ID, Home: row.ProviderHome, AccountID: row.AccountID, Provider: row.Provider, Expected: row.ExpectedIdentity, RuntimeRoot: filepath.Join(filepath.Dir(path), "accounts", "runtime")} |
| + lease, err := provider.OpenAccount(ctx, b) |
| + if err != nil { |
| + return true, err |
| + } |
| + defer lease.Close() |
| + if err = lease.Preflight(ctx, probe); err != nil { |
| + return true, provider.ErrIdentity |
| + } |
| + _, err = instance.ReportAccountSetup(ctx, runnerproto.AccountSetupResult{ID: s.ID, Revision: s.Revision, State: "connected", AccountID: b.AccountID, ProviderVersion: b.Expected.ProviderVersion}) |
| + return true, err |
| + } |
| + return false, nil |
| +} |
diff --git a/internal/runner/setup/account_terminal_test.go b/internal/runner/setup/account_terminal_test.go| index 32b2f334..3c35ecb0 100644 |
| --- a/internal/runner/setup/account_terminal_test.go |
| +++ b/internal/runner/setup/account_terminal_test.go |
| @@ -17,7 +17,7 @@ import ( |
| ) |
| // This is a terminal boundary fixture, not a recording of a supported provider |
| -// exchange. Production remains unavailable until the live gate records it. |
| +// exchange. Real provider behavior still requires the live gate. |
| type terminalLogin struct { |
| loginFixture |
| input string |
diff --git a/internal/runner/setup/service.go b/internal/runner/setup/service.go| index a3db761f..18e38035 100644 |
| --- a/internal/runner/setup/service.go |
| +++ b/internal/runner/setup/service.go |
| @@ -4,6 +4,7 @@ import ( |
| "context" |
| "os" |
| "os/exec" |
| + "path/filepath" |
| "strconv" |
| "strings" |
| ) |
| @@ -41,14 +42,33 @@ func enableService(ctx context.Context, path string) error { |
| // CheckServiceEnvironment refuses to enable a unit without its private local |
| // configuration. It reads only the explicit installation root. |
| func CheckServiceEnvironment(root, origin, state string) error { |
| + values, e := ReadServiceEnvironment(root) |
| + if e != nil { |
| + return e |
| + } |
| + if values["EQUIPO_ORIGIN"] != origin || values["EQUIPO_RUNNER_STATE_DIR"] != state { |
| + return errUnavailable |
| + } |
| + return nil |
| +} |
| + |
| +func SaveServiceEnvironment(root string, data []byte) error { |
| + return writeOwned(root+"/runner.env", data, 0600) |
| +} |
| + |
| +func ReadServiceEnvironment(root string) (map[string]string, error) { |
| path := root + "/runner.env" |
| + real, e := filepath.EvalSymlinks(path) |
| + if e != nil || real != path { |
| + return nil, errUnavailable |
| + } |
| i, e := os.Lstat(path) |
| - if e != nil || !i.Mode().IsRegular() || i.Mode().Perm() != 0600 { |
| - return errUnavailable |
| + if e != nil || !i.Mode().IsRegular() || i.Mode().Perm() != 0600 || i.Size() > 65536 { |
| + return nil, errUnavailable |
| } |
| b, e := os.ReadFile(path) |
| if e != nil { |
| - return e |
| + return nil, e |
| } |
| values := map[string]string{} |
| for _, line := range strings.Split(string(b), "\n") { |
| @@ -56,24 +76,18 @@ func CheckServiceEnvironment(root, origin, state string) error { |
| continue |
| } |
| k, v, ok := strings.Cut(line, "=") |
| - if !ok || values[k] != "" { |
| - return errUnavailable |
| + _, duplicate := values[k] |
| + if !ok || !strings.HasPrefix(k, "EQUIPO_") || duplicate { |
| + return nil, errUnavailable |
| } |
| if strings.HasPrefix(v, "\"") { |
| var err error |
| v, err = strconv.Unquote(v) |
| if err != nil { |
| - return errUnavailable |
| + return nil, errUnavailable |
| } |
| } |
| values[k] = v |
| } |
| - if values["EQUIPO_ORIGIN"] != origin || values["EQUIPO_RUNNER_STATE_DIR"] != state { |
| - return errUnavailable |
| - } |
| - return nil |
| -} |
| - |
| -func SaveServiceEnvironment(root string, data []byte) error { |
| - return writeOwned(root+"/runner.env", data, 0600) |
| + return values, nil |
| } |
diff --git a/internal/runnerproto/account_setup.go b/internal/runnerproto/account_setup.go| index 00cbc09c..3b629669 100644 |
| --- a/internal/runnerproto/account_setup.go |
| +++ b/internal/runnerproto/account_setup.go |
| @@ -3,7 +3,6 @@ package runnerproto |
| import ( |
| "context" |
| "net/http" |
| - "regexp" |
| "time" |
| ) |
| @@ -30,14 +29,9 @@ type AccountSetupRequest struct { |
| Result *AccountSetupResult `json:"result,omitempty"` |
| } |
| -var displayCode = regexp.MustCompile(`^[A-Z0-9]{4}-[A-Z0-9]{4}$`) |
| - |
| -func ValidLoginDisplay(provider, mode string, d *LoginDisplay, now time.Time) bool { |
| - if d == nil { |
| - return true |
| - } |
| - return provider == "codex" && mode == "device" && d.VerificationURI == "https://auth.openai.com/codex/device" && displayCode.MatchString(d.UserCode) && now.Before(d.ExpiresAt) && !d.ExpiresAt.After(now.Add(15*time.Minute)) |
| -} |
| +// Terminal passthrough has no instance display contract. Reject all supplied |
| +// display data until a separately verified projection is introduced. |
| +func ValidLoginDisplay(_, _ string, d *LoginDisplay, _ time.Time) bool { return d == nil } |
| type AccountSetupAPI interface { |
| RunnerAccountSetup(context.Context, RunnerPrincipal, string) (AccountSetup, error) |