eleven / messenger Public

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

Plain git — no account needed to clone.

Download

Download this file

1// The flow engine + setup flow, driven end-to-end in Node with a fake io —
2// the whole conversation (bubbles, chips, typed answers, photo, validation
3// branches, the passkey probe) without a browser. This is the transcript-level
4// proof that the flow-as-data refactor preserved setup.js's behaviour, and the
5// fixture discipline the Swift interpreter will inherit.
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { runFlow, renderText, evalCond, cleanNameAnswer } from "../web/static/flow.js";
9import SETUP_FLOW from "../web/static/setup.flow.js";
10import WELCOME_FLOW from "../web/static/welcome.flow.js";
11
12const tick = () => new Promise((r) => setImmediate(r));
13
14// A fake io that mirrors the real engine surface: say dedupes by key||text
15// (like eleven.js) but always re-arms chips; verbs return scripted results.
16function harness({ verbs = {}, done = {}, enrolled = false, fromHome = false, canEnrol = true, myName = "", planBook = null, envExtra = {} } = {}) {
17 const h = {
18 transcript: [], // { text, chips: [labels], extra }
19 verbLog: [],
20 records: [],
21 said: new Set(),
22 lastChips: null,
23 pendingAsk: null,
24 pendingDelays: [],
25 doneSteps: { ...done },
26 enrolled,
27 fromHome,
28 canEnrol,
29 myName,
30 };
31 h.env = {
32 threadId: "T",
33 respond: () => {},
34 typing: null,
35 sender: { name: "Eleven", kind: "bot" },
36 bridge: {
37 myName: () => h.myName,
38 enrolled: () => h.enrolled,
39 fromHome: () => h.fromHome,
40 // Whether signing in is possible at all (#1377) — false on self-hosted
41 // spaces with no home server; the flows skip the un-actionable pitch.
42 canEnrol: () => h.canEnrol,
43 // The plan step's price book (#1374) — mirrors apps/setup.js's getters;
44 // absent (the default) skips the step, like a self-hosted space.
45 planPrices: () => !!planBook,
46 planTeam: () => !!(planBook && planBook.team),
47 planCommunity: () => !!(planBook && planBook.community),
48 planFamily: () => !!(planBook && planBook.family),
49 planNameTeam: () => (planBook && planBook.team && planBook.team.name) || "",
50 planPriceTeam: () => (planBook && planBook.team && planBook.team.price) || "",
51 planNameCommunity: () => (planBook && planBook.community && planBook.community.name) || "",
52 planPriceCommunity: () => (planBook && planBook.community && planBook.community.price) || "",
53 planNameFamily: () => (planBook && planBook.family && planBook.family.name) || "",
54 planPriceFamily: () => (planBook && planBook.family && planBook.family.price) || "",
55 },
56 space: { name: "Old Name", nameSet: false },
57 onEnd: () => (h.ended = true),
58 };
59 Object.assign(h.env, envExtra);
60 h.io = {
61 say: (env, text, chips, extra) => {
62 const key = (extra && extra.key) || text;
63 if (!(extra && extra.local) && h.said.has(key)) {
64 if (chips) h.lastChips = chips;
65 return;
66 }
67 if (!(extra && extra.local)) h.said.add(key);
68 h.transcript.push({ text, chips: (chips || []).map((c) => c.label), extra: extra || {} });
69 if (chips) h.lastChips = chips;
70 },
71 ask: (threadId, cb) => (h.pendingAsk = cb),
72 cancelAnswer: () => {
73 h.cancelled = (h.cancelled || 0) + 1;
74 h.pendingAsk = null;
75 },
76 verb: (name, args) => {
77 h.verbLog.push([name, ...args]);
78 const r = verbs[name];
79 return typeof r === "function" ? r(...args) : r;
80 },
81 record: (step, label, value) => {
82 h.records.push({ step, label, value });
83 h.doneSteps[step] = true;
84 },
85 done: (step) => !!h.doneSteps[step],
86 imgSource: (t) => `IMG(${t})`,
87 delay: (ms, fn) => h.pendingDelays.push({ ms, fn }),
88 };
89 h.answer = async (text, payload) => {
90 const cb = h.pendingAsk;
91 h.pendingAsk = null;
92 cb(text, payload);
93 await tick();
94 await tick();
95 };
96 h.tap = async (label) => {
97 const chip = (h.lastChips || []).find((c) => c.label === label);
98 assert.ok(chip, `chip "${label}" not offered (have: ${(h.lastChips || []).map((c) => c.label).join(", ")})`);
99 chip.run();
100 await tick();
101 await tick();
102 };
103 h.lastText = () => h.transcript[h.transcript.length - 1].text;
104 return h;
105}
106
107await test("cleanNameAnswer strips conversational replies down to the name", () => {
108 // The exact live failure: the "I'm {name}" chip primes typed replies too.
109 assert.equal(cleanNameAnswer("I'm Dermot"), "Dermot");
110 assert.equal(cleanNameAnswer("I’m Dermot"), "Dermot"); // iOS smart apostrophe
111 assert.equal(cleanNameAnswer("i am dermot"), "dermot"); // case kept as typed
112 assert.equal(cleanNameAnswer("My name is Ana."), "Ana");
113 assert.equal(cleanNameAnswer("Hi, I'm Dermot!"), "Dermot");
114 assert.equal(cleanNameAnswer("hello my name's Bo"), "Bo");
115 assert.equal(cleanNameAnswer("you can call me Dermo"), "Dermo");
116 assert.equal(cleanNameAnswer("It's Maud"), "Maud");
117 assert.equal(cleanNameAnswer("Im Dermot"), "Dermot"); // apostrophe skipped
118});
119
120await test("cleanNameAnswer leaves plain names (and lookalikes) alone", () => {
121 assert.equal(cleanNameAnswer("Dermot"), "Dermot");
122 assert.equal(cleanNameAnswer(" Dermot "), "Dermot");
123 assert.equal(cleanNameAnswer("Hilary"), "Hilary"); // "hi" needs a boundary
124 assert.equal(cleanNameAnswer("Ima Jean"), "Ima Jean"); // "im" needs a space
125 assert.equal(cleanNameAnswer("Mary-Kate O'Brien"), "Mary-Kate O'Brien");
126 // Stripping must never clean a name to nothing — keep the original.
127 assert.equal(cleanNameAnswer("I'm"), "I'm");
128 assert.equal(cleanNameAnswer(""), "");
129});
130
131await test("the name step cleans the typed answer — verb, record, and echo all use it", async () => {
132 const h = harness();
133 runFlow(SETUP_FLOW, h.env, h.io);
134 await tick();
135 await h.answer("Hi, I'm Dermot!");
136 assert.deepEqual(h.verbLog[0], ["setMyName", "Dermot"], "the screen name is the cleaned name");
137 assert.deepEqual(h.records[0], { step: "name", label: "noted: you're Dermot", value: "Dermot" });
138 const group = h.transcript.find((t) => /Lovely to meet you/.test(t.text));
139 assert.match(group.text, /^Lovely to meet you, Dermot! 🤝/, "the echo shows the cleaned name");
140});
141
142await test("flows are pure JSON — shippable to native interpreters", () => {
143 for (const FLOW of [SETUP_FLOW, WELCOME_FLOW]) {
144 assert.deepStrictEqual(JSON.parse(JSON.stringify(FLOW)), FLOW);
145 assert.equal(FLOW.schema, 1);
146 // Every goto/skipTo/auto/probe/record target names a real step.
147 const ids = new Set(FLOW.steps.map((s) => s.id));
148 const targets = JSON.stringify(FLOW).match(/"(?:goto|skipTo|auto|step)":"([^"]+)"/g) || [];
149 for (const t of targets) {
150 const id = t.split(":")[1].replaceAll('"', "");
151 assert.ok(ids.has(id), `${FLOW.flow}: dangling target ${id}`);
152 }
153 }
154});
155
156await test("setup: the full first-run transcript, happy path with detours", async () => {
157 const h = harness({
158 verbs: {
159 setGroupName: (name) => (name === "X" ? "invalid" : "ok"),
160 setContactEmail: (e) => (e.includes("@") ? "ok" : "invalid"),
161 adoptServerPhoto: () => true,
162 },
163 });
164 runFlow(SETUP_FLOW, h.env, h.io);
165 await tick();
166
167 // Greeting + name question (fresh run: not resumed, no "Welcome back").
168 assert.match(h.transcript[0].text, /^Hi — I'm Eleven! 👋/);
169 assert.equal(h.transcript[1].extra.label, "Your name:");
170 assert.equal(h.transcript[1].extra.hint, "e.g. Finn Wolfhard");
171 assert.equal(h.transcript.some((t) => /Welcome back/.test(t.text)), false);
172
173 // Name: 40 chars caps to 32 (the profile-rename cap).
174 await h.answer("A".repeat(40));
175 assert.deepEqual(h.verbLog[0], ["setMyName", "A".repeat(32)]);
176 assert.equal(h.records[0].step, "name");
177
178 // Group: ack folded into the context bubble; no Keep chip (nameSet=false).
179 // (lastChips still holds the name step's quick-form chip — a chipless say
180 // doesn't reset it — so check the Keep chip's absence, not emptiness.)
181 const group = h.transcript.find((t) => t.extra.key === "q-group");
182 assert.match(group.text, /^Lovely to meet you, A{32}! 🤝\n\nNext, this space needs a name/);
183 assert.equal((h.lastChips || []).some((c) => /^Keep/.test(c.label)), false, "no Keep chip on a fresh instance");
184
185 // Rejected name says the honest error and re-asks; accepted name records.
186 await h.answer("X");
187 assert.match(h.lastText(), /didn't stick — it needs to be 1–60/);
188 await h.answer("Team Awesome");
189 assert.equal(h.env.space.name, "Team Awesome");
190 assert.deepEqual(h.records[1], { step: "group", label: "named this space “Team Awesome”", value: "Team Awesome" });
191
192 // Email: invalid re-asks in place with the Skip chip still live.
193 await h.answer("not-an-email");
194 assert.match(h.lastText(), /doesn't look like an email address/);
195 assert.ok(h.lastChips.find((c) => c.label === "Skip for now"));
196 await h.answer("paul@example.com");
197 assert.equal(h.records[2].label, "noted a contact email");
198
199 // Photo: a text-only reply is rejected and the waiter re-arms.
200 await h.answer("here you go", { attachments: [] });
201 assert.match(h.lastText(), /Send it as a picture/);
202 await h.answer("Our logo", { attachments: [{ type: "image/jpeg", id: "img1" }] });
203 const adopt = h.verbLog.find((v) => v[0] === "adoptServerPhoto");
204 assert.equal(adopt[2], "Our logo", "message text rides as alt text");
205
206 // Preview: alt-text publicity warning verbatim, image bubble, Keep records.
207 assert.match(h.lastText(), /“Our logo” — and like the photo itself it's PUBLIC/);
208 assert.equal(h.transcript[h.transcript.length - 1].extra.img, "IMG($serverAvatar)");
209 await h.tap("Keep this photo");
210 assert.deepEqual(h.records[3], { step: "photo", label: "set the space photo", value: "Our logo" });
211
212 // Invites → extras → the AI opt-in → keys: the one-tap common path records
213 // and moves on, and AI is always its own explicit question.
214 await h.tap("Only me");
215 assert.ok(h.verbLog.find((v) => v[0] === "setUserInvites" && v[1] === false));
216 assert.ok(h.transcript.find((t) => /comes with a couple of extras/.test(t.text)));
217 await h.tap("Keep both on");
218 assert.ok(h.records.find((r) => r.step === "extras" && r.value === "all-on"));
219 assert.equal(h.verbLog.some((v) => v[0] === "setFeature"), false, "keeping defaults writes nothing");
220 assert.ok(h.transcript.find((t) => /read the chats it's invited to/.test(t.text)), "the AI question carries the honest note");
221 await h.tap("Bring Eleven in");
222 assert.deepEqual(h.verbLog.at(-1), ["setFeature", "ai", true], "opting in writes the gate explicitly");
223 assert.ok(h.records.find((r) => r.step === "ai-optin" && r.value === "on"));
224 assert.ok(h.transcript.find((t) => /Now the most important thing of all/.test(t.text)));
225 await h.tap("Sign in");
226 assert.ok(h.verbLog.find((v) => v[0] === "savePasskey"));
227
228 // The probe fires with no enrolment → the stayed-in-place waiting step. (The
229 // step also arms a background settle poll; target the probe by its interval.)
230 const keysProbe = h.pendingDelays.find((d) => d.ms === 1500);
231 assert.ok(keysProbe, "the Sign in probe schedules a 1500ms check");
232 keysProbe.fn();
233 await tick();
234 assert.match(h.lastText(), /I'll wait here while you finish/);
235
236 // They finish the ceremony elsewhere; Continue records the verified label.
237 h.enrolled = true;
238 await h.tap("Continue");
239 assert.deepEqual(h.records.find((r) => r.step === "keys"), { step: "keys", label: "Signed in — your space's key is safe", value: "passkey" });
240 assert.deepEqual(h.records.at(-1), { step: "finish", label: "Your space is ready", value: "done" }, "finish persists its completion marker");
241
242 // Finish: complete marked, no reminder deferral (backed up), no nag line.
243 assert.ok(h.verbLog.find((v) => v[0] === "markSetupComplete"));
244 assert.equal(h.verbLog.some((v) => v[0] === "deferBackupReminders"), false);
245 const fin = h.transcript.find((t) => /Team Awesome is ready! 🎉/.test(t.text));
246 assert.equal(/One more reminder/.test(fin.text), false);
247 await h.tap("Open admin");
248 assert.ok(h.verbLog.find((v) => v[0] === "openAdmin"));
249 assert.ok(h.ended, "flow signalled completion");
250});
251
252await test("setup: a device that already knows the name RECORDS the skip so other clients converge", async () => {
253 // The 2026-07-19 web-vs-Mac divergence: a second device joining mid-flow
254 // with the member's name already known (an add-device link ships it in the
255 // fragment) skipped the name step via a bare skipIf — nothing landed in
256 // the log, so a client that did NOT know the name stayed armed on
257 // "Your name:" forever while this one moved on. The skip must be a
258 // recorded entry: done.name folds to every client.
259 const h = harness({ myName: "Paul" });
260 runFlow(SETUP_FLOW, h.env, h.io);
261 await tick();
262
263 // First run with a name: still greeted (resumedIf deliberately ignores
264 // bridge.myName — the creator's first run keeps its hello), the name
265 // question never asked, and — the fix — the skip is IN THE LOG.
266 assert.match(h.transcript[0].text, /^Hi — I'm Eleven!/);
267 assert.equal(h.transcript.some((t) => /what should everyone here call you/.test(t.text)), false);
268 assert.ok(h.records.find((r) => r.step === "name"), "the known-name skip writes done.name");
269
270 // A nameless client folding that record lands on the same step (group)
271 // instead of re-arming the name question.
272 const h2 = harness({ done: { name: true } });
273 runFlow(SETUP_FLOW, h2.env, h2.io);
274 await tick();
275 assert.equal(h2.transcript.some((t) => /what should everyone here call you/.test(t.text)), false);
276 assert.ok(h2.transcript.find((t) => t.extra.key === "q-group"), "converged on the group step");
277});
278
279await test("setup: a reentry re-derive resumes quietly — no 'Welcome back' spam", async () => {
280 // env.reentry marks a mid-session restart (the setup host reboots the flow
281 // when ANOTHER client answers the parked step). It re-derives position from
282 // the folded log like any resume, but must not re-greet: one "Welcome back"
283 // per foreign answer would spam the feed.
284 const h = harness({ myName: "Paul", done: { name: true, group: true }, envExtra: { reentry: true } });
285 runFlow(SETUP_FLOW, h.env, h.io);
286 await tick();
287 assert.equal(h.transcript.some((t) => /^Welcome back/.test(t.text)), false, "no re-greeting");
288 // …and it still lands parked on the first unanswered step (email).
289 assert.ok(h.transcript.find((t) => /How can people here reach you outside the chat/.test(t.text)));
290});
291
292await test("setup: resumed run — skips, Keep chip, skip-everything path", async () => {
293 // Resumed = a recorded step (done.name), not merely a set name — a name
294 // alone is the native creator's FIRST run and still gets the greeting.
295 const h = harness({ myName: "Paul", done: { name: true }, verbs: { setContactEmail: () => "ok" } });
296 h.env.space = { name: "Old Name", nameSet: true };
297 runFlow(SETUP_FLOW, h.env, h.io);
298 await tick();
299
300 // Resumed: brief local re-greeting, name step skipped entirely.
301 assert.match(h.transcript[0].text, /^Welcome back/);
302 assert.equal(h.transcript[0].extra.local, true);
303 assert.equal(h.transcript.some((t) => /what should everyone here call you/.test(t.text)), false);
304
305 // Group offers keeping the explicitly-set current name.
306 assert.match(h.transcript.find((t) => t.extra.key === "q-group").text, /^Next, this space needs a name/);
307 await h.tap("Keep “Old Name”");
308 assert.equal(h.verbLog.some((v) => v[0] === "setGroupName"), false, "Keep never re-saves the name");
309
310 await h.tap("Skip for now"); // email
311 await h.tap("Skip for now"); // photo — must disarm the waiter
312 assert.equal(h.cancelled, 1, "photo skip cancels the pending answer");
313 await h.tap("Members can invite people");
314 await h.tap("Keep both on");
315 await h.tap("Not now"); // the AI opt-in — declining writes an explicit off
316 assert.deepEqual(h.verbLog.at(-1), ["setFeature", "ai", false]);
317
318 // Keys: decline twice through the plain-words confirm.
319 await h.tap("Not now");
320 assert.match(h.lastText(), /I have to be straight with you/);
321 await h.tap("I understand the risk");
322 assert.deepEqual(h.records.find((r) => r.step === "keys"), { step: "keys", label: "Skipped signing in for now", value: "skipped" });
323 assert.deepEqual(h.records.at(-1), { step: "finish", label: "Your space is ready", value: "done" });
324
325 // Finish without a backup: reminders deferred, the nag line present.
326 assert.ok(h.verbLog.find((v) => v[0] === "deferBackupReminders"));
327 assert.ok(h.verbLog.find((v) => v[0] === "markSetupComplete"));
328 assert.ok(h.transcript.find((t) => /One more reminder before you go/.test(t.text)));
329 assert.ok(h.transcript.find((t) => /Old Name is ready! 🎉/.test(t.text)));
330});
331
332await test("setup: already enrolled — keys short-circuits with the once-only ack", async () => {
333 const h = harness({
334 myName: "Paul",
335 enrolled: true,
336 done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true },
337 });
338 runFlow(SETUP_FLOW, h.env, h.io);
339 await tick();
340 assert.deepEqual(h.records[0], { step: "keys", label: "Signed in — your space's key is safe", value: "passkey" });
341 assert.ok(h.transcript.find((t) => /your space's key is safe. ✅/.test(t.text)));
342 assert.equal(h.verbLog.some((v) => v[0] === "deferBackupReminders"), false);
343 assert.ok(h.verbLog.find((v) => v[0] === "markSetupComplete"));
344
345 // Second entry with keys done: no duplicate record, straight to finish.
346 const h2 = harness({ myName: "Paul", enrolled: true, done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true, keys: true } });
347 runFlow(SETUP_FLOW, h2.env, h2.io);
348 await tick();
349 // No duplicate keys record — only finish stamping its completion marker.
350 assert.deepEqual(h2.records, [{ step: "finish", label: "Your space is ready", value: "done" }]);
351 assert.equal(h2.transcript.some((t) => /key is safe. ✅/.test(t.text)), false);
352});
353
354await test("setup: extras — 'Let me choose' walks the pair, then the AI opt-in", async () => {
355 const h = harness({
356 myName: "Paul",
357 done: { name: true, group: true, email: true, photo: true, invites: true },
358 });
359 runFlow(SETUP_FLOW, h.env, h.io);
360 await tick();
361 assert.ok(h.transcript.find((t) => /comes with a couple of extras/.test(t.text)));
362
363 await h.tap("Let me choose");
364 assert.ok(h.transcript.find((t) => /Bots — helpers/.test(t.text)));
365 await h.tap("Enable bots");
366 assert.deepEqual(h.verbLog.at(-1), ["setFeature", "bots", true]);
367 await h.tap("No apps here");
368 assert.deepEqual(h.verbLog.at(-1), ["setFeature", "apps", false]);
369 // The AI opt-in follows the granular pair too — never skippable by path.
370 assert.ok(h.transcript.find((t) => /read the chats it's invited to/.test(t.text)));
371 await h.tap("Not now");
372 assert.deepEqual(h.verbLog.at(-1), ["setFeature", "ai", false]);
373 assert.ok(h.records.find((r) => r.step === "extras-apps" && r.value === "off"));
374 assert.ok(h.records.find((r) => r.step === "ai-optin" && r.value === "off"));
375 // The path lands on the keys pitch like the one-tap path.
376 assert.ok(h.transcript.find((t) => /Now the most important thing of all/.test(t.text)));
377
378 // Resume after the granular path: the extras entry closes the step out and
379 // neither the pair nor the AI question replays.
380 const h2 = harness({
381 myName: "Paul",
382 enrolled: true,
383 done: { ...h.doneSteps },
384 });
385 runFlow(SETUP_FLOW, h2.env, h2.io);
386 await tick();
387 assert.equal(h2.transcript.some((t) => /read the chats it's invited to/.test(t.text)), false, "answered steps don't replay");
388 assert.ok(h2.records.find((r) => r.step === "extras" && r.value === "chosen"), "the entry closes extras");
389 assert.ok(h2.records.find((r) => r.step === "keys"), "resume reaches keys");
390});
391
392await test("setup: from-home key step + settle auto-detects the enrolment return", async () => {
393 const h = harness({
394 myName: "Paul",
395 fromHome: true, // arrived from the Eleven sign-in page → the keys-home variant
396 done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true },
397 });
398 runFlow(SETUP_FLOW, h.env, h.io);
399 await tick();
400
401 // fromHome routes to keys-home ("add to your passkey"), not the from-scratch pitch.
402 assert.ok(h.transcript.find((t) => /Last thing — the key/.test(t.text)), "keys-home shown");
403 assert.equal(h.transcript.some((t) => /Now the most important thing of all/.test(t.text)), false);
404
405 // The ceremony returns asynchronously: enrolment lands, and the settle poll —
406 // NOT a manual "Continue" tap — carries the flow on to finish.
407 const settle = h.pendingDelays.find((d) => d.ms === 700);
408 assert.ok(settle, "keys-home arms a settle poll while it waits");
409 h.enrolled = true;
410 settle.fn();
411 await tick();
412 await tick();
413 assert.deepEqual(h.records.find((r) => r.step === "keys-home"), { step: "keys-home", label: "Signed in — your space's key is safe", value: "passkey" });
414 assert.deepEqual(h.records.at(-1), { step: "finish", label: "Your space is ready", value: "done" });
415 assert.ok(h.transcript.find((t) => /your space's key is safe. ✅/.test(t.text)));
416 assert.ok(h.verbLog.find((v) => v[0] === "markSetupComplete"), "reached finish without a tap");
417});
418
419await test("setup: native creator — greeting shows, name pre-set, passkey never pitched, no admin hop", async () => {
420 // The native create-space landing: screen name typed in the create UI, the
421 // conversation runs in the app-thread's embedded webview with env.native.
422 const h = harness({ myName: "Paul", verbs: { setGroupName: () => "ok", setContactEmail: () => "ok" } });
423 h.env.native = true;
424 runFlow(SETUP_FLOW, h.env, h.io);
425 await tick();
426
427 // First run WITH a name: still greeted (not "resumed"), name step skipped.
428 assert.match(h.transcript[0].text, /^Hi — I'm Eleven! 👋/);
429 assert.equal(h.transcript.some((t) => /Welcome back/.test(t.text)), false);
430 assert.equal(h.transcript.some((t) => /what should everyone here call you/.test(t.text)), false);
431 assert.ok(h.transcript.find((t) => t.extra.key === "q-group"));
432
433 await h.answer("Team Awesome");
434 await h.tap("Skip for now"); // email; photo auto-skips under native
435 assert.equal(h.transcript.some((t) => t.extra.key === "q-photo"), false);
436 await h.tap("Members can invite people");
437 await h.tap("Keep both on");
438 await h.tap("Not now"); // the AI opt-in runs under native too
439
440 // Keys: never pitched — recorded as covered by the Eleven account.
441 assert.equal(h.transcript.some((t) => /Now the most important thing of all/.test(t.text)), false);
442 assert.equal(h.verbLog.some((v) => v[0] === "savePasskey"), false);
443 assert.deepEqual(h.records.find((r) => r.step === "keys"), { step: "keys", label: "Your space's key is saved with your Eleven account", value: "native" });
444
445 // Finish: completion marker recorded, complete marked, no backup nag or
446 // reminder deferral (the key IS backed up), and no web-only chips (admin
447 // hop, tour) — the finish bubble's /admin pointer covers it.
448 assert.deepEqual(h.records.at(-1), { step: "finish", label: "Your space is ready", value: "done" });
449 assert.ok(h.verbLog.find((v) => v[0] === "markSetupComplete"));
450 assert.equal(h.verbLog.some((v) => v[0] === "deferBackupReminders"), false);
451 assert.equal(h.transcript.some((t) => /One more reminder/.test(t.text)), false);
452 const chipLabels = h.transcript.flatMap((t) => t.chips || []); // harness stores labels
453 assert.equal(chipLabels.includes("Take the tour"), false, "the tour stays web-only");
454 assert.ok(chipLabels.includes("Open admin"), "native hops to Admin");
455});
456
457await test("setup: keys answered-but-not-enrolled resumes to FINISH — never re-pitched (#1377)", async () => {
458 // The bug: done.keys with the enrolled flag lost ("Continue" after a
459 // detour, "I understand the risk", cleared storage) re-pitched the whole
460 // sign-in speech on every resume and never reached markSetupComplete.
461 const h = harness({
462 myName: "Paul",
463 enrolled: false,
464 done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true, keys: true },
465 });
466 runFlow(SETUP_FLOW, h.env, h.io);
467 await tick();
468 assert.equal(h.transcript.some((t) => /Now the most important thing of all/.test(t.text)), false, "the pitch never replays");
469 assert.deepEqual(h.records, [{ step: "finish", label: "Your space is ready", value: "done" }]);
470 assert.ok(h.verbLog.find((v) => v[0] === "markSetupComplete"), "setup completes");
471 // Not enrolled in THIS browser: the finish reminder stays, honestly.
472 assert.ok(h.transcript.find((t) => /One more reminder before you go/.test(t.text)));
473 // And the finish bubble carries its stable dedup key (renames and backup
474 // flips must not persist a second copy).
475 assert.equal(h.transcript.find((t) => /is ready! 🎉/.test(t.text)).extra.key, "q-finish");
476});
477
478await test("setup: no home server — the sign-in pitch vanishes, recorded honestly (#1377)", async () => {
479 const h = harness({
480 myName: "Paul",
481 canEnrol: false,
482 done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true },
483 });
484 runFlow(SETUP_FLOW, h.env, h.io);
485 await tick();
486 assert.equal(h.transcript.some((t) => /Now the most important thing of all/.test(t.text)), false, "no un-actionable pitch");
487 assert.deepEqual(h.records[0], { step: "keys", label: "This browser holds this space's key", value: "local" });
488 assert.ok(h.verbLog.find((v) => v[0] === "markSetupComplete"));
489 // No sign-in to nag about, and no dead Sign in chip on the finish line.
490 assert.equal(h.transcript.some((t) => /One more reminder before you go/.test(t.text)), false);
491 assert.equal(h.transcript.flatMap((t) => t.chips || []).includes("Sign in"), false);
492});
493
494await test("welcome: no home server — the access ask vanishes, recorded honestly (#1377)", async () => {
495 // Inline env — welcomeEnv() is declared with the welcome section below.
496 const h = harness({
497 canEnrol: false,
498 envExtra: { suggested: "", inviterName: "", adminName: "", hasPendingThread: false, space: { name: "Test Space", nameSet: true } },
499 });
500 runFlow(WELCOME_FLOW, h.env, h.io);
501 await tick();
502 assert.equal(h.transcript.some((t) => /make sure you can't lose your way in/.test(t.text)), false, "no un-actionable ask");
503 assert.deepEqual(h.records[0], { step: "access", label: "Your access lives in this browser", value: "local" });
504 // Straight to the name question instead.
505 assert.ok(h.transcript.find((t) => /call you/.test(t.text) || /your name/i.test(t.text)));
506});
507
508await test("engine: a re-derive consumes env.reentry — the NEXT resume greets again (#1377)", async () => {
509 const h = harness({ myName: "Paul", done: { name: true, group: true }, envExtra: { reentry: true } });
510 runFlow(SETUP_FLOW, h.env, h.io);
511 await tick();
512 assert.equal(h.transcript.some((t) => /Welcome back/.test(t.text)), false, "the re-derive itself stays quiet");
513 assert.equal(h.env.reentry, false, "consumed — a later genuine resume isn't silenced");
514});
515
516await test("setup: the plan step — asked with a price book, priced from it, recorded on 'plan'", async () => {
517 // #1374: "who is this space for?" lives in the conversation; the create
518 // slider is never pay-gated. Names + prices interpolate from the book.
519 const book = {
520 team: { key: "business", name: "Business", price: "€11 per person per year" },
521 community: { key: "community", name: "Community & Friends", price: "€0.11 per member per year (€11 minimum)" },
522 family: { key: "family", name: "Family", price: "€5.50 a year" },
523 };
524 const h = harness({
525 myName: "Paul",
526 planBook: book,
527 done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true },
528 });
529 runFlow(SETUP_FLOW, h.env, h.io);
530 await tick();
531
532 const q = h.transcript.find((t) => t.extra.key === "q-plan");
533 assert.ok(q, "the plan question is asked");
534 assert.match(q.text, /who is this space for\?/);
535 assert.deepEqual(q.chips, ["A team", "A community", "Family & friends", "Keep it free"]);
536
537 await h.tap("A team");
538 const price = h.transcript.find((t) => t.extra.key === "q-plan-team");
539 assert.match(price.text, /Business: €11 per person per year/, "name + price come from the book, not the script");
540 await h.tap("Choose Business");
541 assert.deepEqual(h.records.find((r) => r.step === "plan"), {
542 step: "plan",
543 label: "chose the Business plan — payment waits at the finish line",
544 value: "team",
545 });
546
547 // The keys pitch follows; decline through to finish — which carries the
548 // plan note and the payment chip (an action chip, never a side effect).
549 await h.tap("Not now");
550 await h.tap("I understand the risk");
551 assert.ok(h.transcript.find((t) => /the plan you picked — tap below/.test(t.text)));
552 await h.tap("Set up your plan");
553 assert.ok(h.verbLog.find((v) => v[0] === "openPlanCheckout"), "the chip fires the checkout verb");
554 assert.ok(h.verbLog.find((v) => v[0] === "markSetupComplete"), "the flow still completes");
555});
556
557await test("setup: the plan step — 'Keep it free' records free; a partial book trims its chips", async () => {
558 const h = harness({
559 myName: "Paul",
560 planBook: { family: { key: "family", name: "Family", price: "€5.50 a year" } },
561 done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true },
562 });
563 runFlow(SETUP_FLOW, h.env, h.io);
564 await tick();
565 const q = h.transcript.find((t) => t.extra.key === "q-plan");
566 assert.deepEqual(q.chips, ["Family & friends", "Keep it free"], "only tiers the book offers get chips");
567 await h.tap("Family & friends");
568 await h.tap("Keep it free");
569 assert.deepEqual(h.records.find((r) => r.step === "plan"), { step: "plan", label: "kept this space free", value: "free" });
570 // No plan chosen → no payment note and no payment chip at the finish.
571 await h.tap("Not now");
572 await h.tap("I understand the risk");
573 assert.equal(h.transcript.some((t) => /the plan you picked/.test(t.text)), false);
574 assert.equal(h.transcript.flatMap((t) => t.chips || []).includes("Set up your plan"), false);
575});
576
577await test("setup: the plan step vanishes without a price book, on native, and once done", async () => {
578 // No book (self-hosted, billing off, unreachable): straight to keys.
579 const h = harness({ myName: "Paul", done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true } });
580 runFlow(SETUP_FLOW, h.env, h.io);
581 await tick();
582 assert.equal(h.transcript.some((t) => t.extra.key === "q-plan"), false);
583 assert.ok(h.transcript.find((t) => /Now the most important thing of all/.test(t.text)));
584
585 // Done (answered on another client): never re-asked, even with a book.
586 const book = { family: { key: "family", name: "Family", price: "€5.50 a year" } };
587 const h2 = harness({
588 myName: "Paul",
589 planBook: book,
590 done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true, plan: true },
591 });
592 runFlow(SETUP_FLOW, h2.env, h2.io);
593 await tick();
594 assert.equal(h2.transcript.some((t) => t.extra.key === "q-plan"), false);
595});
596
597await test("engine: template + condition mini-language", () => {
598 const env = { vars: { x: "hi" }, space: { name: "" }, __ack: "A" };
599 assert.equal(renderText(env, "{vars.x} {space.name|fallback}"), "hi fallback");
600 assert.equal(renderText(env, "{ack?}rest"), "A\n\nrest");
601 assert.equal(renderText(env, "{ack?}rest"), "rest", "ack is consumed");
602 assert.equal(renderText(env, ["a", { if: "vars.x", text: "-b" }, { if: "vars.missing", text: "-c" }]), "a-b");
603 assert.equal(renderText(env, { if: "vars.missing", then: "T", else: "E" }), "E");
604 assert.equal(evalCond(env, "!vars.missing"), true);
605});
606
607// ---- welcome flow -----------------------------------------------------------
608
609const welcomeEnv = (over = {}) => ({
610 suggested: "",
611 inviterName: "",
612 adminName: "",
613 hasPendingThread: false,
614 space: { name: "Test Space", nameSet: true },
615 ...over,
616});
617
618// The quick-form fast path: both conversations' FIRST interactive step offers
619// a right-aligned "Fill in a form instead" chip whose tap opens the host form
620// (the openQuickForm verb) WITHOUT consuming the step — the conversation stays
621// answerable while the form is up (Cancel walks away scot-free).
622await test("quick form: the trailing fast-path chip on welcome access + setup name", async () => {
623 const h = harness({ envExtra: welcomeEnv() });
624 runFlow(WELCOME_FLOW, h.env, h.io);
625 await tick();
626 const chip = (h.lastChips || []).find((c) => c.label === "Fill in a form instead");
627 assert.ok(chip, "the welcome access step offers the quick-form chip");
628 assert.equal(chip.trailing, true, "flagged trailing — the renderer right-aligns it");
629 assert.equal((h.lastChips || []).find((c) => c.label === "Sign in (recommended)").trailing, undefined, "primary chips stay untagged");
630 await h.tap("Fill in a form instead");
631 assert.ok(h.verbLog.find((v) => v[0] === "openQuickForm"), "the tap fires the openQuickForm verb");
632 await h.tap("Sign in (recommended)"); // non-advancing: the step is still live after peeking at the form
633 assert.ok(h.verbLog.find((v) => v[0] === "savePasskey"));
634
635 const h2 = harness();
636 runFlow(SETUP_FLOW, h2.env, h2.io);
637 await tick();
638 const chip2 = (h2.lastChips || []).find((c) => c.label === "Fill in a form instead");
639 assert.ok(chip2, "the setup name step offers the quick-form chip");
640 assert.equal(chip2.trailing, true);
641 await h2.tap("Fill in a form instead");
642 assert.ok(h2.verbLog.find((v) => v[0] === "openQuickForm"));
643 await h2.answer("Paul"); // the typed answer still lands after the chip tap
644 assert.deepEqual(h2.verbLog.find((v) => v[0] === "setMyName"), ["setMyName", "Paul"]);
645});
646
647await test("welcome: invited fresh join — passkey probe, suggested name, photo nokey retry", async () => {
648 let photoTries = 0;
649 const h = harness({
650 verbs: { adoptProfilePhoto: () => (++photoTries === 1 ? "nokey" : true) },
651 envExtra: welcomeEnv({ suggested: "Luan", inviterName: "Ciara", hasPendingThread: true }),
652 });
653 h.env.accessBackedUp = () => h.enrolled;
654 runFlow(WELCOME_FLOW, h.env, h.io);
655 await tick();
656
657 // The greeting assumes nothing: inviter named, admin unknown → generic.
658 assert.match(h.transcript[0].text, /^Welcome! 👋 I'm Eleven, your guide here\./);
659 assert.match(h.transcript[0].text, /Ciara invited you to Test Space/);
660 assert.match(h.transcript[0].text, /run by one of its members/);
661 assert.match(h.transcript[0].text, /locked with keys only members hold/);
662
663 // Passkey first; the ceremony stays put → probe routes to the waiting step.
664 // (The step also arms a background settle poll; target the probe by interval.)
665 await h.tap("Sign in (recommended)");
666 const accessProbe = h.pendingDelays.find((d) => d.ms === 1500);
667 assert.ok(accessProbe, "the Save-my-access probe schedules a 1500ms check");
668 accessProbe.fn();
669 await tick();
670 assert.match(h.lastText(), /I'll wait here while you finish/);
671 h.enrolled = true;
672 await h.tap("Continue");
673 assert.deepEqual(h.records[0], { step: "access", label: "Signed in — your access is safe", value: "passkey" });
674
675 // The ack folds into the name question; the suggested-name chip is offered.
676 const nameQ = h.transcript.find((t) => t.extra.key === "q-name");
677 assert.match(nameQ.text, /^Perfect — you're all set\. 🔒\n\nFirst things first/);
678 await h.tap("I'm Luan");
679 assert.deepEqual(h.verbLog.find((v) => v[0] === "setMyName"), ["setMyName", "Luan"]);
680 assert.equal(h.records[1].label, "noted: you're Luan");
681
682 // Photo: instance key not here yet → honest nokey line, then a retry works.
683 const photoQ = h.transcript.find((t) => t.extra.key === "q-photo");
684 assert.match(photoQ.text, /^Lovely to meet you, Luan! 🤝\n\nWant to add a profile photo\?/);
685 await h.answer("me on holiday", { attachments: [{ type: "image/png" }] });
686 assert.ok(h.transcript.find((t) => /still finishing your secure setup/.test(t.text)));
687 assert.match(h.lastText(), /Ready when you are — send that photo again/);
688 await h.answer("me on holiday", { attachments: [{ type: "image/png" }] });
689 assert.deepEqual(h.verbLog.filter((v) => v[0] === "adoptProfilePhoto").length, 2);
690
691 // Preview is client-only with the round profile image; Keep records "photo".
692 assert.equal(h.transcript.at(-1).extra.img, "IMG($myAvatar)");
693 assert.equal(h.transcript.at(-1).extra.imgRound, true);
694 await h.tap("Keep this photo");
695 assert.deepEqual(h.records.find((r) => r.step === "photo"), { step: "photo", label: "set your profile photo", value: "" });
696 assert.deepEqual(h.records.at(-1), { step: "finish", label: "You're all set", value: "done" }, "finish persists its completion marker");
697
698 // Finish: welcome marked done, no backup nag (enrolled), inviter chip first.
699 assert.ok(h.verbLog.find((v) => v[0] === "markWelcomeDone"));
700 const fin = h.transcript.find((t) => t.extra.key === "q-finish");
701 assert.match(fin.text, /you're all set\. 🎉 Enjoy Test Space!/);
702 assert.equal(/One more reminder/.test(fin.text), false);
703 await h.tap("Say hi to Ciara");
704 assert.ok(h.verbLog.find((v) => v[0] === "openPendingThread"));
705 assert.ok(h.lastChips.find((c) => c.label === "Take the tour"));
706 assert.ok(h.ended);
707});
708
709await test("welcome: skip everything — nudge acks, photo skip disarms, nag on finish", async () => {
710 const h = harness({ envExtra: welcomeEnv({ space: { name: "", nameSet: false } }) });
711 h.env.accessBackedUp = () => false;
712 runFlow(WELCOME_FLOW, h.env, h.io);
713 await tick();
714
715 // No inviter → the generic invitation line, with the space-name fallback.
716 assert.match(h.transcript[0].text, /You've been invited to this space/);
717
718 await h.tap("Not now");
719 assert.ok(h.verbLog.find((v) => v[0] === "deferBackupReminders"), "declining defers the reminders");
720 const nameQ = h.transcript.find((t) => t.extra.key === "q-name");
721 assert.match(nameQ.text, /^No problem — I'll nudge you again in a day or so\.\n\nFirst things first/);
722 assert.deepEqual(nameQ.chips, [], "no suggested-name chip without a suggestion");
723
724 await h.answer("Paul");
725 await h.tap("Skip for now");
726 assert.equal(h.cancelled, 1, "photo skip disarms the waiter");
727
728 // Finish: skipped-photo comfort line + the backup nag; no pending-thread chip.
729 const fin = h.transcript.find((t) => t.extra.key === "q-finish");
730 assert.match(fin.text, /^No problem — you can add one anytime from your profile\./);
731 assert.match(fin.text, /One more reminder before you go/);
732 assert.deepEqual(h.lastChips.map((c) => c.label), ["Sign in", "Take the tour"], "the parting sign-in chip rides the finish");
733 // No open groups in this env — the mention and its chip stay hidden.
734 assert.equal(/open groups/.test(fin.text), false);
735});
736
737await test("welcome: open groups get a finish mention + a Browse chip", async () => {
738 const h = harness({ enrolled: true, envExtra: welcomeEnv({ openGroups: true }) });
739 h.env.accessBackedUp = () => true;
740 runFlow(WELCOME_FLOW, h.env, h.io);
741 await tick();
742 await h.answer("Paul");
743 await h.tap("Skip for now"); // photo
744 const fin = h.transcript.find((t) => t.extra.key === "q-finish");
745 assert.match(fin.text, /This space also has open groups anyone here can join/);
746 await h.tap("Browse open groups");
747 assert.ok(h.verbLog.find((v) => v[0] === "openDiscover"), "the chip hands over to the directory");
748});
749
750await test("welcome: native embed — passkey step skipped, access secured by the sign-in, finish records completion", async () => {
751 const h = harness({ envExtra: welcomeEnv({ native: true, inviterName: "Ciara" }) });
752 h.env.accessBackedUp = () => true; // native: secured by Sign in with Eleven
753 runFlow(WELCOME_FLOW, h.env, h.io);
754 await tick();
755
756 // The passkey ask never renders; the access step records the native reason
757 // and the conversation goes straight from the greeting to the name.
758 assert.equal(h.transcript.some((t) => /Sign in with Eleven and your access is safe/.test(t.text)), false);
759 assert.deepEqual(h.records[0], { step: "access", label: "Your access is already secured by your Eleven sign-in", value: "native" });
760 const nameQ = h.transcript.find((t) => t.extra.key === "q-name");
761 assert.ok(nameQ);
762 // The question carries the composer's inset field label + an example hint.
763 assert.equal(nameQ.extra.label, "Your name:");
764 assert.equal(nameQ.extra.hint, "e.g. Finn Wolfhard");
765
766 // Run it to the end: finish persists its completion marker (what the native
767 // embed gates on — no localStorage marker there) and never nags about the
768 // access backup.
769 await h.answer("Paul");
770 // The photo step auto-skips under native (no attachment flow in the
771 // conversation composer yet) — finish follows the name directly.
772 const fin = h.transcript.find((t) => t.extra.key === "q-finish");
773 assert.ok(fin, "finish reached without a photo ask");
774 assert.equal(h.transcript.some((t) => t.extra.key === "q-photo"), false);
775 assert.equal(/One more reminder/.test(fin.text), false, "no sign-in nag — access is the sign-in");
776 assert.ok(h.records.find((r) => r.step === "finish" && r.value === "done"), "finish records the completion marker");
777});
778
779await test("welcome: passkey-return leg — richer ack, no generic re-greet, question never re-asked", async () => {
780 const h = harness({ enrolled: true, envExtra: welcomeEnv() });
781 h.env.accessBackedUp = () => true;
782 runFlow(WELCOME_FLOW, h.env, h.io);
783 await tick();
784
785 // Not "resumed" (nothing recorded, no name) so no "Welcome back —" line; the
786 // access entry supplies the richer ack instead, and the passkey question
787 // never renders.
788 assert.equal(h.transcript.some((t) => /^Welcome back — let's pick up/.test(t.text)), false);
789 assert.ok(h.transcript.find((t) => /^Great — you're signed in/.test(t.text)));
790 assert.equal(h.transcript.some((t) => /Sign in with Eleven and your access is safe/.test(t.text)), false);
791 assert.deepEqual(h.records[0], { step: "access", label: "Signed in — your access is safe", value: "passkey" });
792 assert.ok(h.transcript.find((t) => t.extra.key === "q-name"));
793
794 // A later reload (name set, access recorded): generic re-greet, hello skipped.
795 const h2 = harness({ enrolled: true, myName: "Paul", done: { access: true, name: true }, envExtra: welcomeEnv() });
796 h2.env.accessBackedUp = () => true;
797 runFlow(WELCOME_FLOW, h2.env, h2.io);
798 await tick();
799 assert.match(h2.transcript[0].text, /^Welcome back — let's pick up/);
800 assert.equal(h2.transcript.some((t) => /^Welcome! 👋/.test(t.text)), false, "hello step skipped on resume");
801 assert.ok(h2.transcript.find((t) => t.extra.key === "q-photo"), "resumes at the first undone step");
802});
803
804// The ceremony can finish in ANOTHER browsing context (iOS home-screen apps run
805// it in an in-app overlay; the native wrapper in the system browser) — the
806// completion poll flips bridge.enrolled while the flow sits on the WAITING
807// step. The waiting step's settle must then carry the flow on, with the access
808// step's proper record + ack, and never require the manual "Continue" tap.
809await test("welcome: enrolment confirmed while on access-waiting settles through", async () => {
810 const h = harness({ envExtra: welcomeEnv() });
811 runFlow(WELCOME_FLOW, h.env, h.io);
812 await tick();
813
814 await h.tap("Sign in (recommended)"); // fire-and-forget verb; page stays (stay mode)
815 const probe = h.pendingDelays.find((d) => d.ms === 1500);
816 assert.ok(probe, "the save chip arms its fall-to-waiting probe");
817 probe.fn();
818 await tick();
819 assert.ok(h.transcript.find((t) => /I'll wait here while you finish signing in/.test(t.text)), "fell to access-waiting");
820
821 // The poll confirms; access-waiting's settle re-enters access, whose entry
822 // records the backup and acks — no Continue tap.
823 h.enrolled = true;
824 const settle = h.pendingDelays.filter((d) => d.ms === 700).at(-1);
825 assert.ok(settle, "access-waiting arms a settle poll");
826 settle.fn();
827 await tick();
828 await tick();
829 assert.deepEqual(h.records.find((r) => r.step === "access"),
830 { step: "access", label: "Signed in — your access is safe", value: "passkey" });
831 assert.ok(h.transcript.find((t) => /^Great — you're signed in/.test(t.text)));
832 assert.ok(h.transcript.find((t) => t.extra.key === "q-name"), "carried on to the name step");
833});
834
835await test("setup: enrolment confirmed while on keys-waiting settles through", async () => {
836 const h = harness({
837 myName: "Paul",
838 done: { name: true, group: true, email: true, photo: true, invites: true, extras: true, "ai-optin": true },
839 });
840 runFlow(SETUP_FLOW, h.env, h.io);
841 await tick();
842 assert.ok(h.transcript.find((t) => /Now the most important thing of all/.test(t.text)), "keys pitch shown");
843
844 await h.tap("Sign in");
845 const probe = h.pendingDelays.find((d) => d.ms === 1500);
846 probe.fn();
847 await tick();
848 assert.ok(h.transcript.find((t) => /I'll wait here while you finish signing in/.test(t.text)), "fell to keys-waiting");
849
850 h.enrolled = true;
851 const settle = h.pendingDelays.filter((d) => d.ms === 700).at(-1);
852 assert.ok(settle, "keys-waiting arms a settle poll");
853 settle.fn();
854 await tick();
855 await tick();
856 assert.deepEqual(h.records.find((r) => r.step === "keys"),
857 { step: "keys", label: "Signed in — your space's key is safe", value: "passkey" });
858 assert.ok(h.transcript.find((t) => /your space's key is safe. ✅/.test(t.text)));
859 assert.ok(h.verbLog.find((v) => v[0] === "markSetupComplete"), "reached finish without a tap");
860 // Backed up → the finish bubble must NOT nag about coming back to it.
861 assert.equal(h.transcript.some((t) => /One more reminder/.test(t.text)), false);
862});
863
864// ---- native bundle drift gate ------------------------------------------------
865// The Swift interpreter (ios/.../FlowEngine.swift) runs byte-derived copies of
866// these flow documents (Flows/*.json). Regenerate after editing a flow:
867// node -e 'import("./web/static/setup.flow.js").then(async m => { (await import("fs")).writeFileSync("ios/LChatCore/Sources/LChatCore/Flows/setup.json", JSON.stringify(m.default, null, 2) + "\n"); })'
868// (and the welcome twin).
869import { readFileSync } from "fs";
870import { fileURLToPath } from "url";
871import { dirname, join } from "path";
872const __dir = dirname(fileURLToPath(import.meta.url));
873await test("native flow bundles match the canonical flow documents", () => {
874 for (const [name, flow] of [["setup", SETUP_FLOW], ["welcome", WELCOME_FLOW]]) {
875 const bundled = JSON.parse(readFileSync(join(__dir, "..", "ios", "LChatCore", "Sources", "LChatCore", "Flows", `${name}.json`), "utf8"));
876 assert.deepEqual(bundled, flow, `${name}.json drifted — regenerate from ${name}.flow.js (see comment above)`);
877 }
878});
879