44import { beforeEach , describe , expect , it , vi } from 'vitest'
55import {
66 EXPORT_PRESERVED_RESOURCE_TYPES ,
7- sanitizeForExport ,
87 sanitizeWorkflowForSharing ,
98} from '@/lib/workflows/credentials/credential-extractor'
109import { WORKFLOW_SEARCH_SUBBLOCK_RESOURCE_TYPES } from '@/lib/workflows/search-replace/resources/registry'
@@ -46,14 +45,25 @@ function stateWithSubBlock(type: string, value: unknown): Partial<WorkflowState>
4645 } as unknown as Partial < WorkflowState >
4746}
4847
48+ /**
49+ * The exact option set `json-sanitizer`'s `sanitizeForExport` passes, copied rather than imported
50+ * so this suite keeps testing `credential-extractor` without pulling in its own consumer.
51+ *
52+ * The copy cannot drift unnoticed: `import-export-roundtrip` calls the real `sanitizeForExport`
53+ * and asserts the same withholding, so dropping an option there turns that suite red. Every
54+ * export-shaped assertion below must use this constant — one that quietly omitted
55+ * `redactOpaqueCredentialInputs` would describe a configuration no export surface runs.
56+ */
57+ const EXPORT_OPTIONS = { preserveEnvVars : true , redactOpaqueCredentialInputs : true } as const
58+
4959function sanitizedValue ( type : string , value : unknown ) : unknown {
5060 vi . mocked ( getBlock ) . mockReturnValue ( {
5161 name : 'Test' ,
5262 description : '' ,
5363 subBlocks : [ { id : 'field' , title : 'Field' , type } ] ,
5464 outputs : { } ,
5565 } as never )
56- const sanitized = sanitizeForExport ( stateWithSubBlock ( type , value ) )
66+ const sanitized = sanitizeWorkflowForSharing ( stateWithSubBlock ( type , value ) , EXPORT_OPTIONS )
5767 return sanitized . blocks ?. b1 ?. subBlocks ?. field ?. value
5868}
5969
@@ -98,19 +108,22 @@ describe('export sanitizer resource coverage', () => {
98108
99109 it ( 'clears tableId by key on a block with no registry config' , ( ) => {
100110 vi . mocked ( getBlock ) . mockReturnValue ( undefined as never )
101- const sanitized = sanitizeForExport ( {
102- blocks : {
103- b1 : {
104- id : 'b1' ,
105- type : 'unknown-block' ,
106- name : 'Test' ,
107- position : { x : 0 , y : 0 } ,
108- subBlocks : { tableId : { id : 'tableId' , type : 'short-input' , value : 'tbl_abc' } } ,
109- outputs : { } ,
110- enabled : true ,
111+ const sanitized = sanitizeWorkflowForSharing (
112+ {
113+ blocks : {
114+ b1 : {
115+ id : 'b1' ,
116+ type : 'unknown-block' ,
117+ name : 'Test' ,
118+ position : { x : 0 , y : 0 } ,
119+ subBlocks : { tableId : { id : 'tableId' , type : 'short-input' , value : 'tbl_abc' } } ,
120+ outputs : { } ,
121+ enabled : true ,
122+ } ,
111123 } ,
112- } ,
113- } as unknown as Partial < WorkflowState > )
124+ } as unknown as Partial < WorkflowState > ,
125+ EXPORT_OPTIONS
126+ )
114127 expect ( sanitized . blocks ?. b1 ?. subBlocks ?. tableId ?. value ) . toBeNull ( )
115128 } )
116129
@@ -133,10 +146,10 @@ describe('export sanitizer resource coverage', () => {
133146 outputs : { } ,
134147 } as never )
135148
136- const sanitized = sanitizeWorkflowForSharing ( stateWithSubBlock ( 'tool-input' , value ) , {
137- preserveEnvVars : true ,
138- redactOpaqueCredentialInputs : true ,
139- } )
149+ const sanitized = sanitizeWorkflowForSharing (
150+ stateWithSubBlock ( 'tool-input' , value ) ,
151+ EXPORT_OPTIONS
152+ )
140153
141154 expect ( sanitized . blocks ?. b1 ?. subBlocks ?. field ?. value ) . toEqual ( [
142155 {
@@ -167,10 +180,10 @@ describe('export sanitizer resource coverage', () => {
167180 outputs : { } ,
168181 } as never )
169182
170- const sanitized = sanitizeWorkflowForSharing ( stateWithSubBlock ( 'tool-input' , value ) , {
171- preserveEnvVars : true ,
172- redactOpaqueCredentialInputs : true ,
173- } )
183+ const sanitized = sanitizeWorkflowForSharing (
184+ stateWithSubBlock ( 'tool-input' , value ) ,
185+ EXPORT_OPTIONS
186+ )
174187
175188 expect ( sanitized . blocks ?. b1 ?. subBlocks ?. field ?. value ) . toEqual ( [
176189 {
@@ -182,7 +195,7 @@ describe('export sanitizer resource coverage', () => {
182195 ] )
183196 } )
184197
185- it ( 'withholds opaque table values from public snapshots' , ( ) => {
198+ it ( 'withholds opaque table values from public snapshots and exports ' , ( ) => {
186199 const value = [
187200 { Key : 'Authorization' , Value : 'Bearer plaintext-secret' } ,
188201 { Key : 'API_TOKEN' , Value : '{{API_TOKEN}}' } ,
@@ -194,10 +207,7 @@ describe('export sanitizer resource coverage', () => {
194207 outputs : { } ,
195208 } as never )
196209
197- const sanitized = sanitizeWorkflowForSharing ( stateWithSubBlock ( 'table' , value ) , {
198- preserveEnvVars : true ,
199- redactOpaqueCredentialInputs : true ,
200- } )
210+ const sanitized = sanitizeWorkflowForSharing ( stateWithSubBlock ( 'table' , value ) , EXPORT_OPTIONS )
201211
202212 expect ( sanitized . blocks ?. b1 ?. subBlocks ?. field ?. value ) . toBeNull ( )
203213 } )
0 commit comments