Skip to content

Commit dcfeb05

Browse files
ochafikclaude
andcommitted
fix: stdio tests failing due to Zod v4 key reordering
The stdio tests were timing out because Zod v4 reconstructs objects with keys in schema definition order, causing JSON.stringify-based message comparisons to fail. Root cause: - Tests sent messages with keys: {jsonrpc, method, ...} - Zod parsed and returned: {method, jsonrpc, ...} - String comparison failed: JSON.stringify(received) !== JSON.stringify(expected) - Promise never resolved, tests timed out Fix: - Replace fragile JSON.stringify comparisons with property-based comparison - Compare actual message content (method, jsonrpc) instead of serialized strings - Key order doesn't matter for semantic equality This is not a breaking change - JSON-RPC doesn't mandate key order, and the SDK handles messages correctly. Only test assertions needed updating. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b35bfa6 commit dcfeb05

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

test/client/stdio.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ test('should read messages', async () => {
5252
client.onmessage = message => {
5353
readMessages.push(message);
5454

55-
if (JSON.stringify(message) === JSON.stringify(messages[1])) {
55+
// Compare message content instead of JSON.stringify (Zod reorders keys)
56+
const msg1 = messages[1];
57+
if (message.method === msg1.method && message.jsonrpc === msg1.jsonrpc) {
5658
resolve();
5759
}
5860
};

test/server/stdio.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ test('should read multiple messages', async () => {
8787
const finished = new Promise<void>(resolve => {
8888
server.onmessage = message => {
8989
readMessages.push(message);
90-
if (JSON.stringify(message) === JSON.stringify(messages[1])) {
90+
// Compare message content instead of JSON.stringify (Zod reorders keys)
91+
const msg1 = messages[1];
92+
if (message.method === msg1.method && message.jsonrpc === msg1.jsonrpc) {
9193
resolve();
9294
}
9395
};

0 commit comments

Comments
 (0)