carlos / platform Public

C2 Task 5: the re-base's four proofs through the real scanner

On a fixture module with root and non-root units: (a) console-only,
template, agent-only and agent-helper edits pass, new kinds of read
included; (b) a root unit's changed reads, a new root unit with reads and
an edit to an installed unit file fail; (c) a helper's read moved into a
root path fails as a new unit, a decision; (d) deleting a root unit and a
root package passes through R0's removed path and closes the census.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 1b3e3cb1e9ff8099a55555376d83d5e7b443b731 parent bdf3624
1 file changed, +111 −0
  • internal/provision/census_rebase_proof_test.go +111 −0
diff --git a/internal/provision/census_rebase_proof_test.go b/internal/provision/census_rebase_proof_test.go
new file mode 100644
index 000000000..edb3640aa
--- /dev/null
+++ b/internal/provision/census_rebase_proof_test.go
@@ -0,0 +1,111 @@
+package provision
+
+// What the re-base (C2) must keep and what it must drop, proved on a
+// fixture module through the real scanner and the real graph
+// (scopeFiles): (a) console-only and template edits pass; (b) a root unit
+// whose reads change, and a new root unit with reads, fail; (c) a read
+// moved from an out-of-scope helper into a root path fails; (d) a deletion
+// passes through R0's path.
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// cleanCensus is a fixture tree and its census, classified clean.
+func cleanCensus(t *testing.T) (string, rootReadInventory, string) {
+ t.Helper()
+ root := scopeTree(t)
+ inv, seal := inventoryOf(scopedTree(t, root), readConfigUnit)
+ if errs := censusDiscrepancies(scopedTree(t, root), inv, seal); len(errs) != 0 {
+ t.Fatalf("fixture census: %v", errs)
+ }
+ return root, inv, seal
+}
+
+// (a) An edit to a console-only function, its template, an agent-only
+// function in a root package and a helper only the agent calls: none
+// needs a card, even one that adds a new kind of read.
+func TestCensusRebaseProofConsoleAndTemplateEditsPass(t *testing.T) {
+ root, inv, seal := cleanCensus(t)
+ editFile(t, root, "internal/console/console.go", `os.ReadFile("/data/console")`, `os.ReadFile("/data/console"); os.Stat("/data/other")`)
+ editFile(t, root, "internal/console/templates/page.html", "hello", "goodbye")
+ editFile(t, root, "internal/host/host.go", `os.ReadFile("/data/agent")`, `os.Open("/data/agent")`)
+ editFile(t, root, "internal/helper/helper.go", `os.ReadFile("/data/helper")`, `os.ReadDir("/data")`)
+ if errs := censusDiscrepancies(scopedTree(t, root), inv, seal); len(errs) != 0 {
+ t.Fatalf("an edit outside root's scope failed the census: %v", errs)
+ }
+}
+
+// (b) A reachable unit whose reads change fails, as a decision when it
+// reads a new kind; so does a new reachable unit with reads, and an edit
+// to a unit file root installs.
+func TestCensusRebaseProofRootReadsStillFail(t *testing.T) {
+ for name, tc := range map[string]struct {
+ file, old, new, key, class string
+ }{
+ "changed reads": {"internal/host/host.go", `func readConfig() { os.ReadFile("/data/config") }`, `func readConfig() { os.ReadFile("/data/config"); os.Stat("/data/x") }`, readConfigUnit, censusReads},
+ "new unit": {"internal/host/host.go", "func RunAdopt() { readConfig() }", "func RunAdopt() { readConfig(); newRead() }\n\nfunc newRead() { os.Open(\"/data/new\") }", "internal/host/host.go:newRead", censusNew},
+ "unit file": {"internal/host/units/carlos-edge.service", "User=carlos\n", "", "internal/host/units/carlos-edge.service:external", censusBody},
+ } {
+ t.Run(name, func(t *testing.T) {
+ root, inv, seal := cleanCensus(t)
+ editFile(t, root, tc.file, tc.old, tc.new)
+ got := scopedTree(t, root)
+ if errs := censusDiscrepancies(got, inv, seal); len(errs) == 0 {
+ t.Fatal("the census passed")
+ }
+ if classes := classesOf(classifyRootReads(got, inv, seal)); classes[tc.key] != tc.class {
+ t.Fatalf("class of %s = %q, want %q (all %v)", tc.key, classes[tc.key], tc.class, classes)
+ }
+ })
+ }
+}
+
+// (c) The helper's read was out of scope while only the agent called it;
+// a root path calling it brings the read into the census, as a new unit.
+func TestCensusRebaseProofReadMovedIntoRootPathFails(t *testing.T) {
+ root, inv, seal := cleanCensus(t)
+ editFile(t, root, "internal/host/host.go", "func RunAdopt() { readConfig() }", "func RunAdopt() { readConfig(); helper.Load() }")
+ got := scopedTree(t, root)
+ if errs := censusDiscrepancies(got, inv, seal); !containsPrefix(errs, "unclassified root read internal/helper/helper.go:Load") {
+ t.Fatalf("a read moved into root's path: %v", errs)
+ }
+ if _, err := proposeRootReads(got, inv, seal, "x", map[string]string{}); err == nil || !strings.Contains(err.Error(), "new internal/helper/helper.go:Load") {
+ t.Fatalf("propose: %v, want the new unit named as a decision", err)
+ }
+}
+
+// (d) Deleting a root unit, and a whole root package, passes through R0's
+// path: removed, approved, the overlay closes the census.
+func TestCensusRebaseProofDeletionPassesThroughR0(t *testing.T) {
+ root, inv, seal := cleanCensus(t)
+ editFile(t, root, "internal/host/host.go", "func RunAdopt() { readConfig() }\n\nfunc readConfig() { os.ReadFile(\"/data/config\") }\n", "func RunAdopt() {}\n")
+ editFile(t, root, "internal/host/host.go", "\t_ \"fixture/root/internal/initpkg\"\n", "")
+ if err := os.RemoveAll(filepath.Join(root, "internal/initpkg")); err != nil {
+ t.Fatal(err)
+ }
+ got := scopedTree(t, root)
+ classes := classesOf(classifyRootReads(got, inv, seal))
+ for _, k := range []string{readConfigUnit, "internal/initpkg/init.go:initRead", "internal/initpkg/init.go:varRead", "internal/initpkg"} {
+ if classes[k] != censusRemoved {
+ t.Fatalf("class of %s = %q (all %v)", k, classes[k], classes)
+ }
+ }
+ p, err := proposeRootReads(got, inv, seal, "drop-config", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(p.Overlay, "@coverage\tinternal/initpkg\t-\n") || !strings.Contains(p.Overlay, ";absent;basis=") {
+ t.Fatalf("overlay:\n%s", p.Overlay)
+ }
+ after := cloneRootReadInventory(inv)
+ if err := loadRootReadInventory(writeOverlay(t, p.Overlay), &after, true); err != nil {
+ t.Fatal(err)
+ }
+ if errs := censusDiscrepancies(got, after, p.Seal); len(errs) != 0 {
+ t.Fatalf("after the overlay: %v", errs)
+ }
+}