carlos / platform Public

Census R0: deletions become reviewer approvals (test only)

Paul's ruling on #280 (2026-10-25): a removed unit is an approval, since a deletion
cannot add a read. census-propose now handles 'removed' (absent declaration and
sites, proven from the scanned tree and by Lstat with no symlinks), and retires a
deleted directory's envelope with '@coverage <dir> -'. 'new', 'reads', 'other' and
the new 'quiet' class stay decisions. J4 keeps a family's witnesses while any
declared authority row in the full chain names it, and an unparseable family tag
fails. Production code unchanged; AGENTS.md's census section updated. Astra READY
after three rounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from claims-cleanup-r0 into main.
claude agent, operated by paul@keymail.dev 6bead9d524974a8248375742e2e43ffd486cc1bd parent 39cda41
8 files changed, +1,199 −59
  • AGENTS.md +48 −5
  • docs/superpowers/plans/2026-10-25-claims-cleanup-r0.md +80 −0
  • internal/provision/census_propose_internal_test.go +1 −0
  • internal/provision/census_propose_test.go +117 −19
  • internal/provision/census_removal_fs_test.go +266 −0
  • internal/provision/census_removal_test.go +408 −0
  • internal/provision/plan14_input_inventory_test.go +156 −8
  • internal/provision/plan14_root_reads_test.go +123 −27

CI passed — run details

