| 1 | package checks |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "context" |
| 6 | "os" |
| 7 | "os/exec" |
| 8 | "path/filepath" |
| 9 | "testing" |
| 10 | |
| 11 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 12 | "amadan.net/oficina/equipo/internal/testci" |
| 13 | ) |
| 14 | |
| 15 | func TestSandboxDisablesDetachedHelpers(t *testing.T) { |
| 16 | root := t.TempDir() |
| 17 | work := filepath.Join(root, "work") |
| 18 | must(t, os.Mkdir(work, 0700)) |
| 19 | testci.Tools(t, "codex", "bwrap", "python3", "sh") |
| 20 | binary, err := exec.LookPath("codex") |
| 21 | must(t, err) |
| 22 | s, err := NewCodexSandbox(context.Background(), testSandboxConfig(t, binary, root)) |
| 23 | must(t, err) |
| 24 | policy := provider.ReadPolicy{ConfigHash: "policy", DeniedPaths: []string{filepath.Join(root, "secret")}} |
| 25 | for _, tc := range []struct{ name, script string }{ |
| 26 | {"telemetry", `test "$GOTELEMETRY" = off && test "$(go env GOTELEMETRY)" = off`}, |
| 27 | {"maintenance", `test "$(git config --get maintenance.auto)" = false`}, |
| 28 | {"gc", `test "$(git config --get gc.autoDetach)" = false`}, |
| 29 | } { |
| 30 | t.Run(tc.name, func(t *testing.T) { |
| 31 | var out, stderr bytes.Buffer |
| 32 | code, err := s.Run(context.Background(), Command{Argv: []string{"/bin/sh", "-c", tc.script}, Dir: ".", TimeoutSeconds: 10}, work, policy, &out, &stderr) |
| 33 | must(t, err) |
| 34 | if code != 0 { |
| 35 | t.Fatalf("detached helper guard missing: code=%d out=%s err=%s", code, &out, &stderr) |
| 36 | } |
| 37 | }) |
| 38 | } |
| 39 | } |
| 40 | |