|
1 | 1 | 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"; |
3 | 3 | import { tmpdir } from "node:os"; |
4 | 4 | import { join } from "node:path"; |
5 | 5 | import { isRealBunBinary, bundledBunPath, durableBunPath, durableBunRuntime, overrideBunPath } from "../src/lib/bun-runtime"; |
@@ -60,6 +60,31 @@ describe("bundledBunPath / durableBunPath", () => { |
60 | 60 | else process.env.OPENCODEX_BUN_PATH = previousOverride; |
61 | 61 | }); |
62 | 62 |
|
| 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 | + |
63 | 88 | it("resolves the installed bundled bun binary (dev has the bun dep)", () => { |
64 | 89 | const p = bundledBunPath(); |
65 | 90 | // In this repo the `bun` dependency is installed, so the real binary resolves. |
|
0 commit comments