@@ -645,4 +645,68 @@ describe("StepExecutor + WorkflowCtx integration", () => {
645645 / C a n n o t c a l l s t e p m e t h o d s i n s i d e a s t e p \. r u n \( \) h a n d l e r / ,
646646 ) ;
647647 } ) ;
648+
649+ it ( "ctx.run() journals deps and replays when they match" , async ( ) => {
650+ const channel = new BaseChannel < StepRequest > ( 0 ) ;
651+ const ctx = createWorkflowCtx ( "wf-20" as any , channel ) ;
652+
653+ const entry = journalEntry ( {
654+ name : "run" ,
655+ functionType : "mutation" ,
656+ handle : "inline" ,
657+ args : { userId : "u1" , count : 3 } ,
658+ runResult : { kind : "success" , returnValue : "done" } ,
659+ } ) ;
660+
661+ const [ result ] = await Promise . all ( [
662+ ctx . run ( async ( ) => "done" , {
663+ deps : { userId : "u1" , count : 3 } ,
664+ } ) ,
665+ replayFromJournal ( channel , [ entry ] ) ,
666+ ] ) ;
667+
668+ expect ( result ) . toBe ( "done" ) ;
669+ } ) ;
670+
671+ it ( "ctx.run() sends deps through the channel as args" , async ( ) => {
672+ const channel = new BaseChannel < StepRequest > ( 0 ) ;
673+ const ctx = createWorkflowCtx ( "wf-21" as any , channel ) ;
674+
675+ const deps = { userId : "u1" , count : 3 } ;
676+
677+ // Read the message from the channel and verify the args match deps.
678+ const inspectMessage = async ( ) => {
679+ const message = await channel . get ( ) ;
680+ expect ( message . target . args ) . toEqual ( deps ) ;
681+ expect ( message . target . kind ) . toBe ( "inline" ) ;
682+ message . resolve ( { kind : "success" , returnValue : "ok" } ) ;
683+ } ;
684+
685+ const [ result ] = await Promise . all ( [
686+ ctx . run ( async ( ) => "ok" , { deps } ) ,
687+ inspectMessage ( ) ,
688+ ] ) ;
689+
690+ expect ( result ) . toBe ( "ok" ) ;
691+ } ) ;
692+
693+ it ( "ctx.run() without deps still journals empty args" , async ( ) => {
694+ const channel = new BaseChannel < StepRequest > ( 0 ) ;
695+ const ctx = createWorkflowCtx ( "wf-22" as any , channel ) ;
696+
697+ const entry = journalEntry ( {
698+ name : "run" ,
699+ functionType : "mutation" ,
700+ handle : "inline" ,
701+ args : { } ,
702+ runResult : { kind : "success" , returnValue : 42 } ,
703+ } ) ;
704+
705+ const [ result ] = await Promise . all ( [
706+ ctx . run ( async ( ) => 42 ) ,
707+ replayFromJournal ( channel , [ entry ] ) ,
708+ ] ) ;
709+
710+ expect ( result ) . toBe ( 42 ) ;
711+ } ) ;
648712} ) ;
0 commit comments