Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

3.4 KB
Raw Blame
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { expect, it } from "vitest";
import { launchVerificationServer, runControlOmb } from "../scripts/control-omb.ts";

it("names a successful fixture conversation from the request and first visible reply", async () => {
  const dir = mkdtempSync(join(tmpdir(), "omb-title-e2e-"));
  const title = join(dir, "title.txt"), dump = join(dir, "title-dump.json"), script = join(dir, "stream.json");
  writeFileSync(title, "Payroll | export fix");
  writeFileSync(script, JSON.stringify({ "Fix payroll export": [
    { think: "Private reasoning about the ledger." },
    { say: "I found a mismatch in the payroll schema." },
    { say: "The export is ready." },
  ] }));
  const fixture = await launchVerificationServer({ ...process.env, FAKE_CLAUDE_TEXT_FILE: title, FAKE_CLAUDE_TEXT_DUMP: dump, FAKE_STREAM_SCRIPT: script, FAKE_STREAM_CADENCE: "100:1" });
  const control = (...args: string[]) => runControlOmb([...args, "--url", fixture.info.url]) as Promise<any>;
  try {
    const { bot } = await control("new-bot", "--name", "Title fixture");
    await control("send", "--bot", bot.id, "--text", "Fix payroll export");
    expect((await control("wait", "--bot", bot.id, "--timeout", "30")).status).toBe("settled");
    await expect.poll(async () => {
      const result = await control("bots");
      return result.bots.find((candidate: any) => candidate.id === bot.id)?.tasks.find((task: any) => task.taskId === bot.activeTaskId)?.title;
    }, { timeout: 15_000 }).toBe("Payroll | export fix");
    const { prompt } = JSON.parse(readFileSync(dump, "utf8"));
    expect(prompt).toContain("User: Fix payroll export");
    expect(prompt).toContain("Bot: I found a mismatch in the payroll schema.");
    expect(prompt).not.toContain("The export is ready.");
    expect(prompt).not.toContain("Private reasoning about the ledger.");
  } finally {
    await fixture.close();
    rmSync(dir, { recursive: true, force: true });
  }
}, 120_000);

it("titles a failed turn from the request without its interim progress", async () => {
  const dir = mkdtempSync(join(tmpdir(), "omb-title-failed-e2e-"));
  const title = join(dir, "title.txt"), dump = join(dir, "title-dump.json"), script = join(dir, "stream.json");
  writeFileSync(title, "Payroll export");
  writeFileSync(script, JSON.stringify({ "Fix payroll export": [{ say: "Inspecting the ledger." }, { fail: "Fixture terminal failure" }] }));
  const fixture = await launchVerificationServer({ ...process.env, FAKE_CLAUDE_TEXT_FILE: title, FAKE_CLAUDE_TEXT_DUMP: dump, FAKE_STREAM_SCRIPT: script, FAKE_STREAM_CADENCE: "100:1" });
  const control = (...args: string[]) => runControlOmb([...args, "--url", fixture.info.url]) as Promise<any>;
  try {
    const { bot } = await control("new-bot", "--name", "Title fixture");
    await control("send", "--bot", bot.id, "--text", "Fix payroll export");
    expect(await control("wait", "--bot", bot.id, "--timeout", "30")).toMatchObject({ status: "settled", state: "failed" });
    await expect.poll(() => { try { return JSON.parse(readFileSync(dump, "utf8")).prompt; } catch { return ""; } }, { timeout: 15_000 }).toContain("Fix payroll export");
    const { prompt } = JSON.parse(readFileSync(dump, "utf8"));
    expect(prompt).not.toContain("Inspecting the ledger.");
  } finally {
    await fixture.close();
    rmSync(dir, { recursive: true, force: true });
  }
}, 120_000);