Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
// Every test file gets a throwaway home, so DATA_DIR (~/.openmausbot) never touches the real one;
// os.homedir() reads HOME / USERPROFILE at call time, and this runs before server/config.ts is imported.
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterAll, afterEach } from "vitest";
import { removeTempDir } from "./cleanup.ts";
import { noHostContainerEnv } from "./container-env.ts";
const home = mkdtempSync(join(tmpdir(), "omb-test-home-"));
process.env.HOME = home;
process.env.USERPROFILE = home;
// A test server with the host's PATH can adopt and recreate the installed app's Local VM.
Object.assign(process.env, noHostContainerEnv(home));
// A provider that answers 5xx retries with backoff: no test should wait out real seconds.
process.env.FAKE_OPENAI_COMPAT_RETRY_SCALE ??= "0.001";
// OMB_DATA_DIR must never escape the throwaway home the suite deletes.
delete process.env.OMB_DATA_DIR;
// The model manifest comes from the bundled copy in tests; refreshing it would be a network call in every server boot.
process.env.OMB_DISABLE_MODEL_MANIFEST_FETCH = "1";
// Do not let a developer's Hermes global config path leak into per-test homes.
delete process.env.HERMES_HOME;
// A ChatGPT-plan turn links the person's Codex home ($CODEX_HOME or ~/.codex) into its own: keep it in the throwaway home.
delete process.env.CODEX_HOME;
// Pi turns copy from the person's Pi agent folder ($PI_CODING_AGENT_DIR or ~/.pi/agent): keep it in the throwaway home.
delete process.env.PI_CODING_AGENT_DIR;
// The canonical event log's bounds are server settings; a developer's shell must not shrink a test bus's queue.
for (const name of ["OMB_EVENT_LOG_BATCH_LINES", "OMB_EVENT_LOG_QUEUE_BYTES", "OMB_EVENT_LOG_QUEUE_EVENTS", "OMB_EVENT_LOG_DRAIN_THREADS"]) delete process.env[name];
// No server in a test downloads the project's announcement cards; its tests hand the store a fake fetch.
process.env.OMB_DISABLE_ANNOUNCEMENTS = "1";
// Named explicitly although homedir() already covers it: the device tests delete this directory wholesale.
process.env.OMB_COMPANION_DIR = join(home, ".openmausbot-companion");
// Product code follows navigator.language; pin it so English assertions do not depend on the host locale.
Object.defineProperty(globalThis.navigator, "language", { value: "en", configurable: true });
// Page tests drive the live feed through a fake EventSource; without this a direct page would open a real socket first.
if ("window" in globalThis) Reflect.deleteProperty(globalThis, "WebSocket");
// Windows will not remove a directory holding an open SQLite database: close it before the reset.
const { closeMessageDb } = await import("../message-db.ts");
afterEach(closeMessageDb);
// Windows holds a live process's cwd, and a just-killed CLI lets go a beat after the kill returns.
afterAll(async () => {
closeMessageDb();
await removeTempDir(home);
});