fix(make-pdf): Bun.which-based binary resolution for browse + pdftotext on Windows (v1.24 extension)#1307
Open
scarson wants to merge 1 commit intogarrytan:mainfrom
Open
Conversation
…xt on Windows Extends v1.24.0.0's Bun.which + GSTACK_*_BIN override pattern (introduced in browse/src/claude-bin.ts via garrytan#1252) to the two other binary resolvers in the codebase: make-pdf/src/browseClient.ts:resolveBrowseBin and make-pdf/src/pdftotext.ts:resolvePdftotext. Same Windows quirks (fs.accessSync(X_OK) degrades to existence-check; `which` isn't available outside Git Bash; bun --compile --outfile X emits X.exe), same Bun.which-based fix shape, same env override convention. Changes: - GSTACK_BROWSE_BIN / GSTACK_PDFTOTEXT_BIN as the v1.24-aligned overrides; BROWSE_BIN / PDFTOTEXT_BIN remain as back-compat aliases. - Bun.which() replaces execFileSync('which', ...) for PATH lookup. Handles Windows PATHEXT natively; no more `where`-vs-`which` branch. - findExecutable(base) helper exported from each module, probes .exe/.cmd/.bat after the bare-path miss on win32. Linux/macOS behavior is bit-identical (isExecutable short-circuits before the win32 branch ever runs). - macCandidates renamed posixCandidates (always was — /opt/homebrew, /usr/local, /usr/bin). No Windows candidates added; Poppler installs scatter across Scoop/Chocolatey/portable zips and guessing causes false positives. - Error messages get a Windows install hint (scoop install poppler / oschwartz10612) and `setx` example for GSTACK_*_BIN. - Pre-existing test 'honors BROWSE_BIN when it points at a real executable' was hardcoded /bin/sh — made cross-platform via a REAL_EXE constant (cmd.exe on win32, /bin/sh on POSIX). Was a Windows-CI blocker on its own. Coordination: PR garrytan#1094 (@BkashJEE) covered browseClient.ts independently with a narrower scope; this PR's pdftotext + cross-platform tests + GSTACK_*_BIN naming are additive. Either order of merge works. Test plan: - bun test make-pdf/test/browseClient.test.ts make-pdf/test/pdftotext.test.ts on win32 — 29 pass, 0 fail (12 new assertions: findExecutable POSIX/win32/null, resolveBrowseBin GSTACK_BROWSE_BIN + BROWSE_BIN + precedence + quote-strip, same shape for resolvePdftotext + Windows install hint in error message). - POSIX branch unchanged — fs.accessSync(X_OK) on Linux/macOS short-circuits before any win32 logic runs, matching the v1.24 claude-bin.ts pattern.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows,
make-pdf generatefails withbrowse binary not foundeven after a successful./setup. The resolution logic inmake-pdf/src/browseClient.tsprobes bare paths, butbun build --compile --outfile browse/dist/browseemitsbrowse/dist/browse.exeon Windows, so every probe misses. Same root cause inmake-pdf/src/pdftotext.ts:resolvePdftotext.This is a v1.24-aligned reshape of #1118 (closed in favor of this PR). v1.24.0.0 (#1252) introduced
Bun.which()+GSTACK_*_BINoverride pattern inbrowse/src/claude-bin.tsfor theclaudebinary. This PR extends the same pattern to the two other binary resolvers in the codebase:resolveBrowseBinandresolvePdftotext.Root cause
Two independent issues compound:
1.
fs.constants.X_OKis degraded to existence-checking on Windows. Per the Node.js docs onfs.accessSync:fs.accessSync('/path/to/browse', X_OK)on Windows checks whether a file literally namedbrowse(no extension) exists. When bun emitsbrowse.exe, the check returns false.Bun.which()handles this correctly via PATHEXT.2. bun
--compile --outfileappends.exeon Windows unconditionally. The build command targetsbrowse/dist/browseetc.; on Windows, bun silently appends.exe. Confirmed:3. The
which browsePATH fallback doesn't help native Windows.whichships with Git Bash but not cmd.exe / PowerShell.Bun.which('browse')works from all three.Coordination with #1094
@BkashJEE's PR #1094 (still open) covered
browseClient.tsindependently with a narrower scope (nopdftotext, no tests, no GSTACK_*_BIN naming). This PR's pdftotext fix + cross-platform tests + v1.24-aligned env override naming are additive. Either order of merge works; happy to rebase as a follow-on if #1094 lands first.What changed from #1118
BROWSE_BIN/PDFTOTEXT_BINremain as back-compat aliases (matching v1.24'sGSTACK_CLAUDE_BIN ?? CLAUDE_BINpattern).Bun.which()replacesexecFileSync('which', ...)for PATH lookup. No morewhere-vs-whichbranch.findExecutable(base)helper exported from each module — probes.exe/.cmd/.batafter the bare-path miss on win32. POSIX behavior bit-identical (isExecutable short-circuits before the win32 branch).macCandidates→posixCandidatesin pdftotext.ts (always was POSIX-only). No Windows candidates added — Poppler scatters across Scoop / Chocolatey / oschwartz10612-poppler-windows; guessing causes false positives. SetGSTACK_PDFTOTEXT_BINexplicitly. Error message gets a Windows install hint (scoop install poppler) andsetxexample.'honors BROWSE_BIN when it points at a real executable'was hardcoded/bin/sh— made cross-platform via aREAL_EXEconstant (cmd.exeon win32,/bin/shon POSIX). This was a Windows-CI blocker on its own.Test plan
bun test make-pdf/test/browseClient.test.ts make-pdf/test/pdftotext.test.tson win32 — 29 pass, 0 fail (12 new assertions:findExecutablePOSIX/win32-extension-probe/null;resolveBrowseBinGSTACK_BROWSE_BIN + BROWSE_BIN + precedence + quote-strip; same shape forresolvePdftotext+ Windows install hint in error message)Bun.which('browse')on Linux/macOS resolves via PATH the same wayexecFileSync('which', 'browse')did, minus the Git Bash dependency.What this PR doesn't do
findTelemetryBinaryinbrowse/src/security.ts. Different bug (shebang-script invocation on Windows), different fix — see companion PR fix(browse): bash.exe wrap for telemetry on Windows (v1.24 extension) #1306 (closed fix(browse): wrap telemetry bash script with bash.exe on Windows #1119, reopened against v1.24).windows-free-tests.yml. ✅🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.