Uh oh!
There was an error while loading. Please reload this page.
fix(tests): the default comment opener never reached the stripper (client#788) - #796
Conversation
…ient#788)
`write_ds`'s default opener was written `"${1:-\{\{/\*}"`. Bash keeps those
backslashes inside double quotes, so the fixture carried a 7-byte `\{\{/\*`
line in which `{{` never even appears adjacently -- a string the guard's
opener regex cannot match. Every default-opener case therefore ran against a
file nothing was stripped from.
That is the whole shape .cursor/BUGBOT.md names for this suite. The unreachable
fixture came with a redundant mechanism behind it: the poison prose in the
comment block says `v1beta1.metrics.k8s.io` and `fail `, so with the block left
unstripped it satisfied check 3 on its own and the lookup and fail it merely
describes never had to be there. The happy path exited 0 either way.
Two halves, and the second is the one that matters:
1. Emit the opener literally. Single-quoted, assigned outside the double-quoted
expansion so no backslash can creep back in.
2. Make an assertion depend on the strip. Fixing the quoting alone leaves a test
that still cannot fail: stripping only ever REMOVES lines and every check-3
finding fires on an ABSENCE, so an under-stripping stripper can only turn a
finding into a pass -- no exit-0 case can see one, however it is written. So
the default opener is now exercised as a pair. The existing green half keeps
catching over-stripping; `catches the chart no longer looking up the
APIService` drops its explicit `{{/*` and takes the default, which makes it
the half that reddens when the strip stops happening. It also asserts WHICH
refusal it got, since exit 1 is equally how a disagreeing pair of installers
reports (backend#1729 rule 10) -- the same assertion added to its `{{- /*`
sibling, which had the same gap.
Plus a direct assertion on the fixture's own quoting, per the ticket's DoD, with
the expected pattern written out independently of `write_ds` so a re-escaped
opener cannot agree with itself.
Mutation-proved both ways: with the opener's `-?` narrowed to `-`, and again
with the strip disabled outright, `develop`'s default-opener case stays green
and this one reddens. Full output on the PR.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
saadqbal
left a comment
There was a problem hiding this comment.
Approving — and this is my favourite kind of test fix, because the tests were green and proving nothing.
Confirmed the mechanism: "${1:-\{\{/\*}" is inside double quotes, and bash only strips a backslash there before $ \ " ` or newline — so \{ stays two characters and the default opener really was the 7-byte \{\{/\*. Not just unmatchable by the stripper: {{ never appears adjacently in it. So every default-opener case ran against an unstripped file, the poison prose survived into ds_body and satisfied check 3 by itself, and the lookup-and-fail it merely describes never had to exist for those cases to pass.
The fix is right and the quoting is right for the reason the comment gives — opener='{{/*' single-quoted, with ${1-} plus [ -n ] so an explicit '' also takes the default, which is what lets a caller vary only the mode. That matches the new signature comment.
The new fixture-quoting test is the one that would have caught this, and it's written the way it has to be: grep -qxF '{{/*' spelled out independently of write_ds, so a re-escaped opener can't agree with itself.
The pair argument is the part worth keeping in the file, and it's correct: stripping only ever removes lines and every check-3 finding fires on an absence, so an under-stripping stripper can only ever convert a finding into a pass — which the green half structurally cannot see. The red half is the only thing that reddens when the opener stops matching, and the green half is the only thing that catches over-stripping eating the code below. Neither is a test of the stripper alone, and saying so beside them is worth more than either assertion.
saqlainsyed007
left a comment
There was a problem hiding this comment.
Verified against the fixture behaviour, not just the description — clean fix.
The bug is real and the fix is correct.local opener="${1:-\{\{/\*}" keeps the backslashes inside double quotes, so the default fixture opened with a 7-byte \{\{/\* the stripper's regex can't match — every default-opener case ran against an unstripped file, and the redundant poison-prose path masked it. Rewriting as opener="${1-}"; [ -n "$opener" ] || opener='{{/*' (single-quoted literal) is right, and the comment correctly warns that a backslash here silently disarms the cases below.
The new guards are mutation-proof and non-vacuous, which is what makes this worth more than a one-liner:
the default opener reaches the strippergreps-qxF '{{/*'on the fixture's first line, written independently ofwrite_ds— so a re-escaped opener cannot agree with itself (rule 9). Re-introduce the backslashes and this reddens.- The check-3 cases now assert the specific refusal string (
no longer looks up v1beta1.metrics.k8s.io), not barestatus -eq 1— because a disagreeing installer pair also exits 1, so the old assertion could pass for the wrong reason (rule 10). - The green/red pairing rationale is spelled out correctly: under-stripping only ever turns a finding into a pass, so each opener spelling needs both halves.
CI green, no threads, mergeable clean. LGTM.
Closes#788.
The bug
scripts/tests/k3s-components-agreement.bats,write_ds:Bash keeps those backslashes inside double quotes, so the fixture's first line was
never
{{/*:Seven bytes, and
{{never appears adjacently, so the guard's opener regex/\{\{-?[[:space:]]*\/\*/cannot match it. Every default-opener case ran against adaemonset fixture that nothing was stripped from.
The unreachable fixture came with a redundant mechanism sitting behind it, which is
why nobody noticed: the poison prose inside the comment block says
v1beta1.metrics.k8s.ioandfail, so with the block left inds_bodyitsatisfied check 3 by itself. The happy path exited 0 whether or not the lookup and
the
failit merely describes were there. That is exactly theunreachable-fixture + redundant-mechanism pair
.cursor/BUGBOT.mdalready names forthis suite.
The fix — both halves
1. Emit the opener literally. Assigned outside the double-quoted expansion, so no
backslash can creep back in:
2. Make an assertion depend on the strip. This is the half that matters — fixing
only the quoting leaves a test that still cannot fail.
Why no exit-0 case can carry this: stripping only ever removes lines, and every
check-3 finding fires on an absence. So an under-stripping stripper can only turn
a finding into a pass; the green half of any pair is blind to it, however loudly it is
written. Only a case that expects exit 1 can see the strip stop happening.
So the default opener is now exercised as a pair:
over-strips and eats the coupling below the block (client#764);
catches the chart no longer looking up the APIServicedrops its explicit{{/*and takes the default, making it the red half — with the coupling deleted, the
guard must still refuse, which it can only do if the poison prose was stripped.
That test also now asserts which refusal it got. Exit 1 is equally how a
disagreeing pair of installers reports, so a bare
[ "$status" -eq 1 ]is a coin tossabout what was exercised (backend#1729 rule 10). The same assertion is added to its
{{- /*sibling, which had the identical gap.Plus a direct assertion on the fixture's own quoting, per the ticket's DoD. The
expected pattern is written out independently of
write_ds, so a re-escaped openercannot agree with itself (#1729 rule 9).
Only
scripts/tests/k3s-components-agreement.batschanges. The guard itself isuntouched.
Mutation proof
Two mutations, both on the real stripper in
scripts/tests/k3s-components-agreement.sh.Each is run against
develop's suite and against this PR's suite, so the logshows the gap and not just the coverage.
Mutation 1 — narrow the opener's
-?to-, so the plain{{/*no longer opens a blockAnchor, proven applied:
develop's default-opener case — survives:This PR's default-opener cases — reddens:
Mutation 2 — disable the strip outright
Anchor, proven applied:
develop's default-opener case — survives:This PR's default-opener cases — reddens:
Note what mutation 1 does not show:
develop's suite is not blind to it overall —its
catches the chart no longer looking up the APIServicepassed'{{/*'explicitlyand does redden. The gap is the default-opener path specifically, which is what
this ticket is about and what the log above isolates.
Restored — green
Test plan
The guard itself, unchanged, still exits 0 against the real tree:
Full
scripts/tests/*.bats, green —bats (bash unit, mocked), 3m52s, plan1..1326with no
not okline in the job log(run).
The twelve cases of this suite in that run:
(Started locally too, but this box was at load 18 with several agents' suites in flight;
it reached 632 of 1326 with 0 failures before I tore its worktree down, and the clean
runner had already finished by then. The CI run above is the full-suite evidence.)
bats-hygiene.batsis green too (18/18) — the new assertions all end in|| { …; return 1; }, andunenforced-assertions.awkreports no offenders in thisfile.
Why now
This unblocks #786: its Bugbot thread is the one #788 was filed from, and per
.cursor/BUGBOT.mdan unresolved cursor thread is a soft gate that holds release-trainpromotions for the whole fleet, not just that PR. With this merged the thread can be
answered with a fix rather than a note.
🤖 Generated with Claude Code