Skip to content

fix(scripts): make add-lang bench scripts work on Windows#1246

Open
bslatner wants to merge 1 commit into
colbymchenry:mainfrom
bslatner:claude/upbeat-gates-f57426
Open

fix(scripts): make add-lang bench scripts work on Windows#1246
bslatner wants to merge 1 commit into
colbymchenry:mainfrom
bslatner:claude/upbeat-gates-f57426

Conversation

@bslatner

Copy link
Copy Markdown

Problem

scripts/add-lang/verify-extraction.mjs hard-codes execFileSync('codegraph', ...), which always fails with ENOENT on Windows: CreateProcess does no PATHEXT resolution, and npm exposes CLIs on Windows only as .cmd / extensionless-sh / .ps1 shims — none of which Node can spawn without a shell (spawning a .cmd without shell: true is even a hard EINVAL since the CVE-2024-27980 fix). The phantom "could not read codegraph status" failure then forces FORCE_AB=1 workarounds in bench.sh to get past a perfectly healthy extraction.

This bites anyone running the /add-lang bench flow on Windows, regardless of how Node is installed.

Fix

verify-extraction.mjs — resolve the binary instead of assuming a bare name works:

  • CODEGRAPH_BIN env var takes priority everywhere; a .js/.mjs/.cjs path runs via process.execPath.
  • On win32 with no env var, scan PATH for the codegraph.cmd/.exe/.bat shim; batch shims run through the shell with self-quoted args (Node doesn't escape when shell is enabled), so paths with spaces survive.
  • On macOS/Linux with no env var, the call is byte-for-byte the old behavior.
  • The could-not-run path now exits 2 with a CODEGRAPH_BIN hint instead of a raw ENOENT.

bench.sh — honor CODEGRAPH_BIN via a codegraph() function that shadows the PATH lookup (routing .js paths through node), exported so the verify-extraction.mjs child resolves the same binary. Behavior with the env var unset is unchanged.

Validation (Windows 11, Git Bash + PowerShell, real runs)

  • CODEGRAPH_BIN=dist/bin/codegraph.js → verify reads status, RESULT: PASS, exit 0.
  • .cmd shim on PATH, no env var → resolved and passed, including a shim dir and repo path containing spaces (the exact case that previously died with ENOENT).
  • No codegraph resolvable → graceful exit 2 with the hint.
  • Full bench.sh run under Git Bash (env-var and shim-pair variants): clone → wipe+index → verify → correctly skips the paid A/B on a deliberate critical failure, exit code propagated.
  • bash -n clean; POSIX default paths are unchanged by inspection (only error-message text gained a hint).

🤖 Generated with Claude Code

verify-extraction.mjs hard-coded execFileSync('codegraph', ...), which is
ENOENT on Windows: CreateProcess does no PATHEXT resolution, and npm ships
CLIs only as .cmd / sh / .ps1 shims (no .exe), none of which Node can spawn
without a shell. That forced FORCE_AB=1 workarounds to get past a phantom
extraction failure.

- verify-extraction.mjs: resolve the binary — CODEGRAPH_BIN env var first
  (.js/.mjs/.cjs run via process.execPath), else on win32 scan PATH for the
  .cmd/.exe/.bat shim and run batch shims through the shell with self-quoted
  args (Node does not escape when shell is enabled). POSIX default path is
  unchanged. Failure now exits 2 with a CODEGRAPH_BIN hint instead of a raw
  ENOENT.
- bench.sh: honor CODEGRAPH_BIN via a codegraph() function shadowing the
  PATH lookup, exported so the verify-extraction.mjs child resolves the
  same binary. Unset-env behavior is unchanged.

Validated on Windows 11 (Git Bash + PowerShell): env-var override, .cmd
shim resolution with spaces in both shim dir and repo path, graceful
no-binary failure, and a full bench.sh clone->index->verify->skip-A/B run.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant