C2 Task 4: J4 checks only rows in the census's scope
A surviving row of J4's inventory that root no longer runs is reported as left-scope and not checked; rows in scope keep the caller and witness checks, and live families now come from the re-based chain. The census, census-propose and J4 share one scoped scan and one linux graph per test process. Today: 1395 rows checked, 268 left scope.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+79
−16
internal/provision/census_propose_test.go+1 −1internal/provision/census_scope_fixture_test.go+21 −0internal/provision/census_scope_test.go+17 −0internal/provision/plan14_input_inventory_test.go+39 −14internal/provision/plan14_root_reads_test.go+1 −1
diff --git a/internal/provision/census_propose_test.go b/internal/provision/census_propose_test.go| index ead905305..de6a7f001 100644 |
| --- a/internal/provision/census_propose_test.go |
| +++ b/internal/provision/census_propose_test.go |
| @@ -644,7 +644,7 @@ func TestPlan14RootReadCensusPropose(t *testing.T) { |
| } |
| before = rootReadOverlayFile(name) |
| } |
| - got, err := rootReadScoped(root, censusGraphShared) |
| + got, err := rootReadScopedShared(root) |
| if err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/provision/census_scope_fixture_test.go b/internal/provision/census_scope_fixture_test.go| index 86f3b15d8..f6fc92f07 100644 |
| --- a/internal/provision/census_scope_fixture_test.go |
| +++ b/internal/provision/census_scope_fixture_test.go |
| @@ -391,3 +391,24 @@ func inventoryOfCoverage(scan rootReadScan) rootReadInventory { |
| inv, _ := inventoryOf(scan) |
| return inv |
| } |
| + |
| +// J4 narrowed (C2): a surviving row in the census's scope keeps its caller |
| +// and witness checks; a row out of scope is reported and not checked. |
| +func TestPlan14J4ChecksRowsInScope(t *testing.T) { |
| + row := func(file, unit string) classifiedRootRead { |
| + return classifiedRootRead{rootReadEntry: rootReadEntry{File: file, Unit: unit}, Class: "authority", Task: "A,J4"} |
| + } |
| + in, out := row("internal/host/a.go", "Root"), row("internal/hostclaim/b.go", "Claim") |
| + rows := map[string]classifiedRootRead{"internal/host/a.go:Root": in, "internal/hostclaim/b.go:Claim": out} |
| + inScope := func(key string) bool { return key == "internal/host/a.go:Root" } |
| + failures, report := checkInputRows(rows, map[string]string{}, map[string]bool{}, inScope) |
| + if !containsPrefix(failures, "internal/host/a.go:Root: no production caller") || !containsPrefix(failures, "family A missing") { |
| + t.Fatalf("a row in scope escaped its checks: %v", failures) |
| + } |
| + if containsPrefix(failures, "internal/hostclaim/b.go:Claim") { |
| + t.Fatalf("a row out of scope was checked: %v", failures) |
| + } |
| + if !containsPrefix(report, "left-scope\tinternal/hostclaim/b.go\tClaim") || !containsPrefix(report, "enabled\tinternal/host/a.go\tRoot") { |
| + t.Fatalf("report: %v", report) |
| + } |
| +} |
diff --git a/internal/provision/census_scope_test.go b/internal/provision/census_scope_test.go| index 413b47915..5613a33c0 100644 |
| --- a/internal/provision/census_scope_test.go |
| +++ b/internal/provision/census_scope_test.go |
| @@ -523,6 +523,23 @@ func rootReadScoped(root string, load func(root, platform string) (*refGraph, er |
| return rootReadScope(raw, s) |
| } |
| +// rootReadScopedShared is rootReadScoped for the repository, scanned once |
| +// per test process: the census, census-propose and J4 share it. |
| +var rootReadScopedOnce sync.Map |
| + |
| +type rootReadScopedResult struct { |
| + once sync.Once |
| + scan rootReadScan |
| + err error |
| +} |
| + |
| +func rootReadScopedShared(root string) (rootReadScan, error) { |
| + v, _ := rootReadScopedOnce.LoadOrStore(root, &rootReadScopedResult{}) |
| + r := v.(*rootReadScopedResult) |
| + r.once.Do(func() { r.scan, r.err = rootReadScoped(root, censusGraphShared) }) |
| + return r.scan, r.err |
| +} |
| + |
| // rootReadScope narrows a scan of the whole tree to the census's scope. A |
| // Go unit is in scope when root reaches its declaration. A non-Go file is |
| // when a reached declaration embeds it, when it is under infra/ (user_data |
diff --git a/internal/provision/plan14_input_inventory_test.go b/internal/provision/plan14_input_inventory_test.go| index 2b71e90b8..1d96d5914 100644 |
| --- a/internal/provision/plan14_input_inventory_test.go |
| +++ b/internal/provision/plan14_input_inventory_test.go |
| @@ -333,6 +333,35 @@ func checkInputRow(e classifiedRootRead, callers map[string]string, tests map[st |
| return failures |
| } |
| +// checkInputRows checks J4's surviving rows that are in the census's scope |
| +// (checkInputRow) and reports every authority row: "enabled" or |
| +// "report-only" as before, "left-scope" for a row root no longer runs, |
| +// which is not checked (C2). |
| +func checkInputRows(rows map[string]classifiedRootRead, callers map[string]string, tests map[string]bool, inScope func(key string) bool) (failures, report []string) { |
| + for key, e := range rows { |
| + mode := "enabled" |
| + switch { |
| + case !inScope(key): |
| + mode = "left-scope" |
| + case !inputActivationEnabled(e): |
| + mode = "report-only" |
| + } |
| + if mode != "left-scope" { |
| + failures = append(failures, checkInputRow(e, callers, tests)...) |
| + } |
| + if e.Class != "authority" { |
| + continue |
| + } |
| + family, familyErr := inputFamilyFor(e) |
| + if familyErr != nil { |
| + family = []string{e.Task} |
| + } |
| + 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[key], e.Basis)) |
| + } |
| + sort.Strings(report) |
| + return failures, report |
| +} |
| + |
| // 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 |
| @@ -496,21 +525,17 @@ func TestPlan14RootInputInventoryCoverage(t *testing.T) { |
| }) |
| failures = append(failures, liveErrs...) |
| failures = append(failures, checkInputLiveWitnesses(live, tests)...) |
| - var report []string |
| - for _, e := range inputSurviving(inv, retired) { |
| - failures = append(failures, checkInputRow(e, callers, tests)...) |
| - if e.Class == "authority" { |
| - family, familyErr := inputFamilyFor(e) |
| - if familyErr != nil { |
| - family = []string{e.Task} |
| - } |
| - mode := "enabled" |
| - if !inputActivationEnabled(e) { |
| - mode = "report-only" |
| - } |
| - 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)) |
| - } |
| + // Narrowed to the census's scope (C2): a row root no longer runs is |
| + // reported, not checked. |
| + scoped, err := rootReadScopedShared(root) |
| + if err != nil { |
| + t.Fatal(err) |
| } |
| + rowFailures, report := checkInputRows(inputSurviving(inv, retired), callers, tests, func(key string) bool { |
| + _, ok := scoped.Declarations[key] |
| + return ok |
| + }) |
| + failures = append(failures, rowFailures...) |
| if declaredErr != nil { |
| t.Fatal(declaredErr) |
| } |
diff --git a/internal/provision/plan14_root_reads_test.go b/internal/provision/plan14_root_reads_test.go| index 189d4131f..a49673f9a 100644 |
| --- a/internal/provision/plan14_root_reads_test.go |
| +++ b/internal/provision/plan14_root_reads_test.go |
| @@ -722,7 +722,7 @@ func TestPlan14RootReadCensus(t *testing.T) { |
| // here but the build cache), so it runs in parallel. |
| t.Parallel() |
| root := censusRoot(t) |
| - got, err := rootReadScoped(root, censusGraphShared) |
| + got, err := rootReadScopedShared(root) |
| if err != nil { |
| t.Fatal(err) |
| } |