import { describe, it, expect } from "vitest"; import { normalizeHeadingForMatch, headingsMatch } from "../../unresolvedLink/linkHelpers"; describe("Direct edge matching simulation", () => { it("should match guides edge with exact values", () => { const filePath = "03_experience/Geburt unserer Kinder Rouven und Rohan.md"; // Edge as created by buildNoteIndex const edge = { rawEdgeType: "guides", source: { file: filePath, sectionHeading: "Reflexion & Learning (Was lerne ich daraus?) ^learning", }, target: { file: "Geburt unserer Kinder Rouven und Rohan", // No path! heading: "Nächster Schritt ^next", }, }; // Keys as created in buildCandidateNodes and used in scoreAssignment const norm = (h: string | null | undefined) => normalizeHeadingForMatch(h ?? null) ?? ""; const fromKey = `${filePath}:${norm("Reflexion & Learning (Was lerne ich daraus?) ^learning")}`; const toKey = `${filePath}:${norm("Nächster Schritt ^next")}`; console.log("fromKey:", fromKey); console.log("toKey:", toKey); // Parse keys const parseNodeKey = (key: string) => { const i = key.lastIndexOf(":"); if (i < 0) return { file: key, heading: null }; return { file: key.slice(0, i), heading: key.slice(i + 1) || null }; }; const normalizePathForComparison = (path: string) => { return path.trim().replace(/\\/g, "/").replace(/\/+$/, "") || path; }; const { file: fromFile, heading: fromHeading } = parseNodeKey(fromKey); const { file: toFile, heading: toHeading } = parseNodeKey(toKey); console.log("\nParsed fromKey:"); console.log(" file:", fromFile); console.log(" heading:", fromHeading); console.log("\nParsed toKey:"); console.log(" file:", toFile); console.log(" heading:", toHeading); // Simulate edgeTargetResolutionMap const edgeTargetResolutionMap = new Map(); edgeTargetResolutionMap.set(edge.source.file, filePath); // CRITICAL: Resolve target file - should be same as source for intra-note link const sourceBasename = filePath.split("/").pop()?.replace(/\.md$/, "") || ""; if (sourceBasename === edge.target.file) { edgeTargetResolutionMap.set(edge.target.file, filePath); } else { edgeTargetResolutionMap.set(edge.target.file, edge.target.file); // Fallback } console.log("\nResolution map:"); console.log(" source file ->", edgeTargetResolutionMap.get(edge.source.file)); console.log(" target file ->", edgeTargetResolutionMap.get(edge.target.file)); // Simulate findEdgeBetween logic const resolvedSourceFile = edgeTargetResolutionMap.get(edge.source.file) || edge.source.file; const resolvedTargetFile = edgeTargetResolutionMap.get(edge.target.file) || edge.target.file; const resolvedSourceNorm = normalizePathForComparison(resolvedSourceFile); const resolvedTargetNorm = normalizePathForComparison(resolvedTargetFile); const fromFileNorm = normalizePathForComparison(fromFile); const toFileNorm = normalizePathForComparison(toFile); console.log("\nFile comparison:"); console.log(" resolvedSourceNorm:", resolvedSourceNorm); console.log(" fromFileNorm:", fromFileNorm); console.log(" Match?", resolvedSourceNorm === fromFileNorm); console.log(" resolvedTargetNorm:", resolvedTargetNorm); console.log(" toFileNorm:", toFileNorm); console.log(" Match?", resolvedTargetNorm === toFileNorm); const sourceHeading = edge.source.sectionHeading; const targetHeading = edge.target.heading; console.log("\nHeading comparison:"); console.log(" sourceHeading:", sourceHeading); console.log(" fromHeading:", fromHeading); console.log(" Match?", headingsMatch(sourceHeading, fromHeading)); console.log(" targetHeading:", targetHeading); console.log(" toHeading:", toHeading); console.log(" Match?", headingsMatch(targetHeading, toHeading)); const allMatch = resolvedSourceNorm === fromFileNorm && headingsMatch(sourceHeading, fromHeading) && resolvedTargetNorm === toFileNorm && headingsMatch(targetHeading, toHeading); console.log("\nAll match?", allMatch); expect(allMatch).toBe(true); }); });