test(threading): positive control on the backfillPending absence probe - #1230
Conversation
@sprint-review noted that rule 18's rider two asks for a positive control and the exemplar the rule is built on hasn't got one. It is safe anyway, because `read()` is an unguarded `readFileSync` — a bad path throws rather than yielding ''. That closes one of the two ways to match nothing. The other is not closed by anything the loader does. A wrong needle — a typo'd identifier, an over-anchored regex, or a haystack that is simply the wrong file — matches nothing against source where the code is in plain sight, and the absence assertion passes vacuously. Control matches THREADING_BACKFILL_MIGRATION, chosen because it shares the substring: if a backfill-named identifier can be found in this file, the probe's silence about backfillPending is informative. Negative control run, isolated and restored: repointing CONTROLLER_SRC at models/User.ts reddens the new line and leaves `not.toMatch(/backfillPending/)` green — the exact vacuous pass this closes. 21/21 on Node 22. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
lilyshen0722
left a comment
There was a problem hiding this comment.
PASS at dbf84bbcb6418e568c58b5def4258bdbe4124b1b — CLEAN, green, base main, no prior review. Ten lines, and they're the right ten.
Checked every factual claim in the new comment rather than reading it for plausibility, because a control that is itself vacuous is worse than no control:
read()really is unguarded —fs.readFileSync(path.join(__dirname, '../../../', p), 'utf8')at:14, notry, no|| ''. So "an empty haystack cannot happen" holds: a bad path throws and the suite goes red rather than silently matching nothing.CONTROLLER_SRCat:184readscontrollers/threadStateController.ts, so the control is checking the same buffer as the negative one line below. That was the thing most likely to be quietly wrong and it isn't.THREADING_BACKFILL_MIGRATIONis genuinely present in that controller onorigin/main, so the control asserts something the file can fail.backfillPendingappears nowhere inbackend/onmainexcept this test file's own two lines, so the negative is true and the probe is not masking a live reference.
The distinction the comment draws is the useful part and I'd want it repeated elsewhere: "matches nothing" has two causes, one of which — the empty haystack — was already structurally closed by the unguarded read, and one of which — a typo'd needle — was not. A lot of rule-18 assertions get a control bolted on that only re-proves the half already guaranteed. This one names which half it is covering and why the other doesn't need it.
Minor, take it or leave it: the control needle is uppercase and the negative needle is lowercase, so a case-folding accident in either regex would not be caught by the pairing. A needle differing from backfillPending by one character would bind the two more tightly. Not worth a round trip — the current one already proves the file is the controller and contains backfill code, which is what the comment claims for it.
Merge as-is.
Follow-up to @sprint-review's note on #1209: rule 18's rider two asks every absence assertion for a positive control, and the exemplar the rule is built on hasn't got one.
They are right that it is sound anyway, and right that the reason is worth naming rather than assuming.
read()in this suite is an unguardedreadFileSync, so a bad path throws instead of yielding''— the source string can never quietly be empty.That closes one of the two ways to match nothing. The other is untouched by anything the loader does: a wrong needle — a typo'd identifier, an over-anchored regex, or a haystack that is simply the wrong file — matches nothing against source where the code is sitting in plain sight, and the absence assertion passes vacuously.
So the control matches
THREADING_BACKFILL_MIGRATION, picked because it shares the substring with the retired probe: if a backfill-named identifier can be found in this file, then the probe's silence aboutbackfillPendingis informative.Negative control
Run in isolation with a verified backup and restored afterwards (this suite's file,
CONTROLLER_SRCrepointed atmodels/User.ts):The new line reddens;
not.toMatch(/backfillPending/)stays green. That is exactly the vacuous pass this closes — reading the wrong file makes the absence assertion succeed for no reason at all.21/21 on Node 22. #1209 carries the matching sharpening to rider two, so the rule now asks which half of "matches nothing" you closed.
🤖 Generated with Claude Code