oficina / equipo Public

runner: Task 17 review 2, keep cancels before diagnostics, bound proof

A certified run cancelled during its base gate ends cancelled with its
proof: no diagnostic is prepared or launched, and a preparation cut short
by the cancel stays a cancel. A start error's exit proof is bounded by
the step context and 10 s; unproven, the run is unterminated and its
record stays for recovery.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev cbf27a2ffc8d8d94c76e8e615ff4610163b75274 parent 7432ab3
7 files changed, +258 −7
  • .rastrillo/budgets.txt +1 −1
  • docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md +34 −0
  • internal/runner/checkrun/run.go +7 −3
  • internal/runner/checkrun/run_test.go +50 −0
  • internal/runner/linuxworker/gate.go +16 −3
  • internal/runner/linuxworker/worker_test.go +92 −0
  • internal/runner/thin/primary_checks_test.go +58 −0

CI failed — run details

CI log
=== prepare ===
ci-box: machine: aarch64, 32 CPUs, 62 GiB memory, kernel 7.0.0-1017-aws
ci-box: python 3.12.3; Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2
ci-box: user namespaces allowed: 233151
ci-box: cgroup: cgroup2fs
ci-box: disk /home/ci/work/repos/oficina__equipo/wt/hosted-runners-2: Type  Size Avail | ext4   96G   84G
ci-box: disk /home/ci/.cache/equipo-ci-box: Type  Size Avail | ext4   96G   84G
ci-box: bwrap: fetched and verified in 0.3s
ci-box: claude: fetched and verified in 2.0s
ci-box: codex: fetched and verified in 4.4s
ci-box: codex-code-mode-host: fetched and verified in 1.7s
ci-box: libwrap: fetched and verified in 0.3s
ci-box: socat: fetched and verified in 0.3s
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
ci-box: image pulled in 9.9s
ci-box: pi: installed and verified in 7.3s
ci-box: opencode: installed and verified in 2.4s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 8.6s
ci-box: clone deepened in 5.4s
ci-box: file times set from content: 3882 files, 271 directories
ci-box: ready in 20.0s
=== copy ===
EQUIPO_RELEASE_COPY_CHECK=1 CGO_ENABLED=0 go test ./internal/equipotest -run '^TestReleaseCopyReviewed$' -count=1
--- FAIL: TestReleaseCopyReviewed (0.09s)
    task_pages_test.go:236: COPY REVIEW REQUIRED: copy-status.py verify found copy pending review or stale bookkeeping
FAIL
rastrillo-budget/v1 ran 87ms
FAIL	amadan.net/oficina/equipo/internal/equipotest	0.236s
FAIL
make: *** [Makefile:273: copy-release-check] Error 1

amadan: step copy failed: exit status 2

