|
5 | 5 | advertisedTools, |
6 | 6 | createActivatedToolTracker, |
7 | 7 | } from "./agent/tool-search.js"; |
| 8 | +import { createAdvertisedToolset } from "./session/assemble-runtime.js"; |
8 | 9 | import { createPermissionGate } from "./permission/gate.js"; |
9 | 10 | import { |
10 | 11 | COMPACTOR_KEEP_RECENT_TURNS, |
@@ -1145,6 +1146,64 @@ describe("updateToolDefinitions rewrites infer tools", () => { |
1145 | 1146 | expect(JSON.stringify(after)).toBe(JSON.stringify(before)); |
1146 | 1147 | }); |
1147 | 1148 |
|
| 1149 | + // CL-7868: the provider cache is a prefix cache keyed on the tools array, |
| 1150 | + // so a tool_search turn that promotes a genuinely new tool must not reshape |
| 1151 | + // the wire set mid-session. The call gate opens (the model invokes the tool |
| 1152 | + // from the search result's schema) while the advertised array holds steady |
| 1153 | + // until the next cache-safe boundary. |
| 1154 | + test("a tool_search turn promoting a genuinely new tool leaves the wire byte-identical", async () => { |
| 1155 | + const linearTool = { |
| 1156 | + name: "mcp__linear__list_issues", |
| 1157 | + description: "list issues", |
| 1158 | + inputSchema: { type: "object", properties: {}, required: [] }, |
| 1159 | + }; |
| 1160 | + const toolset = await createAgentToolset({ |
| 1161 | + cwd: process.cwd(), |
| 1162 | + permissionGate: createPermissionGate({ |
| 1163 | + approvals: [], |
| 1164 | + interactive: false, |
| 1165 | + skipPermissions: true, |
| 1166 | + reactorGated: false, |
| 1167 | + }), |
| 1168 | + onOperatorGate: async () => ({ kind: "cancel" }), |
| 1169 | + }); |
| 1170 | + toolset.dynamicRunner.addTools([ |
| 1171 | + { kind: "string", definition: linearTool, handler: async () => "ok" }, |
| 1172 | + ]); |
| 1173 | + |
| 1174 | + const advertised = createAdvertisedToolset({ |
| 1175 | + sessionMode: "orchestrator", |
| 1176 | + toolAvailability: { languageServerAvailable: false }, |
| 1177 | + getProvider: () => ({ providerName: "openai", model: "gpt-5" }), |
| 1178 | + }); |
| 1179 | + const director = createChatDirector( |
| 1180 | + "base-prompt", |
| 1181 | + advertised.computeAdvertised(toolset.dynamicRunner.currentDefinitions()), |
| 1182 | + { onTasksChange: () => undefined }, |
| 1183 | + ); |
| 1184 | + |
| 1185 | + const before = await firstInferTools( |
| 1186 | + director, |
| 1187 | + makeMessageReceivedEvent("hello"), |
| 1188 | + ); |
| 1189 | + |
| 1190 | + // tool_search matched a genuinely new tool: the runner opens the call |
| 1191 | + // gate and refreshes the director exactly as it does today. |
| 1192 | + advertised.activated.activate(["mcp__linear__list_issues"]); |
| 1193 | + director.updateToolDefinitions( |
| 1194 | + advertised.computeAdvertised(toolset.dynamicRunner.currentDefinitions()), |
| 1195 | + ); |
| 1196 | + |
| 1197 | + const after = await firstInferTools( |
| 1198 | + director, |
| 1199 | + makeMessageReceivedEvent("continue"), |
| 1200 | + ); |
| 1201 | + expect(JSON.stringify(after)).toBe(JSON.stringify(before)); |
| 1202 | + expect(advertised.isAdvertised("mcp__linear__list_issues")).toBe(true); |
| 1203 | + |
| 1204 | + await toolset.dispose(); |
| 1205 | + }); |
| 1206 | + |
1148 | 1207 | // submit_output is always on the wire so a workflow going active never grows |
1149 | 1208 | // the array and busts the provider cache prefix. |
1150 | 1209 | test("submit_output is advertised even with no active workflow", async () => { |
|
0 commit comments