Skip to content

check-*.mjs under bash: the script exits 2, but a piped grep reports it as a pass #505

Description

@explosivebit

What is wrong

website/scripts/check-*.mjs are Node ESM scripts, but they are runnable-looking as
bash scripts/check-content-completeness.mjs - and that form fails in a way that reads as success
in the most common usage.

$ bash website/scripts/check-content-completeness.mjs
website/scripts/check-content-completeness.mjs: line 2: //: is a directory
website/scripts/check-content-completeness.mjs: line 3: //: is a directory
$ echo $?
2

The script itself fails loudly. The trap is the pipeline: bash script.mjs | grep … reports
grep's status (1 for "no matches"), so a caller checking the exit code of the pipeline sees "no
issues found" - a green that never ran the check. Three agents hit exactly this in one session and
two of them reported the completeness gate as green before realising.

Evidence

  • bash website/scripts/check-content-completeness.mjs → exit 2, //: is a directory
  • node website/scripts/check-content-completeness.mjs → exit 0, [content] total 176 files scanned, 0 issues
  • the same shape applies to check-translation-drift.mjs and check-dead-links.mjs

Fix options

  1. Add a #!/usr/bin/env node-aware guard is not possible in bash - the practical fixes are:
  2. a one-line note next to each documented invocation (docs/ and AGENTS.md) that the runner is
    node, and
  3. make the scripts refuse to be interpreted by anything but Node is not feasible; instead, prefer
    wiring the common ones into npm scripts (npm run check:content), so the invocation people copy
    is already correct.

Option 3 removes the failure mode instead of warning about it.

Revisit trigger

Act if a review or CI summary reports one of these checks green while the underlying command was
bash. The two are indistinguishable in every summary format we use today.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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