eleven / ocho Public

Clone
git clone https://amadan.net/eleven/ocho

Plain git — no account needed to clone.

Download

Download this file

1// 🤖 The quick-form planner: form values → the exact verbs + step records the
2// conversational path would produce. The records here are pinned against the
3// flow documents' own labels — if a flow's record copy changes, this test (and
4// the planner) must change with it, or the two paths' transcripts diverge.
5import assert from "node:assert/strict";
6import { test } from "node:test";
7import { planQuickForm } from "../web/static/quickform.js";
8import SETUP_FLOW from "../web/static/setup.flow.js";
9import WELCOME_FLOW from "../web/static/welcome.flow.js";
10
11await test("welcome plan: cleaned name + the photo skip record", () => {
12 // The same clean-before-cap rule as the typed answer ("I'm Dermot" → Dermot).
13 const p = planQuickForm("welcome", { name: " Hi, I'm Dermot! " });
14 assert.equal(p.name, "Dermot");
15 assert.deepEqual(p.verbs, [{ verb: "setMyName", args: ["Dermot"] }]);
16 assert.deepEqual(p.records, [
17 { step: "name", label: "noted: you're Dermot", value: "Dermot" },
18 { step: "photo", label: "skipped the profile photo", value: "skipped" },
19 ]);
20});
21
22await test("welcome plan: the 32-char cap holds after cleaning", () => {
23 const p = planQuickForm("welcome", { name: "my name is " + "A".repeat(40) });
24 assert.equal(p.name, "A".repeat(32));
25});
26
27await test("setup plan, everything on: no setFeature writes, the one-tap extras record", () => {
28 const p = planQuickForm("setup", {
29 name: "Paul",
30 spaceName: " Team Awesome ",
31 email: "paul@example.com",
32 invites: true,
33 ai: true,
34 bots: true,
35 apps: true,
36 });
37 assert.deepEqual(p.verbs, [
38 { verb: "setMyName", args: ["Paul"] },
39 { verb: "setGroupName", args: ["Team Awesome"] },
40 { verb: "setContactEmail", args: ["paul@example.com"] },
41 { verb: "setUserInvites", args: [true] },
42 // AI is its own explicit opt-in: ALWAYS written, even in the
43 // everything-on plan (bots/apps stay write-nothing defaults).
44 { verb: "setFeature", args: ["ai", true] },
45 ]);
46 assert.deepEqual(p.records, [
47 { step: "name", label: "noted: you're Paul", value: "Paul" },
48 { step: "group", label: "named this space “Team Awesome”", value: "Team Awesome" },
49 { step: "email", label: "noted a contact email", value: "paul@example.com" },
50 { step: "photo", label: "skipped the space photo", value: "skipped" },
51 { step: "invites", label: "decided members can invite people", value: "members" },
52 { step: "extras", label: "kept bots and apps on", value: "all-on" },
53 { step: "ai-optin", label: "invited Eleven's AI in", value: "on" },
54 ]);
55});
56
57await test("setup plan, granular extras + skipped email + admin-only invites", () => {
58 const p = planQuickForm("setup", {
59 name: "Paul",
60 spaceName: "Team Awesome",
61 email: " ",
62 invites: false,
63 ai: false,
64 bots: true,
65 apps: false,
66 });
67 assert.equal(p.verbs.some((v) => v.verb === "setContactEmail"), false, "an empty email writes nothing");
68 assert.deepEqual(p.verbs.filter((v) => v.verb === "setFeature"), [
69 { verb: "setFeature", args: ["bots", true] },
70 { verb: "setFeature", args: ["apps", false] },
71 { verb: "setFeature", args: ["ai", false] },
72 ]);
73 assert.deepEqual(p.verbs.find((v) => v.verb === "setUserInvites"), { verb: "setUserInvites", args: [false] });
74 const by = Object.fromEntries(p.records.map((r) => [r.step, r]));
75 assert.deepEqual(by.email, { step: "email", label: "skipped the contact email", value: "skipped" });
76 assert.deepEqual(by.invites, { step: "invites", label: "decided only the admin invites people", value: "admin only" });
77 assert.deepEqual(by["extras-bots"], { step: "extras-bots", label: "enabled bots", value: "on" });
78 assert.deepEqual(by["extras-apps"], { step: "extras-apps", label: "switched apps off", value: "off" });
79 assert.deepEqual(by["ai-optin"], { step: "ai-optin", label: "kept AI off", value: "off" });
80 assert.equal(by.extras, undefined, "the one-tap record only when the pair stays on");
81});
82
83// The crucial invariant behind the fast-fill: every planned record names a
84// real step of its flow, so the resume machinery recognises them all.
85await test("planned record steps all exist in their flow documents", () => {
86 for (const [kind, flow, values] of [
87 ["welcome", WELCOME_FLOW, { name: "Paul" }],
88 ["setup", SETUP_FLOW, { name: "Paul", spaceName: "X", email: "a@b.c", ai: false, bots: false, apps: false }],
89 ["setup", SETUP_FLOW, { name: "Paul", spaceName: "X", email: "" }],
90 ]) {
91 const ids = new Set(flow.steps.map((s) => s.id));
92 for (const r of planQuickForm(kind, values).records) {
93 assert.ok(ids.has(r.step), `${kind}: record for unknown step ${r.step}`);
94 }
95 }
96});
97