@intentius/behold 0.29.43 → 0.29.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/AGENTS.md +77 -0
  2. package/dist/cli.js +4065 -1918
  3. package/package.json +1 -1
  4. package/web/app.js +1469 -74
  5. package/web/carve-narration.js +33 -1
  6. package/web/chant-live-pace.js +138 -0
  7. package/web/chant-live-pace.test.js +116 -0
  8. package/web/chant-pr-marks.js +417 -39
  9. package/web/chant-pr-marks.test.js +208 -4
  10. package/web/collision-marks.js +124 -0
  11. package/web/collision-marks.test.js +89 -0
  12. package/web/cone.js +269 -0
  13. package/web/cone.test.js +213 -0
  14. package/web/dots-live.test.js +151 -1
  15. package/web/dots-lod.js +20 -0
  16. package/web/dots-lod.test.js +19 -1
  17. package/web/dots-scene.js +110 -10
  18. package/web/dots.js +144 -31
  19. package/web/embed.js +1 -1
  20. package/web/event-help-modal.js +98 -3
  21. package/web/event-help-modal.test.js +85 -1
  22. package/web/feature-flags.js +143 -0
  23. package/web/feature-flags.test.js +96 -0
  24. package/web/index.html +33 -0
  25. package/web/kiosk-carve.js +59 -6
  26. package/web/kiosk-demo-frame.test.js +27 -0
  27. package/web/kiosk-event-help-ui.js +186 -20
  28. package/web/kiosk-event-help.js +175 -15
  29. package/web/kiosk-event-help.test.js +58 -1
  30. package/web/kiosk-highlight.test.js +249 -0
  31. package/web/kiosk-metrics.js +4 -3
  32. package/web/kiosk-runs.js +8 -5
  33. package/web/kiosk-shot.js +157 -3
  34. package/web/kiosk-shot.test.js +223 -1
  35. package/web/kiosk-source.js +43 -0
  36. package/web/kiosk-source.test.js +39 -0
  37. package/web/kiosk-story-gate.test.js +44 -0
  38. package/web/kiosk-track.js +312 -0
  39. package/web/kiosk-track.test.js +148 -0
  40. package/web/kiosk-unknown-step.test.js +58 -0
  41. package/web/kiosk-vendor.js +73 -4
  42. package/web/kiosk-vendor.test.js +103 -3
  43. package/web/kiosk-watch.js +154 -1
  44. package/web/kiosk-watch.test.js +53 -1
  45. package/web/kiosk.html +57 -22
  46. package/web/kiosk.js +583 -53
  47. package/web/kiosk.test.js +2 -1
  48. package/web/small-stage.test.js +150 -0
  49. package/web/terragucci-blocked.test.js +192 -0
  50. package/web/terragucci-change.js +197 -17
  51. package/web/terragucci-components-live.js +189 -13
  52. package/web/terragucci-live-pace.js +92 -0
  53. package/web/terragucci-wave-results.test.js +125 -0
  54. package/web/terralith.html +7 -7
  55. package/web/tg-outside.js +124 -0
  56. package/web/tg-outside.test.js +100 -0
  57. package/web/tg-read-pills.js +145 -0
  58. package/web/tg-read-pills.test.js +158 -0
  59. package/web/theme.js +13 -1
  60. package/web/theme.test.js +21 -1
  61. package/web/tooltip.js +19 -7
  62. package/web/tooltip.test.js +15 -0
  63. package/web/tours/terralith.json +4 -4
  64. package/web/trunk-lane.test.js +1 -1
  65. package/web/view-url.js +8 -2
  66. package/web/why.js +129 -1
  67. package/web/why.test.js +113 -1
