import { ensureChromiumExecutable } from "@oh-my-pi/pi-coding-agent/tools/browser/launch"; /** * Whether the Chromium puppeteer resolves can actually execute on this host. * CI runners without Chrome's system libraries (libnspr4 & co.) hold the * downloaded binary but cannot exec it — probe with --version and skip * instead of failing. */ async function chromiumCanLaunch(): Promise { try { const executable = await ensureChromiumExecutable(); if (!executable) return false; const probe = Bun.spawnSync([executable, "--version"], { stdout: "ignore", stderr: "ignore" }); return probe.exitCode === 0; } catch { return false; } } let probe: Promise | undefined; /** * Gate for tests that launch a real Chromium: * * const CHROMIUM_AVAILABLE = await chromiumAvailable(); * describe.skipIf(!CHROMIUM_AVAILABLE)(…); * * The result is a promise rather than an awaited `export const`. A module whose * exports are initialized by top-level await hands the test runner a binding * that is still in its temporal dead zone when a second test file in the same * process imports it, and that file dies during registration with "Cannot * access 'CHROMIUM_AVAILABLE' before initialization". Awaiting in the importer * makes the wait part of that file's own evaluation, which the runner does * sequence. The probe runs once per process. */ export function chromiumAvailable(): Promise { probe ??= chromiumCanLaunch(); return probe; }