@@ -5,6 +5,7 @@ import { describe, expect, it } from 'vitest';
55
66import {
77 getUpdatedNodeExecutionStateOnInvocationComplete ,
8+ getUpdatedNodeExecutionStateOnInvocationError ,
89 getUpdatedNodeExecutionStateOnInvocationProgress ,
910 getUpdatedNodeExecutionStateOnInvocationStarted ,
1011} from './nodeExecutionState' ;
@@ -87,6 +88,26 @@ const buildInvocationCompleteEvent = (
8788 ...overrides ,
8889 } ) as S [ 'InvocationCompleteEvent' ] ;
8990
91+ const buildInvocationErrorEvent = ( overrides : Partial < S [ 'InvocationErrorEvent' ] > = { } ) : S [ 'InvocationErrorEvent' ] =>
92+ ( {
93+ queue_id : 'default' ,
94+ item_id : 1 ,
95+ batch_id : 'batch-1' ,
96+ origin : 'workflows' ,
97+ destination : 'gallery' ,
98+ user_id : 'user-1' ,
99+ session_id : 'session-1' ,
100+ invocation_source_id : 'node-1' ,
101+ invocation : {
102+ id : 'prepared-node-1' ,
103+ type : 'add' ,
104+ } ,
105+ error_type : 'TestError' ,
106+ error_message : 'boom' ,
107+ error_traceback : 'traceback' ,
108+ ...overrides ,
109+ } ) as S [ 'InvocationErrorEvent' ] ;
110+
90111describe ( getUpdatedNodeExecutionStateOnInvocationStarted . name , ( ) => {
91112 it ( 'creates an execution state when started arrives before initialization' , ( ) => {
92113 const event = buildInvocationStartedEvent ( ) ;
@@ -219,3 +240,41 @@ describe(getUpdatedNodeExecutionStateOnInvocationComplete.name, () => {
219240 expect ( secondUpdate ?. outputs ) . toEqual ( [ firstEvent . result , secondEvent . result ] ) ;
220241 } ) ;
221242} ) ;
243+
244+ describe ( getUpdatedNodeExecutionStateOnInvocationError . name , ( ) => {
245+ it ( 'creates an execution state when error arrives before initialization' , ( ) => {
246+ const event = buildInvocationErrorEvent ( ) ;
247+ const updated = getUpdatedNodeExecutionStateOnInvocationError ( undefined , event ) ;
248+
249+ expect ( updated ?. nodeId ) . toBe ( event . invocation_source_id ) ;
250+ expect ( updated ?. status ) . toBe ( zNodeStatus . enum . FAILED ) ;
251+ expect ( updated ?. progress ) . toBeNull ( ) ;
252+ expect ( updated ?. progressImage ) . toBeNull ( ) ;
253+ expect ( updated ?. error ) . toEqual ( {
254+ error_type : event . error_type ,
255+ error_message : event . error_message ,
256+ error_traceback : event . error_traceback ,
257+ } ) ;
258+ } ) ;
259+
260+ it ( 'marks the node failed and records the error' , ( ) => {
261+ const event = buildInvocationErrorEvent ( ) ;
262+ const updated = getUpdatedNodeExecutionStateOnInvocationError (
263+ buildNodeExecutionState ( {
264+ status : zNodeStatus . enum . IN_PROGRESS ,
265+ progress : 0.5 ,
266+ progressImage : { dataURL : 'data:image/png;base64,abc' , width : 64 , height : 64 } ,
267+ } ) ,
268+ event
269+ ) ;
270+
271+ expect ( updated ?. status ) . toBe ( zNodeStatus . enum . FAILED ) ;
272+ expect ( updated ?. progress ) . toBeNull ( ) ;
273+ expect ( updated ?. progressImage ) . toBeNull ( ) ;
274+ expect ( updated ?. error ) . toEqual ( {
275+ error_type : event . error_type ,
276+ error_message : event . error_message ,
277+ error_traceback : event . error_traceback ,
278+ } ) ;
279+ } ) ;
280+ } ) ;
0 commit comments