|
| 1 | +import { flushMacrotask } from '@sim/testing/helpers/async' |
1 | 2 | import { createDeferred } from '@sim/testing/helpers/deferred' |
2 | 3 | import { |
3 | 4 | mothershipAsyncRunsMock, |
@@ -2252,6 +2253,112 @@ describe('sse-handlers tool lifecycle', () => { |
2252 | 2253 | ) |
2253 | 2254 | }) |
2254 | 2255 |
|
| 2256 | + it("executes a resolved MCP operation with its own arguments under the gateway's grouping", async () => { |
| 2257 | + isSimExecuted.mockReturnValue(false) |
| 2258 | + executeTool.mockResolvedValueOnce({ success: true, output: {} }) |
| 2259 | + const grouping = { id: 'gauge-read', title: 'Reading Gauge', completedTitle: 'Read Gauge' } |
| 2260 | + |
| 2261 | + await sseHandlers.tool( |
| 2262 | + { |
| 2263 | + type: MothershipStreamV1EventType.tool, |
| 2264 | + payload: { |
| 2265 | + toolCallId: 'gateway-mcp', |
| 2266 | + toolName: 'call_integration_tool', |
| 2267 | + arguments: { |
| 2268 | + toolId: 'mcp-server-get_overview', |
| 2269 | + description: 'Pulling the overview', |
| 2270 | + activity: grouping, |
| 2271 | + arguments: { category_id: null }, |
| 2272 | + }, |
| 2273 | + executor: MothershipStreamV1ToolExecutor.go, |
| 2274 | + mode: MothershipStreamV1ToolMode.sync, |
| 2275 | + phase: MothershipStreamV1ToolPhase.call, |
| 2276 | + }, |
| 2277 | + } satisfies StreamEvent, |
| 2278 | + context, |
| 2279 | + execContext, |
| 2280 | + { interactive: false, timeout: 1000 } |
| 2281 | + ) |
| 2282 | + |
| 2283 | + await sseHandlers.tool( |
| 2284 | + { |
| 2285 | + type: MothershipStreamV1EventType.tool, |
| 2286 | + payload: { |
| 2287 | + toolCallId: 'gateway-mcp', |
| 2288 | + toolName: 'mcp-server-get_overview', |
| 2289 | + arguments: { category_id: null }, |
| 2290 | + executor: MothershipStreamV1ToolExecutor.sim, |
| 2291 | + mode: MothershipStreamV1ToolMode.async, |
| 2292 | + phase: MothershipStreamV1ToolPhase.call, |
| 2293 | + }, |
| 2294 | + } satisfies StreamEvent, |
| 2295 | + context, |
| 2296 | + execContext, |
| 2297 | + { interactive: false, timeout: 1000 } |
| 2298 | + ) |
| 2299 | + |
| 2300 | + await flushMacrotask() |
| 2301 | + |
| 2302 | + expect(executeTool).toHaveBeenCalledWith( |
| 2303 | + 'mcp-server-get_overview', |
| 2304 | + { category_id: null }, |
| 2305 | + expect.any(Object) |
| 2306 | + ) |
| 2307 | + expect(context.toolCalls.get('gateway-mcp')?.activity).toEqual(grouping) |
| 2308 | + }) |
| 2309 | + |
| 2310 | + it("keeps an integration operation's own activity argument under the gateway's grouping", async () => { |
| 2311 | + isSimExecuted.mockReturnValue(false) |
| 2312 | + executeTool.mockResolvedValueOnce({ success: true, output: {} }) |
| 2313 | + |
| 2314 | + await sseHandlers.tool( |
| 2315 | + { |
| 2316 | + type: MothershipStreamV1EventType.tool, |
| 2317 | + payload: { |
| 2318 | + toolCallId: 'gateway-work-item', |
| 2319 | + toolName: 'call_integration_tool', |
| 2320 | + arguments: { |
| 2321 | + toolId: 'azure_devops_create_work_item', |
| 2322 | + description: 'Filing the task', |
| 2323 | + activity: { id: 'filing', title: 'Filing tasks', completedTitle: 'Filed tasks' }, |
| 2324 | + arguments: { title: 'Ship it', activity: 'Development' }, |
| 2325 | + }, |
| 2326 | + executor: MothershipStreamV1ToolExecutor.go, |
| 2327 | + mode: MothershipStreamV1ToolMode.sync, |
| 2328 | + phase: MothershipStreamV1ToolPhase.call, |
| 2329 | + }, |
| 2330 | + } satisfies StreamEvent, |
| 2331 | + context, |
| 2332 | + execContext, |
| 2333 | + { interactive: false, timeout: 1000 } |
| 2334 | + ) |
| 2335 | + |
| 2336 | + await sseHandlers.tool( |
| 2337 | + { |
| 2338 | + type: MothershipStreamV1EventType.tool, |
| 2339 | + payload: { |
| 2340 | + toolCallId: 'gateway-work-item', |
| 2341 | + toolName: 'azure_devops_create_work_item', |
| 2342 | + arguments: { title: 'Ship it', activity: 'Development' }, |
| 2343 | + executor: MothershipStreamV1ToolExecutor.sim, |
| 2344 | + mode: MothershipStreamV1ToolMode.async, |
| 2345 | + phase: MothershipStreamV1ToolPhase.call, |
| 2346 | + }, |
| 2347 | + } satisfies StreamEvent, |
| 2348 | + context, |
| 2349 | + execContext, |
| 2350 | + { interactive: false, timeout: 1000 } |
| 2351 | + ) |
| 2352 | + |
| 2353 | + await flushMacrotask() |
| 2354 | + |
| 2355 | + expect(executeTool).toHaveBeenCalledWith( |
| 2356 | + 'azure_devops_create_work_item', |
| 2357 | + { title: 'Ship it', activity: 'Development' }, |
| 2358 | + expect.any(Object) |
| 2359 | + ) |
| 2360 | + }) |
| 2361 | + |
2255 | 2362 | it('clears pending continuation state when a run resumes', async () => { |
2256 | 2363 | context.awaitingAsyncContinuation = { |
2257 | 2364 | checkpointId: 'cp-1', |
|
0 commit comments