feat(confidence-engine): preserve initial reconstruction relationships

This commit is contained in:
2026-09-05 11:53:58 +01:00
parent 13fbceee7a
commit 7472b6ecb0
7 changed files with 485 additions and 23 deletions
+92
View File
@@ -216,6 +216,98 @@ describe("buildInitialGraph", () => {
expect(depEdges.length).toBe(2); // Two unknown nodes
});
it("projects a supplied dependency between reconstruction source IDs", () => {
const reconstruction = {
...makeReconstructionFixture(),
importantUnknowns: [
{ id: "u_problem", description: "Whether a quality problem exists", confidence: "high" },
{ id: "u_intervention", description: "Whether inspection is appropriate", confidence: "high" },
],
relationships: [{
id: "r-dependency",
fromId: "u_intervention",
toId: "u_problem",
relationship: "depends_on",
description: "Inspection appropriateness depends on the quality problem.",
confidence: "high",
}],
};
const result = buildInitialGraph({ reconstruction, evidence: [] });
const intervention = result.nodes.find((node) => node.label === "Whether inspection is appropriate");
const problem = result.nodes.find((node) => node.label === "Whether a quality problem exists");
expect(result.edges).toContainEqual(expect.objectContaining({
id: "e-rel-r-dependency",
fromNodeId: intervention.id,
toNodeId: problem.id,
relationship: "depends_on",
}));
});
it("preserves a supplied compares_with relationship type", () => {
const reconstruction = {
...makeReconstructionFixture(),
observedStates: [
{ id: "u_a", description: "Complaint rate before", confidence: "high" },
{ id: "u_b", description: "Complaint rate after", confidence: "high" },
],
relationships: [{
id: "r-compare",
fromId: "u_a",
toId: "u_b",
relationship: "compares_with",
description: "Compare complaint rates before and after.",
confidence: "medium",
}],
};
const result = buildInitialGraph({ reconstruction, evidence: [] });
expect(result.edges).toContainEqual(expect.objectContaining({
id: "e-rel-r-compare",
relationship: "compares_with",
}));
});
it("skips relationships with invalid source IDs without creating substitute nodes", () => {
const reconstruction = {
...makeReconstructionFixture(),
relationships: [{
id: "r-missing",
fromId: "missing-source",
toId: "obs-1",
relationship: "depends_on",
description: "This must be skipped.",
confidence: "low",
}],
};
expect(() => buildInitialGraph({ reconstruction, evidence: [] })).not.toThrow();
const result = buildInitialGraph({ reconstruction, evidence: [] });
expect(result.edges.find((edge) => edge.id === "e-rel-r-missing")).toBeUndefined();
expect(result.nodes.find((node) => node.label === "missing-source")).toBeUndefined();
});
it("does not infer direct dependencies between related descriptions without relationships", () => {
const reconstruction = {
...makeReconstructionFixture(),
importantUnknowns: [
{ id: "u_problem", description: "Whether a quality problem exists", confidence: "high" },
{ id: "u_intervention", description: "Whether inspection is appropriate", confidence: "high" },
],
};
const result = buildInitialGraph({ reconstruction, evidence: [] });
const intervention = result.nodes.find((node) => node.label === "Whether inspection is appropriate");
const problem = result.nodes.find((node) => node.label === "Whether a quality problem exists");
expect(result.edges).not.toContainEqual(expect.objectContaining({
fromNodeId: intervention.id,
toNodeId: problem.id,
relationship: "depends_on",
}));
});
it("handles empty observedStates gracefully", () => {
const reconstruction = {
...makeReconstructionFixture(),