carlos / platform Public

demobuild: a truncated list-units capture is not proof of absence

The systemctl wrapper keeps 128 KiB and reports success, so a listing
that may have been cut keeps the full show/stop proof (R1 P2-3). The
instancectl and activator listings use uncapped captures.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1326e34a184bc1dd599ce69b24e184762ef1190e parent b584902
2 files changed, +52 −3
  • internal/demobuild/gvisor_never_loaded_test.go +42 −0
  • internal/demobuild/unit.go +10 −3
diff --git a/internal/demobuild/gvisor_never_loaded_test.go b/internal/demobuild/gvisor_never_loaded_test.go
index b2ff52cc4..018b2bc01 100644
--- a/internal/demobuild/gvisor_never_loaded_test.go
+++ b/internal/demobuild/gvisor_never_loaded_test.go
@@ -3,8 +3,10 @@ package demobuild
import (
"context"
"errors"
+ "fmt"
"os"
"path/filepath"
+ "slices"
"strings"
"testing"
@@ -94,3 +96,43 @@ func TestGVisorBuildNeverLoadedIsNotNamed(t *testing.T) {
})
}
}
+
+// R1 P2-3: the wrapper keeps only systemctlCaptureLimit bytes of output and
+// reports success. A listing cut there is not an inventory: the target may
+// sit past the cut, so the full proof runs.
+func TestGVisorBuildTruncatedListingKeepsTheProof(t *testing.T) {
+ fakeUnitController(t)
+ w, j, _, _ := workerFixture(t)
+ dir := filepath.Join(w.root, j.ID, "1")
+ if err := os.MkdirAll(dir+"/work", 0o700); err != nil {
+ t.Fatal(err)
+ }
+ gvisor, err := layoutFor(w.root, dir, execsandbox.FamilyGVisor)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var full strings.Builder
+ for i := 0; full.Len() <= systemctlCaptureLimit; i++ {
+ fmt.Fprintf(&full, "carlos-demo-build-gvisor@%064x_%d.service loaded inactive dead carlos gVisor offline demo build\n", i, i)
+ }
+ full.WriteString(gvisor.unit + " loaded active running carlos gVisor offline demo build\n")
+ var calls []string
+ systemctl = func(_ context.Context, args ...string) (string, error) {
+ calls = append(calls, strings.Join(args, " "))
+ if args[0] == "list-units" {
+ var captured limitedLog // what the production wrapper keeps
+ captured.Write([]byte(full.String()))
+ if strings.Contains(string(captured.b), gvisor.unit) {
+ t.Fatal("fixture: target inside the captured part")
+ }
+ return string(captured.b), nil
+ }
+ return "LoadState=not-found\nActiveState=inactive\nMainPID=0\nControlPID=0\nSubState=dead\nJob=\n", nil
+ }
+ if err := stopBuildContext(context.Background(), gvisor); err != nil {
+ t.Fatal(err)
+ }
+ if !slices.ContainsFunc(calls, func(c string) bool { return strings.HasPrefix(c, "show "+gvisor.unit) }) {
+ t.Fatalf("truncated listing taken as absence:\n%s", strings.Join(calls, "\n"))
+ }
+}
diff --git a/internal/demobuild/unit.go b/internal/demobuild/unit.go
index 882a1f605..55705913a 100644
--- a/internal/demobuild/unit.go
+++ b/internal/demobuild/unit.go
@@ -88,11 +88,15 @@ var systemctl = func(ctx context.Context, args ...string) (string, error) {
return string(b.b), err
}
+// systemctlCaptureLimit caps what the systemctl wrapper keeps of its
+// output. Output of exactly this length may have been cut short.
+const systemctlCaptureLimit = 128 * 1024
+
type limitedLog struct{ b []byte }
func (b *limitedLog) Write(p []byte) (int, error) {
n := len(p)
- if room := 128*1024 - len(b.b); room > 0 {
+ if room := systemctlCaptureLimit - len(b.b); room > 0 {
b.b = append(b.b, p[:min(room, len(p))]...)
}
return n, nil
@@ -391,7 +395,8 @@ func stopBuildContext(ctx context.Context, l buildLayout) error {
// families, so every build on a systemd-mode box did). The proof: no cgroup
// directory (the path emptyBuildCgroup reads), no job drop-in directory, and
// no listing among the units systemd holds, asked by family glob rather than
-// by name. Any error is false and the full proof runs.
+// by name. Any error, or a listing that may be truncated, is false and the
+// full proof runs.
func gvisorBuildNeverLoaded(ctx context.Context, unit string) bool {
for _, path := range []string{filepath.Join(buildCgroupRoot, unit), filepath.Join(unitRoot, unit+".d")} {
if _, err := os.Lstat(path); !errors.Is(err, os.ErrNotExist) {
@@ -399,7 +404,9 @@ func gvisorBuildNeverLoaded(ctx context.Context, unit string) bool {
}
}
out, err := systemctl(ctx, "list-units", "--all", "--plain", "--no-legend", "--no-pager", "carlos-demo-build-gvisor@*.service")
- if err != nil {
+ // Absence needs the whole inventory: a listing the capture may have cut
+ // at its limit keeps the full proof.
+ if err != nil || len(out) >= systemctlCaptureLimit {
return false
}
for _, line := range strings.Split(out, "\n") {