mindnet_obsidian/src/tests/analysis/directEdgeMatching.test.ts
Lars e6cd4aafec
Some checks are pending
Node.js build / build (20.x) (push) Waiting to run
Node.js build / build (22.x) (push) Waiting to run
Enhance edge parsing and settings for improved template matching
- Updated `parseEdgesFromCallouts.ts` to support edge extraction from both callout blocks and plain lines, allowing for more flexible edge definitions.
- Introduced new settings in `settings.ts` for maximum assignments collected per template, enhancing loop protection during edge processing.
- Enhanced documentation in `Entwicklerhandbuch.md` to reflect changes in edge parsing and settings.
- Improved UI components to utilize the new settings for better user experience in the Chain Workbench and related features.
2026-02-06 11:40:44 +01:00

104 lines
4.3 KiB
TypeScript

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<string, string>();
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);
});
});