@intentius/behold 0.29.18 → 0.29.20
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/AGENTS.md +15 -0
- package/dist/cli.js +615 -417
- package/package.json +1 -1
- package/web/kiosk-approval.js +4 -2
- package/web/kiosk-approval.test.js +2 -0
- package/web/kiosk-metrics.js +281 -0
- package/web/kiosk-metrics.test.js +94 -0
- package/web/kiosk-vendor.test.js +11 -5
- package/web/kiosk.html +115 -58
- package/web/kiosk.js +258 -73
- package/web/kiosk.test.js +105 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/behold",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.20",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "behold — a live control plane on chant. See your whole estate (every substrate in one graph), coloured by drift; act through delegated, gated Ops.",
|
package/web/kiosk-approval.js
CHANGED
|
@@ -86,7 +86,7 @@ function lineTime(run, f) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* The panel's model: `{ wave, digest, rows: [{ id, label, state, … }] }`, or
|
|
89
|
+
* The panel's model: `{ wave, digest, run, rows: [{ id, label, state, … }] }`, or
|
|
90
90
|
* null when the step is not one the panel shows or no wave of the cycle
|
|
91
91
|
* held. `state` is `lit`, `going` (begun, not done) or `dim`. Inputs:
|
|
92
92
|
*
|
|
@@ -178,7 +178,9 @@ export function approvalModel({ demo, runs = [], history = null, lifecycle = nul
|
|
|
178
178
|
});
|
|
179
179
|
} else Object.assign(spRow, { state: "dim", text: `Once wave ${wave} applies, this approval is used up for good.` });
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
// behold#571: the run the hold is in now, for the panel's head: the resume once there is one, else the run that held the wave.
|
|
182
|
+
const run = resume ? resume.id : holdRun ? holdRun.id : null;
|
|
183
|
+
return { wave, digest, run, rows: inferBack([reqRow, apRow, rsRow, spRow], { wave, gateRead, spentLine, resumeRuns }) };
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
/** The words a row lit only because a later one is, by row. Each says it was inferred; none invents a time. */
|
|
@@ -115,6 +115,8 @@ describe("the approval panel (behold#571)", () => {
|
|
|
115
115
|
const m = approvalModel({ demo: demo("applied"), runs: [run(444), resumeless], now: Date.parse("2026-10-15T04:11:00Z") });
|
|
116
116
|
expect(m.rows.map((r) => r.state)).toEqual(["lit", "lit", "lit", "lit"]);
|
|
117
117
|
expect(m.rows[2]).toMatchObject({ inferred: true, runId: 445, at: null });
|
|
118
|
+
// behold#571: the run the hold panel's head names: the run that held the wave, with no resume run copied.
|
|
119
|
+
expect(m.run).toBe(444);
|
|
118
120
|
expect(rowFacts(m.rows[2])).toEqual(["inferred from the rows after it", "run #445"]);
|
|
119
121
|
expect(m.rows[1]).toMatchObject({ inferred: true, text: "terragucci-admin approved this plan." });
|
|
120
122
|
expect(inferBack([{ id: "requested", state: "dim" }, { id: "approved", state: "dim" }], { wave: 2 }).map((r) => r.state)).toEqual(["dim", "dim"]);
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// behold#571: the kiosk's "Pipeline metrics" pane. The repo's numbers from
|
|
2
|
+
// Prometheus (/api/metrics, src/prometheus-metrics.ts): this run's waves, each
|
|
3
|
+
// with its roots' plan and apply time, the time an approval held it at its
|
|
4
|
+
// gate and what it applied, and the estate's four delivery (DORA) metrics.
|
|
5
|
+
//
|
|
6
|
+
// It shows what Prometheus returned and nothing else: with no Prometheus, or
|
|
7
|
+
// no number for the repo, there is no pane at all. A viewer can fold it to
|
|
8
|
+
// its header, which keeps a count; the fold is kept per viewer.
|
|
9
|
+
//
|
|
10
|
+
// The pane reads on its own: demo.json for the repo and commit the kiosk is
|
|
11
|
+
// on (on a tool's page, that tool's repo), then the metrics. All GET.
|
|
12
|
+
|
|
13
|
+
/** The localStorage key of the viewer's fold. */
|
|
14
|
+
export const METRICS_STORE = "behold.kiosk.metrics";
|
|
15
|
+
|
|
16
|
+
/** How often the pane asks again. The route shares one read for 30 s. */
|
|
17
|
+
export const METRICS_POLL_MS = 15_000;
|
|
18
|
+
|
|
19
|
+
const ACTION_WORDS = { create: "created", update: "updated", delete: "deleted", replace: "replaced", forget: "forgotten", import: "imported", move: "moved" };
|
|
20
|
+
|
|
21
|
+
/** "6.4 s", "48 s", "2 min 5 s", "1 h 20 min", "3 d 4 h". */
|
|
22
|
+
export function secondsWords(secs) {
|
|
23
|
+
if (typeof secs !== "number" || !Number.isFinite(secs) || secs < 0) return null;
|
|
24
|
+
if (secs < 10) return `${Math.round(secs * 10) / 10} s`;
|
|
25
|
+
if (secs < 60) return `${Math.round(secs)} s`;
|
|
26
|
+
const m = Math.floor(secs / 60);
|
|
27
|
+
if (m < 60) {
|
|
28
|
+
const s = Math.round(secs - m * 60);
|
|
29
|
+
return s ? `${m} min ${s} s` : `${m} min`;
|
|
30
|
+
}
|
|
31
|
+
const h = Math.floor(m / 60);
|
|
32
|
+
if (h < 24) return m % 60 ? `${h} h ${m % 60} min` : `${h} h`;
|
|
33
|
+
const d = Math.floor(h / 24);
|
|
34
|
+
return h % 24 ? `${d} d ${h % 24} h` : `${d} d`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** "10%", "8.3%". */
|
|
38
|
+
export function percentWords(ratio) {
|
|
39
|
+
if (typeof ratio !== "number" || !Number.isFinite(ratio)) return null;
|
|
40
|
+
const p = ratio * 100;
|
|
41
|
+
return `${Math.round(p * 10) / 10}%`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** "4.5 a week". */
|
|
45
|
+
export function perWeekWords(n) {
|
|
46
|
+
if (typeof n !== "number" || !Number.isFinite(n)) return null;
|
|
47
|
+
return `${Math.round(n * 10) / 10} a week`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** "2 created, 1 updated", in the order terragucci's actions read; null for none. */
|
|
51
|
+
export function changeWords(changes) {
|
|
52
|
+
const parts = Object.entries(changes || {})
|
|
53
|
+
.filter(([, n]) => typeof n === "number" && n > 0)
|
|
54
|
+
.sort((a, b) => Object.keys(ACTION_WORDS).indexOf(a[0]) - Object.keys(ACTION_WORDS).indexOf(b[0]))
|
|
55
|
+
.map(([a, n]) => `${n} ${ACTION_WORDS[a] || a}`);
|
|
56
|
+
return parts.length ? parts.join(", ") : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** "14:05", the viewer's clock, from Unix seconds. */
|
|
60
|
+
export function clockWords(unix) {
|
|
61
|
+
if (typeof unix !== "number" || !Number.isFinite(unix)) return null;
|
|
62
|
+
const d = new Date(unix * 1000);
|
|
63
|
+
return `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* What the pane shows, from one /api/metrics answer, or null for no pane:
|
|
68
|
+
* `{ count, run: { label, waves: [{ head, rows: [[label, value, root?]] }] } | null, dora: [[label, value]] | null }`.
|
|
69
|
+
*/
|
|
70
|
+
export function metricsModel(answer) {
|
|
71
|
+
if (!answer || answer.error) return null;
|
|
72
|
+
let run = null;
|
|
73
|
+
if (answer.run && Array.isArray(answer.run.waves)) {
|
|
74
|
+
const waves = [];
|
|
75
|
+
for (const w of answer.run.waves) {
|
|
76
|
+
const rows = [];
|
|
77
|
+
for (const r of w.roots || []) {
|
|
78
|
+
const plan = secondsWords(r.plan_seconds);
|
|
79
|
+
const apply = secondsWords(r.apply_seconds);
|
|
80
|
+
const parts = [plan && `plan ${plan}`, apply && `apply ${apply}`].filter(Boolean);
|
|
81
|
+
if (parts.length) rows.push([r.root, parts.join(" · "), r.root]);
|
|
82
|
+
}
|
|
83
|
+
const held = secondsWords(w.held_seconds);
|
|
84
|
+
if (held) rows.push(["Held at the gate", held]);
|
|
85
|
+
const since = clockWords(w.waiting_since);
|
|
86
|
+
if (since) rows.push(["Waiting since", since]);
|
|
87
|
+
const changed = changeWords(w.changes);
|
|
88
|
+
if (changed) rows.push(["Applied", changed]);
|
|
89
|
+
if (rows.length) waves.push({ wave: w.wave, head: `Wave ${w.wave}`, rows });
|
|
90
|
+
}
|
|
91
|
+
if (waves.length) {
|
|
92
|
+
const c = answer.run.commit ? ` · ${String(answer.run.commit).slice(0, 8)}` : "";
|
|
93
|
+
run = { label: `${answer.run.current ? "This run" : "Latest run"}${c}`, waves };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let dora = null;
|
|
97
|
+
if (answer.dora) {
|
|
98
|
+
const d = answer.dora;
|
|
99
|
+
const rows = [
|
|
100
|
+
["Deploys", perWeekWords(d.deployments_per_week)],
|
|
101
|
+
["Lead time", secondsWords(d.lead_time_seconds)],
|
|
102
|
+
["Change failure rate", percentWords(d.change_failure_ratio)],
|
|
103
|
+
["Time to restore", secondsWords(d.restore_seconds)],
|
|
104
|
+
].filter(([, v]) => v);
|
|
105
|
+
if (rows.length) dora = rows;
|
|
106
|
+
}
|
|
107
|
+
if (!run && !dora) return null;
|
|
108
|
+
const n = run ? run.waves.length : 0;
|
|
109
|
+
const count = [n ? `${n} ${n === 1 ? "wave" : "waves"}` : null, dora ? `${dora.length} delivery` : null].filter(Boolean).join(" · ");
|
|
110
|
+
return { count, run, dora };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The viewer's fold: true open, false folded, null when they never chose. */
|
|
114
|
+
export function metricsStored(store) {
|
|
115
|
+
try {
|
|
116
|
+
const v = store && store.getItem(METRICS_STORE);
|
|
117
|
+
return v === "open" ? true : v === "closed" ? false : null;
|
|
118
|
+
} catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The repo and commit the pane is about: the narration's, or on a tool's page while another tool runs, that tool's newest cycle's repo. */
|
|
124
|
+
export function metricsTarget(demo, cycle, tool) {
|
|
125
|
+
const d = demo && demo.demo;
|
|
126
|
+
if (d && d.repo && (!tool || d.tool === tool)) return { repo: d.repo, commit: d.commit || null };
|
|
127
|
+
if (tool && cycle && cycle.cycle && cycle.cycle.repo) return { repo: cycle.cycle.repo, commit: null };
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The URL the pane asks. */
|
|
132
|
+
export function metricsUrl(target) {
|
|
133
|
+
const q = new URLSearchParams({ project: target.repo });
|
|
134
|
+
if (target.commit && /^[0-9a-f]{7,64}$/.test(target.commit)) q.set("commit", target.commit);
|
|
135
|
+
return `/api/metrics?${q}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const STYLE = `
|
|
139
|
+
#k-metrics { background: var(--surface-pane-b); border-radius: 6px; overflow-y: auto; min-height: 0; font-size: 0.9em; }
|
|
140
|
+
#k-metrics[hidden] { display: none; }
|
|
141
|
+
body.k-has-metrics #stage { grid-template-rows: minmax(0, 1fr) auto; }
|
|
142
|
+
body.k-has-metrics #runs-side { grid-row: 1; grid-column: 1; }
|
|
143
|
+
body.k-has-metrics #runs-main, body.k-has-metrics #view-pane { grid-row: 1 / span 2; }
|
|
144
|
+
body.k-has-metrics #k-metrics { grid-row: 2; grid-column: 1; max-height: 46vh; }
|
|
145
|
+
body.k-has-metrics.k-notyet #view-pane { grid-row: 1; }
|
|
146
|
+
.k-metrics-head { display: flex; width: 100%; gap: 0.6em; align-items: baseline; padding: 0.55em 1em; background: transparent; border: 0; color: var(--muted); cursor: pointer; text-align: left; font: 600 0.82em var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; }
|
|
147
|
+
.k-metrics-head:hover { color: var(--fg); }
|
|
148
|
+
.k-metrics-head::after { content: " \\25B8"; margin-left: auto; }
|
|
149
|
+
.k-metrics-open .k-metrics-head::after { content: " \\25BE"; }
|
|
150
|
+
.k-metrics-count { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted-ink, var(--muted)); }
|
|
151
|
+
.k-metrics-body { padding: 0 1em 0.7em; }
|
|
152
|
+
.k-metrics-label { margin: 0.35em 0 0.2em; font: 600 0.72em var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
|
|
153
|
+
.k-metrics-waves { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35em; }
|
|
154
|
+
.k-metrics-wave { background: var(--surface-box); border-radius: 6px; padding: 0.3em 0.6em 0.35em; }
|
|
155
|
+
.k-metrics-wave-head { font: 700 0.85em var(--font-mono); color: var(--fg); }
|
|
156
|
+
.k-metrics-rows { display: grid; grid-template-columns: minmax(0, 9.5em) minmax(0, 1fr); gap: 0.05em 0.7em; margin: 0.1em 0 0; }
|
|
157
|
+
.k-metrics-rows dt.k-metrics-root, .k-metrics-rows dt.k-metrics-root + dd { grid-column: 1 / -1; }
|
|
158
|
+
.k-metrics-rows dt.k-metrics-root + dd { padding-left: 0.8em; }
|
|
159
|
+
.k-metrics-rows dt { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
160
|
+
.k-metrics-rows dt.k-metrics-root { font-family: var(--font-mono); color: var(--fg); }
|
|
161
|
+
.k-metrics-rows dd { margin: 0; color: var(--fg); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
162
|
+
.k-metrics-dora { background: var(--surface-box); border-radius: 6px; padding: 0.3em 0.6em 0.35em; }
|
|
163
|
+
@media (max-width: 900px) and (min-width: 601px) { body.k-has-metrics #runs-main, body.k-has-metrics #view-pane { grid-row: auto; } body.k-has-metrics #k-metrics { grid-row: auto; grid-column: auto; } body.k-has-metrics #stage { grid-template-rows: none; } }
|
|
164
|
+
@media (max-width: 600px) { #k-metrics, body.k-has-metrics #k-metrics { order: 2; margin: 0.6em 16px 0; max-height: none; } }
|
|
165
|
+
`;
|
|
166
|
+
|
|
167
|
+
const el = (doc, tag, cls, text) => {
|
|
168
|
+
const n = doc.createElement(tag);
|
|
169
|
+
if (cls) n.className = cls;
|
|
170
|
+
if (text !== undefined && text !== null) n.textContent = text;
|
|
171
|
+
return n;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
function rowsEl(doc, rows, cls = "k-metrics-rows") {
|
|
175
|
+
const dl = el(doc, "dl", cls);
|
|
176
|
+
for (const [label, value, root] of rows) {
|
|
177
|
+
const dt = el(doc, "dt", root ? "k-metrics-root" : null, label);
|
|
178
|
+
if (root) dt.dataset.kRoot = root;
|
|
179
|
+
dt.title = label;
|
|
180
|
+
dl.append(dt, el(doc, "dd", null, value));
|
|
181
|
+
}
|
|
182
|
+
return dl;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Draw the pane from its model; null hides it. */
|
|
186
|
+
export function renderMetrics(host, model, { open = true, onToggle = () => {}, doc = document } = {}) {
|
|
187
|
+
host.replaceChildren();
|
|
188
|
+
host.hidden = !model;
|
|
189
|
+
if (doc.body && doc.body.classList) doc.body.classList.toggle("k-has-metrics", !!model);
|
|
190
|
+
if (!model) return;
|
|
191
|
+
host.classList.toggle("k-metrics-open", open);
|
|
192
|
+
const head = el(doc, "button", "k-metrics-head");
|
|
193
|
+
head.type = "button";
|
|
194
|
+
head.setAttribute("aria-expanded", String(open));
|
|
195
|
+
head.append(el(doc, "span", null, "Pipeline metrics"), el(doc, "span", "k-metrics-count", model.count));
|
|
196
|
+
head.addEventListener("click", () => onToggle(!open));
|
|
197
|
+
host.appendChild(head);
|
|
198
|
+
if (!open) return;
|
|
199
|
+
const body = el(doc, "div", "k-metrics-body");
|
|
200
|
+
if (model.run) {
|
|
201
|
+
body.appendChild(el(doc, "h3", "k-metrics-label", model.run.label));
|
|
202
|
+
const list = el(doc, "ol", "k-metrics-waves");
|
|
203
|
+
for (const w of model.run.waves) {
|
|
204
|
+
const li = el(doc, "li", "k-metrics-wave");
|
|
205
|
+
li.dataset.kWave = String(w.wave);
|
|
206
|
+
li.append(el(doc, "div", "k-metrics-wave-head", w.head), rowsEl(doc, w.rows));
|
|
207
|
+
list.appendChild(li);
|
|
208
|
+
}
|
|
209
|
+
body.appendChild(list);
|
|
210
|
+
}
|
|
211
|
+
if (model.dora) {
|
|
212
|
+
body.appendChild(el(doc, "h3", "k-metrics-label", "Delivery (DORA)"));
|
|
213
|
+
const box = el(doc, "div", "k-metrics-dora");
|
|
214
|
+
box.appendChild(rowsEl(doc, model.dora));
|
|
215
|
+
body.appendChild(box);
|
|
216
|
+
}
|
|
217
|
+
host.appendChild(body);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function defaultFetch(url) {
|
|
221
|
+
try {
|
|
222
|
+
const r = await fetch(url, { headers: { accept: "application/json" } });
|
|
223
|
+
if (!r.ok) return { error: `${url} answered ${r.status}` };
|
|
224
|
+
return await r.json();
|
|
225
|
+
} catch (e) {
|
|
226
|
+
return { error: String(e) };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Start the pane in `host`. `tool` is the tool of a tool's page, null on
|
|
232
|
+
* /kiosk. Returns `{ stop }`.
|
|
233
|
+
*/
|
|
234
|
+
export function startMetrics(host, { tool = null, fetchJson = defaultFetch, store = null, setTimer = setInterval, clearTimer = clearInterval, doc = document } = {}) {
|
|
235
|
+
if (!host) return { stop() {} };
|
|
236
|
+
if (doc.head && !doc.getElementById("k-metrics-style")) {
|
|
237
|
+
const style = el(doc, "style");
|
|
238
|
+
style.id = "k-metrics-style";
|
|
239
|
+
style.textContent = STYLE;
|
|
240
|
+
doc.head.appendChild(style);
|
|
241
|
+
}
|
|
242
|
+
const shelf = store || (() => { try { return localStorage; } catch { return null; } })();
|
|
243
|
+
let open = metricsStored(shelf);
|
|
244
|
+
if (open === null) open = !(typeof matchMedia === "function" && matchMedia("(max-width: 600px)").matches);
|
|
245
|
+
let model = null;
|
|
246
|
+
let busy = false;
|
|
247
|
+
const draw = () =>
|
|
248
|
+
renderMetrics(host, model, {
|
|
249
|
+
open,
|
|
250
|
+
doc,
|
|
251
|
+
onToggle: (next) => {
|
|
252
|
+
open = next;
|
|
253
|
+
try {
|
|
254
|
+
if (shelf) shelf.setItem(METRICS_STORE, next ? "open" : "closed");
|
|
255
|
+
} catch {
|
|
256
|
+
/* private mode: the fold lasts this visit */
|
|
257
|
+
}
|
|
258
|
+
draw();
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
const tick = async () => {
|
|
262
|
+
if (busy) return;
|
|
263
|
+
busy = true;
|
|
264
|
+
try {
|
|
265
|
+
const demo = await fetchJson("/api/terragucci/demo");
|
|
266
|
+
const cycle = tool && !(demo && demo.demo && demo.demo.tool === tool) ? await fetchJson(`/api/terragucci/cycles/${tool}`) : null;
|
|
267
|
+
const target = metricsTarget(demo, cycle, tool);
|
|
268
|
+
const next = target ? metricsModel(await fetchJson(metricsUrl(target))) : null;
|
|
269
|
+
if (JSON.stringify(next) !== JSON.stringify(model)) {
|
|
270
|
+
model = next;
|
|
271
|
+
draw();
|
|
272
|
+
}
|
|
273
|
+
} finally {
|
|
274
|
+
busy = false;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
draw();
|
|
278
|
+
void tick();
|
|
279
|
+
const timer = setTimer(() => void tick(), METRICS_POLL_MS);
|
|
280
|
+
return { stop: () => clearTimer(timer), tick };
|
|
281
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// behold#571: the kiosk's "Pipeline metrics" pane, as words. No DOM: the
|
|
2
|
+
// model decides what shows, and an answer with nothing in it shows no pane.
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { changeWords, METRICS_STORE, metricsModel, metricsStored, metricsTarget, metricsUrl, percentWords, perWeekWords, secondsWords } from "./kiosk-metrics.js";
|
|
5
|
+
|
|
6
|
+
const C1 = "9f3c2a71d04e5b8c6a1f2e3d4c5b6a7980716253";
|
|
7
|
+
const answer = () => ({
|
|
8
|
+
read: "2026-10-16T00:00:00Z",
|
|
9
|
+
repo: "terragucci-admin/demo",
|
|
10
|
+
project: "forgejo:3000/terragucci-admin/demo",
|
|
11
|
+
run: {
|
|
12
|
+
commit: C1,
|
|
13
|
+
current: true,
|
|
14
|
+
waves: [
|
|
15
|
+
{ wave: 1, run: "4101", roots: [{ root: "network", plan_seconds: 6.4, apply_seconds: 2.1 }], changes: { update: 1 }, settled_at: 1000 },
|
|
16
|
+
{ wave: 2, run: "4102", roots: [{ root: "app", plan_seconds: 7.2, apply_seconds: 3.4 }], held_seconds: 95, changes: { update: 1, create: 2 }, settled_at: 1200 },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
dora: { from: "prometheus", deployments_per_week: 30, lead_time_seconds: 900, change_failure_ratio: 0.1 },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("kiosk metrics: the words", () => {
|
|
23
|
+
it("reads seconds with their unit, short", () => {
|
|
24
|
+
expect([6.44, 48.4, 125, 120, 4800, 3600, 97200].map(secondsWords)).toEqual(["6.4 s", "48 s", "2 min 5 s", "2 min", "1 h 20 min", "1 h", "1 d 3 h"]);
|
|
25
|
+
expect(secondsWords(undefined)).toBeNull();
|
|
26
|
+
expect(secondsWords(-1)).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("reads a ratio as a percent, a rate per week, and changes by action in terragucci's order", () => {
|
|
30
|
+
expect([percentWords(0.1), percentWords(0.0833), percentWords(0)]).toEqual(["10%", "8.3%", "0%"]);
|
|
31
|
+
expect(perWeekWords(4.54)).toBe("4.5 a week");
|
|
32
|
+
expect(changeWords({ update: 1, create: 2, delete: 0 })).toBe("2 created, 1 updated");
|
|
33
|
+
expect(changeWords({})).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("kiosk metrics: what the pane shows", () => {
|
|
38
|
+
it("each wave's roots with their plan and apply time, the gate's hold, what it applied, and the delivery metrics", () => {
|
|
39
|
+
const m = metricsModel(answer());
|
|
40
|
+
expect(m.count).toBe("2 waves · 3 delivery");
|
|
41
|
+
expect(m.run.label).toBe("This run · 9f3c2a71");
|
|
42
|
+
expect(m.run.waves).toEqual([
|
|
43
|
+
{ wave: 1, head: "Wave 1", rows: [["network", "plan 6.4 s · apply 2.1 s", "network"], ["Applied", "1 updated"]] },
|
|
44
|
+
{ wave: 2, head: "Wave 2", rows: [["app", "plan 7.2 s · apply 3.4 s", "app"], ["Held at the gate", "1 min 35 s"], ["Applied", "2 created, 1 updated"]] },
|
|
45
|
+
]);
|
|
46
|
+
expect(m.dora).toEqual([["Deploys", "30 a week"], ["Lead time", "15 min"], ["Change failure rate", "10%"]]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("names a run that is not the kiosk's commit as the latest, and a run with no commit by none", () => {
|
|
50
|
+
const a = answer();
|
|
51
|
+
a.run.current = false;
|
|
52
|
+
expect(metricsModel(a).run.label).toBe("Latest run · 9f3c2a71");
|
|
53
|
+
a.run.commit = null;
|
|
54
|
+
expect(metricsModel(a).run.label).toBe("Latest run");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("a waiting wave says since when, by the viewer's clock", () => {
|
|
58
|
+
const a = answer();
|
|
59
|
+
a.run.waves = [{ wave: 2, run: "4101", roots: [{ root: "app", plan_seconds: 7.9 }], changes: {}, waiting_since: Date.parse("2026-10-16T14:05:00") / 1000 }];
|
|
60
|
+
expect(metricsModel(a).run.waves[0].rows).toEqual([["app", "plan 7.9 s", "app"], ["Waiting since", "14:05"]]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("shows no pane for no answer, a refusal, or nothing for the repo; a part with no number is left out", () => {
|
|
64
|
+
expect(metricsModel(null)).toBeNull();
|
|
65
|
+
expect(metricsModel({ error: "behold reads no Prometheus" })).toBeNull();
|
|
66
|
+
expect(metricsModel({ repo: "x/y", project: null, run: null, dora: null })).toBeNull();
|
|
67
|
+
expect(metricsModel({ run: { commit: C1, current: true, waves: [{ wave: 1, roots: [], changes: {} }] }, dora: null })).toBeNull();
|
|
68
|
+
const onlyDora = metricsModel({ run: null, dora: { from: "dora.json", restore_seconds: 600 } });
|
|
69
|
+
expect(onlyDora).toEqual({ count: "1 delivery", run: null, dora: [["Time to restore", "10 min"]] });
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("kiosk metrics: which repo, and the fold", () => {
|
|
74
|
+
it("follows the narration's repo and commit; on a tool's page while another tool runs, that tool's newest cycle's repo", () => {
|
|
75
|
+
const demo = { demo: { repo: "terragucci-admin/demo", commit: C1, tool: "terraform" } };
|
|
76
|
+
expect(metricsTarget(demo, null, null)).toEqual({ repo: "terragucci-admin/demo", commit: C1 });
|
|
77
|
+
expect(metricsTarget(demo, null, "terraform")).toEqual({ repo: "terragucci-admin/demo", commit: C1 });
|
|
78
|
+
expect(metricsTarget(demo, { cycle: { repo: "terragucci-admin/demo-terragrunt" } }, "terragrunt")).toEqual({ repo: "terragucci-admin/demo-terragrunt", commit: null });
|
|
79
|
+
expect(metricsTarget({ demo: null }, null, null)).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("asks for the repo by project, and the commit only when it is a commit", () => {
|
|
83
|
+
expect(metricsUrl({ repo: "terragucci-admin/demo", commit: C1 })).toBe(`/api/metrics?project=terragucci-admin%2Fdemo&commit=${C1}`);
|
|
84
|
+
expect(metricsUrl({ repo: "terragucci-admin/demo", commit: "main" })).toBe("/api/metrics?project=terragucci-admin%2Fdemo");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("keeps the viewer's fold, and has none when they never chose or storage refuses", () => {
|
|
88
|
+
const shelf = (v) => ({ getItem: (k) => (k === METRICS_STORE ? v : null) });
|
|
89
|
+
expect(metricsStored(shelf("open"))).toBe(true);
|
|
90
|
+
expect(metricsStored(shelf("closed"))).toBe(false);
|
|
91
|
+
expect(metricsStored(shelf(null))).toBeNull();
|
|
92
|
+
expect(metricsStored({ getItem: () => { throw new Error("denied"); } })).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
});
|
package/web/kiosk-vendor.test.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { VENDOR_TOOLS } from "../src/terragucci-demo.ts";
|
|
4
4
|
import { logRows } from "./kiosk-runs.js";
|
|
5
|
-
import { NO_GRAPH_WORDS, SCENARIOS,
|
|
5
|
+
import { NO_GRAPH_WORDS, SCENARIOS, readingRows, scenarioHead } from "./kiosk.js";
|
|
6
6
|
import {
|
|
7
7
|
REPLAY_LAST_HOLD_MS,
|
|
8
8
|
RUNS_WITH,
|
|
@@ -145,7 +145,7 @@ describe("the branding table (behold#571)", () => {
|
|
|
145
145
|
it("says on each page who makes the tool and that they don't endorse the demo, naming no other tool or maker", () => {
|
|
146
146
|
for (const tool of VENDOR_TOOLS) {
|
|
147
147
|
const v = VENDORS[tool];
|
|
148
|
-
const words = [v.name, ...creditLines(tool).map((l) => l.map((s) => s.text).join("")), ...Object.values(notRunWords(v)),
|
|
148
|
+
const words = [v.name, ...creditLines(tool).map((l) => l.map((s) => s.text).join("")), ...Object.values(notRunWords(v)), ...readingRows("components", tool).map((r) => r.words), ...readingRows("resources", tool).map((r) => r.words)];
|
|
149
149
|
for (const w of words) expect(namesOther(w, tool), `${tool}: ${w}`).toBe(false);
|
|
150
150
|
// choudoufu and chant are ours: their credits say so instead.
|
|
151
151
|
if (tool !== "choudoufu" && tool !== "chant") expect(v.credit).toMatch(/(does not|don't) endorse this demo\./);
|
|
@@ -153,7 +153,7 @@ describe("the branding table (behold#571)", () => {
|
|
|
153
153
|
expect(VENDORS.choudoufu.credit).toMatch(/AWS and Kubernetes/);
|
|
154
154
|
expect(VENDORS.choudoufu.credit).not.toMatch(/experimental/i);
|
|
155
155
|
});
|
|
156
|
-
it("links each name in the
|
|
156
|
+
it("links each name in the credit, the tool's to its site and OpenTofu's where its scenarios run on it", () => {
|
|
157
157
|
const tf = creditLines("terraform");
|
|
158
158
|
expect(tf.flat().filter((s) => s.url).map((s) => [s.text, s.url])).toEqual([
|
|
159
159
|
["Terraform", VENDORS.terraform.url],
|
|
@@ -228,7 +228,7 @@ describe("a tool's page, drawn (behold#571)", () => {
|
|
|
228
228
|
};
|
|
229
229
|
const text = (n) => (n.children && n.children.length ? n.children.map(text).join("") : n.textContent || "");
|
|
230
230
|
const all = (n) => [n, ...(n.children || []).flatMap(all)];
|
|
231
|
-
it("puts the tool's name before the scenario, the banner over it, and the credit
|
|
231
|
+
it("puts the tool's name before the scenario, the banner over it, and the credit at the lead block's foot, with no count", async () => {
|
|
232
232
|
const { renderKiosk } = await import("./kiosk.js");
|
|
233
233
|
const was = globalThis.document;
|
|
234
234
|
globalThis.document = fakeDocument();
|
|
@@ -253,7 +253,11 @@ describe("a tool's page, drawn (behold#571)", () => {
|
|
|
253
253
|
expect(text(bar2)).toContain("Big Terraform setups");
|
|
254
254
|
// No graph of this repo here: one line in the header says so.
|
|
255
255
|
expect(all(bar).filter((n) => n.className === "k-nograph-note").map(text)).toEqual([NO_GRAPH_WORDS]);
|
|
256
|
-
|
|
256
|
+
// behold#571: no footer: the credit is the lead block's last line.
|
|
257
|
+
const lead = all(bar).find((n) => n.className === "k-left k-lead");
|
|
258
|
+
expect(lead.children[lead.children.length - 1].className).toBe("k-credits");
|
|
259
|
+
expect(all(bar).filter((n) => n.className === "k-credit").map(text)).toEqual([VENDORS.terragrunt.credit]);
|
|
260
|
+
expect(foot.children).toEqual([]);
|
|
257
261
|
} finally {
|
|
258
262
|
globalThis.document = was;
|
|
259
263
|
}
|
|
@@ -283,6 +287,8 @@ describe("a tool's page, drawn (behold#571)", () => {
|
|
|
283
287
|
expect(text(bar)).toContain("This scenario hasn't run yet");
|
|
284
288
|
const brand = all(bar).find((n) => n.className === "k-brand");
|
|
285
289
|
expect(brand.href).toBe(VENDORS.choudoufu.url);
|
|
290
|
+
// The credit shows on every tool page, before its first cycle too.
|
|
291
|
+
expect(all(bar).filter((n) => n.className === "k-credit").map(text)).toEqual([VENDORS.choudoufu.credit]);
|
|
286
292
|
expect(all(brand).some((n) => n.className === "k-brand-logo" && n.src === VENDORS.choudoufu.logo.src)).toBe(true);
|
|
287
293
|
} finally {
|
|
288
294
|
globalThis.document = was;
|