Diagnosis (2026-09-11 user testing, minimal-effort GLM): sessions stuck on 'plan' forever. Two causes: (1) the three-phase view read the stored tree's currentNodeId, which nothing ever writes post author-once (2026-09-03) — a structural dead seam; (2) the teacher stochastically left quiz.nodeId untagged, and done-by-quiz-result semantics would have falsely completed nodes anyway. The redesign (docs/probe-teach-split.md) abolishes derived occupancy in favor of explicit events: - Two agents over one transcript: createProberAgent (quiz without a nodeId field, ask, probe_done) and createTeacherAgent (full toolset, plan_init onward). The chat-handler construction branch keys on a probe_done part in the transcript. MODELS.prober added. - probe_done: server-side seam tool — carries the learner assessment (strands + free-form edge read), refuses while a question is open or the probe is already concluded, and queues a handoff steer through the generalized wake pipeline (steers now dedupe by id, not jobId; job finalization only for job steers). The teacher auto-wakes and authors the plan; the learner sees the assessment via the probe-done card. - phases: probe ends at a concluded probe_done, plan ends at a successful plan_init — strictly sequential, no skipping, no legacy compatibility (data wiped at the pivot per doctrine). - Plan map = position, not completion: derivePlanStatuses reads only tagged quiz CALLS (state/outcome feed nothing); current = latest tagged node with consecutive duplicates collapsed, visited = earlier distinct stays (a revisit stays in both — current wins at render). PlanTree is structure-only; currentNodeId/doneNodeIds and the dead mutation helpers are gone. No fallback current. - Prompts split per agent (prompts/prober/, prompts/teacher/ over the trimmed shared base); graph-context injection removed entirely (shelved, docs/probe-teach-split.md §5); knowledge-graph context no longer reaches either agent. - Plan blocks are full-only snapshots at plan_init (neighborhood machinery retired; the persistent DAG window is the future UI wave); usage capture unchanged. Gates: tsc clean, 294/294 tests (phases/plan-tree/plan-blocks/question- tools rewritten to the new semantics; probe-done + handoff-wake tests added), lint, build. Live GLM smoke PASS: prober concluded with an honest assessment, teacher auto-woke, authored a 10-node plan with the block attached, then tagged checks on slope-instinct → secant derived current/ visited exactly as designed; grading honest both ways (driver off-by-one proved a wrong answer grades false).
147 lines
5.0 KiB
TypeScript
147 lines
5.0 KiB
TypeScript
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
PlanBlock,
|
|
PlanPopup,
|
|
blockLayout,
|
|
topoFor,
|
|
wrapTitle,
|
|
GAP_X,
|
|
NODE_H,
|
|
NODE_W,
|
|
type PopupMessage,
|
|
} from "../components/plan-block.tsx";
|
|
import type { PlanBlockData, PlanTree } from "../src/core/contracts.ts";
|
|
|
|
// Plan blocks: the pure layered layout, the frozen-snapshot rendering
|
|
// (full = borderless + column-filling
|
|
// with the glowing current), and the popup's LIVE derivation.
|
|
|
|
const CHAIN: PlanTree = {
|
|
nodes: [
|
|
{ id: "a", title: "Alpha node" },
|
|
{ id: "b", title: "Beta node" },
|
|
{ id: "c", title: "Gamma node" },
|
|
],
|
|
edges: [
|
|
{ from: "a", to: "b" },
|
|
{ from: "b", to: "c" },
|
|
],
|
|
version: 1,
|
|
};
|
|
|
|
describe("plan block layout (pure)", () => {
|
|
it("layers a chain top-down, one node per depth row", () => {
|
|
const { order, depth } = topoFor(CHAIN.nodes, CHAIN.edges);
|
|
assert.deepEqual(order.map((n) => n.id), ["a", "b", "c"]);
|
|
assert.equal(depth.get("c"), 2);
|
|
const layout = blockLayout(CHAIN.nodes, CHAIN.edges);
|
|
assert.equal(layout.width, NODE_W); // widest row is the single-node rows
|
|
assert.equal(layout.height, 3 * NODE_H + 2 * 48);
|
|
});
|
|
|
|
it("centers same-depth nodes over the widest row; tolerates dangling edges", () => {
|
|
const nodes = [
|
|
{ id: "r", title: "Root" },
|
|
{ id: "x", title: "Left" },
|
|
{ id: "y", title: "Right" },
|
|
];
|
|
const layout = blockLayout(nodes, [
|
|
{ from: "r", to: "x" },
|
|
{ from: "r", to: "y" },
|
|
{ from: "ghost", to: "r" }, // dangling: ignored defensively
|
|
]);
|
|
assert.equal(layout.width, 2 * NODE_W + GAP_X);
|
|
// Root centered over its two children: (2*W+GAP - W)/2
|
|
assert.equal(layout.x.get("r"), (2 * NODE_W + GAP_X - NODE_W) / 2);
|
|
assert.ok(layout.x.get("x") === 0 && layout.x.get("y") === NODE_W + GAP_X);
|
|
});
|
|
|
|
it("wrapTitle wraps greedily and ellipsizes overflow", () => {
|
|
assert.deepEqual(wrapTitle("Chain rule intuition"), ["Chain rule intuition"]); // exactly 20 chars — fits one line
|
|
assert.deepEqual(wrapTitle("Chain rule intuition and fluency"), ["Chain rule intuition", "and fluency"]);
|
|
assert.deepEqual(wrapTitle("supercalifragilisticexpialidocious word"), ["supercalifragilisti…", "word"]); // oversized word hard-clamped, overflow dropped
|
|
assert.deepEqual(wrapTitle("supercalifragilistic"), ["supercalifragilistic"]); // exactly maxChars — fits
|
|
});
|
|
});
|
|
|
|
describe("plan block render", () => {
|
|
it("full block: borderless, column-filling, statuses AS CARRIED (never re-derived)", () => {
|
|
const data: PlanBlockData = {
|
|
kind: "full",
|
|
at: "2026-09-09T12:00:00Z",
|
|
current: null,
|
|
nodes: [
|
|
{ id: "a", title: "Alpha node", status: "visited" },
|
|
{ id: "b", title: "Beta node", status: "upcoming" },
|
|
],
|
|
edges: [{ from: "a", to: "b" }],
|
|
};
|
|
const html = renderToStaticMarkup(<PlanBlock data={data} onOpen={() => {}} />);
|
|
assert.match(html, /data-testid="plan-block-full"/);
|
|
// Borderless: the wrapper carries no border/rounded chrome.
|
|
assert.ok(!/data-testid="plan-block-full"[^>]*border/.test(html), "no wrapping chrome");
|
|
// Fills the column: the svg is w-full with the layout extent as viewBox
|
|
// (leftmost/rightmost nodes hug the edges), height natural.
|
|
assert.match(html, /<svg[^>]*class="block h-auto w-full"/);
|
|
// Two stacked nodes: 2*NODE_H + GAP_Y = 136 natural height, width = one node column.
|
|
assert.match(html, /viewBox="0 0 160 136"/);
|
|
// Snapshot statuses render as carried.
|
|
assert.match(html, /data-testid="plan-node-a" data-status="visited"/);
|
|
assert.match(html, /data-testid="plan-node-b" data-status="upcoming"/);
|
|
assert.match(html, /Open the full plan/);
|
|
});
|
|
|
|
});
|
|
|
|
describe("plan popup (live derivation)", () => {
|
|
function messages(): PopupMessage[] {
|
|
return [
|
|
{
|
|
parts: [
|
|
{
|
|
type: "tool-plan_init",
|
|
state: "output-available",
|
|
output: { ok: true, tree: CHAIN },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
parts: [
|
|
{
|
|
type: "tool-quiz",
|
|
state: "output-available",
|
|
input: { nodeId: "a" },
|
|
output: { correct: true },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
parts: [
|
|
{
|
|
type: "tool-quiz",
|
|
state: "input-available",
|
|
input: { nodeId: "b" },
|
|
},
|
|
],
|
|
},
|
|
];
|
|
}
|
|
|
|
it("derives statuses at click time: latest tagged call → current, earlier → visited (glowing)", () => {
|
|
const html = renderToStaticMarkup(<PlanPopup messages={messages()} onClose={() => {}} />);
|
|
assert.match(html, /data-testid="plan-popup"/);
|
|
assert.match(html, /data-testid="plan-node-a" data-status="visited"/);
|
|
assert.match(html, /data-testid="plan-node-b" data-status="current"/);
|
|
assert.match(html, /data-testid="plan-node-c" data-status="upcoming"/);
|
|
// The current node is the glow target.
|
|
assert.match(html, /stroke-primary\/70 animate-pulse/);
|
|
assert.match(html, /live — statuses derive from your check outcomes/);
|
|
});
|
|
|
|
it("renders the empty state when the session has no plan", () => {
|
|
const html = renderToStaticMarkup(<PlanPopup messages={[{ parts: [] }]} onClose={() => {}} />);
|
|
assert.match(html, /No plan in this session yet\./);
|
|
});
|
|
}); |