Skip to content

Commit ad61fff

Browse files
committed
fix(tests): bind the real cancellation handler in the router test; mock the narrowed contract path
1 parent 1c3707d commit ad61fff

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

apps/sim/lib/copilot/server/agent-url.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { envMock } = vi.hoisted(() => ({
1616
},
1717
}))
1818

19-
vi.mock('@/lib/api/contracts', () => ({
19+
vi.mock('@/lib/api/contracts/user', () => ({
2020
mothershipEnvironmentSchema: {
2121
safeParse: (value: unknown) =>
2222
['default', 'dev', 'staging', 'prod'].includes(String(value))

apps/sim/lib/copilot/tool-executor/router.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import { describe, expect, it, vi } from 'vitest'
77
/**
88
* The handler map is a wiring table from tool id to implementation. Only its
99
* shape is asserted here, so every implementation module it imports is stubbed
10-
* — loading them for real reaches the block registry, the executor, and most
11-
* of `lib/`. Every export resolves to a mock function, which is all the table
12-
* needs to bind.
10+
* except `workflow/mutations`, which holds the cancellation handler under test
11+
* and loads for real so a renamed or removed export fails at link time.
12+
* Loading the rest reaches the block registry, the executor, and most of
13+
* `lib/`; every stubbed export resolves to a mock function, which is all the
14+
* table needs to bind.
1315
*/
1416
const { stubHandlerModule } = vi.hoisted(() => ({
1517
stubHandlerModule: () =>
@@ -40,19 +42,20 @@ vi.mock('@/lib/copilot/tools/handlers/restore-resource', stubHandlerModule)
4042
vi.mock('@/lib/copilot/tools/handlers/run-code', stubHandlerModule)
4143
vi.mock('@/lib/copilot/tools/handlers/vfs', stubHandlerModule)
4244
vi.mock('@/lib/copilot/tools/handlers/vfs-mutate', stubHandlerModule)
43-
vi.mock('@/lib/copilot/tools/handlers/workflow/mutations', stubHandlerModule)
4445
vi.mock('@/lib/copilot/tools/handlers/workflow/queries', stubHandlerModule)
4546

4647
/** Server-router tools are appended to the map from their own registry, which this test does not cover. */
4748
vi.mock('@/lib/copilot/tools/server/router', () => ({ getRegisteredServerToolNames: () => [] }))
4849

4950
import { hasHandler } from '@/lib/copilot/tool-executor/executor'
51+
import { buildHandlerMap } from '@/lib/copilot/tool-executor/handler-map'
5052
import { ensureHandlersRegistered } from '@/lib/copilot/tool-executor/register-handlers'
5153
import {
5254
getToolEntry,
5355
isSimExecuted,
5456
toolRequiresApproval,
5557
} from '@/lib/copilot/tool-executor/router'
58+
import { executeCancelWorkflowRun } from '@/lib/copilot/tools/handlers/workflow/mutations'
5659

5760
describe('workflow-run cancellation tool routing', () => {
5861
it('routes cancellation through Sim with write permission and explicit approval', () => {
@@ -68,5 +71,7 @@ describe('workflow-run cancellation tool routing', () => {
6871
await ensureHandlersRegistered()
6972

7073
expect(hasHandler('cancel_workflow_run')).toBe(true)
74+
expect(executeCancelWorkflowRun).toBeTypeOf('function')
75+
expect(buildHandlerMap().cancel_workflow_run).toBe(executeCancelWorkflowRun)
7176
})
7277
})

0 commit comments

Comments
 (0)