From 274c9f7d61c2836b19a7bb341f5cbbc842a3d9c3 Mon Sep 17 00:00:00 2001 From: Tela Andrews Date: Mon, 2 Mar 2026 11:16:19 -0800 Subject: [PATCH] Add MCP server edge-case tests for find_nodes and Zod validation Covers a few gaps in the existing MCP test suite: - find_nodes filtering by type (wasn't exercised at all) - create_shape with an invalid type enum (Zod enforcement) - create_shape with a missing required param (Zod enforcement) --- tests/engine/mcp-server.test.ts | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/engine/mcp-server.test.ts b/tests/engine/mcp-server.test.ts index f19c657e2..716082801 100644 --- a/tests/engine/mcp-server.test.ts +++ b/tests/engine/mcp-server.test.ts @@ -217,4 +217,48 @@ describe('MCP server', () => { const container2 = tree2.children.find((c) => c.id === frame.id) expect(container2!.children ?? []).toHaveLength(0) }) + + test('find_nodes filters by type', async () => { + await client.callTool({ name: 'new_document', arguments: {} }) + await client.callTool({ + name: 'create_shape', + arguments: { type: 'FRAME', x: 0, y: 0, width: 100, height: 100, name: 'F1' } + }) + await client.callTool({ + name: 'create_shape', + arguments: { type: 'RECTANGLE', x: 0, y: 0, width: 50, height: 50, name: 'R1' } + }) + await client.callTool({ + name: 'create_shape', + arguments: { type: 'FRAME', x: 0, y: 0, width: 100, height: 100, name: 'F2' } + }) + + const result = await client.callTool({ name: 'find_nodes', arguments: { type: 'FRAME' } }) + const data = parseResult(result) as { count: number } + expect(data.count).toBe(2) + }) + + test('create_shape rejects invalid type enum', async () => { + await client.callTool({ name: 'new_document', arguments: {} }) + + const result = await client.callTool({ + name: 'create_shape', + arguments: { type: 'INVALID_TYPE', x: 0, y: 0, width: 100, height: 100 } + }) + const r = result as { content: { text: string }[]; isError?: boolean } + const text = r.content[0].text + expect(r.isError === true || text.toLowerCase().includes('invalid')).toBe(true) + }) + + test('create_shape rejects missing required param', async () => { + await client.callTool({ name: 'new_document', arguments: {} }) + + const result = await client.callTool({ + name: 'create_shape', + arguments: { x: 0, y: 0, width: 100, height: 100 } + }) + const r = result as { content: { text: string }[]; isError?: boolean } + const text = r.content[0].text + expect(r.isError === true || text.toLowerCase().includes('required')).toBe(true) + }) })