@intentius/behold 0.29.29 → 0.29.31
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.
- package/dist/cli.js +8 -3
- package/package.json +1 -1
- package/web/app.js +261 -4
- package/web/index.html +42 -2
- package/web/kiosk-approval.js +1 -1
- package/web/kiosk-metrics.js +36 -7
- package/web/kiosk-metrics.test.js +52 -3
- package/web/kiosk-runs.js +12 -6
- package/web/kiosk-runs.test.js +11 -1
- package/web/kiosk-shot.js +103 -0
- package/web/kiosk-shot.test.js +79 -0
- package/web/kiosk-trace.js +29 -5
- package/web/kiosk-trace.test.js +29 -1
- package/web/kiosk-vendor.test.js +5 -3
- package/web/kiosk-watch.js +263 -0
- package/web/kiosk-watch.test.js +181 -0
- package/web/kiosk.html +227 -50
- package/web/kiosk.js +565 -71
- package/web/kiosk.test.js +31 -20
- package/web/operator.js +3 -0
- package/web/run-playhead.js +4 -0
- package/web/theme.js +49 -0
- package/web/theme.test.js +56 -1
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// behold#571: the kiosk's Watch mode, its default. The Components graph is
|
|
2
|
+
// the stage, and the rest rides on it: the narration is a caption along the
|
|
3
|
+
// bottom, the approval a callout on the held wave's box, the running job's
|
|
4
|
+
// log a drawer from the active wave's box, the pipeline metrics a badge on
|
|
5
|
+
// each wave's box, and the delivery numbers one line in the header. With
|
|
6
|
+
// each step the kiosk moves the graph to what the step is about (a "shot":
|
|
7
|
+
// web/kiosk-shot.js does the camera). Inspect is the dense layout, one click
|
|
8
|
+
// away, and a viewer's choice of the two is kept in their browser.
|
|
9
|
+
//
|
|
10
|
+
// This module decides what each piece says and where it goes. It reads only
|
|
11
|
+
// what the kiosk already holds (demo.json, the reports, the run view, the
|
|
12
|
+
// runs, the metrics model); web/kiosk.js draws it.
|
|
13
|
+
|
|
14
|
+
import { STEP_WORDS, focusRoots, matchingPull, matchingRun, scenarioHead, introText, aboutRows, nextWords, demoStage } from "./kiosk.js";
|
|
15
|
+
import { defaultJob, defaultStep, logLineWords, setupLine } from "./kiosk-runs.js";
|
|
16
|
+
|
|
17
|
+
/** The two modes, Watch first: it is the default. */
|
|
18
|
+
export const MODES = [
|
|
19
|
+
{ id: "watch", words: "Watch", shows: "the graph, moved to each step as it happens" },
|
|
20
|
+
{ id: "inspect", words: "Inspect", shows: "the runs and their logs beside the graph" },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/** Where a viewer's mode is kept, in their own browser. */
|
|
24
|
+
export const MODE_STORE = "behold.kiosk.mode";
|
|
25
|
+
|
|
26
|
+
/** The viewer's mode: "watch" unless they picked Inspect. */
|
|
27
|
+
export function modeStored(store) {
|
|
28
|
+
try {
|
|
29
|
+
return store && store.getItem(MODE_STORE) === "inspect" ? "inspect" : "watch";
|
|
30
|
+
} catch {
|
|
31
|
+
return "watch";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The tone a step's chip takes, by the same colours the strip and the wave boxes use. */
|
|
36
|
+
export function stepTone(step) {
|
|
37
|
+
if (step === "waiting") return "wait";
|
|
38
|
+
if (step === "failed" || step === "stalled") return "bad";
|
|
39
|
+
if (step === "applied") return "ok";
|
|
40
|
+
if (step === "reset") return "idle";
|
|
41
|
+
return "busy";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The wave the run is on: from the run view, the wave applying, else failed
|
|
46
|
+
* or refused, else the first that has not applied. Before the run view has
|
|
47
|
+
* this cycle's run, the wave whose job is running, waiting or failed in the
|
|
48
|
+
* pipeline's run (`runDoc`, its jobs named as `waves` names them). Null when
|
|
49
|
+
* neither says.
|
|
50
|
+
*/
|
|
51
|
+
export function activeWave(demo, progress, { runDoc = null, waves = [] } = {}) {
|
|
52
|
+
const run = demo ? matchingRun(progress, demo) : null;
|
|
53
|
+
if (run) {
|
|
54
|
+
const states = progress.states || [];
|
|
55
|
+
for (const want of ["applying", "failed", "refused"]) {
|
|
56
|
+
const w = states.find((x) => x.state === want);
|
|
57
|
+
if (w) return w.number;
|
|
58
|
+
}
|
|
59
|
+
const next = states.find((x) => x.state !== "applied" && x.state !== "skipped");
|
|
60
|
+
if (next) return next.number;
|
|
61
|
+
}
|
|
62
|
+
const jobs = runDoc && Array.isArray(runDoc.jobs) ? runDoc.jobs : [];
|
|
63
|
+
for (const status of ["running", "waiting", "failure"]) {
|
|
64
|
+
const job = jobs.find((j) => j.status === status && waves.some((w) => w.job === j.name));
|
|
65
|
+
if (job) return waves.find((w) => w.job === job.name).wave;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The roots a pull request's shot frames: the roots it changes, and each
|
|
72
|
+
* root a read joins to them, so the reads' lines are in the picture.
|
|
73
|
+
*/
|
|
74
|
+
export function changeRoots(demo, answer, progress) {
|
|
75
|
+
const roots = focusRoots(demo, answer, progress) || [];
|
|
76
|
+
const pr = matchingPull(answer, demo);
|
|
77
|
+
const reads = pr && Array.isArray(pr.reads) ? pr.reads : [];
|
|
78
|
+
const out = new Set(roots);
|
|
79
|
+
for (const r of reads) if (out.has(r.root) || out.has(r.upstream)) [r.root, r.upstream].filter(Boolean).forEach((x) => out.add(x));
|
|
80
|
+
return [...out];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The shot for a step: what the graph frames and which overlay leads.
|
|
85
|
+
* `{ id, kind, roots, waves, whole }`, `kind` one of:
|
|
86
|
+
*
|
|
87
|
+
* - "change" (pull request, planned): the changing roots and the reads;
|
|
88
|
+
* - "held" (waiting, approved): the held wave, with the approval callout; the whole graph for a gate on the whole change (`gate`);
|
|
89
|
+
* - "active" (applying, running again, failed): the wave the run is on, its log drawer open;
|
|
90
|
+
* - "result" (applied): the whole graph, its badges and the result card;
|
|
91
|
+
* - "intro" (reset, the base): the whole graph, with the demo's intro;
|
|
92
|
+
* - "whole": the whole graph (merged, stalled, and a step with nothing to frame yet).
|
|
93
|
+
*
|
|
94
|
+
* `id` changes only when the frame should move.
|
|
95
|
+
*/
|
|
96
|
+
export function shotFor(demo, { answer = null, progress = null, held = null, gate = false, runDoc = null, waves = [] } = {}) {
|
|
97
|
+
if (!demo) return { id: "none", kind: "whole", roots: [], waves: [], whole: true };
|
|
98
|
+
const base = `${demo.cycle}|${demo.step}`;
|
|
99
|
+
const whole = (kind) => ({ id: `${base}|${kind}`, kind, roots: [], waves: [], whole: true });
|
|
100
|
+
if (demo.step === "reset" || demoStage(demo) === "none") return whole("intro");
|
|
101
|
+
if (demo.step === "applied") return whole("result");
|
|
102
|
+
if (demo.step === "pull-request" || demo.step === "planned") {
|
|
103
|
+
const roots = changeRoots(demo, answer, progress);
|
|
104
|
+
return roots.length ? { id: `${base}|change|${roots.join(",")}`, kind: "change", roots, waves: [], whole: false } : whole("change");
|
|
105
|
+
}
|
|
106
|
+
if ((demo.step === "waiting" || demo.step === "approved") && Number.isInteger(held)) return { id: `${base}|held|${held}`, kind: "held", roots: [], waves: [held], whole: false };
|
|
107
|
+
// A gate on the whole change (chant's pull-request gate, one approval for every wave): the whole graph, with the callout.
|
|
108
|
+
if ((demo.step === "waiting" || demo.step === "approved") && gate) return { id: `${base}|held|all`, kind: "held", roots: [], waves: [], whole: true };
|
|
109
|
+
if (["applying", "resumed", "failed", "waiting", "approved"].includes(demo.step)) {
|
|
110
|
+
const n = activeWave(demo, progress, { runDoc, waves });
|
|
111
|
+
if (Number.isInteger(n)) return { id: `${base}|active|${n}`, kind: "active", roots: [], waves: [n], whole: false };
|
|
112
|
+
}
|
|
113
|
+
return whole("whole");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The caption along the bottom: the scenario's title, what changes, and the
|
|
118
|
+
* step. `lead` says which line leads: "changes" before the merge, when the
|
|
119
|
+
* change is what to read, else "step". Between scenarios, the intro.
|
|
120
|
+
*/
|
|
121
|
+
export function captionModel(demo, { vendor = null, now = new Date() } = {}) {
|
|
122
|
+
if (!demo) return null;
|
|
123
|
+
const head = scenarioHead(demo, { vendor });
|
|
124
|
+
const rows = aboutRows(demo);
|
|
125
|
+
const changes = rows.find((r) => r.label === "What changes") || null;
|
|
126
|
+
const intro = demo.step === "reset" ? introText(demo) : null;
|
|
127
|
+
const nx = nextWords(demo, now);
|
|
128
|
+
return {
|
|
129
|
+
kicker: head.kicker,
|
|
130
|
+
title: head.title || "",
|
|
131
|
+
lead: demo.step === "pull-request" || demo.step === "planned" ? "changes" : "step",
|
|
132
|
+
changes: intro ? null : changes ? { label: changes.label, text: changes.text } : null,
|
|
133
|
+
intro: intro ? { label: "What this demo is about", text: intro } : null,
|
|
134
|
+
step: { word: STEP_WORDS[demo.step] || demo.step, text: demo.label || "", tone: stepTone(demo.step), id: demo.step },
|
|
135
|
+
next: nx.action ? { action: nx.action, when: nx.when } : null,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** "1.6 s · held 25 s · 4 created": one wave's numbers from the metrics model's wave, or null when it has none. */
|
|
140
|
+
export function badgeWords(wave) {
|
|
141
|
+
if (!wave) return null;
|
|
142
|
+
const parts = [wave.seconds, wave.held ? `held ${wave.held}` : null, wave.changed].filter(Boolean);
|
|
143
|
+
return parts.length ? parts.join(" · ") : null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The badge's words with what they are, for the callout's and the drawer's heads and a badge's tooltip. */
|
|
147
|
+
export function badgeTitle(words) {
|
|
148
|
+
return words ? `Pipeline metrics · ${words}` : null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Each wave's badge, by wave number, from the metrics model; only for this cycle's run, never an older one. */
|
|
152
|
+
export function badges(metrics) {
|
|
153
|
+
const run = metrics && metrics.run;
|
|
154
|
+
if (!run || !run.current) return {};
|
|
155
|
+
const out = {};
|
|
156
|
+
for (const w of run.waves) {
|
|
157
|
+
const words = badgeWords(w);
|
|
158
|
+
if (words) out[w.wave] = words;
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** "19,489 deploys a week · lead time 1 min 56 s · change failure rate 1% · time to restore 1 min 12 s", or null. */
|
|
164
|
+
export function doraLine(metrics) {
|
|
165
|
+
const rows = metrics && metrics.dora;
|
|
166
|
+
if (!rows || !rows.length) return null;
|
|
167
|
+
const say = {
|
|
168
|
+
Deploys: (v) => `${roundedWeek(v)} deploys a week`,
|
|
169
|
+
"Lead time": (v) => `lead time ${v}`,
|
|
170
|
+
"Change failure rate": (v) => `change failure rate ${v}`,
|
|
171
|
+
"Time to restore": (v) => `time to restore ${v}`,
|
|
172
|
+
};
|
|
173
|
+
return rows.map(([label, v]) => (say[label] ? say[label](v) : `${label.toLowerCase()} ${v}`)).join(" · ");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** "19488.7 a week" as "19,489"; a small rate keeps its tenth ("4.5"). */
|
|
177
|
+
function roundedWeek(v) {
|
|
178
|
+
const n = Number(String(v).replace(/ a week$/, ""));
|
|
179
|
+
if (!Number.isFinite(n)) return String(v).replace(/ a week$/, "");
|
|
180
|
+
return n >= 100 ? Math.round(n).toLocaleString("en-US") : String(Math.round(n * 10) / 10);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The result card, the applied shot's focal point: the result line (the
|
|
185
|
+
* step's own words), the counts (the waves that applied and what they
|
|
186
|
+
* changed, from the run view the graph draws; the job time and the hold, from
|
|
187
|
+
* the metrics when they cover every wave), and each wave's numbers as its
|
|
188
|
+
* badge has them. Null without this cycle's run.
|
|
189
|
+
*/
|
|
190
|
+
export function resultModel(demo, metrics, progress = null) {
|
|
191
|
+
if (!demo || demo.step !== "applied") return null;
|
|
192
|
+
const run = matchingRun(progress, demo);
|
|
193
|
+
const states = run ? (progress.states || []).filter((w) => w.state === "applied") : [];
|
|
194
|
+
const m = metrics && metrics.run && metrics.run.current ? metrics.run.waves : [];
|
|
195
|
+
const n = states.length || m.length;
|
|
196
|
+
if (!n) return null;
|
|
197
|
+
const counts = [`${n} ${n === 1 ? "wave" : "waves"} applied`];
|
|
198
|
+
const changed = states.length ? mergeChanges(states.map((w) => w.totals)) : mergeChanges(m.map((w) => w.changesRaw));
|
|
199
|
+
counts.push(changed || "nothing to change");
|
|
200
|
+
// The metrics cover the run when they have a number for each wave that applied.
|
|
201
|
+
if (m.length >= n) {
|
|
202
|
+
const secs = m.reduce((a, w) => a + (Number.isFinite(w.secondsRaw) ? w.secondsRaw : 0), 0);
|
|
203
|
+
if (secs > 0) counts.push(`${secondsShort(secs)} of job time`);
|
|
204
|
+
const held = m.reduce((a, w) => a + (Number.isFinite(w.heldRaw) ? w.heldRaw : 0), 0);
|
|
205
|
+
if (held > 0) counts.push(`${secondsShort(held)} held for an approval`);
|
|
206
|
+
}
|
|
207
|
+
const waves = [...m].sort((a, b) => a.wave - b.wave).map((w) => ({ wave: w.wave, words: badgeWords(w) })).filter((w) => w.words);
|
|
208
|
+
return { head: "Applied", line: typeof demo.label === "string" ? demo.label : "", counts, waves };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const ACTION_ORDER = ["create", "update", "delete", "replace", "forget", "import", "move"];
|
|
212
|
+
const ACTION_WORDS = { create: "created", update: "updated", delete: "deleted", replace: "replaced", forget: "forgotten", import: "imported", move: "moved" };
|
|
213
|
+
function mergeChanges(list) {
|
|
214
|
+
const sum = {};
|
|
215
|
+
for (const c of list) for (const [a, n] of Object.entries(c || {})) if (a in ACTION_WORDS && typeof n === "number" && n > 0) sum[a] = (sum[a] || 0) + n;
|
|
216
|
+
const parts = ACTION_ORDER.filter((a) => sum[a]).map((a) => `${sum[a]} ${ACTION_WORDS[a]}`);
|
|
217
|
+
return parts.length ? parts.join(", ") : null;
|
|
218
|
+
}
|
|
219
|
+
function secondsShort(secs) {
|
|
220
|
+
if (secs < 10) return `${Math.round(secs * 10) / 10} s`;
|
|
221
|
+
if (secs < 60) return `${Math.round(secs)} s`;
|
|
222
|
+
const m = Math.floor(secs / 60);
|
|
223
|
+
const s = Math.round(secs - m * 60);
|
|
224
|
+
return s ? `${m} min ${s} s` : `${m} min`;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The drawer's folded lines: the job the run is on and the last lines its
|
|
229
|
+
* step wrote, as the jobs pane would show them. `{ job, step, status, lines }`
|
|
230
|
+
* or null without a run read.
|
|
231
|
+
*/
|
|
232
|
+
export function tailLines(runDoc, n = 2) {
|
|
233
|
+
if (!runDoc || !Array.isArray(runDoc.jobs) || !runDoc.jobs.length) return null;
|
|
234
|
+
const job = defaultJob(runDoc.jobs);
|
|
235
|
+
if (!job) return null;
|
|
236
|
+
const steps = job.steps || [];
|
|
237
|
+
const i = defaultStep(steps);
|
|
238
|
+
const step = i >= 0 ? steps[i] : null;
|
|
239
|
+
// Node's own warnings (a deprecation, and its hint) are the runtime's, not the job's.
|
|
240
|
+
const runtime = (l) => /^\s*\((node:\d+|Use `node )/.test(l);
|
|
241
|
+
const said = (step && Array.isArray(step.log) ? step.log : []).filter((l) => typeof l === "string" && l.trim() && !setupLine(l) && !runtime(l));
|
|
242
|
+
const lines = said.slice(-n).map((l) => logLineWords(job.status, l).text);
|
|
243
|
+
return { job: job.name, step: step ? step.name : null, status: job.status, lines };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Where an overlay of `size` goes beside `box` inside `view` (all pixels,
|
|
248
|
+
* `{x, y, w, h}`): to the right of the box when it fits, else to its left,
|
|
249
|
+
* else under it; its top level with the box's, kept inside the view. On the
|
|
250
|
+
* right it moves past any of `avoid` (the reads' labels) it would cover.
|
|
251
|
+
* `{ x, y, side }`, `side` "right", "left" or "below".
|
|
252
|
+
*/
|
|
253
|
+
export function placeBeside(box, size, view, gap = 18, avoid = []) {
|
|
254
|
+
const top = Math.max(view.y + 8, Math.min(box.y, view.y + view.h - size.h - 8));
|
|
255
|
+
// Clear of the graph's own labels beside the box: past the right edge of any it would cover.
|
|
256
|
+
const over = (x) => avoid.filter((a) => a.x < x + size.w && a.x + a.w > x && a.y < top + size.h && a.y + a.h > top);
|
|
257
|
+
let right = box.x + box.w + gap;
|
|
258
|
+
for (let i = 0; i < 4 && over(right).length; i++) right = Math.max(...over(right).map((a) => a.x + a.w)) + gap / 2;
|
|
259
|
+
if (right + size.w <= view.x + view.w - 8) return { x: right, y: top, side: "right" };
|
|
260
|
+
if (box.x - gap - size.w >= view.x + 8) return { x: box.x - gap - size.w, y: top, side: "left" };
|
|
261
|
+
const x = Math.max(view.x + 8, Math.min(box.x, view.x + view.w - size.w - 8));
|
|
262
|
+
return { x, y: Math.min(box.y + box.h + gap, view.y + view.h - size.h - 8), side: "below" };
|
|
263
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// behold#571: Watch mode, as words and places. No DOM: which shot each step
|
|
2
|
+
// takes, what the caption leads with, the badges, the delivery line, the
|
|
3
|
+
// result card, the drawer's folded lines, and where an overlay goes.
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { MODE_STORE, activeWave, badgeTitle, badgeWords, badges, captionModel, changeRoots, doraLine, modeStored, placeBeside, resultModel, shotFor, stepTone, tailLines } from "./kiosk-watch.js";
|
|
6
|
+
|
|
7
|
+
const C = "9f3c2a71d04e5b8c6a1f2e3d4c5b6a7980716253";
|
|
8
|
+
const P = "1111111111111111111111111111111111111111";
|
|
9
|
+
const demo = (step, more = {}) => ({
|
|
10
|
+
cycle: 12,
|
|
11
|
+
scenario: "a-known",
|
|
12
|
+
title: "A new subnet, approved once its id exists",
|
|
13
|
+
index: 1,
|
|
14
|
+
scenarios: 4,
|
|
15
|
+
step,
|
|
16
|
+
label: `the ${step} line`,
|
|
17
|
+
started_at: "2026-10-16T10:00:00Z",
|
|
18
|
+
next: { action: "approve wave-2", at: "2026-10-16T10:02:00Z" },
|
|
19
|
+
pull: 7,
|
|
20
|
+
commit: step === "pull-request" || step === "planned" ? P : C,
|
|
21
|
+
about: { changes: "A pull request adds a subnet to network.", watch: "Wave 1 builds it.", shows: "Values made during the apply." },
|
|
22
|
+
intro: "Big Terraform setups split what they build across many states.",
|
|
23
|
+
...more,
|
|
24
|
+
});
|
|
25
|
+
const answer = {
|
|
26
|
+
roots: [{ path: "network" }, { path: "app" }, { path: "edge" }, { path: "other" }],
|
|
27
|
+
pull_request: {
|
|
28
|
+
run: { pull_request: 7, commit: P },
|
|
29
|
+
roots: ["network", "app"],
|
|
30
|
+
reads: [{ root: "app", upstream: "network", outputs: "planned", unknown: ["subnet_id"] }, { root: "edge", upstream: "app", outputs: "applied", unknown: [] }],
|
|
31
|
+
waves: [],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const progress = (states) => ({ run: { present: true, commit: C, updated: "2026-10-16T10:01:00Z" }, states, reads: [] });
|
|
35
|
+
const st = (number, state, roots, totals = {}) => ({ number, state, roots, changed: roots, totals });
|
|
36
|
+
|
|
37
|
+
describe("kiosk watch: the mode", () => {
|
|
38
|
+
it("is Watch until a viewer picks Inspect, and Watch when storage refuses", () => {
|
|
39
|
+
const shelf = (v) => ({ getItem: (k) => (k === MODE_STORE ? v : null) });
|
|
40
|
+
expect(modeStored(shelf(null))).toBe("watch");
|
|
41
|
+
expect(modeStored(shelf("inspect"))).toBe("inspect");
|
|
42
|
+
expect(modeStored(shelf("watch"))).toBe("watch");
|
|
43
|
+
expect(modeStored({ getItem: () => { throw new Error("denied"); } })).toBe("watch");
|
|
44
|
+
expect(modeStored(null)).toBe("watch");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("kiosk watch: the shot each step takes", () => {
|
|
49
|
+
it("frames the pull request's changing roots and the roots their reads join, before the merge", () => {
|
|
50
|
+
const shot = shotFor(demo("planned"), { answer });
|
|
51
|
+
expect(shot.kind).toBe("change");
|
|
52
|
+
expect(shot.roots.sort()).toEqual(["app", "edge", "network"]);
|
|
53
|
+
expect(changeRoots(demo("pull-request"), answer, null).sort()).toEqual(["app", "edge", "network"]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("frames the held wave while it waits, the active wave while it applies, and the whole graph at the end", () => {
|
|
57
|
+
const p = progress([st(1, "applied", ["network"]), st(2, "waiting", ["app"]), st(3, "not-started", ["edge"])]);
|
|
58
|
+
expect(shotFor(demo("waiting"), { progress: p, held: 2 })).toMatchObject({ kind: "held", waves: [2], whole: false });
|
|
59
|
+
const applying = progress([st(1, "applying", ["network"]), st(2, "not-started", ["app"])]);
|
|
60
|
+
expect(shotFor(demo("applying"), { progress: applying })).toMatchObject({ kind: "active", waves: [1] });
|
|
61
|
+
expect(shotFor(demo("failed"), { progress: progress([st(1, "applied", ["network"]), st(2, "failed", ["app"])]) })).toMatchObject({ kind: "active", waves: [2] });
|
|
62
|
+
expect(shotFor(demo("applied"), { progress: p })).toMatchObject({ kind: "result", whole: true });
|
|
63
|
+
expect(shotFor(demo("reset"))).toMatchObject({ kind: "intro", whole: true });
|
|
64
|
+
expect(shotFor(demo("merged"), { progress: p })).toMatchObject({ kind: "whole", whole: true });
|
|
65
|
+
// One gate for the whole change (chant's pull-request loop): the whole graph, the callout beside it.
|
|
66
|
+
expect(shotFor(demo("waiting"), { gate: true })).toMatchObject({ kind: "held", waves: [], whole: true });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("keeps its id while the step and what it frames stay, so the frame moves only when they change", () => {
|
|
70
|
+
const p = progress([st(1, "applying", ["network"])]);
|
|
71
|
+
expect(shotFor(demo("applying"), { progress: p }).id).toBe(shotFor(demo("applying"), { progress: p }).id);
|
|
72
|
+
expect(shotFor(demo("applying"), { progress: p }).id).not.toBe(shotFor(demo("applying"), { progress: progress([st(1, "applied", ["network"]), st(2, "applying", ["app"])]) }).id);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("before the run view has the cycle's run, finds the active wave by the pipeline's running job", () => {
|
|
76
|
+
const runDoc = { jobs: [{ name: "check", status: "success" }, { name: "apply-wave-1", status: "success" }, { name: "apply-wave-2", status: "running" }] };
|
|
77
|
+
const waves = [{ job: "apply-wave-1", wave: 1 }, { job: "apply-wave-2", wave: 2 }];
|
|
78
|
+
expect(activeWave(demo("applying"), null, { runDoc, waves })).toBe(2);
|
|
79
|
+
expect(shotFor(demo("applying"), { runDoc, waves })).toMatchObject({ kind: "active", waves: [2] });
|
|
80
|
+
expect(activeWave(demo("applying"), null, {})).toBeNull();
|
|
81
|
+
expect(shotFor(demo("applying"))).toMatchObject({ kind: "whole" });
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("kiosk watch: the caption", () => {
|
|
86
|
+
it("leads with what changes before the merge, and with the step after it", () => {
|
|
87
|
+
const now = new Date("2026-10-16T10:01:30Z");
|
|
88
|
+
const pr = captionModel(demo("pull-request"), { now });
|
|
89
|
+
expect(pr).toMatchObject({ kicker: "Scenario 1 of 4", title: "A new subnet, approved once its id exists", lead: "changes", changes: { label: "What changes", text: "A pull request adds a subnet to network." } });
|
|
90
|
+
expect(pr.step).toMatchObject({ word: "pull request open", text: "the pull-request line", tone: "busy" });
|
|
91
|
+
expect(pr.next).toEqual({ action: "approve wave-2", when: "in 30 s" });
|
|
92
|
+
expect(captionModel(demo("waiting"), { now })).toMatchObject({ lead: "step", step: { word: "waiting for an approval", tone: "wait" } });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("gives the intro in place of what changes between scenarios", () => {
|
|
96
|
+
const c = captionModel(demo("reset"));
|
|
97
|
+
expect(c.changes).toBeNull();
|
|
98
|
+
expect(c.intro).toEqual({ label: "What this demo is about", text: "Big Terraform setups split what they build across many states." });
|
|
99
|
+
expect(captionModel(null)).toBeNull();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("tones each step as the strip and the boxes do", () => {
|
|
103
|
+
expect(["waiting", "failed", "stalled", "applied", "reset", "applying"].map(stepTone)).toEqual(["wait", "bad", "bad", "ok", "idle", "busy"]);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("kiosk watch: the numbers", () => {
|
|
108
|
+
const metrics = {
|
|
109
|
+
run: {
|
|
110
|
+
current: true,
|
|
111
|
+
waves: [
|
|
112
|
+
{ wave: 1, seconds: "1.6 s", held: null, changed: "1 updated", secondsRaw: 1.6, heldRaw: null, changesRaw: { update: 1 } },
|
|
113
|
+
{ wave: 2, seconds: "9.5 s", held: "25 s", changed: "4 created", secondsRaw: 9.5, heldRaw: 25, changesRaw: { create: 4 } },
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
dora: [["Deploys", "19488.7 a week"], ["Lead time", "1 min 56 s"], ["Change failure rate", "1%"], ["Time to restore", "1 min 12 s"]],
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
it("puts each wave's time, hold and changes on its badge, and none from an older run", () => {
|
|
120
|
+
expect(badges(metrics)).toEqual({ 1: "1.6 s · 1 updated", 2: "9.5 s · held 25 s · 4 created" });
|
|
121
|
+
expect(badges({ ...metrics, run: { ...metrics.run, current: false } })).toEqual({});
|
|
122
|
+
expect(badges(null)).toEqual({});
|
|
123
|
+
expect(badgeWords({ seconds: null, held: null, changed: null })).toBeNull();
|
|
124
|
+
expect(badgeTitle("1.6 s")).toBe("Pipeline metrics · 1.6 s");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("says the delivery numbers on one line, a large rate rounded", () => {
|
|
128
|
+
expect(doraLine(metrics)).toBe("19,489 deploys a week · lead time 1 min 56 s · change failure rate 1% · time to restore 1 min 12 s");
|
|
129
|
+
expect(doraLine({ dora: [["Deploys", "4.5 a week"]] })).toBe("4.5 deploys a week");
|
|
130
|
+
expect(doraLine({ dora: null })).toBeNull();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("sums the run on the result card: the step's line, the waves and changes from the run view, the time and the hold from the metrics, each wave's numbers", () => {
|
|
134
|
+
const p = progress([st(1, "applied", ["network"], { update: 1, "no-op": 2 }), st(2, "applied", ["app"], { create: 4 })]);
|
|
135
|
+
expect(resultModel(demo("applied"), metrics, p)).toEqual({
|
|
136
|
+
head: "Applied",
|
|
137
|
+
line: "the applied line",
|
|
138
|
+
counts: ["2 waves applied", "4 created, 1 updated", "11 s of job time", "25 s held for an approval"],
|
|
139
|
+
waves: [{ wave: 1, words: "1.6 s · 1 updated" }, { wave: 2, words: "9.5 s · held 25 s · 4 created" }],
|
|
140
|
+
});
|
|
141
|
+
// Metrics that cover fewer waves than applied say nothing of the time.
|
|
142
|
+
const three = progress([...p.states, st(3, "applied", ["edge"], {})]);
|
|
143
|
+
expect(resultModel(demo("applied"), metrics, three).counts).toEqual(["3 waves applied", "4 created, 1 updated"]);
|
|
144
|
+
expect(resultModel(demo("applying"), metrics, p)).toBeNull();
|
|
145
|
+
expect(resultModel(demo("applied"), null, null)).toBeNull();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("kiosk watch: the drawer's folded lines", () => {
|
|
150
|
+
it("shows the running job and the last lines its running step wrote, set-up lines and node's warnings left out", () => {
|
|
151
|
+
const runDoc = {
|
|
152
|
+
jobs: [
|
|
153
|
+
{ name: "check", status: "success", steps: [{ name: "Set up job", status: "success", log: ["x"] }] },
|
|
154
|
+
{
|
|
155
|
+
name: "apply-wave-2",
|
|
156
|
+
status: "running",
|
|
157
|
+
steps: [
|
|
158
|
+
{ name: "Set up job", status: "success", log: ["runner"] },
|
|
159
|
+
{ name: "Apply wave 2 of 3", status: "running", log: ["wave 2 of 3: planning app", "", "app: Plan: 4 to add", "(node:41) [DEP0040] DeprecationWarning: The `punycode` module is deprecated.", "wave 2 of 3: apply", "(Use `node --trace-deprecation ...` to show where the warning was created)"] },
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
};
|
|
164
|
+
expect(tailLines(runDoc)).toEqual({ job: "apply-wave-2", step: "Apply wave 2 of 3", status: "running", lines: ["app: Plan: 4 to add", "wave 2 of 3: apply"] });
|
|
165
|
+
expect(tailLines(null)).toBeNull();
|
|
166
|
+
expect(tailLines({ jobs: [] })).toBeNull();
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe("kiosk watch: where an overlay goes", () => {
|
|
171
|
+
const view = { x: 0, y: 0, w: 1600, h: 800 };
|
|
172
|
+
it("goes right of its box when it fits, else left, else below; level with the box's top and inside the view", () => {
|
|
173
|
+
expect(placeBeside({ x: 400, y: 200, w: 300, h: 200 }, { w: 400, h: 300 }, view)).toEqual({ x: 718, y: 200, side: "right" });
|
|
174
|
+
expect(placeBeside({ x: 1000, y: 200, w: 400, h: 200 }, { w: 400, h: 300 }, view)).toEqual({ x: 582, y: 200, side: "left" });
|
|
175
|
+
expect(placeBeside({ x: 100, y: 100, w: 1400, h: 200 }, { w: 400, h: 300 }, view)).toMatchObject({ side: "below", y: 318 });
|
|
176
|
+
// A label of the graph's beside the box: the overlay moves past it.
|
|
177
|
+
expect(placeBeside({ x: 400, y: 200, w: 300, h: 200 }, { w: 400, h: 300 }, view, 18, [{ x: 600, y: 450, w: 200, h: 24 }])).toEqual({ x: 809, y: 200, side: "right" });
|
|
178
|
+
// A box low in the view: the overlay rises to stay in it.
|
|
179
|
+
expect(placeBeside({ x: 400, y: 700, w: 300, h: 80 }, { w: 400, h: 300 }, view).y).toBe(492);
|
|
180
|
+
});
|
|
181
|
+
});
|