// 🤖 The quick-form planner: form values → the exact verbs + step records the // conversational path would produce. The records here are pinned against the // flow documents' own labels — if a flow's record copy changes, this test (and // the planner) must change with it, or the two paths' transcripts diverge. import assert from "node:assert/strict"; import { test } from "node:test"; import { planQuickForm } from "../web/static/quickform.js"; import SETUP_FLOW from "../web/static/setup.flow.js"; import WELCOME_FLOW from "../web/static/welcome.flow.js"; await test("welcome plan: cleaned name + the photo skip record", () => { // The same clean-before-cap rule as the typed answer ("I'm Dermot" → Dermot). const p = planQuickForm("welcome", { name: " Hi, I'm Dermot! " }); assert.equal(p.name, "Dermot"); assert.deepEqual(p.verbs, [{ verb: "setMyName", args: ["Dermot"] }]); assert.deepEqual(p.records, [ { step: "name", label: "noted: you're Dermot", value: "Dermot" }, { step: "photo", label: "skipped the profile photo", value: "skipped" }, ]); }); await test("welcome plan: the 32-char cap holds after cleaning", () => { const p = planQuickForm("welcome", { name: "my name is " + "A".repeat(40) }); assert.equal(p.name, "A".repeat(32)); }); await test("setup plan, everything on: no setFeature writes, the one-tap extras record", () => { const p = planQuickForm("setup", { name: "Paul", spaceName: " Team Awesome ", email: "paul@example.com", invites: true, ai: true, bots: true, apps: true, }); assert.deepEqual(p.verbs, [ { verb: "setMyName", args: ["Paul"] }, { verb: "setGroupName", args: ["Team Awesome"] }, { verb: "setContactEmail", args: ["paul@example.com"] }, { verb: "setUserInvites", args: [true] }, // AI is its own explicit opt-in: ALWAYS written, even in the // everything-on plan (bots/apps stay write-nothing defaults). { verb: "setFeature", args: ["ai", true] }, ]); assert.deepEqual(p.records, [ { step: "name", label: "noted: you're Paul", value: "Paul" }, { step: "group", label: "named this space “Team Awesome”", value: "Team Awesome" }, { step: "email", label: "noted a contact email", value: "paul@example.com" }, { step: "photo", label: "skipped the space photo", value: "skipped" }, { step: "invites", label: "decided members can invite people", value: "members" }, { step: "extras", label: "kept bots and apps on", value: "all-on" }, { step: "ai-optin", label: "invited Eleven's AI in", value: "on" }, ]); }); await test("setup plan, granular extras + skipped email + admin-only invites", () => { const p = planQuickForm("setup", { name: "Paul", spaceName: "Team Awesome", email: " ", invites: false, ai: false, bots: true, apps: false, }); assert.equal(p.verbs.some((v) => v.verb === "setContactEmail"), false, "an empty email writes nothing"); assert.deepEqual(p.verbs.filter((v) => v.verb === "setFeature"), [ { verb: "setFeature", args: ["bots", true] }, { verb: "setFeature", args: ["apps", false] }, { verb: "setFeature", args: ["ai", false] }, ]); assert.deepEqual(p.verbs.find((v) => v.verb === "setUserInvites"), { verb: "setUserInvites", args: [false] }); const by = Object.fromEntries(p.records.map((r) => [r.step, r])); assert.deepEqual(by.email, { step: "email", label: "skipped the contact email", value: "skipped" }); assert.deepEqual(by.invites, { step: "invites", label: "decided only the admin invites people", value: "admin only" }); assert.deepEqual(by["extras-bots"], { step: "extras-bots", label: "enabled bots", value: "on" }); assert.deepEqual(by["extras-apps"], { step: "extras-apps", label: "switched apps off", value: "off" }); assert.deepEqual(by["ai-optin"], { step: "ai-optin", label: "kept AI off", value: "off" }); assert.equal(by.extras, undefined, "the one-tap record only when the pair stays on"); }); // The crucial invariant behind the fast-fill: every planned record names a // real step of its flow, so the resume machinery recognises them all. await test("planned record steps all exist in their flow documents", () => { for (const [kind, flow, values] of [ ["welcome", WELCOME_FLOW, { name: "Paul" }], ["setup", SETUP_FLOW, { name: "Paul", spaceName: "X", email: "a@b.c", ai: false, bots: false, apps: false }], ["setup", SETUP_FLOW, { name: "Paul", spaceName: "X", email: "" }], ]) { const ids = new Set(flow.steps.map((s) => s.id)); for (const r of planQuickForm(kind, values).records) { assert.ok(ids.has(r.step), `${kind}: record for unknown step ${r.step}`); } } });