Skip to content

Commit 643220f

Browse files
committed
fix(runtime): normalize Bun override path
1 parent 72db422 commit 643220f

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/lib/bun-runtime.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* back to `process.execPath` (which is itself Bun when run via `bun src/cli/index.ts`).
1212
*/
1313
import { createRequire } from "node:module";
14-
import { dirname, join } from "node:path";
14+
import { dirname, join, resolve } from "node:path";
1515
import { isRealBunBinary } from "./bun-binary-validator.mjs";
1616

1717
export { isRealBunBinary };
@@ -48,7 +48,8 @@ export function bundledBunPath(): string | null {
4848
export function overrideBunPath(): string | null {
4949
const value = process.env[BUN_OVERRIDE_ENV]?.trim();
5050
if (!value) return null;
51-
return isRealBunBinary(value) ? value : null;
51+
const resolved = resolve(value);
52+
return isRealBunBinary(resolved) ? resolved : null;
5253
}
5354

5455
export function durableBunRuntime(): DurableBunRuntime {

tests/bun-runtime.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, afterAll } from "bun:test";
2-
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
2+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
55
import { isRealBunBinary, bundledBunPath, durableBunPath, durableBunRuntime, overrideBunPath } from "../src/lib/bun-runtime";
@@ -60,6 +60,31 @@ describe("bundledBunPath / durableBunPath", () => {
6060
else process.env.OPENCODEX_BUN_PATH = previousOverride;
6161
});
6262

63+
it("resolves a relative override against the launcher cwd", () => {
64+
const launcherCwd = join(tmp, "launcher-cwd");
65+
const real = join(launcherCwd, "relative-bun.exe");
66+
const previousCwd = process.cwd();
67+
const inheritedOverride = process.env.OPENCODEX_BUN_PATH;
68+
mkdirSync(launcherCwd, { recursive: true });
69+
writeFileSync(real, Buffer.alloc(1_000_000));
70+
71+
try {
72+
process.chdir(launcherCwd);
73+
process.env.OPENCODEX_BUN_PATH = " relative-bun.exe ";
74+
expect(overrideBunPath()).toBe(real);
75+
expect(durableBunRuntime()).toEqual({
76+
path: real,
77+
source: "override",
78+
overrideEnv: "OPENCODEX_BUN_PATH",
79+
});
80+
expect(durableBunPath()).toBe(real);
81+
} finally {
82+
process.chdir(previousCwd);
83+
if (inheritedOverride === undefined) delete process.env.OPENCODEX_BUN_PATH;
84+
else process.env.OPENCODEX_BUN_PATH = inheritedOverride;
85+
}
86+
});
87+
6388
it("resolves the installed bundled bun binary (dev has the bun dep)", () => {
6489
const p = bundledBunPath();
6590
// In this repo the `bun` dependency is installed, so the real binary resolves.

0 commit comments

Comments
 (0)