Skip to content

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

Tests: fakes vary their looping calls, answer only POSTs, and match Windows paths (#4197)

Milind Soniddafb4c551ae
diff --git a/server/comms.test.ts b/server/comms.test.ts
index 8f87c675aa..ce139a1606 100644
--- a/server/comms.test.ts
+++ b/server/comms.test.ts
@@ -231,7 +231,7 @@ describe("routine comms e2e on the job runtime (fake ACP fleet)", () => {
}
const steps = compatAnswer === "steps";
const delta = steps
- ? { content: "Still exporting.", tool_calls: [{ index: 0, id: `call_${randomUUID()}`, type: "function", function: { name: "missing_tool", arguments: "{}" } }] }
+ ? { content: "Still exporting.", tool_calls: [{ index: 0, id: `call_${randomUUID()}`, type: "function", function: { name: "missing_tool", arguments: JSON.stringify({ call: randomUUID() }) } }] }
: { content: "ping from fake" };
res.writeHead(200, { "content-type": "text/event-stream" });
res.end(`data: ${JSON.stringify({ choices: [{ index: 0, delta, finish_reason: steps ? "tool_calls" : "stop" }] })}\n\ndata: [DONE]\n\n`);
diff --git a/server/delta-context.e2e.test.ts b/server/delta-context.e2e.test.ts
index 743d1bdc9f..00b3b05561 100644
--- a/server/delta-context.e2e.test.ts
+++ b/server/delta-context.e2e.test.ts
@@ -638,6 +638,8 @@ it.each(["SIGTERM", "SIGKILL"] as const)("runs each teammate turn a restart cut
const upstream = createServer(async (req, res) => {
if (req.url === "/v1/models") { res.setHeader("content-type", "application/json"); res.end(JSON.stringify({ data: [{ id: "fixture-model" }] })); return; }
let body = "";
+ // Only a turn's POST carries a body; the Ollama probe GETs /api/version first (ollama-context.ts).
+ if (req.method !== "POST") { res.writeHead(404); res.end(); return; }
for await (const chunk of req) body += chunk;
const content = JSON.parse(body).messages.filter((m: any) => m.role === "user").at(-1)?.content;
chats.push(typeof content === "string" ? content : JSON.stringify(content));
diff --git a/server/drivers/agents-bridge-chat.test.ts b/server/drivers/agents-bridge-chat.test.ts
index b771c364aa..8f18bdaff3 100644
--- a/server/drivers/agents-bridge-chat.test.ts
+++ b/server/drivers/agents-bridge-chat.test.ts
@@ -45,6 +45,8 @@ it("a bridged turn on the chat-completions runtime carries on after use_tool nam
return;
}
let data = "";
+ // Only a turn's POST carries a body; the Ollama probe GETs /api/version first (ollama-context.ts).
+ if (request.method !== "POST") { response.writeHead(404); response.end(); return; }
for await (const part of request) data += part.toString();
requests.push(JSON.parse(data) as ChatRequest);
if (requests.length === 1) calls(response, "call_guess", "agents_use_tool", { name: "schedule_task", arguments: { every: "morning" } });
diff --git a/server/drivers/chat-size-limit.test.ts b/server/drivers/chat-size-limit.test.ts
index 719c5b7846..19e6a0f957 100644
--- a/server/drivers/chat-size-limit.test.ts
+++ b/server/drivers/chat-size-limit.test.ts
@@ -109,6 +109,8 @@ describe("an OpenAI-compatible provider that refuses large requests", () => {
return;
}
const chunks: Buffer[] = [];
+ // Only a turn's POST carries a body; the Ollama probe GETs /api/version first (ollama-context.ts).
+ if (req.method !== "POST") { res.writeHead(404); res.end(); return; }
for await (const chunk of req) chunks.push(chunk as Buffer);
const raw = Buffer.concat(chunks);
requests.push({ bytes: raw.length, messages: JSON.parse(raw.toString("utf8")).messages });
diff --git a/server/drivers/openai-chat-local-model.test.ts b/server/drivers/openai-chat-local-model.test.ts
index 5d2bbd5297..386b33fbd4 100644
--- a/server/drivers/openai-chat-local-model.test.ts
+++ b/server/drivers/openai-chat-local-model.test.ts
@@ -56,6 +56,8 @@ async function fixture(script: Script, driver: "local" | "hosted" = "local") {
const server = createServer(async (request, response) => {
if (request.url === "/v1/models") { response.setHeader("content-type", "application/json"); response.end('{"data":[]}'); return; }
let data = "";
+ // Only a turn's POST carries a body; the Ollama probe GETs /api/version first (ollama-context.ts).
+ if (request.method !== "POST") { response.writeHead(404); response.end(); return; }
for await (const part of request) data += part.toString();
const body = JSON.parse(data) as ChatRequest;
requests.push(body);
diff --git a/server/drivers/openai-chat-safety-floor.test.ts b/server/drivers/openai-chat-safety-floor.test.ts
index 8050412ddf..6c89f3b5e0 100644
--- a/server/drivers/openai-chat-safety-floor.test.ts
+++ b/server/drivers/openai-chat-safety-floor.test.ts
@@ -75,6 +75,8 @@ async function fixture(commands: string[]) {
return;
}
let data = "";
+ // Only a turn's POST carries a body; the Ollama probe GETs /api/version first (ollama-context.ts).
+ if (request.method !== "POST") { response.writeHead(404); response.end(); return; }
for await (const part of request) data += part.toString();
requests.push(JSON.parse(data) as ChatRequest);
const command = commands[requests.length - 1];
diff --git a/server/drivers/openai-chat-tools.test.ts b/server/drivers/openai-chat-tools.test.ts
index e5aed70893..e9c94d66c1 100644
--- a/server/drivers/openai-chat-tools.test.ts
+++ b/server/drivers/openai-chat-tools.test.ts
@@ -103,6 +103,8 @@ async function fixture(script: Script, provider: Provider = "openai-compat", api
return;
}
let data = "";
+ // Only a turn's POST carries a body; the Ollama probe GETs /api/version first (ollama-context.ts).
+ if (request.method !== "POST") { response.writeHead(404); response.end(); return; }
for await (const part of request) data += part.toString();
if (request.url === "/mcp-start") {
rpcStarted.resolve(JSON.parse(data));
diff --git a/server/drivers/openai-responses.test.ts b/server/drivers/openai-responses.test.ts
index fc1b615e13..7a98d2aebd 100644
--- a/server/drivers/openai-responses.test.ts
+++ b/server/drivers/openai-responses.test.ts
@@ -106,6 +106,8 @@ async function fixture(script: Script, apiUrl = OPENAI) {
return;
}
let data = "";
+ // Only a turn's POST carries a body; the Ollama probe GETs /api/version first (ollama-context.ts).
+ if (request.method !== "POST") { response.writeHead(404); response.end(); return; }
for await (const part of request) data += part.toString();
const call = { path: request.url ?? "", body: JSON.parse(data) as Record<string, any> };
calls.push(call);
diff --git a/server/long-running-chief.e2e.test.ts b/server/long-running-chief.e2e.test.ts
index 02066155c2..695a1e2def 100644
--- a/server/long-running-chief.e2e.test.ts
+++ b/server/long-running-chief.e2e.test.ts
@@ -34,6 +34,8 @@ async function chiefJob(test: (f: any) => Promise<void>) {
const model = createServer(async (req, res) => {
if (req.url?.endsWith("/models")) { res.setHeader("content-type", "application/json"); res.end(JSON.stringify({ data: [{ id: "loop-model" }] })); return; }
let body = "";
+ // Only a turn's POST carries a body; the Ollama probe GETs /api/version first (ollama-context.ts).
+ if (req.method !== "POST") { res.writeHead(404); res.end(); return; }
for await (const chunk of req) body += chunk;
const sent = JSON.parse(body) as { messages: Array<{ role: string; content?: unknown }>; tools?: Array<{ function: { name: string } }> };
const text = (message: { content?: unknown }) => typeof message.content === "string" ? message.content
@@ -47,7 +49,9 @@ async function chiefJob(test: (f: any) => Promise<void>) {
if ("hold" in given) { await given.hold; return reply(out, given.after); }
out.writeHead(200, { "content-type": "text/event-stream" });
out.end("say" in given ? frame({ content: given.say }, "stop") + "data: [DONE]\n\n"
- : frame({ tool_calls: [{ index: 0, id: `call_${++callSerial}`, type: "function", function: { name: tool, arguments: "{}" } }] }, "tool_calls") + "data: [DONE]\n\n");
+ // Each call carries its own round: a local model that repeats one identical call is stopped after ten (chat-repeat-guard.ts),
+ // and this loop is meant to run to the step cap.
+ : frame({ tool_calls: [{ index: 0, id: `call_${++callSerial}`, type: "function", function: { name: tool, arguments: JSON.stringify({ round: callSerial }) } }] }, "tool_calls") + "data: [DONE]\n\n");
};
await reply(res, answer(request)).catch(() => {});
});
diff --git a/server/runtime-roots.e2e.test.ts b/server/runtime-roots.e2e.test.ts
index ef52505542..6e7f49d13a 100644
--- a/server/runtime-roots.e2e.test.ts
+++ b/server/runtime-roots.e2e.test.ts
@@ -64,6 +64,8 @@ async function loopbackModel() {
const model = createServer(async (req, res) => {
if (req.url?.endsWith("/models")) { res.setHeader("content-type", "application/json"); res.end(JSON.stringify({ data: [{ id: "loop-model" }] })); return; }
let body = "";
+ // Only a turn's POST carries a body; the Ollama probe GETs /api/version first (ollama-context.ts).
+ if (req.method !== "POST") { res.writeHead(404); res.end(); return; }
for await (const chunk of req) body += chunk;
const sent = JSON.parse(body) as { messages: Array<{ role: string; content?: unknown }>; tools?: Array<{ function: { name: string } }> };
const text = (message: { content?: unknown }) => typeof message.content === "string" ? message.content
@@ -76,7 +78,7 @@ async function loopbackModel() {
const reply = (out: ServerResponse, given: ModelAnswer) => {
out.writeHead(200, { "content-type": "text/event-stream" });
out.end("say" in given ? frame({ content: given.say }, "stop") + "data: [DONE]\n\n"
- : frame({ tool_calls: [{ index: 0, id: `call_${++callSerial}`, type: "function", function: { name: tool, arguments: "{}" } }] }, "tool_calls") + "data: [DONE]\n\n");
+ : frame({ tool_calls: [{ index: 0, id: `call_${++callSerial}`, type: "function", function: { name: tool, arguments: JSON.stringify({ round: callSerial }) } }] }, "tool_calls") + "data: [DONE]\n\n");
};
reply(res, answer(request));
});
diff --git a/server/server-writes.test.ts b/server/server-writes.test.ts
index 3cc0e74125..ebf64bb62f 100644
--- a/server/server-writes.test.ts
+++ b/server/server-writes.test.ts
@@ -2,7 +2,7 @@
// (where a crash or an exit can land) the files hold what one write per change would have left.
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
-import { join } from "node:path";
+import { basename, join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
// Spied, not replaced: every call reaches the real filesystem, and a test counts the renames a save costs.
@@ -16,8 +16,9 @@ const { RoutineManager } = await import("./routines.ts");
type RuntimeEvent = import("./contracts.ts").RuntimeEvent;
const selection = () => ({ instanceId: "claude", model: "claude-sonnet-5" });
-const writesOf = (name: string) => vi.mocked(fs.renameSync).mock.calls.filter(([, to]) => String(to).endsWith(`/${name}`)).length;
-const reads = (name: string) => vi.mocked(fs.readFileSync).mock.calls.filter(([path]) => String(path).endsWith(`/${name}`)).length;
+// By file name, so a Windows path (backslashes) counts the same as any other.
+const writesOf = (name: string) => vi.mocked(fs.renameSync).mock.calls.filter(([, to]) => basename(String(to)) === name).length;
+const reads = (name: string) => vi.mocked(fs.readFileSync).mock.calls.filter(([path]) => basename(String(path)) === name).length;
const bots = () => readFileSync(join(DATA_DIR, "bots.json"), "utf8");
describe("bots.json saves", () => {