Skip to content

Assert every shipped shell script parses, under the bash that can actually see the failure - #305

Merged
fdaviddpt merged 1 commit into
mainfrom
test/302-shell-parse-gate
Aug 4, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
test/302-shell-parse-gate

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #302.

Nothing in the suite checked that the shipped shell scripts parse. A syntax error in scripts/*.sh or hooks.d/** makes a hook exit non-zero, and on UserPromptSubmit that discards the prompt the user just typed. #301's implementation hit exactly this — case inside a $( ) command substitution — and it was caught only because user-prompt-hook.sh happens to be one of the better-tested paths here.

The interpreter question, and a correction to the issue

The issue justified running under the floor bash by citing printf '%(FMT)T'. That is wrong, checked rather than reasoned about: bash -n returns 0 on it under real bash 3.2. It is a runtime failure, and scripts/lib-clock.sh:97 carries it today with a correct runtime guard.

The conclusion survives for a better reason. The #301 construct — case inside $( ) — is a bash-3.2-only parse error; it parses cleanly on bash 4+. So a gate running under whatever bash is first on PATH would have returned ok on the exact file that erased a prompt. The catchable-only-on-3.2 set is ;;&, |&, coproc, and case inside $( ).

So the gate does not pick an interpreter. It probes every bash it can find, dedupes by real path, records versions, and runs all of them.

Three claims, none standing in for another

  • Parse errors — runs wherever a bash exists, always has value.
  • Floor coverage — report.floor_covered, a separate boolean. Exactly one test claims it, and on a runner without bash 3.2 that test pytest.skips with the gap named verbatim, listing the four constructs. A bash-5 pass never stands in for it.
  • The mirror gap — this machine has only bash 3.2, so what is missing locally is modern-bash coverage. The run prints that too.

Both no-op paths return SKIPPED, not ok: no bash on the machine, and a tree with no shell files. Both say "the gate did not run, which is not the same as finding nothing wrong."

offered and used are separate fields. The first draft printed offered under the label interpreters:, overstating coverage by exactly the amount this gate exists to prevent — /bin/sh is discovered everywhere and handed nothing, because no #!/bin/sh script exists.

File set, cross-checked rather than trusted

23 files: scripts/*.sh (21), hooks.d/** (2), one test fixture the suite actually executes. Untracked files are walked deliberately — a hook written five minutes ago is when this earns its keep; .gitignored machine state is not.

test_the_walk_covers_every_shell_file_git_tracks asserts git ls-files '*.sh' ⊆ the walk, so a silently dropped directory fails rather than shrinking the set. Plus named files and a > 15 floor. That is the direct answer to "would this pass if it checked nothing?"

Shebang selects the grammar: #!/bin/sh → sh -n; no shebang → bash, and the file is recorded in assumptions; a non-shell shebang → unchecked, which a test asserts is empty.

Tests

TDD. RED, with the authentic #301 construct injected into hooks.d/after_save/50-git-backup.sh — the quiet hook the issue names:

E       AssertionError: 1 of 23 shell file(s) do not parse under /bin/bash (bash 3.2) — shipped shell that does not parse:
E           hooks.d/after_save/50-git-backup.sh under /bin/bash (bash 3.2)
E             .../50-git-backup.sh: line 23: syntax error near unexpected token `;;'
E           .../50-git-backup.sh: line 23: `  auto) echo automatic ;;'
2 failed, 14 passed in 2.36s

GREEN: 16 passed in 1.99s. Full suite after: 1447 passed, 43 skipped.

What it found

Nothing. All 23 parse under bash 3.2.

Cost

2.0s on a 1047s suite (0.2%). One process per (file, interpreter) pair, lru_cached across the five tests that ask for the repo-wide run.

Not changed here

pyproject.toml has no -rs in addopts, so on a runner without the floor bash the skip renders as a bare s and the gap message is invisible in the log — a green CI run then reads as "3.2 is covered" when it is not. That affects the 43 skips already in the suite, not just this one, so it is filed separately rather than changed inside this PR.

…ly present (#302)

Nothing in the suite checked that scripts/*.sh and hooks.d/** parse. A syntax
error in a hook makes it exit non-zero, and on UserPromptSubmit a non-zero exit
discards the prompt the user just typed. #301 produced exactly that shape --
a case inside the hook's $( ) substitution -- and it was caught only because
that one file happens to be well tested.

The interpreter is the whole question. #302 cites printf '%(FMT)T' as the
reason to check under bash 3.2, but that construct parses fine on 3.2 and fails
at runtime, so no parse gate can catch it. What a 3.2 parse does catch is
;;&, |&, coproc, and case inside $( ) -- the last being #301's own error, which
parses cleanly on bash 5. A gate under whatever bash is first on PATH would
have reported ok on the file that erased a prompt.

So the gate runs under every bash it finds and states which, separating what
the machine offered from what was used. Floor coverage is a separate field
claimed by exactly one test, which skips loudly naming the unchecked constructs
rather than letting a bash-5 pass stand in for a user's Mac. Files dispatch on
shebang; anything unclassifiable lands in unchecked, which a test asserts empty.
The walk is cross-checked against git ls-files so a dropped directory fails
rather than shrinking the file set in silence.

Red against the #301 construct injected into hooks.d/after_save/50-git-backup.sh,
green with it removed. Found nothing: all 23 files parse under bash 3.2 today.
Cost 2.0s on a 1047s suite.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt force-pushed the test/302-shell-parse-gate branch from 0e67e35 to 953bb14 Compare August 4, 2026 11:32
@fdaviddpt
fdaviddpt merged commit 29670b3 into main Aug 4, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the test/302-shell-parse-gate branch August 4, 2026 11:50
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.

No test asserts the shipped shell scripts parse — a syntax error in a hook erases the user's prompt

1 participant