amadan: job failed at step copy — its output is above, not at the tail of this log
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index dbe0d351..5de6f2ce 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -40,7 +40,7 @@ perf GET /releases/* skip Verified runner release file downloads, not browser GE
perf GET /install.sh skip Mac runners: the one-line bootstrap a terminal pipes to sh, not a browser screen.
time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s;
time internal/runner/linuxworker 30s Hosted slice 2 Task 17: each test starts real bubblewrap namespaces through the containment manager over real git stores (base gates, pins, restart and cancel proof, offline, staged cache, six dependency outcomes); measured 11.6 to 14.5s on a loaded docs-t1; review round 1 tests: 15 to 23s under load.
-size internal/runner/thin 36076 35824 Protocols 31-35, merge credential, publication guards, kept work, scans, 36 lookups; Mac pin, Engineering, asks, F probes, D1, P2, held reports; 38 Design step, renderer; hosted slice 2 Task 11 moved the base-gate checks to checkrun (source down) and pinned the primary and Mac behaviour with tests (test up), and its round 1 fixes added the worker step-engine wiring test; Task 12 added Link.TokenSource and Link.HTTPClient (a hosted runner's bearer is read at each dial and its dial goes through the proxy) and their two tests; 35831/35453. Task 14 review round 1 added Link.ReconnectWait (the wait between connections, a fake clock's in the hosted renewal tests, which drive the real Link through certificate rotation and bearer renewal); 35839/35453. Task 15: the hosted pack (inboundHeader selects by attempt and kind, Worker.Hosted indexes the base and the candidate into an empty store, pack_incomplete) and hosted_pack_test.go; 35863/35688. Task 17 wiring for the Linux checks worker (hosted_worker.go): Options.Hosted (HostedLink: the session's in-memory credential, proxy client, Work context, Flush on a failed renewal and token_renewal_failed), WorkerKind.Checks and Probe, runHosted, the Linux worker refusal outside hosted-run, the hand-off of an indexed hosted attempt and its deps bundle to the kind's checks, the receiver's per-kind transfer limits; its two tests; 36073/35768. Review round 1: the deps header checked before the wait, and TestDepsPackPerKindLimits (the receiver past the old 64 MiB and chunk limits); 36076/35824.
+size internal/runner/thin 36076 35882 Protocols 31-35, merge credential, publication guards, kept work, scans, 36 lookups; Mac pin, Engineering, asks, F probes, D1, P2, held reports; 38 Design step, renderer; hosted slice 2 Task 11 moved the base-gate checks to checkrun (source down) and pinned the primary and Mac behaviour with tests (test up), and its round 1 fixes added the worker step-engine wiring test; Task 12 added Link.TokenSource and Link.HTTPClient (a hosted runner's bearer is read at each dial and its dial goes through the proxy) and their two tests; 35831/35453. Task 14 review round 1 added Link.ReconnectWait (the wait between connections, a fake clock's in the hosted renewal tests, which drive the real Link through certificate rotation and bearer renewal); 35839/35453. Task 15: the hosted pack (inboundHeader selects by attempt and kind, Worker.Hosted indexes the base and the candidate into an empty store, pack_incomplete) and hosted_pack_test.go; 35863/35688. Task 17 wiring for the Linux checks worker (hosted_worker.go): Options.Hosted (HostedLink: the session's in-memory credential, proxy client, Work context, Flush on a failed renewal and token_renewal_failed), WorkerKind.Checks and Probe, runHosted, the Linux worker refusal outside hosted-run, the hand-off of an indexed hosted attempt and its deps bundle to the kind's checks, the receiver's per-kind transfer limits; its two tests; 36073/35768. Review round 1: the deps header checked before the wait, and TestDepsPackPerKindLimits (the receiver past the old 64 MiB and chunk limits); 36076/35824. Review round 2: TestPrimaryChecksCancelledChangedGate (a certified changed-gate run cancelled in its base run ends cancelled, no diagnostic); 36076/35882.
time internal/thintest 240s Thin contract and page tests, the Assistant's and the models' included, share one harness. Measured 202s on a shared 16 CPU box (2026-11-13); CI runs two lanes.
time internal/runner/mac 45s Real processes killed and proven gone: groups, sessions, the runner-user sweep, turns, restarts; probes end to end. Measured 29.3s locally.
time internal/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s).
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
index e9aed4ec..d658e6b2 100644
--- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
@@ -1337,3 +1337,37 @@ Mutations (scripted exact-string replace under `$TMPDIR`, one at a time, the fil
- **218** a diagnostic that cannot be prepared reports the base run (no reset). In `internal/runner/checkrun/run.go`, `out.BaseChecks, out.BaseChecksSHA = "", ""` became `_ = 0` (sed). `CGO_ENABLED=0 go test ./internal/runner/checkrun -run TestChecksRunDiagnosticUnavailable -count=1`: exit 1, `run_test.go:283: outcome {Checks:cannot_run BaseChecks:passed Reason:checks_unavailable ... BaseChecksSHA:0a3c108f... }`. Restored (`cp`, `cmp` identical).
One guard was merged. Mutations taken first on two separate guards (the diagnostic's preparation, and its launch) showed that the launch guard alone survived: with the tree never prepared, nothing launches. Preparation and launch are now one block under one guard, and mutations 212 and 213 remove that guard.
+
+### Task 17 review round 2 (t17-r2.md: two regressions from round 1 fixed)
+
+1. **Cancellation before the diagnostic.** `checkrun.Run` prepares and launches a diagnostic only while the run is not cancelled: the guard is now `certified && changedGate && res.Terminated && ctx.Err() == nil`. A cancel during the base run falls to the tail, which reports `StepCancelled` `cancelled`, terminated, with the base run's proof. If preparing the diagnostic fails because the run was cancelled meanwhile, it also ends `StepCancelled`, never done/`checks_unavailable`. This is shared code. The primary now reports cancelled again in this case, as it did before round 1, when the diagnostic was prepared before the base run.
+2. **Bounded startup proof.** On a start error after a namespace record, `bwrapGate.Run` proves the exit with `verify(ctx', id)`. Here `ctx'` is the step context bounded by `startProofWait` (10 s). Proof not reached in time is no proof: `Terminated: false`, and the record stays. `Verify(id)` (recovery) keeps its unbounded background context.
+
+Red, before the fixes:
+- `go test ./internal/runner/checkrun -run TestChecksRunCancelledBeforeDiagnostic -count=1`: `run_test.go:324: cancelled in the base run: {Checks:cannot_run ... Reason:checks_unavailable ... State:done Terminated:true ...}, 1 runs, 1 diagnostics prepared`.
+- `go test ./internal/runner/thin -run TestPrimaryChecksCancelledChangedGate -count=1`: `primary_checks_test.go:253: report {... State:done Reason:checks_unavailable ...}`.
+- `go test ./internal/runner/linuxworker -run 'TestHostedStartErrorProofBounded|TestHostedCancelChangedGate' -count=1`:
+ - `worker_test.go:992: the run waited for its own runner to exit` (after 10 s)
+ - `worker_test.go:1020: cancelled report {... State:done Reason:checks_unavailable ...}`
+
+Tests:
+- `TestChecksRunCancelledBeforeDiagnostic` (checkrun): a cancel in the base run, and a cancel during the diagnostic's preparation.
+- `TestPrimaryChecksCancelledChangedGate` (thin, real bubblewrap): cancelled, terminated, and one launch, counted by `launchRecorder`.
+- `TestHostedCancelChangedGate` (linuxworker): cancelled, namespace proof, one launch counted at `start`, and the base sandbox's PID gone.
+- `TestHostedStartErrorProofBounded` (linuxworker): an intent record whose parent is this test process (its PID and start ticks), with no exit-proof file. It returns within the 300 ms test bound, unterminated, with the record kept.
+
+Green:
+- `CGO_ENABLED=0 go test ./internal/runner/checkrun -count=1`: ok.
+- `go test ./internal/runner/linuxworker -count=1`: ok (16.4 s).
+- `go test ./internal/runner/thin -run 'TestPrimaryChecks|TestHosted|TestDepsPack|TestCandidateGate|TestBaseGate|TestLinuxWorker' -count=1`: ok (42.4 s).
+- `make budget build vet`: exit 0 (thin test record 35882, with the reason). gofmt and `git diff --check`: clean.
+- containment is untouched, so the namespace lane was not rerun.
+
+Mutations (scripted, one at a time, restored from a copy and `cmp`-checked):
+- **219** a cancelled base run goes on to the diagnostic (no cancel guard). In `internal/runner/checkrun/run.go`, `if certified && changedGate && res.Terminated && ctx.Err() == nil {` became `if certified && changedGate && res.Terminated {`. `CGO_ENABLED=0 go test ./internal/runner/checkrun -run TestChecksRunCancelledBeforeDiagnostic -count=1`: exit 1, `run_test.go:324: cancelled in the base run: {Checks: BaseChecks:cannot_run Reason:cancelled Output: BaseChecksSHA: Sandbox: Evidence:<nil> State:cancelled Terminated:true Gate: LogTail: ExitCode:<nil>`. Restored (`cp`, `cmp` identical).
+- **222** a preparation cut short by a cancel ends done, not cancelled. In `internal/runner/checkrun/run.go`, `err != nil && ctx.Err() != nil {` became `err != nil && false {`. `CGO_ENABLED=0 go test ./internal/runner/checkrun -run TestChecksRunCancelledBeforeDiagnostic -count=1`: exit 1, `run_test.go:333: cancelled while preparing the diagnostic: {Checks:cannot_run BaseChecks: Reason:checks_unavailable Output: BaseChecksSHA: Sandbox: Evidence:<nil> State:done Terminated:true Gate: LogT`. Restored (`cp`, `cmp` identical).
+- **223** a start error's proof is not bounded. In `internal/runner/linuxworker/gate.go`, `vctx, cancel := context.WithTimeout(ctx, startProofWait)` became `vctx, cancel := context.WithCancel(context.Background())`. `CGO_ENABLED=0 go test ./internal/runner/linuxworker -run TestHostedStartErrorProofBounded -count=1`: exit 1, `worker_test.go:992: the run waited for its own runner to exit`. Restored (`cp`, `cmp` identical).
+- **220** both cancel guards removed (the `ctx.Err() == nil` in the diagnostic guard, and the cancelled branch on a failed preparation, as `err != nil && false`). `CGO_ENABLED=0 go test ./internal/runner/thin -run TestPrimaryChecksCancelledChangedGate -count=1`: exit 1, `primary_checks_test.go:253: report {... State:done Reason:checks_unavailable ...}`. Restored (`cp`, `cmp` identical).
+- **221** the same two removals. `CGO_ENABLED=0 go test ./internal/runner/linuxworker -run TestHostedCancelChangedGate -count=1`: exit 1, `worker_test.go:1020: cancelled report {... State:done Reason:checks_unavailable ...}`. Restored (`cp`, `cmp` identical).
+
+Each guard alone is redundant end to end: a real checkout fails on a cancelled context, and that failure is now kept as a cancel. So removing the first guard alone left the primary and hosted tests passing; they fail only with both removed (220, 221). checkrun's own test (219, 222) catches each guard separately.
diff --git a/internal/runner/checkrun/run.go b/internal/runner/checkrun/run.go
index 1550c536..c3f3df38 100644
--- a/internal/runner/checkrun/run.go
+++ b/internal/runner/checkrun/run.go
@@ -178,10 +178,14 @@ func Run(ctx context.Context, g gate.Runner, repo checks.Repo, in Inputs) Outcom
// A base run whose end is not proven stops everything after it: no
// diagnostic is prepared or launched, since its namespace would
// replace the base run's record and recovery would then prove the
- // wrong one. The tail below fails the run, unterminated.
- if certified && changedGate && res.Terminated {
+ // wrong one. Nor does a cancelled run go on. The tail below ends both
+ // (failed unterminated, or cancelled with its proof).
+ if certified && changedGate && res.Terminated && ctx.Err() == nil {
if in.Diagnostic != nil {
- if diagnostic, err = in.Diagnostic(ctx); err != nil {
+ if diagnostic, err = in.Diagnostic(ctx); err != nil && ctx.Err() != nil {
+ out.State, out.Reason, out.Terminated = wire.StepCancelled, "cancelled", true
+ return out
+ } else if err != nil {
// As when this was decided before any run: nothing of the
// base run is reported.
out.BaseChecks, out.BaseChecksSHA = "", ""
diff --git a/internal/runner/checkrun/run_test.go b/internal/runner/checkrun/run_test.go
index 59959eff..63bf64a3 100644
--- a/internal/runner/checkrun/run_test.go
+++ b/internal/runner/checkrun/run_test.go
@@ -283,3 +283,53 @@ func TestChecksRunDiagnosticUnavailable(t *testing.T) {
t.Fatalf("outcome %+v", out)
}
}
+
+// cancellingGate's base run is cancelled while it runs, and ends proven.
+type cancellingGate struct {
+ execGate
+ cancel context.CancelFunc
+}
+
+func (g *cancellingGate) Run(ctx context.Context, attempt, dir string, argv []string, _ time.Duration, record func(string) error) gate.Result {
+ id := fmt.Sprintf("ns-%d", len(g.runs)+1)
+ g.runs = append(g.runs, execRun{argv: argv, dir: dir, attempt: attempt, recorded: id})
+ if err := record(id); err != nil {
+ return gate.Result{Reason: "checks_unavailable", Terminated: true}
+ }
+ g.cancel()
+ return gate.Result{Reason: "cancelled", Code: -1, Terminated: true, Sandbox: wire.SandboxBubblewrap}
+}
+
+// TestChecksRunCancelledBeforeDiagnostic (Task 17 review 2, finding 1):
+// a certified run whose candidate changed a gate file, cancelled during
+// the base run, ends cancelled with its proof: no diagnostic is prepared
+// or launched; and one cancelled while its diagnostic tree is prepared
+// ends cancelled too, never done.
+func TestChecksRunCancelledBeforeDiagnostic(t *testing.T) {
+ files := map[string]string{".equipo/gates.json": contract, "Makefile": budgetGate, "size.txt": "1\n", "budgets.txt": "1\n"}
+ r, tree, base, candidate := repo(t, files, map[string]string{"Makefile": "ci:\n\ttrue\n"})
+ ctx, cancel := context.WithCancel(context.Background())
+ g := &cancellingGate{cancel: cancel}
+ diagnostics := 0
+ in := Inputs{Workspace: tree, BaseSHA: base, CandidateSHA: candidate, Attempt: "checks/k", Record: func(string) error { return nil },
+ Diagnostic: func(ctx context.Context) (string, error) {
+ diagnostics++
+ if ctx.Err() != nil {
+ return "", ctx.Err()
+ }
+ return filepath.Join(t.TempDir(), "diagnostic"), nil
+ }}
+ out := Run(ctx, g, r, in)
+ if out.State != wire.StepCancelled || !out.Terminated || out.Reason != "cancelled" || len(g.runs) != 1 || diagnostics != 0 {
+ t.Fatalf("cancelled in the base run: %+v, %d runs, %d diagnostics prepared", out, len(g.runs), diagnostics)
+ }
+ r, tree, base, candidate = repo(t, files, map[string]string{"Makefile": "ci:\n\ttrue\n"})
+ ctx, cancel = context.WithCancel(context.Background())
+ eg := &execGate{}
+ in.Workspace, in.BaseSHA, in.CandidateSHA = tree, base, candidate
+ in.Diagnostic = func(context.Context) (string, error) { cancel(); return "", context.Canceled }
+ out = Run(ctx, eg, r, in)
+ if out.State != wire.StepCancelled || !out.Terminated || out.Reason != "cancelled" || len(eg.runs) != 1 {
+ t.Fatalf("cancelled while preparing the diagnostic: %+v, %d runs", out, len(eg.runs))
+ }
+}
diff --git a/internal/runner/linuxworker/gate.go b/internal/runner/linuxworker/gate.go
index 4f18329e..ff5bc808 100644
--- a/internal/runner/linuxworker/gate.go
+++ b/internal/runner/linuxworker/gate.go
@@ -53,6 +53,10 @@ func CertificationPolicy(work, runnerBinary, goRoot string, argv []string) (prov
return Policy(SandboxInputs{Workspace: work, RunnerBinary: runnerBinary, GoRoot: goRoot, Argv: argv})
}
+// startProofWait bounds establishing the exit of a namespace whose start
+// failed (tests shorten it).
+var startProofWait = 10 * time.Second
+
// defaultLimit bounds a gate run given none.
const defaultLimit = 20 * time.Minute
@@ -132,7 +136,13 @@ func (g *bwrapGate) Run(ctx context.Context, attempt, dir string, argv []string,
// its end must be established (containment's exit proof) before
// the run counts as ended; otherwise its record stays for
// recovery.
- unavailable.Terminated = recorded == "" || g.Verify(recorded)
+ if recorded != "" {
+ // Bounded: recovery of an intent whose parent is this runner
+ // waits for the runner itself; unproven, the record stays.
+ vctx, cancel := context.WithTimeout(ctx, startProofWait)
+ unavailable.Terminated = g.verify(vctx, recorded)
+ cancel()
+ }
return unavailable
}
out := &lineTail{max: wire.MaxChecksLines}
@@ -212,11 +222,14 @@ func (g *bwrapGate) forget(id string) {
// sure: its record is gone (released only after proof), or recovery
// proves it ended now, killing it if it had not. "" is an attempt that
// recorded no namespace: proven only once none of this runner's remains.
-func (g *bwrapGate) Verify(id string) bool {
+func (g *bwrapGate) Verify(id string) bool { return g.verify(context.Background(), id) }
+
+// verify is Verify within ctx: a proof not reached before ctx ends is no
+// proof.
+func (g *bwrapGate) verify(ctx context.Context, id string) bool {
if g.m == nil {
return false
}
- ctx := context.Background()
records, err := g.m.Records(ctx)
if err != nil {
return false
diff --git a/internal/runner/linuxworker/worker_test.go b/internal/runner/linuxworker/worker_test.go
index acf58a76..d112ff88 100644
--- a/internal/runner/linuxworker/worker_test.go
+++ b/internal/runner/linuxworker/worker_test.go
@@ -934,3 +934,95 @@ func TestHostedUnprovenBaseStops(t *testing.T) {
t.Fatalf("records %v %v, want the base run's kept", recs, err)
}
}
+
+// selfTicks is this process's start time in clock ticks (/proc/self/stat
+// field 22), as containment records a namespace's parent.
+func selfTicks(t *testing.T) uint64 {
+ t.Helper()
+ raw, err := os.ReadFile("/proc/self/stat")
+ if err != nil {
+ t.Fatal(err)
+ }
+ fields := strings.Fields(string(raw)[strings.LastIndexByte(string(raw), ')')+1:])
+ var ticks uint64
+ if _, err := fmt.Sscan(fields[19], &ticks); err != nil {
+ t.Fatal(err)
+ }
+ return ticks
+}
+
+// TestHostedStartErrorProofBounded (review 2, finding 2): a start that
+// failed after recording an intent whose parent is this very runner, with
+// no exit proof written, cannot be proven ended here (recovery would wait
+// for the runner itself). The run returns within its bound, unterminated,
+// and the record stays for recovery.
+func TestHostedStartErrorProofBounded(t *testing.T) {
+ r := newRig(t)
+ defer func(d time.Duration) { startProofWait = d }(startProofWait)
+ startProofWait = 300 * time.Millisecond
+ work := filepath.Join(r.root, "work")
+ if err := os.Mkdir(work, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ boot, err := os.ReadFile("/proc/sys/kernel/random/boot_id")
+ if err != nil {
+ t.Fatal(err)
+ }
+ id := fmt.Sprintf("%032x", 7)
+ rec := containment.Record{ID: id, AttemptKey: "checks/k/x", BootID: strings.TrimSpace(string(boot)), ManifestHash: "m", PolicyHash: "p", ParentPID: os.Getpid(), ParentTicks: selfTicks(t)}
+ g := NewGate(r.m, "", StagedUnder(r.deps)).(*bwrapGate)
+ g.start = func(ctx context.Context, _ provider.Launch, _ []string, record func(context.Context, containment.Record) error) (provider.Process, error) {
+ raw, _ := json.Marshal(rec)
+ if err := os.WriteFile(filepath.Join(r.scratch, id+".json"), raw, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if err := record(ctx, rec); err != nil {
+ return nil, err
+ }
+ return nil, errors.New("namespace_startup_failed: no exit proof written")
+ }
+ done := make(chan gate.Result, 1)
+ go func() {
+ done <- g.Run(context.Background(), "checks/start", work, []string{"/usr/bin/true"}, time.Minute, func(string) error { return nil })
+ }()
+ var res gate.Result
+ select {
+ case res = <-done:
+ case <-time.After(10 * time.Second):
+ t.Fatal("the run waited for its own runner to exit")
+ }
+ recs, err := r.m.Records(context.Background())
+ if err != nil {
+ t.Fatal(err)
+ }
+ if res.Terminated || res.Reason != "checks_unavailable" || !slices.ContainsFunc(recs, func(c containment.Record) bool { return c.ID == id }) {
+ t.Fatalf("result %+v, records %v", res, recs)
+ }
+}
+
+// TestHostedCancelChangedGate (review 2, finding 1): a certified attempt
+// whose candidate changed a gate file, cancelled during the base run,
+// reports cancelled with the base namespace's end as proof, and no
+// diagnostic is launched.
+func TestHostedCancelChangedGate(t *testing.T) {
+ r := newRig(t)
+ base := map[string]string{".equipo/gates.json": contract, "Makefile": "ci:\n\t@sleep 300\n", "budgets.txt": "1\n"}
+ r.dispatch(base, map[string]string{"Makefile": "ci:\n\t@echo candidate gate\n"}, emptyBundle(t))
+ launches := r.countLaunches()
+ ctx, cancel := context.WithCancel(context.Background())
+ e := r.engine(r.kind, nil)
+ r.start(ctx, e)
+ defer func() { cancel(); e.Wait() }()
+ rec := r.waitRecorded(r.m)
+ e.Cancel("s1", 1)
+ rep := r.final(time.Minute)
+ if rep.State != wire.StepCancelled || !rep.Termination || rep.TerminationKind != wire.TerminationNamespace || rep.Checks == wire.ChecksCannotRun {
+ t.Fatalf("cancelled report %+v", rep)
+ }
+ if *launches != 1 {
+ t.Fatalf("%d launches, want only the base gate's", *launches)
+ }
+ if err := syscall.Kill(rec.HostPID, 0); !errors.Is(err, syscall.ESRCH) {
+ t.Fatalf("the base sandbox (pid %d) outlived its cancelled step: %v", rec.HostPID, err)
+ }
+}
diff --git a/internal/runner/thin/primary_checks_test.go b/internal/runner/thin/primary_checks_test.go
index 63523b1c..635c8923 100644
--- a/internal/runner/thin/primary_checks_test.go
+++ b/internal/runner/thin/primary_checks_test.go
@@ -198,3 +198,61 @@ func TestPrimaryChecksGatePins(t *testing.T) {
t.Fatalf("launches %+v", rec.launches)
}
}
+
+// TestPrimaryChecksCancelledChangedGate (hosted slice 2, Task 17 review
+// 2): the primary's certified checks of a candidate that changed a gate
+// file, cancelled during the base run, end cancelled with the namespace's
+// end as proof, and no diagnostic is launched.
+func TestPrimaryChecksCancelledChangedGate(t *testing.T) {
+ e, f, r, _ := hubRig(t)
+ seed := filepath.Join(filepath.Dir(f.dir), "seed")
+ writeFile(t, seed, ".equipo/gates.json", `{"version":1,"files":["budgets.txt"]}`)
+ writeFile(t, seed, "Makefile", "ci:\n\t@sleep 300\n")
+ writeFile(t, seed, "budgets.txt", "1\n")
+ gitOut(t, seed, "add", "-A")
+ gitOut(t, seed, "commit", "-qm", "base")
+ r.BaseSHA = gitOut(t, seed, "rev-parse", "HEAD")
+ gitOut(t, seed, "checkout", "-q", "-B", r.Branch)
+ writeFile(t, seed, "Makefile", "ci:\n\t@echo candidate gate\n")
+ gitOut(t, seed, "add", "-A")
+ gitOut(t, seed, "commit", "-qm", "candidate")
+ r.CandidateSHA = gitOut(t, seed, "rev-parse", "HEAD")
+ gitOut(t, seed, "push", "-q", "--force", f.dir, "main", r.Branch)
+ r.Specialist = wire.SpecialistChecks
+ scratch := filepath.Join(filepath.Dir(f.dir), "sandbox")
+ _ = os.Mkdir(scratch, 0o700)
+ self, _ := os.Executable()
+ m, err := containment.New(containment.Config{Binary: "/usr/bin/bwrap", RunnerBinary: self, ScratchRoot: scratch})
+ if err != nil {
+ t.Fatal(err)
+ }
+ rec := &launchRecorder{m: m}
+ e.O.Manager, e.checkStarter = m, rec
+ if err := e.O.State.AcceptDispatch(context.Background(), "d", r.DispatchCommand); err != nil {
+ t.Fatal(err)
+ }
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ done := make(chan wire.StepReport, 1)
+ go func() { done <- e.Exec(ctx, r, func(wire.StepReport) {}) }()
+ for range 600 {
+ recs, _ := m.Records(context.Background())
+ if len(recs) == 1 && recs[0].HostPID > 0 {
+ break
+ }
+ time.Sleep(50 * time.Millisecond)
+ }
+ cancel()
+ var rep wire.StepReport
+ select {
+ case rep = <-done:
+ case <-time.After(time.Minute):
+ t.Fatal("no report after the cancel")
+ }
+ if rep.State != wire.StepCancelled || !rep.Termination || rep.Reason != "cancelled" {
+ t.Fatalf("report %+v", rep)
+ }
+ if len(rec.launches) != 1 || strings.HasSuffix(rec.launches[0].workspace, "-diagnostic") {
+ t.Fatalf("launches %+v, want only the base gate's", rec.launches)
+ }
+}