diff --git a/src/create-runtime-tmux-config.test.ts b/src/create-runtime-tmux-config.test.ts index efc03fa4a..cb3604892 100644 --- a/src/create-runtime-tmux-config.test.ts +++ b/src/create-runtime-tmux-config.test.ts @@ -1,6 +1,10 @@ /// import { describe, expect, test } from "bun:test" +import { spawnSync } from "node:child_process" +import { mkdtempSync, rmSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" import { TmuxConfigSchema } from "./config/schema/tmux" import { createRuntimeTmuxConfig } from "./create-runtime-tmux-config" @@ -14,4 +18,40 @@ describe("createRuntimeTmuxConfig", () => { expect(runtimeTmuxConfig.isolation).toBe(schemaDefault) }) }) + + describe("#given the runtime does not expose Bun", () => { + test("#when interactive bash availability is checked from a bundled module #then it returns false without crashing", async () => { + const outdir = mkdtempSync(join(tmpdir(), "omo-desktop-runtime-")) + + try { + const build = await Bun.build({ + entrypoints: [join(import.meta.dir, "create-runtime-tmux-config.ts")], + outdir, + target: "bun", + format: "esm", + }) + expect(build.success).toBe(true) + + const result = spawnSync(Bun.which("node") ?? "node", [ + "--input-type=module", + "-e", + `import { pathToFileURL } from "node:url"; +const mod = await import(pathToFileURL(process.env.MODULE_PATH).href); +console.log(String(mod.isInteractiveBashEnabled()));`, + ], { + env: { + ...process.env, + MODULE_PATH: join(outdir, "create-runtime-tmux-config.js"), + }, + encoding: "utf8", + }) + + expect(result.stderr).toBe("") + expect(result.status).toBe(0) + expect(result.stdout.trim()).toBe("false") + } finally { + rmSync(outdir, { recursive: true, force: true }) + } + }) + }) }) diff --git a/src/create-runtime-tmux-config.ts b/src/create-runtime-tmux-config.ts index 937fc4b14..8e41ef6cf 100644 --- a/src/create-runtime-tmux-config.ts +++ b/src/create-runtime-tmux-config.ts @@ -1,6 +1,16 @@ import type { OhMyOpenCodeConfig, TmuxConfig } from "./config" import { TmuxConfigSchema } from "./config/schema/tmux" +type RuntimeWithBun = typeof globalThis & { + Bun?: { + which(binary: string): string | null + } +} + +function defaultWhich(binary: string): string | null { + return (globalThis as RuntimeWithBun).Bun?.which(binary) ?? null +} + export function isTmuxIntegrationEnabled( pluginConfig: { tmux?: { enabled?: boolean } | undefined }, ): boolean { @@ -8,7 +18,7 @@ export function isTmuxIntegrationEnabled( } export function isInteractiveBashEnabled( - which: (binary: string) => string | null = Bun.which, + which: (binary: string) => string | null = defaultWhich, ): boolean { return which("tmux") !== null }