66import { db } from '@sim/db'
77import {
88 pausedExecutions ,
9+ permissions ,
910 user ,
1011 workflow ,
1112 workflowDeploymentVersion ,
@@ -24,6 +25,7 @@ import {
2425} from '@/lib/billing/core/attribution'
2526import { LoggingSession } from '@/lib/logs/execution/logging-session'
2627import type { WorkflowState } from '@/lib/logs/types'
28+ import { readPausedWorkflowExecution } from '@/lib/workflows/application/read-paused-workflow-execution'
2729import {
2830 getWorkflowExecutionStatus ,
2931 readPausedRunPoints ,
@@ -154,6 +156,13 @@ beforeAll(async () => {
154156 ownerId : ids . owner ,
155157 billedAccountUserId : ids . owner ,
156158 } )
159+ await db . insert ( permissions ) . values ( {
160+ id : generateId ( ) ,
161+ entityType : 'workspace' ,
162+ entityId : ids . workspace ,
163+ userId : ids . owner ,
164+ permissionType : 'admin' ,
165+ } )
157166 await db . insert ( workflow ) . values ( {
158167 id : ids . workflow ,
159168 userId : ids . owner ,
@@ -175,6 +184,7 @@ afterAll(async () => {
175184 await db
176185 . delete ( workflowExecutionSnapshots )
177186 . where ( eq ( workflowExecutionSnapshots . workflowId , ids . workflow ) )
187+ await db . delete ( permissions ) . where ( eq ( permissions . entityId , ids . workspace ) )
178188 await deleteWorkspaceFixture ( db , eq ( workspace . id , ids . workspace ) )
179189 await db . delete ( user ) . where ( eq ( user . id , ids . owner ) )
180190} )
@@ -496,3 +506,65 @@ describe('readPausedRunPoints', () => {
496506 } )
497507 } )
498508} )
509+
510+ describe ( 'resume page reads' , ( ) => {
511+ /** Gives the published snapshot a workflow naming the paused block, as a real run's carries. */
512+ async function nameApprovalBlockInSnapshot ( executionId : string ) {
513+ const [ row ] = await db
514+ . select ( { executionSnapshot : pausedExecutions . executionSnapshot } )
515+ . from ( pausedExecutions )
516+ . where ( eq ( pausedExecutions . executionId , executionId ) )
517+ const seed = row . executionSnapshot as { snapshot : string ; triggerIds : string [ ] }
518+ const snapshot = {
519+ ...JSON . parse ( seed . snapshot ) ,
520+ workflow : { blocks : [ { id : CONTEXT_ID , metadata : { name : 'Approval' } } ] } ,
521+ }
522+ await db
523+ . update ( pausedExecutions )
524+ . set ( { executionSnapshot : { ...seed , snapshot : JSON . stringify ( snapshot ) } } )
525+ . where ( eq ( pausedExecutions . executionId , executionId ) )
526+ }
527+
528+ it ( 'names every parallel branch point from the snapshot and keeps the snapshot out of the pause context' , async ( ) => {
529+ const registry = registryWithResolvedSecret ( )
530+ const executionId = await publishPausedRun ( [
531+ humanBranchPoint ( 0 , registry ) ,
532+ humanBranchPoint ( 1 , registry ) ,
533+ ] )
534+ await nameApprovalBlockInSnapshot ( executionId )
535+
536+ const detail = await readPausedWorkflowExecution . execute ( {
537+ principal : { kind : 'session' , userId : ids . owner , sessionId : generateId ( ) } ,
538+ input : { workflowId : ids . workflow , executionId } ,
539+ } )
540+ const context = await PauseResumeManager . getPauseContextDetail ( {
541+ workflowId : ids . workflow ,
542+ executionId,
543+ contextId : BRANCH_IDS [ 1 ] ,
544+ } )
545+
546+ expect ( detail . pausePoints . map ( ( point ) => point . blockName ) ) . toEqual ( [ 'Approval' , 'Approval' ] )
547+ expect ( context ?. pausePoint . blockName ) . toBe ( 'Approval' )
548+ expect ( context ?. execution . pausePoints . map ( ( point ) => point . blockName ) ) . toEqual ( [
549+ 'Approval' ,
550+ 'Approval' ,
551+ ] )
552+ expect ( JSON . stringify ( context ) ) . not . toContain ( SNAPSHOT_SENTINEL )
553+ } )
554+
555+ it ( 'falls back to no block name when the snapshot cannot be read' , async ( ) => {
556+ const executionId = await publishPausedRun ( [ humanBranchPoint ( 0 , registryWithResolvedSecret ( ) ) ] )
557+ await db
558+ . update ( pausedExecutions )
559+ . set ( { executionSnapshot : { snapshot : '{not json' , triggerIds : [ ] } } )
560+ . where ( eq ( pausedExecutions . executionId , executionId ) )
561+
562+ const context = await PauseResumeManager . getPauseContextDetail ( {
563+ workflowId : ids . workflow ,
564+ executionId,
565+ contextId : BRANCH_IDS [ 0 ] ,
566+ } )
567+
568+ expect ( context ?. pausePoint ) . not . toHaveProperty ( 'blockName' )
569+ } )
570+ } )
0 commit comments