fix: handle unjustified unknown selection ties
This commit is contained in:
@@ -183,6 +183,87 @@ describe("lib/graph/orchestrator startCase", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("returns an ambiguous tie result instead of choosing by label order", async () => {
|
||||
mockAnalyseScenario.mockResolvedValue(
|
||||
makeAnalysisResult({
|
||||
reconstruction: {
|
||||
summary: "Revenue up while cash falls",
|
||||
actors: [],
|
||||
systemsOrObjects: [],
|
||||
expectedStates: [],
|
||||
observedStates: [
|
||||
{
|
||||
id: "obs-1",
|
||||
label: "Revenue increased by 18%.",
|
||||
description: "Revenue increased by 18%.",
|
||||
confidence: "high",
|
||||
},
|
||||
{
|
||||
id: "obs-2",
|
||||
label: "Cash in the bank decreased over the same period.",
|
||||
description: "Cash in the bank decreased over the same period.",
|
||||
confidence: "high",
|
||||
},
|
||||
],
|
||||
differences: [],
|
||||
knownTransitions: [],
|
||||
unexplainedTransitions: [],
|
||||
contradictions: [
|
||||
{
|
||||
id: "c-1",
|
||||
label:
|
||||
"Apparent contradiction between profitability/revenue expansion and liquidity reduction.",
|
||||
description:
|
||||
"Apparent contradiction between profitability/revenue expansion and liquidity reduction.",
|
||||
confidence: "medium",
|
||||
},
|
||||
],
|
||||
importantUnknowns: [
|
||||
{
|
||||
id: "unk-1",
|
||||
label:
|
||||
"Whether revenue recognition timing differs from cash collection timing.",
|
||||
description:
|
||||
"Whether revenue recognition timing differs from cash collection timing.",
|
||||
confidence: "high",
|
||||
},
|
||||
{
|
||||
id: "unk-2",
|
||||
label:
|
||||
"Magnitude and nature of cash outflows (operating expenses, debt repayments, capex, or working capital shifts).",
|
||||
description:
|
||||
"Magnitude and nature of cash outflows (operating expenses, debt repayments, capex, or working capital shifts).",
|
||||
confidence: "high",
|
||||
},
|
||||
],
|
||||
plausibleInterpretations: [],
|
||||
},
|
||||
}),
|
||||
);
|
||||
const { startCase } = await import("@/lib/graph/orchestrator.js");
|
||||
|
||||
const result = await startCase({
|
||||
scenario:
|
||||
"Revenue increased by 18%, but cash in the bank fell over the same period.",
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.situationGraph.activeUnknownNodeId).toBeNull();
|
||||
expect(result.selectedQuestion).toMatchObject({
|
||||
id: "q_tie_resolution",
|
||||
selectionStatus: "ambiguous",
|
||||
question:
|
||||
"What changed during the period that could explain why Revenue increased by 18%, but cash in the bank fell over the same period?",
|
||||
tiedCandidateIds: expect.arrayContaining([expect.any(String)]),
|
||||
});
|
||||
expect(result.diagnostics.unknownSelectionExplanation).toMatchObject({
|
||||
status: "ambiguous",
|
||||
tieType: "complete_unresolved_tie",
|
||||
selectedNodeId: null,
|
||||
alphabeticalUsedAsReasoning: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns structured failure when graph reference validation fails", async () => {
|
||||
mockAnalyseScenario.mockResolvedValue(makeAnalysisResult());
|
||||
const utils = await import("@/lib/graph/utils.js");
|
||||
|
||||
Reference in New Issue
Block a user