@@ -0,0 +1,312 @@
1
+ // behold#631: the projected cycle track, a chant kiosk's bottom band.
2
+ //
3
+ // A viewer walking up to the loop between events saw breadcrumbs of what had
4
+ // happened and no idea of what was left. The track lays the whole cycle out
5
+ // from the first second, from the tool's last finished cycle
6
+ // (`cycles/<tool>/latest.json`, demo.cycle/v1): a segment per step, grouped
7
+ // into a chapter per pull request ("The change", "The fix"), as wide as that
8
+ // step took last time. Past segments are filled (a failure red, the end
9
+ // green), the current one fills as its time passes (never past 95% until the
10
+ // step really ends, with a sheen so a quiet stretch never looks frozen), and
11
+ // what is left stays outlined. Under it, the now line says what is happening
12
+ // and what is waited on, with the typical time.
13
+ //
14
+ // The same words make the "Waiting on…" modal (waitingSpec), the big version
15
+ // for someone just walking up, so the two always agree.
16
+ //
17
+ // Pure apart from drawTrack, which builds DOM from a model.
18
+
19
+ /** A segment's label, by the step it shows. A later pull request's open is the fix's. */
20
+ const LABELS = { "pull-request": "opened", planned: "planned", waiting: "review", approved: "review", merged: "merged", applying: "applying", resumed: "applying", failed: "failed", applied: "done", reset: "reset" };
21
+ /** A label's short form, said when the whole word does not fit its segment. */
22
+ export const SHORT = { opened: "open", planned: "plan", review: "review", merged: "merge", applying: "apply", failed: "fail", "fix opened": "fix", done: "done", reset: "reset" };
23
+ /**
24
+ * When a step counts as running long: past half again its usual time, and at
25
+ * least 8 s past it. Before that the fill holds and the usual time stands.
26
+ */
27
+ export const overrunAfter = (expected) => Math.max(1.5 * expected, expected + 8_000);
28
+ /** The share of a step the fill reaches before the step really ends. */
29
+ export const FILL_CAP = 0.95;
30
+ /** A segment's least share of the track, so its label fits. */
31
+ export const MIN_SHARE = 0.045;
32
+ /** How long nothing must change before the "Waiting on…" modal shows. */
33
+ export const WAITING_AFTER_MS = 3_000;
34
+
35
+ const ms = (a, b) => Math.max(0, Date.parse(b) - Date.parse(a));
36
+ const secs = (n) => Math.max(1, Math.round(n / 1000));
37
+
38
+ /**
39
+ * The track's frame from the last cycle: chapters, each with its segments, a
40
+ * segment being one or more steps in a row with one label ("review" holds
41
+ * waiting and approved). Each segment's `ms` is how long its steps took last
42
+ * time. Null when the cycle has no steps.
43
+ */
44
+ export function cycleTrack(cycle) {
45
+ const steps = cycle && Array.isArray(cycle.steps) ? cycle.steps.filter((s) => s && typeof s.step === "string" && typeof s.at === "string") : [];
46
+ if (!steps.length) return null;
47
+ const end = typeof cycle.ended === "string" ? cycle.ended : null;
48
+ const pulls = [];
49
+ const chapters = [];
50
+ // behold#631: a cycle whose steps carry their story's chapter ({ n, of, headline }) is told in those chapters; else one per pull request.
51
+ const byStory = steps.every((s) => s.chapter && Number.isInteger(s.chapter.n));
52
+ steps.forEach((s, i) => {
53
+ const next = steps[i + 1];
54
+ const took = next ? ms(s.at, next.at) : end ? ms(s.at, end) : 3_000;
55
+ // Which pull request of the cycle this is: a later one's open is the fix's.
56
+ if (Number.isInteger(s.pull) && !pulls.includes(s.pull)) pulls.push(s.pull);
57
+ const pi = Number.isInteger(s.pull) ? pulls.indexOf(s.pull) : pulls.length - 1;
58
+ let ci;
59
+ if (byStory) {
60
+ ci = chapters.findIndex((c) => c.n === s.chapter.n);
61
+ if (ci < 0) {
62
+ chapters.push({ index: chapters.length, n: s.chapter.n, of: s.chapter.of, headline: s.chapter.headline, short: s.chapter.short || shortOf(s.chapter.headline), segments: [] });
63
+ ci = chapters.length - 1;
64
+ }
65
+ } else {
66
+ // A step with no pull request of its own (the reset) closes the chapter it follows.
67
+ ci = Number.isInteger(s.pull) ? pi : chapters.length - 1;
68
+ if (ci < 0 || ci >= chapters.length) {
69
+ chapters.push({ index: chapters.length, lastPull: s.pull, segments: [] });
70
+ ci = chapters.length - 1;
71
+ }
72
+ }
73
+ const chapter = chapters[ci];
74
+ const label = s.step === "pull-request" && pi > 0 ? "fix opened" : LABELS[s.step] || s.step;
75
+ const last = chapter.segments[chapter.segments.length - 1];
76
+ if (last && last.label === label) {
77
+ last.steps.push(s.step);
78
+ last.ms += took;
79
+ return;
80
+ }
81
+ chapter.segments.push({ label, steps: [s.step], ms: took, labelText: s.label || "" });
82
+ });
83
+ const total = chapters.reduce((sum, c) => sum + c.segments.reduce((a, g) => a + g.ms, 0), 0) || 1;
84
+ return { chapters, total, cycle: cycle.cycle, byStory };
85
+ }
86
+
87
+ /** A chapter's short name for the track, from its headline when the driver gives none: up to its first comma, colon or dash, at most five words. */
88
+ export function shortOf(headline) {
89
+ if (typeof headline !== "string") return "";
90
+ const head = headline.split(/[,:;·]|\s[—–-]\s/)[0].trim();
91
+ const words = head.split(/\s+/);
92
+ return words.length > 5 ? words.slice(0, 5).join(" ") : head;
93
+ }
94
+
95
+ /** "The change (PR #12)", "The fix (PR #13)": the current cycle's numbers once known, the chapter's role alone before. */
96
+ export function chapterTitle(index, pull) {
97
+ const role = index === 0 ? "The change" : index === 1 ? "The fix" : `Pull request ${index + 1}`;
98
+ return Number.isInteger(pull) ? `${role} (PR #${pull})` : role;
99
+ }
100
+
101
+ /**
102
+ * The track as it stands now. `demo` is demo.json; `pulls` the pull requests
103
+ * this cycle has opened, in order; `since` when the current segment began
104
+ * (ms); `waves` the apply's waves as the paced graph shows them
105
+ * ([{ wave, state }]), for the applying segment's ticks.
106
+ */
107
+ export function trackModel(track, { demo, pulls = [], since = null, now = Date.now(), waves = null } = {}) {
108
+ if (!track || !demo) return null;
109
+ // Where the cycle is: the step's own story chapter when told in them; else the chapter of the current pull request
110
+ // (the reset, the last). Then the segment holding the step.
111
+ const ci = track.byStory && demo.chapter && Number.isInteger(demo.chapter.n)
112
+ ? Math.max(0, track.chapters.findIndex((c) => c.n === demo.chapter.n))
113
+ : demo.step === "reset" || !Number.isInteger(demo.pull) ? track.chapters.length - 1 : Math.max(0, pulls.indexOf(demo.pull));
114
+ const chapter = track.chapters[Math.min(ci, track.chapters.length - 1)];
115
+ const si = chapter ? chapter.segments.findIndex((g) => g.steps.includes(demo.step)) : -1;
116
+ const at = { chapter: Math.min(ci, track.chapters.length - 1), segment: si };
117
+ const elapsed = typeof since === "number" ? Math.max(0, now - since) : 0;
118
+ const current = chapter && si >= 0 ? chapter.segments[si] : null;
119
+ const expected = current ? current.ms : 0;
120
+ const overrun = !!current && expected > 0 && elapsed > overrunAfter(expected);
121
+ const fill = current ? (expected > 0 ? Math.min(FILL_CAP, elapsed / expected) : FILL_CAP) : 0;
122
+ const share = (g) => Math.max(MIN_SHARE, g.ms / track.total);
123
+ const chapters = track.chapters.map((c, i) => ({
124
+ title: track.byStory ? `${c.n} ${c.short}` : chapterTitle(i, pulls[i]),
125
+ state: i < at.chapter ? "done" : i === at.chapter ? "current" : "ahead",
126
+ segments: c.segments.map((g, j) => {
127
+ const state = i < at.chapter || (i === at.chapter && j < at.segment) ? "done" : i === at.chapter && j === at.segment ? "current" : "ahead";
128
+ const tone = g.label === "failed" && state !== "ahead" ? "bad" : g.label === "done" && state !== "ahead" ? "ok" : state === "ahead" ? "ahead" : "past";
129
+ return {
130
+ label: g.label,
131
+ short: SHORT[g.label] || g.label,
132
+ share: share(g),
133
+ state,
134
+ tone,
135
+ fill: state === "done" ? 1 : state === "current" ? fill : 0,
136
+ ...(state === "current" && g.label === "applying" && Array.isArray(waves) && waves.length ? { ticks: waves.map((w) => ({ wave: w.wave, state: w.state })) } : {}),
137
+ };
138
+ }),
139
+ }));
140
+ const nowLine = nowWords({ demo, segment: current, expected, elapsed, overrun, waves, now, fix: track.byStory ? pulls.indexOf(demo.pull) > 0 : at.chapter > 0 });
141
+ return { chapters, at, elapsed, expected, overrun, now: nowLine };
142
+ }
143
+
144
+ const typical = (expected, overrun) => (overrun ? "taking longer than usual…" : expected > 0 ? `usually about ${secs(expected)} s` : null);
145
+ const countdown = (demo, now) => {
146
+ const at = demo && demo.next && demo.next.at ? Date.parse(demo.next.at) : NaN;
147
+ return Number.isFinite(at) ? Math.max(0, Math.ceil((at - now) / 1000)) : null;
148
+ };
149
+
150
+ /** What is happening now and what is waited on, in plain words: `{ text, waiting, why, expected, elapsed, overrun }`. */
151
+ export function nowWords({ demo, segment, expected = 0, elapsed = 0, overrun = false, waves = null, now = Date.now(), fix = false } = {}) {
152
+ if (!demo || !segment) return null;
153
+ const why = firstSentence(demo.label);
154
+ const base = { why, expected, elapsed, overrun };
155
+ const left = countdown(demo, now);
156
+ const running = Array.isArray(waves) ? waves.filter((w) => w.state === "running").map((w) => w.wave) : [];
157
+ const wavesSeen = Array.isArray(waves) && waves.some((w) => w.state && w.state !== "waiting");
158
+ const say = (text, waiting = null, timed = true) => ({ ...base, text: timed && typical(expected, overrun) ? `${text} · ${typical(expected, overrun)}` : text, waiting });
159
+ switch (segment.label) {
160
+ case "opened":
161
+ case "fix opened":
162
+ return say("The pipeline is starting the plan job", "the pipeline to start the plan");
163
+ case "planned":
164
+ return say(fix ? "The fix is planned; a review is asked next" : "The plan is in; a review is asked next");
165
+ case "review":
166
+ return say("Waiting for the reviewer", "the reviewer to approve the plan");
167
+ case "merged":
168
+ return say("The pipeline is starting the apply job", "the pipeline to start the apply");
169
+ case "applying":
170
+ if (running.length) return say(`Wave ${running.join(" and ")} is applying`, null, false);
171
+ if (wavesSeen) return say("The apply is under way", null, false);
172
+ return say("The pipeline is starting the apply job", "the pipeline to start the apply");
173
+ case "failed":
174
+ return { ...base, text: left !== null && left > 0 ? `The fix opens in ${left} s` : "The fix opens next", waiting: "the fix to open" };
175
+ case "done":
176
+ return { ...base, text: left !== null && left > 0 ? `All done · reset in ${left} s` : "All done" };
177
+ case "reset":
178
+ return say("Resetting for the next cycle", null);
179
+ default:
180
+ return say(segment.label);
181
+ }
182
+ }
183
+
184
+ /** A label's first sentence, when it reads as one line. */
185
+ function firstSentence(label) {
186
+ if (typeof label !== "string" || !label.trim()) return null;
187
+ const m = /^(.+?[.!?])(\s|$)/.exec(label.trim());
188
+ const s = m ? m[1] : label.trim();
189
+ return s.length <= 160 ? s : null;
190
+ }
191
+
192
+ /**
193
+ * The "Waiting on…" modal, or null: only in a quiet stretch (nothing new for
194
+ * {@link WAITING_AFTER_MS}), only for a step that waits on something (the
195
+ * plan or apply job starting, the reviewer, the fix's countdown), never while
196
+ * an apply is receiving events. `{ key, what, why, fraction, words }`.
197
+ */
198
+ export function waitingSpec(model, { quietMs = 0, applyLive = false } = {}) {
199
+ if (!model || !model.now || !model.now.waiting) return null;
200
+ if (quietMs < WAITING_AFTER_MS) return null;
201
+ if (applyLive) return null;
202
+ const n = model.now;
203
+ const fraction = n.expected > 0 ? Math.min(FILL_CAP, n.elapsed / n.expected) : null;
204
+ return {
205
+ key: `${model.at.chapter}|${model.at.segment}|${n.waiting}`,
206
+ what: n.waiting,
207
+ why: n.why,
208
+ fraction,
209
+ words: n.overrun ? "taking longer than usual" : n.expected > 0 ? `usually about ${secs(n.expected)} s` : null,
210
+ };
211
+ }
212
+
213
+ /** The track's look, once per document. Motion only without prefers-reduced-motion. */
214
+ export const TRACK_STYLE = `
215
+ #k-track { display: flex; flex-direction: column; gap: 0.25em; padding: 0.35em 1.4em 0.4em; font: 600 0.8em var(--font-ui); color: var(--muted); background: var(--surface-pane-b); border-top: 1px solid color-mix(in srgb, var(--rule) 60%, transparent); border-radius: 8px 8px 0 0; }
216
+ body.k-watch #k-track { position: fixed; z-index: 7; left: 5px; right: 5px; }
217
+ #k-track .kt-row { display: flex; gap: 0.6em; align-items: stretch; min-width: 0; }
218
+ #k-track .kt-chapter { display: flex; flex-direction: column; gap: 0.15em; min-width: min-content; }
219
+ #k-track .kt-chapter-title { font-size: 0.85em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--fg); }
220
+ #k-track .kt-chapter.kt-ahead .kt-chapter-title { color: var(--muted); }
221
+ #k-track .kt-chapter.kt-current .kt-chapter-title { color: var(--pending); }
222
+ #k-track .kt-segs { display: flex; gap: 3px; }
223
+ #k-track .kt-seg { position: relative; height: 1.7em; border-radius: 5px; border: 1.5px solid color-mix(in srgb, var(--muted) 60%, transparent); overflow: hidden; min-width: 0; flex-shrink: 1; }
224
+ #k-track .kt-seg .kt-fill { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--pending) 55%, transparent); }
225
+ #k-track .kt-seg.kt-past .kt-fill { background: color-mix(in srgb, var(--neutral, var(--muted)) 45%, transparent); }
226
+ #k-track .kt-seg.kt-ok { border-color: var(--frame-managed, var(--managed)); }
227
+ #k-track .kt-seg.kt-ok .kt-fill { background: color-mix(in srgb, var(--frame-managed, var(--managed)) 60%, transparent); }
228
+ #k-track .kt-seg.kt-bad { border-color: var(--frame-degraded, var(--degraded)); }
229
+ #k-track .kt-seg.kt-bad .kt-fill { background: color-mix(in srgb, var(--frame-degraded, var(--degraded)) 65%, transparent); }
230
+ #k-track .kt-seg.kt-current { border-color: var(--pending); }
231
+ #k-track .kt-seg .kt-label { position: relative; z-index: 1; display: block; padding: 0 0.4em; line-height: 1.7em; font-size: 0.85em; white-space: nowrap; overflow: hidden; text-overflow: clip; color: var(--fg); text-align: center; }
232
+ #k-track .kt-seg.kt-ahead .kt-label { color: var(--muted); }
233
+ #k-track .kt-tick { position: absolute; top: 0; bottom: 0; width: 3px; background: color-mix(in srgb, var(--muted) 50%, transparent); }
234
+ #k-track .kt-tick.kt-tick-running { background: var(--frame-runtime, var(--runtime)); }
235
+ #k-track .kt-tick.kt-tick-applied { background: var(--frame-managed, var(--managed)); }
236
+ #k-track .kt-tick.kt-tick-failed { background: var(--frame-degraded, var(--degraded)); }
237
+ #k-track .kt-now { font-size: 1.05em; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
238
+ @media (prefers-reduced-motion: no-preference) {
239
+ #k-track .kt-seg.kt-current .kt-fill { transition: width 0.9s linear; }
240
+ #k-track .kt-seg.kt-current .kt-fill::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, color-mix(in srgb, white 28%, transparent), transparent); background-size: 50% 100%; background-repeat: no-repeat; animation: kt-sheen 2.4s ease-in-out infinite; }
241
+ @keyframes kt-sheen { from { background-position: -60% 0; } to { background-position: 160% 0; } }
242
+ }
243
+ @media (max-width: 600px) {
244
+ body.k-watch #k-track { position: static; }
245
+ #k-track .kt-segs .kt-label { display: none; }
246
+ #k-track .kt-seg { height: 0.8em; }
247
+ }
248
+ `;
249
+
250
+ /** Draw the model into `host` (a fresh build each time: the track is a few dozen nodes). */
251
+ export function drawTrack(host, model, doc = typeof document !== "undefined" ? document : null) {
252
+ if (!host || !doc) return;
253
+ if (doc.head && !doc.getElementById("kt-style")) {
254
+ const st = doc.createElement("style");
255
+ st.id = "kt-style";
256
+ st.textContent = TRACK_STYLE;
257
+ doc.head.appendChild(st);
258
+ }
259
+ const el = (tag, cls, text) => {
260
+ const n = doc.createElement(tag);
261
+ if (cls) n.className = cls;
262
+ if (text !== undefined && text !== null) n.textContent = text;
263
+ return n;
264
+ };
265
+ host.replaceChildren();
266
+ if (!model) {
267
+ host.hidden = true;
268
+ return;
269
+ }
270
+ host.hidden = false;
271
+ const row = el("div", "kt-row");
272
+ const total = model.chapters.reduce((s, c) => s + c.segments.reduce((a, g) => a + g.share, 0), 0) || 1;
273
+ for (const c of model.chapters) {
274
+ const share = c.segments.reduce((a, g) => a + g.share, 0) / total;
275
+ const ch = el("div", `kt-chapter kt-${c.state}`);
276
+ // Grow factors summing to well over 1: below 1 a flex row leaves the rest of its width empty.
277
+ ch.style.flex = `${Math.round(share * 1000)} 1 0`;
278
+ ch.appendChild(el("div", "kt-chapter-title", c.title));
279
+ const segs = el("div", "kt-segs");
280
+ for (const g of c.segments) {
281
+ const seg = el("div", `kt-seg kt-${g.state} kt-${g.tone}`);
282
+ seg.style.flex = `${Math.round(g.share * 1000)} 1 0`;
283
+ // Never narrower than its short label, whole.
284
+ seg.style.minWidth = `${(g.short.length * 0.62 + 1).toFixed(2)}em`;
285
+ seg.title = g.label;
286
+ const fill = el("div", "kt-fill");
287
+ fill.style.width = `${Math.round(g.fill * 1000) / 10}%`;
288
+ seg.appendChild(fill);
289
+ if (g.ticks) {
290
+ // The apply's waves, each a tick at its share of the segment, lit as the paced graph lights them.
291
+ g.ticks.forEach((t, i) => {
292
+ const tick = el("i", `kt-tick kt-tick-${t.state === "running" ? "running" : t.state === "applied" ? "applied" : t.state === "failed" ? "failed" : "waiting"}`);
293
+ tick.style.left = `${Math.round(((i + 1) / (g.ticks.length + 1)) * 1000) / 10}%`;
294
+ tick.title = `wave ${t.wave}`;
295
+ seg.appendChild(tick);
296
+ });
297
+ }
298
+ const lab = el("span", "kt-label", g.label);
299
+ lab.dataset.short = g.short;
300
+ seg.appendChild(lab);
301
+ segs.appendChild(seg);
302
+ }
303
+ ch.appendChild(segs);
304
+ row.appendChild(ch);
305
+ }
306
+ host.appendChild(row);
307
+ if (model.now && model.now.text) host.appendChild(el("p", "kt-now", model.now.text));
308
+ // A label its segment cannot hold whole says its short form ("plan", "merge"); never a clipped word.
309
+ for (const lab of host.querySelectorAll ? host.querySelectorAll(".kt-label") : []) {
310
+ if (lab.scrollWidth > lab.clientWidth + 1 && lab.dataset.short) lab.textContent = lab.dataset.short;
311
+ }
312
+ }
@@ -0,0 +1,148 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { FILL_CAP, cycleTrack, trackModel, waitingSpec } from "./kiosk-track.js";
3
+
4
+ // behold#631: chant-fanout's last finished cycle as cycles/chant-fanout/latest.json had it (cycle 499):
5
+ // fifteen steps, two pull requests, from the change's open to the reset.
6
+ const T = (s) => `2026-10-18T18:${s}Z`;
7
+ const step = (at, s, pull, label = "", next = null) => ({ at: T(at), step: s, pull, label, ...(next ? { next } : {}) });
8
+ const cycle = {
9
+ cycle: 499,
10
+ started: T("18:48"),
11
+ ended: T("21:10"),
12
+ steps: [
13
+ step("18:49", "pull-request", 641, "Pull request 641 is open."),
14
+ step("19:01", "planned", 641),
15
+ step("19:14", "waiting", 641, "The plan waits for a reviewer's approval."),
16
+ step("19:27", "approved", 641),
17
+ step("19:27", "merged", 641),
18
+ step("19:30", "applying", 641),
19
+ step("19:49", "failed", 641),
20
+ step("20:10", "pull-request", 642),
21
+ step("20:22", "planned", 642),
22
+ step("20:26", "waiting", 642),
23
+ step("20:36", "approved", 642),
24
+ step("20:36", "merged", 642),
25
+ step("20:37", "applying", 642),
26
+ step("20:56", "applied", 642),
27
+ step("21:10", "reset", null),
28
+ ],
29
+ };
30
+
31
+ describe("the projected cycle track (behold#631)", () => {
32
+ const track = cycleTrack(cycle);
33
+
34
+ it("lays the last cycle out as two chapters of plainly labelled segments, as long as each step took", () => {
35
+ expect(track.chapters.map((c) => c.segments.map((g) => g.label))).toEqual([
36
+ ["opened", "planned", "review", "merged", "applying", "failed"],
37
+ ["fix opened", "planned", "review", "merged", "applying", "done", "reset"],
38
+ ]);
39
+ // The review holds the wait and the approval: 13 s from waiting to the merge.
40
+ expect(track.chapters[0].segments[2]).toMatchObject({ steps: ["waiting", "approved"], ms: 13_000 });
41
+ expect(track.chapters[0].segments[4].ms).toBe(19_000);
42
+ });
43
+
44
+ it("fills what is past, fills the current step as its time passes, and leaves the rest outlined", () => {
45
+ const now = Date.parse(T("40:00"));
46
+ const m = trackModel(track, { demo: { step: "waiting", pull: 12, cycle: 7, label: "The plan waits for a reviewer's approval." }, pulls: [12], since: now - 6_500, now });
47
+ expect(m.chapters.map((c) => c.title)).toEqual(["The change (PR #12)", "The fix"]);
48
+ const segs = m.chapters[0].segments;
49
+ expect(segs.slice(0, 2).map((g) => [g.state, g.fill])).toEqual([["done", 1], ["done", 1]]);
50
+ expect(segs[2]).toMatchObject({ state: "current", label: "review" });
51
+ expect(segs[2].fill).toBeCloseTo(0.5, 1);
52
+ expect(m.chapters[1].segments.every((g) => g.state === "ahead" && g.fill === 0)).toBe(true);
53
+ expect(m.now.text).toBe("Waiting for the reviewer · usually about 13 s");
54
+ });
55
+
56
+ it("caps the fill and says so when a step runs long", () => {
57
+ const now = Date.parse(T("40:00"));
58
+ // 12 s usual: still "usually" at 19 s (under 12 + 8), long at 21 s.
59
+ const early = trackModel(track, { demo: { step: "pull-request", pull: 12 }, pulls: [12], since: now - 19_000, now });
60
+ expect(early.chapters[0].segments[0].fill).toBe(FILL_CAP);
61
+ expect(early.now.text).toBe("The pipeline is starting the plan job · usually about 12 s");
62
+ const m = trackModel(track, { demo: { step: "pull-request", pull: 12 }, pulls: [12], since: now - 21_000, now });
63
+ expect(m.chapters[0].segments[0].fill).toBe(FILL_CAP);
64
+ expect(m.now.text).toBe("The pipeline is starting the plan job · taking longer than usual…");
65
+ });
66
+
67
+ it("colours a failure red and the end green, and puts the fix's own pull request number on its chapter", () => {
68
+ const now = Date.parse(T("40:00"));
69
+ const m = trackModel(track, { demo: { step: "applied", pull: 13 }, pulls: [12, 13], since: now, now });
70
+ expect(m.chapters.map((c) => c.title)).toEqual(["The change (PR #12)", "The fix (PR #13)"]);
71
+ expect(m.chapters[0].segments[5]).toMatchObject({ label: "failed", tone: "bad", fill: 1 });
72
+ expect(m.chapters[1].segments[5]).toMatchObject({ label: "done", tone: "ok", state: "current" });
73
+ });
74
+
75
+ it("lights the apply's waves inside its segment, and says which one applies", () => {
76
+ const now = Date.parse(T("40:00"));
77
+ const waves = [{ wave: 1, state: "applied" }, { wave: 2, state: "running" }, { wave: 3, state: "waiting" }];
78
+ const m = trackModel(track, { demo: { step: "applying", pull: 12 }, pulls: [12], since: now - 4_000, now, waves });
79
+ expect(m.chapters[0].segments[4].ticks).toEqual(waves);
80
+ expect(m.now.text).toBe("Wave 2 is applying");
81
+ });
82
+
83
+ it("says the fix's countdown", () => {
84
+ const now = Date.parse(T("40:00"));
85
+ const m = trackModel(track, { demo: { step: "failed", pull: 12, next: { action: "open the fix", at: T("40:14") } }, pulls: [12], since: now, now });
86
+ expect(m.now.text).toBe("The fix opens in 14 s");
87
+ });
88
+
89
+ it("is nothing without a last cycle, so the chip strip stays", () => {
90
+ expect(cycleTrack(null)).toBeNull();
91
+ expect(cycleTrack({ steps: [] })).toBeNull();
92
+ });
93
+ });
94
+
95
+ describe("the track in the story's four chapters (behold#631)", () => {
96
+ const ch = (n, headline, short) => ({ n, of: 4, headline, ...(short ? { short } : {}) });
97
+ const chapters = [ch(1, "A change to the shared network goes out to all 15 stacks", "The change goes out"), ch(2, "cluster-a breaks, and only its six apps wait", "cluster-a breaks"), ch(3, "The fix applies only the seven left", "The fix"), ch(4, "All fifteen are in", "Done")];
98
+ const of = (step) => (["failed"].includes(step) ? chapters[1] : ["applied", "reset"].includes(step) ? chapters[3] : null);
99
+ const told = { ...cycle, steps: cycle.steps.map((s, i) => ({ ...s, chapter: of(s.step) || (i < 6 ? chapters[0] : chapters[2]) })) };
100
+ const track = cycleTrack(told);
101
+ it("groups the segments by chapter, each titled with its number and short name", () => {
102
+ expect(track.byStory).toBe(true);
103
+ expect(track.chapters.map((c) => [c.n, c.short, c.segments.map((g) => g.label)])).toEqual([
104
+ [1, "The change goes out", ["opened", "planned", "review", "merged", "applying"]],
105
+ [2, "cluster-a breaks", ["failed"]],
106
+ [3, "The fix", ["fix opened", "planned", "review", "merged", "applying"]],
107
+ [4, "Done", ["done", "reset"]],
108
+ ]);
109
+ });
110
+ it("finds where the cycle is by the step's own chapter, and lights that chapter's title", () => {
111
+ const now = Date.parse(T("40:00"));
112
+ const m = trackModel(track, { demo: { step: "applying", pull: 13, chapter: chapters[2] }, pulls: [12, 13], since: now - 2_000, now });
113
+ expect(m.chapters.map((c) => [c.title, c.state])).toEqual([["1 The change goes out", "done"], ["2 cluster-a breaks", "done"], ["3 The fix", "current"], ["4 Done", "ahead"]]);
114
+ expect(m.chapters[2].segments[4]).toMatchObject({ label: "applying", state: "current" });
115
+ });
116
+ it("names a chapter from its headline when the driver gives no short name", () => {
117
+ const plain = cycleTrack({ ...cycle, steps: told.steps.map((s) => ({ ...s, chapter: { n: s.chapter.n, of: 4, headline: s.chapter.headline } })) });
118
+ expect(plain.chapters[1].short).toBe("cluster-a breaks");
119
+ });
120
+ it("keeps one chapter per pull request for a cycle whose steps carry no chapter", () => {
121
+ expect(cycleTrack(cycle).byStory).toBe(false);
122
+ });
123
+ });
124
+
125
+ describe("the Waiting on… modal (behold#631)", () => {
126
+ const track = cycleTrack(cycle);
127
+ const now = Date.parse(T("40:00"));
128
+ const at = (demo, ago) => trackModel(track, { demo, pulls: [12], since: now - ago, now });
129
+ it("shows after 3 s with nothing new, for what the step waits on, with the usual time", () => {
130
+ const m = at({ step: "pull-request", pull: 12, label: "Pull request 12 is open. Network changes." }, 4_000);
131
+ expect(waitingSpec(m, { quietMs: 2_000 })).toBeNull();
132
+ const w = waitingSpec(m, { quietMs: 3_500 });
133
+ expect(w).toMatchObject({ what: "the pipeline to start the plan", why: "Pull request 12 is open.", words: "usually about 12 s" });
134
+ expect(w.fraction).toBeCloseTo(4 / 12, 2);
135
+ });
136
+ it("covers the reviewer, the apply starting and the fix's countdown, and says when a step runs long", () => {
137
+ expect(waitingSpec(at({ step: "waiting", pull: 12 }, 1_000), { quietMs: 5_000 }).what).toBe("the reviewer to approve the plan");
138
+ expect(waitingSpec(at({ step: "merged", pull: 12 }, 1_000), { quietMs: 5_000 }).what).toBe("the pipeline to start the apply");
139
+ expect(waitingSpec(at({ step: "failed", pull: 12 }, 1_000), { quietMs: 5_000 }).what).toBe("the fix to open");
140
+ expect(waitingSpec(at({ step: "waiting", pull: 12 }, 60_000), { quietMs: 5_000 }).words).toBe("taking longer than usual");
141
+ // Not before half again its usual time and 8 s past it: 14 s into a 13 s review is still usual.
142
+ expect(waitingSpec(at({ step: "waiting", pull: 12 }, 14_000), { quietMs: 5_000 }).words).toBe("usually about 13 s");
143
+ });
144
+ it("never during an apply that is receiving events, or a step that waits on nothing", () => {
145
+ expect(waitingSpec(at({ step: "applying", pull: 12 }, 1_000), { quietMs: 5_000, applyLive: true })).toBeNull();
146
+ expect(waitingSpec(at({ step: "planned", pull: 12 }, 1_000), { quietMs: 5_000 })).toBeNull();
147
+ });
148
+ });
@@ -0,0 +1,58 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { STRIP, renderKiosk, stripStops } from "./kiosk.js";
3
+ import { captionModel, stepTone } from "./kiosk-watch.js";
4
+ import { cycleTrack, trackModel } from "./kiosk-track.js";
5
+
6
+ // behold#752 (chant#4102): a step can be added within demo-step contract 1, so a step the kiosk doesn't know is
7
+ // unclassified: shown by its own name, lighting no stop, never breaking the page.
8
+ const UNKNOWN = "rolling-back";
9
+ const demo = (step, extra = {}) => ({ cycle: 610, scenario: "fan-out", title: "A broken stack shouldn't stall the whole rollout", step, label: "The driver does something new.", started_at: "2026-10-19T02:25:07Z", next: null, pull: 774, commit: "80eef4a5e0eb747fddb04a7067e91ea59dd8dade", tool: "chant-fanout", repo: "chant-demo/fan-out-estate", ...extra });
10
+
11
+ describe("a step the kiosk doesn't know (behold#752)", () => {
12
+ it("lights no stop of the strip and takes a running tone", () => {
13
+ expect(stripStops(UNKNOWN, STRIP).every((s) => s.state === "ahead")).toBe(true);
14
+ expect(stepTone(UNKNOWN)).toBe("busy");
15
+ });
16
+ it("is captioned by its own name, with the driver's label", () => {
17
+ const c = captionModel(demo(UNKNOWN, { chapter: { n: 3, of: 4, headline: "The fix", short: "The fix" } }), { now: new Date("2026-10-19T02:27:05Z") });
18
+ expect(c.step).toMatchObject({ word: UNKNOWN, text: "The driver does something new.", id: UNKNOWN });
19
+ });
20
+ it("leaves the projected track drawn from the last cycle, with nothing current", () => {
21
+ const T = (s) => `2026-10-19T02:${s}Z`;
22
+ const cycle = { cycle: 610, started: T("25:07"), ended: T("27:37"), steps: [
23
+ { at: T("25:09"), step: "pull-request", pull: 773 },
24
+ { at: T("25:20"), step: "planned", pull: 773 },
25
+ { at: T("25:48"), step: "applying", pull: 773 },
26
+ { at: T("26:00"), step: UNKNOWN, pull: 773 },
27
+ { at: T("26:12"), step: "failed", pull: 773 },
28
+ { at: T("27:37"), step: "reset", pull: null },
29
+ ] };
30
+ const track = cycleTrack(cycle);
31
+ const now = Date.parse(T("40:00"));
32
+ const m = trackModel(track, { demo: demo(UNKNOWN, { pull: 773 }), pulls: [773], since: now - 1000, now });
33
+ expect(m).toBeTruthy();
34
+ });
35
+ it("renders in the bar, its row named by the step", () => {
36
+ const make = (tag) => {
37
+ const n = { tagName: tag, className: "", textContent: "", children: [] };
38
+ n.appendChild = (c) => (n.children.push(c), c);
39
+ n.append = (...cs) => cs.forEach((c) => n.children.push(typeof c === "string" ? { tagName: "#text", textContent: c, children: [] } : c));
40
+ n.replaceChildren = () => (n.children = []);
41
+ return n;
42
+ };
43
+ const find = (n, cls) => (n.className.split(" ").includes(cls) ? [n] : []).concat(...(n.children || []).map((c) => (c.className !== undefined ? find(c, cls) : [])));
44
+ const was = globalThis.document;
45
+ globalThis.document = { createElement: make };
46
+ try {
47
+ const bar = document.createElement("header");
48
+ const s = { demo: { source: "fx", read: "2026-10-19T02:27:05Z", demo: demo(UNKNOWN) }, answer: null, progress: null };
49
+ expect(() => renderKiosk(bar, s, new Date("2026-10-19T02:27:05Z"))).not.toThrow();
50
+ const row = find(bar, "k-row-step")[0];
51
+ expect(row.className).toContain(`k-step-${UNKNOWN}`);
52
+ expect(row.children[0].textContent).toBe(UNKNOWN);
53
+ expect(find(bar, "k-stop").length).toBeGreaterThan(0);
54
+ } finally {
55
+ globalThis.document = was;
56
+ }
57
+ });
58
+ });
@@ -84,6 +84,54 @@ export const VENDORS = {
84
84
  runsWith: ["opentofu"],
85
85
  reports: false,
86
86
  },
