@@ -4,6 +4,7 @@ import vm from 'node:vm';
4
4
import anyTest , { ExecutionContext , TestFn } from 'ava' ;
5
5
import dedent from 'dedent' ;
6
6
import Long from 'long' ; // eslint-disable-line import/no-named-as-default
7
+ import escapeStringRexep from 'escape-string-regexp' ;
7
8
import {
8
9
ApplicationFailure ,
9
10
defaultFailureConverter ,
@@ -172,6 +173,14 @@ function compareCompletion(
172
173
) ;
173
174
}
174
175
176
+ // Compare stack traces while handling $CLASS keyword to match any identifier that isn't consistent across Node versions.
177
+ // As of Node 24.6.0 type names are now present on source mapped stack traces
178
+ // See [f33e0fcc83954f728fcfd2ef6ae59435bc4af059](https://github.com/nodejs/node/commit/f33e0fcc83954f728fcfd2ef6ae59435bc4af059)
179
+ function compareFailureStackTrace ( t : ExecutionContext < Context > , actual : string , expected : string ) {
180
+ const escapedTrace = escapeStringRexep ( expected ) . replaceAll ( '\\$CLASS' , '(?:[A-Za-z]+)' ) ;
181
+ t . regex ( actual , RegExp ( `^${ escapedTrace } $` ) ) ;
182
+ }
183
+
175
184
function makeSuccess (
176
185
commands : coresdk . workflow_commands . IWorkflowCommand [ ] = [ makeCompleteWorkflowExecution ( ) ] ,
177
186
usedInternalFlags : SdkFlag [ ] = [ ]
@@ -307,13 +316,12 @@ function makeCompleteWorkflowExecution(result?: Payload): coresdk.workflow_comma
307
316
308
317
function makeFailWorkflowExecution (
309
318
message : string ,
310
- stackTrace : string ,
311
319
type = 'Error' ,
312
320
nonRetryable = true
313
321
) : coresdk . workflow_commands . IWorkflowCommand {
314
322
return {
315
323
failWorkflowExecution : {
316
- failure : { message, stackTrace , applicationFailureInfo : { type, nonRetryable } , source : 'TypeScriptSDK' } ,
324
+ failure : { message, applicationFailureInfo : { type, nonRetryable } , source : 'TypeScriptSDK' } ,
317
325
} ,
318
326
} ;
319
327
}
@@ -453,22 +461,28 @@ function cleanWorkflowQueryFailureStackTrace(
453
461
return req ;
454
462
}
455
463
464
+ function removeWorkflowFailureStackTrace (
465
+ req : coresdk . workflow_completion . IWorkflowActivationCompletion ,
466
+ commandIndex = 0
467
+ ) {
468
+ const stackTrace = req . successful ! . commands ! [ commandIndex ] . failWorkflowExecution ! . failure ! . stackTrace ! ;
469
+ delete req . successful ! . commands ! [ commandIndex ] . failWorkflowExecution ! . failure ! . stackTrace ;
470
+ return stackTrace ;
471
+ }
472
+
456
473
test ( 'throwAsync' , async ( t ) => {
457
474
const { workflowType } = t . context ;
458
475
const req = cleanWorkflowFailureStackTrace ( await activate ( t , makeStartWorkflow ( workflowType ) ) ) ;
459
- compareCompletion (
476
+ const actualStackTrace = removeWorkflowFailureStackTrace ( req ) ;
477
+ compareCompletion ( t , req , makeSuccess ( [ makeFailWorkflowExecution ( 'failure' ) ] ) ) ;
478
+ compareFailureStackTrace (
460
479
t ,
461
- req ,
462
- makeSuccess ( [
463
- makeFailWorkflowExecution (
464
- 'failure' ,
465
- dedent `
480
+ actualStackTrace ,
481
+ dedent `
466
482
ApplicationFailure: failure
467
- at Function .nonRetryable (common/src/failure.ts)
483
+ at $CLASS .nonRetryable (common/src/failure.ts)
468
484
at throwAsync (test/src/workflows/throw-async.ts)
469
485
`
470
- ) ,
471
- ] )
472
486
) ;
473
487
} ) ;
474
488
@@ -768,27 +782,26 @@ test('interruptableWorkflow', async (t) => {
768
782
const req = cleanWorkflowFailureStackTrace (
769
783
await activate ( t , await makeSignalWorkflow ( 'interrupt' , [ 'just because' ] ) )
770
784
) ;
785
+ const stackTrace = removeWorkflowFailureStackTrace ( req ) ;
771
786
compareCompletion (
772
787
t ,
773
788
req ,
774
789
makeSuccess (
775
- [
776
- makeFailWorkflowExecution (
777
- 'just because' ,
778
- // The stack trace is weird here and might confuse users, it might be a JS limitation
779
- // since the Error stack trace is generated in the constructor.
780
- dedent `
781
- ApplicationFailure: just because
782
- at Function.retryable (common/src/failure.ts)
783
- at test/src/workflows/interrupt-signal.ts
784
- ` ,
785
- 'Error' ,
786
- false
787
- ) ,
788
- ] ,
790
+ [ makeFailWorkflowExecution ( 'just because' , 'Error' , false ) ] ,
789
791
[ SdkFlags . ProcessWorkflowActivationJobsAsSingleBatch ]
790
792
)
791
793
) ;
794
+ compareFailureStackTrace (
795
+ t ,
796
+ stackTrace ,
797
+ // The stack trace is weird here and might confuse users, it might be a JS limitation
798
+ // since the Error stack trace is generated in the constructor.
799
+ dedent `
800
+ ApplicationFailure: just because
801
+ at $CLASS.retryable (common/src/failure.ts)
802
+ at test/src/workflows/interrupt-signal.ts
803
+ `
804
+ ) ;
792
805
}
793
806
} ) ;
794
807
@@ -800,24 +813,24 @@ test('failSignalWorkflow', async (t) => {
800
813
}
801
814
{
802
815
const req = cleanWorkflowFailureStackTrace ( await activate ( t , await makeSignalWorkflow ( 'fail' , [ ] ) ) ) ;
816
+ const stackTrace = removeWorkflowFailureStackTrace ( req ) ;
803
817
compareCompletion (
804
818
t ,
805
819
req ,
806
820
makeSuccess (
807
- [
808
- makeFailWorkflowExecution (
809
- 'Signal failed' ,
810
- dedent `
811
- ApplicationFailure: Signal failed
812
- at Function.nonRetryable (common/src/failure.ts)
813
- at test/src/workflows/fail-signal.ts
814
- ` ,
815
- 'Error'
816
- ) ,
817
- ] ,
821
+ [ makeFailWorkflowExecution ( 'Signal failed' , 'Error' ) ] ,
818
822
[ SdkFlags . ProcessWorkflowActivationJobsAsSingleBatch ]
819
823
)
820
824
) ;
825
+ compareFailureStackTrace (
826
+ t ,
827
+ stackTrace ,
828
+ dedent `
829
+ ApplicationFailure: Signal failed
830
+ at $CLASS.nonRetryable (common/src/failure.ts)
831
+ at test/src/workflows/fail-signal.ts
832
+ `
833
+ ) ;
821
834
}
822
835
} ) ;
823
836
@@ -840,23 +853,23 @@ test('asyncFailSignalWorkflow', async (t) => {
840
853
}
841
854
{
842
855
const req = cleanWorkflowFailureStackTrace ( await activate ( t , makeFireTimer ( 2 ) ) ) ;
856
+ const stackTrace = removeWorkflowFailureStackTrace ( req ) ;
843
857
compareCompletion (
844
858
t ,
845
859
req ,
846
860
makeSuccess (
847
- [
848
- makeFailWorkflowExecution (
849
- 'Signal failed' ,
850
- dedent `
851
- ApplicationFailure: Signal failed
852
- at Function.nonRetryable (common/src/failure.ts)
853
- at test/src/workflows/async-fail-signal.ts` ,
854
- 'Error'
855
- ) ,
856
- ] ,
861
+ [ makeFailWorkflowExecution ( 'Signal failed' , 'Error' ) ] ,
857
862
[ SdkFlags . ProcessWorkflowActivationJobsAsSingleBatch ]
858
863
)
859
864
) ;
865
+ compareFailureStackTrace (
866
+ t ,
867
+ stackTrace ,
868
+ dedent `
869
+ ApplicationFailure: Signal failed
870
+ at $CLASS.nonRetryable (common/src/failure.ts)
871
+ at test/src/workflows/async-fail-signal.ts`
872
+ ) ;
860
873
}
861
874
} ) ;
862
875
@@ -1445,6 +1458,7 @@ test('nonCancellableInNonCancellable', async (t) => {
1445
1458
test ( 'cancellationErrorIsPropagated' , async ( t ) => {
1446
1459
const { workflowType, logs } = t . context ;
1447
1460
const req = cleanWorkflowFailureStackTrace ( await activate ( t , makeStartWorkflow ( workflowType ) ) , 2 ) ;
1461
+ const stackTrace = removeWorkflowFailureStackTrace ( req , 2 ) ;
1448
1462
compareCompletion (
1449
1463
t ,
1450
1464
req ,
@@ -1455,22 +1469,26 @@ test('cancellationErrorIsPropagated', async (t) => {
1455
1469
failWorkflowExecution : {
1456
1470
failure : {
1457
1471
message : 'Cancellation scope cancelled' ,
1458
- stackTrace : dedent `
1459
- CancelledFailure: Cancellation scope cancelled
1460
- at CancellationScope.cancel (workflow/src/cancellation-scope.ts)
1461
- at test/src/workflows/cancellation-error-is-propagated.ts
1462
- at CancellationScope.runInContext (workflow/src/cancellation-scope.ts)
1463
- at CancellationScope.run (workflow/src/cancellation-scope.ts)
1464
- at Function.cancellable (workflow/src/cancellation-scope.ts)
1465
- at cancellationErrorIsPropagated (test/src/workflows/cancellation-error-is-propagated.ts)
1466
- ` ,
1467
1472
canceledFailureInfo : { } ,
1468
1473
source : 'TypeScriptSDK' ,
1469
1474
} ,
1470
1475
} ,
1471
1476
} ,
1472
1477
] )
1473
1478
) ;
1479
+ compareFailureStackTrace (
1480
+ t ,
1481
+ stackTrace ,
1482
+ dedent `
1483
+ CancelledFailure: Cancellation scope cancelled
1484
+ at CancellationScope.cancel (workflow/src/cancellation-scope.ts)
1485
+ at test/src/workflows/cancellation-error-is-propagated.ts
1486
+ at CancellationScope.runInContext (workflow/src/cancellation-scope.ts)
1487
+ at CancellationScope.run (workflow/src/cancellation-scope.ts)
1488
+ at $CLASS.cancellable (workflow/src/cancellation-scope.ts)
1489
+ at cancellationErrorIsPropagated (test/src/workflows/cancellation-error-is-propagated.ts)
1490
+ `
1491
+ ) ;
1474
1492
t . deepEqual ( logs , [ ] ) ;
1475
1493
} ) ;
1476
1494
@@ -1655,13 +1673,9 @@ test('resolve activity with failure - http', async (t) => {
1655
1673
} ,
1656
1674
} )
1657
1675
) ;
1658
- compareCompletion (
1659
- t ,
1660
- completion ,
1661
- makeSuccess ( [
1662
- makeFailWorkflowExecution ( 'Connection timeout' , 'ApplicationFailure: Connection timeout' , 'MockError' ) ,
1663
- ] )
1664
- ) ;
1676
+ const stackTrace = removeWorkflowFailureStackTrace ( completion ) ;
1677
+ compareCompletion ( t , completion , makeSuccess ( [ makeFailWorkflowExecution ( 'Connection timeout' , 'MockError' ) ] ) ) ;
1678
+ compareFailureStackTrace ( t , stackTrace , 'ApplicationFailure: Connection timeout' ) ;
1665
1679
}
1666
1680
} ) ;
1667
1681
@@ -1872,19 +1886,16 @@ test('tryToContinueAfterCompletion', async (t) => {
1872
1886
const { workflowType } = t . context ;
1873
1887
{
1874
1888
const completion = cleanWorkflowFailureStackTrace ( await activate ( t , makeStartWorkflow ( workflowType ) ) ) ;
1875
- compareCompletion (
1889
+ const stackTrace = removeWorkflowFailureStackTrace ( completion ) ;
1890
+ compareCompletion ( t , completion , makeSuccess ( [ makeFailWorkflowExecution ( 'fail before continue' ) ] ) ) ;
1891
+ compareFailureStackTrace (
1876
1892
t ,
1877
- completion ,
1878
- makeSuccess ( [
1879
- makeFailWorkflowExecution (
1880
- 'fail before continue' ,
1881
- dedent `
1893
+ stackTrace ,
1894
+ dedent `
1882
1895
ApplicationFailure: fail before continue
1883
- at Function .nonRetryable (common/src/failure.ts)
1896
+ at $CLASS .nonRetryable (common/src/failure.ts)
1884
1897
at tryToContinueAfterCompletion (test/src/workflows/try-to-continue-after-completion.ts)
1885
1898
`
1886
- ) ,
1887
- ] )
1888
1899
) ;
1889
1900
}
1890
1901
} ) ;
0 commit comments