@@ -173,6 +173,52 @@ describe("fixmap mcp server", () => {
173173 expect ( comparison . confidenceChanged ) . toHaveLength ( 1 ) ;
174174 } ) ;
175175
176+ it ( "rejects a contextFiles-only empty object instead of treating it as a report" , async ( ) => {
177+ const client = await connectClient ( ) ;
178+ const result = await client . callTool ( {
179+ name : "fixmap_compare" ,
180+ arguments : {
181+ previous : { contextFiles : [ ] } ,
182+ current : { contextFiles : [ ] } ,
183+ format : "json"
184+ }
185+ } ) ;
186+
187+ expect ( result . isError ) . toBe ( true ) ;
188+ expect ( ( result . content as Array < { text : string } > ) [ 0 ] ?. text ) . toContain ( "complete FixMap report envelope" ) ;
189+ } ) ;
190+
191+ it ( "still accepts complete reports that legitimately have no context files" , async ( ) => {
192+ const client = await connectClient ( ) ;
193+ const empty = { summary : "No matches" , contextFiles : [ ] , testRoutes : [ ] , risks : [ ] , changedFiles : [ ] , diagnostics : [ ] } ;
194+ const result = await client . callTool ( {
195+ name : "fixmap_compare" ,
196+ arguments : { previous : empty , current : empty , format : "json" }
197+ } ) ;
198+
199+ expect ( result . isError ) . not . toBe ( true ) ;
200+ expect ( JSON . parse ( ( result . content as Array < { text : string } > ) [ 0 ] ! . text ) . unchanged ) . toEqual ( [ ] ) ;
201+ } ) ;
202+
203+ it . each ( [
204+ [ { path : "" } , "path" ] ,
205+ [ { path : "a.ts" , rank : 0 } , "rank" ] ,
206+ [ { path : "a.ts" , score : "ten" } , "score" ] ,
207+ [ { path : "a.ts" , confidence : "certain" } , "confidence" ]
208+ ] ) ( "rejects malformed optional comparison fields in %j" , async ( entry , expectedField ) => {
209+ const client = await connectClient ( ) ;
210+ const result = await client . callTool ( {
211+ name : "fixmap_compare" ,
212+ arguments : {
213+ previous : { contextFiles : [ entry ] } ,
214+ current : { contextFiles : [ { path : "a.ts" } ] }
215+ }
216+ } ) ;
217+
218+ expect ( result . isError ) . toBe ( true ) ;
219+ expect ( ( result . content as Array < { text : string } > ) [ 0 ] ?. text ) . toContain ( expectedField ) ;
220+ } ) ;
221+
176222 it ( "compares report file paths through MCP like the CLI" , async ( ) => {
177223 const client = await connectClient ( ) ;
178224 const directory = await mkdtemp ( join ( tmpdir ( ) , "fixmap-mcp-compare-" ) ) ;
0 commit comments