33 */
44
55import { beforeEach , describe , expect , it , vi } from 'vitest'
6+ import type { WorkflowExecutionOptions } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-execution-utils'
67
78const {
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+
6976vi . 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