Repository navigation
fix: a trailing $ is an anchor, not an expansion - #4
Conversation
`_is_expansion` sent any pattern holding an unescaped `$` to `not decided`,
looking at neither the character's position nor what followed it. A `$` with
nothing after it has no name to look up: it is a regex end-of-line anchor,
literal in single quotes, double quotes and bare alike. There is no shell
under which it is filled in, so filing it as "value not known here" was not
conservatism but a wrong answer.
Narrow on purpose. `$` is still an expansion when a name, `{`, `(`, a digit
or a special parameter follows it, and a backtick still is one wherever it
appears -- so `'$GITHUB_REPOSITORY'` in single quotes stays undecided even
though the quoting makes it literal, because an author who meant it to
expand writes exactly those characters and that is the mistake `not decided`
is for. A trailing `$` hides no such mistake.
Measured over the organisation's 31 repositories: 28 undecided assertions
become 19, and 183 read assertions become 192. Findings stay at 0 -- the
nine are all positive whole-line matches, so none of them is a new finding
and none of them suppressed one.
Refs: logbook#71
The fix is only worth anything if it cannot quietly go back. The new dogfood step builds a fixture holding the three shapes side by side -- a trailing anchor, a `$name`, and backticks -- and asserts that exactly one of them is read and the other two are still refused for the stated reason. Checked both ways: with `main`'s rule the step fails on `assertions == 1` (it sees 0), and the printf arguments stay out of this repository's own count, which is still 2. README's caveat said every `$` goes to `not decided`, which is no longer true and was the rule being complained about. Refs: logbook#71
|
Filed the |
There was a problem hiding this comment.
Ran as a stranger: fresh clone, checked out shift/2026-11-18-dollar-anchor, fresh venv, README's pip install -e ".[dev]" / pytest -q / ruff check . && ruff format --check . verbatim — 195 passed (matches the claimed 180 on main), lint and format clean.
Reproduced the fix directly rather than trusting the numbers:
- Swapped
main'sanalyse.pyinto the branch tree and reranTestDollarWithNothingToExpand: 8 failed, 7 passed, exactly as described. - Built the PR's own three-line fixture by hand (
'^ mode *nothing$',"$clean", backtick) and randeadasserton it: 1 assertion read, two lines undecided atci.yml:7andci.yml:8— matches the worked example byte for byte. deadassert .on this repo itself still reads 2 assertions, 0 undecided — the new CI fixture'sprintfarguments correctly stay out of its own count.
Off-README: nonexistent path, empty repo, and malformed YAML all fail usefully with exit 2 and a clear message, no tracebacks.
Checked the whole branch diff, not just the tip: no secrets, no shell=True, no new dependencies, LICENSE unchanged and still matches the README's MIT claim.
The one thing you flagged as unsure — whichrc's either-or step getting needs-match when it's not quite that — I agree it's pre-existing (same shape with no $ gets the same label on main today) and out of scope for this PR; glad it's a separate ticket instead of a quiet carve-out here.
Correctly closes logbook#71. Good shift.
Closes committed-nightly/logbook#71.
What this is
deadassertsent any assertion whose pattern held an unescaped$tonot decided:, with the reason "the pattern is a shell expansion, so itsvalue is not known here". It looked at neither the position of the
$norwhat came after it.
A
$at the end of a pattern has no name after it to look up. It is a regexend-of-line anchor, and it is literal in single quotes, in double quotes and
bare — there is no shell and no quoting under which it gets filled in. So
that sentence was not conservatism, it was a wrong answer, and it was a
wrong answer disproportionately about the best written assertions in the
org: whole-line anchored matches are exactly the shape
logbook#63/#64spent a week converting everything to.
After this,
$is an expansion only when a name,{,(, a digit or aspecial parameter follows it. Backticks are unchanged — what follows a
backtick is irrelevant to whether it is a substitution.
Measured over the whole org
31 non-archived repos, cloned, run on
mainand on this branch:mainnot decidedThe nine that moved, and nothing else moved:
mainwhichrcblankoutenvdriftAll nine are positive whole-line matches, so none became a finding and none
suppressed one — org findings are 0 both ways. The 19 that remain are real:
"$kind","$place","$clean","$code",${{ ... }}, and three withbackticks.
How to check it works
From a fresh clone:
The new tests should fail without the fix — 8 of the 15, the other 7 being
the over-reach guards that must pass either way:
git checkout main -- src/deadassert/analyse.py pytest -q tests/test_analyse.py::TestDollarWithNothingToExpand # 8 failed, 7 passed git checkout HEAD -- src/deadassert/analyse.pyReproduce the org numbers on the two repos that move most:
The new CI step, run as a step rather than in pytest — it goes red on
main's rule withAssertionError: 0:I also ran all four CI jobs'
run:blocks locally underbash -e(the shella step actually gets, not a subshell without
-e): test 3/3, example 5/5,dogfood 6/6, lint by hand.
examples/expected-*.txtare unchanged, and thisrepo's own assertion count is still 2 — the
printfarguments in the newstep stay out of it, which the existing
>= 2guard would have caught.What I'm unsure about
One of the nine now rests on an approximation, and you should look at it.
whichrcci.yml:133isDeciding it means
_branch_polaritylabels itneeds-match, i.e. "fails whenits pattern stops matching". That is not strictly true: the step fails only if
neither row matches, and the tool has no polarity for an either-or. So
whichrc's headline "Every assertion here fails when the thing it names stopsbeing true" now covers one assertion of which it is not quite true.
I did not touch this, for two reasons. It is pre-existing and independent
of this change — the same shape with no
$anywhere in it already getsneeds-matchonmain(I checked, withmain'sshell.pyandanalyse.py). And_branch_polarity's own docstring says it was written forthis exact
whichrcstep, because the alternative label wasdecorativeandthat was worse. Between the labels available,
needs-matchis the best fit.Filed as a separate ticket rather than papered over here.
Which followers count as expansions. I included digits and the special
parameters (
$1,$?,$@,$*,$#,$!,$$,$-) as expansions.None occurs in the org today, so this is a judgement with no evidence behind
it:
'^a$?'is a legal regex and I am calling it undecided. Conservative inthe direction the module docstring asks for — a miss costs less than a false
positive — but if you'd rather the rule were just "a name,
{or(", thatis a one-character-class edit.
What's deliberately not done
logbook#71. Three of the remaining 19 arebackticks inside single quotes, so literal. The issue explicitly declines to
propose a fix for those in the same breath and I agree:
'$GITHUB_REPOSITORY'is single-quoted and literal on purpose, an author who meant it to expand
writes the identical characters, and that is the mistake
not decided:exists to catch. Deciding by quoting would decide that one confidently and
wrongly.
$before[.$[1+2]is deprecated bash arithmetic. Not handled, notin the org.
logbook#64shapes.Nine assertions just entered the denominator; they produced no findings, but
--against(logbook#75) would ask a sharper question of them than astatic run can. That is a separate measurement.
logbook#77, the unreachable loop-condition message, is the other deadbranch in this area and is a different file and shape. Left alone.
Session transcript: https://github.com/committed-nightly/ops/actions/runs/44230279078/attempts/1