From 9ad07a01cdc208ab14e0fe115d5d472340a0a39c Mon Sep 17 00:00:00 2001 From: Qwen Code Autofix Date: Fri, 31 Jul 2026 11:09:00 +0000 Subject: [PATCH] fix(integration-tests): stabilize async SDK MCP tool handler E2E (#8222) Assert on the deterministic tool result instead of the model's paraphrased final text, which did not reliably echo the value verbatim and caused intermittent failures on main. --- .../sdk-typescript/sdk-mcp-server.test.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/integration-tests/sdk-typescript/sdk-mcp-server.test.ts b/integration-tests/sdk-typescript/sdk-mcp-server.test.ts index a12c885bf58..fe63185ed13 100644 --- a/integration-tests/sdk-typescript/sdk-mcp-server.test.ts +++ b/integration-tests/sdk-typescript/sdk-mcp-server.test.ts @@ -27,6 +27,7 @@ import { SDKTestHelper, extractText, findToolUseBlocks, + findToolResults, createSharedTestOptions, } from './test-helper.js'; @@ -431,7 +432,6 @@ describe('SDK MCP Server Integration (E2E)', () => { }); const messages: SDKMessage[] = []; - let assistantText = ''; let foundToolUse = false; try { @@ -446,15 +446,19 @@ describe('SDK MCP Server Integration (E2E)', () => { if (toolUseBlocks.length > 0) { foundToolUse = true; } - assistantText += extractText(message.message.content); } } // Validate tool was called expect(foundToolUse).toBe(true); - // Validate result contains the delayed response - expect(assistantText.toLowerCase()).toMatch(/test_async/i); + // Assert on the deterministic tool result rather than the model's + // paraphrased final text, which does not reliably echo the value + // verbatim and made this test flaky on main. + const toolResults = findToolResults(messages, MCP_DELAYED_RESPONSE); + expect(toolResults.length).toBeGreaterThan(0); + expect(toolResults[0]?.isError).toBe(false); + expect(toolResults[0]?.content.toLowerCase()).toMatch(/test_async/i); // Validate successful completion const lastMessage = messages[messages.length - 1];