@@ -59,16 +59,28 @@ describe("altimate_core_validate error propagation", () => {
5959 } )
6060
6161 test ( "surfaces errors when schema provided but table missing from schema" , async ( ) => {
62- // Uses real napi handler — schema has 'orders' but SQL references 'users'
63- // The handler completes successfully (no exception) — it reports findings
64- // via data.valid/data.errors, so success=true (the operation itself succeeded).
62+ // Mock: dispatcher returns what the real handler produces when SQL references
63+ // a table not in the schema — valid=false with error details in data.errors[].
64+ // The handler completes normally (success=true), findings live in data fields.
65+ Dispatcher . register ( "altimate_core.validate" as any , async ( ) => ( {
66+ success : true ,
67+ data : {
68+ valid : false ,
69+ errors : [ { code : "E001" , kind : { type : "TableNotFound" } , message : "Table 'users' not found" , suggestions : [ "orders" ] } ] ,
70+ warnings : [ ] ,
71+ } ,
72+ } ) )
73+
6574 const { AltimateCoreValidateTool } = await import ( "../../src/altimate/tools/altimate-core-validate" )
6675 const tool = await AltimateCoreValidateTool . init ( )
6776 const result = await tool . execute ( { sql : "SELECT * FROM users" , schema_context : { orders : { id : "INT" } } } , stubCtx ( ) )
6877
6978 expect ( result . metadata . success ) . toBe ( true )
7079 // Validation findings are reported via data fields, not as tool errors
71- expect ( result . metadata . valid ) . toBeDefined ( )
80+ expect ( result . metadata . valid ) . toBe ( false )
81+ // The finding message is surfaced in metadata.error for telemetry
82+ expect ( result . metadata . error ) . toContain ( "Table 'users' not found" )
83+ expect ( telemetryWouldExtract ( result . metadata ) ) . not . toBe ( "unknown error" )
7284 } )
7385} )
7486
@@ -89,12 +101,25 @@ describe("altimate_core_semantics error propagation", () => {
89101 } )
90102
91103 test ( "surfaces errors when schema provided but table missing from schema" , async ( ) => {
104+ // Mock: dispatcher returns validation_errors when semantic check can't plan the query.
105+ // Handler completes normally (success=true per ok() contract), but validation_errors
106+ // in the data signal the engine couldn't analyze. The tool wrapper treats this as failure.
107+ Dispatcher . register ( "altimate_core.semantics" as any , async ( ) => ( {
108+ success : true ,
109+ data : {
110+ valid : false ,
111+ issues : [ ] ,
112+ validation_errors : [ "Failed to resolve table 'users' in schema" ] ,
113+ } ,
114+ } ) )
115+
92116 const { AltimateCoreSemanticsTool } = await import ( "../../src/altimate/tools/altimate-core-semantics" )
93117 const tool = await AltimateCoreSemanticsTool . init ( )
94118 const result = await tool . execute ( { sql : "SELECT * FROM users" , schema_context : { orders : { id : "INT" } } } , stubCtx ( ) )
95119
96- expect ( result . metadata . success ) . toBe ( false )
97- expect ( result . metadata . error ) . toBeDefined ( )
120+ // Handler completed (success=true), but validation_errors are surfaced in metadata.error
121+ expect ( result . metadata . success ) . toBe ( true )
122+ expect ( result . metadata . error ) . toContain ( "Failed to resolve table" )
98123 expect ( telemetryWouldExtract ( result . metadata ) ) . not . toBe ( "unknown error" )
99124 } )
100125} )
@@ -116,12 +141,24 @@ describe("altimate_core_equivalence error propagation", () => {
116141 } )
117142
118143 test ( "surfaces errors when schema provided but table missing from schema" , async ( ) => {
144+ // Mock: handler completes normally (success=true per ok() contract), but
145+ // validation_errors signal the engine couldn't plan the query.
146+ // The equivalence wrapper uses isRealFailure to override success to false.
147+ Dispatcher . register ( "altimate_core.equivalence" as any , async ( ) => ( {
148+ success : true ,
149+ data : {
150+ equivalent : false ,
151+ validation_errors : [ "Failed to resolve table 'users' in schema" ] ,
152+ } ,
153+ } ) )
154+
119155 const { AltimateCoreEquivalenceTool } = await import ( "../../src/altimate/tools/altimate-core-equivalence" )
120156 const tool = await AltimateCoreEquivalenceTool . init ( )
121157 const result = await tool . execute ( { sql1 : "SELECT * FROM users" , sql2 : "SELECT * FROM users" , schema_context : { orders : { id : "INT" } } } , stubCtx ( ) )
122158
159+ // Equivalence wrapper overrides success via isRealFailure when validation_errors exist
123160 expect ( result . metadata . success ) . toBe ( false )
124- expect ( result . metadata . error ) . toBeDefined ( )
161+ expect ( result . metadata . error ) . toContain ( "Failed to resolve table" )
125162 expect ( telemetryWouldExtract ( result . metadata ) ) . not . toBe ( "unknown error" )
126163 } )
127164} )
@@ -386,11 +423,20 @@ describe("extractors handle empty message fields", () => {
386423 beforeEach ( ( ) => Dispatcher . reset ( ) )
387424
388425 test ( "validate extractor filters out empty messages" , async ( ) => {
426+ // Mock: dispatcher returns errors with empty message fields
427+ Dispatcher . register ( "altimate_core.validate" as any , async ( ) => ( {
428+ success : true ,
429+ data : {
430+ valid : false ,
431+ errors : [ { code : "E001" , kind : { type : "TableNotFound" } , message : "" , suggestions : [ ] } ] ,
432+ warnings : [ ] ,
433+ } ,
434+ } ) )
435+
389436 const { AltimateCoreValidateTool } = await import ( "../../src/altimate/tools/altimate-core-validate" )
390437 const tool = await AltimateCoreValidateTool . init ( )
391- // Schema provided but table missing — real handler returns error with actual message
392438 const result = await tool . execute ( { sql : "SELECT * FROM nonexistent_table" , schema_context : { users : { id : "INT" } } } , stubCtx ( ) )
393- // The error should never be empty string
439+ // The error should never be empty string — .filter(Boolean) removes it
394440 if ( result . metadata . error !== undefined ) {
395441 expect ( result . metadata . error ) . not . toBe ( "" )
396442 }
0 commit comments