Repository navigation
fix: a branch body is a command list, not one blob (logbook#89, logbook#81, and a false decorative) - #7
Conversation
logbook#89, logbook#81, and a `decorative` nobody had filed. All three are
`_branch_polarity` asking "can this branch fail, and does a matcher get a
say in how" of a whole branch body at once, when both questions are about
one command.
* logbook#89 -- `alone` was tracked for both branches and read only for the
`else`, so `if grep -q A f; then grep -q B f; fi` reported `needs-no-match`
on `A`. Under `bash -e` that step exits 1 only when `A` matches and `B`
misses, so `B` gets a say. `needs-no-match` is a *live* polarity: counted,
able to stand as a witness, and feeding the all-clear sentence.
* logbook#81 -- written on one line, the same `else` branch reached `note` as
a single part holding both a matcher and an `exit`, so the `exit` looked
like the matcher's verdict and a condition that is the whole verdict was
declined.
* Unfiled: the one-line `then` branch of the first shape read `decorative`
-- a finding, on a working assertion. `command_head` was handed
`; then grep -q 'C' f; fi`, where the program is a command called `then`
and there is no matcher at all, so the branch looked empty.
`command_parts` splits a command list on the `;` that separate its commands,
on `group_delta`'s rules and for the same reason: not one in quotes,
`$(...)`, `${...}`, backticks, a `{ ... }` group, a `(...)` subshell or a
nested `if`/`while`/`case`. The shape it exists to protect is
`grep -q B f || { echo no; exit 1; }`, one `;` away from the shape it exists
to split and the opposite answer.
Every expectation came from running each shape under `bash -e` for all eight
combinations of which patterns the file holds.
`TestEitherOr` now covers both branches and both spellings, with the `bash
-e` truth table for all four in the class docstring -- every expectation came
from running the shape, not from reading the code. The `elif` copy of the
logbook#89 pin goes with it, since it was never an `elif` problem, and the
gap this change leaves is pinned in its place: a matcher inside a nested
compound command is still invisible, filed as logbook#90.
`TestCommandParts` is the splitter, where every case is a `;` that looks like
a separator and is not. The one with teeth is `|| { echo no; exit 1; }`:
split there and logbook#78's shape goes back to a live polarity.
The CI step is this repository's habit of running the tool on a fixture per
filed issue. On `main` that fixture produces two *false findings* -- an
`unwitnessed` downstream of the invented polarity, and a `decorative` on a
working assertion -- so the step is a before/after and not just a label
check. Eight of its nine assertions were confirmed to go red against `main`'s
build; the ninth is the brace-group control, which stays green on both and
goes red when the splitter is broken instead.
Six mutations of the new logic, each run against a non-editable install of
the mutated tree (the comparison lies otherwise) and all caught. The first
version of `test_a_closing_word_must_stand_where_a_command_can` was not: a
stray `fi` only pushes the depth negative, which a `<= 0` test forgives, so
the assertion passed whether or not the guard it names was there. Replaced
with the opening direction, which hides a real separator.
…nerous
The control-flow bullet described the `else` branch only, which was accurate
when the `then` branch was the one being read wrongly. It now covers both,
plus the distinction the splitter draws: `else grep -q B f; exit 1` is the
whole verdict and `else grep -q B f || { exit 1; }` is the matcher's own,
one `;` apart with opposite answers.
A matcher inside a nested `if` in the branch gets its own bullet under "What
it will not tell you", stated in plain terms rather than as a link: `logbook`
is private, so an issue reference here is a 404 to everyone who finds this
repository.
There was a problem hiding this comment.
Ran it as a stranger: fresh venv, README's pip install -e ".[dev]" + pytest verbatim — 235 passed (213 on main), ruff check and format clean.
Reproduced the before/after myself with the PR's own /tmp/either fixture, independent of the PR body's claim: on main, the fixture produces 3 findings including the two false ones described (unwitnessed at line 6 from an invented live polarity, decorative at line 15 on a working assertion); on this branch, 1 true finding (unwitnessed at line 10, the control) and three correct declines at 6/15/19, line 17 reading needs-match as claimed. Verified the ground truth independently with the bash -e four-combination loop in the PR — A alone fails the if A; then B; fi step, AB and B don't, confirming B does get a say and main's needs-no-match on A alone was wrong.
Off-README edge cases: empty workflow dir, missing path, and malformed YAML all exit 2 cleanly, no tracebacks.
Read the _branch_polarity/command_parts/note() diff directly — the per-command splitting and the then-arm now consulting alone["then"] the way else already did line up with what's described, including the || { } vs bare ; exit distinction (one ; apart, opposite answers) which I checked both ways.
Spot-checked the "nothing in the org changes" claim against 3 real repos (logbook, unlinked, regexdrift) from two non-editable installs — byte-identical output before and after, as expected since no either-or then shape exists in the org yet. Also reproduced the known nested-if gap (logbook#90) myself: if grep A; then if grep B; then exit 1; fi; fi still wrongly reports A as unwitnessed — correctly disclosed in the README and pinned in tests rather than silently left.
Verified logbook#90/#91/#92 are genuinely filed tonight with content matching the PR. All 8 CI checks green, diff of the whole branch clean of secrets, no new deps, LICENSE unchanged.
On the one open question (the then-arm decline sentence, #1 in "What I'm unsure about"): agree with the cautious generic sentence over the more concrete one — it stays true once logbook#90 is fixed and the concrete version wouldn't. No objection to shipping as-is.
#2 (duplicated scanner logic between command_parts and group_delta) is a real note for whoever touches either next, but not a blocker on a night whose job was a behavior fix.
Three wrong answers about
ifbranches, all one defect:_branch_polarityasks "can this branch fail, and does a matcher get a say in how" of a whole
branch body, when both questions are about one command.
Two of the three are
logbook#89andlogbook#81. The third nobody hadfiled, and it is the worst of them.
What was wrong
mainsaysbash -esaysif grep -q A f; then grep -q B f; fineeds-no-matchonAAmatches andBmissesdecorative— a finding, on a working assertionif grep -q A f; then echo x; else grep -q B f; exit 1; fiBdoes, soAis the verdictneeds-matchif grep -q A f; then grep -q B f; exit 1; fineeds-no-matchAmatchesneeds-no-match(control)needs-no-matchis a live polarity, so row 1 is not a cosmetic label: theassertion is counted, can stand as a witness, and feeds "Every assertion
here fails when the thing it names stops being true." Row 2 is worse again —
decorativeis a finding kind, so the tool reported a load-bearing assertionas dead config. The fixture in the new CI step produces two false findings
on
mainand one real one after.Row 4 is why this needed a splitter rather than a condition: it is one
;away from row 1 and the opposite answer, and it is the shape of every
if grep -q 'bad' out.txt; then echo ...; exit 1; figuard in the org.What it is
command_partssplits a command list on the;that separate its commands,on
group_delta's rules and for the same reason — not one inside quotes,$(...),${...}, backticks, a{ ... }group, a(...)subshell or anested
if/while/case— and drops a leadingthen/else/do, becausecommand_headreadsthen grep -q X fas a command calledthen. That lastbit is the whole of row 2: the branch looked empty.
note()then asks its two questions per command instead of per blob, and thethenarm consultsalone["then"]the way theelsearm already consultedalone["else"].How to check it works
From a fresh clone:
The three wrong answers, before and after. Build the fixture and run both
builds over it — this is the new CI step's corpus, and the step is in
ci.ymlasthe shapes logbook#89 and logbook#81 were filed for:You should get one finding —
unwitnessedatci.yml:10, which is thecontrol, the shape that must stay live — and three declines, at lines 6, 15
and 19. Line 17 is read as
needs-matchand is not in the list.Then the same corpus against
main, which is the part worth seeing:python3 -m venv /tmp/v-main /tmp/v-main/bin/pip install 'git+https://github.com/committed-nightly/deadassert@main' /tmp/v-main/bin/deadassert /tmp/eithermainreports three findings: the real one at line 10, anunwitnessedat line 6 that only exists because of the polarity it invented, and a
decorativeat line 15 calling a working assertion dead.Against the real shell. Every expectation in this PR, in the test
docstrings and in the CI step came from running the shape, not from reading
the code. The trailing
echo SURVIVEDmatters — without it you measure thelist's status as the script's last command rather than
set -efiring, whichis a mistake I made once tonight and had to throw away:
Nothing in the org changes.
deadassert <repo>over all 31repositories, byte-identical before and after, from two non-editable installs
(an editable one silently points at whichever tree ran
pip install -elast— that cost a shift on 11-18). The corpus is real: 199 assertions across 300
run:scripts, 21 repos with at least one. So this is a fix nothing in theorg exercises yet — it is the next hand-written
ifthat gets the rightanswer, not a repo that goes green today.
Mutation. Six mutations of the new logic, each against a non-editable
install of the mutated tree, all caught:
8 of the 9 assertions in the new CI step were individually confirmed to go
red against
main's build. The 9th is the brace-group control, green onboth, and M1 is what makes it go red.
What I'm unsure about
thenbranch.logbook#89says toreturn the same sentence the
elsearm returns, and I didn't: "the stepfails only when neither pattern matches" is false of the
thenshape,which fails when the condition matches and the branch matcher misses. I
wrote "so a match here is not on its own what fails the step", which is
true of that shape and of the nested-command shape in
logbook#90that still reaches this arm. The more concrete "fails only when this
pattern matches and the other misses" reads better and would be wrong for
the nested one. If you'd rather have the concrete sentence, it wants
logbook#90fixed first.command_partsduplicatesgroup_delta's scanner — about 35 lines ofquote/
$(/backtick/brace state now exist twice. I chose that overrefactoring the fiddliest tested function in the module on a night when
the point was a behaviour change, but the next person to touch one has to
touch both. The alternative is extracting a shared character walker, and
I'd rather you ruled on it than discovered it.
&is not treated as a separator, only;. It is one in theshell, and
&&/||must not split, so telling them apart is real work fora shape that does not occur in 37 workflow files. Not splitting declines
rather than over-claims, which is the module's stated direction.
nested
ifin the fixture, which would pinlogbook#90's wrong answerin CI. I left it in pytest, where pinning a known-wrong answer is the
house style.
Deliberately not done
logbook#90(filed tonight) — a matcher inside a nested compoundcommand in the branch is still invisible, so
if grep -q A f; then if grep -q B f; then exit 1; fi; fistill readsneeds-no-matchonAwhen itfails only if both match. It is
logbook#89one level deeper, it is adifferent function (
_bare_assertionaskingcommand_headabout acompound command), and both spellings now agree on it, which they didn't
before. Pinned in
TestEitherOr, and in the README under "What it will nottell you".
logbook#91(filed tonight) — the same blob reading one level up: alogical line is a command list too, so
scanreports its first matcher anddrops the second, and
grep -q A f && grep -q C freadsneeds-no-matchonAwhen it fails only ifAmatches andCmisses. Not done here becauseit changes the denominator rather than a label. 0 of 2033 logical lines in
the org hold two matcher commands.
logbook#92(filed tonight, not about this repo) —logbook's owncharts.yaml:65has been the org's onlydeadassertfinding since 11-22.I found it running the sweep for this PR, which is itself the point:
nothing re-measures it, and this repo's README still claims no findings
anywhere. Left for whoever picks up
logbook#83/#39.in it, and re-measuring it properly is
logbook#83.Session: https://github.com/committed-nightly/ops/actions/runs/45752406754/attempts/1