Skip to content

Fix resolveGrokBin() ENOENT on Windows - #3

Open
irdatrais wants to merge 1 commit into
zachdunn:mainfrom
irdatrais:fix/windows-exe-resolution
Open

irdatrais wants to merge 1 commit into
zachdunn:mainfrom
irdatrais:fix/windows-exe-resolution

Conversation

@irdatrais

Copy link
Copy Markdown

Fixes #2

Problem

On Windows (Git Bash / MSYS2), grok-companion.mjs fails every task with:

Failed to launch grok: spawn /c/Users/<user>/.grok/bin/grok ENOENT

resolveGrokBin() resolves the binary path via which grok (or the ~/.grok/bin/grok fallback) and validates it with existsSync(). The actual installed binary is grok.exe, but:

  • which grok (Git Bash) returns the path without the .exe suffix
  • existsSync() on Windows resolves that bare path leniently and returns true even though the file on disk is grok.exe
  • spawn() does not share that leniency and requires the exact filename, so it throws ENOENT

Setting GROK_BIN manually didn't help either, since the same lenient existsSync() check was used for that path too. The setup subcommand also silently masked this: it reported ok: true with a resolved binary path, while grokVersion() (which spawns that same unresolved path) quietly returned null.

Fix

Added resolveSpawnable(), which on win32 checks for a .exe/.cmd/.bat suffix when the bare path doesn't spawn cleanly, and applied it to all three resolution sources (GROK_BIN, which, and the default fallback path).

Verification

Tested on Windows with GROK_BIN unset:

Before:

{ "ok": true, "binary": "...\grok", "version": null }

task run → Failed to launch grok: spawn ...\grok ENOENT

After:

{ "ok": true, "binary": "...\grok.exe", "version": "grok 0.2.118 (1e1687c1cf) [stable]" }

task --read "..." → runs end-to-end successfully.

No changes to non-Windows behavior — resolveSpawnable() is a no-op passthrough (just existsSync) on other platforms.

which/existsSync resolve the grok binary path without the .exe
suffix on Windows, and existsSync() resolves it leniently even
though the real file is grok.exe. spawn() doesn't share that
leniency, so every task failed with ENOENT unless GROK_BIN was
set to the exact .exe path manually.

resolveSpawnable() checks for .exe/.cmd/.bat on win32 before
falling back to the bare path, applied to the GROK_BIN, which,
and fallback resolution paths.

Fixes zachdunn#2
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.

resolveGrokBin() ENOENT on Windows: spawn fails because resolved path lacks .exe extension

1 participant