| 1 | //go:build testbuild |
| 2 | |
| 3 | package thin |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "os" |
| 8 | "path/filepath" |
| 9 | "testing" |
| 10 | |
| 11 | "amadan.net/oficina/equipo/internal/runner" |
| 12 | "amadan.net/oficina/equipo/internal/runner/mac" |
| 13 | "amadan.net/oficina/equipo/internal/wire" |
| 14 | ) |
| 15 | |
| 16 | // Whole-branch fix 1, #2: the scanner passes, but its user-temp cleanup |
| 17 | // fails: the scan's end is not proven, so the attempt is unterminated |
| 18 | // and nothing is uploaded. The cleanup stays pending for the scan's own |
| 19 | // proof. |
| 20 | func TestWorkerEngineeringScanCleanupFailed(t *testing.T) { |
| 21 | x := newEngRig(t) |
| 22 | x.note("edit:Swipe.swift|false|true") |
| 23 | runnerPath := previewScannerFixture(t) |
| 24 | binary, pin := previewScannerTool(runner.Config{Executable: runnerPath}) |
| 25 | temp := filepath.Join(t.TempDir(), "T") |
| 26 | if err := os.Mkdir(temp, 0o700); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | t.Cleanup(func() { _ = os.Chmod(temp, 0o700) }) |
| 30 | g := &mac.Gate{Env: []string{"PATH=/usr/bin:/bin"}, ScratchHome: true, Lines: 10, Sandbox: wire.SandboxSeatbelt, UserTemp: temp, Turns: x.m.turns, |
| 31 | QuietSimulators: func(context.Context) { _ = os.Chmod(temp, 0) }} |
| 32 | var scan string |
| 33 | x.w.Eng.Leaks = func(ctx context.Context, stage, marker string, record func(string) error) (bool, error) { |
| 34 | return gateLeaks(ctx, g, binary, pin, stage, marker, func(id string) error { scan = id; return record(id) }) |
| 35 | } |
| 36 | rep := x.run(t) |
| 37 | if rep.State != wire.StepFailed || rep.Reason != wire.ReasonSecretInCandidate || rep.Termination || rep.CandidateSHA != "" { |
| 38 | t.Fatalf("report %+v", rep) |
| 39 | } |
| 40 | if c := x.committed(); c.CandidateSHA != "" { |
| 41 | t.Fatalf("committed %+v", c) |
| 42 | } |
| 43 | for _, f := range x.outbox(t) { |
| 44 | if f.Type == wire.FrameBlob { |
| 45 | t.Fatalf("uploaded %s", f.ID) |
| 46 | } |
| 47 | } |
| 48 | if !x.m.turns.Pending() { |
| 49 | t.Fatal("the scan's cleanup is not pending") |
| 50 | } |
| 51 | g.QuietSimulators = nil |
| 52 | if err := os.Chmod(temp, 0o700); err != nil { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | if !g.Verify(scan) || x.m.turns.Pending() { |
| 56 | t.Fatal("the scan's proof did not finish its cleanup") |
| 57 | } |
| 58 | } |
| 59 | |