Skip to content

Commit f431355

Browse files
icecrasher321claude
andcommitted
test(copilot): type the run-tool execution mocks with the real options contract
Greptile flagged the new mock's `options: any`; the sibling abort test had the same shape. Export WorkflowExecutionOptions from the shared executor and use it in both, with a helper that fails the test if the run tool ever stops passing an abort signal. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent d1b017c commit f431355

2 files changed

Lines changed: 31 additions & 20 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-execution-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ export function handleExecutionCancelledConsole(
947947
addCancelledConsoleEntry(deps.addConsole, params)
948948
}
949949

950-
interface WorkflowExecutionOptions {
950+
export interface WorkflowExecutionOptions {
951951
workflowId?: string
952952
workflowInput?: any
953953
onStream?: (se: StreamingExecution) => Promise<void>

apps/sim/lib/copilot/tools/client/run-tool-execution.test.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import { beforeEach, describe, expect, it, vi } from 'vitest'
6+
import type { WorkflowExecutionOptions } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-execution-utils'
67

78
const {
89
clearExecutionPointer,
@@ -66,6 +67,12 @@ vi.mock('@/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-execution-u
6667
executeWorkflowWithFullLogging,
6768
}))
6869

70+
/** The abort signal the run tool wires into every client-side execution. */
71+
function requireAbortSignal(options: WorkflowExecutionOptions): AbortSignal {
72+
if (!options.abortSignal) throw new Error('run tool did not pass an abort signal')
73+
return options.abortSignal
74+
}
75+
6976
vi.mock('@/stores/execution/store', () => ({
7077
useExecutionStore: {
7178
getState: () => ({
@@ -132,16 +139,18 @@ describe('run tool execution cancellation', () => {
132139

133140
it('passes an abort signal into executeWorkflowWithFullLogging and aborts it', async () => {
134141
let capturedSignal: AbortSignal | undefined
135-
executeWorkflowWithFullLogging.mockImplementationOnce(async (options: any) => {
136-
capturedSignal = options.abortSignal
137-
await new Promise((_, reject) => {
138-
options.abortSignal.addEventListener(
139-
'abort',
140-
() => reject(new DOMException('Aborted', 'AbortError')),
141-
{ once: true }
142-
)
143-
})
144-
})
142+
executeWorkflowWithFullLogging.mockImplementationOnce(
143+
async (options: WorkflowExecutionOptions) => {
144+
capturedSignal = requireAbortSignal(options)
145+
await new Promise((_, reject) => {
146+
capturedSignal?.addEventListener(
147+
'abort',
148+
() => reject(new DOMException('Aborted', 'AbortError')),
149+
{ once: true }
150+
)
151+
})
152+
}
153+
)
145154

146155
executeRunToolOnClient('tool-1', 'run_workflow', { workflowId: 'wf-1' })
147156
await Promise.resolve()
@@ -153,15 +162,17 @@ describe('run tool execution cancellation', () => {
153162
})
154163

155164
it('owns the workflow for exactly as long as the client run is in flight', async () => {
156-
executeWorkflowWithFullLogging.mockImplementationOnce(async (options: any) => {
157-
await new Promise((_, reject) => {
158-
options.abortSignal.addEventListener(
159-
'abort',
160-
() => reject(new DOMException('Aborted', 'AbortError')),
161-
{ once: true }
162-
)
163-
})
164-
})
165+
executeWorkflowWithFullLogging.mockImplementationOnce(
166+
async (options: WorkflowExecutionOptions) => {
167+
await new Promise((_, reject) => {
168+
requireAbortSignal(options).addEventListener(
169+
'abort',
170+
() => reject(new DOMException('Aborted', 'AbortError')),
171+
{ once: true }
172+
)
173+
})
174+
}
175+
)
165176
let ownedWhenPointerSaved: boolean | undefined
166177
saveExecutionPointer.mockImplementationOnce(() => {
167178
ownedWhenPointerSaved = isRunToolActiveForWorkflow('wf-1')

0 commit comments

Comments
 (0)