11import { describe , it , expect , beforeEach , afterEach } from 'vitest' ;
22import { mkdtemp , rm , mkdir , writeFile } from 'node:fs/promises' ;
3- import { join } from 'node:path' ;
3+ import { join , sep } from 'node:path' ;
44import { tmpdir } from 'node:os' ;
55import {
66 findDefinition ,
@@ -12,6 +12,9 @@ import {
1212 formatGraphForAI ,
1313} from './call-graph.js' ;
1414
15+ /** Normalize a path to use forward slashes for cross-platform comparison. */
16+ const norm = ( p : string ) => p . replace ( / \\ / g, '/' ) ;
17+
1518// ── Test workspace setup ─────────────────────────────────────────────────────
1619
1720let workspace : string ;
@@ -92,7 +95,7 @@ describe('findDefinition', () => {
9295 expect ( def ) . not . toBeNull ( ) ;
9396 expect ( def ! . name ) . toBe ( 'processData' ) ;
9497 expect ( def ! . kind ) . toBe ( 'function' ) ;
95- expect ( def ! . file ) . toBe ( 'src/processor.ts' ) ;
98+ expect ( norm ( def ! . file ) ) . toBe ( 'src/processor.ts' ) ;
9699 expect ( def ! . params ) . toContain ( 'input: string' ) ;
97100 expect ( def ! . returnType ) . toContain ( 'Promise<string>' ) ;
98101 } ) ;
@@ -113,7 +116,7 @@ describe('findDefinition', () => {
113116 const def = await findDefinition ( 'Logger' , workspace ) ;
114117 expect ( def ) . not . toBeNull ( ) ;
115118 expect ( def ! . kind ) . toBe ( 'class' ) ;
116- expect ( def ! . file ) . toBe ( 'src/utils.ts' ) ;
119+ expect ( norm ( def ! . file ) ) . toBe ( 'src/utils.ts' ) ;
117120 } ) ;
118121
119122 it ( 'returns null for nonexistent symbol' , async ( ) => {
@@ -126,19 +129,21 @@ describe('findDefinition', () => {
126129
127130describe ( 'findReferences' , ( ) => {
128131 it ( 'finds call sites for processData' , async ( ) => {
129- const { callers, imports } = await findReferences ( 'processData' , 'src/processor.ts' , workspace ) ;
132+ const defFile = [ 'src' , 'processor.ts' ] . join ( sep ) ;
133+ const { callers, imports } = await findReferences ( 'processData' , defFile , workspace ) ;
130134
131135 // handler.ts imports and calls processData
132136 expect ( imports . length ) . toBeGreaterThanOrEqual ( 1 ) ;
133- expect ( imports . some ( ( i ) => i . file === 'src/handler.ts' ) ) . toBe ( true ) ;
137+ expect ( imports . some ( ( i ) => norm ( i . file ) === 'src/handler.ts' ) ) . toBe ( true ) ;
134138
135139 expect ( callers . length ) . toBeGreaterThanOrEqual ( 2 ) ;
136- expect ( callers . some ( ( c ) => c . file === 'src/handler.ts' && c . args . includes ( 'body' ) ) ) . toBe ( true ) ;
140+ expect ( callers . some ( ( c ) => norm ( c . file ) === 'src/handler.ts' && c . args . includes ( 'body' ) ) ) . toBe ( true ) ;
137141 } ) ;
138142
139143 it ( 'finds import references for handleRequest' , async ( ) => {
140- const { imports } = await findReferences ( 'handleRequest' , 'src/handler.ts' , workspace ) ;
141- expect ( imports . some ( ( i ) => i . file === 'src/server.ts' ) ) . toBe ( true ) ;
144+ const defFile = [ 'src' , 'handler.ts' ] . join ( sep ) ;
145+ const { imports } = await findReferences ( 'handleRequest' , defFile , workspace ) ;
146+ expect ( imports . some ( ( i ) => norm ( i . file ) === 'src/server.ts' ) ) . toBe ( true ) ;
142147 } ) ;
143148} ) ;
144149
@@ -182,7 +187,7 @@ describe('buildCallGraph', () => {
182187 const graph = await buildCallGraph ( 'processData' , workspace , { depth : 2 } ) ;
183188
184189 expect ( graph . symbol . name ) . toBe ( 'processData' ) ;
185- expect ( graph . symbol . file ) . toBe ( 'src/processor.ts' ) ;
190+ expect ( norm ( graph . symbol . file ) ) . toBe ( 'src/processor.ts' ) ;
186191 expect ( graph . callers . length ) . toBeGreaterThanOrEqual ( 2 ) ;
187192 expect ( graph . imports . length ) . toBeGreaterThanOrEqual ( 1 ) ;
188193 expect ( graph . callees . length ) . toBeGreaterThanOrEqual ( 1 ) ;
@@ -204,7 +209,7 @@ describe('formatAsciiTree', () => {
204209
205210 expect ( tree ) . toContain ( 'processData' ) ;
206211 expect ( tree ) . toContain ( 'Defined:' ) ;
207- expect ( tree ) . toContain ( 'src/ processor.ts' ) ;
212+ expect ( tree ) . toContain ( [ 'src' , ' processor.ts'] . join ( sep ) ) ;
208213 } ) ;
209214} ) ;
210215
0 commit comments