From 9e6b850f507ddd335aecc086740598e7630c7de3 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Tue, 28 Apr 2026 00:09:42 -0700 Subject: [PATCH] fix(find-browse): guard main() with import.meta.main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round 7 of windows-free-tests fixes (and a genuine bug fix beyond Windows). browse/src/find-browse.ts called main() unconditionally at module load. main() calls process.exit(1) when no compiled `browse` binary exists at the known install paths. Any test that imports `locateBinary` from this module then exits the entire test process before any tests run. This affected the windows-free-tests CI lane because the runner intentionally doesn't compile the browse binary (only server-node.mjs is built — full binary compilation is slow and not needed for the curated subset). It would also affect any Mac/Linux contributor who runs tests in a fresh checkout before running ./setup, though the symptom is rarer there. Fix: wrap `main()` in `if (import.meta.main) { main() }`. The CLI invocation (via the find-browse binary or `bun run browse/src/find-browse.ts`) still runs main() and emits the path. Imports get only the named exports. Verified locally: - `bun run browse/src/find-browse.ts` still prints the binary path. - `import { locateBinary } from '...'` no longer exits the process. - `bun test browse/test/find-browse.test.ts` passes 4/4 (was crashing at module load). Co-Authored-By: Claude Opus 4.7 (1M context) --- browse/src/find-browse.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/browse/src/find-browse.ts b/browse/src/find-browse.ts index 93c4a26e..44138257 100644 --- a/browse/src/find-browse.ts +++ b/browse/src/find-browse.ts @@ -58,4 +58,12 @@ function main() { console.log(bin); } -main(); +// Only run main() when this module is the entry point. Without this guard, +// any test that imports `locateBinary` from this file would have main() fire +// at module-load time, calling process.exit(1) when no compiled binary +// exists — killing the test process before any test runs. Surfaced on the +// windows-free-tests CI lane where the runner has no compiled browse +// binary (intentional — that lane only builds server-node.mjs). +if (import.meta.main) { + main(); +}