diff --git a/AGENTS.md b/AGENTS.md
index a57f05a58..a05cc3c01 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -237,15 +237,33 @@ approved like this:
- `body`: the digest moved and the reads did not;
- `sites`: more or fewer reads of kinds the unit already makes;
- `envelope`: a package was re-pinned;
+ - `removed`: the scan finds neither the unit's declaration nor any of
+ its sites, or an envelope's directory is gone. A path counts as gone
+ only if it is absent by Lstat: no file, directory or symlink there,
+ and no symlink above it;
- `reads` (a kind of read the unit did not make before), `new`,
- `removed` or `other` (any census discrepancy none of these explains,
- shown with the census's own message): a decision.
+ `quiet` (a unit still declared that reads nothing now, a directory
+ still there with no source the census scans, or a path replaced by a
+ symlink) or `other` (any census
+ discrepancy none of these explains, shown with the census's own
+ message): a decision.
2. Write a CLAIMS file with one line per changed unit:
`<file>:<unit><TAB><what changed, and that no read was added or which one was>`.
+ A claim for a removed unit is optional. A branch that only deletes
+ code can pass an empty file.
3. `make census-propose NAME=<branch> CLAIMS=<file>` writes the rest:
- the overlay (`testdata/plan14-root-reads-<NAME>.tsv`), each unit
re-frozen at its existing disposition with the claim appended;
- - the `@legacy` fingerprints, the envelope re-pins and the new seal;
+ - for each removed unit, `@remove` for its row and, if its declaration
+ was frozen, `@removed` with the basis
+ `census-ruling-<NAME>;absent;basis=<claim>`. That removal holds only
+ while the declaration stays out of the tree, even one that reads
+ nothing;
+ - for each deleted directory, `@coverage <dir> -`, which retires its
+ envelope. The census fails while anything is at that path, even a
+ directory of tests or a symlink;
+ - the `@legacy` fingerprints, the envelope re-pins and the new seal (a
+ deletion alone leaves the seal as it was);
- its line in `testdata/plan14-root-reads-chain.tsv`;
- the approval card, `docs/superpowers/notes/census-proposal-<NAME>.md`.
@@ -263,7 +281,10 @@ approved like this:
the card lists;
- an envelope means every changed function in that package and what
it reaches, since an envelope re-pin is how the census sees reads its
- scanner cannot attribute to a unit.
+ scanner cannot attribute to a unit;
+ - a removed unit or a retired envelope means confirming the code is
+ deleted, not moved, and that no check root relies on goes with it
+ unless its callers' changes on the card account for that.
It escalates if the change lets root open, run, query or follow
anything it did not before from a path or input a tenant, an app or a
@@ -280,7 +301,29 @@ read, not where a read points, so a `body` change can aim an existing
`Open` at a tenant-writable path. Someone other than the author has to
read the diff, but it need not be the owner.
-The tool refuses decisions (`reads`, `new`, `removed`, `other`): a new
+A deletion is an approval, not a decision (Paul, 2026-10-25, ruling 1 on
+#280): a deletion cannot add a read, and the scan, not the claim, proves
+the unit absent. Code that moved is not a deletion. A unit moved whole
+shows as `new`, and a read that moved shows as a change to the unit that
+took it.
+
+J4 (`TestPlan14RootInputInventoryCoverage`) checks its own inventory,
+the 27 overlays up to `activation-tools`, and its caller check covers
+those rows only. A row a later overlay added is never caller-checked. A
+row of J4's inventory is retired when the full chain no longer carries
+it and the tree no longer declares its unit. J4 skips a retired row. A
+row the chain removed whose unit is still declared is still checked. A
+family's witness tests stay required while any authority row in the full
+chain names the family and its unit is still declared. That includes a
+row only a later overlay added. Rows outside J4's scope do not count:
+those tagged only E4 or J1 to J4, and the relocation and activator
+worker files. Once no such
+row names the family, its witnesses may go in the same change. A
+surviving row of J4's inventory with no production caller still fails,
+so a deleting branch removes the row or keeps the caller. An exemption
+for a retired unit fails until it is deleted with the unit.
+
+The tool refuses decisions (`reads`, `new`, `quiet`, `other`): a new
kind of read can make a unit's disposition wrong, so it is the owner's
call, not an approval. Write those rows by hand, following the overlays in the
chain, and ask on #280 with the card attached; the census owner decides
diff --git a/docs/superpowers/plans/2026-10-25-claims-cleanup-r0.md b/docs/superpowers/plans/2026-10-25-claims-cleanup-r0.md
new file mode 100644
index 000000000..489398cff
--- /dev/null
+++ b/docs/superpowers/plans/2026-10-25-claims-cleanup-r0.md
@@ -0,0 +1,80 @@
+# Claims cleanup R0: census removal plumbing
+
+> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [x]`) syntax for tracking.
+
+**Goal:** A deleted unit, frozen declaration or package directory passes the census with an overlay `make census-propose` writes and a reviewer's approval; changed and new reads still fail.
+
+**Architecture:** Test code only, all in `internal/provision`. The scan records every directory it walks, the inventory learns a retired envelope (`@coverage <dir> -`), census-propose treats an absent unit or directory as the approval class `removed`, and J4 drops a row the full chain removed once its declaration is gone.
+
+**Tech Stack:** Go tests in `internal/provision`; the TSV census chain under `internal/provision/testdata`.
+
+**Spec:** Paul's ruling 1 on amadan #280 (2026-10-25); `docs/superpowers/plans/2026-10-25-claims-cleanup.md` row R0; `docs/superpowers/notes/claims-inventory.md` §4 R0 and §5 (on design-live-moves-ha).
+
+## Global Constraints
+
+- Production code unchanged. Only `*_test.go`, testdata and AGENTS.md.
+- The seal chain stays append-only: no existing overlay or seal is edited.
+- `new`, `reads` and `other` stay decisions census-propose refuses.
+- Run census tests under `nice -n 19`, serially, only `internal/provision`.
+- AGENTS.md prose: short sentences, no em dashes.
+
+## Review Focus
+
+- A unit still declared but reading nothing is not a deletion: it stays a decision (new class `quiet`), never `removed`.
+- A directory that lost its scanned files but still exists (tests or testdata left) is not retired: `quiet`, a decision.
+- A retired envelope whose directory comes back fails the census, even if the directory holds only test files.
+- A generated `@removed` row must not tolerate the declaration coming back without reads (the zddr3 H3 rule would): it requires absence.
+- J4 must not stop checking a row the chain removed while its declaration is still in the tree.
+
+---
+
+### Task 1: Retired envelopes
+
+**Files:** Modify `internal/provision/plan14_root_reads_test.go` (`rootReadScan`, `rootReadProduction`, `rootReadInventory`, `loadRootReadInventory`, `compareRootReads`); `census_propose_test.go` (`cloneRootReadInventory`). Test: `plan14_root_reads_test.go`.
+
+**Interfaces:**
+- Produces: `rootReadScan.Dirs map[string]bool` (every walked directory, slash-relative, "." for the root); `rootReadInventory.Retired map[string]bool`; directive `@coverage<TAB><dir><TAB>-` (delta only; refused for an envelope not pinned); compare error `retired root source envelope still present <dir>` when `Dirs == nil || Dirs[dir]`.
+
+- [x] Test `TestPlan14RetiredEnvelope`: an overlay `@coverage internal/gone -` loaded on an inventory pinning `internal/gone` leaves no discrepancy for a scan without that directory; the same scan with `Dirs["internal/gone"]` fails with "retired root source envelope still present"; the directive in a base file, or for an unpinned directory, fails to load; a later `@coverage internal/gone <hash>` clears the retirement.
+- [x] Run it, see it fail; implement; run it, see it pass.
+- [x] Commit; advance the amadan task.
+
+### Task 2: `removed` as an approval in census-propose
+
+**Files:** Modify `internal/provision/census_propose_test.go`, `plan14_root_reads_test.go` (`checkRootReadDeclarations`). Test: `census_propose_internal_test.go`.
+
+**Interfaces:**
+- Consumes: Task 1's `Dirs`, `Retired`, the `-` directive.
+- Produces: class `censusQuiet = "quiet"` (a decision); `censusRemoved` approvable, used only when the scan proves the unit or directory absent; `rootReadAbsentRemoval(removal string) bool`, true for a removal whose basis is `census-ruling-<name>;absent;...`; such a removal fails while the declaration exists, unlike the H3 retire rule.
+- Overlay rows for a removed unit: `@remove<TAB>file<TAB>unit` when classified; for a frozen unit not already removed, `@removed<TAB>file<TAB>unit<TAB><owner><TAB>census-ruling-<NAME>;absent;basis=<claim or "deleted: declaration and sites absent from the tree">`, owner the row's task when it is a kept family, else `H3`. A retired directory: `@coverage<TAB>dir<TAB>-`. Claims for removed units are optional.
+
+- [x] Tests: `TestCensusClassifiesARemovedUnit` keeps `removed` and now also wants `Absent`; `TestCensusClassifiesAQuietUnit` (declared, no reads: `quiet`); `TestCensusProposalRetiresADeletedPackage` (fixture deletes a legacy frozen unit, an authority unit and their directory: the overlay loads, leaves the census clean, keeps the seal, and the card lists both units, their dispositions and the retired envelope); `TestCensusProposalRefusesADeletionWithAChangedRead` (same deletion plus a `reads` change or a new unit elsewhere: refused as a decision); `TestCensusAbsentRemovalNeedsAbsence` (after the generated overlay, the unit's declaration back without reads fails; back with reads fails; the directory back fails).
+- [x] Run, see them fail; implement; run, see them pass, with the existing census-propose tests.
+- [x] Commit; advance the amadan task.
+
+### Task 3: J4 retires a family's rows with its witnesses
+
+**Files:** Modify `internal/provision/plan14_input_inventory_test.go`. Test: same file.
+
+**Interfaces:**
+- Produces: `inputRetired(inv, full rootReadInventory, declared map[string]bool, key string) bool`: true when the full chain no longer carries the row and the tree declares no such unit. `TestPlan14RootInputInventoryCoverage` skips retired rows. `rootReadDeclared(root string) (map[string]bool, error)` names every declaration as the census does, without type-checking.
+
+- [x] Test `TestPlan14J4RetiresAFamily`: family A's every row retired and its witnesses gone: no failure; one surviving A row and a witness gone: fails "missing"; a surviving row with no production caller still fails; a row removed from the chain whose declaration is still in the tree is still checked.
+- [x] Run, see it fail; implement; run it and the J4 coverage test.
+- [x] Commit; advance the amadan task.
+
+### Task 4: AGENTS.md, the experiment, and the gate
+
+**Files:** Modify `AGENTS.md` ("The census").
+
+- [x] Describe `removed` as an approval class, `quiet` as a decision, and the envelope retirement.
+- [x] Experiment (not committed): delete `internal/sim/hostlife`, run census-propose with an empty CLAIMS file, run `TestPlan14RootReadCensus`, restore with `git checkout -- internal/sim/hostlife` plus removing the generated files by exact path, confirm `git status` is clean.
+Result (2026-10-25): deleting `internal/sim/hostlife` gave a card with one removed unit (`mutate.sh`, frozen legacy) and one retired envelope, and an overlay of `@remove`, `@removed` (absent) and `@coverage internal/sim/hostlife -` with the seal unchanged. `TestPlan14RootReadCensus` and J4 both passed on the deleted tree. Restored; `git status` clean. J4's new retired-exemption check caught the roster-binding exemption for the deleted `servingPriorRevision`, which the retirement rule now covers, so that exemption was removed.
+
+- [x] `go vet ./internal/provision/`, the census and census-propose tests, `GOOS=darwin` and `GOOS=windows go build ./...`; push; `amadan ci status carlos/platform -branch claims-cleanup-r0`.
+
+## Review fixes (Astra, NOT READY at 4c85788e)
+
+- P1, J4: a family's witnesses stay required while any in-scope authority row of the full chain names it and its unit is still declared (`inputLiveFamilies`, `checkInputLiveWitnesses`), so a later-only row such as roster-binding's `servingPriorBinding` keeps them. J4's caller check still covers only its 27-overlay inventory. A retired row is not caller-checked.
+- P1, symlinks: a removed unit's file and a retired directory must be absent by Lstat with no symlinked ancestor (`rootReadPathAbsent`), when classifying and when re-checking a retired envelope.
+- P2: `census_removal_fs_test.go` runs `rootReadProduction` over a temp module for deletion, tests left behind, recreation, symlinks and a tagged declaration.
diff --git a/internal/provision/census_propose_internal_test.go b/internal/provision/census_propose_internal_test.go
index 782e197fa..a6e93a9b8 100644
--- a/internal/provision/census_propose_internal_test.go
+++ b/internal/provision/census_propose_internal_test.go
@@ -24,6 +24,7 @@ func proposeFixture(t *testing.T) (rootReadScan, rootReadInventory, string) {
Entries: []rootReadEntry{legacy.rootReadEntry, auth.rootReadEntry},
Declarations: map[string]string{"internal/a/a.go:Wake": legacy.Digest, "internal/a/b.go:Route": auth.Digest},
Coverage: map[string]string{"internal/a": strings.Repeat("c", 64)},
+ Dirs: map[string]bool{".": true, "internal": true, "internal/a": true},
}
return got, inv, rootReadLegacySeal(inv)
}
diff --git a/internal/provision/census_propose_test.go b/internal/provision/census_propose_test.go
index 415fa5501..b73e24b55 100644
--- a/internal/provision/census_propose_test.go
+++ b/internal/provision/census_propose_test.go
@@ -7,9 +7,12 @@ package provision
// This file classifies each discrepancy, writes the overlay that closes the
// approvable ones (rows, @legacy fingerprints, envelope re-pins, the seal,
// the chain manifest line), and the approval card an independent reviewer
-// reads to approve it. Changes that need a disposition (a new unit, a removed one,
-// the scanner's field list) are decisions: it names them and writes
-// nothing.
+// reads to approve it. A deletion is an approval too (Paul's ruling 1 on
+// #280, 2026-10-25): a unit whose declaration the scan no longer finds, and
+// the envelope of a directory that is gone, since a deletion cannot add a
+// read. Changes that need a disposition (a new unit, a unit still declared
+// that stopped reading, the scanner's field list) are decisions: it names
+// them and writes nothing.
//
// make census-card print the card; writes nothing
// make census-propose NAME=<branch> CLAIMS=<file> write the overlay and the card
@@ -28,23 +31,26 @@ import (
"testing"
)
-// Change classes. The first three are approvals; the rest are decisions.
+// Change classes. The first four are approvals; the rest are decisions.
const (
censusBody = "body" // digest moved, the same reads (offsets aside)
censusSites = "sites" // more or fewer reads of kinds the unit already makes
censusEnvelope = "envelope" // a package's source fingerprint moved
+ censusRemoved = "removed" // a unit's declaration, or an envelope's directory, gone from the tree
censusReads = "reads" // a kind of read the unit did not make before
censusNew = "new" // an unclassified unit: needs a disposition
- censusRemoved = "removed" // a unit or envelope gone: needs a removal row
+ censusQuiet = "quiet" // still declared and reads nothing now, or a directory still there with no scanned source
censusOther = "other" // a census discrepancy no change above explains
)
// censusDecision: a new kind of read can make a unit's disposition wrong
// (a registry reader that starts opening files is not the unit that was
-// classified), so it is the owner's call, as a new or removed unit is
-// (Astra review, census-approvals P1).
+// classified), so it is the owner's call, as a new unit is (Astra review,
+// census-approvals P1). So is a unit that stays declared and stops reading:
+// it is not a deletion, so the scan cannot vouch that its reads went with
+// it.
func censusDecision(class string) bool {
- return class == censusReads || class == censusNew || class == censusRemoved || class == censusOther
+ return class == censusReads || class == censusNew || class == censusQuiet || class == censusOther
}
type censusChange struct {
@@ -158,8 +164,16 @@ func classifyRootReads(got rootReadScan, inv rootReadInventory, seal string) []c
// Declared, reads nothing, unchanged: not a discrepancy.
case w.Class != "legacy" && w.Kinds == "" && declared:
cs = append(cs, censusChange{Key: key, Class: censusBody, Before: w, After: rootReadEntry{File: w.File, Unit: w.Unit, Digest: decl}})
- default:
+ case declared:
+ cs = append(cs, censusChange{Key: key, Class: censusQuiet, Before: w, After: rootReadEntry{File: w.File, Unit: w.Unit, Digest: decl}})
+ case got.Files[w.File] || got.absent(w.File):
+ // The scan proves the declaration gone, and every site with it:
+ // its file was read without it, or the file is gone by Lstat.
cs = append(cs, censusChange{Key: key, Class: censusRemoved, Before: w})
+ default:
+ // Not declared, but its file's path is a symlink or behind one,
+ // or otherwise unproven: not a deletion the scan can vouch for.
+ cs = append(cs, censusChange{Key: key, Class: censusQuiet, Before: w, After: rootReadEntry{File: w.File, Unit: w.Unit}})
}
}
for dir, hash := range got.Coverage {
@@ -169,7 +183,11 @@ func classifyRootReads(got rootReadScan, inv rootReadInventory, seal string) []c
}
for dir, hash := range inv.Coverage {
if _, ok := got.Coverage[dir]; !ok {
- cs = append(cs, censusChange{Key: dir, Class: censusRemoved, OldHash: hash})
+ class := censusRemoved
+ if !got.absent(dir) {
+ class = censusQuiet
+ }
+ cs = append(cs, censusChange{Key: dir, Class: class, OldHash: hash})
}
}
keys := map[string]bool{}
@@ -236,9 +254,13 @@ var censusName = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
// proposeRootReads writes the overlay that closes every change in the scan,
// re-freezing each changed unit at the disposition it already has with its
-// claim appended, under census-ruling-<name>. It refuses decisions, a
-// change with no claim and a claim for no change, and checks its own work:
-// loaded onto a copy of inv, the overlay must leave the census clean.
+// claim appended, under census-ruling-<name>. A removed unit loses its row
+// (@remove) and, if frozen, has its declaration retired (@removed, with the
+// absent mark rootReadAbsentRemoval checks); a removed directory has its
+// envelope retired (@coverage <dir> -). It refuses decisions, a body or
+// sites change with no claim and a claim for no change (a removed unit's
+// claim is optional), and checks its own work: loaded onto a copy of inv,
+// the overlay must leave the census clean.
func proposeRootReads(got rootReadScan, inv rootReadInventory, seal, name string, claims map[string]string) (rootReadProposal, error) {
if !censusName.MatchString(name) {
return rootReadProposal{}, fmt.Errorf("census name %q: want lower-case letters, digits and dashes", name)
@@ -257,6 +279,12 @@ func proposeRootReads(got rootReadScan, inv rootReadInventory, seal, name string
units[c.Key] = true
}
}
+ removed := map[string]bool{}
+ for _, c := range cs {
+ if c.Class == censusRemoved && c.OldHash == "" {
+ removed[c.Key] = true
+ }
+ }
if len(decisions) > 0 {
return rootReadProposal{}, fmt.Errorf("a decision is needed, not an approval: %s; write those rows by hand and ask on #280", strings.Join(decisions, "; "))
}
@@ -266,7 +294,7 @@ func proposeRootReads(got rootReadScan, inv rootReadInventory, seal, name string
}
}
for key, claim := range claims {
- if !units[key] {
+ if !units[key] && !removed[key] {
return rootReadProposal{}, fmt.Errorf("claim for %s: not a change the census sees", key)
}
if strings.ContainsAny(claim, "\t\n\r") {
@@ -275,7 +303,7 @@ func proposeRootReads(got rootReadScan, inv rootReadInventory, seal, name string
}
ruling := "census-ruling-" + name
- var frozen, plain, cover []string
+ var frozen, plain, gone, cover []string
counts := map[string]int{}
for _, c := range cs {
counts[c.Class]++
@@ -283,6 +311,26 @@ func proposeRootReads(got rootReadScan, inv rootReadInventory, seal, name string
cover = append(cover, "@coverage\t"+c.Key+"\t"+c.NewHash)
continue
}
+ if c.Class == censusRemoved && c.OldHash != "" {
+ cover = append(cover, "@coverage\t"+c.Key+"\t-")
+ continue
+ }
+ if c.Class == censusRemoved {
+ b := c.Before
+ gone = append(gone, "@remove\t"+b.File+"\t"+b.Unit)
+ if _, isFrozen := inv.Frozen[c.Key]; isFrozen && inv.Removed[c.Key] == "" {
+ owner := "H3"
+ if rootReadKeptTask(b.Task) {
+ owner = b.Task
+ }
+ claim := strings.TrimSpace(claims[c.Key])
+ if claim == "" {
+ claim = "deleted: declaration and sites absent from the tree"
+ }
+ gone = append(gone, "@removed\t"+b.File+"\t"+b.Unit+"\t"+owner+"\t"+ruling+";"+censusAbsentMark+";basis="+claim)
+ }
+ continue
+ }
e := classifiedRootRead{rootReadEntry: c.After, Class: c.Before.Class, Task: c.Before.Task, Basis: c.Before.Basis + ";rev3=" + ruling + ";basis=" + strings.TrimSpace(claims[c.Key])}
row := strings.Join([]string{e.File, e.Unit, e.Class, e.Task, e.Basis, e.Kinds, e.Digest}, "\t")
if e.Class == "legacy" {
@@ -294,7 +342,11 @@ func proposeRootReads(got rootReadScan, inv rootReadInventory, seal, name string
fmt.Sprintf("# Census overlay %s, "+censusProposeMark+". %s, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-%s.md.", name, ruling, name),
fmt.Sprintf("# %d body, %d sites, %d envelope: each changed unit re-frozen at its existing disposition with its claim appended.", counts[censusBody], counts[censusSites], counts[censusEnvelope]),
}
- overlay := strings.Join(append(append(append(header, frozen...), plain...), cover...), "\n") + "\n"
+ if counts[censusRemoved] > 0 {
+ header = append(header, fmt.Sprintf("# %d removed: each unit's declaration, or each envelope's directory, is absent from the scanned tree, so its row goes, a frozen declaration is retired as absent, and an envelope is retired.", counts[censusRemoved]))
+ }
+ lines := append(append(append(append(header, frozen...), plain...), gone...), cover...)
+ overlay := strings.Join(lines, "\n") + "\n"
after := cloneRootReadInventory(inv)
f, err := os.CreateTemp("", "census-overlay-*.tsv")
@@ -332,14 +384,18 @@ func rootReadCard(name string, cs []censusChange, claims map[string]string, seal
var b strings.Builder
fmt.Fprintf(&b, "# Census approval: %s\n\n", name)
var decisions []censusChange
- var envelopes []string
- var units []censusChange
+ var envelopes, retired []string
+ var units, removed []censusChange
for _, c := range cs {
switch {
case censusDecision(c.Class):
decisions = append(decisions, c)
case c.Class == censusEnvelope:
envelopes = append(envelopes, "`"+c.Key+"`")
+ case c.Class == censusRemoved && c.OldHash != "":
+ retired = append(retired, "`"+c.Key+"`")
+ case c.Class == censusRemoved:
+ removed = append(removed, c)
default:
units = append(units, c)
}
@@ -367,9 +423,26 @@ func rootReadCard(name string, cs []censusChange, claims map[string]string, seal
if len(envelopes) > 0 {
fmt.Fprintf(&b, "Envelopes re-pinned: %s.\n\n", strings.Join(envelopes, ", "))
}
- if len(units) > 0 || len(envelopes) > 0 {
+ if len(removed) > 0 {
+ b.WriteString("Removed units: the scan finds neither the declaration nor any of its sites.\n\n| unit | recorded disposition | basis | what changed |\n|---|---|---|---|\n")
+ for _, c := range removed {
+ claim := strings.TrimSpace(claims[c.Key])
+ if claim == "" {
+ claim = "deleted"
+ }
+ fmt.Fprintf(&b, "| `%s` `%s` | %s, task %s | %s | %s |\n", c.Before.File, c.Before.Unit, c.Before.Class, c.Before.Task, c.Before.Basis, claim)
+ }
+ b.WriteString("\n")
+ }
+ if len(retired) > 0 {
+ fmt.Fprintf(&b, "Envelopes retired: %s. Each directory is gone from the tree.\n\n", strings.Join(retired, ", "))
+ }
+ if len(units) > 0 || len(envelopes) > 0 || len(removed) > 0 || len(retired) > 0 {
b.WriteString(censusReviewQuestion)
}
+ if len(removed) > 0 || len(retired) > 0 {
+ b.WriteString(censusRemovalQuestion)
+ }
if len(units) > 0 {
b.WriteString("Recorded dispositions, which each change must still satisfy:\n\n")
for _, c := range units {
@@ -403,6 +476,30 @@ func rootReadCard(name string, cs []censusChange, claims map[string]string, seal
// approvals on a card (AGENTS.md, The census).
const censusReviewQuestion = "Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Escalate if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. An escalation goes to the census owner as a decision.\n\n"
+// censusRemovalQuestion is what the reviewer answers for removed units and
+// retired envelopes on a card: a deletion cannot add a read, but code can
+// move, and a check root relied on can go with the code that held it.
+const censusRemovalQuestion = "A removed unit's recorded disposition and basis are in its table above. For a removed unit or a retired envelope, confirm from the diff that the code is deleted and not moved: a read that moved shows on this card as a change to the unit that took it, and a unit moved whole shows as a new unit, a decision. Escalate if a check, refusal or validation that root relies on goes with the deleted code and its callers' changes on this card do not account for that.\n\n"
+
+// censusAbsentMark follows the ruling in the basis of an @removed row
+// census-propose writes: the declaration must stay out of the tree
+// (rootReadAbsentRemoval).
+const censusAbsentMark = "absent"
+
+// rootReadAbsentRemoval reports whether a removal (owner;basis, as
+// inv.Removed holds it) is one census-propose wrote for a deleted unit:
+// basis census-ruling-<name>;absent[;...]. Such a removal holds only while
+// the scan finds no declaration, unlike the H3 retirement of a unit still
+// declared that reads nothing (census ruling zddr3).
+func rootReadAbsentRemoval(removal string) bool {
+ _, basis, _ := strings.Cut(removal, ";")
+ ruling, rest, ok := strings.Cut(basis, ";")
+ if !ok || !strings.HasPrefix(ruling, "census-ruling-") || !censusName.MatchString(strings.TrimPrefix(ruling, "census-ruling-")) {
+ return false
+ }
+ return rest == censusAbsentMark || strings.HasPrefix(rest, censusAbsentMark+";")
+}
+
// censusProposeMark is in the first line of every overlay census-propose
// writes: a re-run replaces only a file that carries it.
const censusProposeMark = "written by census-propose (#369)"
@@ -415,6 +512,7 @@ func cloneRootReadInventory(inv rootReadInventory) rootReadInventory {
out.Frozen = cloneMap(inv.Frozen)
out.Removed = cloneMap(inv.Removed)
out.Coverage = cloneMap(inv.Coverage)
+ out.Retired = cloneMap(inv.Retired)
out.Legacy = cloneMap(inv.Legacy)
return out
}
diff --git a/internal/provision/census_removal_fs_test.go b/internal/provision/census_removal_fs_test.go
new file mode 100644
index 000000000..a60c1871e
--- /dev/null
+++ b/internal/provision/census_removal_fs_test.go
@@ -0,0 +1,266 @@
+package provision
+
+// Census removals through the real scanner (Astra review of R0, P1 and
+// P2): a temp module scanned by rootReadProduction, so the absence proof
+// is the scanner's and the filesystem's, not a cleared map. A retired or
+// removed path must be absent by Lstat: no file, directory or symlink
+// there, and no symlinked ancestor.
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+func writeTree(t *testing.T, root string, files map[string]string) {
+ t.Helper()
+ for name, body := range files {
+ path := filepath.Join(root, filepath.FromSlash(name))
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+// removalTree is a small module: a kept package, a package to delete (a Go
+// unit and a shell helper, both frozen legacy, and a test file), a package
+// whose one unit is declared per GOOS, and a helper under testdata, which
+// the scanner skips, for a symlink to point at.
+func removalTree(t *testing.T) string {
+ t.Helper()
+ // The temp module may sit inside someone's git tree; the census's own
+ // run (the Makefile) disables VCS stamping the same way.
+ t.Setenv("GOFLAGS", "-buildvcs=false")
+ root := t.TempDir()
+ tagged := func(goos string) string {
+ return "//go:build " + goos + "\n\npackage tagged\n\nimport \"os\"\n\nfunc L() { os.Stat(\"/data/" + goos + "\") }\n"
+ }
+ writeTree(t, root, map[string]string{
+ "go.mod": "module fixture/root\n\ngo 1.24\n",
+ "main.go": "package main\n\nfunc main() {}\n",
+ "internal/keep/keep.go": "package keep\n\nimport \"os\"\n\nfunc Read() ([]byte, error) { return os.ReadFile(\"/data/keep\") }\n",
+ "internal/gone/gone.go": "package gone\n\nimport \"os\"\n\nfunc Gone() ([]byte, error) { return os.ReadFile(\"/data/gone\") }\n",
+ "internal/gone/run.sh": "cat /data/gone\n",
+ "internal/gone/gone_test.go": "package gone\n\nimport \"testing\"\n\nfunc TestGone(t *testing.T) {}\n",
+ "internal/tagged/t_linux.go": tagged("linux"),
+ "internal/tagged/t_darwin.go": tagged("darwin"),
+ "internal/tagged/t_windows.go": tagged("windows"),
+ "testdata/helper/run.sh": "cat /data/elsewhere\n",
+ "testdata/helper/gone.go": "package gone\n\nimport \"os\"\n\nfunc Gone() ([]byte, error) { return os.ReadFile(\"/data/elsewhere\") }\n",
+ })
+ return root
+}
+
+func scanTree(t *testing.T, root string) rootReadScan {
+ t.Helper()
+ got, err := rootReadProduction(root)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return got
+}
+
+// inventoryOf classifies a clean scan: the units in legacy as frozen
+// accepted-legacy, the rest as authority, every envelope pinned.
+func inventoryOf(scan rootReadScan, legacy ...string) (rootReadInventory, string) {
+ frozen := map[string]bool{}
+ for _, k := range legacy {
+ frozen[k] = true
+ }
+ inv := rootReadInventory{Entries: map[string]classifiedRootRead{}, Frozen: map[string]classifiedRootRead{}, Legacy: map[string]bool{}, Coverage: cloneMap(scan.Coverage), Fields: strings.Join(scan.Fields, ",")}
+ for _, e := range scan.Entries {
+ key := e.File + ":" + e.Unit
+ c := classifiedRootRead{rootReadEntry: e, Class: "authority", Task: "E4", Basis: "fixture"}
+ if frozen[key] {
+ c = classifiedRootRead{rootReadEntry: e, Class: "legacy", Task: "accepted-legacy", Basis: "accepted-legacy;rev3=J1;basis=fixture"}
+ inv.Frozen[key] = c
+ inv.Legacy[rootReadLegacyFingerprint(c)] = true
+ }
+ inv.Entries[key] = c
+ }
+ return inv, rootReadLegacySeal(inv)
+}
+
+const (
+ goneUnit = "internal/gone/gone.go:Gone"
+ goneShell = "internal/gone/run.sh:external"
+)
+
+func TestCensusRemovalThroughTheScanner(t *testing.T) {
+ root := removalTree(t)
+ base := scanTree(t, root)
+ for _, k := range []string{goneUnit, goneShell, "internal/tagged/t_linux.go:L", "internal/tagged/t_darwin.go:L", "internal/tagged/t_windows.go:L"} {
+ if !rootReadScanned(base, k) {
+ t.Fatalf("the scan lacks %s: %v", k, base.Entries)
+ }
+ }
+ inv, seal := inventoryOf(base, goneUnit, goneShell)
+ if errs := censusDiscrepancies(base, inv, seal); len(errs) != 0 {
+ t.Fatalf("fixture census: %v", errs)
+ }
+ gone := filepath.Join(root, "internal/gone")
+ helper := filepath.Join(root, "testdata/helper")
+ if err := os.RemoveAll(gone); err != nil {
+ t.Fatal(err)
+ }
+
+ got := scanTree(t, root)
+ classes := classesOf(classifyRootReads(got, inv, seal))
+ for _, k := range []string{goneUnit, goneShell, "internal/gone"} {
+ if classes[k] != censusRemoved {
+ t.Fatalf("class of %s = %q (all %v)", k, classes[k], classes)
+ }
+ }
+ p, err := proposeRootReads(got, inv, seal, "drop-gone", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ 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 || p.Seal != seal {
+ t.Fatalf("after the overlay: %v (seal %s, was %s)\n%s", errs, p.Seal, seal, p.Overlay)
+ }
+
+ // After the retirement, each way back fails the census.
+ for name, back := range map[string]func(){
+ "a tests-only directory": func() {
+ writeTree(t, root, map[string]string{"internal/gone/gone_test.go": "package gone\n"})
+ },
+ "the directory with its source": func() {
+ writeTree(t, root, map[string]string{"internal/gone/gone.go": "package gone\n\nfunc Gone() {}\n"})
+ },
+ "a symlink to a directory the scanner skips": func() {
+ if err := os.Symlink(helper, gone); err != nil {
+ t.Fatal(err)
+ }
+ },
+ "a symlink to nowhere": func() {
+ if err := os.Symlink(filepath.Join(root, "nowhere"), gone); err != nil {
+ t.Fatal(err)
+ }
+ },
+ } {
+ t.Run(name, func(t *testing.T) {
+ back()
+ defer os.RemoveAll(gone)
+ again := scanTree(t, root)
+ errs := censusDiscrepancies(again, after, p.Seal)
+ if !containsPrefix(errs, "retired root source envelope still present internal/gone") {
+ t.Fatalf("came back unseen: %v", errs)
+ }
+ })
+ }
+ // The symlinked helper's shell file is invisible to the walk: the
+ // census sees the resurrection only through the Lstat proof.
+ if err := os.Symlink(helper, gone); err != nil {
+ t.Fatal(err)
+ }
+ if again := scanTree(t, root); rootReadScanned(again, goneShell) || again.Dirs["internal/gone"] {
+ t.Fatalf("the walk followed the symlink; this test no longer pins the Lstat proof")
+ }
+}
+
+// Replacing a directory with a symlink, or leaving its tests behind, is
+// not a deletion: quiet, a decision census-propose refuses.
+func TestCensusRemovalRefusesWhatIsStillThere(t *testing.T) {
+ for name, edit := range map[string]func(t *testing.T, root string){
+ "replaced by a symlink": func(t *testing.T, root string) {
+ if err := os.RemoveAll(filepath.Join(root, "internal/gone")); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink(filepath.Join(root, "testdata/helper"), filepath.Join(root, "internal/gone")); err != nil {
+ t.Fatal(err)
+ }
+ },
+ "its tests left behind": func(t *testing.T, root string) {
+ for _, f := range []string{"internal/gone/gone.go", "internal/gone/run.sh"} {
+ if err := os.Remove(filepath.Join(root, f)); err != nil {
+ t.Fatal(err)
+ }
+ }
+ },
+ } {
+ t.Run(name, func(t *testing.T) {
+ root := removalTree(t)
+ inv, seal := inventoryOf(scanTree(t, root), goneUnit, goneShell)
+ edit(t, root)
+ got := scanTree(t, root)
+ classes := classesOf(classifyRootReads(got, inv, seal))
+ if classes["internal/gone"] != censusQuiet {
+ t.Fatalf("envelope class %q (all %v)", classes["internal/gone"], classes)
+ }
+ if name == "replaced by a symlink" && (classes[goneUnit] != censusQuiet || classes[goneShell] != censusQuiet) {
+ t.Fatalf("units behind a symlinked directory: %v", classes)
+ }
+ if _, err := proposeRootReads(got, inv, seal, "x", nil); err == nil || !strings.Contains(err.Error(), "decision") {
+ t.Fatalf("err = %v, want a decision", err)
+ }
+ })
+ }
+}
+
+// One GOOS's declaration deleted: that unit is removed, the package's
+// envelope re-pinned, and the other two stay as they were.
+func TestCensusRemovalOfATaggedDeclaration(t *testing.T) {
+ root := removalTree(t)
+ inv, seal := inventoryOf(scanTree(t, root), goneUnit, goneShell)
+ if err := os.Remove(filepath.Join(root, "internal/tagged/t_darwin.go")); err != nil {
+ t.Fatal(err)
+ }
+ got := scanTree(t, root)
+ classes := classesOf(classifyRootReads(got, inv, seal))
+ want := map[string]string{"internal/tagged/t_darwin.go:L": censusRemoved, "internal/tagged": censusEnvelope}
+ if len(classes) != len(want) || classes["internal/tagged/t_darwin.go:L"] != censusRemoved || classes["internal/tagged"] != censusEnvelope {
+ t.Fatalf("classes %v, want %v", classes, want)
+ }
+ p, err := proposeRootReads(got, inv, seal, "drop-darwin", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ 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)
+ }
+}
+
+func TestRootReadPathAbsent(t *testing.T) {
+ root := t.TempDir()
+ writeTree(t, root, map[string]string{"real/x": "x", "target/x": "x", "file": "f"})
+ if err := os.Symlink(filepath.Join(root, "target"), filepath.Join(root, "link")); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink(filepath.Join(root, "nowhere"), filepath.Join(root, "dangling")); err != nil {
+ t.Fatal(err)
+ }
+ for rel, want := range map[string]bool{
+ "none": true,
+ "none/x": true,
+ "real/none": true,
+ "real": false,
+ "real/x": false,
+ "link": false,
+ "link/x": false,
+ "link/none": false,
+ "dangling": false,
+ "dangling/x": false,
+ "file/x": false,
+ "real/../x": false,
+ "": false,
+ "/abs": false,
+ "real//none": false,
+ "./real/none": false,
+ } {
+ if got := rootReadPathAbsent(root, rel); got != want {
+ t.Errorf("rootReadPathAbsent(%q) = %v, want %v", rel, got, want)
+ }
+ }
+}
diff --git a/internal/provision/census_removal_test.go b/internal/provision/census_removal_test.go
new file mode 100644
index 000000000..70727fd03
--- /dev/null
+++ b/internal/provision/census_removal_test.go
@@ -0,0 +1,408 @@
+package provision
+
+// Census removals (claims cleanup R0; Paul's ruling 1 on #280, 2026-10-25):
+// a removed unit, a retired frozen declaration and a deleted directory's
+// envelope are approvals when the scan proves them absent, since a deletion
+// cannot add a read. These tests pin the retired envelope, the generated
+// removal rows and what still fails.
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+func writeOverlay(t *testing.T, body string) string {
+ t.Helper()
+ path := filepath.Join(t.TempDir(), "overlay.tsv")
+ if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ return path
+}
+
+// @coverage <dir> - retires the envelope of a directory that is gone. It
+// is refused while the directory is still in the tree, even holding only
+// tests, and a later pin brings the envelope back.
+func TestPlan14RetiredEnvelope(t *testing.T) {
+ pinned := func() rootReadInventory {
+ return rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{"internal/gone": strings.Repeat("c", 64), "internal/kept": strings.Repeat("d", 64)}, Fields: ""}
+ }
+ scan := rootReadScan{Coverage: map[string]string{"internal/kept": strings.Repeat("d", 64)}, Dirs: map[string]bool{".": true, "internal": true, "internal/kept": true}}
+
+ inv := pinned()
+ if errs := compareRootReads(scan, inv); len(errs) != 1 || !strings.Contains(errs[0], "stale root source envelope internal/gone") {
+ t.Fatalf("before the retirement: %v", errs)
+ }
+ if err := loadRootReadInventory(writeOverlay(t, "@coverage\tinternal/gone\t-\n"), &inv, true); err != nil {
+ t.Fatal(err)
+ }
+ if errs := compareRootReads(scan, inv); len(errs) != 0 {
+ t.Fatalf("retired envelope of a deleted directory: %v", errs)
+ }
+
+ // The directory is still there (only tests left, say): refused.
+ present := scan
+ present.Dirs = map[string]bool{".": true, "internal": true, "internal/kept": true, "internal/gone": true}
+ if errs := compareRootReads(present, inv); len(errs) != 1 || errs[0] != "retired root source envelope still present internal/gone" {
+ t.Fatalf("retired envelope of a present directory: %v", errs)
+ }
+ // A scan that walked no directories proves nothing.
+ unwalked := scan
+ unwalked.Dirs = nil
+ if errs := compareRootReads(unwalked, inv); len(errs) != 1 {
+ t.Fatalf("retired envelope with no directory list: %v", errs)
+ }
+ // The directory back with source: changed, and still retired.
+ back := present
+ back.Coverage = map[string]string{"internal/kept": strings.Repeat("d", 64), "internal/gone": strings.Repeat("e", 64)}
+ if errs := compareRootReads(back, inv); len(errs) != 2 {
+ t.Fatalf("retired directory back with source: %v", errs)
+ }
+ // A later pin ends the retirement.
+ if err := loadRootReadInventory(writeOverlay(t, "@coverage\tinternal/gone\t"+strings.Repeat("e", 64)+"\n"), &inv, true); err != nil {
+ t.Fatal(err)
+ }
+ if errs := compareRootReads(back, inv); len(errs) != 0 {
+ t.Fatalf("re-pinned envelope: %v", errs)
+ }
+
+ for name, tc := range map[string]struct {
+ body string
+ delta bool
+ }{
+ "in the base": {"@coverage\tinternal/gone\t-\n", false},
+ "of an unpinned dir": {"@coverage\tinternal/never\t-\n", true},
+ "twice in one overlay": {"@coverage\tinternal/gone\t-\n@coverage\tinternal/gone\t-\n", true},
+ } {
+ t.Run(name, func(t *testing.T) {
+ inv := pinned()
+ if err := loadRootReadInventory(writeOverlay(t, tc.body), &inv, tc.delta); err == nil {
+ t.Fatal("retirement loaded")
+ }
+ })
+ }
+}
+
+// deletePackage edits the fixture scan as deleting internal/a would: both
+// units, their declarations, the envelope and the directory are gone.
+func deletePackage(got *rootReadScan) {
+ got.Entries = nil
+ got.Declarations = map[string]string{}
+ got.Coverage = map[string]string{}
+ got.Dirs = map[string]bool{".": true, "internal": true}
+}
+
+func classesOf(cs []censusChange) map[string]string {
+ out := map[string]string{}
+ for _, c := range cs {
+ out[c.Key] = c.Class
+ }
+ return out
+}
+
+// A unit gone from the tree is removed, an approval; a unit still declared
+// that reads nothing now is quiet, a decision, as is a directory that lost
+// its source but is still there.
+func TestCensusClassifiesRemovedAndQuiet(t *testing.T) {
+ got, inv, seal := proposeFixture(t)
+ deletePackage(&got)
+ want := map[string]string{"internal/a/a.go:Wake": censusRemoved, "internal/a/b.go:Route": censusRemoved, "internal/a": censusRemoved}
+ if classes := classesOf(classifyRootReads(got, inv, seal)); len(classes) != len(want) {
+ t.Fatalf("classes = %v, want %v", classes, want)
+ } else {
+ for k, v := range want {
+ if classes[k] != v {
+ t.Errorf("class of %s = %q, want %q", k, classes[k], v)
+ }
+ }
+ }
+ if censusDecision(censusRemoved) || !censusDecision(censusQuiet) {
+ t.Fatal("removed must be an approval and quiet a decision")
+ }
+
+ quiet, inv, seal := proposeFixture(t)
+ quiet.Entries = quiet.Entries[1:]
+ quiet.Declarations["internal/a/a.go:Wake"] = strings.Repeat("7", 64)
+ delete(quiet.Coverage, "internal/a")
+ classes := classesOf(classifyRootReads(quiet, inv, seal))
+ if classes["internal/a/a.go:Wake"] != censusQuiet || classes["internal/a"] != censusQuiet {
+ t.Fatalf("still declared, or a directory still there: %v", classes)
+ }
+ if _, err := proposeRootReads(quiet, inv, seal, "x", nil); err == nil || !strings.Contains(err.Error(), "decision") {
+ t.Fatalf("quiet proposed: %v", err)
+ }
+}
+
+// Deleting a package is the whole job: the overlay census-propose writes
+// loads, leaves the census clean under the same seal, names the ruling on
+// every removal and retires the envelope, and the card lists each removed
+// unit with its disposition for the reviewer.
+func TestCensusProposalRetiresADeletedPackage(t *testing.T) {
+ got, inv, seal := proposeFixture(t)
+ deletePackage(&got)
+ if len(censusDiscrepancies(got, inv, seal)) == 0 {
+ t.Fatal("the deletion made no discrepancy")
+ }
+ p, err := proposeRootReads(got, inv, seal, "drop-a", map[string]string{"internal/a/a.go:Wake": "deleted with internal/a; the wake moved nowhere"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ after := cloneRootReadInventory(inv)
+ if err := loadRootReadInventory(writeOverlay(t, p.Overlay), &after, true); err != nil {
+ t.Fatalf("%v\n%s", err, p.Overlay)
+ }
+ if errs := censusDiscrepancies(got, after, p.Seal); len(errs) != 0 {
+ t.Fatalf("after the proposal: %v\n%s", errs, p.Overlay)
+ }
+ if p.Seal != seal {
+ t.Errorf("a deletion moved the seal: %s -> %s", seal, p.Seal)
+ }
+ for _, line := range []string{
+ "@remove\tinternal/a/a.go\tWake",
+ "@removed\tinternal/a/a.go\tWake\tH3\tcensus-ruling-drop-a;absent;basis=deleted with internal/a; the wake moved nowhere",
+ "@remove\tinternal/a/b.go\tRoute",
+ "@coverage\tinternal/a\t-",
+ } {
+ if !strings.Contains(p.Overlay, line+"\n") {
+ t.Errorf("overlay lacks %q:\n%s", line, p.Overlay)
+ }
+ }
+ // Route was never frozen: its row goes, and no @removed is written.
+ if strings.Contains(p.Overlay, "@removed\tinternal/a/b.go") {
+ t.Errorf("an unfrozen unit got a frozen removal:\n%s", p.Overlay)
+ }
+ for _, want := range []string{"internal/a/a.go", "Wake", "internal/a/b.go", "Route", "accepted-legacy;rev3=J1;basis=root-route", "root-route", "Envelopes retired: `internal/a`", censusRemovalQuestion, "deleted with internal/a"} {
+ if !strings.Contains(p.Card, want) {
+ t.Errorf("card lacks %q:\n%s", want, p.Card)
+ }
+ }
+ if !strings.Contains(p.Card, "needs an approval, not a decision") {
+ t.Errorf("card:\n%s", p.Card)
+ }
+}
+
+// A deletion beside a changed or new read is still refused: census-propose
+// writes nothing while any decision is on the card.
+func TestCensusProposalRefusesADeletionWithAChangedRead(t *testing.T) {
+ for name, edit := range map[string]func(*rootReadScan){
+ "a new kind of read in a surviving unit": func(g *rootReadScan) {
+ g.Entries = g.Entries[:1]
+ delete(g.Declarations, "internal/a/b.go:Route")
+ change(g, "internal/a/a.go:Wake", "registry:Host@10,registry:DBPath@20,file:Open@30", strings.Repeat("8", 64))
+ },
+ "the deleted unit's name back in another file": func(g *rootReadScan) {
+ deletePackage(g)
+ g.Entries = []rootReadEntry{{File: "internal/z/b.go", Unit: "Route", Kinds: "registry:Host@5", Digest: strings.Repeat("2", 64)}}
+ g.Declarations["internal/z/b.go:Route"] = strings.Repeat("2", 64)
+ g.Coverage["internal/z"] = strings.Repeat("f", 64)
+ g.Dirs["internal/z"] = true
+ },
+ } {
+ t.Run(name, func(t *testing.T) {
+ got, inv, seal := proposeFixture(t)
+ edit(&got)
+ if _, err := proposeRootReads(got, inv, seal, "x", nil); err == nil || !strings.Contains(err.Error(), "decision") {
+ t.Fatalf("err = %v, want a decision", err)
+ }
+ })
+ }
+}
+
+// A generated removal holds only while the unit stays gone. Unlike the H3
+// census-ruling retirement (zddr3), it does not tolerate the declaration
+// coming back with no read; back with a read is unclassified; the
+// directory back fails its retired envelope.
+func TestCensusAbsentRemovalNeedsAbsence(t *testing.T) {
+ got, inv, seal := proposeFixture(t)
+ deletePackage(&got)
+ p, err := proposeRootReads(got, inv, seal, "drop-a", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ after := cloneRootReadInventory(inv)
+ if err := loadRootReadInventory(writeOverlay(t, p.Overlay), &after, true); err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(p.Overlay, "census-ruling-drop-a;absent;basis=deleted: declaration and sites absent from the tree") {
+ t.Errorf("default removal basis:\n%s", p.Overlay)
+ }
+ for name, edit := range map[string]func(*rootReadScan){
+ "declared again, no read": func(g *rootReadScan) {
+ g.Declarations["internal/a/a.go:Wake"] = strings.Repeat("9", 64)
+ g.Dirs["internal/a"] = true
+ g.Coverage["internal/a"] = strings.Repeat("9", 64)
+ },
+ "declared again, reading": func(g *rootReadScan) {
+ g.Declarations["internal/a/b.go:Route"] = strings.Repeat("2", 64)
+ g.Entries = []rootReadEntry{{File: "internal/a/b.go", Unit: "Route", Kinds: "registry:Host@5", Digest: strings.Repeat("2", 64)}}
+ },
+ "the directory back, tests only": func(g *rootReadScan) {
+ g.Dirs["internal/a"] = true
+ },
+ } {
+ t.Run(name, func(t *testing.T) {
+ g := got
+ g.Declarations, g.Coverage, g.Dirs = cloneMap(got.Declarations), cloneMap(got.Coverage), cloneMap(got.Dirs)
+ edit(&g)
+ if errs := censusDiscrepancies(g, after, p.Seal); len(errs) == 0 {
+ t.Fatal("accepted")
+ }
+ })
+ }
+ // The removal's own check, apart from the envelope: a frozen absent
+ // removal refuses a quiet declaration that H3's retirement would pass.
+ key := "internal/a/a.go:Wake"
+ quiet := rootReadScan{Declarations: map[string]string{key: strings.Repeat("9", 64)}}
+ if errs := checkRootReadDeclarations(quiet, after); len(errs) != 1 || errs[0] != "removed legacy declaration still present "+key {
+ t.Fatalf("absent removal with the declaration back: %v", errs)
+ }
+ h3 := cloneRootReadInventory(after)
+ h3.Removed[key] = "H3;census-ruling-drop-a: still declared, and reads nothing now"
+ if errs := checkRootReadDeclarations(quiet, h3); len(errs) != 0 {
+ t.Fatalf("the H3 retirement changed: %v", errs)
+ }
+ for removal, want := range map[string]bool{
+ "H3;census-ruling-drop-a;absent;basis=x": true,
+ "C,J4;census-ruling-drop-a;absent": true,
+ "H3;census-ruling-drop-a: absent": false,
+ "H3;drop-a;absent;basis=x": false,
+ "H3;census-ruling-drop-a;absentee": false,
+ } {
+ if rootReadAbsentRemoval(removal) != want {
+ t.Errorf("rootReadAbsentRemoval(%q) = %v, want %v", removal, !want, want)
+ }
+ }
+}
+
+// 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)...)
+ }
+ live, liveErrs := inputLiveFamilies(full, func(k string) bool { return declared[k] })
+ failures = append(failures, liveErrs...)
+ failures = append(failures, checkInputLiveWitnesses(live, 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)
+ }
+ // A row only a later overlay added (outside J4's inventory) still names
+ // family A and is still declared: A's witnesses stay required (Astra
+ // review of R0, P1; servingPriorBinding in roster-binding is one).
+ later := row("internal/z/later.go", "Bind", "A,J4")
+ if errs := check(carried(b, later), map[string]bool{key(b): true, key(later): true}, nil); !containsPrefix(errs, "family A missing") {
+ t.Fatalf("a later-only surviving row lost its witnesses: %v", errs)
+ }
+ // A tag J4 does not know beside a family it does: the census accepts
+ // the row for its one recognized owner, so J4 fails on the tag and
+ // still keeps A's witnesses (Astra review of R0, round 2).
+ mixed := row("internal/z/later.go", "Mixed", "A,J4,unknown")
+ errs = check(carried(b, mixed), map[string]bool{key(b): true, key(mixed): true}, nil)
+ if !containsPrefix(errs, key(mixed)+": unknown family") || !containsPrefix(errs, "family A missing") {
+ t.Fatalf("a later-only row with an unknown tag: %v", errs)
+ }
+ // Deleted too, it no longer holds them.
+ if errs := check(carried(b, later), map[string]bool{key(b): true}, nil); len(errs) != 0 {
+ t.Fatalf("a deleted later-only row: %v", errs)
+ }
+ // Only J4's scope counts: a later row of E4 and J tags alone names no family.
+ scoped := row("internal/z/later.go", "Grant", "E4,J4")
+ if live, errs := inputLiveFamilies(carried(scoped), func(string) bool { return true }); len(live) != 0 || len(errs) != 0 {
+ t.Fatalf("an out-of-scope row named families: %v %v", live, 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..d13f3635e 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,127 @@ 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 retired row is
+// not caller-checked (its unit is gone); its family's witnesses stay
+// required while inputLiveFamilies still names the family.
+func inputRetired(full rootReadInventory, declared bool, key string) bool {
+ _, carried := full.Entries[key]
+ return !carried && !declared
+}
+
+// inputLiveFamilies is every family named by an authority row of the full
+// chain, after every overlay, that J4's scope covers (inputActivationEnabled)
+// and whose unit the tree still declares. A family's witnesses may go only
+// once it is not here (Astra review of R0, P1): a row only a later overlay
+// added keeps them required, though J4's caller check covers only its own
+// inventory, up to activation-tools. A row whose task list J4 cannot
+// parse is a failure, never a skip, and still keeps every family it does
+// name (Astra review of R0, round 2): the census accepts an authority row
+// with one recognized owner beside an unknown tag.
+func inputLiveFamilies(full rootReadInventory, declared func(key string) bool) (map[string]bool, []string) {
+ live := map[string]bool{}
+ var failures []string
+ for key, e := range full.Entries {
+ if e.Class != "authority" || !inputActivationEnabled(e) || !declared(key) {
+ continue
+ }
+ families, err := inputFamilyFor(e)
+ if err != nil {
+ failures = append(failures, key+": "+err.Error())
+ for _, owner := range strings.Split(e.Task, ",") {
+ if _, ok := inputFamilies[owner]; ok {
+ live[owner] = true
+ }
+ }
+ continue
+ }
+ for _, f := range families {
+ live[f] = true
+ }
+ }
+ return live, failures
+}
+
+// checkInputLiveWitnesses fails a live family with a witness slot that is
+// empty or names no test in the tree, as checkInputRow does for a row.
+func checkInputLiveWitnesses(live, tests map[string]bool) []string {
+ var failures []string
+ for name := range live {
+ f := inputFamilies[name]
+ for slot, test := range []string{f.Hostile, f.Rename, f.Erasure, f.Retry, f.Positive} {
+ if test == "" || !tests[test] {
+ failures = append(failures, "family "+name+" missing "+[]string{"hostile", "rename", "erasure", "retry", "positive"}[slot]+" fixture "+test)
+ }
+ }
+ }
+ return failures
+}
+
+// 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 +582,35 @@ 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)
- var report []string
- for key, e := range inv.Entries {
- if inv.Removed[key] != "" {
- continue
+ failures = append(failures, checkInputRetiredExemptions(inputExemptions, retired)...)
+ live, liveErrs := inputLiveFamilies(full, func(key string) bool {
+ d, err := declared(key)
+ if err != nil {
+ declaredErr = err
}
+ return d || err != nil
+ })
+ 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)
@@ -479,6 +624,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 72cc46997..de6120c83 100644
--- a/internal/provision/plan14_root_reads_test.go
+++ b/internal/provision/plan14_root_reads_test.go
@@ -28,6 +28,53 @@ type rootReadScan struct {
Entries []rootReadEntry
Coverage map[string]string
Fields []string
+ // Dirs is every directory the scan walked, holding scanned source or
+ // not, and Files every file it read. Root is the tree scanned, for the
+ // Lstat proof in absent; an in-memory fixture leaves it empty.
+ Dirs map[string]bool
+ Files map[string]bool
+ Root string
+}
+
+// absent reports whether the scan proves a path (slash-relative) gone: not
+// a walked directory or a read file, and, for a real tree, absent by Lstat
+// with no symlinked ancestor (rootReadPathAbsent). WalkDir does not follow
+// a directory symlink, so a walk alone cannot see a retired directory
+// brought back as one (Astra review of R0, P1). A scan with no directory
+// list proves nothing.
+func (s rootReadScan) absent(rel string) bool {
+ if s.Dirs == nil || s.Dirs[rel] || s.Files[rel] {
+ return false
+ }
+ return s.Root == "" || rootReadPathAbsent(s.Root, rel)
+}
+
+// rootReadPathAbsent walks rel's components below root by Lstat: absent
+// once a component does not exist, provided every component before it is
+// a real directory. A symlink, a file where a directory should be, an
+// Lstat error or a malformed path is not proof of absence.
+func rootReadPathAbsent(root, rel string) bool {
+ if rel == "" || strings.HasPrefix(rel, "/") {
+ return false
+ }
+ parts := strings.Split(rel, "/")
+ p := root
+ for _, part := range parts {
+ if part == "" || part == "." || part == ".." {
+ return false
+ }
+ }
+ for _, part := range parts {
+ p = filepath.Join(p, part)
+ fi, err := os.Lstat(p)
+ if os.IsNotExist(err) {
+ return true
+ }
+ if err != nil || fi.Mode()&fs.ModeSymlink != 0 || !fi.IsDir() {
+ return false
+ }
+ }
+ return false
}
// Match names conservatively, including method values, aliases and writes.
@@ -159,7 +206,7 @@ func rootReadTyped(root string) (map[string]string, map[string]bool, error) {
}
func rootReadProduction(root string) (rootReadScan, error) {
- out := rootReadScan{Coverage: map[string]string{}, Declarations: map[string]string{}}
+ out := rootReadScan{Coverage: map[string]string{}, Declarations: map[string]string{}, Dirs: map[string]bool{}, Files: map[string]bool{}, Root: root}
typed, active, err := rootReadTyped(root)
if err != nil {
return out, err
@@ -188,6 +235,11 @@ func rootReadProduction(root string) (rootReadScan, error) {
if p != root && (strings.HasPrefix(d.Name(), ".") || strings.HasPrefix(d.Name(), "_") || d.Name() == "testdata") {
return filepath.SkipDir
}
+ rel, e := filepath.Rel(root, p)
+ if e != nil {
+ return e
+ }
+ out.Dirs[filepath.ToSlash(rel)] = true
return nil
}
if !strings.HasSuffix(p, ".go") || strings.HasSuffix(p, "_test.go") {
@@ -233,6 +285,10 @@ func rootReadProduction(root string) (rootReadScan, error) {
paths := make([]string, 0, len(files))
for p := range files {
paths = append(paths, p)
+ out.Files[p] = true
+ }
+ for p := range extra {
+ out.Files[p] = true
}
sort.Strings(paths)
fields := map[string]bool{}
@@ -284,29 +340,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
@@ -382,6 +417,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
@@ -392,8 +460,11 @@ type rootReadInventory struct {
Removed map[string]string
Entries map[string]classifiedRootRead
Coverage map[string]string
- Fields string
- Legacy map[string]bool
+ // Retired is every envelope a "@coverage <dir> -" retired: its
+ // directory must stay out of the tree.
+ Retired map[string]bool
+ Fields string
+ Legacy map[string]bool
}
func loadRootReadInventory(path string, inv *rootReadInventory, delta bool) error {
@@ -461,7 +532,24 @@ func loadRootReadInventory(path string, inv *rootReadInventory, delta bool) erro
return fmt.Errorf("%s:%d: coverage", path, i+1)
}
key = "@coverage:" + col[1]
+ if col[2] == "-" {
+ // A retired envelope (claims cleanup R0): the directory is
+ // gone, which compareRootReads checks against the scan.
+ if !delta {
+ return fmt.Errorf("%s:%d: an envelope is retired only by an overlay", path, i+1)
+ }
+ if _, ok := inv.Coverage[col[1]]; !ok {
+ return fmt.Errorf("%s:%d: retirement of unknown envelope %s", path, i+1, col[1])
+ }
+ delete(inv.Coverage, col[1])
+ if inv.Retired == nil {
+ inv.Retired = map[string]bool{}
+ }
+ inv.Retired[col[1]] = true
+ break
+ }
inv.Coverage[col[1]] = col[2]
+ delete(inv.Retired, col[1])
case "@remove":
if !delta || len(col) != 3 {
return fmt.Errorf("%s:%d: removal", path, i+1)
@@ -577,6 +665,12 @@ func compareRootReads(got rootReadScan, want rootReadInventory) []string {
errs = append(errs, "stale root source envelope "+dir)
}
}
+ // The directory must stay absent by Lstat, symlinks included.
+ for dir := range want.Retired {
+ if !got.absent(dir) {
+ errs = append(errs, "retired root source envelope still present "+dir)
+ }
+ }
if strings.Join(got.Fields, ",") != want.Fields {
errs = append(errs, "changed registry schema")
}
@@ -1658,7 +1752,9 @@ func checkRootReadDeclarations(scan rootReadScan, inv rootReadInventory) []strin
// Census ruling zddr3: an H3 census-ruling removal may retire a
// unit that is still declared only when this scan finds no read in
// it. The basis text is never evidence; the scan is.
- retired := exists && strings.HasPrefix(removal, "H3;census-ruling-") && !rootReadScanned(scan, key)
+ // A removal census-propose wrote for a deleted unit holds only
+ // while the declaration stays gone (claims cleanup R0).
+ retired := exists && strings.HasPrefix(removal, "H3;census-ruling-") && !rootReadScanned(scan, key) && !rootReadAbsentRemoval(removal)
if (exists && !retired) || classified {
errs = append(errs, "removed legacy declaration still present "+key)
}