diff --git a/src/services/graph-analysis.ts b/src/services/graph-analysis.ts index bc4354e..1650092 100644 --- a/src/services/graph-analysis.ts +++ b/src/services/graph-analysis.ts @@ -14,7 +14,7 @@ export function getFileDependencies(graph: CodeGraph, relativePath: string): { importedBy: string[]; } { const normalized = toForwardSlash(relativePath); - const node = graph.nodes.find((n) => n.relativePath === normalized); + const node = graph.nodes.find((n) => toForwardSlash(n.relativePath) === normalized); if (!node) { return { imports: [], importedBy: [] }; } diff --git a/tests/unit/graph-analysis.test.ts b/tests/unit/graph-analysis.test.ts index 8757da4..89f7034 100644 --- a/tests/unit/graph-analysis.test.ts +++ b/tests/unit/graph-analysis.test.ts @@ -145,6 +145,26 @@ describe("graph-analysis", () => { expect(depsMixed.imports).toEqual(deps.imports); expect(depsMixed.importedBy).toEqual(deps.importedBy); }); + + it("finds nodes in a legacy cached graph with backslash keys", () => { + // Simulate a graph built on Windows before the fix: stored keys have backslashes + const nodes: CodeGraphNode[] = [ + makeNode("src\\services\\api.ts", ["src\\types.ts"], []), + makeNode("src\\types.ts", [], ["src\\services\\api.ts"]), + ]; + // Fix relativePath (makeNode sets it from the argument) + nodes[0].relativePath = "src\\services\\api.ts"; + nodes[1].relativePath = "src\\types.ts"; + + const edges: CodeGraphEdge[] = [ + makeEdge("src\\services\\api.ts", "src\\types.ts"), + ]; + const graph = makeGraph(nodes, edges); + + // Query with forward slashes should still find the node + const deps = getFileDependencies(graph, "src/services/api.ts"); + expect(deps.imports).toContain("src\\types.ts"); + }); }); describe("findCircularDependencies", () => {