@@ -154,6 +154,11 @@ function graph(includeCustom = false) {
154154 }
155155}
156156
157+ /** Resolves the graph the write is given, running its reader the way the row-locked transaction does. */
158+ async function resolveWrittenState ( state : unknown ) {
159+ return typeof state === 'function' ? state ( { } ) : state
160+ }
161+
157162const add : EditWorkflowOperation = {
158163 operation_type : 'add' ,
159164 block_id : 'new-worker' ,
@@ -171,7 +176,9 @@ describe('custom blocks in authorized workflow authoring', () => {
171176 workflowRecord : context . workflow ,
172177 normalizedData : graph ( true ) ,
173178 } ) )
174- mocks . replace . mockImplementation ( async ( { state } ) => prepareWorkflowStateForPersistence ( state ) )
179+ mocks . replace . mockImplementation ( async ( { state } ) =>
180+ prepareWorkflowStateForPersistence ( await resolveWrittenState ( state ) )
181+ )
175182 } )
176183
177184 it . each ( [ session , copilot ] ) (
@@ -218,7 +225,7 @@ describe('custom blocks in authorized workflow authoring', () => {
218225 expect ( result . lint . fieldIssues ) . toEqual ( [ ] )
219226 expect ( mocks . replace ) . toHaveBeenCalledTimes ( dryRun ? 0 : 1 )
220227 if ( ! dryRun ) {
221- const persisted = mocks . replace . mock . calls [ 0 ] [ 0 ] . state
228+ const { state : persisted } = await mocks . replace . mock . results [ 0 ] . value
222229 expect ( persisted . blocks . worker . subBlocks [ 'input-text' ] ) . toMatchObject ( {
223230 value : 'updated' ,
224231 type : 'short-input' ,
@@ -265,7 +272,7 @@ describe('custom blocks in authorized workflow authoring', () => {
265272 mocks . replace . mockImplementation ( async ( { state, workspaceId } ) => {
266273 const foreignType = workspaceId === 'one' ? other . type : customBlock . type
267274 expect ( getBlock ( foreignType ) ) . toBeUndefined ( )
268- return prepareWorkflowStateForPersistence ( state )
275+ return prepareWorkflowStateForPersistence ( await resolveWrittenState ( state ) )
269276 } )
270277 const results = await Promise . all (
271278 [ customBlock , other ] . map ( ( row , index ) =>
@@ -298,7 +305,7 @@ describe('custom blocks in authorized workflow authoring', () => {
298305 expect ( result . lint . fieldIssues ) . toEqual ( [ ] )
299306 expect ( mocks . replace ) . toHaveBeenCalledTimes ( dryRun ? 0 : 1 )
300307 if ( ! dryRun ) {
301- const persisted = mocks . replace . mock . calls [ 0 ] [ 0 ] . state
308+ const { state : persisted } = await mocks . replace . mock . results [ 0 ] . value
302309 expect ( persisted . blocks . worker . subBlocks [ 'input-text' ] ) . toMatchObject ( {
303310 value : 'hello' ,
304311 type : 'short-input' ,
0 commit comments