|
7 | 7 | } from "../../../src/adapters/cursor/native-exec"; |
8 | 8 | import { resetAppOwnedMemoryForTests } from "../../../src/lib/app-owned-memory"; |
9 | 9 | import { encodeCursorRunRequest } from "../../../src/adapters/cursor/protobuf-request"; |
10 | | -import { applyCursorToolBudget, CURSOR_TOOL_BYTES_LIMIT } from "../../../src/adapters/cursor/request-builder"; |
11 | | -import { cursorMcpToolEncodedSize, cursorMcpToolsEncodedSize } from "../../../src/adapters/cursor/tool-definitions"; |
| 10 | +import { applyCursorToolBudget, createCursorRequest, CURSOR_TOOL_BYTES_LIMIT } from "../../../src/adapters/cursor/request-builder"; |
| 11 | +import { buildCursorToolDefinitions, cursorMcpToolEncodedSize, cursorMcpToolsEncodedSize } from "../../../src/adapters/cursor/tool-definitions"; |
| 12 | +import { parseRequest } from "../../../src/responses/parser"; |
12 | 13 | import type { OcxTool } from "../../../src/types"; |
13 | 14 | import { resetCursorCallIdProvenanceForTests } from "../../../src/adapters/cursor/call-id"; |
14 | 15 | import { |
@@ -107,6 +108,62 @@ describe("Cursor blob handshake", () => { |
107 | 108 | }); |
108 | 109 |
|
109 | 110 | describe("Cursor Claude client tool catalog budget", () => { |
| 111 | + test.each([ |
| 112 | + { bridge: true, name: "Read", expected: ["Read"] }, |
| 113 | + { bridge: true, name: "ocx_client_Read", expected: ["Read"] }, |
| 114 | + { bridge: false, name: "Read", expected: ["Read"] }, |
| 115 | + { bridge: false, name: "ocx_client_Read", expected: [] }, |
| 116 | + ])("registers forced $name with bridge=$bridge after choice filtering", ({ bridge, name, expected }) => { |
| 117 | + const parsed = parseRequest({ |
| 118 | + model: "cursor/auto", input: "read a file", |
| 119 | + tools: [...(bridge ? ["exec_command"] : []), "Read", "Write"].map(name => ({ type: "function", name, parameters: {} })), |
| 120 | + tool_choice: { type: "function", name }, |
| 121 | + }); |
| 122 | + const request = createCursorRequest(parsed); |
| 123 | + expect(buildCursorToolDefinitions(request.tools, request.toolChoice).map(tool => tool.toolName)).toEqual(expected); |
| 124 | + }); |
| 125 | + |
| 126 | + test.each([ |
| 127 | + { allowed: ["ocx_client_Read"], expected: ["Read"] }, |
| 128 | + { allowed: ["exec_command", "ocx_client_Read"], expected: ["exec_command", "ocx_client_Read"] }, |
| 129 | + ])("registers allowed aliases $allowed after choice filtering", ({ allowed, expected }) => { |
| 130 | + const parsed = parseRequest({ |
| 131 | + model: "cursor/auto", input: "read a file", |
| 132 | + tools: ["exec_command", "Read", "Write"].map(name => ({ type: "function", name, parameters: {} })), |
| 133 | + tool_choice: { type: "allowed_tools", mode: "required", tools: allowed.map(name => ({ type: "function", name })) }, |
| 134 | + }); |
| 135 | + const request = createCursorRequest(parsed); |
| 136 | + expect(buildCursorToolDefinitions(request.tools, request.toolChoice).map(tool => tool.toolName)).toEqual(expected); |
| 137 | + }); |
| 138 | + |
| 139 | + test.each(["function", "allowed_tools"])("keeps an aliased %s choice scoped to its original bare identity", type => { |
| 140 | + const parsed = parseRequest({ |
| 141 | + model: "cursor/auto", input: "read a file", |
| 142 | + tools: [ |
| 143 | + { type: "function", name: "exec_command", parameters: {} }, |
| 144 | + { type: "function", name: "Read", parameters: {} }, |
| 145 | + { type: "namespace", name: "mcp__remote", tools: [{ type: "function", name: "Read", parameters: {} }] }, |
| 146 | + ], |
| 147 | + tool_choice: type === "function" |
| 148 | + ? { type, name: "ocx_client_Read" } |
| 149 | + : { type, mode: "required", tools: [{ type: "function", name: "ocx_client_Read" }] }, |
| 150 | + }); |
| 151 | + const request = createCursorRequest(parsed); |
| 152 | + expect(request.tools?.map(tool => [tool.namespace, tool.name])).toEqual([[undefined, "Read"]]); |
| 153 | + expect(buildCursorToolDefinitions(request.tools, request.toolChoice).map(tool => tool.toolName)).toEqual(["Read"]); |
| 154 | + }); |
| 155 | + |
| 156 | + test("preserves both allowed semantic names when a literal name shadows a generated alias", () => { |
| 157 | + const parsed = parseRequest({ |
| 158 | + model: "cursor/auto", input: "read a file", |
| 159 | + tools: ["exec_command", "Read", "ocx_client_Read"].map(name => ({ type: "function", name, parameters: {} })), |
| 160 | + tool_choice: { type: "allowed_tools", mode: "required", tools: ["Read", "ocx_client_Read"].map(name => ({ type: "function", name })) }, |
| 161 | + }); |
| 162 | + const request = createCursorRequest(parsed); |
| 163 | + expect(buildCursorToolDefinitions(request.tools, request.toolChoice).map(tool => tool.toolName)) |
| 164 | + .toEqual(["Read", "ocx_client_ocx_client_Read"]); |
| 165 | + }); |
| 166 | + |
110 | 167 | test("individual sizes use catalog wire names and aliased tool choices", () => { |
111 | 168 | const bridge: OcxTool = { name: "exec_command", parameters: {} }; |
112 | 169 | const read: OcxTool = { name: "Read", parameters: {} }; |
|
0 commit comments