fix: link emergent unknowns to answer-derived graph nodes

This commit is contained in:
2026-08-02 12:17:49 +01:00
parent 392564ed61
commit 4affadab4b
4 changed files with 383 additions and 9 deletions
+202
View File
@@ -623,6 +623,208 @@ describe("applyValidatedProposal", () => {
);
});
it("accepts a newly added unknown explicitly linked through answer-derived node fields", () => {
const { graph, ids } = makeApplicationFixture();
const proposal = {
addedNodes: [
makeNode({
id: "n-answer-context",
label: "Build Confidence Engine decision",
description: "Decision context introduced by the answer.",
kind: "state",
status: "supported",
confidence: "medium",
childIds: ["n-commercial-value"],
}),
makeNode({
id: "n-commercial-value",
label: "Commercial value definition",
description:
"Need commercial value definition because the decision depends on it.",
kind: "unknown",
status: "unknown",
confidence: "high",
dependsOn: ["n-answer-context"],
}),
],
updatedNodes: [
{
nodeId: ids.complaintRateUnknown,
previousStatus: "unknown",
newStatus: "resolved",
previousValue: null,
newValue: "Decision whether to build Confidence Engine",
reason: "The answer resolves the original context unknown.",
},
],
addedEdges: [],
removedEdgeIds: [],
resolvedUnknownNodeIds: [ids.complaintRateUnknown],
affectedNodeIds: [],
selectedQuestion: {
nodeId: "n-commercial-value",
question: "How should commercial value be defined for this decision?",
reason: "A consequential unknown remains unresolved.",
},
};
const result = applyValidatedProposal({ situationGraph: graph, proposal });
expect(result.success).toBe(true);
expect(result.selectedQuestion?.nodeId).toBe("n-commercial-value");
});
it("rejects a newly added unknown linked only to the original unresolved node when that node is not answer-derived", () => {
const { graph, ids } = makeApplicationFixture();
const result = applyValidatedProposal({
situationGraph: graph,
proposal: {
addedNodes: [
makeNode({
id: "n-commercial-value",
label: "Commercial value definition",
description:
"Need commercial value definition because the decision depends on it.",
kind: "unknown",
status: "unknown",
confidence: "high",
dependsOn: [ids.complaintRateUnknown],
}),
],
updatedNodes: [],
addedEdges: [
makeEdge({
id: "e-legacy-unknown-commercial-value",
fromNodeId: ids.complaintRateUnknown,
toNodeId: "n-commercial-value",
relationship: "depends_on",
confidence: "medium",
description: "Links only to the original unresolved unknown.",
}),
],
removedEdgeIds: [],
resolvedUnknownNodeIds: [],
affectedNodeIds: [],
selectedQuestion: {
nodeId: "n-commercial-value",
question: "How should commercial value be defined for this decision?",
reason: "A consequential unknown remains unresolved.",
},
},
});
expect(result.success).toBe(false);
expect(result.errors.join(" ")).toContain(
"explicitly related to an answer-derived node",
);
});
it("rejects a floating emergent unknown with no explicit relationship", () => {
const { graph } = makeApplicationFixture();
const result = applyValidatedProposal({
situationGraph: graph,
proposal: {
addedNodes: [
makeNode({
id: "n-floating",
label: "Floating unknown",
description: "Need this because it matters to the decision.",
kind: "unknown",
status: "unknown",
confidence: "medium",
}),
],
updatedNodes: [],
addedEdges: [],
removedEdgeIds: [],
resolvedUnknownNodeIds: [],
affectedNodeIds: [],
selectedQuestion: {
nodeId: "n-floating",
question: "What would resolve Floating unknown?",
reason: "Test case for floating unknown rejection.",
},
},
});
expect(result.success).toBe(false);
expect(result.errors.join(" ")).toContain(
"explicitly related to an answer-derived node",
);
});
it("accepts the reported live-shaped commercial-value proposal when the linkage is explicit in node references", () => {
const { graph, ids } = makeApplicationFixture();
const proposal = {
addedNodes: [
makeNode({
id: "answer_context_build",
label: "Build Confidence Engine decision context",
description:
"The answer introduces a concrete decision about whether to build Confidence Engine.",
kind: "state",
status: "known",
confidence: "high",
dependsOn: [ids.complaintRateUnknown, "nu_commercial_val"],
childIds: ["nu_commercial_val"],
affects: ["nu_commercial_val"],
}),
makeNode({
id: "nu_commercial_val",
label: "Commercial viability assessment of Confidence Engine",
description:
"The commercial viability of Confidence Engine remains unknown because resolving it is needed to decide whether building it is justified.",
kind: "unknown",
status: "unknown",
confidence: "medium",
dependsOn: ["answer_context_build"],
childIds: ["answer_context_build"],
}),
],
updatedNodes: [
{
nodeId: ids.complaintRateUnknown,
previousStatus: "unknown",
newStatus: "resolved",
previousValue: null,
newValue:
"Deciding whether to build the Confidence Engine due to uncertainty about its commercial value.",
reason: "The answer resolves the original context unknown.",
},
],
addedEdges: [],
removedEdgeIds: [],
resolvedUnknownNodeIds: [ids.complaintRateUnknown],
affectedNodeIds: [
ids.complaintRateUnknown,
"answer_context_build",
"nu_commercial_val",
],
selectedQuestion: {
nodeId: "nu_commercial_val",
question:
"How should commercial viability be defined for this decision?",
reason: "A foundational commercial-value unknown remains unresolved.",
},
};
const result = applyValidatedProposal({ situationGraph: graph, proposal });
expect(result.success).toBe(true);
expect(result.updatedSituationGraph.resolvedNodeIds).toContain(
ids.complaintRateUnknown,
);
expect(
result.updatedSituationGraph.nodes.some(
(node) => node.id === "nu_commercial_val",
),
).toBe(true);
});
it("rejects selected question referencing resolved node", () => {
const { graph, proposal, ids } = makeApplicationFixture();