@@ -412,6 +412,33 @@ describe("OpenWorkflow", () => {
412412 expect ( workflowRun ?. finishedAt ) . not . toBeNull ( ) ;
413413 } ) ;
414414
415+ test ( "cancels workflow run via client by ID" , async ( ) => {
416+ const backend = await createBackend ( ) ;
417+ const client = new OpenWorkflow ( { backend } ) ;
418+
419+ const workflow = client . defineWorkflow ( { name : "cancel-test" } , noopFn ) ;
420+ const handle = await workflow . run ( { value : 1 } ) ;
421+
422+ await client . cancelWorkflowRun ( handle . workflowRun . id ) ;
423+
424+ const workflowRun = await backend . getWorkflowRun ( {
425+ workflowRunId : handle . workflowRun . id ,
426+ } ) ;
427+ expect ( workflowRun ?. status ) . toBe ( "canceled" ) ;
428+ expect ( workflowRun ?. finishedAt ) . not . toBeNull ( ) ;
429+ } ) ;
430+
431+ test ( "throws when canceling a non-existent workflow run" , async ( ) => {
432+ const backend = await createBackend ( ) ;
433+ const client = new OpenWorkflow ( { backend } ) ;
434+
435+ const nonExistentId = randomUUID ( ) ;
436+
437+ await expect (
438+ client . cancelWorkflowRun ( nonExistentId ) ,
439+ ) . rejects . toThrow ( `Workflow run ${ nonExistentId } does not exist` ) ;
440+ } ) ;
441+
415442 describe ( "defineWorkflowSpec / implementWorkflow API" , ( ) => {
416443 test ( "defineWorkflowSpec returns a spec that can be used to schedule runs" , async ( ) => {
417444 const backend = await createBackend ( ) ;
0 commit comments