Skip to content

check-changeset-drift.test.ts silently runs zero tests on Windows (shebang + CRLF) #1788

Closed

Description

@bradygaster

Summary

test/scripts/check-changeset-drift.test.ts fails to load entirely on Windows checkouts — it reports SyntaxError: Invalid or unexpected token and runs 0 of its 8 tests. Green on Linux CI, so it has gone unnoticed since the file landed in #1481 (2026-07-19).

Discovered by Booster while working #1770 (PR #1786). Independently reproduced and root-caused here.

Impact

The changeset-drift gate is a CI enforcement gate (squad-ci.yml:202 runs node scripts/check-changeset-drift.mjs). Its unit tests are silently dead for every Windows developer. A local npm test shows a failure that reads like environment noise, so the natural response is to ignore it — meaning regressions in evaluateDrift / listFragments would not be caught locally.

This is the same failure shape the workstream keeps hitting: something reports nothing and is mistaken for something passing.

Root cause

scripts/check-changeset-drift.mjs begins with a shebang:

#!/usr/bin/env node

It legitimately needs one — CI invokes it directly. But there is no .gitattributes rule for *.mjs, so it checks out CRLF on Windows. Vite/esbuild's shebang stripping does not survive the \r, leaving # as the first token of the module → SyntaxError: Invalid or unexpected token.

Node itself strips shebangs correctly, which is why node -e "import('./scripts/check-changeset-drift.mjs')" succeeds and masks the problem.

Proof — three controlled runs

Working tree restored clean after each.

Variant Shebang Line endings Result
As committed present CRLF (113) ❌ SyntaxError, 0 tests
Shebang stripped absent CRLF ✅ 8/8 pass
CRLF → LF, shebang kept present LF ✅ 8/8 pass

Natural control in the same directory — the three sibling suites in test/scripts/ all import a .mjs too, and all pass:

Test Imports First line Result
check-changeset-drift.test.ts scripts/check-changeset-drift.mjs #!/usr/bin/env node ❌ fails
parse-diff.test.ts scripts/impact-utils/parse-diff.mjs /** ✅ passes
risk-scorer.test.ts scripts/impact-utils/risk-scorer.mjs /** ✅ passes

The shebang is the only differentiator. test/scripts/ overall: 1 failed | 3 passed (4), 33 tests passing.

Why CI never caught it

  • The test file is in scope — vitest.config.ts has include: ['test/**/*.test.ts'] and npm test is plain vitest run.
  • Linux runners check out LF, so the shebang strips cleanly and all 8 tests pass.
  • Latest dev CI run 32414111495 — test job success.
  • File is byte-identical to origin/dev; this is pre-existing, not introduced by any in-flight PR.

Suggested fix — one line

.gitattributes already encodes exactly this lesson for shell scripts:

# Squad: shell scripts must stay LF — CRLF breaks the shebang on Linux/macOS.
*.sh text eol=lf

The same rule was simply never extended to .mjs:

# Squad: CRLF breaks shebang stripping when a .mjs is imported by vitest on Windows.
*.mjs text eol=lf

Verified above: with LF and the shebang intact, all 8 tests pass.

Note this needs a re-normalize on existing checkouts (git add --renormalize .) for developers who already have the CRLF copy on disk.

Success criteria

  • npx vitest run test/scripts/check-changeset-drift.test.ts reports 8 passed on a fresh Windows checkout
  • scripts/check-changeset-drift.mjs retains its shebang and still runs via node scripts/check-changeset-drift.mjs in CI
  • No other *.mjs regresses — npx vitest run test/scripts/ reports 4 files / 41 tests passing
  • A guard prevents recurrence: any .mjs imported by a test and carrying a shebang is pinned to LF

Repro

git checkout dev
npx vitest run test/scripts/check-changeset-drift.test.ts
# ❯ test/scripts/check-changeset-drift.test.ts (0 test)
# SyntaxError: Invalid or unexpected token

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions