openclaw/scripts/lib/test-runtime.mts
Peter Steinberger 1c6ed448c1
feat(dev): default local tests and CLI to pinned Bun (#172625)
* feat(dev): default local tests and CLI to pinned Bun

* fix(test): preserve Bun launch and report contracts in CI

* fix(test): preserve workflow-provisioned Bun in CI

* fix(test): report pinned Bun staging failure causes
2026-10-15 05:58:40 -07:00

27 lines
791 B
TypeScript

import { isCiEnvironment, resolvePinnedBun } from "./pinned-bun.mts";
let fallbackReported = false;
export function resolveTestRuntime(env: NodeJS.ProcessEnv = process.env): "node" | "bun" {
const runtime = env.OPENCLAW_VITEST_RUNTIME?.trim();
if (runtime) {
if (runtime !== "node" && runtime !== "bun") {
throw new Error(`Invalid OPENCLAW_VITEST_RUNTIME: ${runtime}; expected node or bun`);
}
return runtime;
}
if (isCiEnvironment(env)) {
return "node";
}
const bun = resolvePinnedBun(env);
if (bun.command) {
return "bun";
}
if (!fallbackReported) {
fallbackReported = true;
console.error(
`[openclaw] Bun fork unavailable (${bun.reason}); using Node. Set OPENCLAW_VITEST_RUNTIME=node to silence.`,
);
}
return "node";
}