11import { randomUUID } from 'crypto' ;
22import type { ExecutionContext } from 'ava' ;
3- import { Client , WithStartWorkflowOperation } from '@temporalio/client' ;
3+ import { Client , WithStartWorkflowOperation , WorkflowFailedError } from '@temporalio/client' ;
44import { workflowInterceptorModules } from '@temporalio/testing' ;
55import { bundleWorkflowCode } from '@temporalio/worker' ;
66import type { TestWorkflowEnvironment } from './helpers' ;
@@ -12,9 +12,13 @@ import {
1212 makeConfigurableEnvironmentTestFn ,
1313} from './helpers-integration' ;
1414import {
15+ parentWorkflowChildDefinition ,
16+ parentWorkflowChildDefinitionInvalidCallSiteTypeInfo ,
17+ continueAsNewToWorkflowWithTypeInfo ,
1518 finishSignal ,
1619 finishUpdate ,
1720 Order ,
21+ parentWorkflowChildString ,
1822 Receipt ,
1923 workflowTypeInfo ,
2024 workflowWithSignalStart ,
@@ -158,6 +162,38 @@ test('detached workflow handle uses call-site output type information', async (t
158162 } ) ;
159163} ) ;
160164
165+ test ( 'same-type continue-as-new reuses definition-supplied input and output type information' , async ( t ) => {
166+ const h = configurableHelpers ( t , t . context . workflowBundle , t . context . env ) ;
167+ const client = makeClient ( t . context . env ) ;
168+ const worker = await h . createWorker ( { dataConverter } ) ;
169+
170+ await worker . runUntil ( async ( ) => {
171+ const result = await client . workflow . execute ( workflowWithTypeInfo , {
172+ workflowId : `wf-${ randomUUID ( ) } ` ,
173+ taskQueue : h . taskQueue ,
174+ args : [ new Order ( 'order-1' , 12345n , 1 ) ] ,
175+ } ) ;
176+
177+ assertReceipt ( t , result ) ;
178+ } ) ;
179+ } ) ;
180+
181+ test ( 'continue-as-new to a different workflow uses explicit input type information' , async ( t ) => {
182+ const h = configurableHelpers ( t , t . context . workflowBundle , t . context . env ) ;
183+ const client = makeClient ( t . context . env ) ;
184+ const worker = await h . createWorker ( { dataConverter } ) ;
185+
186+ await worker . runUntil ( async ( ) => {
187+ const result = await client . workflow . execute ( continueAsNewToWorkflowWithTypeInfo , {
188+ workflowId : `wf-${ randomUUID ( ) } ` ,
189+ taskQueue : h . taskQueue ,
190+ args : [ new Order ( 'order-1' , 12345n ) ] ,
191+ } ) ;
192+
193+ assertReceipt ( t , result ) ;
194+ } ) ;
195+ } ) ;
196+
161197test ( 'signal-with-start carries definition-supplied workflow type information' , async ( t ) => {
162198 const h = configurableHelpers ( t , t . context . workflowBundle , t . context . env ) ;
163199 const client = makeClient ( t . context . env ) ;
@@ -195,3 +231,54 @@ test('update-with-start carries definition-supplied workflow type information',
195231 assertReceipt ( t , await ( await startOperation . workflowHandle ( ) ) . result ( ) ) ;
196232 } ) ;
197233} ) ;
234+
235+ test ( 'child workflow uses definition-supplied input and output type information' , async ( t ) => {
236+ const h = configurableHelpers ( t , t . context . workflowBundle , t . context . env ) ;
237+ const client = makeClient ( t . context . env ) ;
238+ const worker = await h . createWorker ( { dataConverter } ) ;
239+
240+ await worker . runUntil ( async ( ) => {
241+ const result = await client . workflow . execute ( parentWorkflowChildDefinition , {
242+ workflowId : `wf-${ randomUUID ( ) } ` ,
243+ taskQueue : h . taskQueue ,
244+ args : [ new Order ( 'order-1' , 12345n ) ] ,
245+ } ) ;
246+
247+ assertReceipt ( t , result ) ;
248+ } ) ;
249+ } ) ;
250+
251+ test ( 'child workflow uses call-site input and output type information for string workflow type' , async ( t ) => {
252+ const h = configurableHelpers ( t , t . context . workflowBundle , t . context . env ) ;
253+ const client = makeClient ( t . context . env ) ;
254+ const worker = await h . createWorker ( { dataConverter } ) ;
255+
256+ await worker . runUntil ( async ( ) => {
257+ const result = await client . workflow . execute ( parentWorkflowChildString , {
258+ workflowId : `wf-${ randomUUID ( ) } ` ,
259+ taskQueue : h . taskQueue ,
260+ args : [ new Order ( 'order-1' , 12345n ) ] ,
261+ } ) ;
262+
263+ assertReceipt ( t , result ) ;
264+ } ) ;
265+ } ) ;
266+
267+ test ( 'child workflow definition with call-site type information is invalid' , async ( t ) => {
268+ const h = configurableHelpers ( t , t . context . workflowBundle , t . context . env ) ;
269+ const client = makeClient ( t . context . env ) ;
270+ const worker = await h . createWorker ( { dataConverter } ) ;
271+
272+ await worker . runUntil ( async ( ) => {
273+ const err = await t . throwsAsync (
274+ client . workflow . execute ( parentWorkflowChildDefinitionInvalidCallSiteTypeInfo , {
275+ workflowId : `wf-${ randomUUID ( ) } ` ,
276+ taskQueue : h . taskQueue ,
277+ args : [ new Order ( 'order-1' , 12345n ) ] ,
278+ } ) ,
279+ { instanceOf : WorkflowFailedError }
280+ ) ;
281+
282+ t . regex ( err ?. cause ?. message ?? '' , / W o r k f l o w t y p e i n f o r m a t i o n c a n n o t b e s u p p l i e d a t t h e c a l l s i t e / ) ;
283+ } ) ;
284+ } ) ;
0 commit comments