From c1ea6ca7dc975d205cb3f6fac2c679fbbfb7c88a Mon Sep 17 00:00:00 2001 From: Mathews-Tom Date: Thu, 2 Jul 2026 06:46:17 +0530 Subject: [PATCH] test: fix azure msg-id preservation and retry-diagnostics log shape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Second upstream merge (upstream/main advanced 24 more commits) pulled in two independent behavior changes that broke tests I'd already touched or that existed: - packages/ai: commits cda6df81d/d7f070d44 added preserveAssistantMessageIds for Azure specifically (azure sets it true), so the earlier fix stripping msg ids in azure-openai-responses-stream.test.ts is now wrong for Azure — it should preserve them, unlike the plain OpenAI path. Restored the id/phase assertions and renamed both tests to describe the preserve-not-omit contract. - packages/coding-agent: commit 0e2feab74 (refactor: reduced session log footprint) deleted the '#agentContinueState'/'agent.continue failed state after scheduling' debug diagnostics and changed 'agent active context assistant removal' to fire only on a miss, renamed to 'agent active context assistant removal missed' with a smaller payload (no more removed/beforeLength/afterLength/etc). agent-session-retry-diagnostics.test.ts still asserted the old shape and waited on a debug call that no longer exists, so it hung for the full 5s timeout. Updated to match the new log name/payload and dropped the removed diagnostic assertion; the retry-recovery behavior itself is unchanged and still exercised end to end. --- .../ai/test/azure-openai-responses-stream.test.ts | 6 ++++-- .../test/agent-session-retry-diagnostics.test.ts | 15 +++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/ai/test/azure-openai-responses-stream.test.ts b/packages/ai/test/azure-openai-responses-stream.test.ts index 8f37a5731..02c4ef193 100644 --- a/packages/ai/test/azure-openai-responses-stream.test.ts +++ b/packages/ai/test/azure-openai-responses-stream.test.ts @@ -285,7 +285,7 @@ describe("azure openai responses streaming", () => { expect(result.stopReason).toBe("error"); expect(result.errorMessage).toContain("server_error: backend exploded late"); }); - it("preserves assistant message phase when rebuilding fallback replay history", async () => { + it("preserves assistant message id and phase when rebuilding fallback replay history", async () => { const payload = await captureAzurePayload({ messages: [ { role: "user", content: "first user", timestamp: Date.now() }, @@ -304,13 +304,14 @@ describe("azure openai responses streaming", () => { role: "assistant", content: [{ type: "output_text", text: "Commentary answer", annotations: [] }], status: "completed", + id: "msg_commentary", phase: "final_answer", }, { role: "user", content: [{ type: "input_text", text: "follow-up" }] }, ]); }); - it("omits legacy plain-string text signature IDs when rebuilding fallback replay history without reasoning", async () => { + it("preserves legacy plain-string text signature IDs when rebuilding fallback replay history", async () => { const payload = await captureAzurePayload({ messages: [ { role: "user", content: "first user", timestamp: Date.now() }, @@ -326,6 +327,7 @@ describe("azure openai responses streaming", () => { role: "assistant", content: [{ type: "output_text", text: "Legacy answer", annotations: [] }], status: "completed", + id: "msg_legacy", }, { role: "user", content: [{ type: "input_text", text: "follow-up" }] }, ]); diff --git a/packages/coding-agent/test/agent-session-retry-diagnostics.test.ts b/packages/coding-agent/test/agent-session-retry-diagnostics.test.ts index 5c39a74cc..b8b4c9fa7 100644 --- a/packages/coding-agent/test/agent-session-retry-diagnostics.test.ts +++ b/packages/coding-agent/test/agent-session-retry-diagnostics.test.ts @@ -74,11 +74,11 @@ async function waitFor(predicate: () => boolean, timeoutMs = 500): Promise function isRemovalMissDebugCall(call: unknown[]): boolean { const payload = call[1]; return ( - call[0] === "agent active context assistant removal" && + call[0] === "agent active context assistant removal missed" && typeof payload === "object" && payload !== null && - "removed" in payload && - payload.removed === false + "reason" in payload && + payload.reason === "auto-retry" ); } @@ -143,15 +143,10 @@ describe("AgentSession retry diagnostics", () => { const promptPromise = session.prompt("trigger transient error").catch(() => undefined); await waitFor(() => debugSpy.mock.calls.some(isRemovalMissDebugCall)); - await waitFor(() => debugSpy.mock.calls.some(call => call[0] === "agent.continue failed state after scheduling")); expect(debugSpy.mock.calls).toContainEqual([ - "agent active context assistant removal", - expect.objectContaining({ reason: "auto-retry", removed: false, lastRole: "assistant" }), - ]); - expect(debugSpy.mock.calls).toContainEqual([ - "agent.continue failed state after scheduling", - expect.objectContaining({ lastRole: "assistant", messageCount: 2 }), + "agent active context assistant removal missed", + expect.objectContaining({ reason: "auto-retry", lastRole: "assistant" }), ]); await session.abort(); await promptPromise;