| 1 | package checks |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "slices" |
| 6 | "testing" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/equipo/team" |
| 9 | ) |
| 10 | |
| 11 | func TestTrustedExitInterpreterRefused(t *testing.T) { |
| 12 | f := newFixture(t) |
| 13 | for _, program := range []string{"python", "python3", "node"} { |
| 14 | for _, prefix := range []string{"", "/bin/", "/usr/bin/"} { |
| 15 | t.Run(prefix+program, func(t *testing.T) { |
| 16 | d := f.d |
| 17 | d.TrustedPaths = []string{"gate.py", "gate.js"} |
| 18 | script := "gate.py" |
| 19 | if program == "node" { |
| 20 | script = "gate.js" |
| 21 | } |
| 22 | d.Commands = append(slices.Clone(d.Commands), Command{Argv: []string{prefix + program, script}, Dir: ".", Parser: "exit", TimeoutSeconds: 10}) |
| 23 | if _, err := ParseDefinition(context.Background(), raw(d), repoID, baseID); err == nil { |
| 24 | t.Fatal("interpreter gate accepted with declared entrypoint") |
| 25 | } |
| 26 | }) |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func TestTrustedExitGoSpelling(t *testing.T) { |
| 32 | f := newFixture(t) |
| 33 | for _, program := range []string{"go", "/bin/go", "/usr/bin/go"} { |
| 34 | t.Run(program, func(t *testing.T) { |
| 35 | d := f.d |
| 36 | d.Commands = append(slices.Clone(d.Commands), Command{Argv: []string{program, "vet"}, Dir: ".", Parser: "exit", TimeoutSeconds: 10}) |
| 37 | _, err := ParseDefinition(context.Background(), raw(d), repoID, baseID) |
| 38 | if program == "go" { |
| 39 | must(t, err) |
| 40 | } else if err == nil { |
| 41 | t.Fatal("absolute Go spelling bypasses pinned toolchain") |
| 42 | } |
| 43 | }) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | func TestExecutorIsolationDuplicates(t *testing.T) { |
| 48 | for _, kind := range []string{"acknowledgements", "tuples"} { |
| 49 | t.Run(kind, func(t *testing.T) { |
| 50 | f := newFixture(t) |
| 51 | iso := team.IsolationSnapshot{Status: "unconfined", RunnerTainted: true, AcknowledgementIDs: []string{"z", "a"}, ObservedTuples: []team.IsolationTuple{{Provider: "codex"}, {Provider: "claude"}}} |
| 52 | f.e.cfg.Isolation = func(context.Context) (team.IsolationSnapshot, error) { return iso, nil } |
| 53 | result, err := f.e.Reproduce(context.Background(), f.d, f.r, baseID, "") |
| 54 | must(t, err) |
| 55 | if kind == "acknowledgements" { |
| 56 | iso.AcknowledgementIDs = append(iso.AcknowledgementIDs, "z", "a") |
| 57 | } else { |
| 58 | iso.ObservedTuples = append(iso.ObservedTuples, iso.ObservedTuples...) |
| 59 | } |
| 60 | before := raw(iso) |
| 61 | _, err = f.e.ValidateEvidence(context.Background(), nil, f.e.cfg.Scope, f.e.cfg.Handle, team.ArtifactSpec{Role: team.RoleBaseResult, Payload: raw(result)}) |
| 62 | if err != nil { |
| 63 | t.Fatalf("duplicate %s invalidated unchanged evidence: %v", kind, err) |
| 64 | } |
| 65 | if string(raw(iso)) != string(before) { |
| 66 | t.Fatal("canonicalization changed callback snapshot") |
| 67 | } |
| 68 | if len(f.e.exposure.AcknowledgementIDs) != 2 || len(f.e.exposure.ObservedTuples) != 2 { |
| 69 | t.Fatal("duplicate isolation retained in historical exposure") |
| 70 | } |
| 71 | }) |
| 72 | } |
| 73 | } |
| 74 | |