From de0965984ff3edf611ae6d0e7ca5c7d5ae3947bb Mon Sep 17 00:00:00 2001 From: Dotta Date: Sat, 3 Oct 2026 07:33:01 -0500 Subject: [PATCH] Reject malformed stock-harness context snapshots Co-Authored-By: Paperclip --- tests/runner-e2e/stock-harness.test.ts | 13 +++++++++++++ tests/runner-e2e/stock-harness.ts | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/runner-e2e/stock-harness.test.ts b/tests/runner-e2e/stock-harness.test.ts index 8f4f57c526..b8ef4087c0 100644 --- a/tests/runner-e2e/stock-harness.test.ts +++ b/tests/runner-e2e/stock-harness.test.ts @@ -153,11 +153,24 @@ describe("stock harness Product E2E", () => { .rejects.toThrow("Public API unavailable"); }); + it("normalizes an omitted conversationMode only from a complete scoped task snapshot", async () => { + const api = { async get(url: string): Promise { + return (url.endsWith("/instructions-bundle") ? { entryFile: "AGENTS.md", files: [] } + : url.endsWith("/heartbeat-runs/run") ? { id: "run", companyId: "company", agentId: "agent", contextSnapshot: { taskId: "task", issueId: "task" } } + : url.includes("/events?") ? [{ eventType: "adapter.invoke", payload: { prompt: "Task context", promptMetrics: { heartbeatPromptChars: 1 } } }] + : { budgetMonthlyCents: 1000 }) as T; + } }; + const result = await captureStockHarness({ api, companyId: "company", agentId: "agent", generation: "legacy", runIds: ["run"] }); + expect(result.invocations[0]?.conversationMode).toBe(false); + }); + it.each([ { id: "other", companyId: "company", agentId: "agent", contextSnapshot: {} }, { id: "run", companyId: "other", agentId: "agent", contextSnapshot: {} }, { id: "run", companyId: "company", agentId: "other", contextSnapshot: {} }, { id: "run", companyId: "company", agentId: "agent" }, + { id: "run", companyId: "company", agentId: "agent", contextSnapshot: "invalid" }, + { id: "run", companyId: "company", agentId: "agent", contextSnapshot: [] }, { id: "run", companyId: "company", agentId: "agent", contextSnapshot: { conversationMode: "unknown" } }, ])("rejects missing or mismatched public invocation mode attribution %#", async run => { const api = { async get(url: string): Promise { diff --git a/tests/runner-e2e/stock-harness.ts b/tests/runner-e2e/stock-harness.ts index 61505e4a0b..7e7fd1dac1 100644 --- a/tests/runner-e2e/stock-harness.ts +++ b/tests/runner-e2e/stock-harness.ts @@ -138,7 +138,8 @@ export async function captureStockHarness(input: { ), }))); if (events.some(({ runId, run }) => run.id !== runId || run.companyId !== input.companyId || run.agentId !== input.agentId || - !run.contextSnapshot || (run.contextSnapshot.conversationMode !== undefined && typeof run.contextSnapshot.conversationMode !== "boolean"))) { + !run.contextSnapshot || typeof run.contextSnapshot !== "object" || Array.isArray(run.contextSnapshot) || + (run.contextSnapshot.conversationMode !== undefined && typeof run.contextSnapshot.conversationMode !== "boolean"))) { throw new Error("Stock invocation mode receipt is missing or bound to a different run/company/agent."); } return {