Skip to content

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

Test that a routine's report keeps its turn's files when the person writes in the run, and drops them when it recovered

Xiaolei Shi98c96be631e5
diff --git a/server/automation-reports.e2e.test.ts b/server/automation-reports.e2e.test.ts
index 1ae818228a..dd45604690 100644
--- a/server/automation-reports.e2e.test.ts
+++ b/server/automation-reports.e2e.test.ts
@@ -1,7 +1,8 @@
// Automations report into the bot's chat, end to end: the real server and Claude driver, the scripted fake engine
// answering each turn by what it was sent, and the permission broker reached the way the CLI's proxy reaches it.
-import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
import { connect, type Socket } from "node:net";
+import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, expect, it } from "vitest";
@@ -434,3 +435,33 @@ it("brings the files a run sent with attach_file into its report", async () => {
text: "Today's brief is attached.", attachments: [expect.objectContaining({ kind: "file", name: "brief.pdf" })],
})]);
}, 120_000);
+
+it("leaves the images a run's tools returned in the run, and reports the files it sent", async () => {
+ const calls = join(mkdtempSync(join(tmpdir(), "omb-report-files-")), "tool-calls.json");
+ fixture = await launchVerificationServer({ ...process.env, FAKE_CLAUDE_TOOL_CALLS_FILE: calls });
+ const { url, dataDir } = fixture.info;
+ const api = async (method: string, path: string, body?: unknown) => (await fetch(`${url}${path}`, {
+ method, headers: { "content-type": "application/json", origin: url }, ...(body === undefined ? {} : { body: JSON.stringify(body) }),
+ })).json() as Promise<any>;
+ const { bot } = await runControlOmb(["new-bot", "--name", "Pepper", "--url", url]) as any;
+ const folder = join(dataDir, "workspaces", bot.id);
+ mkdirSync(folder, { recursive: true });
+ writeFileSync(join(folder, "brief.pdf"), "%PDF-brief");
+ const page = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
+ writeFileSync(calls, JSON.stringify([
+ { name: "Read", input: { file_path: "brief.pdf" }, output: [{ type: "image", source: { type: "base64", media_type: "image/png", data: page } }] },
+ { name: "attach_file", server: "agents", input: { path: join(folder, "brief.pdf") } },
+ ]));
+ const { routine } = await api("POST", "/api/routines", {
+ name: "Daily brief", prompt: "Do the Daily brief check.", botId: bot.id, enabled: false,
+ schedule: { type: "interval", everyMinutes: 60, anchorAt: Date.now() + 3_600_000 },
+ });
+ const { run: { id } } = await api("POST", `/api/routines/${routine.id}/run`);
+ const run = async () => (await api("GET", "/api/routines")).runs.find((candidate: any) => candidate.id === id);
+ await expect.poll(async () => (await run())?.report?.state, { timeout: 30_000 }).toBe("posted");
+ const messages = async (threadId: string) => (await api("GET", `/api/threads/${threadId}/messages?limit=200`)).messages as any[];
+ const inRun = (await messages((await run()).threadId)).flatMap((message) => message.attachments ?? []);
+ expect(inRun).toEqual(expect.arrayContaining([expect.objectContaining({ kind: "image", fromTool: true }), expect.objectContaining({ kind: "file", name: "brief.pdf" })]));
+ const report = (await messages(bot.activeTaskId)).filter((message) => message.automation);
+ expect(report).toEqual([expect.objectContaining({ attachments: [expect.objectContaining({ kind: "file", name: "brief.pdf" })] })]);
+}, 120_000);
diff --git a/server/automation-reports.test.ts b/server/automation-reports.test.ts
index 91a879dc59..110c74ec9e 100644
--- a/server/automation-reports.test.ts
+++ b/server/automation-reports.test.ts
@@ -474,6 +474,32 @@ describe("automation reports", () => {
expect(f.runs.get(run.id)!.report).toMatchObject({ state: "posted" });
});
+ it("still carries the turn's files when the person wrote in the run before its report was written", () => {
+ const f = fixture();
+ const run = f.finished(null);
+ const pdf = { kind: "file" as const, path: "brief-1.pdf", mime: "application/pdf", name: "Brief.pdf" };
+ f.store.appendMessage(run.threadId!, { role: "bot", kind: "text", text: "", attachments: [pdf] });
+ f.store.appendMessage(run.threadId!, { role: "bot", kind: "text", text: "Your brief.", turnId: `turn-${run.id}`, turnTerminal: true });
+ f.busy.add(f.main);
+ f.reports.runSettled(run, `turn-${run.id}`);
+ f.store.appendMessage(run.threadId!, { role: "user", kind: "text", text: "Thanks." });
+ f.busy.delete(f.main);
+ f.reports.flush();
+ expect(f.lines()).toEqual([expect.objectContaining({ text: "Your brief.", attachments: [pdf] })]);
+ });
+
+ it("says only that an automation recovered, without the files its quiet run sent", () => {
+ const f = fixture();
+ const failed = f.finished(null, "Inbox brief", { status: "failed", error: "Timed out" });
+ f.reports.runFailed(failed, "it ran past its 25-minute limit.");
+ const ok = f.finished(null);
+ f.store.appendMessage(ok.threadId!, { role: "bot", kind: "text", text: "", attachments: [{ kind: "file", path: "brief-1.pdf", mime: "application/pdf", name: "Brief.pdf" }] });
+ f.store.appendMessage(ok.threadId!, { role: "bot", kind: "text", text: "NOTHING NEW", turnId: `turn-${ok.id}`, turnTerminal: true });
+ f.reports.runSettled(ok, `turn-${ok.id}`);
+ expect(f.lines().at(-1)).toMatchObject({ automation: expect.objectContaining({ recovered: true }) });
+ expect(f.lines().at(-1)).not.toHaveProperty("attachments");
+ });
+
it("keeps a run quiet that said nothing and sent nothing, though its tools returned images", () => {
const f = fixture();
const run = f.finished(null);