//go:build testbuild package thin import ( "context" "os" "path/filepath" "testing" "amadan.net/oficina/equipo/internal/runner" "amadan.net/oficina/equipo/internal/runner/mac" "amadan.net/oficina/equipo/internal/wire" ) // Whole-branch fix 1, #2: the scanner passes, but its user-temp cleanup // fails: the scan's end is not proven, so the attempt is unterminated // and nothing is uploaded. The cleanup stays pending for the scan's own // proof. func TestWorkerEngineeringScanCleanupFailed(t *testing.T) { x := newEngRig(t) x.note("edit:Swipe.swift|false|true") runnerPath := previewScannerFixture(t) binary, pin := previewScannerTool(runner.Config{Executable: runnerPath}) temp := filepath.Join(t.TempDir(), "T") if err := os.Mkdir(temp, 0o700); err != nil { t.Fatal(err) } t.Cleanup(func() { _ = os.Chmod(temp, 0o700) }) g := &mac.Gate{Env: []string{"PATH=/usr/bin:/bin"}, ScratchHome: true, Lines: 10, Sandbox: wire.SandboxSeatbelt, UserTemp: temp, Turns: x.m.turns, QuietSimulators: func(context.Context) { _ = os.Chmod(temp, 0) }} var scan string x.w.Eng.Leaks = func(ctx context.Context, stage, marker string, record func(string) error) (bool, error) { return gateLeaks(ctx, g, binary, pin, stage, marker, func(id string) error { scan = id; return record(id) }) } rep := x.run(t) if rep.State != wire.StepFailed || rep.Reason != wire.ReasonSecretInCandidate || rep.Termination || rep.CandidateSHA != "" { t.Fatalf("report %+v", rep) } if c := x.committed(); c.CandidateSHA != "" { t.Fatalf("committed %+v", c) } for _, f := range x.outbox(t) { if f.Type == wire.FrameBlob { t.Fatalf("uploaded %s", f.ID) } } if !x.m.turns.Pending() { t.Fatal("the scan's cleanup is not pending") } g.QuietSimulators = nil if err := os.Chmod(temp, 0o700); err != nil { t.Fatal(err) } if !g.Verify(scan) || x.m.turns.Pending() { t.Fatal("the scan's proof did not finish its cleanup") } }