@@ -115,9 +115,11 @@ describe("execution-manager", () => {
115115 it ( "should create a new execution with the provided parameters" , ( ) => {
116116 // Test data
117117 const executionId = createExecutionId ( "test-execution-id" ) ;
118+ const invocationId = createInvocationId ( "test-invocation-id" ) ;
118119 const params : StartExecutionParams = {
119120 executionId,
120121 payload : '{"key":"value"}' ,
122+ invocationId,
121123 } ;
122124
123125 // Expected mock operation with properly typed id
@@ -144,9 +146,9 @@ describe("execution-manager", () => {
144146
145147 // Verify results
146148 expect ( result ) . toEqual ( {
147- checkpointToken : `encoded-{"executionId":"test-execution-id ","token":"mocked-uuid","invocationId":"mocked-uuid "}` ,
149+ checkpointToken : `encoded-{"executionId":"${ executionId } ","token":"mocked-uuid","invocationId":"${ invocationId } "}` ,
148150 executionId,
149- invocationId : "mocked-uuid" ,
151+ invocationId,
150152 operationEvents : [
151153 {
152154 operation : mockInitialOperation ,
@@ -167,6 +169,7 @@ describe("execution-manager", () => {
167169 const executionId = createExecutionId ( "test-execution-id" ) ;
168170 const params : StartExecutionParams = {
169171 executionId,
172+ invocationId : createInvocationId ( "test-invocation-id" ) ,
170173 } ;
171174
172175 const initializeSpy = jest . spyOn (
@@ -185,38 +188,48 @@ describe("execution-manager", () => {
185188 it ( "should throw error if execution ID doesn't exist" , ( ) => {
186189 const nonExistentId = createExecutionId ( "non-existent" ) ;
187190
188- expect ( ( ) => executionManager . startInvocation ( nonExistentId ) ) . toThrow (
191+ expect ( ( ) =>
192+ executionManager . startInvocation ( {
193+ executionId : nonExistentId ,
194+ invocationId : createInvocationId ( "test-invocation-id" ) ,
195+ } ) ,
196+ ) . toThrow (
189197 "Could not start invocation for invalid execution non-existent" ,
190198 ) ;
191199 } ) ;
192200
193201 it ( "should start a new invocation for an existing execution" , ( ) => {
194202 // First create an execution
195203 const executionId = createExecutionId ( "test-execution-id" ) ;
196- executionManager . startExecution ( { executionId } ) ;
204+ const invocationId = createInvocationId ( "test-invocation-id" ) ;
205+ executionManager . startExecution ( { executionId, invocationId } ) ;
197206
198207 // Reset mocks to track new calls
199208 jest . clearAllMocks ( ) ;
200- ( randomUUID as jest . Mock ) . mockReturnValue ( "new-invocation-uuid" ) ;
201209
210+ const newInvocationId = createInvocationId ( "new-invocation-id" ) ;
202211 // Start a new invocation
203- const result = executionManager . startInvocation ( executionId ) ;
212+ const result = executionManager . startInvocation ( {
213+ executionId,
214+ invocationId : newInvocationId ,
215+ } ) ;
204216
205217 expect ( result ) . toBeDefined ( ) ;
206218 expect ( result . executionId ) . toBe ( executionId ) ;
207- expect ( result . invocationId ) . toBe ( "new-invocation-uuid" ) ;
219+ expect ( result . invocationId ) . toBe ( newInvocationId ) ;
208220 expect ( result . operationEvents ) . toBeInstanceOf ( Array ) ;
209221 expect ( encodeCheckpointToken ) . toHaveBeenCalledWith ( {
210222 executionId,
211- token : "new-invocation-uuid" ,
212- invocationId : "new-invocation-uuid" ,
223+ token : expect . any ( String ) ,
224+ invocationId : newInvocationId ,
213225 } ) ;
214226 } ) ;
215227
216228 it ( "should include all operations from the checkpoint storage" , ( ) => {
217229 // Create an execution with a mock operation
218230 const executionId = createExecutionId ( "test-execution-id" ) ;
219- executionManager . startExecution ( { executionId } ) ;
231+ const invocationId = createInvocationId ( "test-invocation-id" ) ;
232+ executionManager . startExecution ( { executionId, invocationId } ) ;
220233
221234 // Get the storage and add some operations to it
222235 const storage = executionManager . getCheckpointsByExecution ( executionId ) ;
@@ -247,7 +260,11 @@ describe("execution-manager", () => {
247260 } ) ;
248261
249262 // Start a new invocation
250- const result = executionManager . startInvocation ( executionId ) ;
263+ const newInvocationId = createInvocationId ( "new-invocation-id" ) ;
264+ const result = executionManager . startInvocation ( {
265+ executionId,
266+ invocationId : newInvocationId ,
267+ } ) ;
251268
252269 // Check that we got all operations
253270 expect ( result . operationEvents ) . toHaveLength ( 2 ) ;
@@ -264,13 +281,20 @@ describe("execution-manager", () => {
264281 it ( "should throw error if execution is completed already" , ( ) => {
265282 // First create an execution
266283 const executionId = createExecutionId ( "test-execution-id" ) ;
267- executionManager . startExecution ( { executionId } ) ;
284+ const invocationId = createInvocationId ( "test-invocation-id" ) ;
285+ executionManager . startExecution ( { executionId, invocationId } ) ;
268286
269287 jest
270288 . spyOn ( CheckpointManager . prototype , "isExecutionCompleted" )
271289 . mockReturnValue ( true ) ;
272290
273- expect ( ( ) => executionManager . startInvocation ( executionId ) ) . toThrow (
291+ const newInvocationId = createInvocationId ( "new-invocation-id" ) ;
292+ expect ( ( ) =>
293+ executionManager . startInvocation ( {
294+ executionId,
295+ invocationId : newInvocationId ,
296+ } ) ,
297+ ) . toThrow (
274298 `Could not start invocation for completed execution ${ executionId } ` ,
275299 ) ;
276300 } ) ;
@@ -286,7 +310,8 @@ describe("execution-manager", () => {
286310
287311 it ( "should return the checkpoint storage for an existing execution ID" , ( ) => {
288312 const executionId = createExecutionId ( "test-execution-id" ) ;
289- executionManager . startExecution ( { executionId } ) ;
313+ const invocationId = createInvocationId ( "test-invocation-id" ) ;
314+ executionManager . startExecution ( { executionId, invocationId } ) ;
290315
291316 const storage = executionManager . getCheckpointsByExecution ( executionId ) ;
292317
@@ -321,7 +346,8 @@ describe("execution-manager", () => {
321346 it ( "should return storage and token data for a valid token" , ( ) => {
322347 // Create an execution
323348 const executionId = createExecutionId ( "test-execution-id" ) ;
324- executionManager . startExecution ( { executionId } ) ;
349+ const invocationId = createInvocationId ( "test-invocation-id" ) ;
350+ executionManager . startExecution ( { executionId, invocationId } ) ;
325351
326352 // Create token data that references the execution
327353 const tokenData : CheckpointTokenData = {
@@ -378,7 +404,8 @@ describe("execution-manager", () => {
378404 it ( "should return CheckpointManager for valid callback ID with existing execution" , ( ) => {
379405 // Create an execution first
380406 const executionId = createExecutionId ( "test-execution-id" ) ;
381- executionManager . startExecution ( { executionId } ) ;
407+ const invocationId = createInvocationId ( "test-invocation-id" ) ;
408+ executionManager . startExecution ( { executionId, invocationId } ) ;
382409
383410 const callbackId = createCallbackId ( "valid-callback-id" ) ;
384411
@@ -398,7 +425,8 @@ describe("execution-manager", () => {
398425 it ( "should return the same CheckpointManager instance as getCheckpointsByExecution" , ( ) => {
399426 // Create an execution first
400427 const executionId = createExecutionId ( "test-execution-id" ) ;
401- executionManager . startExecution ( { executionId } ) ;
428+ const invocationId = createInvocationId ( "test-invocation-id" ) ;
429+ executionManager . startExecution ( { executionId, invocationId } ) ;
402430
403431 const callbackId = createCallbackId ( "valid-callback-id" ) ;
404432
@@ -451,7 +479,7 @@ describe("execution-manager", () => {
451479 // Create an execution first
452480 const executionId = createExecutionId ( "test-execution-id" ) ;
453481 const invocationId = createInvocationId ( "test-invocation-id" ) ;
454- executionManager . startExecution ( { executionId } ) ;
482+ executionManager . startExecution ( { executionId, invocationId } ) ;
455483
456484 const storage = executionManager . getCheckpointsByExecution ( executionId ) ;
457485 expect ( storage ) . toBeDefined ( ) ;
@@ -517,7 +545,7 @@ describe("execution-manager", () => {
517545 // Create an execution first
518546 const executionId = createExecutionId ( "test-execution-id" ) ;
519547 const invocationId = createInvocationId ( "test-invocation-id" ) ;
520- executionManager . startExecution ( { executionId } ) ;
548+ executionManager . startExecution ( { executionId, invocationId } ) ;
521549
522550 const storage = executionManager . getCheckpointsByExecution ( executionId ) ;
523551 expect ( storage ) . toBeDefined ( ) ;
@@ -590,7 +618,7 @@ describe("execution-manager", () => {
590618 // Create an execution first
591619 const executionId = createExecutionId ( "test-execution-id" ) ;
592620 const invocationId = createInvocationId ( "test-invocation-id" ) ;
593- executionManager . startExecution ( { executionId } ) ;
621+ executionManager . startExecution ( { executionId, invocationId } ) ;
594622
595623 const storage = executionManager . getCheckpointsByExecution ( executionId ) ;
596624 expect ( storage ) . toBeDefined ( ) ;
0 commit comments