formwork-vacuity-census

command
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 41 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Corpus-independent calibration for the class-2 verdict probes (#15917).

WHY THIS FILE EXISTS, and it is not tidiness. mutation-proof materialises a scratch corpus PRUNED to the rule under test alone (rewriteRuleFileToSingleID in scripts/dev/mutation-proof), and the survivor is formwork-rules-not-vacuous itself — a type: command rule. Class-2 verdicts are witness probes over CONTENT rules, so in that scratch there is nothing for them to classify and the verdict is over an empty population whatever the logic says. Demonstrated, not argued: a spec mutating classify.go so DETECTOR-SATISFIED fires for EVERY witness-bearing rule was answered by mutation-proof with "did not reject the mutation — it stayed green on wrong evidence inside its own scope".

So the one arm of this census that could be proven was the fixture-registry arm, which reads the TREE rather than the pruned rule corpus. The constraint SELECTED the arm that got proven, and it is the arm whose loss costs least.

arm-shape-ratchets hit the identical wall and its spec notes record the cure: a corpus-INDEPENDENT calibration that runs BEFORE the corpus scan, so a mutation to the verdict logic is caught by calibration rather than by a corpus the scratch does not have. This census already had that mechanism — selfTest() in calibrate.go — and it was scoped to the scope MATCHER alone, the arm that needed it least. Same pattern one level down.

This block calibrates the two load-bearing class-2 probes on inputs whose answers are known, so they are falsifiable without any corpus at all.

formwork-vacuity-census — how many formwork rules currently protect nothing?

Usage: go run -C tools/formwork-vacuity-census . [--full] [--write-inventory] <repo-root>

Product enforcement is formwork type:command with origin on this file. Exit 0 = no vacuous rules, 1 = offenders listed or the scope-phase wall budget blown (#12419), 2 = usage/env error.

A rule that cannot fail is worse than no rule: it burns CI time and reads as coverage in docs/lockdown-enumeration.md while guarding nothing. This census classifies every rule in .formwork/rules/ into the three vacuity classes and fails CI on any of them, so vacuity cannot silently regrow (#10083).

class 1  EMPTY SCOPE       scope.include matches no file in the tree.
class 1  EMPTY GLOB        ONE scope.include glob matches no file while a
                           sibling glob keeps the whole rule looking healthy
                           (per-glob arm, #10626 — see below).
class 1  GLOB REMOVED      a previously-live include glob was deleted from
                           the rule (inventory arm, #10876 — see below).
class 1  GLOB UNTRACKED    a live include glob is missing from the inventory.
class 1  SOURCE UNLISTED   a rule DECLARES its scope.include exhaustive over a
                           source directory (`# source-list-exhaustive:`) and a
                           non-test .go file there is covered by no entry
                           (#13517 — the file matches no glob, so every arm
                           above is blind to it by construction).
class 1  SOURCE-LIST-      that declaration names a directory holding no
         VACUOUS           non-test Go source, so it gates nothing.
class 1  DEAD-EXCEPT-GLOB  an except.paths entry names a literal path that is
                           not in the repository (#12178 — see below).
class 1  INERT-EXCEPT      an except.paths entry names a literal path that IS
                           there and in scope, but which the rule does not
                           fire on, so it suppresses nothing (#10777).
class 2  SELF-SATISFIED    the rule's evidence is not the thing it guards —
                           it is a comment, its own detector, or a token so
                           generic that any fragment of the file supplies it.
class 2  INERT-REQUIRED    a set-relation whose required side can be blanked
                           ENTIRELY with the relation still holding (#12180).
class 2  DEAD-TRIGGER      a pair-consistency rule whose trigger matches
                           nothing, so no unit ever enters the obligation
                           and the companion is never asked for (#12181).
class 3  DEAD FIXTURE      the fire/pass pair no longer discriminates.
class 3  EMPTY-SCOPE FIRE  no fire fixture contains a file the rule's scope
                           matches, so each fires on an EMPTY scope and
                           demonstrates nothing about the evidence (#12178).
class 3  NO FIRE WITNESS   a heavy rule with no fixture AND no lockdown
                           synth that both names it and declares a test
                           function (#12178).
class 3  FIXTURE REMOVED   a fixture directory the rule used to have is gone
                           (registry arm, #10838 — see below).
class 3  FIXTURE UNTRACKED a fixture directory is missing from the registry.

The per-glob arm (#10626)

config.Rule.Applies is a union predicate: once it returns true, which include glob earned the match is unrecoverable. Every whole-rule instrument inherits that blindness — a rule watching six places, five of which moved away, reports a healthy file count while five-sixths of its stated coverage is gone. A refactor almost never kills every glob at once, so this is the common case of scope rot, and both whole-rule arms (formwork lint's empty-scope, class 1 EMPTY-SCOPE) correctly report 0 throughout. The census therefore also matches every declared scope.include glob INDIVIDUALLY (perglob.go) and gates each dead one as EMPTY-GLOB, naming the glob and how many siblings are live. A genuinely aspirational glob is declared in place with `# glob-dead: <reason>` on the line above it — the reviewed escape, never a separate allowlist file.

scope.exclude and except.paths globs are GATED (#12178), on the half of them that discriminates. Two things were wrong with reporting and never gating.

First the DENOMINATOR. The defensive entries were partly "dead" because they were measured against the post-skip scan.Walk FileSet rather than against the repository: scan.Walk drops .formwork before rules run, so an exclude naming '.formwork/**' matched zero SCANNED files while naming thousands of real ones — and formwork-engine-skip-declared REQUIRES that declaration on every content rule whose include reaches a .formwork path, so the two rules demanded opposite things. Subtractive globs are therefore counted against a walk that keeps the built-in skip (perglob.go, walkIncludingBuiltinSkip), while includes stay on the engine's own FileSet so no coverage claim is ever measured over files the engine will not read. Counting a subtraction over a superset can only ever be generous.

Second the PREDICATE. "Matches nothing" is the right test for an include and the wrong one for an exclude, because the two halves of a scope are not symmetric: a dead include OVER-CLAIMS coverage the rule does not have, while a dead exclude claims nothing — it is a guard, and an unfired guard is not a dead guard. Of the 263 subtractive globs matching nothing here, 232 are wildcard CLASS GUARDS (`**/node_modules/**`, `**/*.pbjson.dart`, `**/.dart_tool/**`, `.agent-work/**`) naming a class of path that appears whenever a build runs or an agent opens a scratch tree; deleting one is a regression. The 31 that remain name a LITERAL path, and every one proved to be drift — 29 a scripts/check-*.sh gate formwork replaced and deleted, one a Dart provider that moved, one a proto that moved. That is the gated half (isClassGuard, classify.go).

This measures glob-vs-tree, not glob-vs-intent: a glob that matches the WRONG files (too broad, or the right count for the wrong reason) is invisible here. That is class 2's territory.

The inert except.paths entry (#10777)

DEAD-EXCEPT-GLOB above asks whether the path is still THERE. INERT-EXCEPT asks the next question — whether an entry whose path IS there still suppresses anything — and it is a question only an except.paths entry raises, because except.paths is a scope SUBTRACTION rather than a suppression. config.Rule. Applies returns false for a matched path, so the rule never evaluates the file, no finding is produced to be suppressed, and formwork lint's escape-hatch census keeps printing the entry as a live, accounted-for exception no matter what happened to the code underneath it. An allowlist entry cannot rot this way — lint's exemption-hygiene compares it against real findings — which is why the same rot living one level over went unseen.

It was found by accident during #10346: dart-measure-active-step named measure_type_filter_providers.dart as the home of a resolver that issue had turned into a projection off the server's resolution, and the only thing that ever noticed was a human running the rule's own regex across two revisions. The cost is governance rather than tidiness — once the list stops saying which entries are load-bearing, an honest amendment to an ownership manifest reads exactly like an allowlist widening.

Answered by evaluating the rule over a one-file tree with ExceptPaths CLEARED (probe.go, exceptExcuses); probing the rule as written would drop the file at Applies and report every entry in the corpus inert. Literal paths only, same isClassGuard split as the DEAD arm and for the same reason. A file that can never be a violator — the declaration home of the very field a rule is written against — is declared in place with `# except-declaration: <reason>`, distinct vocabulary from `# glob-dead:` because "matches nothing" and "matches a file the rule cannot fire on" are different claims with different cures.

The live-include inventory (#10876)

EMPTY-GLOB only sees declared globs. Deleting a live include glob — and its fixtures — leaves no EMPTY-GLOB, no class-3 half-fixture, and a green census: the thorough gaming run that dropped admin_app from the global-error-handler rules. tools/formwork-vacuity-census/live-include-globs.tsv is the packed declared-sibling registry (#12398): every LIVE scope.include glob is listed as rule-id<TAB>glob, and removing one from a rule without removing the row gates as GLOB-REMOVED. Adding live coverage without a row gates as GLOB-UNTRACKED. Regenerate with --write-inventory. Synthetic corpora (rule count ≤ minCorpusForCanaries) skip the registry unless they plant a file.

The fixture-directory registry (#10838)

The class-3 arms judge the fixtures a rule STILL HAS. None of them can see one that is GONE: delete a directory from a rule with twelve and `formwork test` prints "OK — 11 fixture(s)", `formwork lint` is satisfied by the survivors, and this census stays green — so a lockdown is weakenable in two green commits, one deleting the fixture that pins a property and one making the change it forbade. .formwork/fixtures/<rule-id>/INVENTORY.tsv is the registry that makes the deletion leave a trace: a row whose directory is gone gates as FIXTURE-REMOVED, a directory with no row as FIXTURE-UNTRACKED. Same shape, same canary threshold, the same --write-inventory regeneration and the same per-rule keying (#12043) as the live-include registry above — here the rule id is the parent directory, so the manifest travels with the tree it registers. Details in fixtureinventory.go.

Why this imports formwork's own matcher

An earlier census expanded each scope.include with the shell and reported 133 of 200 rules matching zero files — including dart-file-size-cap, which caps 3229 live Dart files. formwork scopes are doublestar globs (packages/*/lib/**) and `ls` does not expand `**`, so every pattern containing one returned nothing. The instrument, not the corpus, was empty. So every scope here is matched by config.Rule.Applies and every verdict is rendered by engine.Run — the same code the gate engine runs — and the census prints a calibration block against known-live rules before it reports a single zero. The per-glob arm keeps the same discipline: each glob is counted through a one-glob config.Rule (never the shell, never a re-implementation), and the calibration block requires dart-file-size-cap's `**/*.dart` glob to report a four-figure count and a deliberately-impossible glob to report zero before any per-glob zero is believed.

The scope-phase wall budget (#12419)

Building every rule's in-scope file set is O(rules×files) union-predicate work, and the census runs on every Architecture Guardrails pass. Computed serially it put minutes on the PR critical path; computed through buildScopeIndex (per-rule scans fanned across a GOMAXPROCS pool, each rule's own scan serial so file order is preserved) it is a fraction of a second on the real corpus. run() builds scopes only through buildScopesWithBudget, which refuses the result — exit 1, census FAIL — when the phase exceeds scopeWallBudget. The budget value is pinned by the formwork rule vacuity-census-wall-budget-pinned, and the wired-through- the-index shape by vacuity-census-scope-index-wired: the ceiling is mechanical on both axes, never a convention.

How class 2 is measured

For a rule whose obligation is that something EXISTS (required-pattern mode:exists, pattern-count op:at-least), a file that satisfies the rule on its own is a WITNESS: it is where the evidence lives. Witnesses are found by running the real engine over one-file trees. Three probes then ask whether that evidence is the invariant or a shadow of it:

  • COMMENT-SATISFIED — blank every comment-only line of each witness and the rule stops passing. Then prose is the evidence: the code it names could be deleted and the rule would still be green (the #9992 class). A rule that legitimately reads comments declares preprocess: comments-only-*, and is exempt by that declaration rather than by a list.
  • DETECTOR-SATISFIED — every witness is a gate source (under scripts/ or tools/, or the rule's own declared origin). The rule asserts its own detector still contains some text, not that the detector's invariant holds (the no-zero-reader-columns class). Documented here from the day the census landed and unimplemented until #12178; it is a live gate now.
  • DIFFUSE-EVIDENCE — split each witness into 16 contiguous blocks; if at least 14 blocks satisfy the rule ALONE, the pattern matches something so common that near-any fragment of the file supplies it.

A ceiling (pattern-count op:at-most, required-pattern every-file) stays outside the WITNESS probes: deleting a file satisfies those vacuously, so single-file satisfaction does not mean "the evidence lives here" and every probe above would misread.

Relations no longer sit outside the population entirely (#12178 defect 1). set-relation and pair-consistency were excluded on the same argument, and #12180 and #12181 then found live, execution-proven vacuity in exactly those two types — 34 set-relation and 45 pair-consistency rules in one shard alone had never been probed by anything. They get the two probes that ARE valid for a relation, each the mechanical form of the experiment that found the live instance:

  • INERT-REQUIRED-SIDE — blank EVERY file the side the relation REQUIRES (params.b.files) draws from, in one experiment, and ask whether the relation still holds. If it does, the whole side could be deleted with the rule staying green: the join is carried by names that appear anyway. Reported only for `subset`/`equal` (where params.b IS the required side) and only where the two sides' globs are separable. Those are the conditions that make the experiment mean anything, not a narrowing — see relation.go, and the coverage line the report prints for the population they exclude, which this instrument does not decide.
  • DEAD-TRIGGER — no obligation-entering unit matches in scope under the rule's own preprocess and `where` geometry. Entry is trigger, and when also_present is set trigger∧also_present (I17). same-func matches on FuncDecl / var-bound FuncLit spans so multi-line triggers are not false- dead and package-level residue is not false-live (I18). No unit ever enters the obligation, so the `requires` half is never asked for and the rule is green over any tree. This is the pair-consistency spelling of the engine's own AnchorProbe. It is deliberately NOT "duplicate a trigger and see whether the rule notices the extra one": `where: same-file` is this type's DEFAULT and its documented meaning is PRESENCE within a unit, not pairing, so a second trigger beside an existing companion is compliant by definition. Measured against this corpus that probe flagged 93 of 106 pair-consistency rules — it was reading the rule type, not the rule.
  • EMPTY-SIDE — a live equal|subset set-relation whose either extracted side has cardinality 0 on the real tree (V4). empty=empty / empty⊆B holds by set algebra with no load-bearing evidence; the engine's min_count floor closes the same hole when authors set it.

Neither is a witness probe, because a relation is satisfied by an empty tree and "this file satisfies it alone" would carry no information.

DIFFUSE-EVIDENCE no longer stops at three witnesses (#12178 defect 3). The verdict requires EVERY witness to be internally redundant, so the arm still exits on the first witness that pins a line; the old cap excluded exactly the rules whose evidence was most redundant. Having MANY witnesses is a separate property and stays out — that grain is tools/formwork-witness-census's (#12182), and the two must not both claim it.

Relation probes. A set-relation or pair-consistency rule is satisfied by an EMPTY tree, so none of the witness probes in classify.go can read one: "this file satisfies the rule alone" carries no information about where the evidence lives. Until #12178 that put both types outside the class-2 population entirely — isExistenceObligation admitted only required-pattern(exists) and pattern-count(at-least) — so nothing had ever probed them, and #12180 / #12181 then found live vacuity in exactly those two.

scopeglobs.go — the class-1 scope-glob integrity arm: every declared scope.include / scope.exclude / except.paths glob judged on its own. Split from classify.go, which the 750-line full-repo file cap bounds; same package. perglob.go measures the globs, this file decides what the measurements mean.

sourcelist.go — the class-1 arm that pins a rule's DECLARED source list to the sources it claims to cover (#13517).

THE DEFECT. formwork-rules-not-vacuous enumerates, file by file, the Go sources the vacuity census is built from. Nothing checked that enumeration against the package on disk, and it drifted by three files — scopeglobs.go (#10777), scopeindex.go and wallbudget.go (#12419) — across three separate changes over months, with every gate green throughout. The control is the identical classify.go split that produced relation.go (#12178): same operation, list updated, no gate between them either way. The rule that proves no other rule has quietly stopped protecting anything was itself maintained by a comment asking the next person to remember, and that comment had already failed three times running.

WHY THE OTHER ARMS CANNOT SEE IT. Every instrument here measures a DECLARED glob against the tree; this defect is a source with no glob to measure. A file present in the directory and absent from the list matches nothing, is counted nowhere, and is invisible to EMPTY-SCOPE, EMPTY-GLOB and GLOB-UNTRACKED alike. Only the reverse direction — a listed path that is gone — was ever observable, and EMPTY-GLOB already gates it. The arm below is deliberately one-directional for that reason: adding it to the deletion side would double-count the same fact as two offenders.

OPT-IN, BY MARKER. The census cannot guess which include lists are meant to be exhaustive — most are not, and a rule watching six unrelated trees would fire constantly. A rule subscribes by declaring it, in the comment plane the per-glob arm already reads:

scope:
  # source-list-exhaustive: tools/formwork-vacuity-census
  include:
    - "tools/formwork-vacuity-census/main.go"

Non-recursive, and non-test only: a Go package IS one directory, and a test file is not a source the rule is built from. Coverage is decided with formwork's own matcher, so a list that names its directory with a glob is covered rather than flagged — the claim is that nothing is MISSING, not that the list is spelled one particular way.

Symbol-anchor probes. A rule that selects its subject by NAME — the `symbol` of a call-confined-to-func-name confinement, the `sink` a guard-precedes-call rule guards, the `funcs` filter either of them admits through — stops seeing anything the moment that name is deleted or renamed, and then reports green forever.

The engine already names this failure and already owns the mechanism: rules.AnchorProbe is wired into call-order-in-func, per-func-count-relation and the Dart method-delegates type. It is NOT wired into call-confined-to-func-name or guard-precedes-call, which is 41 live rules across the two types. These arms are the census spelling of that probe for the two types the engine skips, exactly as DEAD-TRIGGER is its pair-consistency spelling (#12181).

WHAT "DEAD" MEANS HERE, and why the obvious reading is wrong. A confinement is a BAN. Zero call sites today does not make a ban unfallible — if the symbol still EXISTS, a new call site can appear tomorrow and the ban catches it. Read naively, "no call site" condemns a rule for being OBEYED. Measured against the real 1873-rule corpus, that naive reading produced five findings and all five were false: .GenerateContent (SDK, used as a method value rather than a call), json.Marshal (stdlib, in a file that moved to proto.Marshal), ReducePhases, FindRole and sectionsComplete (all still declared). The last is the sharpest — its rule is a TOTAL ban that carves its legitimate callers out through scope.exclude, so zero call sites in scope is precisely its compliant state.

So the verdict needs BOTH halves #12494 asked for: no call site AND no declaration. Only a symbol that exists nowhere can never be called.

The total-ban case needs no branch of its own: a total ban whose symbol is declared is silenced by the declaration test, and one whose symbol is genuinely gone IS vacuous and should be reported like any other.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL