Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Fix two flaky tests: Team Cloud DuckDB link and the frame-batching burst
milind-sonibd58d978ae43
diff --git a/scripts/testing/cloud-send-fixture.ts b/scripts/testing/cloud-send-fixture.tsindex 235bb984ab..48e272980b 100644--- a/scripts/testing/cloud-send-fixture.ts+++ b/scripts/testing/cloud-send-fixture.ts@@ -6,7 +6,7 @@// and a fake 1Password SDK; no network.import { randomBytes } from "node:crypto";import { spawn, type ChildProcess } from "node:child_process";-import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, writeFileSync } from "node:fs";+import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, symlinkSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { fileURLToPath, pathToFileURL } from "node:url";@@ -165,7 +165,10 @@ exports.createClient = async ({ auth }) => {export async function launchCloudSendFixture({ onePasswordToken, cloudOnePasswordToken = onePasswordToken, toolCalls = 0, broker, env = {}, cloudEnv = {}, cloudEngine = "", desktopEngine = "", space, cloudSignedIn = true, team }: {onePasswordToken: string; cloudOnePasswordToken?: string; toolCalls?: number;/** A Team Cloud too (OMB_CLOUD_ROLE=team), with its own environment and synthetic Claude CLI lines. */- team?: { id: string; name: string; env?: NodeJS.ProcessEnv; engine?: string; noAi?: boolean };+ team?: { id: string; name: string; env?: NodeJS.ProcessEnv; engine?: string; noAi?: boolean;+ /** Scopes of this checkout's node_modules (`@duckdb`) linked into the Team Cloud's native tree before it starts: the+ * server can load DuckDB at its first config broadcast, and a failed load stays failed for the server's life. */+ native?: string[] };broker?: { url: string; install(): Promise<{ id: string; token: string; userId: string }> };env?: NodeJS.ProcessEnv;/** My Cloud's own environment only (a store limit, say). */@@ -286,6 +289,10 @@ await import(${JSON.stringify(pathToFileURL(join(SERVER_DIR, "testing", "fake-clmkdirSync(join(root, "team", ".openmausbot"), { recursive: true });writeFileSync(join(root, "team", ".openmausbot", "config.json"), JSON.stringify({ instances: Object.fromEntries(["claude", "codex", "cursor", "githubCopilot", "openaiCompat", "qwen", "hermes", "pi", "grok"].map((id) => [id, { driver: "not-a-real-driver" }])) }));}+ for (const scope of team.native ?? []) {+ mkdirSync(join(root, "team", "native", "node_modules"), { recursive: true });+ symlinkSync(join(SERVER_DIR, "..", "node_modules", scope), join(root, "team", "native", "node_modules", scope), "junction");+ }const startTeam = (more: NodeJS.ProcessEnv = {}) => start("team", { OMB_CLOUD_ROLE: "team", OMB_CLOUD_TEAM_ID: team.id, OMB_CLOUD_TEAM_NAME: team.name,OMB_CLOUD_MACHINE_ID: "0d9e8f7a-6b5c-4d3e-9f8a-7b6c5d4e3f2a", OMB_CLOUD_ADMIN_URL: "https://cloud.example.test", OMB_CLOUD_BOOTSTRAP_SECRET: secret,OMB_PUBLIC_URL: `https://${CLOUD_HOST}`, OMB_TEST_INTERNAL_CAPABILITY_KEY: CAPABILITY_KEY, ...(broker ? { OMB_COMPOSIO_BROKER_URL: broker.url } : {}), ...team.env, ...more },diff --git a/server/team-phone-data.e2e.test.ts b/server/team-phone-data.e2e.test.tsindex c2f0e83bd3..3597bf174a 100644--- a/server/team-phone-data.e2e.test.ts+++ b/server/team-phone-data.e2e.test.ts@@ -2,9 +2,6 @@// a chart card's picture. Tried as a Team Cloud member, whose session is the same client scope a `pair --phone` phone gets:// a bot they can't see answers exactly as a missing one, and nothing that runs, changes or exports data opens to them.import { randomBytes } from "node:crypto";-import { symlinkSync } from "node:fs";-import { join } from "node:path";-import { fileURLToPath } from "node:url";import { expect, it } from "vitest";import { launchCloudSendFixture } from "../scripts/testing/cloud-send-fixture.ts";@@ -14,11 +11,11 @@ import { hostTimeout } from "./testing/host-timeout.ts";const NO_SUCH_BOT = { status: 404, body: { error: "no such bot" } };it("lets a member's phone read a visible bot's Data, and nothing of a bot they can't see", async () => {- const fx = await launchCloudSendFixture({ onePasswordToken: `ops_fake-${randomBytes(8).toString("hex")}`, team: { id: "team-phone-data", name: "Acme" } });+ // DuckDB and the chart renderer join the fixture's native tree (a fake 1Password SDK) before the Team Cloud starts: its+ // first config broadcast loads DuckDB, and a link made after that came too late.+ const fx = await launchCloudSendFixture({ onePasswordToken: `ops_fake-${randomBytes(8).toString("hex")}`, team: { id: "team-phone-data", name: "Acme", native: ["@duckdb", "@resvg"] } });try {const team = fx.team!;- // The fixture's native tree holds a fake 1Password SDK only; DuckDB loads on first use, so it can join it now.- for (const scope of ["@duckdb", "@resvg"]) symlinkSync(fileURLToPath(new URL(`../node_modules/${scope}`, import.meta.url)), join(team.home, "native", "node_modules", scope), "junction");const owner = (await team.pair({ email: "[email protected]", role: "owner" })).token!;const member = (await team.pair({ email: "[email protected]", role: "member" })).token!;expect((await team.as(member, "GET", "/api/auth/session")).body.scopes).toEqual(["client"]);diff --git a/src/state/frame-batching.test.ts b/src/state/frame-batching.test.tsindex 80da8553aa..ae94d2ddd1 100644--- a/src/state/frame-batching.test.ts+++ b/src/state/frame-batching.test.ts@@ -46,10 +46,13 @@ function Probe() {let root: Root;const task = () => new Promise((resolve) => setTimeout(resolve, 0));const settle = async () => { for (let i = 0; i < 5; i++) await task(); };-const paint = async () => {+const drawFrames = () => {painting = true;for (const callback of paints.splice(0)) callback(performance.now());painting = false;+};+const paint = async () => {+ drawFrames();await settle();};const stream = () => FixtureEventSource.opened[0]!;@@ -82,16 +85,28 @@ beforeEach(async () => {describe("live frames reach the screen once per paint", () => {it("draws a burst of frames that arrived in separate tasks in one render, in arrival order", async () => {- const before = renders;- const start = ids().length;- for (let i = 0; i < 10; i++) {- stream().send(frame(`burst-${i}`), `run:${++cursor}`);- await task();+ // The batch also flushes after a 100 ms timer, for a hidden window without frames. Ten real timer tasks can take that+ // long (Windows' clock ticks every 15.6 ms), so the timers' clock moves only here: the frames come 1 ms apart, each in+ // its own task (setImmediate stays real).+ vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });+ try {+ const nextTask = () => new Promise((resolve) => setImmediate(resolve));+ const before = renders;+ const start = ids().length;+ for (let i = 0; i < 10; i++) {+ stream().send(frame(`burst-${i}`), `run:${++cursor}`);+ await nextTask();+ vi.advanceTimersByTime(1);+ }+ expect(renders, "nothing renders before the paint").toBe(before);+ drawFrames();+ for (let i = 0; i < 5; i++) await nextTask();+ expect(renders).toBe(before + 1);+ expect(ids().slice(start)).toEqual(Array.from({ length: 10 }, (_, i) => `burst-${i}`));+ expect(vi.getTimerCount(), "the paint cancels the fallback timer").toBe(0);+ } finally {+ vi.useRealTimers();}- expect(renders, "nothing renders before the paint").toBe(before);- await paint();- expect(renders).toBe(before + 1);- expect(ids().slice(start)).toEqual(Array.from({ length: 10 }, (_, i) => `burst-${i}`));});it("applies frames that arrived before an action ahead of it", async () => {