@@ -87,7 +87,9 @@ const {
8787 } ,
8888 mockNodeOutputStore : {
8989 refreshNodeOutputs : vi . fn ( ) ,
90- resetAllOutputsAndPreviews : vi . fn ( )
90+ resetAllOutputsAndPreviews : vi . fn ( ) ,
91+ snapshotOutputs : vi . fn ( ) ,
92+ restoreOutputs : vi . fn ( )
9193 } ,
9294 mockWorkspaceWorkflow : {
9395 activeWorkflow : null as ComfyWorkflow | null ,
@@ -178,7 +180,9 @@ vi.mock('@/stores/nodeOutputStore', () => ({
178180vi . mock ( '@/stores/subgraphNavigationStore' , ( ) => ( {
179181 useSubgraphNavigationStore : vi . fn ( ( ) => ( {
180182 saveCurrentViewport : vi . fn ( ) ,
181- updateHash : vi . fn ( )
183+ updateHash : vi . fn ( ) ,
184+ exportState : vi . fn ( ( ) => [ ] ) ,
185+ restoreState : vi . fn ( )
182186 } ) )
183187} ) )
184188
@@ -1208,20 +1212,6 @@ describe('ComfyApp', () => {
12081212 )
12091213 }
12101214
1211- /** Mirrors `loadApiJson`/`importA1111`: the root graph is populated in
1212- * place and never configured, so it still carries the zero id. */
1213- async function importWorkflow (
1214- workflowService : WorkflowService ,
1215- graph : LGraph ,
1216- workflow : ComfyWorkflow
1217- ) : Promise < ComfyWorkflowJSON > {
1218- workflowService . beforeLoadNewGraph ( )
1219- app . clean ( )
1220- const workflowData = { ...createWorkflowGraphData ( ) , id : graph . id }
1221- await workflowService . afterLoadNewGraph ( workflow , workflowData )
1222- return workflowData
1223- }
1224-
12251215 it ( 'restores the failed run state when returning to a workflow tab' , async ( ) => {
12261216 const workflowService = await useRealWorkflowService ( )
12271217 const graph = new LGraph ( )
@@ -1253,46 +1243,45 @@ describe('ComfyApp', () => {
12531243
12541244 it ( 'gives each imported workflow its own restorable run errors' , async ( ) => {
12551245 const workflowService = await useRealWorkflowService ( )
1246+ const workflowStore = useWorkflowStore ( )
12561247 const graph = new LGraph ( )
12571248 Reflect . set ( app , 'rootGraphInternal' , graph )
12581249 Reflect . set ( singletonApp , 'rootGraphInternal' , graph )
1259-
1260- const importedA = markLoaded (
1261- new ComfyWorkflow ( {
1262- path : 'workflows/api-a.json' ,
1263- modified : 0 ,
1264- size : 0
1265- } )
1250+ singletonApp . canvas = mockCanvas
1251+ Reflect . set ( mockCanvas , 'ds' , { scale : 1 , offset : [ 0 , 0 ] } )
1252+ mockWorkspaceWorkflow . createNewTemporary . mockImplementation (
1253+ workflowStore . createNewTemporary
12661254 )
1267- const importedB = markLoaded (
1268- new ComfyWorkflow ( {
1269- path : 'workflows/api-b.json' ,
1270- modified : 0 ,
1271- size : 0
1272- } )
1255+ mockWorkspaceWorkflow . getWorkflowByPath . mockImplementation (
1256+ workflowStore . getWorkflowByPath
12731257 )
1274-
1275- const firstImport = await importWorkflow (
1276- workflowService ,
1277- graph ,
1278- importedA
1258+ mockWorkspaceWorkflow . isActive . mockImplementation ( workflowStore . isActive )
1259+ mockWorkspaceWorkflow . openWorkflow . mockImplementation (
1260+ async ( workflow ) => {
1261+ const loadedWorkflow = await workflowStore . openWorkflow ( workflow )
1262+ mockWorkspaceWorkflow . activeWorkflow = loadedWorkflow
1263+ return loadedWorkflow
1264+ }
12791265 )
1280- expect ( firstImport . id ) . not . toBe ( zeroUuid )
1281- expect ( firstImport . id ) . toBe ( graph . id )
1266+
1267+ await app . loadApiJson ( { } , 'api-a' )
1268+ const importedA = mockWorkspaceWorkflow . activeWorkflow
1269+ const importedAId = importedA ?. activeState ?. id
1270+ if ( ! importedA || ! importedAId ) {
1271+ throw new Error ( 'Expected the first imported workflow to have an id' )
1272+ }
1273+ expect ( importedAId ) . not . toBe ( zeroUuid )
1274+ expect ( importedAId ) . toBe ( graph . id )
12821275
12831276 const executionErrorStore = useExecutionErrorStore ( )
12841277 executionErrorStore . recordNodeErrors ( failedKSamplerErrors )
12851278
1286- const secondImport = await importWorkflow (
1287- workflowService ,
1288- graph ,
1289- importedB
1290- )
1291- expect ( secondImport . id ) . not . toBe ( firstImport . id )
1279+ await app . loadApiJson ( { } , 'api-b' )
1280+ const importedBId = mockWorkspaceWorkflow . activeWorkflow ?. activeState ?. id
1281+ expect ( importedBId ) . not . toBe ( importedAId )
12921282 expect ( executionErrorStore . lastNodeErrors ) . toBeNull ( )
12931283
1294- // Reopening the first import replays the state it persisted.
1295- await switchToWorkflow ( workflowService , graph , importedA , firstImport . id ! )
1284+ await switchToWorkflow ( workflowService , graph , importedA , importedAId )
12961285
12971286 expect ( executionErrorStore . lastNodeErrors ) . toEqual ( failedKSamplerErrors )
12981287 } )
0 commit comments