fix: support a toolchain-switched Go runtime in check namespaces
8 files changed,
+191
−37
docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md+58 −0internal/equipotest/preparation_integration_test.go+11 −6internal/equipotest/runner_flow_test.go+4 −4internal/runner/checks/containment_test.go+84 −12internal/runner/checks/sandbox.go+6 −5internal/runner/checks/sandbox_test.go+21 −4internal/runner/direct_graph_test.go+4 −4internal/runner/provider/check_policy.go+3 −2
CI failed — run details
Intent
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md| index ddf5a1f2..0efae190 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md |
| @@ -23891,3 +23891,61 @@ python3 scripts/runner-dead-references.py |
| reference scan: 501 text files, 969 matches, 0 failures |
| ``` |
| Exit 0. Task-owned exact inventory entries were updated after reviewing each changed line. No blanket exceptions were introduced. |
| + |
| + |
| +## CI fix after Task 11b: toolchain-switched Go runtime |
| + |
| +The clean PATH selected `/usr/local/go/bin/go` (go1.26.5). Fixtures inferred that bootstrap's GOROOT, then the check sandbox correctly rejected it because checks require go1.26.10 with `GOTOOLCHAIN=local`. This checkout has no `toolchain` directive, so the brief's automatic-switch assumption did not hold. Fixtures now resolve `go env GOROOT` with the exact required `GOTOOLCHAIN=go1.26.10`, including the downloaded runtime under GOMODCACHE. Production configuration remains explicit; wrong versions still fail with binary/root/observed/required details. |
| + |
| +Directory refusals now identify the path. Preparation tests log callback failures and saved task state. New regressions check version diagnostics, symlink refusal diagnostics, and a real Go runtime nested under the read-only module cache. The nested test compiles/runs a Go test, checks both aliases for write protection and denial, and excludes the host build cache. No mount, namespace, alias, version or digest rule was relaxed. |
| + |
| +All commands below ran from `/home/paulca/amadan.net/oficina/equipo-plan-2b` on `plan-2b`. |
| + |
| +RED commands (all exit 1, named failures): |
| + |
| +```sh |
| +env -i HOME=$HOME PATH=/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin TMPDIR=/home/paulca/t/e2b CGO_ENABLED=0 go test ./internal/runner -run '^TestDirectBugWorkflow$' -count=1 |
| +CGO_ENABLED=0 go test ./internal/runner/checks -run '^TestCheckSandboxToolchainDiagnostic$' -count=1 |
| +CGO_ENABLED=0 go test ./internal/runner/checks -run '^TestCheckCacheRejectsSymlinkPathDiagnostic$' -count=1 |
| +``` |
| + |
| +Results: original `direct_graph_test.go:74: provider_contract` in 0.060s; new tests report missing path/version detail and missing refused-path detail, respectively. |
| + |
| +GREEN commands (all exit 0): |
| + |
| +```sh |
| +env -i HOME=$HOME PATH=/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin TMPDIR=/home/paulca/t/e2b CGO_ENABLED=0 go test ./internal/runner -run '^TestDirectBugWorkflow$' -count=1 |
| +env -i HOME=$HOME PATH=/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin TMPDIR=/home/paulca/t/e2b CGO_ENABLED=0 go test ./internal/runner ./internal/equipotest -run '^(TestDirectBugWorkflow|TestBugPreparationIntegration|TestBugPreparationCrashRealProtocolLocalGit|TestRunnerDirectEndToEnd)$' -count=1 |
| +CGO_ENABLED=0 go test ./internal/runner ./internal/equipotest -run '^(TestDirectBugWorkflow|TestBugPreparationIntegration|TestBugPreparationCrashRealProtocolLocalGit|TestRunnerDirectEndToEnd)$' -count=1 |
| +CGO_ENABLED=0 go test ./internal/runner/checks -run '^(TestCheckNamespaceGoRootInsideModuleCache|TestCheckCacheRejectsSymlinkPathDiagnostic|TestCheckSandboxToolchainDiagnostic|TestCheckSandboxToolchain|TestCheckCacheIsolation|TestCheckNamespaceDeniedMountAliases|TestCheckCacheRejectsBroadHome|TestCheckCacheRejectsNamespaceScratch)$' -count=1 |
| +CGO_ENABLED=0 go vet ./... |
| +``` |
| + |
| +Results: exact reproduction 68.861s; runner/equipotest clean PATH 116.107s/78.834s; default PATH 114.746s/80.227s; targeted checks 15.826s; vet no output. |
| + |
| +Mutations, each independently applied and restored, all compiled and exited 1 with the named test failing: |
| + |
| +| Mutation | Exact command | Observed failure | |
| +| --- | --- | --- | |
| +| M1: fixture requests local bootstrap instead of required version | `env -i HOME=$HOME PATH=/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin TMPDIR=/home/paulca/t/e2b CGO_ENABLED=0 go test ./internal/runner -run '^TestDirectBugWorkflow$' -count=1` | Error names `/usr/local/go/bin/go`, go1.26.5 and required go1.26.10. | |
| +| M2: bypass version rejection | `CGO_ENABLED=0 go test ./internal/runner/checks -run '^TestCheckSandboxToolchainDiagnostic$' -count=1` | Invalid runtime accepted; diagnostic assertion sees nil. | |
| +| M3: return bare contract class | `CGO_ENABLED=0 go test ./internal/runner/checks -run '^TestCheckSandboxToolchainDiagnostic$' -count=1` | Missing path/version details. | |
| +| M4: resolve symlink before directory pinning | `CGO_ENABLED=0 go test ./internal/runner/checks -run '^TestCheckCacheRejectsSymlinkPathDiagnostic$' -count=1` | Alias accepted; assertion sees nil. | |
| +| M5: return bare pinning error | `CGO_ENABLED=0 go test ./internal/runner/checks -run '^TestCheckCacheRejectsSymlinkPathDiagnostic$' -count=1` | Missing refused-path detail. | |
| +| M6: omit runtime alias denial | `CGO_ENABLED=0 go test ./internal/runner/checks -run '^TestCheckNamespaceGoRootInsideModuleCache$' -count=1` | `/opt/go/VERSION` becomes readable, exit 0. | |
| +| M7: omit module alias denial | `CGO_ENABLED=0 go test ./internal/runner/checks -run '^TestCheckNamespaceGoRootInsideModuleCache$' -count=1` | `/opt/go-mod/golang.org/toolchain@.../VERSION` becomes readable, exit 0. | |
| + |
| +Full source mutations, output excerpts, interpretations, files and new diagnostic strings are in `.superpowers/sdd/2026-11-03-equipo-plan-2b-direct/ci-fix-report.md`. No new app strings or `copy.go` entries. No live/provider run, full test suite, copy-review server, helper agent, merge, push or deployment. |
| + |
| +### Final restored verification |
| + |
| +After all seven mutations were restored: |
| + |
| +```sh |
| +env -i HOME=$HOME PATH=/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin TMPDIR=/home/paulca/t/e2b CGO_ENABLED=0 go test ./internal/runner -run '^TestDirectBugWorkflow$' -count=1 |
| +env -i HOME=$HOME PATH=/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin TMPDIR=/home/paulca/t/e2b CGO_ENABLED=0 go test ./internal/runner/checks -run '^(TestCheckNamespaceGoRootInsideModuleCache|TestCheckCacheRejectsSymlinkPathDiagnostic|TestCheckSandboxToolchainDiagnostic|TestCheckSandboxToolchain|TestCheckCacheIsolation|TestCheckNamespaceDeniedMountAliases|TestCheckCacheRejectsBroadHome|TestCheckCacheRejectsNamespaceScratch)$' -count=1 |
| +CGO_ENABLED=0 go vet ./... |
| +git diff --check |
| +``` |
| + |
| +All exited 0. Runner: 80.806s. Targeted checks: 17.590s. Vet and diff check: no output. `internal/runner/checks/namespace.go` has no final diff. All owned test processes finished; test fixtures removed their scratch. Session scratch `/home/paulca/t/e2b/ci-fix.EXjMwN` was removed after copying its evidence into this report. |
diff --git a/internal/equipotest/preparation_integration_test.go b/internal/equipotest/preparation_integration_test.go| index ae3a8207..906eb859 100644 |
| --- a/internal/equipotest/preparation_integration_test.go |
| +++ b/internal/equipotest/preparation_integration_test.go |
| @@ -94,11 +94,11 @@ func runPreparationSupervisor(t *testing.T, crash bool) { |
| policy := provider.ReadPolicy{ConfigHash: strings.Repeat("a", 64), DeniedPaths: []string{state, private}} |
| binary, err := exec.LookPath("codex") |
| executionMust(t, err) |
| - goBinary, err := exec.LookPath("go") |
| + goCommand := exec.Command("go", "env", "GOROOT") |
| + goCommand.Env = append(os.Environ(), "GOROOT=", "GOTOOLCHAIN="+checks.GoVersion) |
| + goOutput, err := goCommand.Output() |
| executionMust(t, err) |
| - goBinary, err = filepath.EvalSymlinks(goBinary) |
| - executionMust(t, err) |
| - goRoot := filepath.Dir(filepath.Dir(goBinary)) |
| + goRoot := strings.TrimSpace(string(goOutput)) |
| helper, err := os.Executable() |
| executionMust(t, err) |
| namespaces, err := containment.New(containment.Config{Binary: "/usr/bin/bwrap", RunnerBinary: helper, ScratchRoot: scratch, ProviderNetworks: []provider.NetworkContract{{Provider: "claude"}, {Provider: "codex"}}}) |
| @@ -111,7 +111,12 @@ func runPreparationSupervisor(t *testing.T, crash bool) { |
| sandbox, err := checks.NewCodexSandbox(ctx, checks.SandboxConfig{Binary: binary, ScratchRoot: scratch, GoRoot: goRoot, GoBinary: filepath.Join(goRoot, "bin/go"), Protected: protected, Host: host, RunnerBinary: helper, Bwrap: "/usr/bin/bwrap", ModuleCache: filepath.Join(root, "modules")}) |
| executionMust(t, err) |
| localRepo := "" |
| - m, err := workspace.New(workspace.Config{PrivateRoot: private, WorkspaceRoot: filepath.Join(root, "work"), GitPath: "/usr/bin/git", Forge: preparationRemote{remote}, Protected: protected, Policy: func(context.Context, provider.Selection) (provider.ReadPolicy, error) { return policy, nil }, Definitions: func(ctx context.Context, target team.TargetBinding, repo string) (runnerproto.PreparedBug, error) { |
| + m, err := workspace.New(workspace.Config{PrivateRoot: private, WorkspaceRoot: filepath.Join(root, "work"), GitPath: "/usr/bin/git", Forge: preparationRemote{remote}, Protected: protected, Policy: func(context.Context, provider.Selection) (provider.ReadPolicy, error) { return policy, nil }, Definitions: func(ctx context.Context, target team.TargetBinding, repo string) (prepared runnerproto.PreparedBug, preparationErr error) { |
| + defer func() { |
| + if preparationErr != nil { |
| + t.Logf("preparation definition/baseline: %+v", preparationErr) |
| + } |
| + }() |
| localRepo = repo |
| d, err := checks.LoadBaseDefinition(ctx, repo, target.Repository, target.BaseRevision, scratch) |
| if err != nil { |
| @@ -178,7 +183,7 @@ func runPreparationSupervisor(t *testing.T, crash bool) { |
| savedPreparation, err := f.s.Task(ctx, ownerActor, task.ID) |
| executionMust(t, err) |
| if savedPreparation.BaseCommit != base { |
| - t.Fatal("preparation did not pin immutable Git base") |
| + t.Fatalf("preparation did not pin immutable Git base: got %q, want %q; task: %+v", savedPreparation.BaseCommit, base, savedPreparation) |
| } |
| if scalar(t, f.d, "SELECT count(*) FROM runner_assignments WHERE state='contained'") != 1 { |
| t.Fatal("supervisor did not prove preparation containment") |
diff --git a/internal/equipotest/runner_flow_test.go b/internal/equipotest/runner_flow_test.go| index 4842d8c2..3fd9672b 100644 |
| --- a/internal/equipotest/runner_flow_test.go |
| +++ b/internal/equipotest/runner_flow_test.go |
| @@ -92,11 +92,11 @@ func TestRunnerDirectEndToEnd(t *testing.T) { |
| protected := workspace.SecurityPaths{RunnerState: state, RunnerConfig: filepath.Join(state, "config"), Journal: filepath.Join(state, "j.db"), Bearer: filepath.Join(state, "bearer"), Cleanup: filepath.Join(state, "cleanup"), ForgeCredential: filepath.Join(state, "forge"), LegacyHome: filepath.Join(state, "paseo"), ProviderHomes: []string{filepath.Join(state, "provider")}, SSH: filepath.Join(state, "ssh")} |
| codex, err := exec.LookPath("codex") |
| executionMust(t, err) |
| - goBinary, err := exec.LookPath("go") |
| + goCommand := exec.Command("go", "env", "GOROOT") |
| + goCommand.Env = append(os.Environ(), "GOROOT=", "GOTOOLCHAIN="+checks.GoVersion) |
| + goOutput, err := goCommand.Output() |
| executionMust(t, err) |
| - goBinary, err = filepath.EvalSymlinks(goBinary) |
| - executionMust(t, err) |
| - goRoot := filepath.Dir(filepath.Dir(goBinary)) |
| + goRoot := strings.TrimSpace(string(goOutput)) |
| executionMust(t, os.Mkdir(filepath.Join(root, "modules"), 0700)) |
| sandbox, err := checks.NewCodexSandbox(ctx, checks.SandboxConfig{Binary: codex, ScratchRoot: scratch, GoRoot: goRoot, GoBinary: filepath.Join(goRoot, "bin/go"), Protected: protected, Host: host, RunnerBinary: helper, Bwrap: "/usr/bin/bwrap", ModuleCache: filepath.Join(root, "modules")}) |
| executionMust(t, err) |
diff --git a/internal/runner/checks/containment_test.go b/internal/runner/checks/containment_test.go| index 86532afe..ae2be617 100644 |
| --- a/internal/runner/checks/containment_test.go |
| +++ b/internal/runner/checks/containment_test.go |
| @@ -3,9 +3,12 @@ package checks_test |
| import ( |
| "bytes" |
| "context" |
| + "errors" |
| "os" |
| "os/exec" |
| "path/filepath" |
| + "runtime" |
| + "strconv" |
| "strings" |
| "testing" |
| @@ -29,7 +32,7 @@ func (h *checkHost) Start(ctx context.Context, l provider.Launch, argv []string) |
| return h.ProcessHost.Start(ctx, l, argv) |
| } |
| -func namespaceCheck(t *testing.T, cacheInScratch ...bool) (*checks.CodexSandbox, string, string, provider.ReadPolicy, *checkHost) { |
| +func namespaceCheck(t *testing.T, configure ...func(*checks.SandboxConfig)) (*checks.CodexSandbox, string, string, provider.ReadPolicy, *checkHost) { |
| t.Helper() |
| root := t.TempDir() |
| if err := os.Chmod(root, 0700); err != nil { |
| @@ -41,21 +44,17 @@ func namespaceCheck(t *testing.T, cacheInScratch ...bool) (*checks.CodexSandbox, |
| t.Fatal(err) |
| } |
| } |
| - if len(cacheInScratch) > 0 && cacheInScratch[0] { |
| - mods = scratch |
| - } |
| binary, err := exec.LookPath("codex") |
| if err != nil { |
| t.Fatal(err) |
| } |
| - goBin, err := exec.LookPath("go") |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - goBin, err = filepath.EvalSymlinks(goBin) |
| + goCommand := exec.Command("go", "env", "GOROOT") |
| + goCommand.Env = append(os.Environ(), "GOROOT=", "GOTOOLCHAIN="+checks.GoVersion) |
| + goOutput, err := goCommand.Output() |
| if err != nil { |
| - t.Fatal(err) |
| + t.Fatalf("resolve check toolchain: %v", err) |
| } |
| + goRoot := strings.TrimSpace(string(goOutput)) |
| helper, err := os.Executable() |
| if err != nil { |
| t.Fatal(err) |
| @@ -75,7 +74,11 @@ func namespaceCheck(t *testing.T, cacheInScratch ...bool) (*checks.CodexSandbox, |
| p := filepath.Join(root, "private") |
| protected := workspace.SecurityPaths{RunnerState: p, RunnerConfig: p, Journal: p, Bearer: p, Cleanup: p, ForgeCredential: p, LegacyHome: p, SSH: p, ProviderHomes: []string{p}} |
| host := &checkHost{ProcessHost: runner.NewDirectHost(j, m)} |
| - s, err := checks.NewCodexSandbox(context.Background(), checks.SandboxConfig{Binary: binary, ScratchRoot: scratch, GoBinary: goBin, GoRoot: filepath.Dir(filepath.Dir(goBin)), Protected: protected, Host: host, RunnerBinary: helper, Bwrap: "/usr/bin/bwrap", ModuleCache: mods}) |
| + cfg := checks.SandboxConfig{Binary: binary, ScratchRoot: scratch, GoBinary: filepath.Join(goRoot, "bin/go"), GoRoot: goRoot, Protected: protected, Host: host, RunnerBinary: helper, Bwrap: "/usr/bin/bwrap", ModuleCache: mods} |
| + for _, apply := range configure { |
| + apply(&cfg) |
| + } |
| + s, err := checks.NewCodexSandbox(context.Background(), cfg) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -197,9 +200,78 @@ func TestCheckCacheRejectsBroadHome(t *testing.T) { |
| } |
| func TestCheckCacheRejectsNamespaceScratch(t *testing.T) { |
| - s, work, _, policy, _ := namespaceCheck(t, true) |
| + s, work, _, policy, _ := namespaceCheck(t, func(cfg *checks.SandboxConfig) { cfg.ModuleCache = cfg.ScratchRoot }) |
| var out, stderr bytes.Buffer |
| if _, err := s.Run(context.Background(), checks.Command{Argv: []string{"/usr/bin/true"}, Dir: ".", TimeoutSeconds: 10}, work, policy, &out, &stderr); err == nil { |
| t.Fatal("namespace scratch accepted as module cache") |
| } |
| } |
| + |
| +func TestCheckNamespaceGoRootInsideModuleCache(t *testing.T) { |
| + var goRoot string |
| + s, work, _, policy, tracker := namespaceCheck(t, func(cfg *checks.SandboxConfig) { |
| + goRoot = filepath.Join(cfg.ModuleCache, "golang.org/toolchain@v0.0.1-"+checks.GoVersion+"."+runtime.GOOS+"-"+runtime.GOARCH) |
| + if err := os.CopyFS(goRoot, os.DirFS(cfg.GoRoot)); err != nil { |
| + t.Fatal(err) |
| + } |
| + cfg.GoRoot, cfg.GoBinary = goRoot, filepath.Join(goRoot, "bin/go") |
| + }) |
| + home, err := os.UserHomeDir() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + script := `import os,subprocess |
| +assert not os.path.exists(` + strconv.Quote(filepath.Join(home, ".cache/go-build")) + `) |
| +assert os.environ['GOTOOLCHAIN']=='local' |
| +for path in ['/opt/go/VERSION', '/opt/go-mod/` + filepath.ToSlash(filepath.Join("golang.org", filepath.Base(goRoot))) + `/VERSION']: |
| + assert os.path.isfile(path), path |
| + try: |
| + fd=os.open(path,os.O_WRONLY) |
| + except OSError: pass |
| + else: |
| + os.close(fd) |
| + raise Exception('runtime alias writable: '+path) |
| +assert os.statvfs('/opt/go-mod').f_flag & os.ST_RDONLY |
| +subprocess.run(['/opt/go/bin/go','test','./...'],check=True) |
| +print('nested runtime isolated')` |
| + for name, data := range map[string]string{"go.mod": "module nestedfixture\n\ngo 1.26.0\n", "nested_test.go": "package nestedfixture\nimport \"testing\"\nfunc TestNested(t *testing.T) {}\n"} { |
| + if err := os.WriteFile(filepath.Join(work, name), []byte(data), 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + var out, stderr bytes.Buffer |
| + code, err := s.Run(context.Background(), checks.Command{Argv: []string{"/usr/bin/python3", "-c", script}, Dir: ".", TimeoutSeconds: 120}, work, policy, &out, &stderr) |
| + if err != nil || code != 0 || !strings.Contains(out.String(), "nested runtime isolated") { |
| + t.Fatalf("nested runtime: code=%d error=%v stdout=%s stderr=%s", code, err, &out, &stderr) |
| + } |
| + for _, mount := range tracker.launches[0].Policy.Mounts { |
| + if !mount.ReadOnly || mount.Source == filepath.Join(home, ".cache/go-build") { |
| + t.Fatalf("unsafe mount: %+v", mount) |
| + } |
| + } |
| + policy.DeniedPaths = append(policy.DeniedPaths, filepath.Join(goRoot, "VERSION")) |
| + for _, alias := range []string{"/opt/go/VERSION", "/opt/go-mod/" + filepath.ToSlash(filepath.Join("golang.org", filepath.Base(goRoot))) + "/VERSION"} { |
| + out.Reset() |
| + stderr.Reset() |
| + code, err := s.Run(context.Background(), checks.Command{Argv: []string{"/usr/bin/cat", alias}, Dir: ".", TimeoutSeconds: 10}, work, policy, &out, &stderr) |
| + if err != nil || code == 0 || out.Len() != 0 { |
| + t.Fatalf("denied runtime alias %q: code=%d error=%v stdout=%s stderr=%s", alias, code, err, &out, &stderr) |
| + } |
| + } |
| +} |
| + |
| +func TestCheckCacheRejectsSymlinkPathDiagnostic(t *testing.T) { |
| + root := t.TempDir() |
| + real := filepath.Join(root, "real") |
| + alias := filepath.Join(root, "alias") |
| + if err := os.Mkdir(real, 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Symlink(real, alias); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, err := provider.BuildCheckPolicy(provider.CheckPolicyInputs{Workspace: root, GoRoot: real, ModuleCache: alias, Binary: "/usr/bin/true", RunnerBinary: "/usr/bin/true", Bwrap: "/usr/bin/bwrap"}) |
| + if !errors.Is(err, provider.ErrPolicy) || !strings.Contains(err.Error(), alias) { |
| + t.Fatalf("refused module cache must retain policy class and identify path %q: %v", alias, err) |
| + } |
| +} |
diff --git a/internal/runner/checks/sandbox.go b/internal/runner/checks/sandbox.go| index 008bb20e..d97960a5 100644 |
| --- a/internal/runner/checks/sandbox.go |
| +++ b/internal/runner/checks/sandbox.go |
| @@ -4,6 +4,7 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "fmt" |
| "io" |
| "os" |
| "os/exec" |
| @@ -63,10 +64,10 @@ func NewCodexSandbox(ctx context.Context, cfg SandboxConfig) (*CodexSandbox, err |
| cmd.Env = []string{"PATH=/usr/bin:/bin"} |
| b, err := cmd.Output() |
| if err != nil || strings.TrimSpace(string(b)) != CodexVersion { |
| - return nil, provider.ErrContract |
| + return nil, fmt.Errorf("%w: Codex binary %q returned %q, want %q (probe: %v)", provider.ErrContract, binary, strings.TrimSpace(string(b)), CodexVersion, err) |
| } |
| if !filepath.IsAbs(cfg.GoRoot) || !filepath.IsAbs(cfg.GoBinary) { |
| - return nil, provider.ErrContract |
| + return nil, fmt.Errorf("%w: Go root %q and binary %q must be absolute", provider.ErrContract, cfg.GoRoot, cfg.GoBinary) |
| } |
| goRoot, err := filepath.EvalSymlinks(cfg.GoRoot) |
| if err != nil { |
| @@ -74,11 +75,11 @@ func NewCodexSandbox(ctx context.Context, cfg SandboxConfig) (*CodexSandbox, err |
| } |
| info, err := os.Stat(goRoot) |
| if err != nil || !info.IsDir() { |
| - return nil, provider.ErrContract |
| + return nil, fmt.Errorf("%w: Go root %q is not a directory (stat: %v)", provider.ErrContract, goRoot, err) |
| } |
| goBinary, err := filepath.EvalSymlinks(cfg.GoBinary) |
| if err != nil || goBinary != filepath.Join(goRoot, "bin/go") { |
| - return nil, provider.ErrContract |
| + return nil, fmt.Errorf("%w: Go binary %q resolves to %q, want %q (resolve: %v)", provider.ErrContract, cfg.GoBinary, goBinary, filepath.Join(goRoot, "bin/go"), err) |
| } |
| probe, err := os.MkdirTemp(cfg.ScratchRoot, "go-probe-") |
| if err != nil { |
| @@ -93,7 +94,7 @@ func NewCodexSandbox(ctx context.Context, cfg SandboxConfig) (*CodexSandbox, err |
| cmd.Env = []string{"PATH=/usr/bin:/bin", "GOROOT=" + goRoot, "GOTOOLCHAIN=local", "GOENV=off", "GOTELEMETRY=off", "XDG_CONFIG_HOME=" + xdg} |
| b, err = cmd.Output() |
| if err != nil || strings.TrimSpace(string(b)) != "go version "+GoVersion+" "+runtime.GOOS+"/"+runtime.GOARCH { |
| - return nil, provider.ErrContract |
| + return nil, fmt.Errorf("%w: Go binary %q with GOROOT %q returned %q, want %q (probe: %v)", provider.ErrContract, goBinary, goRoot, strings.TrimSpace(string(b)), "go version "+GoVersion+" "+runtime.GOOS+"/"+runtime.GOARCH, err) |
| } |
| return &CodexSandbox{direct: cfg, binary: binary, version: CodexVersion, scratch: cfg.ScratchRoot, home: home, protected: paths, goRoot: goRoot, goBinary: goBinary, goVersion: GoVersion}, nil |
| } |
diff --git a/internal/runner/checks/sandbox_test.go b/internal/runner/checks/sandbox_test.go| index b783be19..4826dbde 100644 |
| --- a/internal/runner/checks/sandbox_test.go |
| +++ b/internal/runner/checks/sandbox_test.go |
| @@ -3,6 +3,7 @@ package checks |
| import ( |
| "bytes" |
| "context" |
| + "errors" |
| "os" |
| "os/exec" |
| "path/filepath" |
| @@ -131,11 +132,12 @@ func TestCheckSandboxDeniedPathsRequired(t *testing.T) { |
| func testSandboxConfig(t *testing.T, binary, root string) SandboxConfig { |
| t.Helper() |
| - goBinary, err := exec.LookPath("go") |
| + goCommand := exec.Command("go", "env", "GOROOT") |
| + goCommand.Env = append(os.Environ(), "GOROOT=", "GOTOOLCHAIN="+GoVersion) |
| + goOutput, err := goCommand.Output() |
| must(t, err) |
| - goBinary, err = filepath.EvalSymlinks(goBinary) |
| - must(t, err) |
| - goRoot := filepath.Dir(filepath.Dir(goBinary)) |
| + goRoot := strings.TrimSpace(string(goOutput)) |
| + goBinary := filepath.Join(goRoot, "bin/go") |
| p := func(s string) string { return filepath.Join(root, s) } |
| return SandboxConfig{Binary: binary, ScratchRoot: root, GoRoot: goRoot, GoBinary: goBinary, Protected: workspace.SecurityPaths{RunnerState: p("state"), RunnerConfig: p("config"), Journal: p("journal"), Bearer: p("bearer"), Cleanup: p("cleanup"), ForgeCredential: p("amadan"), LegacyHome: p("paseo"), SSH: p("ssh"), ProviderHomes: []string{p("codex"), p("claude"), p("alias")}}} |
| } |
| @@ -234,3 +236,18 @@ func TestCheckSandboxToolchain(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +func TestCheckSandboxToolchainDiagnostic(t *testing.T) { |
| + root := t.TempDir() |
| + binary, err := exec.LookPath("codex") |
| + must(t, err) |
| + cfg := testSandboxConfig(t, binary, root) |
| + cfg.GoRoot = filepath.Join(root, "wrong-go") |
| + cfg.GoBinary = filepath.Join(cfg.GoRoot, "bin/go") |
| + put(t, cfg.GoRoot, "bin/go", "#!/bin/sh\necho 'go version go1.1 linux/amd64'\n") |
| + must(t, os.Chmod(cfg.GoBinary, 0700)) |
| + _, err = NewCodexSandbox(context.Background(), cfg) |
| + if !errors.Is(err, provider.ErrContract) || !strings.Contains(err.Error(), cfg.GoBinary) || !strings.Contains(err.Error(), "go1.1") || !strings.Contains(err.Error(), GoVersion) { |
| + t.Fatalf("toolchain rejection lacks path, observed version or required version: %v", err) |
| + } |
| +} |
diff --git a/internal/runner/direct_graph_test.go b/internal/runner/direct_graph_test.go| index 659b93cb..0844bfb5 100644 |
| --- a/internal/runner/direct_graph_test.go |
| +++ b/internal/runner/direct_graph_test.go |
| @@ -64,11 +64,11 @@ func runDirectBugGraph(t *testing.T) { |
| protected := workspace.SecurityPaths{RunnerState: state, RunnerConfig: filepath.Join(state, "config"), Journal: filepath.Join(state, "j.db"), Bearer: filepath.Join(state, "bearer"), Cleanup: filepath.Join(state, "cleanup"), ForgeCredential: filepath.Join(state, "forge"), LegacyHome: filepath.Join(state, "paseo"), ProviderHomes: []string{filepath.Join(state, "provider")}, SSH: filepath.Join(state, "ssh")} |
| codex, err := exec.LookPath("codex") |
| wfMust(t, err) |
| - goBinary, err := exec.LookPath("go") |
| + goCommand := exec.Command("go", "env", "GOROOT") |
| + goCommand.Env = append(os.Environ(), "GOROOT=", "GOTOOLCHAIN="+checks.GoVersion) |
| + goOutput, err := goCommand.Output() |
| wfMust(t, err) |
| - goBinary, err = filepath.EvalSymlinks(goBinary) |
| - wfMust(t, err) |
| - goRoot := filepath.Dir(filepath.Dir(goBinary)) |
| + goRoot := strings.TrimSpace(string(goOutput)) |
| wfMust(t, os.Mkdir(filepath.Join(root, "modules"), 0700)) |
| sandbox, err := checks.NewCodexSandbox(ctx, checks.SandboxConfig{Binary: codex, ScratchRoot: scratch, GoRoot: goRoot, GoBinary: filepath.Join(goRoot, "bin/go"), Protected: protected, Host: host, Bwrap: "/usr/bin/bwrap", RunnerBinary: helper, ModuleCache: filepath.Join(root, "modules")}) |
| wfMust(t, err) |
diff --git a/internal/runner/provider/check_policy.go b/internal/runner/provider/check_policy.go| index 2b5a7450..18f09d5a 100644 |
| --- a/internal/runner/provider/check_policy.go |
| +++ b/internal/runner/provider/check_policy.go |
| @@ -2,6 +2,7 @@ package provider |
| import ( |
| "encoding/json" |
| + "fmt" |
| "os" |
| "path/filepath" |
| "reflect" |
| @@ -26,11 +27,11 @@ func BuildCheckPolicy(in CheckPolicyInputs) (Policy, error) { |
| m := effectiveManifest{Version: checkPolicyVersion, Workspace: in.Workspace, Argv: in.Argv, Env: in.Env, NamespaceArgs: NamespaceArguments()} |
| for _, path := range []string{in.Workspace, in.GoRoot, in.ModuleCache} { |
| if path == "/" || withinPath(home, path) { |
| - return Policy{}, ErrPolicy |
| + return Policy{}, fmt.Errorf("%w: check directory %q includes the host home", ErrPolicy, path) |
| } |
| f, err := pinDirectory(path) |
| if err != nil { |
| - return Policy{}, err |
| + return Policy{}, fmt.Errorf("%w: check directory %q must be a canonical directory without symlinks", err, path) |
| } |
| f.Close() |
| } |