@@ -112,6 +112,66 @@ describe('execution state lookup', () => {
112112 } )
113113 } )
114114
115+ it ( 'recovers legacy workflow input from the pre-populated starter block state' , async ( ) => {
116+ const legacyInput = { leadId : 'legacy-lead' }
117+ queueTableRows ( schemaMock . workflowExecutionLogs , [
118+ {
119+ executionId : 'execution-1' ,
120+ workflowId : 'workflow-1' ,
121+ workspaceId : 'workspace-1' ,
122+ executionData : { } ,
123+ } ,
124+ ] )
125+ mockMaterializeExecutionData . mockResolvedValueOnce ( {
126+ executionState : {
127+ blockStates : {
128+ 'executed-block' : {
129+ output : { leadId : 'wrong-lead' } ,
130+ executed : true ,
131+ executionTime : 10 ,
132+ } ,
133+ start : {
134+ output : legacyInput ,
135+ executed : false ,
136+ executionTime : 0 ,
137+ } ,
138+ } ,
139+ } ,
140+ } )
141+
142+ const result = await getExecutionInputForWorkflow ( 'execution-1' , 'workflow-1' )
143+
144+ expect ( result ) . toEqual ( { found : true , input : legacyInput } )
145+ } )
146+
147+ it ( 'prefers persisted workflow input over the legacy starter block state' , async ( ) => {
148+ const workflowInput = { leadId : 'current-lead' }
149+ queueTableRows ( schemaMock . workflowExecutionLogs , [
150+ {
151+ executionId : 'execution-1' ,
152+ workflowId : 'workflow-1' ,
153+ workspaceId : 'workspace-1' ,
154+ executionData : { } ,
155+ } ,
156+ ] )
157+ mockMaterializeExecutionData . mockResolvedValueOnce ( {
158+ workflowInput,
159+ executionState : {
160+ blockStates : {
161+ start : {
162+ output : { leadId : 'legacy-lead' } ,
163+ executed : false ,
164+ executionTime : 0 ,
165+ } ,
166+ } ,
167+ } ,
168+ } )
169+
170+ const result = await getExecutionInputForWorkflow ( 'execution-1' , 'workflow-1' )
171+
172+ expect ( result ) . toEqual ( { found : true , input : workflowInput } )
173+ } )
174+
115175 it ( 'checks older pointer-backed candidates when the latest has no execution state' , async ( ) => {
116176 queueTableRows ( schemaMock . workflowExecutionLogs , [
117177 {
0 commit comments