87
+ // behold#746: a page per fan-out scenario. The loop runs one fan-out per
88
+ // pipeline, each on its own repo, and each repo's behold links its own page;
89
+ // /kiosk follows whichever runs. A fan-out page carries its product's name
90
+ // alone and competes with the other fan-outs (`kind: "fanout"`), so none
91
+ // names another's product. `hides` are words the page leaves out anywhere,
92
+ // inside an identifier too (the jobs' `terragucci-demo-tofu:local` image,
93
+ // the forge's `terragucci-admin`).
94
+ // - chant-fanout: chant's own pull-request pipeline does the work; terragucci
95
+ // only supplies the demo stack and its driver, so neither terragucci nor the
96
+ // OpenTofu its jobs install is said. Its runs are chant's (no terragucci reports).
97
+ // chant is no word the other two leave out: terragucci's waves approve
98
+ // with `chant approve`, as on the engine pages (COMPETES).
99
+ // - tofu-fanout: terragucci's pipeline on OpenTofu. terragucci is the product
100
+ // there, so it stays. Its repo is demo-fanout (`checkout`).
101
+ // - choudoufu-fanout: terragucci's pipeline on choudoufu.
102
+ "chant-fanout": {
103
+ name: "chant",
104
+ owner: "Intentius",
105
+ url: "https://intentius.io/chant/",
106
+ logo: null,
107
+ credit: "chant is made by Intentius, who also make this demo.",
108
+ kind: "fanout",
109
+ terms: [],
110
+ runsWith: [],
111
+ reports: false,
112
+ hides: ["terragucci", "tofu"],
113
+ },
114
+ "tofu-fanout": {
115
+ name: "OpenTofu",
116
+ owner: "the Linux Foundation",
117
+ url: "https://opentofu.org/",
118
+ logo: null,
119
+ credit: "OpenTofu is a Linux Foundation project. Its makers don't endorse this demo.",
120
+ kind: "fanout",
121
+ terms: ["OpenTofu"],
122
+ runsWith: [],
123
+ checkout: "demo-fanout",
124
+ },
125
+ "choudoufu-fanout": {
126
+ name: "choudoufu",
127
+ owner: "Intentius",
128
+ url: "https://intentius.io/choudoufu/",
129
+ logo: { src: "/vendors/choudoufu-64.png", src2x: "/vendors/choudoufu-128.png" },
130
+ credit: "choudoufu is made by Intentius, who also make this demo. It supports AWS and Kubernetes.",
131
+ kind: "fanout",
132
+ terms: ["choudoufu"],
133
+ runsWith: [],
134
+ },
87
135
  };
