W5: probe/teach phases — divider + collapsed teach checks
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Phase derivation (W5, vision §2 "two phases") — the probe→teach boundary.
|
||||
*
|
||||
* phaseAt is the pure seam-finder: plan_init IS the transition marker, so the
|
||||
* first message containing a tool-plan_init part flips everything from it
|
||||
* onward to "teach". The boundary cases here are the ones the UI leans on:
|
||||
* teach checks collapse behind the reveal button, probe questions auto-open.
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { phaseAt, type PhaseMessage } from "../src/core/phases.ts";
|
||||
|
||||
/** A minimal message: just typed parts, exactly the structural slice phaseAt reads. */
|
||||
function msg(...partTypes: string[]): PhaseMessage {
|
||||
return { parts: partTypes.map((type) => ({ type })) };
|
||||
}
|
||||
|
||||
/** Realistic shape: full tool part objects with state fields (extra fields ignored). */
|
||||
function toolMsg(...parts: { type: string; state: string; toolCallId: string }[]): PhaseMessage {
|
||||
return { parts };
|
||||
}
|
||||
|
||||
describe("phaseAt", () => {
|
||||
it("no messages → probe", () => {
|
||||
assert.equal(phaseAt([]), "probe");
|
||||
});
|
||||
|
||||
it("no plan_init anywhere → probe at every index (pre-plan sessions keep the old behavior)", () => {
|
||||
const messages = [
|
||||
msg("text"),
|
||||
msg("text", "tool-quiz", "text"),
|
||||
toolMsg({ type: "tool-quiz", state: "input-available", toolCallId: "q1" }),
|
||||
msg("text"),
|
||||
];
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
assert.equal(phaseAt(messages, i), "probe", `index ${i}`);
|
||||
}
|
||||
assert.equal(phaseAt(messages), "probe");
|
||||
});
|
||||
|
||||
it("the boundary: probe before the plan_init message, teach from it onward", () => {
|
||||
const messages = [
|
||||
msg("text"), // probe chatter
|
||||
msg("text", "tool-quiz"), // probe question
|
||||
msg("text", "tool-plan_init", "text"), // ← the seam (divider renders here)
|
||||
msg("text", "tool-quiz"), // a check — teach phase
|
||||
msg("text"),
|
||||
];
|
||||
assert.equal(phaseAt(messages, 0), "probe");
|
||||
assert.equal(phaseAt(messages, 1), "probe");
|
||||
assert.equal(phaseAt(messages, 2), "teach", "the message containing plan_init is already teach");
|
||||
assert.equal(phaseAt(messages, 3), "teach");
|
||||
assert.equal(phaseAt(messages, 4), "teach");
|
||||
assert.equal(phaseAt(messages), "teach", "default = current phase (last message)");
|
||||
});
|
||||
|
||||
it("multiple plan_init parts → the FIRST wins (a later re-init never moves the seam)", () => {
|
||||
const messages = [
|
||||
msg("text"),
|
||||
msg("tool-plan_init"), // first — the seam
|
||||
msg("text"),
|
||||
msg("tool-plan_init"), // a refused re-init attempt: must not matter
|
||||
msg("text"),
|
||||
];
|
||||
assert.equal(phaseAt(messages, 0), "probe");
|
||||
assert.equal(phaseAt(messages, 1), "teach");
|
||||
assert.equal(phaseAt(messages, 2), "teach", "between the two plan_inits: already teach (first wins)");
|
||||
assert.equal(phaseAt(messages, 3), "teach");
|
||||
});
|
||||
|
||||
it("any part state counts — the call itself is the transition, even mid-stream", () => {
|
||||
const messages = [
|
||||
msg("text"),
|
||||
toolMsg({ type: "tool-plan_init", state: "input-streaming", toolCallId: "p1" }),
|
||||
];
|
||||
assert.equal(phaseAt(messages, 1), "teach");
|
||||
});
|
||||
|
||||
it("upToIndex past the end / negative → clamped, never throws", () => {
|
||||
const messages = [msg("tool-plan_init")];
|
||||
assert.equal(phaseAt(messages, 99), "teach");
|
||||
assert.equal(phaseAt(messages, -1), "probe", "empty scan range → probe");
|
||||
assert.equal(phaseAt([]), "probe");
|
||||
});
|
||||
});
|
||||
@@ -18,6 +18,7 @@ import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { MessageResponse } from "../components/ai-elements/message.tsx";
|
||||
import { QuestionDock } from "../components/question-dock.tsx";
|
||||
import { AnsweredCard } from "../components/answered-card.tsx";
|
||||
import { PlanDivider } from "../components/artifacts/plan-divider.tsx";
|
||||
import { buildAnswer, coerceCorrectAnswer, normalizeOptions, resolveCorrect, type QuestionData } from "../src/core/question-core.ts";
|
||||
|
||||
const quizInput = {
|
||||
@@ -171,4 +172,92 @@ describe("math rendering (streamdown + KaTeX)", () => {
|
||||
);
|
||||
assert.ok(answeredHtml.includes("katex"), "answered card: option/explanation math renders");
|
||||
});
|
||||
});
|
||||
|
||||
describe("teach-check reveal (W5 phase separation)", () => {
|
||||
// The collapsed dock renders the bar AND the hidden form (it stays mounted
|
||||
// so a half-made selection survives) — assertions target the bar species.
|
||||
it("teach-phase check collapses into the invitation bar, not the scroll bar", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<QuestionDock
|
||||
toolName="quiz"
|
||||
toolCallId="t1"
|
||||
input={quizInput as never}
|
||||
expanded={false}
|
||||
reveal
|
||||
onExpand={() => {}}
|
||||
onSubmit={() => {}}
|
||||
/>,
|
||||
);
|
||||
assert.ok(html.includes('data-testid="teach-check-reveal"'), "invitation affordance present");
|
||||
assert.match(html, /Check your understanding/);
|
||||
assert.match(html, /Which planet is closest/, "question teaser invites, not minimizes");
|
||||
assert.match(html, /Open/, "a clear reveal action");
|
||||
});
|
||||
|
||||
it("probe questions keep the plain collapsed bar (no invitation copy)", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<QuestionDock
|
||||
toolName="quiz"
|
||||
toolCallId="q1"
|
||||
input={quizInput as never}
|
||||
expanded={false}
|
||||
onExpand={() => {}}
|
||||
onSubmit={() => {}}
|
||||
/>,
|
||||
);
|
||||
assert.ok(html.includes('data-testid="question-dock-bar"'), "the scroll-collapse strip");
|
||||
assert.ok(!html.includes("Check your understanding"), "no invitation copy outside teach phase");
|
||||
assert.match(html, /Answer/, "the strip keeps its Answer affordance");
|
||||
});
|
||||
|
||||
it("after the reveal, the teach check renders the full form (probe default, unchanged)", () => {
|
||||
// Post-click: expanded=true — exactly today's dock. The probe auto-open
|
||||
// path renders the identical form; this is also the regression pin for it.
|
||||
const html = renderDock({ toolName: "quiz", toolCallId: "t1", input: quizInput as never });
|
||||
assert.ok(html.includes('data-testid="question-dock"'), "the form is the dock's content once expanded");
|
||||
assert.match(html, /Submit answer/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("PlanDivider (the probe→teach seam)", () => {
|
||||
const tree = {
|
||||
nodes: [
|
||||
{ id: "a", title: "A" },
|
||||
{ id: "b", title: "B" },
|
||||
{ id: "c", title: "C" },
|
||||
],
|
||||
edges: [{ from: "a", to: "b" }],
|
||||
currentNodeId: null,
|
||||
doneNodeIds: [],
|
||||
version: 1,
|
||||
};
|
||||
|
||||
it("renders the quiet divider with the node count once output-available", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<PlanDivider part={{ type: "tool-plan_init", state: "output-available", toolCallId: "p1", output: { ok: true, tree } }} />,
|
||||
);
|
||||
assert.ok(html.includes('data-testid="plan-divider"'));
|
||||
assert.match(html, /Teaching/);
|
||||
assert.match(html, /3 nodes/, "node count from the output tree");
|
||||
assert.ok(!html.includes("banner"), "never a loud banner");
|
||||
});
|
||||
|
||||
it("renders null while the tool streams and on a failed init", () => {
|
||||
const streaming = renderToStaticMarkup(
|
||||
<PlanDivider part={{ type: "tool-plan_init", state: "input-streaming", toolCallId: "p1" }} />,
|
||||
);
|
||||
assert.equal(streaming, "", "null while input-streaming");
|
||||
const failed = renderToStaticMarkup(
|
||||
<PlanDivider
|
||||
part={{
|
||||
type: "tool-plan_init",
|
||||
state: "output-available",
|
||||
toolCallId: "p1",
|
||||
output: { ok: false, error: "Tree already initialized", tree },
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
assert.equal(failed, "", "a refused re-init must not draw a second seam");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user