Skip to content

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

test: fixtures key and fold each turn as the model receives it

Absterrg09ac7ee53a22a
diff --git a/server/direct-coordination.e2e.test.ts b/server/direct-coordination.e2e.test.ts
index eeb701d6a3..3c4b50b061 100644
--- a/server/direct-coordination.e2e.test.ts
+++ b/server/direct-coordination.e2e.test.ts
@@ -544,7 +544,7 @@ it("continues one recipient thread for every follow-up from the same conversatio
const leadTurns = f.evidence().filter((turn: any) => turn.botId === f.lead.id);
expect(leadTurns.map((turn: any) => turn.threadId)).toEqual([first.threadId, first.threadId, first.threadId]);
for (const [index, brief] of briefs.entries()) expect(leadTurns[index].prompt.message.content).toContain(brief);
- expect(leadTurns.every((turn: any) => told(turn).includes("current request and returned results arrive in the user turn"))).toBe(true);
+ expect(leadTurns.every((turn: any) => turn.system.includes("current request and returned results arrive in the user turn"))).toBe(true);
expect(leadTurns.every((turn: any) => turn.snapshotMode === "off")).toBe(true);
for (const brief of briefs) expect(leadTurns.every((turn: any) => !turn.system.includes(brief))).toBe(true);
const receipts = sendReceipts(f, f.chief.id);
diff --git a/server/testing/fake-claude-cli.ts b/server/testing/fake-claude-cli.ts
index 8197e9b0cd..74410254a3 100755
--- a/server/testing/fake-claude-cli.ts
+++ b/server/testing/fake-claude-cli.ts
@@ -1294,8 +1294,7 @@ const playTurn = (prompt: JsonValue, late = false) => {
const tail = steered.length ? ` + steered: ${steered.join(" | ")}` : "";
replaySteered();
out({ type: "assistant", message: { content: [{ type: "text", text: `reply to: ${promptText(prompt)}${tail}` }] } });
- const gate = process.env.FAKE_CLAUDE_SLOW_FINISH_GATE;
- if (!lateContinuation && gate && readFileSync(gate, "utf8").trim() === "fail") {
+ if (!lateContinuation && finishGate && readFileSync(finishGate, "utf8").trim() === "fail") {
out({ type: "result", is_error: true, stop_reason: "error", result: "fixture turn failed" });
turnRunning = false;
finishIfDone();
diff --git a/server/testing/launch-note.ts b/server/testing/launch-note.ts
index 5e5991d965..89f1467468 100644
--- a/server/testing/launch-note.ts
+++ b/server/testing/launch-note.ts
@@ -1,15 +1,17 @@
// The volatile half of a bot's instructions rides in a new session's first
// user message (prompt-split.ts withVolatileNote, launch form) so the system
-// prompt file stays the same for every session of the bot. Fakes fold it back
-// into "the system prompt" they record and drop it from "the prompt", so a
-// test reads both as the model receives them.
+// prompt file stays the same for every session of the bot, and in a warm
+// session's next message when it changed. Fakes fold it back into "the system
+// prompt" they record and drop it from "the prompt", so a test reads both as
+// the model receives them.
const LAUNCH_NOTE = /^<system-reminder>\nThis part of your instructions changes from turn to turn, so it arrives here instead of in the system prompt\. It replaces any earlier copy:\n\n([\s\S]*?)\n<\/system-reminder>(?:\n\n)?/;
+const CHANGED_NOTE = /^<system-reminder>\nThis part of your instructions changed since this session started\. It replaces the earlier copy:\n\n([\s\S]*?)\n<\/system-reminder>(?:\n\n)?/;
-export function splitLaunchNote<T>(prompt: T): { note: string | null; prompt: T } {
+function splitNote<T>(pattern: RegExp, prompt: T): { note: string | null; prompt: T } {
const message = (prompt as { message?: { content?: unknown } } | null)?.message;
const content = message?.content;
const strip = (text: string) => {
- const match = LAUNCH_NOTE.exec(text);
+ const match = pattern.exec(text);
return match ? { note: match[1]!, text: text.slice(match[0].length) } : null;
};
if (typeof content === "string") {
@@ -25,3 +27,11 @@ export function splitLaunchNote<T>(prompt: T): { note: string | null; prompt: T
}
return { note: null, prompt };
}
+
+export function splitLaunchNote<T>(prompt: T): { note: string | null; prompt: T } {
+ return splitNote(LAUNCH_NOTE, prompt);
+}
+
+export function splitChangedNote<T>(prompt: T): { note: string | null; prompt: T } {
+ return splitNote(CHANGED_NOTE, prompt);
+}
diff --git a/server/testing/room-handoff-agent.ts b/server/testing/room-handoff-agent.ts
index 24b5f04a49..3deb7012bb 100644
--- a/server/testing/room-handoff-agent.ts
+++ b/server/testing/room-handoff-agent.ts
@@ -1,5 +1,5 @@
// Scripted provider fixture that exercises the REAL injected agents MCP proxy.
-import { splitLaunchNote } from "./launch-note.ts";
+import { splitChangedNote, splitLaunchNote } from "./launch-note.ts";
import { spawn } from "node:child_process";
import { appendFileSync, readFileSync, existsSync, writeFileSync } from "node:fs";
import { join } from "node:path";
@@ -13,6 +13,8 @@ type ScriptEntry = { key: string; match: string[]; repeat?: boolean; [field: str
// Claude reads its MCP config and system prompt once at launch; the harness deletes both after the first turn.
const launchFiles = new Map<string, string>();
+/** The volatile half this session holds now: from its launch note, then from each note that changed it. */
+let volatileNote: string | null = null;
const readAtLaunch = (path: string) => {
if (!launchFiles.has(path)) launchFiles.set(path, readFileSync(path, "utf8"));
return launchFiles.get(path)!;
@@ -130,9 +132,11 @@ export async function runRoomHandoffAgent(argv: string[], planPath: string, prom
const agent = agentEnv(integration);
const botId = agent.OMB_BOT_ID;
const launchNote = splitLaunchNote(prompt);
- prompt = launchNote.prompt;
+ const changedNote = splitChangedNote(launchNote.prompt);
+ prompt = changedNote.prompt;
+ volatileNote = launchNote.note ?? changedNote.note ?? volatileNote;
const launchSystem = launch?.system ?? readAtLaunch(arg("--append-system-prompt-file"));
- const system = launchNote.note && typeof launchSystem === "string" ? `${launchSystem}\n\n${launchNote.note}` : launchSystem;
+ const system = volatileNote && typeof launchSystem === "string" ? `${launchSystem}\n\n${volatileNote}` : launchSystem;
// Claude snapshots the launch-time system prompt; later instructions arrive in the user message.
const turnContext = `${system}\n${JSON.stringify(prompt)}`;
const resumed = turnContext.includes("Your downstream room requests have settled.");
diff --git a/server/thread-aware-bots.e2e.test.ts b/server/thread-aware-bots.e2e.test.ts
index 8f18f52aed..6840ca94f6 100644
--- a/server/thread-aware-bots.e2e.test.ts
+++ b/server/thread-aware-bots.e2e.test.ts
@@ -164,21 +164,23 @@ beforeAll(async () => {
"const relay = new PassThrough();",
"const real = process.stdin;",
'Object.defineProperty(process, "stdin", { value: relay, configurable: true });',
- "let decided = false;",
'let held = "";',
'real.on("data", (chunk) => {',
- " if (decided) { relay.write(chunk); return; }",
" held += chunk;",
- ' const nl = held.indexOf("\\n");',
- " if (nl === -1) return;",
- " const marker = /\\[\\[gate:([\\w-]+)\\]\\]/.exec(held.slice(0, nl));",
- ' const key = marker?.[1] ?? thread ?? "peer";',
- ` process.env.FAKE_CLAUDE_SLOW_FINISH_GATE = join(${JSON.stringify(gates)}, key + ".gate");`,
- ` process.env.FAKE_CLAUDE_DUMP = join(${JSON.stringify(gates)}, key + ".json");`,
- ` process.env.FAKE_CLAUDE_PROMPTS = join(${JSON.stringify(gates)}, key + ".prompts.jsonl");`,
- " decided = true;",
- " relay.write(held);",
- ' held = "";',
+ " let nl;",
+ ' while ((nl = held.indexOf("\\n")) !== -1) {',
+ " const line = held.slice(0, nl + 1);",
+ " held = held.slice(nl + 1);",
+ " if (line.includes('\"type\":\"user\"')) {",
+ ' const withoutInstructions = line.replace(/<system-reminder>[\\s\\S]*?<\\/system-reminder>/g, "");',
+ " const marker = /\\[\\[gate:([\\w-]+)\\]\\]/.exec(withoutInstructions);",
+ ' const key = marker?.[1] ?? thread ?? "peer";',
+ ` process.env.FAKE_CLAUDE_SLOW_FINISH_GATE = join(${JSON.stringify(gates)}, key + ".gate");`,
+ ` process.env.FAKE_CLAUDE_DUMP = join(${JSON.stringify(gates)}, key + ".json");`,
+ ` process.env.FAKE_CLAUDE_PROMPTS = join(${JSON.stringify(gates)}, key + ".prompts.jsonl");`,
+ " }",
+ " relay.write(line);",
+ " }",
"});",
'real.on("end", () => relay.end());',
'process.env.FAKE_CLAUDE_MODE = "slow";',