88
136
 
89
137
  /** What a tool's scenarios run on, said on its page as the owner's rules allow ("works with OpenTofu"). */
@@ -114,8 +162,10 @@ export const COMPETITORS = {
114
162
  * freely; an engine's page names no other engine, but for the one its
115
163
  * scenarios really run with (`runsWith`). chant is a pipeline, so the engine
116
164
  * and orchestrator pages keep the `chant approve` lines their runs print.
165
+ * behold#746: the fan-out pages compete with each other alone, whatever
166
+ * engine or pipeline each runs: three takes on one scenario.
117
167
  */
118
- export const COMPETES = { engine: "engine", orchestrator: "orchestrator", pipeline: "pipeline" };
168
+ export const COMPETES = { engine: "engine", orchestrator: "orchestrator", pipeline: "pipeline", fanout: "fanout" };
119
169
 
120
170
  const own = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
121
171
 
@@ -131,10 +181,21 @@ export function pageTool(doc) {
131
181
  return vendorOf(t) ? t : null;
132
182
  }
133
183
 
184
+ /**
185
+ * behold#746: a scenario's tool as /kiosk brands it: its entry, but none for a
186
+ * fan-out tool, whose brand only its own page carries (/kiosk draws a fan-out
187
+ * as it did before the fan-outs had pages).
188
+ */
189
+ export function kioskVendorOf(tool) {
190
+ const v = vendorOf(tool);
191
+ return v && v.kind !== "fanout" ? v : null;
192
+ }
193
+
134
194
  /**
135
195
  * The words no page for `tool` may show: each competitor's name and maker's,
136
196
  * the competitors being the other tools of its kind, less what its scenarios
137
- * run with. A page for no tool (/kiosk) has none.
197
+ * run with, then (behold#746) what the tool's entry `hides`. A page for no
198
+ * tool (/kiosk) has none.
138
199
  */
139
200
  export function otherTerms(tool) {
140
201
  const v = vendorOf(tool);
@@ -145,7 +206,7 @@ export function otherTerms(tool) {
145
206
  if (id === tool || x.kind !== rivals || v.runsWith.includes(id)) continue;
146
207
  out.push(...x.terms);
147
208
  }
148
- return out;
209
+ return [...out, ...(v.hides || [])];
149
210
  }
150
211
 
151
212
  const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -157,6 +218,9 @@ const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
157
218
  */
158
219
  export function namesOther(text, tool) {
159
220
  if (typeof text !== "string" || !text) return false;
221
+ // behold#746: a word the tool's entry `hides` goes inside an identifier too (`terragucci-demo-tofu:local`).
222
+ const hides = (vendorOf(tool) || {}).hides || [];
223
+ if (hides.some((t) => text.toLowerCase().includes(t.toLowerCase()))) return true;
160
224
  return otherTerms(tool).some((t) => new RegExp(`(?<![\\w./-])${escapeRe(t)}(?![\\w/-])`, "i").test(text));
161
225
  }
162
226
 
@@ -183,6 +247,8 @@ export function scrubDemo(demo, tool) {
183
247
  label: keep(demo.label) ?? "",
184
248
  about: about && Object.keys(about).length ? about : null,
185
249
  next: demo.next ? { ...demo.next, action: keep(demo.next.action) ?? "the next step" } : null,
250
+ // behold#757: a step's highlight goes whole when its title or body names a rival: half of it would read wrong.
251
+ ...(demo.highlight ? { highlight: namesOther(demo.highlight.title, tool) || namesOther(demo.highlight.body, tool) ? null : demo.highlight } : {}),
186
252
  };
187
253
  }
188
254
 
@@ -370,7 +436,10 @@ export function notRunWords(vendor, { graph = false } = {}) {
370
436
  * for a tool with no page.
371
437
  */
372
438
  export function toolCheckout(tool) {
373
- if (!vendorOf(tool)) return null;
439
+ const v = vendorOf(tool);
440
+ if (!v) return null;
441
+ // behold#746: a repo the driver names otherwise says so (tofu-fanout's is demo-fanout).
442
+ if (v.checkout) return v.checkout;
374
443
  return tool === "terraform" ? "demo" : `demo-${tool}`;
375
444
  }
376
445