mirror of
https://github.com/giancarloerra/socraticode.git
synced 2026-06-01 22:18:57 +02:00
fix(graph): normalize stored node keys during lookup for legacy cache compat
Address CodeRabbit review: also normalize stored graph node keys when comparing, not just the query input. Handles pre-fix Windows caches where node keys still contain backslashes until the graph is rebuilt.
This commit is contained in:
@@ -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: [] };
|
||||
}
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user