J4: a deleted unit's row retires, and its family's witnesses with it
J4 loads overlays only up to activation-tools, so a row the full chain has since removed, for a unit the tree no longer declares, is retired: J4 stops checking it. A family whose every row is retired names no surviving row, so its witnesses may go in the same change; while one row survives, its witnesses stay required, and a surviving row with no production caller still fails. A row the chain removed whose unit is still declared is still checked. An exemption for a retired unit fails, so it goes with the unit; the roster-binding exemption for the deleted servingPriorRevision was that case and is now covered by the rule. The census's declaration naming moves into rootReadDeclName so J4 can ask whether a unit is still declared without a second type-check. Plan: claims cleanup R0, task 3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+238
−31
internal/provision/census_removal_test.go+104 −0internal/provision/plan14_input_inventory_test.go+99 −8internal/provision/plan14_root_reads_test.go+35 −23
diff --git a/internal/provision/census_removal_test.go b/internal/provision/census_removal_test.go| index e4ee44515..982899fc0 100644 |
| --- a/internal/provision/census_removal_test.go |
| +++ b/internal/provision/census_removal_test.go |
| @@ -275,3 +275,107 @@ func TestCensusAbsentRemovalNeedsAbsence(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// J4 (TestPlan14RootInputInventoryCoverage) sees only the overlays up to |
| +// activation-tools, so a later removal is a retirement: the full chain no |
| +// longer carries the row and the tree no longer declares the unit. A |
| +// family whose every row is retired may lose its witnesses in the same |
| +// change; a witness may not go while a surviving row of its family names |
| +// it; a surviving row with no production caller still fails. |
| +func TestPlan14J4RetiresAFamily(t *testing.T) { |
| + row := func(file, unit, task string) classifiedRootRead { |
| + return classifiedRootRead{rootReadEntry: rootReadEntry{File: file, Unit: unit}, Class: "authority", Task: task} |
| + } |
| + a1, a2, b := row("internal/x/a.go", "One", "A,J4"), row("internal/x/a.go", "Two", "A,J4"), row("internal/y/b.go", "Keep", "B,J4") |
| + key := func(e classifiedRootRead) string { return e.File + ":" + e.Unit } |
| + inv := rootReadInventory{Entries: map[string]classifiedRootRead{key(a1): a1, key(a2): a2, key(b): b}} |
| + callers := map[string]string{key(b): "main.go:main"} |
| + // Every witness but family A's is in the tree. |
| + tests := map[string]bool{} |
| + for name, f := range inputFamilies { |
| + if name == "A" { |
| + continue |
| + } |
| + for _, w := range []string{f.Hostile, f.Rename, f.Erasure, f.Retry, f.Positive} { |
| + tests[w] = true |
| + } |
| + } |
| + for _, w := range []string{inputFamilies["A"].Hostile, inputFamilies["A"].Rename, inputFamilies["A"].Erasure, inputFamilies["A"].Retry, inputFamilies["A"].Positive} { |
| + delete(tests, w) |
| + } |
| + check := func(full rootReadInventory, declared map[string]bool, exemptions map[string]inputExemption) []string { |
| + retired := func(k string) bool { return inputRetired(full, declared[k], k) } |
| + var failures []string |
| + for _, e := range inputSurviving(inv, retired) { |
| + failures = append(failures, checkInputRow(e, callers, tests)...) |
| + } |
| + return append(failures, checkInputRetiredExemptions(exemptions, retired)...) |
| + } |
| + carried := func(rows ...classifiedRootRead) rootReadInventory { |
| + full := rootReadInventory{Entries: map[string]classifiedRootRead{}} |
| + for _, e := range rows { |
| + full.Entries[key(e)] = e |
| + } |
| + return full |
| + } |
| + |
| + // Family A retired whole, its witnesses gone with it. |
| + if errs := check(carried(b), map[string]bool{key(b): true}, nil); len(errs) != 0 { |
| + t.Fatalf("a retired family: %v", errs) |
| + } |
| + // One A row survives: its family's witnesses must stay. |
| + errs := check(carried(a2, b), map[string]bool{key(a2): true, key(b): true}, nil) |
| + if !containsPrefix(errs, "family A missing") { |
| + t.Fatalf("a surviving row's witnesses dropped: %v", errs) |
| + } |
| + // A surviving row with no production caller still fails. |
| + if !containsPrefix(errs, key(a2)+": no production caller") { |
| + t.Fatalf("a callerless surviving row: %v", errs) |
| + } |
| + // Removed from the chain but still declared: not retired, still checked. |
| + if errs := check(carried(b), map[string]bool{key(a1): true, key(b): true}, nil); !containsPrefix(errs, key(a1)+": no production caller") { |
| + t.Fatalf("a still-declared row escaped J4: %v", errs) |
| + } |
| + // An exemption for a retired unit is stale: delete it with the unit. |
| + if errs := check(carried(b), map[string]bool{key(b): true}, map[string]inputExemption{key(a1): {Ruling: "x"}}); len(errs) != 1 || !strings.Contains(errs[0], "retired") { |
| + t.Fatalf("a retired unit's exemption: %v", errs) |
| + } |
| +} |
| + |
| +func containsPrefix(errs []string, prefix string) bool { |
| + for _, e := range errs { |
| + if strings.HasPrefix(e, prefix) { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// inputDeclared answers from the source as the census names declarations. |
| +func TestPlan14J4DeclaredMatchesTheCensus(t *testing.T) { |
| + root := t.TempDir() |
| + if err := os.MkdirAll(filepath.Join(root, "internal/x"), 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + src := "package x\n\nimport \"os\"\n\ntype T struct{}\n\nfunc (t *T) M() {}\n\nfunc F() { os.Exit(0) }\n\nvar (\n\ta = 1\n)\n\nconst c = 2\n" |
| + if err := os.WriteFile(filepath.Join(root, "internal/x/x.go"), []byte(src), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(filepath.Join(root, "internal/x/run.sh"), []byte("true\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + declared := inputDeclared(root) |
| + for k, want := range map[string]bool{ |
| + "internal/x/x.go:type T": true, "internal/x/x.go:T.M": true, "internal/x/x.go:F": true, |
| + "internal/x/x.go:var#1": true, "internal/x/x.go:const c": true, "internal/x/run.sh:external": true, |
| + "internal/x/x.go:G": false, "internal/x/gone.go:F": false, "internal/x/gone.sh:external": false, |
| + } { |
| + got, err := declared(k) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if got != want { |
| + t.Errorf("declared(%s) = %v, want %v", k, got, want) |
| + } |
| + } |
| +} |
diff --git a/internal/provision/plan14_input_inventory_test.go b/internal/provision/plan14_input_inventory_test.go| index ccc79ed5b..de7d371e2 100644 |
| --- a/internal/provision/plan14_input_inventory_test.go |
| +++ b/internal/provision/plan14_input_inventory_test.go |
| @@ -371,10 +371,11 @@ var inputExemptions = map[string]inputExemption{ |
| "internal/hostclaim/relocation.go:StartRelocation": {Ruling: "R-E2a"}, |
| "internal/hostrelocate/participant.go:Participant.Sweep": {Ruling: "R-E2a"}, |
| "internal/hostrelocate/worker.go:Worker.Start": {Ruling: "R-E2a"}, |
| - // This inventory stops at activation-tools, so seed's row outlives the |
| - // deleted function; the roster-binding overlay removes it from the full |
| - // census and declares servingPriorBinding at the same class. |
| - "internal/host/claimservinghandover.go:servingPriorRevision": {Ruling: "census-ruling-roster-binding: deleted, renamed servingPriorBinding (equality on the box binding), which takes over all its callers"}, |
| + // internal/host/claimservinghandover.go:servingPriorRevision was |
| + // exempt here (census-ruling-roster-binding: deleted, renamed |
| + // servingPriorBinding) because this inventory stops at activation-tools. |
| + // It is now retired (inputRetired): the full chain removed its row and |
| + // the tree no longer declares it. |
| } |
| // Update this checkpoint status when merging E's completion report. The 4a |
| @@ -445,6 +446,79 @@ func checkInputRow(e classifiedRootRead, callers map[string]string, tests map[st |
| return failures |
| } |
| +// inputRetired reports whether a row in J4's view has been retired since |
| +// (claims cleanup R0): the full census chain no longer carries it and the |
| +// tree no longer declares the unit. A row the chain removed whose unit is |
| +// still declared is not retired, so J4 keeps checking it. A family whose |
| +// every row is retired names no surviving row, so its witnesses may go in |
| +// the same change; while one row survives, checkInputRow keeps them. |
| +func inputRetired(full rootReadInventory, declared bool, key string) bool { |
| + _, carried := full.Entries[key] |
| + return !carried && !declared |
| +} |
| + |
| +// inputSurviving is the rows J4 checks: neither removed within its own |
| +// overlays nor retired since. |
| +func inputSurviving(inv rootReadInventory, retired func(key string) bool) map[string]classifiedRootRead { |
| + out := map[string]classifiedRootRead{} |
| + for key, e := range inv.Entries { |
| + if inv.Removed[key] != "" || retired(key) { |
| + continue |
| + } |
| + out[key] = e |
| + } |
| + return out |
| +} |
| + |
| +// checkInputRetiredExemptions fails an exemption whose unit is retired: it |
| +// goes with the unit, so it cannot waive a unit that later comes back. |
| +func checkInputRetiredExemptions(exemptions map[string]inputExemption, retired func(key string) bool) []string { |
| + var failures []string |
| + for key := range exemptions { |
| + if retired(key) { |
| + failures = append(failures, key+": exemption for a retired unit; delete it with the unit") |
| + } |
| + } |
| + return failures |
| +} |
| + |
| +// inputDeclared reports whether the tree still declares a census unit, |
| +// named as rootReadProduction names it: an external is its file; a Go unit |
| +// is a top-level declaration of its file (rootReadDeclName). Each file is |
| +// parsed once. |
| +func inputDeclared(root string) func(key string) (bool, error) { |
| + names := map[string]map[string]bool{} |
| + return func(key string) (bool, error) { |
| + file, unit, ok := strings.Cut(key, ":") |
| + if !ok { |
| + return false, fmt.Errorf("census key %q has no unit", key) |
| + } |
| + path := filepath.Join(root, filepath.FromSlash(file)) |
| + if _, err := os.Stat(path); os.IsNotExist(err) { |
| + return false, nil |
| + } else if err != nil { |
| + return false, err |
| + } |
| + if unit == "external" { |
| + return true, nil |
| + } |
| + if names[file] == nil { |
| + f, err := parser.ParseFile(token.NewFileSet(), path, nil, 0) |
| + if err != nil { |
| + return false, err |
| + } |
| + names[file] = map[string]bool{} |
| + grouped := map[string]int{} |
| + for _, decl := range f.Decls { |
| + if name, ok := rootReadDeclName(decl, grouped); ok { |
| + names[file][name] = true |
| + } |
| + } |
| + } |
| + return names[file][unit], nil |
| + } |
| +} |
| + |
| func TestPlan14RootInputInventoryCoverage(t *testing.T) { |
| // Reads the source tree and read-only package maps only, and spends |
| // most of its time type-checking the module, so it runs in parallel |
| @@ -460,12 +534,26 @@ func TestPlan14RootInputInventoryCoverage(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| + // This inventory stops at activation-tools; a unit deleted since, whose |
| + // row the full chain has removed, is retired (inputRetired). |
| + full, _ := rootReadChain(t, root) |
| + declared := inputDeclared(root) |
| + var declaredErr error |
| + retired := func(key string) bool { |
| + if _, carried := full.Entries[key]; carried { |
| + return false |
| + } |
| + d, err := declared(key) |
| + if err != nil { |
| + declaredErr = err |
| + return false |
| + } |
| + return inputRetired(full, d, key) |
| + } |
| failures := checkInputExemptions(inv, callers, inputExemptions, inputTrackEComplete) |
| + failures = append(failures, checkInputRetiredExemptions(inputExemptions, retired)...) |
| var report []string |
| - for key, e := range inv.Entries { |
| - if inv.Removed[key] != "" { |
| - continue |
| - } |
| + for _, e := range inputSurviving(inv, retired) { |
| failures = append(failures, checkInputRow(e, callers, tests)...) |
| if e.Class == "authority" { |
| family, familyErr := inputFamilyFor(e) |
| @@ -479,6 +567,9 @@ func TestPlan14RootInputInventoryCoverage(t *testing.T) { |
| report = append(report, fmt.Sprintf("%s\t%s\t%s\t%s\t%s\t%s", mode, e.File, e.Unit, strings.Join(family, "+"), callers[e.File+":"+e.Unit], e.Basis)) |
| } |
| } |
| + if declaredErr != nil { |
| + t.Fatal(declaredErr) |
| + } |
| sort.Strings(report) |
| for _, row := range report { |
| t.Log("J4\t" + row) |
diff --git a/internal/provision/plan14_root_reads_test.go b/internal/provision/plan14_root_reads_test.go| index 7363d9c5a..41be24a42 100644 |
| --- a/internal/provision/plan14_root_reads_test.go |
| +++ b/internal/provision/plan14_root_reads_test.go |
| @@ -293,29 +293,8 @@ func rootReadProduction(root string) (rootReadScan, error) { |
| } |
| grouped := map[string]int{} |
| for _, decl := range f.Decls { |
| - var name string |
| - switch d := decl.(type) { |
| - case *ast.FuncDecl: |
| - name = d.Name.Name |
| - if d.Recv != nil { |
| - name = censusRecvName(d.Recv.List[0].Type) + "." + name |
| - } |
| - case *ast.GenDecl: |
| - if d.Tok == token.IMPORT { |
| - continue |
| - } |
| - if d.Lparen.IsValid() { |
| - grouped[d.Tok.String()]++ |
| - name = fmt.Sprintf("%s#%d", d.Tok, grouped[d.Tok.String()]) |
| - } else { |
| - switch s := d.Specs[0].(type) { |
| - case *ast.ValueSpec: |
| - name = d.Tok.String() + " " + s.Names[0].Name |
| - case *ast.TypeSpec: |
| - name = "type " + s.Name.Name |
| - } |
| - } |
| - default: |
| + name, ok := rootReadDeclName(decl, grouped) |
| + if !ok { |
| continue |
| } |
| start, end := fset.Position(decl.Pos()).Offset, fset.Position(decl.End()).Offset |
| @@ -391,6 +370,39 @@ func rootReadProduction(root string) (rootReadScan, error) { |
| return out, nil |
| } |
| +// rootReadDeclName names a top-level declaration as the census keys it: |
| +// a func or method ("T.M"), "type T", "var x" or "const x", or "var#N" for |
| +// the Nth grouped declaration of its token in the file (grouped counts |
| +// them). Imports and anything else are not units. |
| +func rootReadDeclName(decl ast.Decl, grouped map[string]int) (string, bool) { |
| + var name string |
| + switch d := decl.(type) { |
| + case *ast.FuncDecl: |
| + name = d.Name.Name |
| + if d.Recv != nil { |
| + name = censusRecvName(d.Recv.List[0].Type) + "." + name |
| + } |
| + case *ast.GenDecl: |
| + if d.Tok == token.IMPORT { |
| + return "", false |
| + } |
| + if d.Lparen.IsValid() { |
| + grouped[d.Tok.String()]++ |
| + name = fmt.Sprintf("%s#%d", d.Tok, grouped[d.Tok.String()]) |
| + } else { |
| + switch s := d.Specs[0].(type) { |
| + case *ast.ValueSpec: |
| + name = d.Tok.String() + " " + s.Names[0].Name |
| + case *ast.TypeSpec: |
| + name = "type " + s.Name.Name |
| + } |
| + } |
| + default: |
| + return "", false |
| + } |
| + return name, true |
| +} |
| + |
| type classifiedRootRead struct { |
| rootReadEntry |
| Class, Task, Basis string |