From 0d543dd1ff875b3a09d2cda3cb269ebad7696707 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 18 Jan 2026 22:49:28 +0000 Subject: [PATCH] test: update expectations for session reset behavior --- src/agents/system-prompt.test.ts | 4 +-- ...ction-failure-by-resetting-session.test.ts | 26 +++++++++++-------- src/cli/memory-cli.test.ts | 8 ++++-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/agents/system-prompt.test.ts b/src/agents/system-prompt.test.ts index 5e34b5d78..06570f6ff 100644 --- a/src/agents/system-prompt.test.ts +++ b/src/agents/system-prompt.test.ts @@ -94,7 +94,7 @@ describe("buildAgentSystemPrompt", () => { expect(prompt).toContain("- Read: Read file contents"); expect(prompt).toContain("- Exec: Run shell commands"); expect(prompt).toContain( - "read its SKILL.md at with `Read`", + "- If exactly one skill clearly applies: read its SKILL.md at with `Read`, then follow it.", ); expect(prompt).toContain("Clawdbot docs: /tmp/clawd/docs"); expect(prompt).toContain( @@ -188,7 +188,7 @@ describe("buildAgentSystemPrompt", () => { expect(prompt).toContain("## Skills"); expect(prompt).toContain( - "read its SKILL.md at with `read`", + "- If exactly one skill clearly applies: read its SKILL.md at with `read`, then follow it.", ); }); diff --git a/src/auto-reply/reply/agent-runner.heartbeat-typing.runreplyagent-typing-heartbeat.retries-after-compaction-failure-by-resetting-session.test.ts b/src/auto-reply/reply/agent-runner.heartbeat-typing.runreplyagent-typing-heartbeat.retries-after-compaction-failure-by-resetting-session.test.ts index 7b3a508ff..4d5e3c1fc 100644 --- a/src/auto-reply/reply/agent-runner.heartbeat-typing.runreplyagent-typing-heartbeat.retries-after-compaction-failure-by-resetting-session.test.ts +++ b/src/auto-reply/reply/agent-runner.heartbeat-typing.runreplyagent-typing-heartbeat.retries-after-compaction-failure-by-resetting-session.test.ts @@ -44,10 +44,6 @@ vi.mock("./queue.js", async () => { import { runReplyAgent } from "./agent-runner.js"; -beforeEach(() => { - runEmbeddedPiAgentMock.mockReset(); -}); - function createMinimalRun(params?: { opts?: GetReplyOptions; resolvedVerboseLevel?: "off" | "on"; @@ -125,6 +121,10 @@ function createMinimalRun(params?: { } describe("runReplyAgent typing (heartbeat)", () => { + beforeEach(() => { + runEmbeddedPiAgentMock.mockReset(); + }); + it("retries after compaction failure by resetting the session", async () => { const prevStateDir = process.env.CLAWDBOT_STATE_DIR; const stateDir = await fs.mkdtemp(path.join(tmpdir(), "clawdbot-session-compaction-reset-")); @@ -141,11 +141,11 @@ describe("runReplyAgent typing (heartbeat)", () => { await fs.mkdir(path.dirname(transcriptPath), { recursive: true }); await fs.writeFile(transcriptPath, "ok", "utf-8"); - runEmbeddedPiAgentMock.mockRejectedValueOnce( - new Error( + runEmbeddedPiAgentMock.mockImplementationOnce(async () => { + throw new Error( 'Context overflow: Summarization failed: 400 {"message":"prompt is too long"}', - ), - ); + ); + }); const { run } = createMinimalRun({ sessionEntry, @@ -160,6 +160,7 @@ describe("runReplyAgent typing (heartbeat)", () => { expect(payload).toMatchObject({ text: expect.stringContaining("Context limit exceeded during compaction"), }); + expect(payload.text?.toLowerCase()).toContain("reset"); expect(sessionStore.main.sessionId).not.toBe(sessionId); const persisted = JSON.parse(await fs.readFile(storePath, "utf-8")); @@ -172,6 +173,7 @@ describe("runReplyAgent typing (heartbeat)", () => { } } }); + it("retries after context overflow payload by resetting the session", async () => { const prevStateDir = process.env.CLAWDBOT_STATE_DIR; const stateDir = await fs.mkdtemp(path.join(tmpdir(), "clawdbot-session-overflow-reset-")); @@ -188,7 +190,7 @@ describe("runReplyAgent typing (heartbeat)", () => { await fs.mkdir(path.dirname(transcriptPath), { recursive: true }); await fs.writeFile(transcriptPath, "ok", "utf-8"); - runEmbeddedPiAgentMock.mockResolvedValueOnce({ + runEmbeddedPiAgentMock.mockImplementationOnce(async () => ({ payloads: [{ text: "Context overflow: prompt too large", isError: true }], meta: { durationMs: 1, @@ -198,7 +200,7 @@ describe("runReplyAgent typing (heartbeat)", () => { 'Context overflow: Summarization failed: 400 {"message":"prompt is too long"}', }, }, - }); + })); const { run } = createMinimalRun({ sessionEntry, @@ -211,8 +213,9 @@ describe("runReplyAgent typing (heartbeat)", () => { expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1); const payload = Array.isArray(res) ? res[0] : res; expect(payload).toMatchObject({ - text: expect.stringContaining("Context limit exceeded."), + text: expect.stringContaining("Context limit exceeded"), }); + expect(payload.text?.toLowerCase()).toContain("reset"); expect(sessionStore.main.sessionId).not.toBe(sessionId); const persisted = JSON.parse(await fs.readFile(storePath, "utf-8")); @@ -225,6 +228,7 @@ describe("runReplyAgent typing (heartbeat)", () => { } } }); + it("resets the session after role ordering payloads", async () => { const prevStateDir = process.env.CLAWDBOT_STATE_DIR; const stateDir = await fs.mkdtemp(path.join(tmpdir(), "clawdbot-session-role-ordering-")); diff --git a/src/cli/memory-cli.test.ts b/src/cli/memory-cli.test.ts index 184e181ed..263b23fc9 100644 --- a/src/cli/memory-cli.test.ts +++ b/src/cli/memory-cli.test.ts @@ -266,7 +266,9 @@ describe("memory cli", () => { registerMemoryCli(program); await program.parseAsync(["memory", "index"], { from: "user" }); - expect(sync).toHaveBeenCalledWith({ reason: "cli", force: false }); + expect(sync).toHaveBeenCalledWith( + expect.objectContaining({ reason: "cli", force: false, progress: expect.any(Function) }), + ); expect(close).toHaveBeenCalled(); expect(log).toHaveBeenCalledWith("Memory index updated (main)."); }); @@ -291,7 +293,9 @@ describe("memory cli", () => { registerMemoryCli(program); await program.parseAsync(["memory", "index"], { from: "user" }); - expect(sync).toHaveBeenCalledWith({ reason: "cli", force: false }); + expect(sync).toHaveBeenCalledWith( + expect.objectContaining({ reason: "cli", force: false, progress: expect.any(Function) }), + ); expect(close).toHaveBeenCalled(); expect(error).toHaveBeenCalledWith( expect.stringContaining("Memory manager close failed: close boom"),