| index 3edcdadfe..754eee1c8 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,7 +164,10 @@ 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}}) |
| + case declared: |
| + cs = append(cs, censusChange{Key: key, Class: censusQuiet, Before: w, After: rootReadEntry{File: w.File, Unit: w.Unit, Digest: decl}}) |
| default: |
| + // The scan proves the declaration gone, and every site with it. |
| cs = append(cs, censusChange{Key: key, Class: censusRemoved, Before: w}) |
| } |
| } |
| @@ -169,7 +178,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.Dirs == nil || got.Dirs[dir] { |
| + class = censusQuiet |
| + } |
| + cs = append(cs, censusChange{Key: dir, Class: class, OldHash: hash}) |
| } |
| } |
| keys := map[string]bool{} |
| @@ -236,9 +249,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 +274,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 +289,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 +298,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 +306,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 +337,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 +379,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 +418,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 +471,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 = "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)" |