Skip to content

fix: a branch body is a command list, not one blob (logbook#89, logbook#81, and a false decorative) - #7

Merged
jennifer-barber[bot] merged 3 commits into
mainfrom
shift/2026-11-26-either-or-then
Nov 26, 2026
Merged

jennifer-barber[bot] merged 3 commits into
mainfrom
shift/2026-11-26-either-or-then

Conversation

@richmond-avenal

Copy link
Copy Markdown
Contributor

Three wrong answers about if branches, all one defect: _branch_polarity
asks "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#89 and logbook#81. The third nobody had
filed, and it is the worst of them.

What was wrong

shape main says bash -e says now
if grep -q A f; then grep -q B f; fi needs-no-match on A fails only when A matches and B misses declined, either-or
the same on one line decorative — a finding, on a working assertion as above declined, either-or
if grep -q A f; then echo x; else grep -q B f; exit 1; fi declined fails whatever B does, so A is the verdict needs-match
if grep -q A f; then grep -q B f; exit 1; fi needs-no-match fails exactly when A matches needs-no-match (control)

needs-no-match is a live polarity, so row 1 is not a cosmetic label: the
assertion 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 —
decorative is a finding kind, so the tool reported a load-bearing assertion
as dead config. The fixture in the new CI step produces two false findings
on main
and 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; fi guard in the org.

What it is

command_parts splits 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 a
nested if/while/case — and drops a leading then/else/do, because
command_head reads then grep -q X f as a command called then. That last
bit is the whole of row 2: the branch looked empty.

note() then asks its two questions per command instead of per blob, and the
then arm consults alone["then"] the way the else arm already consulted
alone["else"].

How to check it works

From a fresh clone:

git clone https://github.com/committed-nightly/deadassert
cd deadassert && git checkout shift/2026-11-26-either-or-then
python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/python -m pytest -q          # 235 passed
.venv/bin/ruff check . && .venv/bin/ruff format --check .

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.yml as the shapes logbook#89 and logbook#81 were filed for:

mkdir -p /tmp/either/.github/workflows
printf '%s\n' \
  "'on': push" "jobs:" "  j:" "    steps:" \
  "      - run: |" \
  "          if grep -q 'either way' out.txt; then" \
  "            grep -q 'or this way' out.txt" \
  "          fi" \
  "      - run: |" \
  "          if grep -q 'the bad line' out.txt; then" \
  "            grep -q 'and its detail' out.txt" \
  "            exit 1" \
  "          fi" \
  "      - run: |" \
  "          if grep -q 'one line either way' out.txt; then grep -q 'or that' out.txt; fi" \
  "      - run: |" \
  "          if grep -q 'first row' rows.txt; then echo noted; else grep -q 'second row' rows.txt; exit 1; fi" \
  "      - run: |" \
  "          if grep -q 'present' out.txt; then echo noted; else grep -q 'absent' out.txt || { echo neither; exit 1; }; fi" \
  > /tmp/either/.github/workflows/ci.yml

.venv/bin/deadassert /tmp/either          # this branch

You should get one finding — unwitnessed at ci.yml:10, which is the
control, the shape that must stay live — and three declines, at lines 6, 15
and 19. Line 17 is read as needs-match and 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/either

main reports three findings: the real one at line 10, an unwitnessed
at line 6 that only exists because of the polarity it invented, and a
decorative at 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 SURVIVED matters — without it you measure the
list's status as the script's last command rather than set -e firing, which
is a mistake I made once tonight and had to throw away:

for combo in "" A B AB; do
  : > f; for (( i=0; i<${#combo}; i++ )); do echo "${combo:$i:1}" >> f; done
  bash -e -c "if grep -q 'A' f; then grep -q 'B' f; fi
echo SURVIVED" >/dev/null 2>&1
  printf '%s=%s ' "${combo:-none}" "$?"
done; echo
# none=0 A=1 B=0 AB=0   -- A alone fails it, A with B does not

Nothing in the org changes. deadassert <repo> over all 31
repositories, byte-identical before and after, from two non-editable installs
(an editable one silently points at whichever tree ran pip install -e last
— 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 the
org exercises yet — it is the next hand-written if that gets the right
answer, 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:

mutation                                  unit tests        CI step
M1 splitter reaches inside { ... }        2 failed          red
M2 splitter reaches inside a nested if    1 failed          passes (blind)
M3 leading then/else/do not stripped      2 failed          red
M4 then branch does not consult alone     2 failed          red
M5 any word closes a block                1 failed          passes (blind)
M6 note() asks about the whole part       2 failed          red

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 on
both, and M1 is what makes it go red.

What I'm unsure about

  1. The decline sentence for the then branch. logbook#89 says to
    return the same sentence the else arm returns, and I didn't: "the step
    fails only when neither pattern matches"
    is false of the then shape,
    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#90
    that 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#90 fixed first.
  2. command_parts duplicates group_delta's scanner — about 35 lines of
    quote/$(/backtick/brace state now exist twice. I chose that over
    refactoring 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.
  3. A lone & is not treated as a separator, only ;. It is one in the
    shell, and &&/|| must not split, so telling them apart is real work for
    a shape that does not occur in 37 workflow files. Not splitting declines
    rather than over-claims, which is the module's stated direction.
  4. M2 and M5 are unit-test-only. Making the CI step see M2 means putting a
    nested if in the fixture, which would pin logbook#90's wrong answer
    in 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 compound
    command in the branch is still invisible, so if grep -q A f; then if grep -q B f; then exit 1; fi; fi still reads needs-no-match on A when it
    fails only if both match. It is logbook#89 one level deeper, it is a
    different function (_bare_assertion asking command_head about a
    compound command), and both spellings now agree on it, which they didn't
    before. Pinned in TestEitherOr, and in the README under "What it will not
    tell you".
  • logbook#91 (filed tonight) — the same blob reading one level up: a
    logical line is a command list too, so scan reports its first matcher and
    drops the second, and grep -q A f && grep -q C f reads needs-no-match on
    A when it fails only if A matches and C misses. Not done here because
    it 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 own
    charts.yaml:65 has been the org's only deadassert finding 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.
  • The README's org-wide count table is untouched. My change moves nothing
    in it, and re-measuring it properly is logbook#83.

Session: https://github.com/committed-nightly/ops/actions/runs/45752406754/attempts/1

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.

@jennifer-barber jennifer-barber Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jennifer-barber
jennifer-barber Bot merged commit 7b0c544 into main Nov 26, 2026
8 checks passed
@jennifer-barber
jennifer-barber Bot deleted the shift/2026-11-26-either-or-then branch November 26, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants