test: stabilize runner proc coverage and reduce check fixture time
6 files changed,
+174
−10
.rastrillo/budgets.txt+1 −1internal/runner/checks/ci_fixture_test.go+29 −0internal/runner/checks/executor_test.go+14 −3internal/runner/ci_proc_test.go+116 −0internal/runner/containment_r1_test.go+12 −0internal/runner/containment_r2_test.go+2 −6
CI passed — run details
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 87f22018..c66b1010 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -16,7 +16,7 @@ time internal/equipotest 300s Final fix package rerun measured 187.035s (review |
| size internal/equipo 10800 - Final fixes retain the plan layout and add bounded row-change notifications, aggregate task counts and runner refusal handling; current source count: 9660. |
| size internal/equipotest - 13000 Final finding regressions stay beside the mandated integration fixtures; current test count: 11667. |
| -time internal/runner/checks 35s Final CI measured 17.268s; prior worst 17.451s. 35s gives 100 percent headroom for real Go fixtures, sandbox sentinels, timeout and child cleanup. |
| +time internal/runner/checks 60s CI worker measured 44.553s (44.6s rounded); 60s gives 34 percent headroom. Shared baseline capture reduces repeated Go runs; retain the CI allowance for sandbox sentinels, timeout and child cleanup. |
| time internal/runner 330s Final corrected package rerun measured 152.897s; review worst 220.6s, interrupted CI 245.239s. 330s exceeds even the interrupted run by 34 percent. Injected-clock lease test measured 8.416s instead of about 65s. |
| perf GET /live skip Authorized notification stream, bounded to 30 seconds; not a GET screen. |
diff --git a/internal/runner/checks/ci_fixture_test.go b/internal/runner/checks/ci_fixture_test.go| new file mode 100644 |
| index 00000000..7f61c01e |
| --- /dev/null |
| +++ b/internal/runner/checks/ci_fixture_test.go |
| @@ -0,0 +1,29 @@ |
| +package checks |
| + |
| +import ( |
| + "context" |
| + "slices" |
| + "testing" |
| +) |
| + |
| +func TestSharedBaselineFixtureIsolation(t *testing.T) { |
| + first := newFixture(t) |
| + original := slices.Clone(first.d.Baseline.Names) |
| + first.d.Baseline.Names[0].Name = "changed" |
| + put(t, first.base, "extra_test.go", "package fixture\nimport \"testing\"\nfunc TestExtra(t *testing.T){}\n") |
| + second := newFixture(t) |
| + if !slices.Equal(second.d.Baseline.Names, original) { |
| + t.Fatal("fixtures share mutable baseline names") |
| + } |
| + fresh, err := second.e.CaptureBaseline(context.Background(), second.d) |
| + must(t, err) |
| + if fresh.Hash != second.d.Baseline.Hash || !slices.Equal(fresh.Names, original) { |
| + t.Fatal("shared baseline differs from fresh isolated capture") |
| + } |
| + first.d.Baseline.Names = slices.Clone(original) |
| + changed, err := first.e.CaptureBaseline(context.Background(), first.d) |
| + must(t, err) |
| + if changed.Hash == fresh.Hash || !slices.Contains(changed.Names, TestIdentity{Package: "fixture", Name: "TestExtra"}) { |
| + t.Fatal("changed fixture bypassed baseline capture") |
| + } |
| +} |
diff --git a/internal/runner/checks/executor_test.go b/internal/runner/checks/executor_test.go| index f8e8f339..071a7a55 100644 |
| --- a/internal/runner/checks/executor_test.go |
| +++ b/internal/runner/checks/executor_test.go |
| @@ -8,7 +8,9 @@ import ( |
| "os" |
| "os/exec" |
| "path/filepath" |
| + "slices" |
| "strings" |
| + "sync" |
| "testing" |
| "time" |
| @@ -68,6 +70,12 @@ type fixture struct { |
| hash string |
| } |
| +var fixtureBaseline struct { |
| + sync.Once |
| + value TestBaseline |
| + err error |
| +} |
| + |
| func newFixture(t *testing.T) fixture { |
| t.Helper() |
| b := t.TempDir() |
| @@ -102,9 +110,12 @@ func newFixture(t *testing.T) fixture { |
| e, err := newExecutor(cfg, localSandbox{}) |
| must(t, err) |
| e.SetAttestationStore(durableFixture{}) |
| - baseline, err := e.CaptureBaseline(context.Background(), d) |
| - must(t, err) |
| - d.Baseline = baseline |
| + fixtureBaseline.Do(func() { |
| + fixtureBaseline.value, fixtureBaseline.err = e.CaptureBaseline(context.Background(), d) |
| + }) |
| + must(t, fixtureBaseline.err) |
| + d.Baseline = fixtureBaseline.value |
| + d.Baseline.Names = slices.Clone(fixtureBaseline.value.Names) |
| e.cfg.DefinitionHash = Digest(raw(d)) |
| e.cfg.ReproductionHash = Digest(raw(r)) |
| return fixture{e, d, r, b, c, cand, CandidateHash(cand)} |
diff --git a/internal/runner/ci_proc_test.go b/internal/runner/ci_proc_test.go| new file mode 100644 |
| index 00000000..94fd36e9 |
| --- /dev/null |
| +++ b/internal/runner/ci_proc_test.go |
| @@ -0,0 +1,116 @@ |
| +package runner |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "os" |
| + "path/filepath" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/paseo" |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +func TestLinuxInspectorNamespaceInitBoundary(t *testing.T) { |
| + if privateProcTest(t) { |
| + return |
| + } |
| + p, o := realInspector(t) |
| + init, err := p.identity(1) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + p.records[ownerKey(o)] = &processRecord{Owner: o, TrackTicks: init.StartTicks, TrackBoot: p.boot} |
| + if err := p.Track(context.Background(), o); !errors.Is(err, paseo.ErrUncertain) { |
| + t.Fatalf("same-tick namespace init must fail closed: %v", err) |
| + } |
| + if err := waitPrivateProcBoundary(init, (linuxClock{}).Read); err != nil { |
| + t.Fatal(err) |
| + } |
| + delete(p.records, ownerKey(o)) |
| + trackPrivateProcess(t, p, o) |
| +} |
| + |
| +func TestPrivateProcBoundaryPreconditions(t *testing.T) { |
| + init := ProcessIdentity{PID: 1, StartTicks: 10, BootID: "boot"} |
| + for _, kind := range []string{"same_tick", "clock_error", "boot_mismatch", "stalled_clock"} { |
| + t.Run(kind, func(t *testing.T) { |
| + calls := 0 |
| + err := waitPrivateProcBoundary(init, func() (ClockReading, error) { |
| + calls++ |
| + reading := ClockReading{BootID: "boot", Elapsed: 100 * time.Millisecond} |
| + if calls > 1 && kind != "stalled_clock" { |
| + reading.Elapsed += 10 * time.Millisecond |
| + } |
| + if kind == "clock_error" { |
| + return ClockReading{}, errors.New("clock unavailable") |
| + } |
| + if kind == "boot_mismatch" { |
| + reading.BootID = "other" |
| + } |
| + return reading, nil |
| + }) |
| + if kind == "same_tick" { |
| + if err != nil || calls < 2 { |
| + t.Fatalf("did not wait past init tick: calls=%d err=%v", calls, err) |
| + } |
| + } else if kind == "stalled_clock" { |
| + if err == nil || !strings.Contains(err.Error(), "init must predate Track") { |
| + t.Fatalf("missing stalled clock diagnostic: %v", err) |
| + } |
| + } else if err == nil || !strings.Contains(err.Error(), kind) { |
| + t.Fatalf("missing %s precondition diagnostic: %v", kind, err) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func waitPrivateProcBoundary(init ProcessIdentity, read func() (ClockReading, error)) error { |
| + deadline := time.Now().Add(time.Second) |
| + for { |
| + reading, err := read() |
| + if err != nil { |
| + return fmt.Errorf("private /proc precondition clock_error: %w", err) |
| + } |
| + if reading.BootID != init.BootID { |
| + return fmt.Errorf("private /proc precondition boot_mismatch: init=%s clock=%s", init.BootID, reading.BootID) |
| + } |
| + ticks := uint64(reading.Elapsed / (10 * time.Millisecond)) |
| + if ticks > init.StartTicks { |
| + return nil |
| + } |
| + if time.Now().After(deadline) { |
| + return fmt.Errorf("private /proc precondition init must predate Track: init=%d clock=%d", init.StartTicks, ticks) |
| + } |
| + time.Sleep(time.Millisecond) |
| + } |
| +} |
| + |
| +func trackPrivateProcess(t *testing.T, p *LinuxProcessInspector, o ProcessOwner) { |
| + t.Helper() |
| + if err := p.Track(context.Background(), o); err != nil { |
| + reading, clockErr := (linuxClock{}).Read() |
| + t.Logf("Track preconditions: clock=%+v clock_error=%v inspector_boot=%s uid=%d pid=%d record=%+v", reading, clockErr, p.boot, os.Getuid(), os.Getpid(), p.records[ownerKey(o)]) |
| + mapping, mapErr := os.ReadFile("/proc/self/uid_map") |
| + t.Logf("UID mapping: %s error=%v", mapping, mapErr) |
| + entries, readErr := os.ReadDir(p.root) |
| + t.Logf("proc readability: %v", readErr) |
| + for _, entry := range entries { |
| + pid, parseErr := strconv.Atoi(entry.Name()) |
| + if parseErr != nil { |
| + continue |
| + } |
| + e, entryErr := p.entry(pid) |
| + var st unix.Stat_t |
| + statErr := unix.Stat(filepath.Join(p.root, entry.Name()), &st) |
| + _, envErr := os.ReadFile(filepath.Join(p.root, entry.Name(), "environ")) |
| + _, cwdErr := os.Readlink(filepath.Join(p.root, entry.Name(), "cwd")) |
| + t.Logf("proc pid=%d identity=%+v parent=%d dead=%t uid=%d stat_error=%v entry_error=%v environ_error=%v cwd_error=%v", pid, e.id, e.parent, e.dead, st.Uid, statErr, entryErr, envErr, cwdErr) |
| + } |
| + t.Fatalf("Track requires matching boot/clock, readable same-UID proc identities and attribution for every process at or after TrackTicks (namespace init must predate it): %v", err) |
| + } |
| +} |
diff --git a/internal/runner/containment_r1_test.go b/internal/runner/containment_r1_test.go| index bdbccc8d..7f2dbdb1 100644 |
| --- a/internal/runner/containment_r1_test.go |
| +++ b/internal/runner/containment_r1_test.go |
| @@ -275,6 +275,18 @@ func TestLinuxInspectorReboot(t *testing.T) { |
| func privateProcTest(t *testing.T) bool { |
| t.Helper() |
| if os.Getenv("EQUIPO_PRIVATE_PROC_TEST") == "1" { |
| + boot, err := os.ReadFile("/proc/sys/kernel/random/boot_id") |
| + if err != nil { |
| + t.Fatalf("private /proc boot ID precondition: %v", err) |
| + } |
| + p := &LinuxProcessInspector{root: "/proc", boot: strings.TrimSpace(string(boot))} |
| + init, err := p.identity(1) |
| + if err != nil { |
| + t.Fatalf("private /proc init identity precondition: %v", err) |
| + } |
| + if err := waitPrivateProcBoundary(init, (linuxClock{}).Read); err != nil { |
| + t.Fatal(err) |
| + } |
| return false |
| } |
| exe, err := os.Executable() |
diff --git a/internal/runner/containment_r2_test.go b/internal/runner/containment_r2_test.go| index 3daf756b..c666e1b4 100644 |
| --- a/internal/runner/containment_r2_test.go |
| +++ b/internal/runner/containment_r2_test.go |
| @@ -97,17 +97,13 @@ func TestLinuxInspectorSequentialJobsRunnerGit(t *testing.T) { |
| prep.Attempt += 2 * team.AttemptID(job) |
| prep.Marker = fmt.Sprintf("prepare-%d", job) |
| prep.LocalOnly = true |
| - if err := p.Track(ctx, prep); err != nil { |
| - t.Fatal(err) |
| - } |
| + trackPrivateProcess(t, p, prep) |
| retiredFixture(t, p, prep) |
| step := prep |
| step.Attempt++ |
| step.Marker = fmt.Sprintf("step-%d", job) |
| step.Workspace.Path = t.TempDir() |
| - if err := p.Track(ctx, step); err != nil { |
| - t.Fatal(err) |
| - } |
| + trackPrivateProcess(t, p, step) |
| git := exec.Command("/usr/bin/git", "hash-object", "--stdin") |
| git.Dir = prep.Workspace.Path |
| git.Env = []string{"GIT_CONFIG_NOSYSTEM=1", "GIT_CONFIG_GLOBAL=/dev/null"} |