diff --git a/components/diagnostics-view.jsx b/components/diagnostics-view.jsx
index 07433ea..8049c26 100644
--- a/components/diagnostics-view.jsx
+++ b/components/diagnostics-view.jsx
@@ -55,11 +55,21 @@ export default function DiagnosticsView({ result }) {
},
{
label: "Node count",
- value: diagnostics.nodeCount != null ? diagnostics.nodeCount : "?",
+ value:
+ diagnostics.nodeCount != null
+ ? diagnostics.nodeCount
+ : diagnostics.graphNodeCount != null
+ ? diagnostics.graphNodeCount
+ : "?",
},
{
label: "Edge count",
- value: diagnostics.edgeCount != null ? diagnostics.edgeCount : "?",
+ value:
+ diagnostics.edgeCount != null
+ ? diagnostics.edgeCount
+ : diagnostics.graphEdgeCount != null
+ ? diagnostics.graphEdgeCount
+ : "?",
},
{
label: "Graph references",
@@ -75,6 +85,9 @@ export default function DiagnosticsView({ result }) {
const errors = [
...(result.errors || []),
...(result.validationErrors || []),
+ ...(result.graphValidationErrors || []),
+ ...(result.proposalErrors || []),
+ ...(result.providerErrors || []),
...(result.analysisErrors || []),
];
diff --git a/components/graph-update-view.jsx b/components/graph-update-view.jsx
new file mode 100644
index 0000000..78f9bcd
--- /dev/null
+++ b/components/graph-update-view.jsx
@@ -0,0 +1,169 @@
+import React from "react";
+
+function ListSection({ title, items, renderItem = (item) => item }) {
+ if (!items?.length) return null;
+
+ return (
+
+ {title}
+
+ {items.map((item, index) => (
+ - {renderItem(item)}
+ ))}
+
+
+ );
+}
+
+export default function GraphUpdateView({ updateResult }) {
+ if (!updateResult?.proposal) return null;
+
+ const {
+ resolvedUnknownNodeIds,
+ affectedNodeIds,
+ previousActiveUnknownNodeId,
+ newActiveUnknownNodeId,
+ changesApplied,
+ proposal,
+ previousSituationGraph,
+ updatedSituationGraph,
+ } = updateResult;
+
+ const previousNodesById = new Map(
+ (previousSituationGraph?.nodes || []).map((node) => [node.id, node]),
+ );
+ const updatedNodesById = new Map(
+ (updatedSituationGraph?.nodes || []).map((node) => [node.id, node]),
+ );
+ const proposalUpdatesByNodeId = new Map(
+ (proposal.updatedNodes || []).map((update) => [update.nodeId, update]),
+ );
+
+ function resolveNodePresentation(nodeId) {
+ const previousNode = previousNodesById.get(nodeId) || null;
+ const updatedNode = updatedNodesById.get(nodeId) || null;
+ const node = updatedNode || previousNode;
+ const update = proposalUpdatesByNodeId.get(nodeId) || null;
+
+ if (!node) {
+ return (
+
- {selectedQuestion?.question && (
+ {selectedQuestionText && (
Selected Question
- {selectedQuestion.question}
+ {selectedQuestionText}
)}
diff --git a/lib/graph/apply-proposal.js b/lib/graph/apply-proposal.js
index 403b311..0410fae 100644
--- a/lib/graph/apply-proposal.js
+++ b/lib/graph/apply-proposal.js
@@ -34,6 +34,140 @@ function collectDuplicateEdgeIds(edges) {
.map(([edgeId, count]) => ({ edgeId, count }));
}
+function normaliseText(value) {
+ return String(value || "")
+ .toLowerCase()
+ .replace(/[^a-z0-9]+/g, " ")
+ .trim();
+}
+
+function buildResolvedUnknownUpdate(node) {
+ return {
+ nodeId: node.id,
+ previousStatus: node.status ?? null,
+ newStatus: "resolved",
+ previousValue: node.value ?? null,
+ newValue: node.value ?? null,
+ reason:
+ "Resolved because the proposal explicitly marked this unknown as resolved.",
+ };
+}
+
+function reconcileResolutionSemantics(graph, proposal) {
+ const nextProposal = cloneJsonSafe(proposal);
+ const errors = [];
+ const graphNodeById = new Map(graph.nodes.map((node) => [node.id, node]));
+ const updatedNodeById = new Map(
+ nextProposal.updatedNodes.map((nodeUpdate) => [
+ nodeUpdate.nodeId,
+ nodeUpdate,
+ ]),
+ );
+
+ for (const resolvedUnknownNodeId of nextProposal.resolvedUnknownNodeIds) {
+ const existingNode = graphNodeById.get(resolvedUnknownNodeId);
+
+ if (!existingNode) {
+ errors.push(
+ `Resolved unknown must reference an existing node: "${resolvedUnknownNodeId}"`,
+ );
+ continue;
+ }
+
+ if (existingNode.kind !== "unknown") {
+ errors.push(
+ `Resolved unknown must reference an existing unknown node: "${resolvedUnknownNodeId}"`,
+ );
+ continue;
+ }
+
+ const existingUpdate = updatedNodeById.get(resolvedUnknownNodeId);
+ if (!existingUpdate) {
+ const syntheticUpdate = buildResolvedUnknownUpdate(existingNode);
+ nextProposal.updatedNodes.push(syntheticUpdate);
+ updatedNodeById.set(resolvedUnknownNodeId, syntheticUpdate);
+ continue;
+ }
+
+ if (existingUpdate.newStatus !== "resolved") {
+ existingUpdate.newStatus = "resolved";
+ if (existingUpdate.previousStatus == null) {
+ existingUpdate.previousStatus = existingNode.status ?? null;
+ }
+ if (existingUpdate.previousValue === undefined) {
+ existingUpdate.previousValue = existingNode.value ?? null;
+ }
+ }
+ }
+
+ for (const update of nextProposal.updatedNodes) {
+ const existingNode = graphNodeById.get(update.nodeId);
+ if (
+ existingNode?.kind === "unknown" &&
+ update.newStatus === "resolved" &&
+ !nextProposal.resolvedUnknownNodeIds.includes(update.nodeId)
+ ) {
+ errors.push(
+ `Unknown node updated to resolved must also appear in resolvedUnknownNodeIds: "${update.nodeId}"`,
+ );
+ }
+ }
+
+ return {
+ proposal: nextProposal,
+ errors,
+ };
+}
+
+function validateSemanticDuplicateUnknowns(graph, proposal) {
+ const errors = [];
+ const unresolvedUnknowns = graph.nodes.filter(
+ (node) =>
+ node.kind === "unknown" &&
+ !proposal.resolvedUnknownNodeIds.includes(node.id),
+ );
+
+ for (const addedNode of proposal.addedNodes) {
+ const addedTexts = [
+ normaliseText(addedNode.label),
+ normaliseText(addedNode.description),
+ ].filter(Boolean);
+
+ for (const unresolvedUnknown of unresolvedUnknowns) {
+ const unresolvedTexts = [
+ normaliseText(unresolvedUnknown.label),
+ normaliseText(unresolvedUnknown.description),
+ ].filter(Boolean);
+
+ const duplicatesMeaning = addedTexts.some((text) =>
+ unresolvedTexts.includes(text),
+ );
+
+ if (!duplicatesMeaning) continue;
+
+ const linkedToUnknown = proposal.addedEdges.some(
+ (edge) =>
+ (edge.fromNodeId === addedNode.id &&
+ edge.toNodeId === unresolvedUnknown.id) ||
+ (edge.toNodeId === addedNode.id &&
+ edge.fromNodeId === unresolvedUnknown.id),
+ );
+
+ const updatedUnknown = proposal.updatedNodes.some(
+ (update) => update.nodeId === unresolvedUnknown.id,
+ );
+
+ if (!linkedToUnknown && !updatedUnknown) {
+ errors.push(
+ `Proposal adds a node duplicating unresolved unknown meaning without linking or resolving it: "${unresolvedUnknown.id}"`,
+ );
+ }
+ }
+ }
+
+ return errors;
+}
+
function buildAffectedNodeIds(graph, proposal) {
const affected = new Set(proposal.affectedNodeIds ?? []);
@@ -116,8 +250,13 @@ export function applyValidatedProposal({ situationGraph, proposal }) {
};
}
- const validatedProposal = proposalValidation.data;
+ const reconciledProposal = reconcileResolutionSemantics(
+ situationGraph,
+ proposalValidation.data,
+ );
+ const validatedProposal = reconciledProposal.proposal;
const proposalCompatibilityErrors = [];
+ proposalCompatibilityErrors.push(...reconciledProposal.errors);
const proposalGraphValidation = validateGraphUpdate(
situationGraph,
validatedProposal,
@@ -180,6 +319,10 @@ export function applyValidatedProposal({ situationGraph, proposal }) {
),
);
+ proposalCompatibilityErrors.push(
+ ...validateSemanticDuplicateUnknowns(situationGraph, validatedProposal),
+ );
+
if (proposalCompatibilityErrors.length > 0) {
return {
success: false,
@@ -288,5 +431,6 @@ export function applyValidatedProposal({ situationGraph, proposal }) {
previousActiveUnknownNodeId,
newActiveUnknownNodeId,
changesApplied: buildChangesApplied(validatedProposal, affectedNodeIds),
+ graphReferenceValidation: resultReferenceValidation,
};
}
diff --git a/lib/graph/orchestrator.js b/lib/graph/orchestrator.js
index 967be9b..6fb3e01 100644
--- a/lib/graph/orchestrator.js
+++ b/lib/graph/orchestrator.js
@@ -46,6 +46,29 @@ function buildDiagnostics({ analysis, graph, graphReferenceValidation }) {
};
}
+function buildUpdateDiagnostics({
+ promptVersion,
+ modelName,
+ responseDurationMs,
+ normalisationsApplied,
+ graph,
+ graphReferenceValidation,
+}) {
+ return {
+ promptVersion: promptVersion ?? "v0.4",
+ modelName: modelName ?? null,
+ responseDurationMs: responseDurationMs ?? null,
+ validationStatus: "valid",
+ nodeCount: graph?.nodes?.length ?? 0,
+ edgeCount: graph?.edges?.length ?? 0,
+ graphReferenceValidation: graphReferenceValidation ?? {
+ valid: true,
+ errors: [],
+ },
+ normalisationsApplied: normalisationsApplied ?? [],
+ };
+}
+
export async function startCase(body) {
const parsedRequest = startCaseRequestSchema.safeParse(body);
@@ -254,12 +277,14 @@ async function updateCaseWithDependencies(body, dependencies = {}) {
stage: applicationResult.stage,
errors: applicationResult.errors,
diagnostics: {
- promptVersion: promptVersion ?? null,
- modelName,
- responseDurationMs,
- normalisationsApplied: parsedProposal.normalisationsApplied,
- graphNodeCount: situationGraph.nodes.length,
- graphEdgeCount: situationGraph.edges.length,
+ ...buildUpdateDiagnostics({
+ promptVersion,
+ modelName,
+ responseDurationMs,
+ normalisationsApplied: parsedProposal.normalisationsApplied,
+ graph: situationGraph,
+ graphReferenceValidation: graphReferenceValidation,
+ }),
},
statusCode:
applicationResult.stage === "application" ||
@@ -280,14 +305,14 @@ async function updateCaseWithDependencies(body, dependencies = {}) {
applicationResult.previousActiveUnknownNodeId,
newActiveUnknownNodeId: applicationResult.newActiveUnknownNodeId,
changesApplied: applicationResult.changesApplied,
- diagnostics: {
- promptVersion: promptVersion ?? null,
+ diagnostics: buildUpdateDiagnostics({
+ promptVersion,
modelName,
responseDurationMs,
normalisationsApplied: parsedProposal.normalisationsApplied,
- graphNodeCount: applicationResult.updatedSituationGraph.nodes.length,
- graphEdgeCount: applicationResult.updatedSituationGraph.edges.length,
- },
+ graph: applicationResult.updatedSituationGraph,
+ graphReferenceValidation: applicationResult.graphReferenceValidation,
+ }),
};
}
@@ -295,13 +320,13 @@ async function updateCaseWithDependencies(body, dependencies = {}) {
success: true,
stage: "proposal_ready",
proposal: parsedProposal.proposal,
- diagnostics: {
- promptVersion: promptVersion ?? null,
+ diagnostics: buildUpdateDiagnostics({
+ promptVersion,
modelName,
responseDurationMs,
normalisationsApplied: parsedProposal.normalisationsApplied,
- graphNodeCount: situationGraph.nodes.length,
- graphEdgeCount: situationGraph.edges.length,
- },
+ graph: situationGraph,
+ graphReferenceValidation,
+ }),
};
}
diff --git a/lib/graph/prompt-builder.js b/lib/graph/prompt-builder.js
index 87b101d..5aaf90b 100644
--- a/lib/graph/prompt-builder.js
+++ b/lib/graph/prompt-builder.js
@@ -98,6 +98,7 @@ The JSON object must contain exactly these top-level fields:
## Additional Guidance
- If the answer only clarifies an existing unknown, prefer updatedNodes and resolvedUnknownNodeIds over creating duplicate nodes.
+- When an answer resolves an existing unknown, include that existing node ID in resolvedUnknownNodeIds and update that node rather than creating only a parallel observation.
- If a new metric or observation is necessary, add the smallest set of nodes and edges needed.
- If the answer does not justify a change, return empty arrays for every category.
diff --git a/tests/graph/apply-proposal.test.js b/tests/graph/apply-proposal.test.js
index 781f3eb..0f90be6 100644
--- a/tests/graph/apply-proposal.test.js
+++ b/tests/graph/apply-proposal.test.js
@@ -280,6 +280,60 @@ describe("applyValidatedProposal", () => {
expect(result.updatedSituationGraph.resolvedNodeIds).toContain(
ids.complaintRateUnknown,
);
+ expect(
+ result.updatedSituationGraph.nodes.find(
+ (node) => node.id === ids.complaintRateUnknown,
+ )?.status,
+ ).toBe("resolved");
+ });
+
+ it("rejects resolvedUnknownNodeIds that do not reference actual unknown nodes", () => {
+ const { graph, proposal, ids } = makeApplicationFixture();
+
+ const result = applyValidatedProposal({
+ situationGraph: graph,
+ proposal: {
+ ...proposal,
+ resolvedUnknownNodeIds: [ids.qualityDeterioration],
+ },
+ });
+
+ expect(result.success).toBe(false);
+ expect(result.stage).toBe("proposal_compatibility");
+ expect(result.errors.join(" ")).toContain(
+ "Resolved unknown must reference an existing unknown node",
+ );
+ });
+
+ it("rejects a duplicate semantic node without resolution", () => {
+ const { graph, proposal } = makeApplicationFixture();
+
+ const result = applyValidatedProposal({
+ situationGraph: graph,
+ proposal: {
+ ...proposal,
+ resolvedUnknownNodeIds: [],
+ updatedNodes: proposal.updatedNodes.filter(
+ (update) => update.nodeId !== "n-complaint-rate-unknown",
+ ),
+ addedNodes: [
+ makeNode({
+ id: "n-parallel-rate",
+ label: "Complaint rate",
+ description: "Need the complaint rate per 100 units",
+ kind: "observation",
+ status: "supported",
+ confidence: "medium",
+ }),
+ ],
+ },
+ });
+
+ expect(result.success).toBe(false);
+ expect(result.stage).toBe("proposal_compatibility");
+ expect(result.errors.join(" ")).toContain(
+ "duplicating unresolved unknown meaning",
+ );
});
it("keeps the active unknown when it remains unresolved", () => {
diff --git a/tests/graph/orchestrator.test.js b/tests/graph/orchestrator.test.js
index 18c48b2..155ba44 100644
--- a/tests/graph/orchestrator.test.js
+++ b/tests/graph/orchestrator.test.js
@@ -13,9 +13,9 @@ function makeAnalysisResult(overrides = {}) {
return {
success: true,
validationStatus: "valid",
- modelName: "llama3",
+ modelName: "configured-model",
responseDurationMs: 321,
- rawResponse: "{}",
+ rawResponse: undefined,
promptVersion: "v0.3",
reconstruction: {
summary: "Revenue and complaints diverge",
@@ -164,7 +164,7 @@ describe("lib/graph/orchestrator startCase", () => {
expect(result.situationGraph.currentSummary).toContain("Nodes:");
expect(result.diagnostics).toMatchObject({
validationStatus: "valid",
- modelName: "llama3",
+ modelName: "configured-model",
graphReferenceValidation: { valid: true, errors: [] },
});
});
@@ -208,7 +208,7 @@ describe("lib/graph/orchestrator startCase", () => {
error: "Provider unavailable",
errors: ["socket hang up"],
rawResponse: null,
- modelName: "llama3",
+ modelName: "configured-model",
responseDurationMs: 99,
promptVersion: "v0.3",
validationStatus: "invalid",
@@ -279,8 +279,9 @@ describe("lib/graph/orchestrator startCase", () => {
diagnostics: {
promptVersion: "v0.4",
modelName: "configured",
- graphNodeCount: 2,
- graphEdgeCount: 0,
+ nodeCount: 2,
+ edgeCount: 0,
+ validationStatus: "valid",
},
});
expect(provider.generateReconstruction).toHaveBeenCalledTimes(1);
diff --git a/tests/smoke.test.js b/tests/smoke.test.js
index a15f642..bd825da 100644
--- a/tests/smoke.test.js
+++ b/tests/smoke.test.js
@@ -4,7 +4,7 @@ const BASE_URL = process.env.PLAYWRIGHT_BASE_URL || "http://localhost:3000";
test.setTimeout(300000);
-test("graph-backed start flow smoke test", async ({ page }) => {
+test("graph-backed one-turn update smoke test", async ({ page }) => {
await page.goto(BASE_URL);
// Page should load without error
@@ -26,7 +26,11 @@ test("graph-backed start flow smoke test", async ({ page }) => {
await page.getByRole("button", { name: /Analyse/i }).click();
await expect(
- page.getByRole("heading", { name: /Selected Question/i }),
+ page
+ .locator("section")
+ .filter({ hasText: /Selected Question/i })
+ .last()
+ .getByRole("heading", { name: /Selected Question/i }),
).toBeVisible({ timeout: 180000 });
await expect(
page.getByRole("heading", { name: /Situation Graph/i }),
@@ -40,13 +44,43 @@ test("graph-backed start flow smoke test", async ({ page }) => {
await rawJsonToggle.click();
await expect(page.getByText(/centralStatement/i)).toBeVisible();
+ const selectedQuestionSections = page
+ .locator("section")
+ .filter({ hasText: "Selected Question" });
+ await expect(selectedQuestionSections).toHaveCount(1);
+ const questionText = await selectedQuestionSections.first().innerText();
+ expect(questionText.length).toBeGreaterThan(25);
+
+ const answerTextarea = page.locator(
+ "textarea[placeholder*='Enter the answer']",
+ );
+ await expect(answerTextarea).toBeVisible();
+ await answerTextarea.fill(
+ "The complaint rate fell from 2.0 complaints per 100 units to 1.9 complaints per 100 units.",
+ );
+ await page.getByRole("button", { name: /Update situation/i }).click();
+
+ await expect(page.getByText(/Graph update applied/i)).toBeVisible({
+ timeout: 240000,
+ });
+ await expect(page.getByText(/Resolved unknowns/i)).toBeVisible();
+ await expect(page.getByText(/Affected nodes/i)).toBeVisible();
+ await expect(
+ page.getByText(/No next question selected yet\./i),
+ ).toBeVisible();
+ await expect(page.getByText(/Error:/i)).toHaveCount(0);
+ await expect(page.getByText(/Update error:/i)).toHaveCount(0);
+ await expect(answerTextarea).toHaveValue("");
+
+ const proposalToggle = page.getByText(/Proposal details/i);
+ await expect(proposalToggle).toBeVisible();
+
+ await rawJsonToggle.click();
+ await expect(page.getByText(/resolvedNodeIds/i)).toBeVisible();
+
// Get full body text for verification
const bodyText = await page.locator("body").innerText();
- console.log("\n=== UI Smoke Test Results ===");
- console.log("Page title:", await page.title());
- console.log("Body content length:", bodyText.length);
-
// Check key content indicators
const hasSelectedQuestion = bodyText.includes("Selected Question");
const hasComplaints =
@@ -59,12 +93,9 @@ test("graph-backed start flow smoke test", async ({ page }) => {
bodyText.toLowerCase().includes("denominator") ||
bodyText.toLowerCase().includes("per-unit");
- console.log("Has selected question heading:", hasSelectedQuestion);
- console.log("Has complaints reference:", hasComplaints);
- console.log("Has production reference:", hasProduction);
- console.log("Has rate context (rate/unit/denominator):", hasRateContext);
-
// Basic structural checks
- expect(bodyText.length).toBeGreaterThan(200);
+ expect(bodyText.length).toBeGreaterThan(400);
expect(hasSelectedQuestion).toBe(true);
+ expect(bodyText.includes("Resolved unknowns")).toBe(true);
+ expect(bodyText.includes("Affected nodes")).toBe(true);
});
diff --git a/tests/ui/scenario-form.test.jsx b/tests/ui/scenario-form.test.jsx
index e08dcbc..1a7f994 100644
--- a/tests/ui/scenario-form.test.jsx
+++ b/tests/ui/scenario-form.test.jsx
@@ -2,9 +2,12 @@ import React from "react";
import { describe, expect, it, vi } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import DiagnosticsView from "@/components/diagnostics-view.jsx";
+import GraphUpdateView from "@/components/graph-update-view.jsx";
import SituationGraphView from "@/components/situation-graph-view.jsx";
import {
ScenarioResultPanels,
+ UpdateErrorPanel,
+ submitAnswerForUpdateCase,
submitScenarioForStartCase,
} from "@/components/scenario-form.jsx";
@@ -70,6 +73,73 @@ function makeGraphResult(overrides = {}) {
};
}
+function makeUpdateSuccess(overrides = {}) {
+ return {
+ success: true,
+ stage: "update_applied",
+ updatedSituationGraph: {
+ centralStatement: "Complaints increased while production increased.",
+ currentSummary: "Updated summary",
+ activeUnknownNodeId: "n-next-unknown",
+ resolvedNodeIds: ["n-unknown"],
+ nodes: [
+ {
+ id: "n-1",
+ label: "Complaints up 35%",
+ description: "Complaints increased by 35%",
+ kind: "observation",
+ status: "supported",
+ confidence: "high",
+ value: 35,
+ unit: "%",
+ },
+ {
+ id: "n-conclusion",
+ label: "Quality deterioration",
+ description: "Quality deterioration conclusion",
+ kind: "conclusion",
+ status: "weakened",
+ confidence: "medium",
+ value: null,
+ unit: null,
+ },
+ {
+ id: "n-unknown",
+ label: "Complaint rate denominator",
+ description: "Need the denominator for complaint rate",
+ kind: "unknown",
+ status: "resolved",
+ confidence: "medium",
+ value: "1.9 complaints per 100 units",
+ unit: null,
+ },
+ ],
+ edges: [],
+ },
+ proposal: {
+ addedNodes: [],
+ updatedNodes: [
+ { nodeId: "n-unknown", newStatus: "resolved", reason: "answered" },
+ ],
+ addedEdges: [],
+ removedEdgeIds: [],
+ resolvedUnknownNodeIds: ["n-unknown"],
+ affectedNodeIds: ["n-conclusion"],
+ },
+ affectedNodeIds: ["n-conclusion"],
+ resolvedUnknownNodeIds: ["n-unknown"],
+ previousActiveUnknownNodeId: "n-unknown",
+ newActiveUnknownNodeId: "n-next-unknown",
+ changesApplied: {
+ updatedNodeCount: 2,
+ resolvedUnknownCount: 1,
+ affectedNodeCount: 1,
+ },
+ diagnostics: { responseDurationMs: 100 },
+ ...overrides,
+ };
+}
+
describe("scenario-form UI helpers", () => {
it("submits to /api/cases/start", async () => {
const fetchImpl = vi.fn().mockResolvedValue({ ok: true });
@@ -84,6 +154,46 @@ describe("scenario-form UI helpers", () => {
}),
);
});
+
+ it("empty answer is rejected without fetch", async () => {
+ const fetchImpl = vi.fn();
+
+ const result = await submitAnswerForUpdateCase(fetchImpl, {
+ situationGraph: { nodes: [] },
+ previousQuestion: "What changed?",
+ answer: " ",
+ });
+
+ expect(result.skipped).toBe(true);
+ expect(fetchImpl).not.toHaveBeenCalled();
+ });
+
+ it("update request body contains graph, previousQuestion and answer", async () => {
+ const fetchImpl = vi.fn().mockResolvedValue({
+ ok: true,
+ json: async () => ({ success: true }),
+ });
+ const graph = { nodes: [{ id: "n1" }], edges: [] };
+
+ await submitAnswerForUpdateCase(fetchImpl, {
+ situationGraph: graph,
+ previousQuestion: "What changed?",
+ answer: "The rate fell.",
+ });
+
+ expect(fetchImpl).toHaveBeenCalledWith(
+ "/api/cases/update",
+ expect.objectContaining({
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ situationGraph: graph,
+ previousQuestion: "What changed?",
+ answer: "The rate fell.",
+ }),
+ }),
+ );
+ });
});
describe("graph-backed UI rendering", () => {
@@ -128,6 +238,17 @@ describe("graph-backed UI rendering", () => {
).toHaveLength(1);
});
+ it("no answer form appears when selectedQuestion is null", () => {
+ const html = renderToStaticMarkup(
+
,
+ );
+
+ expect(html).not.toContain("Update situation");
+ });
+
it("renders diagnostics", () => {
const html = renderToStaticMarkup(
,
@@ -187,4 +308,121 @@ describe("graph-backed UI rendering", () => {
expect(html).toContain("Raw graph JSON");
expect(html).toContain(""centralStatement"");
});
+
+ it("resolved unknowns render", () => {
+ const html = renderToStaticMarkup(
+
,
+ );
+
+ expect(html).toContain("Resolved unknowns");
+ expect(html).toContain("Complaint rate denominator");
+ });
+
+ it("affected nodes render", () => {
+ const html = renderToStaticMarkup(
+
,
+ );
+
+ expect(html).toContain("Affected nodes");
+ expect(html).toContain("Quality deterioration");
+ });
+
+ it("no fake next question appears", () => {
+ const html = renderToStaticMarkup(
+
,
+ );
+
+ expect(html).toContain("No next question selected yet.");
+ });
+
+ it("previous and new active unknowns render labels", () => {
+ const html = renderToStaticMarkup(
+
,
+ );
+
+ expect(html).toContain("Previous active unknown");
+ expect(html).toContain("Complaint rate denominator");
+ expect(html).toContain("New active unknown");
+ expect(html).toContain("Unknown node (ID: n-next-unknown)");
+ });
+
+ it("raw ids remain only in collapsed proposal details", () => {
+ const html = renderToStaticMarkup(
+
,
+ );
+
+ expect(html).toContain("Proposal details");
+ expect(html).toContain(""resolvedUnknownNodeIds"");
+ });
+
+ it("update diagnostics render valid values", () => {
+ const html = renderToStaticMarkup(
+
,
+ );
+
+ expect(html).toContain("v0.4");
+ expect(html).toContain("456ms");
+ expect(html).toContain("7");
+ expect(html).toContain("3");
+ expect(html).toContain("✅ valid");
+ });
+
+ it("structured update error renders", () => {
+ const html = renderToStaticMarkup(
+
,
+ );
+
+ expect(html).toContain("Update error: Invalid graph update proposal");
+ expect(html).toContain("bad proposal");
+ });
+
+ it("proposal details remain collapsible", () => {
+ const html = renderToStaticMarkup(
+
,
+ );
+
+ expect(html).toContain("Proposal details");
+ });
});
\ No newline at end of file