Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Team tests: the team's Chief has a fixed name, so a test's bot can't share its random one
milind-soni0843a3f2e304
diff --git a/scripts/testing/cloud-send-fixture.ts b/scripts/testing/cloud-send-fixture.tsindex 7554d2aa5f..248d273bba 100644--- a/scripts/testing/cloud-send-fixture.ts+++ b/scripts/testing/cloud-send-fixture.ts@@ -124,7 +124,8 @@ export interface CloudTeamFixture {/** The Admin's signed pairing for one member, as the Admin hands it to the app: a one-time code, not redeemed. */grant(member: TeamMember): Promise<{ origin: string; code: string; expiresAt: number }>;/** The Admin's signed pairing for one member, redeemed into a bearer. `body` replaces the member and team claims- * (a forged or missing claim); `secret` signs with another key (a forgery). */+ * (a forged or missing claim); `secret` signs with another key (a forgery). The first owner or admin to pair also gives+ * the team's Chief a fixed name, "Seedling". */pair(member: TeamMember | null, options?: { body?: Record<string, unknown>; secret?: string; label?: string }): Promise<{ status: number; body: any; token: string | null }>;/** A request as one person, by their bearer. */as(token: string, method: string, path: string, body?: unknown, headers?: Record<string, string>): Promise<{ status: number; body: any }>;@@ -288,6 +289,15 @@ await import(${JSON.stringify(pathToFileURL(join(SERVER_DIR, "testing", "fake-clconst response = await remember(await fetch(`${teamBase}${path}`, init));return { status: response.status, body: parse(await response.text()) };};+ // A new Team Cloud's Chief gets a name at random, so one run in 64 it would share a name with a bot the test makes.+ let chiefNamed = false;+ const nameChief = async (token: string) => {+ const listed = await as(token, "GET", "/api/bots?messages=0");+ const chief = (listed.body.bots as Array<{ id: string; chiefOfStaff?: boolean }>).find((bot) => bot.chiefOfStaff);+ if (!chief) return;+ const renamed = await as(token, "PATCH", `/api/bots/${chief.id}`, { name: "Seedling" });+ if (renamed.status !== 200) throw new Error(`could not name the team's Chief: ${renamed.status} ${JSON.stringify(renamed.body)}`);+ };teamFixture = {base: teamBase, home: join(root, "team"), id: team.id, name: team.name,async grant(member) {@@ -308,7 +318,12 @@ await import(${JSON.stringify(pathToFileURL(join(SERVER_DIR, "testing", "fake-clif (minted.status !== 200) return { status: minted.status, body: grant, token: null };const paired = await remember(await fetch(`${teamBase}/api/auth/pair`, { method: "POST", headers: { ...EDGE, "content-type": "application/json" }, body: JSON.stringify({ code: grant.code }) }));const session = parse(await paired.text());- return { status: paired.status, body: session, token: paired.status === 200 ? session.token as string : null };+ if (paired.status !== 200) return { status: paired.status, body: session, token: null };+ if (!chiefNamed && member && member.role !== "member") {+ chiefNamed = true;+ await nameChief(session.token as string);+ }+ return { status: paired.status, body: session, token: session.token as string };},as,signed: (method, path, body) => signedRequest(teamBase, method, path, body === undefined ? "" : JSON.stringify(body)),diff --git a/server/cloud-team-one-answer.e2e.test.ts b/server/cloud-team-one-answer.e2e.test.tsindex 277aa52a6e..bb9e2b07d6 100644--- a/server/cloud-team-one-answer.e2e.test.ts+++ b/server/cloud-team-one-answer.e2e.test.ts@@ -7,7 +7,6 @@import { randomBytes } from "node:crypto";import { existsSync, readFileSync, writeFileSync } from "node:fs";import { join } from "node:path";-import { DatabaseSync } from "node:sqlite";import { afterAll, beforeAll, expect, it } from "vitest";import { launchCloudSendFixture, type CloudSendFixture, type CloudTeamFixture } from "../scripts/testing/cloud-send-fixture.ts";import { hostTimeout } from "./testing/host-timeout.ts";@@ -22,7 +21,7 @@ const JOINED = "Another teammate asked this a moment ago, so it was answered oncconst DONE = "Bolt estimates about 15 working days.";type Bot = { id: string; name: string; threadId: string; tasks?: Array<{ threadId: string; title: string; busy?: boolean }> };-type Turn = { botId: string; turnIndex: number; threadId: string; system: string; prompt: unknown };+type Turn = { botId: string; turnIndex: number; system: string; prompt: unknown };let fx: CloudSendFixture, team: CloudTeamFixture;let olive = "", bob = "";@@ -50,18 +49,6 @@ const boltTasks = async (token: string) =>/** The notes in Bolt's threads this person reads that a request waited for another's answer. */const joinedNotes = async (token: string) => (await Promise.all((await boltTasks(token)).map((task) => messages(token, task.threadId).catch(() => [])))).flat().filter((message) => message.tool?.name.startsWith("notice: Another teammate asked the same a moment ago")).length;-/** The join is decided from these rows, so a request that never joined is explained by them and by the turns that ran. */-const explainNoJoin = () => {- const db = new DatabaseSync(join(team.home, ".openmausbot", "runtime.db"), { readOnly: true });- try {- console.error("one-answer: bots", JSON.stringify({ scout: scout.id, quill: quill.id, bolt: bolt.id, pip: pip.id }));- for (const row of db.prepare("select * from assignments").all()) console.error("one-answer: assignment", JSON.stringify(row).slice(0, 1_500));- } finally {- db.close();- }- console.error("one-answer: turns", turns().map((turn) => `${turn.botId}#${turn.turnIndex} in ${turn.threadId}`).join(", "));- console.error("one-answer: server", fx.logs().split("\n").filter((line) => line.startsWith("coordinator:")).slice(-40).join("\n"));-};const privateChat = async (token: string, bot: Bot, title: string) => {const opened = await team.as(token, "POST", `/api/bots/${bot.id}/tasks`, { title });expect(opened.status, JSON.stringify(opened.body)).toBe(201);@@ -106,10 +93,7 @@ it("answers the same question from two of Bob's teammates once, and Olive's, whiconst sent = await team.as(bob, "POST", `/api/bots/${scout.id}/messages`, { text: "How long will the migration take? Ask Bolt, and have Quill look too.", threadId: bobChat });expect(sent.status, JSON.stringify(sent.body)).toBe(202);// Quill asked while Bolt still works on Scout's question: its request waits for that answer.- await expect.poll(() => joinedNotes(bob), { timeout: 90_000 }).toBe(1).catch((error: unknown) => {- explainNoJoin();- throw error;- });+ await expect.poll(() => joinedNotes(bob), { timeout: 90_000 }).toBe(1);const oliveChat = await privateChat(olive, pip, "Estimate");const asked = await team.as(olive, "POST", `/api/bots/${pip.id}/messages`, { text: "Ask Bolt how long the migration takes.", threadId: oliveChat });