33 */
44import { dbChainMock , dbChainMockFns , resetDbChainMock } from '@sim/testing'
55import { beforeEach , describe , expect , it , vi } from 'vitest'
6- import { writeExecutionsPatch } from '@/lib/table/rows/executions'
7- import type { RowExecutionMetadata } from '@/lib/table/types'
6+ import { deriveExecClearsForDataPatch , writeExecutionsPatch } from '@/lib/table/rows/executions'
7+ import type { RowExecutionMetadata , TableSchema , WorkflowGroup } from '@/lib/table/types'
88
99const EXECUTION_STATE : RowExecutionMetadata = {
1010 status : 'running' ,
@@ -14,6 +14,16 @@ const EXECUTION_STATE: RowExecutionMetadata = {
1414 error : null ,
1515}
1616
17+ const MANUAL_ENRICHMENT_GROUP : WorkflowGroup = {
18+ id : 'enrichment-group' ,
19+ workflowId : '' ,
20+ enrichmentId : 'work-email' ,
21+ type : 'enrichment' ,
22+ autoRun : false ,
23+ inputMappings : [ { inputName : 'companyDomain' , columnName : 'domain' } ] ,
24+ outputs : [ { blockId : '' , path : '' , outputId : 'email' , columnName : 'email' } ] ,
25+ }
26+
1727function renderCondition ( value : unknown ) : string {
1828 if ( ! value || typeof value !== 'object' ) return ''
1929 const record = value as Record < string , unknown >
@@ -110,3 +120,31 @@ describe('writeExecutionsPatch guards', () => {
110120 ) . resolves . toBe ( 'wrote' )
111121 } )
112122} )
123+
124+ describe ( 'deriveExecClearsForDataPatch enrichment inputs' , ( ) => {
125+ it ( 're-arms a completed manual enrichment when a mapped input changes' , ( ) => {
126+ const schema : TableSchema = {
127+ columns : [
128+ { id : 'domain' , name : 'Domain' , type : 'string' } ,
129+ {
130+ id : 'email' ,
131+ name : 'Email' ,
132+ type : 'string' ,
133+ workflowGroupId : MANUAL_ENRICHMENT_GROUP . id ,
134+ } ,
135+ ] ,
136+ workflowGroups : [ MANUAL_ENRICHMENT_GROUP ] ,
137+ }
138+ const completed = { ...EXECUTION_STATE , status : 'completed' as const }
139+
140+ const result = deriveExecClearsForDataPatch (
141+ { domain : 'new.example' } ,
142+ schema ,
143+ { [ MANUAL_ENRICHMENT_GROUP . id ] : completed } ,
144+ undefined ,
145+ { domain : 'new.example' , email : '' }
146+ )
147+
148+ expect ( result . executionsPatch ) . toEqual ( { [ MANUAL_ENRICHMENT_GROUP . id ] : null } )
149+ } )
150+ } )
0 commit comments