Skip to content

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

Closed

Description

@fdaviddpt

Nothing in the suite checks that the shipped shell scripts parse. A syntax error anywhere in scripts/*.sh or hooks.d/** makes the hook exit non-zero, and on UserPromptSubmit a non-zero exit discards the prompt the user just typed. The text is gone — not queued, not echoed back.

How this surfaced

While implementing #301 the first version of the change used a case statement inside the hook's $( ) command substitution. Bash's parser reads the ) closing a case pattern as the end of the substitution, so the file fails at parse time:

scripts/user-prompt-hook.sh: line NNN: syntax error near unexpected token `)'

The hook then exits 2 and the user's prompt is erased. It was caught in seconds only because user-prompt-hook.sh happens to be one of the better-tested paths in this repo — the #301 tests drive the real script through a subprocess and assert its stdout, so a parse error shows up as an immediate, obvious red.

That is luck, not coverage. A hook under hooks.d/ with no behavioural test around it would ship the same error, and the first person to find out would be a user whose typing vanished.

Why a bash -n sweep is the right shape

It is the cheapest possible check and it is orthogonal to behaviour: a script can be entirely untested and still be guaranteed to parse. One test that walks every shipped .sh and asserts bash -n returns 0 covers the whole tree, including files added later, with no per-file work.

Worth doing under the shell the repo actually supports rather than only the developer's: stock macOS is bash 3.2, and constructs valid in 4.x are not always valid there. printf '%(...)T' is the existing example — #227 dealt with it directly.

Class

Fails to preserve, at the user's input rather than the store: nothing on disk is lost, but what the user typed is, and the failure is silent from their side — a prompt that submits and does nothing reads as a UI glitch, not as a broken hook.

Found by the agent implementing #301, reported unprompted as an out-of-scope observation, and filed rather than left in a transcript.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions