Skip to content

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

Main CI: wait for a moving goal run, and name the Team Cloud request that got no answer

milind-sonidad770731355
diff --git a/scripts/testing/cloud-send-fixture.ts b/scripts/testing/cloud-send-fixture.ts
index ee86c1045d..235bb984ab 100644
--- a/scripts/testing/cloud-send-fixture.ts
+++ b/scripts/testing/cloud-send-fixture.ts
@@ -291,11 +291,16 @@ await import(${JSON.stringify(pathToFileURL(join(SERVER_DIR, "testing", "fake-cl
OMB_PUBLIC_URL: `https://${CLOUD_HOST}`, OMB_TEST_INTERNAL_CAPABILITY_KEY: CAPABILITY_KEY, ...(broker ? { OMB_COMPOSIO_BROKER_URL: broker.url } : {}), ...team.env, ...more },
teamPort, stopOverIpc ? ["--import", stopOnMessage] : [], stopOverIpc, onePasswordToken, 0, team.engine ?? "", true);
let teamServer = await startTeam();
+ const teamFetch = (path: string, init: RequestInit) => fetch(`${teamBase}${path}`, init).catch(async (error: unknown) => {
+ await new Promise((resolve) => setTimeout(resolve, 500));
+ const state = teamServer.exitCode === null && teamServer.signalCode === null ? "is still running" : `exited (${teamServer.exitCode ?? teamServer.signalCode})`;
+ throw new Error(`${init.method ?? "GET"} ${path} on the Team Cloud got no answer, and the Team Cloud ${state}. The servers' output:\n${logs.slice(-8_000)}`, { cause: error });
+ });
const as: CloudTeamFixture["as"] = async (token, method, path, body, headers = {}) => {
const init: RequestInit = { method, headers: { ...EDGE, authorization: `Bearer ${token}`, ...headers,
...(body === undefined || body instanceof Uint8Array ? {} : { "content-type": "application/json" }) } };
if (body !== undefined) init.body = body instanceof Uint8Array ? body : JSON.stringify(body);
- const response = await remember(await fetch(`${teamBase}${path}`, init));
+ const response = await remember(await teamFetch(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.
@@ -321,11 +326,11 @@ await import(${JSON.stringify(pathToFileURL(join(SERVER_DIR, "testing", "fake-cl
const claims = options.body ?? { team: { id: team.id, name: team.name }, ...(member ? { member } : {}) };
const body = JSON.stringify({ label: options.label ?? "OpenMausBot app (Team Cloud)", ttlSeconds: 300, ...claims });
const timestamp = String(Math.floor(Date.now() / 1000)), nonce = randomBytes(16).toString("base64url");
- const minted = await remember(await fetch(`${teamBase}/api/cloud/pairing`, { method: "POST", headers: { ...EDGE, "content-type": "application/json",
+ const minted = await remember(await teamFetch("/api/cloud/pairing", { method: "POST", headers: { ...EDGE, "content-type": "application/json",
"x-omb-cloud-timestamp": timestamp, "x-omb-cloud-nonce": nonce, "x-omb-cloud-signature": `v1=${cloudPairingSignature(options.secret ?? secret, timestamp, nonce, body)}` }, body }));
const grant = parse(await minted.text());
if (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 paired = await remember(await teamFetch("/api/auth/pair", { method: "POST", headers: { ...EDGE, "content-type": "application/json" }, body: JSON.stringify({ code: grant.code }) }));
const session = parse(await paired.text());
if (paired.status !== 200) return { status: paired.status, body: session, token: null };
if (!chiefNamed && member && member.role !== "member") {
diff --git a/server/group-goal-run.e2e.test.ts b/server/group-goal-run.e2e.test.ts
index df55f6ad06..95744080ff 100644
--- a/server/group-goal-run.e2e.test.ts
+++ b/server/group-goal-run.e2e.test.ts
@@ -1008,10 +1008,16 @@ describe("goal-driven channel runs", () => {
const card = initial.body.messages.find((message: { kind: string }) => message.kind === "goal.run");
expect(card).toMatchObject({ id: expect.any(String) });
- await expect.poll(async () => {
- const page = await api("GET", `/api/threads/${started.body.threadId}/messages?around=${card.id}&limit=1`);
- return page.body.messages[0]?.goalRun;
- }, { timeout: 15_000 }).toMatchObject({ status: "limit-reached", turnCount: 13, maxTurns: 13 });
+ const goalRun = async () => (await api("GET", `/api/threads/${started.body.threadId}/messages?around=${card.id}&limit=1`)).body.messages[0]?.goalRun;
+ let run = await goalRun();
+ let turn = run?.turnCount, movedAt = Date.now();
+ while (run?.status === "working") {
+ if (run.turnCount !== turn) [turn, movedAt] = [run.turnCount, Date.now()];
+ if (Date.now() - movedAt > hostTimeout(10_000)) throw new Error(`the run stopped at turn ${turn}: ${JSON.stringify(run)}`);
+ await new Promise((resolve) => setTimeout(resolve, 100));
+ run = await goalRun();
+ }
+ expect(run).toMatchObject({ status: "limit-reached", turnCount: 13, maxTurns: 13 });
});
it("never treats a failed provider turn as a completed goal", async () => {