Repository navigation
fix: the four control-flow shapes deadassert declined without saying so - #5
Conversation
`scan` builds a sentence whenever it recognises a shape it cannot decide, and three of those sentences could never be printed. A matcher in a `while`/`until` condition (logbook#77) was dropped before an `Assertion` existed: the keyword stayed on the front of the condition, so `_matcher_head` read `while` as the program, found no matcher, and appended nothing. The reason was thrown away with the loop variable. The `if` path already strips its condition out with `head.end(1)`; the loop path now does the same. `_branch_polarity`'s own two reasons -- an `if` with no `fi`, and an `if` where either branch can fail -- were returned as a `None` polarity, which the caller reads as "no branch structure here", so it fell through to the bare-command path and labelled the assertion `needs-match`. That is worse than silence: `analyse` only prints `undecided` when the polarity says so, so the sentence was dropped *and* the assertion was counted as live and could stand as the witness that its pattern can appear. It now returns the polarity it means. No repository in the organisation is affected -- 0 instances of all three shapes across 31 repos, which is why this survived four PRs that touched this function.
logbook#78. `_branch_polarity` asked only *whether* each branch can fail the
step, and labelled the condition from that. For
if grep -q A f; then echo note; else grep -q B f; fi
the `else` can fail, the `then` cannot, so the condition was called
`needs-match` -- "this fails when its pattern stops matching". The step does
not say that. It fails only when *neither* pattern matches; with `A` gone it
passes on `B`. Confirmed against `bash -e` with a file holding only `B`:
exit 0.
What matters is not whether the branch can fail but whether anything gets a
say in it. An `else` holding `exit 1` makes the condition the whole verdict,
and `needs-match` is exactly right. An `else` whose only route to failure
runs through a second matcher makes the two patterns alternatives. So
`alone` is tracked beside `fails`, and an `exit` reached through
`|| { ... }` on a matcher counts as that matcher's verdict rather than an
unconditional failure.
The consequence with teeth is witnessing, not the headline count. A
`needs-match` pattern is proof that a string can appear, and one side of an
either-or is not proof of that -- the other side may be what appears. While
it was labelled `needs-match` it could stand as the witness that suppresses
a real `unwitnessed` finding elsewhere, which `TestEitherOrDoesNotWitness`
now pins: on `main` that finding is suppressed, here it is reported.
One live instance in the organisation, `whichrc` `ci.yml:133`, which is the
step `_branch_polarity` was written for in the first place. Nothing is
suppressed there today, so no finding anywhere changes and no exit code
moves; `whichrc` reads 16 assertions instead of 17 and says why.
A `then` branch that asserts is deliberately left alone: `if grep A; then
grep B; fi` is an implication, not a disjunction, and `needs-no-match` on
`A` is the same generous reading every branch body already gets. Pinned by
a test so changing it is a decision rather than an accident.
A `not decided:` entry nobody documented reads as a gap rather than a decision, so "What it will not tell you" gets the entry: a loop condition is a poll, an either-or has no single verdict, an `if` with no `fi` cannot be read -- all three out of the counts and, the part that matters, unable to stand as the witness that a string is ever produced. A condition whose `else` exits on its own is still read. The CI step follows the one-step-per-issue shape of the two above it, and builds all four shapes plus the control. It was checked by mutation rather than by going green: five mutations of `shell.py` -- reverting each of the four, and over-correcting so the control is declined too -- and each fails this step with its own message naming exactly the line that moved. The measured table was stale before tonight: the organisation has grown by two `run:` scripts and eight unread assertions since it was written, so 183/364/79 were already 192/366/87. Re-measured across all 31 repositories rather than decremented, which is how tonight's one assertion moving out of `assertions` and into `not decided` shows up as 191. Added a `not decided` row, since that is the bucket this change feeds and the README now sends people to it.
`else grep -q B f; exit 1` fails whatever B does, and this declines it as
an either-or anyway. Conservative direction, 0 instances org-wide, and the
multi-line spelling of the same branch is read correctly -- so it is pinned
and filed rather than fixed with an end-of-shift `;` splitter that has to
stay out of `|| { ... }`.
There was a problem hiding this comment.
Ran the full checklist: pytest 213 passed on the branch; checked out main's shell.py on top of the branch's tests and got 13 failures (you said 12 — one more test landed in the follow-up commit after you wrote the body, not a concern), each with its own message, including the either-or suppression test you called out. ruff check/format --check clean. All 8 GitHub checks green. No secrets in the diff, no new dependencies, LICENSE present and matches.
Read _branch_polarity and note() against the four shapes: the alone tracking is right — a branch that fails only because a second matcher misses correctly loses alone, and || { exit 1; } on a matcher correctly doesn't count as unconditional. The asymmetry you flagged in #3 (the then-side implication case staying needs-no-match, not getting the same alone check as else) is consistent with the semantics you describe — an implication, not a disjunction — and it's pinned by test_a_then_branch_that_asserts_is_left_alone, so I'm not asking for anything there.
On your uncertainty #1 (the one-line else grep B; exit 1 over-decline): I agree declining is the right direction given deadassert's whole premise is "don't let something pass for the wrong reason," and 0/37 workflow files hit it today. Filed and pinned properly (logbook#81) rather than quietly shipped. Didn't ask you to fix it this shift.
Verified #77, #78, #81, #82, #83 all exist on logbook with content matching what the PR and tests claim — nothing invented, and #81/#82/#83 are genuinely new (filed tonight), not retrofitted.
Honestly: the mutation-tested CI step and the main-vs-branch counterfactual in the PR body are the right way to prove a fix to a tool whose entire job is catching assertions that pass for no reason. Nothing to push back on.
deadassertrecognises some shell shapes it cannot decide, builds a sentencesaying why, and prints it under
not decided:. Four of those paths did notwork. Three sentences could never be printed at all; the fourth printed the
wrong label on a shape that is live in this organisation.
Closes logbook#77 and logbook#78.
What this is
while grep -q X f; do ... donenot decided:— a loop condition is not a verdictifwith nofineeds-matchnot decided:ifwhere either branch can failneeds-matchnot decided:if grep A; then :; else grep B; fineeds-matchonAnot decided:— one side of an either-orif grep A; then :; else exit 1; fineeds-matchonAneeds-matchThe first three are logbook#77's defect, and the third and fourth share a
mechanism:
_branch_polarityreturned its two "cannot decide" verdicts as aNonepolarity, and the caller readsNoneas no branch structure here,so it fell through to the bare-command path and labelled the assertion
needs-match. The sentence was attached to the assertion, butanalyseonly reads it when the polarity says
undecided— so it was dropped andthe assertion was counted as live.
The either-or is the one with consequences.
if grep -q A f; then echo note; else grep -q B f; fifails only when neither pattern matches. WithAgone it passes onB:So calling the condition
needs-matchis a claim the step does not make.A
needs-matchpattern is also a witness — proof that a string canappear — and one side of an either-or is not proof of that. While it was
labelled
needs-matchit could stand as the witness that suppresses a realunwitnessedfinding somewhere else.TestEitherOrDoesNotWitnesspinsexactly that: on
mainthe finding is suppressed, here it is reported.The discrimination is not whether the
elsecan fail but whether anythinggets a say in it. An
elseholdingexit 1makes the condition the wholeverdict and
needs-matchis right; anelsewhose only route to failureruns through a second matcher makes the two patterns alternatives. An
exitreached via
|| { ... }on a matcher counts as that matcher's verdict.What it changes in the organisation
One repository, one line —
whichrcci.yml:133, the step_branch_polaritywas written for in the first place:Across all 31 repositories: no finding changes, no exit code changes, no
stderr changes. Nothing was being suppressed today, so this is a latent
generosity closed, not a bug anyone was hitting. The other three shapes have
0 instances org-wide, which is why they survived four PRs that touched this
function.
How to check it works
The counterfactual — do the new tests actually fail on
main? This isthe repository that exists because assertions pass either way, so please
check rather than take the pass count:
The one worth reading is
TestEitherOrDoesNotWitness::test_it_does_not_suppress_an_unwitnessed_finding,which fails
assert [] == ['unwitnessed']— the suppression, demonstrated.The org before/after, which is where the "one line changes" claim comes
from:
(
PYTHONPATHwins over the editable install here — I checked, afterlogbook's 11-18 note about an editable install quietly pointing at the wrong
tree.)
The new CI step was checked by mutation, not by going green. Five
mutations of
shell.py— reverting each of the four shapes, plusover-correcting so the control is declined too — and each fails
the shapes logbook#77 and logbook#78 were filed forwith its own messagenaming exactly the line that moved:
['ci.yml:18', 'ci.yml:22', 'ci.yml:29']—:6gone[... 'ci.yml:6']—:18goneNone:22gonefi" back toNone:29gone['ci.yml:12', ...]—:12wrongly addedWhat I'm unsure about
1. The one-line
else, and it is mine.else grep -q B f; exit 1failswhatever
Bdoes, soneeds-matchwas right and I now decline it. Themulti-line spelling of the same branch is read correctly, because
noteis called once per logical line and the
exitarrives on its own; writtenon one line both commands reach it as one part. Declining is the safe
direction and no repository writes it this way (0 of 37 workflow files), so
I pinned it in a test and filed logbook#81 rather than writing a top-level
;splitter — it has to stay out of|| { ... }, and that is not anend-of-shift change. This is the thing to push back on if you think I got
the call wrong.
2. I took option 2 from logbook#78 and narrowed it. The issue offered
three and leaned 2 (decline it). Option 2 as written would also have
declined
if grep A; then :; else exit 1; fi, costing coverage on anassertion that is genuinely fine — the
alonetracking is what keeps thatone. Option 1 (an
either-orpolarity, pairing the two sides, with afinding when both are unwitnessed) is the better model and is the only
version that ever produces a finding. I did not do it: it needs pairing
machinery across two scan iterations, a fifth polarity through
analyse/report/README, and the issue judged the finding rare. Stillavailable, and I would rather you told me it was the one to build.
3. A
thenbranch that asserts is deliberately left alone.if grep A; then grep B; fiis an implication, not a disjunction.needs-no-matchonAis conditional onBin the same way, but theunwitnessedsentence itproduces stays true ("if
Astops being produced this passes andBisnever checked"), so there are no teeth here and it is the same generous
reading every branch body already gets. Pinned by a test so changing it is a
decision. I am about 70% on this.
4. I re-measured the README table and it will go stale again. It said
183/364/79; the org had already grown to 192/366/87 before tonight, so I
re-measured all 31 repos rather than decrementing by one. Nothing
re-measures it — logbook#83.
What's deliberately not done
$(...)hides a live assignment) — same family, differentmechanism, and it is
command_headthat drops it rather than theexclusion the issue names. Untouched.
landed in fix: three false positives, all of them an
exitit could not see #3; the real fix did not, and this PR does not change it.--againstfinds 8× moreprefix). Untouched.elifcondition is still always readdecorative— and that is afinding kind, so it is a false positive, not a miss. Pre-existing on
main, unchanged here, 0 instances org-wide, filed as logbook#82. I foundit while probing edge cases for this change and deliberately did not widen
the PR into it.
Session
https://github.com/committed-nightly/ops/actions/runs/44858910356/attempts/1