@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
@@ -279,7 +279,7 @@ async function defaultFetch(url) {
279
279
  * Start the pane in `host`. `tool` is the tool of a tool's page, null on
280
280
  * /kiosk. Returns `{ stop }`.
281
281
  */
282
- export function startMetrics(host, { tool = null, fetchJson = defaultFetch, store = null, setTimer = setInterval, clearTimer = clearInterval, doc = document, onModel = () => {} } = {}) {
282
+ export function startMetrics(host, { tool = null, reads = { demo: "/api/terragucci/demo", cycle: (t) => `/api/terragucci/cycles/${t}` }, fetchJson = defaultFetch, store = null, setTimer = setInterval, clearTimer = clearInterval, doc = document, onModel = () => {} } = {}) {
283
283
  if (!host) return { stop() {} };
284
284
  if (doc.head && !doc.getElementById("k-metrics-style")) {
285
285
  const style = el(doc, "style");
@@ -311,8 +311,9 @@ export function startMetrics(host, { tool = null, fetchJson = defaultFetch, stor
311
311
  if (busy) return;
312
312
  busy = true;
313
313
  try {
314
- const demo = await fetchJson("/api/terragucci/demo");
315
- const latest = tool && !(demo && demo.demo && demo.demo.tool === tool) ? await fetchJson(`/api/terragucci/cycles/${tool}`) : null;
314
+ // behold#752: the page's own demo, terragucci's or chant's (web/kiosk-source.js).
315
+ const demo = await fetchJson(reads.demo);
316
+ const latest = tool && !(demo && demo.demo && demo.demo.tool === tool) ? await fetchJson(reads.cycle(tool)) : null;
316
317
  const target = metricsTarget(demo, latest, tool);
317
318
  const answer = target ? await fetchJson(metricsUrl(target)) : null;
318
319
  // behold#571: which cycle this read is of; a read that failed keeps the pane as it was.
package/web/kiosk-runs.js CHANGED
@@ -414,12 +414,13 @@ export function statusIcon(status) {
414
414
  }
415
415
 
416
416
  /** The sidebar: the live run pinned, then the recent ones. `pick(id)` selects one; nothing here writes. */
417
- export function renderSidebar(host, index, selectedId, { now = new Date(), scenarios = {}, titles = {}, names = {}, pick = () => {}, merged = null, replay = false } = {}) {
417
+ export function renderSidebar(host, index, selectedId, { now = new Date(), scenarios = {}, titles = {}, names = {}, pick = () => {}, merged = null, replay = false, chant = false } = {}) {
418
418
  host.replaceChildren();
419
419
  const head = el("div", "r-side-head");
420
420
  head.appendChild(el("div", "r-side-title", "Runs"));
421
421
  // behold#571: a tool's page replays an earlier cycle's runs, and says so.
422
- head.appendChild(el("div", "r-side-note", replay ? "The replayed cycle's runs, newest first." : "From the forge, newest first."));
422
+ // behold#752: chant's demo's runs are built from chant's run events, not copied from the forge.
423
+ head.appendChild(el("div", "r-side-note", replay ? "The replayed cycle's runs, newest first." : chant ? "From chant's run events, newest first." : "From the forge, newest first."));
423
424
  host.appendChild(head);
424
425
  if (!index || index.error || index.absent || !index.doc) {
425
426
  host.appendChild(el("p", "r-note", index ? index.absent || index.error : "Reading the runs…"));
@@ -817,6 +818,8 @@ export function startRuns(
817
818
  filter = (index) => index,
818
819
  replay = () => false,
819
820
  hideLine = null,
821
+ // behold#752: where the live runs are read: terragucci's copies of forge runs, or chant's demo's runs built from its run events.
822
+ urls = { runs: "/api/terragucci/runs", run: (id) => `/api/terragucci/runs/${id}` },
820
823
  } = {},
821
824
  ) {
822
825
  const s = { index: null, run: null, selected: null, picked: 0, ui: { job: null, open: null, setup: null }, note: null, flash: null, scrollTo: null, pending: null, featsOpen: false };
@@ -865,7 +868,7 @@ export function startRuns(
865
868
  }
866
869
  // One merged read of the selected run for both the sidebar and its page.
867
870
  const merged = ans && ans.doc ? mergeRun(entry, ans.doc) : null;
868
- renderSidebar(side, s.index, id, { now: shown(), scenarios, titles: titles(), names: names(), pick, merged, replay: replay() });
871
+ renderSidebar(side, s.index, id, { now: shown(), scenarios, titles: titles(), names: names(), pick, merged, replay: replay(), chant: urls.runs.startsWith("/api/chant/") });
869
872
  // The redraw replaces the scrollers: keep where a viewer left them.
870
873
  const old = main.querySelector(".r-log");
871
874
  const oldSteps = main.querySelector(".r-steps");
@@ -1068,7 +1071,7 @@ export function startRuns(
1068
1071
  const readIndex = async () => {
1069
1072
  // behold#571: a tool's page reads its replay's runs from `source`, and keeps its own repo's alone.
1070
1073
  const src = source();
1071
- s.index = filter(src ? await src.index() : await fetchJson("/api/terragucci/runs"));
1074
+ s.index = filter(src ? await src.index() : await fetchJson(urls.runs));
1072
1075
  const runs = s.index && s.index.doc ? s.index.doc.runs : [];
1073
1076
  const live = liveRun(runs);
1074
1077
  onLive(live);
@@ -1087,7 +1090,7 @@ export function startRuns(
1087
1090
  if (key === lastRunKey && entry && !LIVE.has(entry.status) && s.run && s.run.doc && s.run.doc.id === id) return draw();
1088
1091
  if (s.run && s.run.doc && s.run.doc.id !== id && !s.pending) s.ui = { job: null, open: null, setup: null };
1089
1092
  lastRunKey = key;
1090
- s.run = src ? await src.run(id) : await fetchJson(`/api/terragucci/runs/${id}`);
1093
+ s.run = src ? await src.run(id) : await fetchJson(urls.run(id));
1091
1094
  draw();
1092
1095
  };
1093
1096
  void readIndex();
package/web/kiosk-shot.js CHANGED
@@ -13,8 +13,12 @@ export const SHOT_MAX_SCALE = 1.3;
13
13
  /** Room kept round a shot's target, in svg units. */
14
14
  export const SHOT_PAD = 36;
15
15
 
16
- /** A `behold:shot` message: what to frame, and the pane's covered edges in pixels. */
17
- export function shotMessage({ roots = [], waves = [], whole = false, insets = {}, ms = SHOT_MS, id = null } = {}) {
16
+ /**
17
+ * A `behold:shot` message: what to frame, and the pane's covered edges in
18
+ * pixels. `room`: the caption's tallest in the cycle, as a bottom inset in px
19
+ * (web/kiosk-watch.js captionRoom), which only a held small stage keeps.
20
+ */
21
+ export function shotMessage({ roots = [], waves = [], whole = false, insets = {}, ms = SHOT_MS, id = null, room = 0 } = {}) {
18
22
  const px = (v) => (Number.isFinite(v) && v > 0 ? Math.round(v) : 0);
19
23
  return {
20
24
  type: "behold:shot",
@@ -24,6 +28,7 @@ export function shotMessage({ roots = [], waves = [], whole = false, insets = {}
24
28
  whole: !!whole || (!roots.length && !waves.length),
25
29
  insets: { top: px(insets.top), right: px(insets.right), bottom: px(insets.bottom), left: px(insets.left) },
26
30
  ms: Number.isFinite(ms) && ms >= 0 ? ms : SHOT_MS,
31
+ ...(px(room) ? { room: px(room) } : {}),
27
32
  };
28
33
  }
29
34
 
@@ -35,7 +40,7 @@ export function shotFromMessage(event, host) {
35
40
  // Inspect: no shot; the frame fits the graph as it always has.
36
41
  if (d.release === true) return { type: "behold:shot", release: true };
37
42
  const list = (v) => (Array.isArray(v) ? v : []);
38
- return shotMessage({ roots: list(d.roots), waves: list(d.waves), whole: d.whole, insets: d.insets && typeof d.insets === "object" ? d.insets : {}, ms: d.ms, id: d.id ?? null });
43
+ return shotMessage({ roots: list(d.roots), waves: list(d.waves), whole: d.whole, insets: d.insets && typeof d.insets === "object" ? d.insets : {}, ms: d.ms, id: d.id ?? null, room: d.room });
39
44
  }
40
45
 
41
46
  /** The smallest box round several `{x, y, x2, y2}`, or null for none. */
@@ -101,3 +106,152 @@ export function tweenViewBox(a, b, t) {
101
106
  export function sameViewBox(a, b) {
102
107
  return !!a && !!b && a.length === 4 && b.length === 4 && a.every((v, i) => Math.abs(v - b[i]) < 0.5);
103
108
  }
109
+
110
+ // --- one framing on a small stage --------------------------------------------
111
+ // When the whole graph fits the stage with its cards drawn readably (a card
112
+ // at least SMALL_STAGE_CARD_PX wide on screen, the width the dots layer's
113
+ // cards are fully drawn at: web/dots-lod.js LOD.cardPx), Watch holds one shot
114
+ // of the whole graph: every step's shot frames the whole
115
+ // graph, and the viewBox stays where it is from step to step and cycle to
116
+ // cycle while the graph and the pane stay, so a root no
117
+ // step is about stays in view and emphasis is by light and dim only. A bigger
118
+ // graph keeps the per-step framing.
119
+
120
+ /**
121
+ * Whether a stage may be held at all: an estate whose every root runs on
122
+ * choudoufu's live backend, by the reports (`binaries`, root to binary). The
123
+ * scenarios on any other binary (b-waves, failure, tg-planned-outputs) keep
124
+ * Watch as it always was: a shot per step, and their cards over the graph.
125
+ */
126
+ export function holdsStage(binaries) {
127
+ const b = binaries && typeof binaries === "object" ? Object.values(binaries) : [];
128
+ return b.length > 0 && b.every((x) => x === "choudoufu");
129
+ }
130
+
131
+ /** The width in px a card needs on screen for the stage to count as small: dots-lod.js LOD.cardPx. */
132
+ export const SMALL_STAGE_CARD_PX = 90;
133
+
134
+ /**
135
+ * Room kept under the whole graph beyond the caption first seen, in px: the
136
+ * caption's extra rows (the cone line, the quiet line) and event-help's trail
137
+ * over it, which grows by a line or two as the cycle's beats come in, all fit
138
+ * in it, so none of them moves the frame.
139
+ */
140
+ export const HOLD_RESERVE_PX = 24;
141
+
142
+ /** Room kept at the top for the run's caption over the boxes ("Showing the plan of …"), in px. */
143
+ export const HELD_CAPTION_PX = 32;
144
+
145
+ /**
146
+ * The most a held stage zooms in, px per svg unit: as large as the stage area
147
+ * (the pane less the caption and its reserve) allows, up to this.
148
+ */
149
+ export const HELD_MAX_SCALE = 2.4;
150
+
151
+ /** A held framing at least this share of the width the graph needs is kept; a wider one frames again, to fill the stage. */
152
+ export const HELD_FILL = 0.9;
153
+
154
+ const boxInside = (a, b) => a.x >= b.x - 0.5 && a.y >= b.y - 0.5 && a.x2 <= b.x2 + 0.5 && a.y2 <= b.y2 + 0.5;
155
+
156
+ /**
157
+ * What a held stage frames, from the boxes' rects and the cards' own rects
158
+ * (svg units): the graph's boxes, each innermost box that holds a card (a box
159
+ * round other boxes, a member's or the page's, is not what the graph spans),
160
+ * and the cards inside them. A card in no box, a rect bigger than its card
161
+ * (a hover ring) or anything else on the page counts only when no box holds a
162
+ * card at all: then the cards are the graph. Null with no card.
163
+ */
164
+ export function heldTarget(boxes, cards) {
165
+ const cs = (cards || []).filter(Boolean);
166
+ if (!cs.length) return null;
167
+ const centre = (c) => ({ x: (c.x + c.x2) / 2, y: (c.y + c.y2) / 2 });
168
+ const holds = (b, c) => { const m = centre(c); return m.x > b.x && m.x < b.x2 && m.y > b.y && m.y < b.y2; };
169
+ const cand = (boxes || []).filter((b) => b && cs.some((c) => holds(b, c)));
170
+ const inner = cand.filter((b) => !cand.some((o) => o !== b && boxInside(o, b) && !boxInside(b, o)));
171
+ return inner.length ? unionBox(inner) : unionBox(cs);
172
+ }
173
+
174
+ /** How far the pane's size may differ, in px, and still be the same pane (a swapped-in frame's box can round otherwise). */
175
+ export const PANE_SLACK_PX = 2;
176
+
177
+ /**
178
+ * The insets a held stage frames clear of, from a shot's: the run's caption's
179
+ * room at the top, the caption under the stage, and the same margin at the
180
+ * right as at the left. Nothing a step shows sits over the graph in Watch
181
+ * (web/kiosk-watch.js watchOverlays), so no card's room is kept at the side,
182
+ * and the graph has the stage's whole width; a drawer a viewer opens lies
183
+ * over it until they fold it, and never moves the frame.
184
+ */
185
+ export function heldInsets(insets = {}, room = 0) {
186
+ const n = (v) => (Number.isFinite(v) && v > 0 ? v : 0);
187
+ return { top: n(insets.top) + HELD_CAPTION_PX, right: n(insets.left), bottom: Math.max(n(insets.bottom), n(room)), left: n(insets.left) };
188
+ }
189
+
190
+ /**
191
+ * Room kept round a held stage's graph, in svg units: none. The insets'
192
+ * margins (20 px at the sides, the run's caption's room at the top) keep the
193
+ * boxes off the edges, so the scale applied is min(openW / targetW, openH /
194
+ * targetH), up to HELD_MAX_SCALE.
195
+ */
196
+ export const HELD_PAD = 0;
197
+
198
+ /** How far, in svg units, the graph may lie past a held framing's open part and still be held: a few units, inside the margins. */
199
+ export const HELD_SLACK = 4;
200
+
201
+ /** The middle of a list of card widths, in svg units; 0 for none. */
202
+ export function medianWidth(widths) {
203
+ const w = widths.filter((x) => Number.isFinite(x) && x > 0).sort((a, b) => a - b);
204
+ return w.length ? w[w.length >> 1] : 0;
205
+ }
206
+
207
+ /**
208
+ * Whether the stage is small: the whole graph (`whole`, svg units), framed on
209
+ * `pane` clear of `insets`, draws a card `cardW` units wide at least `minPx` on screen.
210
+ */
211
+ export function smallStage(whole, pane, insets, cardW, { minPx = SMALL_STAGE_CARD_PX } = {}) {
212
+ if (!(cardW > 0)) return false;
213
+ const vb = shotViewBox(whole, pane, insets, { pad: HELD_PAD, maxScale: HELD_MAX_SCALE });
214
+ return !!vb && (cardW * pane.width) / vb[2] >= minPx;
215
+ }
216
+
217
+ /**
218
+ * The held whole-graph framing: `held` from the last call (or null), `key`
219
+ * naming the graph drawn (the repo and the view), the pane, the overlays'
220
+ * insets now (heldInsets) and the whole graph's box. The viewBox stays put
221
+ * from step to step and from cycle to cycle while the key and the pane's size
222
+ * stay (to PANE_SLACK_PX), the overlays fit in the room it kept, and the graph
223
+ * still lies in the open part of it (a badge, a label or a box a few units
224
+ * off moves nothing). Otherwise it is framed again, round the graph as it was
225
+ * and as it is, with room for the largest overlay seen so far, and
226
+ * HOLD_RESERVE_PX more under the graph. `{ key, pane, insets, target, vb,
227
+ * reason }`, `reason` saying why it was framed: "first", "key", "pane",
228
+ * "insets", "target", or "held" when it was not.
229
+ */
230
+ export function heldFrame(held, { key, pane, insets = {}, target }) {
231
+ const i = { top: insets.top || 0, right: insets.right || 0, bottom: insets.bottom || 0, left: insets.left || 0 };
232
+ const samePane = !!held && !!held.pane && Math.abs(held.pane.width - pane.width) <= PANE_SLACK_PX && Math.abs(held.pane.height - pane.height) <= PANE_SLACK_PX;
233
+ const same = !!held && !!held.vb && held.key === key && samePane;
234
+ const roomy = same && ["top", "right", "bottom", "left"].every((k) => i[k] <= held.insets[k]);
235
+ if (roomy && target) {
236
+ const [x, y, w, h] = held.vb;
237
+ const s = held.pane.width / w;
238
+ const open = { x: x + held.insets.left / s, y: y + held.insets.top / s, x2: x + w - held.insets.right / s, y2: y + h - held.insets.bottom / s };
239
+ // A box a few units off (a frame drawn from another checkout) moves nothing: the side margins hold it.
240
+ const inside = target.x >= open.x - HELD_SLACK && target.y >= open.y - HELD_SLACK && target.x2 <= open.x2 + HELD_SLACK && target.y2 <= open.y2 + HELD_SLACK;
241
+ // And it still fills the stage: a framing much wider than the graph needs (the graph got smaller) frames again.
242
+ const ideal = shotViewBox(target, held.pane, held.insets, { pad: HELD_PAD, maxScale: HELD_MAX_SCALE });
243
+ const fills = !ideal || ideal[2] >= held.vb[2] * HELD_FILL;
244
+ if (inside && fills) return held.reason === "held" ? held : { ...held, reason: "held" };
245
+ }
246
+ const reason = !held ? "first" : held.key !== key ? "key" : !samePane ? "pane" : !roomy ? "insets" : !target || !held.target || !boxInside(target, held.target) ? "target" : "fill";
247
+ const keep = same ? held.insets : { top: 0, right: 0, bottom: 0, left: 0 };
248
+ const room = {
249
+ top: Math.max(keep.top, i.top),
250
+ right: Math.max(keep.right, i.right),
251
+ bottom: i.bottom > keep.bottom ? i.bottom + HOLD_RESERVE_PX : keep.bottom,
252
+ left: Math.max(keep.left, i.left),
253
+ };
254
+ // Round the graph as it was and as it is, so a box a few units off never frames twice; a graph that shrank is framed as it is.
255
+ const box = same && target && reason !== "fill" ? unionBox([held.target, target]) : target;
256
+ return { key, pane: { width: pane.width, height: pane.height }, insets: room, target: box, vb: shotViewBox(box, pane, room, { pad: HELD_PAD, maxScale: HELD_MAX_SCALE }), reason };
257
+ }
@@ -1,7 +1,8 @@
1
1
  // behold#571: Watch mode's camera, as arithmetic: where a shot puts its
2
2
  // target, how a move goes, and which messages the frame takes.
3
3
  import { describe, expect, it } from "vitest";
4
- import { SHOT_MS, ease, sameViewBox, shotFromMessage, shotMessage, shotViewBox, tweenViewBox, unionBox } from "./kiosk-shot.js";
4
+ import { HELD_CAPTION_PX, HELD_FILL, HELD_MAX_SCALE, HELD_PAD, HOLD_RESERVE_PX, SHOT_MS, SMALL_STAGE_CARD_PX, ease, heldFrame, heldInsets, heldTarget, holdsStage, medianWidth, sameViewBox, shotFromMessage, shotMessage, shotViewBox, smallStage, tweenViewBox, unionBox } from "./kiosk-shot.js";
5
+ import { captionRoom, shotFor } from "./kiosk-watch.js";
5
6
 
6
7
  const pane = { width: 1600, height: 900 };
7
8
 
@@ -77,3 +78,224 @@ describe("kiosk shot: the messages", () => {
77
78
  expect(shotFromMessage({ origin: host, data: { type: "behold:shot", release: true } }, host)).toEqual({ type: "behold:shot", release: true });
78
79
  });
79
80
  });
81
+
82
+
83
+
84
+ // One framing on a small stage: three roots' cards in two wave boxes, at the kiosk's 1280 x 800, as web/app.js
85
+ // kioskShotBox frames it (heldTarget, heldInsets, heldFrame, the tab's session storage between frames). Nothing a
86
+ // step shows sits over the graph in Watch, so the graph has the stage's whole width less the margins.
87
+ describe("one framing on a small stage", () => {
88
+ const pane = { width: 1280, height: 720 };
89
+ const key = "demo-cone|components";
90
+ const boxes = [{ x: 0, y: 0, x2: 240, y2: 110 }, { x: 300, y: 0, x2: 620, y2: 110 }];
91
+ const cards = [{ x: 20, y: 30, x2: 220, y2: 95 }, { x: 320, y: 30, x2: 460, y2: 95 }, { x: 470, y: 30, x2: 600, y2: 95 }];
92
+ const whole = heldTarget(boxes, cards);
93
+ const STEPS = ["pull-request", "planned", "merged", "applying", "waiting", "approved", "applied", "reset"];
94
+ const demo = (cycle, step) => ({ cycle, scenario: "cone", step, label: "", started_at: "2026-10-17T10:00:00Z", pull: cycle, commit: step === "pull-request" || step === "planned" ? "2222222" : "3333333" });
95
+ /**
96
+ * What the kiosk's shot carries at each step (web/kiosk.js shotInsets): the caption under the stage, taller with
97
+ * the cone line at planned, the quiet line at the waves and the approval, the counts at applied, and event-help's
98
+ * trail over it as the cycle's beats come in. The right inset is a drawer the viewer opened on a wave at applying.
99
+ * The merge frame's pane is half a pixel off the plan frame's.
100
+ */
101
+ const shot = (step) => {
102
+ const trail = { "pull-request": 0, planned: 0, merged: 22, applying: 22, waiting: 44, approved: 44, applied: 44, reset: 0 }[step];
103
+ const lines = { planned: 22, applying: 20, waiting: 20, applied: 20 }[step] || 0;
104
+ const caption = 150 + lines + trail;
105
+ const right = step === "applying" ? Math.round(0.46 * 1280) + 44 : 0;
106
+ return { insets: { top: 20, right, bottom: caption + 16, left: 20 }, pane: step === "merged" || step === "applying" ? { width: 1280, height: 719.5 } : pane };
107
+ };
108
+
109
+ it("counts the stage small when the whole graph draws its cards readably, and a big graph not", () => {
110
+ expect(smallStage(whole, pane, heldInsets({ bottom: 192 }), 140)).toBe(true);
111
+ // 60 roots in a row: the whole graph is a strip of specks.
112
+ expect(smallStage({ x: 0, y: 0, x2: 60 * 220, y2: 500 }, pane, { bottom: 176 }, 180)).toBe(false);
113
+ expect(smallStage(whole, pane, {}, 0)).toBe(false);
114
+ expect(SMALL_STAGE_CARD_PX).toBe(90);
115
+ expect(medianWidth([180, 0, 175, 190])).toBe(180);
116
+ });
117
+
118
+ it("holds one viewBox through every step of three cycles, across the frames the kiosk swaps in", () => {
119
+ let stored = null;
120
+ const seen = [];
121
+ for (const cycle of [111, 112, 113]) {
122
+ for (const step of STEPS) {
123
+ expect(typeof shotFor(demo(cycle, step), {}).id).toBe("string");
124
+ const { insets, pane: p } = shot(step);
125
+ const held = stored ? JSON.parse(stored) : null;
126
+ // The kiosk measures the caption's tallest (kiosk-watch.js captionRoom) and sends it with every shot: 150 px, two extra rows, the trail at two lines, 16.
127
+ const ins = heldInsets(insets, 150 + 2 * 22 + 2 * 26 + 16);
128
+ expect(smallStage(whole, p, held ? held.insets : ins, 140)).toBe(true);
129
+ // A frame drawn from another checkout lays the boxes a few units off.
130
+ const target = step === "merged" ? { x: 2, y: 1, x2: 621, y2: 109 } : whole;
131
+ const next = heldFrame(held, { key, pane: p, insets: ins, target });
132
+ stored = JSON.stringify(next);
133
+ seen.push(next);
134
+ }
135
+ }
136
+ expect(seen).toHaveLength(24);
137
+ expect(seen.map((h) => h.reason)).toEqual(["first", ...Array(23).fill("held")]);
138
+ for (const h of seen) expect(sameViewBox(h.vb, seen[0].vb)).toBe(true);
139
+ const [x, y, w, h] = seen[0].vb;
140
+ const s = pane.width / w;
141
+ // Every box stays in view, clear of the tallest caption and of the run's caption at the top.
142
+ expect(x <= whole.x && x + w >= whole.x2).toBe(true);
143
+ expect(y + (20 + HELD_CAPTION_PX) / s <= whole.y + 36).toBe(true);
144
+ expect(y + h - (150 + 22 + 44 + 16) / s >= whole.y2).toBe(true);
145
+ });
146
+
147
+ it("would have moved at the merge with a step's own card at the right, the 48 px reserve and an exact pane", () => {
148
+ // Round 3's inputs: the shot's right inset growing at the waves, and the trail's growth past 48 px.
149
+ const a = heldFrame(null, { key, pane, insets: { top: 52, right: 450, bottom: 166 }, target: whole });
150
+ const b = heldFrame(a, { key, pane: { width: 1280, height: 719.5 }, insets: { top: 52, right: 454, bottom: 166 + 70 }, target: whole });
151
+ expect(b.reason).toBe("insets");
152
+ const ha = heldFrame(null, { key, pane, insets: heldInsets({ top: 20, bottom: 166, left: 20 }, 262), target: whole });
153
+ const hb = heldFrame(ha, { key, pane: { width: 1280, height: 719.5 }, insets: heldInsets({ top: 20, right: 454, bottom: 166 + 70, left: 20 }, 262), target: whole });
154
+ expect(hb.reason).toBe("held");
155
+ expect(sameViewBox(hb.vb, ha.vb)).toBe(true);
156
+ });
157
+
158
+ it("frames again for another repo or view, or a resized pane, and never for an overlay it kept room for", () => {
159
+ const a = heldFrame(null, { key, pane, insets: { bottom: 150 }, target: whole });
160
+ expect(heldFrame(a, { key, pane, insets: { bottom: 150 + HOLD_RESERVE_PX }, target: whole }).reason).toBe("held");
161
+ expect(heldFrame(a, { key: "demo-cone|resources", pane, insets: { bottom: 150 }, target: whole }).reason).toBe("key");
162
+ expect(heldFrame(a, { key, pane: { width: 1200, height: 720 }, insets: { bottom: 150 }, target: whole }).reason).toBe("pane");
163
+ expect(heldFrame(a, { key, pane, insets: { bottom: 150 }, target: { ...whole, x2: 2400 } }).reason).toBe("target");
164
+ });
165
+
166
+ it("keeps no card's room at the side: the right margin is the left's, whatever the shot says", () => {
167
+ expect(heldInsets({ top: 20, right: 600, bottom: 160, left: 20 })).toEqual({ top: 20 + HELD_CAPTION_PX, right: 20, bottom: 160, left: 20 });
168
+ expect(shotMessage({ whole: true })).not.toHaveProperty("dock");
169
+ expect(shotFromMessage({ origin: "https://k", data: { type: "behold:shot", whole: true, dock: 450 } }, "https://k")).not.toHaveProperty("dock");
170
+ });
171
+ });
172
+
173
+ // Round 5, cycles 111-112: the held framing used a third of the stage (two wave boxes about 220 x 100 px in
174
+ // 1280 x 800). Round 6: with nothing at the side, it fills the stage less the caption and the margins.
175
+ describe("a held small stage fills the stage", () => {
176
+ const pane = { width: 1280, height: 760 };
177
+ const ins = heldInsets({ top: 20, bottom: 192, left: 20 });
178
+ const boxes = [{ x: 0, y: 0, x2: 240, y2: 110 }, { x: 300, y: 0, x2: 620, y2: 110 }];
179
+ const cards = [{ x: 20, y: 30, x2: 220, y2: 95 }, { x: 320, y: 30, x2: 460, y2: 95 }, { x: 470, y: 30, x2: 600, y2: 95 }];
180
+ // A box round every box (a member's, the page's) and a mark far off the graph are not what it spans.
181
+ const outer = { x: -400, y: -200, x2: 1600, y2: 900 };
182
+
183
+ it("frames the innermost boxes that hold the cards, and the cards", () => {
184
+ expect(heldTarget([...boxes, outer], cards)).toEqual({ x: 0, y: 0, x2: 620, y2: 110 });
185
+ expect(heldTarget([{ x: 2000, y: 2000, x2: 2100, y2: 2100 }, ...boxes], cards)).toEqual({ x: 0, y: 0, x2: 620, y2: 110 });
186
+ expect(heldTarget(boxes, [])).toBeNull();
187
+ });
188
+
189
+ it("zooms in as far as the stage area allows, so the boxes fill its width", () => {
190
+ const target = heldTarget([...boxes, outer], cards);
191
+ const h = heldFrame(null, { key: "demo-cone|components", pane, insets: ins, target });
192
+ const s = pane.width / h.vb[2];
193
+ const openW = pane.width - ins.left - ins.right;
194
+ const openH = pane.height - ins.top - (ins.bottom + HOLD_RESERVE_PX);
195
+ expect(Math.max(((target.x2 - target.x + 72) * s) / openW, ((target.y2 - target.y + 72) * s) / openH)).toBeGreaterThan(0.98);
196
+ expect(s).toBeGreaterThan(1.7);
197
+ expect(s).toBeLessThanOrEqual(HELD_MAX_SCALE);
198
+ // apply-wave-2's box is about 2.5 times the 220 px it was.
199
+ expect((boxes[1].x2 - boxes[1].x) * s).toBeGreaterThan(550);
200
+ });
201
+
202
+ it("a framing kept from before, wider than the graph needs, frames again once to fill, then holds", () => {
203
+ const target = heldTarget(boxes, cards);
204
+ const wide = heldFrame(null, { key: "demo-cone|components", pane, insets: ins, target: { x: -180, y: -13, x2: 1222, y2: 826 } });
205
+ const filled = heldFrame(JSON.parse(JSON.stringify(wide)), { key: "demo-cone|components", pane, insets: ins, target });
206
+ expect(filled.reason).toBe("fill");
207
+ expect(filled.vb[2]).toBeLessThan(wide.vb[2] * HELD_FILL);
208
+ expect(heldFrame(filled, { key: "demo-cone|components", pane, insets: ins, target }).reason).toBe("held");
209
+ });
210
+ });
211
+
212
+ describe("which stage may be held", () => {
213
+ it("an estate whose every root runs on choudoufu; b-waves, failure and tg-planned-outputs (tofu) keep a shot per step", () => {
214
+ expect(holdsStage({ network: "choudoufu", "service-a": "choudoufu", "service-b": "choudoufu" })).toBe(true);
215
+ expect(holdsStage({ network: "tofu", app: "tofu", edge: "tofu" })).toBe(false);
216
+ expect(holdsStage({ network: "choudoufu", app: "tofu" })).toBe(false);
217
+ expect(holdsStage({})).toBe(false);
218
+ expect(holdsStage(null)).toBe(false);
219
+ });
220
+ });
221
+
222
+ // Cycle 122: the held viewBox was -339,-10,1325,793 in a 1270 px frame (0.96 px a unit), the wave boxes at about
223
+ // x 200..640 of the window and the right 45% of the stage empty: the target reached past the boxes. It is the boxes.
224
+ describe("the held frame fits the graph's boxes to the open stage", () => {
225
+ const pane = { width: 1270, height: 800 };
226
+ const ins = heldInsets({ top: 20, bottom: 224, left: 20 });
227
+ // network's box, and apply-wave-2's with service-a and service-b, as drawn at x -131..328 of the svg.
228
+ const boxes = [{ x: -131, y: 0, x2: 89, y2: 104 }, { x: 108, y: 0, x2: 328, y2: 104 }];
229
+ const cards = [{ x: -121, y: 30, x2: 79, y2: 90 }, { x: 118, y: 30, x2: 214, y2: 90 }, { x: 222, y: 30, x2: 318, y2: 90 }];
230
+ // What inflated it: a card no box holds, far to the right, and a card's hover ring wider than its box.
231
+ const stray = { x: 700, y: 380, x2: 780, y2: 420 };
232
+ const ring = { x: -160, y: 20, x2: 100, y2: 100 };
233
+
234
+ it("takes the boxes that hold the cards, and nothing in no box", () => {
235
+ expect(heldTarget(boxes, [...cards, stray, ring])).toEqual({ x: -131, y: 0, x2: 328, y2: 104 });
236
+ // No box at all: the cards are the graph.
237
+ expect(heldTarget([], cards)).toEqual({ x: -121, y: 30, x2: 318, y2: 90 });
238
+ });
239
+
240
+ it("scales the boxes up to the open stage's width, about 1230 px here, from 440", () => {
241
+ const target = heldTarget(boxes, [...cards, stray, ring]);
242
+ const h = heldFrame(null, { key: "demo-cone|components", pane, insets: ins, target });
243
+ const s = pane.width / h.vb[2];
244
+ const openW = pane.width - ins.left - ins.right;
245
+ // The boxes and their pad span the open width (the height has room to spare at this shape).
246
+ expect(((target.x2 - target.x + 72) * s) / openW).toBeGreaterThan(0.99);
247
+ expect((target.x2 - target.x) * s).toBeGreaterThan(1000);
248
+ expect(s).toBeGreaterThan(2);
249
+ // Centred: as much room left of the boxes as right of them.
250
+ const left = (target.x - h.vb[0]) * s;
251
+ const right = (h.vb[0] + h.vb[2] - target.x2) * s;
252
+ expect(Math.abs(left - right)).toBeLessThan(2);
253
+ });
254
+
255
+ it("a framing from the inflated target frames again once, then holds", () => {
256
+ const wide = heldFrame(null, { key: "demo-cone|components", pane, insets: ins, target: unionBox([...boxes, stray, ring]) });
257
+ const target = heldTarget(boxes, [...cards, stray, ring]);
258
+ const fit = heldFrame(JSON.parse(JSON.stringify(wide)), { key: "demo-cone|components", pane, insets: ins, target });
259
+ expect(fit.reason).toBe("fill");
260
+ expect(heldFrame(fit, { key: "demo-cone|components", pane, insets: ins, target }).reason).toBe("held");
261
+ });
262
+ });
263
+
264
+ // Cycle 122 at 80a8867e, from window.__kioskHeld(): pane 1270 x 760, insets {top 52, right 20, bottom 271, left 20},
265
+ // target 488 x 384 units (wave 2 stacked over wave 1), vb 1325 wide: 0.958 px a unit, the 36-unit pad included.
266
+ describe("the held scale is the open stage over the graph, nothing else", () => {
267
+ const pane = { width: 1270, height: 760 };
268
+ const key = "demo-choudoufu|components";
269
+ const stacked = { x: 80, y: 80, x2: 568, y2: 464 };
270
+
271
+ it("applies min(openW / targetW, openH / targetH): no pad, the same insets that judged it", () => {
272
+ const insets = { top: 52, right: 20, bottom: 271, left: 20 };
273
+ const h = heldFrame(null, { key, pane, insets: { ...insets, bottom: 271 - HOLD_RESERVE_PX }, target: stacked });
274
+ const s = pane.width / h.vb[2];
275
+ expect(h.insets.bottom).toBe(271);
276
+ expect(s).toBeCloseTo(Math.min((1270 - 40) / 488, (760 - 52 - 271) / 384, HELD_MAX_SCALE), 6);
277
+ expect(HELD_PAD).toBe(0);
278
+ });
279
+
280
+ it("the waves in a row, with the caption's measured tallest plus 24: about twice the scale", () => {
281
+ // captionRoom: a 150 px caption showing one 22 px row and no trail, at most two rows and a two-line trail.
282
+ const room = captionRoom({ capHeight: 150, extras: [22], rowH: 22, trailH: 0, trailLineH: 26, below: 5 });
283
+ expect(room).toBe(5 + 128 + 44 + 52 + 16);
284
+ const insets = heldInsets({ top: 20, bottom: 175, left: 20 }, room);
285
+ expect(insets.bottom).toBe(room);
286
+ // network | service-a, service-b: the same boxes side by side, 900 x 190 units.
287
+ const row = { x: 0, y: 0, x2: 900, y2: 190 };
288
+ const h = heldFrame(null, { key, pane, insets, target: row });
289
+ const s = pane.width / h.vb[2];
290
+ const was = pane.width / 1325.2;
291
+ expect(s).toBeCloseTo(Math.min((1270 - 40) / 900, (760 - 52 - (room + HOLD_RESERVE_PX)) / 190, HELD_MAX_SCALE), 6);
292
+ expect(s / was).toBeGreaterThan(1.4);
293
+ });
294
+
295
+ it("carries the room with the shot, only when there is some", () => {
296
+ expect(shotMessage({ whole: true, room: 245 }).room).toBe(245);
297
+ expect(shotMessage({ whole: true })).not.toHaveProperty("room");
298
+ expect(shotFromMessage({ origin: "https://k", data: { type: "behold:shot", whole: true, room: 245 } }, "https://k").room).toBe(245);
299
+ expect(heldInsets({ bottom: 300 }, 245).bottom).toBe(300);
300
+ });
301
+ });
@@ -0,0 +1,43 @@
1
+ // behold#752: where a kiosk page reads its demo. terragucci's loop (demo.json,
2
+ // cycles/<tool>/latest.json, runs/ copied from the forge) through
3
+ // /api/terragucci/…, or chant's fan-out demo's own records (demo-step/v1,
4
+ // demo-cycle/v1, runs built from chant's run events) through /api/chant/demo…
5
+ // (src/chant-demo.ts). The server says which in a meta tag
6
+ // (src/terragucci-demo.ts vendorPage); a page without it reads terragucci's,
7
+ // as every page did before.
8
+
9
+ /** The reads of terragucci's loop. `own: false`: the reports, run view, event stream and lane are read too. */
10
+ export const TERRAGUCCI_READS = {
11
+ source: null,
12
+ demo: "/api/terragucci/demo",
13
+ cycle: (tool) => `/api/terragucci/cycles/${encodeURIComponent(tool)}`,
14
+ runs: "/api/terragucci/runs",
15
+ run: (id) => `/api/terragucci/runs/${id}`,
16
+ own: false,
17
+ };
18
+
19
+ /**
20
+ * The reads of chant's fan-out demo. `own: true`: the demo is chant's alone, so
21
+ * terragucci's reports, run view, event stream and lane are never asked for.
22
+ * The cycle is the demo's one latest cycle, whatever tool the page names.
23
+ */
24
+ export const CHANT_DEMO_READS = {
25
+ source: "chant-demo",
26
+ demo: "/api/chant/demo",
27
+ cycle: () => "/api/chant/demo/cycle",
28
+ runs: "/api/chant/demo/runs",
29
+ run: (id) => `/api/chant/demo/runs/${id}`,
30
+ own: true,
31
+ };
32
+
33
+ /** The reads for a source name: chant's demo for `chant-demo`, terragucci's for anything else. */
34
+ export function readsFor(source) {
35
+ return source === "chant-demo" ? CHANT_DEMO_READS : TERRAGUCCI_READS;
36
+ }
37
+
38
+ /** The source the page was served for (`<meta name="kiosk-source">`), or null. */
39
+ export function pageSource(doc) {
40
+ const m = doc && doc.querySelector ? doc.querySelector('meta[name="kiosk-source"]') : null;
41
+ const s = m ? m.getAttribute("content") : null;
42
+ return s === "chant-demo" ? s : null;
43
+ }
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { CHANT_DEMO_READS, TERRAGUCCI_READS, pageSource, readsFor } from "./kiosk-source.js";
3
+ import { startMetrics } from "./kiosk-metrics.js";
4
+
5
+ // behold#752: a kiosk page reads terragucci's loop unless the server tells it chant's demo is its source.
6
+ const docWith = (content) => ({ querySelector: (q) => (q === 'meta[name="kiosk-source"]' && content !== null ? { getAttribute: () => content } : null) });
7
+
8
+ describe("where a kiosk page reads its demo (behold#752)", () => {
9
+ it("a page without the tag reads terragucci's loop, as every page did before", () => {
10
+ expect(pageSource(docWith(null))).toBeNull();
11
+ expect(readsFor(pageSource(docWith(null)))).toBe(TERRAGUCCI_READS);
12
+ expect(TERRAGUCCI_READS).toMatchObject({ demo: "/api/terragucci/demo", runs: "/api/terragucci/runs", own: false });
13
+ expect(TERRAGUCCI_READS.cycle("chant-fanout")).toBe("/api/terragucci/cycles/chant-fanout");
14
+ expect(TERRAGUCCI_READS.run(7)).toBe("/api/terragucci/runs/7");
15
+ });
16
+ it("a page told `chant-demo` reads chant's records, and nothing of terragucci's", () => {
17
+ const r = readsFor(pageSource(docWith("chant-demo")));
18
+ expect(r).toBe(CHANT_DEMO_READS);
19
+ expect([r.demo, r.cycle("chant-fanout"), r.runs, r.run(61002)]).toEqual(["/api/chant/demo", "/api/chant/demo/cycle", "/api/chant/demo/runs", "/api/chant/demo/runs/61002"]);
20
+ expect(r.own).toBe(true);
21
+ expect(JSON.stringify([r.demo, r.cycle("x"), r.runs, r.run(1)])).not.toMatch(/terragucci/);
22
+ });
23
+ it("an unknown source name is no source", () => {
24
+ expect(pageSource(docWith("elsewhere"))).toBeNull();
25
+ });
26
+ it("the metrics pane asks the page's own demo", async () => {
27
+ const host = { hidden: true, replaceChildren() {}, appendChild() {}, classList: { toggle() {} } };
28
+ const doc = { createElement: () => ({ classList: { toggle() {} }, dataset: {}, setAttribute() {}, addEventListener() {}, append() {}, appendChild() {} }), body: null, head: null, getElementById: () => null };
29
+ const asked = async (reads) => {
30
+ const urls = [];
31
+ const fetchJson = async (url) => (urls.push(url), { error: "none" });
32
+ const m = startMetrics(host, { tool: "chant-fanout", ...(reads ? { reads } : {}), fetchJson, store: { getItem: () => "closed", setItem() {} }, setTimer: () => 0, clearTimer() {}, doc });
33
+ await m.tick();
34
+ return urls;
35
+ };
36
+ expect(await asked(null)).toEqual(["/api/terragucci/demo", "/api/terragucci/cycles/chant-fanout"]);
37
+ expect(await asked(CHANT_DEMO_READS)).toEqual(["/api/chant/demo", "/api/chant/demo/cycle"]);
38
+ });
39
+ });
@@ -0,0 +1,44 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { storyGate, whatLine, whatParts, whatTool } from "./kiosk.js";
3
+
4
+ // behold#741: the #740 kiosk features (track, chapters, wedge, waiting modal,
5
+ // pacing, wave blocks, applied earlier, one tip at a time, the title line)
6
+ // are on for a chant repo's loop, or a terragucci repo whose demo.json step
7
+ // carries `chapter`. b-waves, failure and tg-planned-outputs carry none.
8
+ const step = (extra = {}) => ({ cycle: 3, scenario: "b-waves", step: "applying", pull: 12, ...extra });
9
+ const chapter = { n: 2, of: 4, headline: "cluster-a breaks" };
10
+
11
+ describe("the kiosk's story gate (behold#741)", () => {
12
+ it("is chant's for a chant repo's loop, whatever the step carries", () => {
13
+ expect(storyGate({ chantLoop: true, demo: step() })).toBe("chant");
14
+ expect(storyGate({ chantLoop: true, terragucciRepo: false, demo: null })).toBe("chant");
15
+ });
16
+ it("is terragucci's for a terragucci repo only when the step carries a chapter", () => {
17
+ expect(storyGate({ terragucciRepo: true, demo: step({ scenario: "fan-out", chapter }) })).toBe("terragucci");
18
+ for (const scenario of ["b-waves", "failure", "tg-planned-outputs"]) expect(storyGate({ terragucciRepo: true, demo: step({ scenario }) })).toBe(null);
19
+ expect(storyGate({ terragucciRepo: true, demo: step({ chapter: { headline: "no number" } }) })).toBe(null);
20
+ expect(storyGate({ terragucciRepo: true, demo: null })).toBe(null);
21
+ });
22
+ it("is off for a repo that is neither, chapter or not", () => {
23
+ expect(storyGate({ demo: step({ chapter }) })).toBe(null);
24
+ });
25
+ });
26
+
27
+ describe("a terragucci story's title line (behold#741)", () => {
28
+ it("names terragucci, its engine and its forge, with only the marks behold ships", () => {
29
+ expect(whatLine({ scenario: "fan-out" }, "forgejo", { tools: ["opentofu"] })).toBe("terragucci · OpenTofu · on Forgejo · fan-out · live demo");
30
+ const parts = whatParts({ scenario: "fan-out" }, "forgejo", { tools: ["opentofu"] });
31
+ // No terragucci mark ships: its name alone.
32
+ expect(parts[0].logo).toBeUndefined();
33
+ expect(parts[1].logo).toBe("opentofu");
34
+ expect(parts[2].logo).toBe("forgejo");
35
+ });
36
+ it("says Terraform by name alone, and no engine when none is declared", () => {
37
+ expect(whatTool(["terraform"])).toEqual({ id: "terraform", name: "Terraform" });
38
+ expect(whatTool([])).toBe(null);
39
+ expect(whatLine({ scenario: "fan-out" }, null, { tools: [] })).toBe("terragucci · fan-out · live demo");
40
+ });
41
+ it("leaves chant's line as it was", () => {
42
+ expect(whatLine({ scenario: "fan-out" }, "forgejo")).toBe("chant's pull-request pipeline · on Forgejo · fan-out · live demo");
43
+ });
44
+ });