Repository navigation
Description
Split out of #845. The remaining Phase 4 item, scoped honestly rather than swept.
The defect class
A gate asserting strings.Contains(artifact, "LITERAL") cannot fail if LITERAL also
appears in a comment in the source that generates the artifact — the sentence
documenting the gate satisfies the gate. That is CLAUDE.md rule 3, and it has bitten
repeatedly:
spawn:versionappeared in a CloudFormation parameterDescriptionand in anecho.put-retention-policyappeared in a comment saying which call to make.- Scope the in-account reaper's SSM grant the way the cross-account template already does #818: my own comment explaining a removed SSM grant satisfied the assertion about it.
spawn validate --nist-800-171 -o jsonsilently prints a table: the compliance flags demand a value they then ignore #808:TestUpgradeScriptIsFailClosedmatched"skipping verification"over the whole
script, and the comment inupgrade_spored.goexplaining the removed fail-open
tripped it.
Why this is not a sweep
There are 324 strings.Contains(artifact, …) assertions in the tree. The large
majority are correct — asserting that a specific generated line is present is the right
thing to do, and most literals are not words that appear in prose.
Why a regex scan will not do
I tried. It reported 38 candidates and is dominated by false positives, because stripping
// comments with a regex also strips inside string literals — so policy JSON, shell
templates and URLs in raw strings get truncated and their contents look comment-only.
Spot-check: it flagged iam:CreateServiceLinkedRole as appearing only in comments; it is
in code at pkg/aws/iam.go:1013.
The deliverable
A gate using go/ast to separate code from comments properly — the approach
cmd/user_facing_strings_test.go already takes, for exactly this reason. For each
strings.Contains(x, "LIT") in a _test.go file:
- collect every string literal and identifier text from the non-test sources of the
package under test (and, where the artifact is spliced from elsewhere, the whole repo); - collect the comment text separately;
- flag an assertion whose literal appears in the comment set and not in the code set.
Expect a handful of real findings and a short exception list — a literal may legitimately
appear in both. Each exception needs a reason, and if the list grows past a few entries the
rule is wrong (rule 6).
Related
The same shape is already gated in two narrower places, which is where the pattern was
learned: scripts/lambda-deploy-census.sh anchors on ^\s*aws logs put-retention-policy
rather than the bare call name, and sigVerifyOn matches (?m)^SPORED_SIG_VERIFY=1$
rather than the bare identifier, because the identifier appears in two shell comments
(#813).
Activity
Make four gates discover their sets instead of listing them
scttfrdmn commentedon Oct 11, 2026
I built this and am recommending against shipping it. Negative result, with the
measurements, so nobody repeats the attempt.
What I built
go/ast-based, as the issue specified: parse every non-test Go file, strip comments bybyte offset so a code pattern asserted as syntax still counts as code, collect comment
text separately, then flag any
strings.Contains(x, "LIT")in a test whose literal appearsin the comment corpus and not the code corpus.
What it found
16 findings, then 6, then 0 true positives.
First run, Go string literals and identifiers as the "code" corpus: 16 findings, all false.
Three distinct corpus gaps:
"./test/e2e"(asserts on the Makefile),"far-future"(asserts ontemplate.yamland a README)"time.Sleep(","return nil","ec2.NewFromConfig(c.cfg)""connection refused","address already in use","InvalidInstanceType"Widening the corpus to raw comment-stripped Go source plus every
.yaml/.yml/.sh/.md/.json/.pyand
Makefilefixed the first two gaps: 16 → 6.All 6 remaining are the third gap — the asserted text is produced by code this repository
does not contain:
"connection refused","address already in use"— Go'snetpackage error text"InvalidInstanceType"— an AWS API error code"(static fallback)"— rendered bySourceLabel()inlibs/pricing, a separate moduleSo: zero true positives, six false ones, and no way to distinguish "prose-only in this
repo" from "produced by a dependency" without enumerating every dependency's error strings.
Why not just add an exception list
Six entries, all saying "this string comes from somewhere else", and no way to tell a
seventh legitimate one from a real defect. That is precisely the smell the rule I added in
#845 describes: if a gate needs an allowlist of things that are obviously fine, the rule is
wrong — a list of what is normal means the rule is wrong, which is rule 4 inside out.
Shipping it would add a gate with no true positives and a maintenance burden that trains
people to extend the allowlist rather than read the failure. That is worse than no gate,
for the same reason stated at the top of the "Writing a gate" section.
What to do instead
The defect class is real — four instances are on record (
spawn:version,put-retention-policy, #818, #808) — but every one was caught by reading the failuremessage of a revert that should have failed and didn't. That is rule 1, and it already
covers this: a gate verified against a compiling revert cannot be satisfied by its own
prose, because the revert changes the code and the prose stays.
Rule 3 remains the right guidance for the author, and rule 1 the enforcement. Automating
the detection does not pay here.
Closing unless you disagree.
Make four gates discover their sets instead of listing them (#847)