@intentius/behold 0.29.33 → 0.29.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/behold",
3
- "version": "0.29.33",
3
+ "version": "0.29.34",
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.",
@@ -279,7 +279,7 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
279
279
  const drawTrail = (h) => {
280
280
  if (!trailHost) return;
281
281
  const facts = [...st.trail.values()].sort((a, b) => a.order - b.order);
282
- const key = facts.map((f) => f.id).join(",");
282
+ const key = facts.map((f) => `${f.id}=${f.text}`).join(",");
283
283
  trailHost.hidden = !facts.length;
284
284
  if (h.watch && h.caption && trailHost.style) {
285
285
  const c = h.caption.getBoundingClientRect();
@@ -347,7 +347,15 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
347
347
  const tick = () => {
348
348
  const h = get();
349
349
  if (!h || !h.demo) return;
350
- const facts = cycleFacts(ehSnapshot({ demo: h.demo, answer: h.answer, progress: h.progress, runDoc: h.runDoc, runDocs: h.runDocs || [], approval: h.approval, metrics: h.metrics, waveTraces: h.waveTraces || {}, waves: h.waves || [], failed: [...st.failed] }));
350
+ // behold#571 (#631): the story is told in the tool's own step order; until that is read, nothing is said in another's.
351
+ if (h.stripReady === false) return;
352
+ const stripKey = JSON.stringify((h.strip || []).map((x) => x.id));
353
+ if (stripKey !== st.stripKey) {
354
+ // Another tool's order: the trail is told again in it.
355
+ st.stripKey = stripKey;
356
+ st.trail.clear();
357
+ }
358
+ const facts = cycleFacts(ehSnapshot({ demo: h.demo, answer: h.answer, progress: h.progress, runDoc: h.runDoc, runDocs: h.runDocs || [], approval: h.approval, metrics: h.metrics, waveTraces: h.waveTraces || {}, strip: h.strip || null, waves: h.waves || [], failed: [...st.failed] }));
351
359
  if (h.demo.cycle !== st.cycle) {
352
360
  // A new cycle: a new story. Its first look is the trail so far, not news.
353
361
  // The first look at a page sees a cycle already under way: no news. A cycle that turns while the page is open is all news.
@@ -63,7 +63,7 @@ const jobLines = (job) => (job && Array.isArray(job.steps) ? job.steps.flatMap((
63
63
  * `waves` is the declared waves (`{ job, wave, roots }`), so a job names its
64
64
  * wave and a wave its roots.
65
65
  */
66
- export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc = null, runDocs = [], approval = null, metrics = null, waveTraces = {}, waves = [], failed = [] } = {}) {
66
+ export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc = null, runDocs = [], approval = null, metrics = null, waveTraces = {}, waves = [], failed = [], strip = null } = {}) {
67
67
  if (!demo) return null;
68
68
  const pr = matchingPull(answer, demo) || (answer && !answer.error && answer.pull_request && demo.pull !== null && String(answer.pull_request.run && answer.pull_request.run.pull_request) === String(demo.pull) ? answer.pull_request : null);
69
69
  const run = matchingRun(progress, demo);
@@ -78,10 +78,12 @@ export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc
78
78
  run: runDoc ? { id: runDoc.id, jobs: jobs.map((j) => ({ name: j.name, status: j.status, wave: waveOfJob(j.name, waves), refusal: j.status === "failure" ? yodelRefusal(jobLines(j)) : null, step: j.steps ? defaultStep(j.steps) : -1 })) } : null,
79
79
  approval: approval && Array.isArray(approval.rows) ? { wave: approval.wave, rows: approval.rows.filter((r) => r.state === "lit").map((r) => ({ id: r.id, at: r.at || null, actor: r.id === "approved" ? actorOf(r.text) : null, signed: !!(r.seal && /^signed/.test(r.seal.text || "")) })) } : null,
80
80
  // The numbers of this cycle's merge only: from the merge on, and only for its commit.
81
- metrics: metrics && metrics.run && metrics.run.current && stepRank(demo.step) >= 2 && (!demo.commit || String(metrics.run.label || "").includes(String(demo.commit).slice(0, 8))) ? metrics.run.waves.map((w) => ({ wave: w.wave, words: [w.seconds, w.held ? `held ${w.held}` : null, w.changed].filter(Boolean).join(" · ") })).filter((w) => w.words) : [],
81
+ metrics: metrics && metrics.run && metrics.run.current && stepRank(demo.step, strip) >= stepRank("merged", strip) && (!demo.commit || String(metrics.run.label || "").includes(String(demo.commit).slice(0, 8))) ? metrics.run.waves.map((w) => ({ wave: w.wave, words: [w.seconds, w.held ? `held ${w.held}` : null, w.changed].filter(Boolean).join(" · ") })).filter((w) => w.words) : [],
82
82
  // Each wave's trace, once Tempo has it (web/kiosk-wave-traces.js): `{ wave, run, job, words }`.
83
83
  traces: Object.keys(waveTraces || {}).map(Number).sort((a, b) => a - b).map((w) => ({ wave: w, run: waveTraces[w].run, job: waveTraces[w].job, words: traceReadyWords(w, waveTraces[w].trace) })).filter((t) => t.words),
84
84
  waves,
85
+ // The scenario's own step order (kiosk.js stripFromSteps), so the story keeps the order the steps had: chant gates before its merge.
86
+ strip: Array.isArray(strip) && strip.length ? strip : STRIP,
85
87
  // The waves this cycle saw fail, kept by the kiosk: a re-run is news only against a failure seen before it.
86
88
  failed: [...new Set(failed)],
87
89
  // The cycle's earlier runs' failures (the approval panel reads them): a viewer who arrives after the re-run still gets the refusal.
@@ -108,7 +110,7 @@ const actorOf = (text) => {
108
110
  };
109
111
 
110
112
  /** The strip's order of a step: 0 for the pull request, up to 5 for the reset; -1 for one the strip doesn't know. */
111
- const stepRank = (step) => STRIP.findIndex((s) => s.steps.includes(step));
113
+ const stepRank = (step, strip = STRIP) => (strip || STRIP).findIndex((s) => s.steps.includes(step));
112
114
 
113
115
  /**
114
116
  * Everything the snapshot says has happened in its cycle, as facts in the
@@ -122,15 +124,17 @@ export function cycleFacts(snap) {
122
124
  if (!snap) return [];
123
125
  const out = [];
124
126
  const add = (f) => out.push({ subjects: { roots: [], wave: null, job: null, run: null }, trail: true, critical: false, ...f, subjects: { roots: [], wave: null, job: null, run: null, ...(f.subjects || {}) } });
125
- const at = stepRank(snap.step);
127
+ const strip = snap.strip || STRIP;
128
+ const at = stepRank(snap.step, strip);
129
+ const rank = (step) => stepRank(step, strip);
126
130
  const c = snap.cycle;
127
131
  const runId = snap.run ? snap.run.id : null;
128
132
  // The pull request and its plan.
129
133
  if (snap.pull !== null && snap.pull !== undefined && at >= 0) add({ id: `${c}|pr`, kind: "pull-request", text: `pull request #${snap.pull} opened`, order: 0, subjects: { roots: snap.plan ? snap.plan.roots : [] } });
130
- if (snap.plan && snap.plan.totals && at >= 1) {
134
+ if (snap.plan && snap.plan.totals && at >= rank("planned")) {
131
135
  add({ id: `${c}|plan`, kind: "planned", text: planWords(snap.plan.totals), order: 1, subjects: { roots: snap.plan.roots } });
132
136
  }
133
- if (at >= 2 && snap.pull !== null && snap.pull !== undefined) add({ id: `${c}|merged`, kind: "merged", text: `pull request #${snap.pull} merged`, order: 2 });
137
+ if (at >= rank("merged") && snap.pull !== null && snap.pull !== undefined) add({ id: `${c}|merged`, kind: "merged", text: `pull request #${snap.pull} merged`, order: 2 });
134
138
  // Each wave, from the run view; a wave's job, from the pipeline's run.
135
139
  const jobOf = (n) => (snap.run ? snap.run.jobs.find((j) => j.wave === n) : null);
136
140
  const approved = snap.approval ? snap.approval.rows.find((r) => r.id === "approved") : null;
@@ -178,16 +182,30 @@ export function cycleFacts(snap) {
178
182
  for (const m of snap.metrics) add({ id: `${c}|metrics|${m.wave}`, kind: "metrics", text: `wave ${m.wave}: ${m.words}`, order: 10 + m.wave * 10 + 9, subjects: { roots: rootsOfWave(m.wave, snap.waves, states), wave: m.wave, run: runId }, trail: false });
179
183
  // A wave's trace, once Tempo has it: a beat of the story, and a tip that opens it.
180
184
  for (const t of snap.traces) add({ id: `${c}|trace|w${t.wave}`, kind: "trace", text: t.words, order: 10 + t.wave * 10 + 9, subjects: { roots: rootsOfWave(t.wave, snap.waves, states), wave: t.wave, job: t.job, run: t.run } });
185
+ // A gate on the whole change (chant's pull-request loop): its approval, no wave named.
186
+ if (snap.approval && !Number.isInteger(snap.approval.wave)) {
187
+ if (snap.approval.rows.some((r) => r.id === "requested" || r.id === "approved")) add({ id: `${c}|held`, kind: "held", text: "the plan waits for an approval", order: 9, critical: true });
188
+ const ok = snap.approval.rows.find((r) => r.id === "approved");
189
+ if (ok) add({ id: `${c}|approved`, kind: "approved", text: ok.actor ? `approved by ${ok.actor}${ok.signed ? ", signed" : ""}` : "approved, signed", order: 9.5 });
190
+ }
181
191
  // A gate on the whole change (chant's pull-request loop): the plan waits, no wave named.
182
192
  // A repo with declared waves names its held wave once the run view has it; this is for a repo without them.
183
193
  if (snap.step === "waiting" && !(snap.waves || []).length && !out.some((f) => f.kind === "held")) add({ id: `${c}|held`, kind: "held", text: "the plan waits for an approval", order: 9, critical: true });
184
- const applied = states.filter((s) => s.state === "applied").length;
185
- if (snap.step === "applied") add({ id: `${c}|applied`, kind: "applied", text: !states.length ? "the change applied" : applied === states.length ? `all ${applied} waves applied` : `${applied} of ${states.length} waves applied`, order: 990, critical: true });
194
+ // The step says the run applied: every wave the run view names, even one a read has not caught up on.
195
+ if (snap.step === "applied") add({ id: `${c}|applied`, kind: "applied", text: !states.length ? "the change applied" : states.length === 1 ? "the wave applied" : `all ${states.length} waves applied`, order: 990, critical: true });
186
196
  if (snap.step === "reset") add({ id: `${c}|reset`, kind: "reset", text: "states back on the base", order: 995 });
187
- // One fact per id (a wave's hold is said by the run view and the approval rows alike), in the cycle's order.
197
+ // One fact per id (a wave's hold is said by the run view and the approval rows alike).
188
198
  const byId = new Map();
189
199
  for (const f of out) if (!byId.has(f.id)) byId.set(f.id, f);
190
- return [...byId.values()].sort((a, b) => a.order - b.order);
200
+ // behold#571 (#631): in the order the scenario's steps went: each fact at its stop of the strip, then in its order within it.
201
+ // An approval before the merge (chant's gate) is its own stop; after it, part of the waves.
202
+ const stopIndex = (id) => {
203
+ const i = strip.findIndex((x) => x.id === id);
204
+ return i >= 0 ? i : strip.findIndex((x) => x.id === "waves");
205
+ };
206
+ const gateStop = strip.some((x) => x.id === "approval") ? "approval" : "waves";
207
+ const stopOf = (f) => (["pull-request", "planned", "merged", "applied", "reset"].includes(f.kind) ? f.kind : f.kind === "pull-request" ? "pull-request" : ["held", "approved", "resumed"].includes(f.kind) && !Number.isInteger(f.subjects.wave) ? gateStop : "waves");
208
+ return [...byId.values()].map((f) => ({ ...f, stop: stopOf(f), order: Math.max(0, stopIndex(stopOf(f))) * 1000 + f.order })).sort((a, b) => a.order - b.order);
191
209
  }
192
210
 
193
211
  /** The story trail: the cycle's facts that are beats of its story. */
@@ -2,6 +2,7 @@
2
2
  // told as facts in order, the news since the last look, the Tips switch, and
3
3
  // the queues that keep tips and modals calm.
4
4
  import { describe, expect, it } from "vitest";
5
+ import { stripFromSteps } from "./kiosk.js";
5
6
  import { EH_STORE, cycleFacts, ehSnapshot, ehStore, ehStored, modalQueue, newEvents, storyTrail, tipsQueue, yodelRefusal } from "./kiosk-event-help.js";
6
7
 
7
8
  const C = "9f3c2a71d04e5b8c6a1f2e3d4c5b6a7980716253";
@@ -62,6 +63,23 @@ describe("event-help: a cycle told in order", () => {
62
63
  expect(facts("waiting").some((f) => f.kind === "held")).toBe(false);
63
64
  });
64
65
 
66
+ it("counts every wave at applied, even one the run view has not caught up on (behold#571)", () => {
67
+ const behind = facts("applied", [st(1, "applied", ["network", "other"]), st(2, "applied", ["app"]), st(3, "not-started", ["edge"])]);
68
+ expect(behind.find((f) => f.kind === "applied").text).toBe("all 3 waves applied");
69
+ expect(facts("applied", [st(1, "applied", ["network", "other"])]).find((f) => f.kind === "applied").text).toBe("the wave applied");
70
+ });
71
+
72
+ it("tells chant's pull-request loop in its own order: the approval before the merge (#631)", () => {
73
+ const strip = stripFromSteps(["pull-request", "planned", "waiting", "approved", "merged", "applying", "applied", "reset"]);
74
+ const chant = (step, approval = null) => cycleFacts(ehSnapshot({ demo: { ...demo(step), scenario: "chant-pr-loop", tool: "chant" }, answer: null, approval, strip }));
75
+ // Waiting for the approval: the pull request is open, not merged.
76
+ expect(storyTrail(chant("waiting")).map((f) => f.text)).toEqual(["pull request #12 opened", "the plan waits for an approval"]);
77
+ const approval = { wave: null, rows: [{ id: "approved", state: "lit", text: "demo-reviewer approved exactly this plan.", seal: { ok: true, text: "signed; matches the repo's allowed signers" } }] };
78
+ expect(storyTrail(chant("applied", approval)).map((f) => f.text)).toEqual(["pull request #12 opened", "the plan waits for an approval", "approved by demo-reviewer, signed", "pull request #12 merged", "the change applied"]);
79
+ // terragucci's waves keep theirs: a wave's hold after the merge.
80
+ expect(storyTrail(facts("waiting", [st(1, "applied", ["network", "other"]), st(2, "waiting", ["app"])])).map((f) => f.kind)).toEqual(["pull-request", "planned", "merged", "applied-wave", "known", "held"]);
81
+ });
82
+
65
83
  it("names each event's subjects, so the kiosk can place it", () => {
66
84
  const held = facts("waiting", [st(1, "applied", ["network", "other"]), st(2, "waiting", ["app"])], { runDoc: { id: 4801, cycle: 7, jobs: [{ name: "apply-wave-2", status: "waiting", steps: [] }] } });
67
85
  expect(held.find((f) => f.kind === "held")).toMatchObject({ critical: true, subjects: { roots: ["app"], wave: 2, job: "apply-wave-2", run: 4801 } });
@@ -198,6 +198,8 @@ const STYLE = `
198
198
  .t-seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 999px; overflow: hidden; flex: none; }
199
199
  .t-tab { font: 600 0.9em var(--font-ui); color: var(--muted); background: transparent; border: 0; padding: 0.25em 1em; cursor: pointer; }
200
200
  .t-tab + .t-tab { border-left: 1px solid var(--rule); }
201
+ .t-attempts { display: flex; align-items: center; justify-content: space-between; gap: 0.6em; }
202
+ .t-seg-small .t-tab { font: 600 0.85em var(--font-mono); padding: 0.05em 0.7em; letter-spacing: 0; }
201
203
  .t-tab:hover { color: var(--fg); }
202
204
  .t-tab[aria-pressed="true"], .t-tab[aria-pressed="true"]:hover { color: var(--bg); background: var(--pending); }
203
205
  .t-sec { font: 600 0.8em var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0.6em 1em 0.25em; }
@@ -265,7 +267,34 @@ function bar(doc, at, width) {
265
267
  * the viewer's folds (`open`, `shut`, sets of span ids) and calls `toggle(id)`
266
268
  * and `pickJob(name)`.
267
269
  */
268
- export function renderTrace(host, { traces, run = [], job }, { doc = document, toggle = () => {}, pickJob = null, open = new Set(), shut = new Set() } = {}) {
270
+ /**
271
+ * behold#571: which of a job's traces is the one asked about: the trace that
272
+ * started at `start` (the wave's own, as the kiosk picked it), else the
273
+ * newest of `wave`'s, else the newest. A resumed run's job applies several
274
+ * waves, and a wave may run twice, so its traces are attempts.
275
+ */
276
+ export function attemptFor(traces, { wave = null, start = null } = {}) {
277
+ if (!traces || !traces.length) return -1;
278
+ if (start !== null) {
279
+ const i = traces.findIndex((t) => Math.abs(t.start - start) < 1);
280
+ if (i >= 0) return i;
281
+ }
282
+ if (wave !== null) {
283
+ let best = -1;
284
+ traces.forEach((t, i) => {
285
+ if (Number(t.wave) === Number(wave) && (best < 0 || traces[best].start < t.start)) best = i;
286
+ });
287
+ if (best >= 0) return best;
288
+ }
289
+ return traces.reduce((b, t, i) => (traces[b].start < t.start ? i : b), 0);
290
+ }
291
+
292
+ /** behold#571: the words over one attempt of several, and the switch's label. */
293
+ export function attemptWords(i, n, start) {
294
+ return `Attempt ${i + 1} of ${n}, started at ${new Date(start).toISOString().slice(11, 16)} UTC`;
295
+ }
296
+
297
+ export function renderTrace(host, { traces, run = [], job }, { doc = document, toggle = () => {}, pickJob = null, open = new Set(), shut = new Set(), attempt = null, pickAttempt = null } = {}) {
269
298
  traceStyle(doc);
270
299
  const box = el(doc, "div", "t-trace");
271
300
  const strip = runStrip(run);
@@ -284,10 +313,29 @@ export function renderTrace(host, { traces, run = [], job }, { doc = document, t
284
313
  }
285
314
  box.appendChild(rows);
286
315
  }
287
- traces.forEach((t, i) => {
288
- const when = new Date(t.start);
289
- const head = traces.length > 1 ? `Attempt ${i + 1} of ${traces.length}, ${when.toISOString().slice(11, 19)} UTC` : `This job · ${msWords(t.ms)}`;
290
- box.appendChild(el(doc, "div", "t-sec", head));
316
+ // behold#571: asked about one attempt of several, it shows that one, with a switch to the others.
317
+ const one = attempt !== null && attempt >= 0 && attempt < traces.length && traces.length > 1;
318
+ const shown = one ? [traces[attempt]] : traces;
319
+ shown.forEach((t, k) => {
320
+ const i = one ? attempt : k;
321
+ const head = traces.length > 1 ? attemptWords(i, traces.length, t.start) : `This job · ${msWords(t.ms)}`;
322
+ if (one) {
323
+ const sec = el(doc, "div", "t-sec t-attempts");
324
+ sec.appendChild(el(doc, "span", null, head));
325
+ const seg = el(doc, "span", "t-seg t-seg-small");
326
+ seg.setAttribute("role", "group");
327
+ seg.setAttribute("aria-label", "attempt");
328
+ traces.forEach((x, j) => {
329
+ const b = el(doc, "button", "t-tab", String(j + 1));
330
+ b.type = "button";
331
+ b.title = attemptWords(j, traces.length, x.start);
332
+ b.setAttribute("aria-pressed", String(j === i));
333
+ if (pickAttempt) b.addEventListener("click", () => pickAttempt(j));
334
+ seg.appendChild(b);
335
+ });
336
+ sec.appendChild(seg);
337
+ box.appendChild(sec);
338
+ } else box.appendChild(el(doc, "div", "t-sec", head));
291
339
  const rows = el(doc, "div", "t-rows");
292
340
  for (const r of waterfallRows(t, { open, shut })) {
293
341
  const cls = ["t-row", r.kids ? "t-can" : "", r.service !== "terragucci" ? "t-bin" : "", r.critical ? "t-crit" : "", r.wait ? "t-wait" : "", r.error ? "t-err" : ""].filter(Boolean).join(" ");
@@ -377,8 +425,8 @@ export function traceSource({ fetchJson, onChange = () => {}, now = () => Date.n
377
425
  has: (repo, run, job) => of(repo, run, job).length > 0,
378
426
  traces: of,
379
427
  all: (repo, run) => (read(repo, run) || { traces: [] }).traces,
380
- draw(host, { repo, run, job, pickJob = null, doc = document }) {
381
- return renderTrace(host, { traces: of(repo, run, job), run: this.all(repo, run), job }, { doc, pickJob, open: folds.open, shut: folds.shut, toggle: (id, depth) => { folds.toggle(id, depth); onChange(); } });
428
+ draw(host, { repo, run, job, pickJob = null, doc = document, attempt = null, pickAttempt = null }) {
429
+ return renderTrace(host, { traces: of(repo, run, job), run: this.all(repo, run), job }, { doc, pickJob, attempt, pickAttempt, open: folds.open, shut: folds.shut, toggle: (id, depth) => { folds.toggle(id, depth); onChange(); } });
382
430
  },
383
431
  };
384
432
  }
@@ -389,19 +437,25 @@ export function traceSource({ fetchJson, onChange = () => {}, now = () => Date.n
389
437
  * it at another job; `stop` ends its reads. With no trace for the job it
390
438
  * draws nothing.
391
439
  */
392
- export function mountTrace(host, { project, run, job, fetchJson = defaultFetch, doc = document, setTimer = setInterval, clearTimer = clearInterval, pickJob = null } = {}) {
393
- let target = { project, run, job };
440
+ export function mountTrace(host, { project, run, job, wave = null, start = null, fetchJson = defaultFetch, doc = document, setTimer = setInterval, clearTimer = clearInterval, pickJob = null } = {}) {
441
+ let target = { project, run, job, wave, start };
442
+ // behold#571: with a wave named, the attempt that is its; a viewer's pick of another holds until the target moves.
443
+ let picked = null;
394
444
  const draw = () => {
395
445
  host.replaceChildren();
396
446
  if (!source.has(target.project, target.run, target.job)) return;
397
- source.draw(host, { repo: target.project, run: target.run, job: target.job, pickJob, doc });
447
+ const traces = source.traces(target.project, target.run, target.job);
448
+ const attempt = target.wave === null && target.start === null ? null : picked !== null && picked < traces.length ? picked : attemptFor(traces, target);
449
+ source.draw(host, { repo: target.project, run: target.run, job: target.job, pickJob, doc, attempt, pickAttempt: (i) => ((picked = i), draw()) });
398
450
  };
399
451
  const source = traceSource({ fetchJson, onChange: draw });
400
452
  draw();
401
453
  const timer = setTimer(draw, TRACE_POLL_MS);
402
454
  return {
403
455
  update(next) {
456
+ const was = JSON.stringify(target);
404
457
  target = { ...target, ...next };
458
+ if (JSON.stringify(target) !== was) picked = null;
405
459
  draw();
406
460
  },
407
461
  stop() {
@@ -155,3 +155,17 @@ describe("the strip's left bars (behold#571)", () => {
155
155
  expect(["failed", "changed-after-approval", "waiting", "applied", "planned", undefined, "other"].map(stripTone)).toEqual(["bad", "bad", "wait", "ok", "ok", "idle", "idle"]);
156
156
  });
157
157
  });
158
+
159
+ describe("kiosk trace: one attempt of several (behold#571)", () => {
160
+ const t = (wave, start) => ({ wave, start, ms: 10, spans: [] });
161
+ it("picks the attempt that is the asked-about wave's: its own start, else that wave's newest, else the newest", async () => {
162
+ const { attemptFor, attemptWords } = await import("./kiosk-trace.js");
163
+ const traces = [t(1, 100), t(2, 200), t(2, 300)];
164
+ expect(attemptFor(traces, { wave: 2, start: 200 })).toBe(1);
165
+ expect(attemptFor(traces, { wave: 2 })).toBe(2);
166
+ expect(attemptFor(traces, { wave: 1 })).toBe(0);
167
+ expect(attemptFor(traces, { wave: 9 })).toBe(2);
168
+ expect(attemptFor([], { wave: 1 })).toBe(-1);
169
+ expect(attemptWords(0, 2, Date.parse("2026-10-16T19:25:38Z"))).toBe("Attempt 1 of 2, started at 19:25 UTC");
170
+ });
171
+ });
@@ -190,9 +190,11 @@ function roundedWeek(v) {
190
190
  export function resultModel(demo, metrics, progress = null) {
191
191
  if (!demo || demo.step !== "applied") return null;
192
192
  const run = matchingRun(progress, demo);
193
- const states = run ? (progress.states || []).filter((w) => w.state === "applied") : [];
193
+ // The step says the run applied: every wave the run view names counts, even one a read has not caught up on yet.
194
+ const all = run ? progress.states || [] : [];
195
+ const states = all.filter((w) => w.state === "applied");
194
196
  const m = metrics && metrics.run && metrics.run.current ? metrics.run.waves : [];
195
- const n = states.length || m.length;
197
+ const n = all.length || m.length;
196
198
  if (!n) return null;
197
199
  const counts = [`${n} ${n === 1 ? "wave" : "waves"} applied`];
198
200
  const changed = states.length ? mergeChanges(states.map((w) => w.totals)) : mergeChanges(m.map((w) => w.changesRaw));
@@ -204,10 +206,48 @@ export function resultModel(demo, metrics, progress = null) {
204
206
  const held = m.reduce((a, w) => a + (Number.isFinite(w.heldRaw) ? w.heldRaw : 0), 0);
205
207
  if (held > 0) counts.push(`${secondsShort(held)} held for an approval`);
206
208
  }
207
- const waves = [...m].sort((a, b) => a.wave - b.wave).map((w) => ({ wave: w.wave, words: badgeWords(w) })).filter((w) => w.words);
209
+ // A row for every wave, its numbers when they have landed; never fewer rows than the count says.
210
+ const numbers = new Map(m.map((w) => [w.wave, badgeWords(w)]));
211
+ const numbered = [...new Set([...all.map((w) => w.number), ...m.map((w) => w.wave)])].sort((a, b) => a - b);
212
+ const waves = numbered.map((w) => ({ wave: w, words: numbers.get(w) || null }));
208
213
  return { head: "Applied", line: typeof demo.label === "string" ? demo.label : "", counts, waves };
209
214
  }
210
215
 
216
+ /**
217
+ * behold#571: the run view as the cycle has seen it, for the result card and
218
+ * the trail. Reads land one by one and a read can lag behind the last: within
219
+ * one cycle's commit, a wave once read as applied stays applied, a wave a
220
+ * read leaves out keeps what it was, and the run stays the last one that
221
+ * matched. `{ memo, progress }`; pass the memo back in with the next read.
222
+ */
223
+ export function steadyRun(memo, progress, demo) {
224
+ const key = demo ? `${demo.cycle}|${demo.commit}` : null;
225
+ const run = demo ? matchingRun(progress, demo) : null;
226
+ const was = memo && memo.key === key ? memo : { key, run: null, states: {} };
227
+ const next = { key, run: run || was.run, states: { ...was.states } };
228
+ if (run) {
229
+ for (const st of progress.states || []) {
230
+ const had = next.states[st.number];
231
+ if (had && had.state === "applied" && st.state !== "applied") continue;
232
+ // A re-run's run view says nothing changed for a wave an earlier run applied: the change stays the one that landed.
233
+ if (had && had.state === "applied" && st.state === "applied" && changeCount(had.totals) > 0 && changeCount(st.totals) === 0) continue;
234
+ next.states[st.number] = st;
235
+ }
236
+ }
237
+ const states = Object.values(next.states).sort((a, b) => a.number - b.number);
238
+ if (!next.run || !states.length) return { memo: next, progress };
239
+ return { memo: next, progress: { ...(run ? progress : {}), reads: run ? progress.reads || [] : [], run: next.run, states } };
240
+ }
241
+
242
+ const changeCount = (totals) => ACTION_ORDER.reduce((a, k) => a + (totals && typeof totals[k] === "number" ? totals[k] : 0), 0);
243
+
244
+ /** behold#571: whether a run view is behind the step: the step says applied, and a wave in it still says otherwise. */
245
+ export function behindStep(demo, progress) {
246
+ if (!demo || demo.step !== "applied") return false;
247
+ const run = matchingRun(progress, demo);
248
+ return !!run && (progress.states || []).some((w) => w.state !== "applied");
249
+ }
250
+
211
251
  const ACTION_ORDER = ["create", "update", "delete", "replace", "forget", "import", "move"];
212
252
  const ACTION_WORDS = { create: "created", update: "updated", delete: "deleted", replace: "replaced", forget: "forgotten", import: "imported", move: "moved" };
213
253
  function mergeChanges(list) {
@@ -2,7 +2,7 @@
2
2
  // takes, what the caption leads with, the badges, the delivery line, the
3
3
  // result card, the drawer's folded lines, and where an overlay goes.
4
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";
5
+ import { MODE_STORE, activeWave, badgeTitle, badgeWords, badges, behindStep, steadyRun, captionModel, changeRoots, doraLine, modeStored, placeBeside, resultModel, shotFor, stepTone, tailLines } from "./kiosk-watch.js";
6
6
 
7
7
  const C = "9f3c2a71d04e5b8c6a1f2e3d4c5b6a7980716253";
8
8
  const P = "1111111111111111111111111111111111111111";
@@ -144,6 +144,36 @@ describe("kiosk watch: the numbers", () => {
144
144
  expect(resultModel(demo("applying"), metrics, p)).toBeNull();
145
145
  expect(resultModel(demo("applied"), null, null)).toBeNull();
146
146
  });
147
+
148
+ it("never counts fewer waves than the step says, nor lists fewer than it counts (behold#571)", () => {
149
+ // The step says applied while the run view still has wave 3 queued: three waves applied, three rows, the third's numbers to come.
150
+ const behind = progress([st(1, "applied", ["network"], { update: 1 }), st(2, "applied", ["app"], { create: 4 }), st(3, "not-started", ["edge"])]);
151
+ const r = resultModel(demo("applied"), metrics, behind);
152
+ expect(r.counts[0]).toBe("3 waves applied");
153
+ expect(r.waves).toEqual([{ wave: 1, words: "1.6 s · 1 updated" }, { wave: 2, words: "9.5 s · held 25 s · 4 created" }, { wave: 3, words: null }]);
154
+ expect(behindStep(demo("applied"), behind)).toBe(true);
155
+ expect(behindStep(demo("applied"), progress([st(1, "applied", ["network"])]))).toBe(false);
156
+ expect(behindStep(demo("applying"), behind)).toBe(false);
157
+ });
158
+
159
+ it("keeps the run view as the cycle has seen it: an applied wave stays applied, a wave a read leaves out stays, a read for another run is set aside", () => {
160
+ const d = demo("applied");
161
+ let { memo, progress: p1 } = steadyRun(null, progress([st(1, "applied", ["network"]), st(2, "applied", ["app"]), st(3, "applied", ["edge"])]), d);
162
+ expect(p1.states.map((w) => w.state)).toEqual(["applied", "applied", "applied"]);
163
+ // A lagging read: the resume's run view, not yet caught up.
164
+ const lag = steadyRun(memo, progress([st(1, "applied", ["network"]), st(2, "not-started", ["app"])]), d);
165
+ expect(lag.progress.states.map((w) => [w.number, w.state])).toEqual([[1, "applied"], [2, "applied"], [3, "applied"]]);
166
+ // A read of another commit (the reset's push): the cycle's run stays.
167
+ const other = steadyRun(lag.memo, { run: { present: true, commit: "0000000000000000000000000000000000000000", updated: "2026-10-16T09:00:00Z" }, states: [st(1, "planned", ["network"])], reads: [] }, d);
168
+ expect(other.progress.states).toHaveLength(3);
169
+ expect(resultModel(d, null, other.progress).counts[0]).toBe("3 waves applied");
170
+ // The resume's run view says the waves an earlier run applied changed nothing now: the changes that landed stay.
171
+ const first = steadyRun(null, progress([st(1, "applied", ["network"], { update: 1 }), st(2, "applied", ["app"], { create: 4 })]), d);
172
+ const resumed = steadyRun(first.memo, progress([st(1, "applied", ["network"], { "no-op": 3 }), st(2, "applied", ["app"], { create: 4 })]), d);
173
+ expect(resultModel(d, null, resumed.progress).counts).toEqual(["2 waves applied", "4 created, 1 updated"]);
174
+ // A new cycle starts over.
175
+ expect(steadyRun(other.memo, null, demo("pull-request", { cycle: 13 })).progress).toBeNull();
176
+ });
147
177
  });
148
178
 
149
179
  describe("kiosk watch: the drawer's folded lines", () => {
package/web/kiosk.html CHANGED
@@ -470,7 +470,9 @@
470
470
  #k-drawer.k-trace-only #k-traces:empty { display: block; }
471
471
  .k-wf { margin-top: 0.7em; padding-top: 0.5em; border-top: 1px solid var(--rule); display: grid; gap: 0.25em; }
472
472
  .k-wf-row { display: grid; grid-template-columns: 4.2em minmax(6em, 1fr) auto auto; align-items: center; gap: 0.6em; width: 100%; padding: 0.2em 0.3em; border: 0; border-radius: 6px; background: transparent; color: var(--fg); font: inherit; text-align: left; cursor: pointer; }
473
- .k-wf-row:hover, .k-wf-row:focus-visible { background: var(--active); }
473
+ .k-wf-row:not(.k-wf-plain):hover, .k-wf-row:focus-visible { background: var(--active); }
474
+ .k-wf-row.k-wf-plain { grid-template-columns: 4.2em minmax(0, 1fr); cursor: default; }
475
+ .k-wf-words { font-size: 0.9em; font-variant-numeric: tabular-nums; }
474
476
  .k-wf-wave { font: 600 0.88em var(--font-mono); color: var(--muted); }
475
477
  .k-wf-track { position: relative; height: 0.85em; border-radius: 3px; background: color-mix(in srgb, var(--rule) 45%, transparent); overflow: hidden; }
476
478
  .k-wf-seg { position: absolute; top: 0; bottom: 0; min-width: 2px; }
@@ -491,6 +493,7 @@
491
493
  .k-result-waves { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.2em 0.9em; margin: 0; padding-top: 0.5em; border-top: 1px solid var(--rule); }
492
494
  .k-result-waves dt { font: 600 0.9em var(--font-mono); color: var(--muted); }
493
495
  .k-result-waves dd { margin: 0; font-variant-numeric: tabular-nums; }
496
+ .k-result-waves dd.k-result-soon { color: var(--muted); font-style: italic; }
494
497
  @media (max-width: 900px) and (min-width: 601px) { body.k-watch #bar { padding-right: 1em; flex-wrap: wrap; } body.k-watch #k-head { display: flex; flex-direction: column-reverse; } body.k-watch #k-tools { position: static; justify-content: flex-end; padding: 0.4em 1em 0; } }
495
498
  .k-w-dora-foot { display: none; }
496
499
  /* A phone: a short header, the graph, then the step and the approval under it; the rest stacks below, in the page's flow. */
package/web/kiosk.js CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  import { CHANT_PANEL_STEPS, chantApprovalModel } from "./chant-pr-marks.js";
17
17
  import { PICK_HOLD_MS, annMark, mergeRun, startRuns, statusIcon } from "./kiosk-runs.js";
18
- import { MODES, MODE_STORE, badges as waveBadges, badgeTitle, captionModel, doraLine, modeStored, placeBeside, resultModel, shotFor, stepTone, tailLines } from "./kiosk-watch.js";
18
+ import { MODES, MODE_STORE, badges as waveBadges, badgeTitle, behindStep, steadyRun, captionModel, doraLine, modeStored, placeBeside, resultModel, shotFor, stepTone, tailLines } from "./kiosk-watch.js";
19
19
  import { shotMessage } from "./kiosk-shot.js";
20
20
  import { mountTrace } from "./kiosk-trace.js";
21
21
  import { startEventHelp } from "./kiosk-event-help-ui.js";
@@ -120,9 +120,40 @@ export function aboutRows(demo) {
120
120
  }
121
121
 
122
122
  /** The strip: each stop, and whether it is done, current or ahead. A stalled cycle marks no stop current. */
123
- export function stripStops(step) {
124
- const at = STRIP.findIndex((s) => s.steps.includes(step));
125
- return STRIP.map((s, i) => ({ id: s.id, words: s.words, state: at < 0 ? "ahead" : i < at ? "done" : i === at ? (step === "failed" ? "failed" : "current") : "ahead" }));
123
+ export function stripStops(step, strip = STRIP) {
124
+ const at = strip.findIndex((s) => s.steps.includes(step));
125
+ return strip.map((s, i) => ({ id: s.id, words: s.words, state: at < 0 ? "ahead" : i < at ? "done" : i === at ? (step === "failed" ? "failed" : "current") : "ahead" }));
126
+ }
127
+
128
+ /** behold#571 (#631): the words of the strip's approval stop, a gate before the merge. */
129
+ export const APPROVAL_STOP = { id: "approval", words: "approval" };
130
+
131
+ /**
132
+ * behold#571 (#631): the strip in a scenario's own order, from the steps its
133
+ * tool's recorded cycle went through (/api/terragucci/cycles/<tool>). A wait
134
+ * for an approval before the merge (chant's pull-request loop gates the plan
135
+ * before it merges) is a stop of its own between "planned" and "merged"; after
136
+ * the merge it is part of the waves, as terragucci's waves are. Null when the
137
+ * steps say nothing, so the default strip stands.
138
+ */
139
+ export function stripFromSteps(steps) {
140
+ if (!Array.isArray(steps) || !steps.length) return null;
141
+ const words = Object.fromEntries(STRIP.map((x) => [x.id, x.words]));
142
+ const stops = [];
143
+ let merged = false;
144
+ for (const step of steps) {
145
+ if (step === "merged") merged = true;
146
+ const id = ["pull-request", "planned", "merged", "applied", "reset"].includes(step) ? step : (step === "waiting" || step === "approved") && !merged ? APPROVAL_STOP.id : "waves";
147
+ let stop = stops.find((x) => x.id === id);
148
+ if (!stop) {
149
+ stop = { id, words: id === APPROVAL_STOP.id ? APPROVAL_STOP.words : words[id] || id, steps: [] };
150
+ stops.push(stop);
151
+ }
152
+ if (!stop.steps.includes(step)) stop.steps.push(step);
153
+ }
154
+ // A stop the default strip has and these steps never reached (the waves of a run that applied in one go) keeps its place.
155
+ for (const d of STRIP) if (!stops.some((x) => x.id === d.id)) stops.splice(Math.min(stops.length, STRIP.indexOf(d)), 0, { id: d.id, words: d.words, steps: d.steps.filter((st) => !stops.some((x) => x.steps.includes(st))) });
156
+ return stops;
126
157
  }
127
158
 
128
159
  /** Seconds from now until `at`, never below 0; null when there is no time. */
@@ -682,7 +713,7 @@ function drawBar(bar, s, now) {
682
713
  over.appendChild(el("span", "k-kicker", head.kicker));
683
714
  // The scenario's progress: the strip's stops, at the end of the line over the title.
684
715
  const strip = el("ol", "k-strip");
685
- for (const stop of stripStops(demo.step)) strip.appendChild(el("li", `k-stop k-${stop.state}`, stop.words));
716
+ for (const stop of stripStops(demo.step, s.strip || STRIP)) strip.appendChild(el("li", `k-stop k-${stop.state}`, stop.words));
686
717
  over.appendChild(strip);
687
718
  const title = el("h1", "k-title");
688
719
  title.appendChild(el("span", "k-title-text", head.title));
@@ -811,7 +842,7 @@ function drawWatchHead(bar, s, now) {
811
842
  place.appendChild(el("span", "k-cycle", cycleWords(demo, now)));
812
843
  bar.appendChild(place);
813
844
  const strip = el("ol", "k-strip");
814
- for (const stop of stripStops(demo.step)) strip.appendChild(el("li", `k-stop k-${stop.state}`, stop.words));
845
+ for (const stop of stripStops(demo.step, s.strip || STRIP)) strip.appendChild(el("li", `k-stop k-${stop.state}`, stop.words));
815
846
  bar.appendChild(strip);
816
847
  if (s.watchHeld) {
817
848
  const p = el("span", "k-w-held", heldWords(s.watchHeld.secs));
@@ -910,18 +941,21 @@ function drawResult(host, model, s) {
910
941
  const counts = el("ul", "k-result-counts");
911
942
  for (const c of model.counts) counts.appendChild(el("li", null, c));
912
943
  host.appendChild(counts);
913
- // behold#571: each wave's trace as one bar of its phases; a click opens the whole trace. A wave without one keeps its numbers.
914
- const rows = miniWaterfall(s.waveTraces || {});
915
- const traced = new Set(rows.map((r) => r.wave));
916
- const untraced = model.waves.filter((w) => !traced.has(w.wave));
917
- if (untraced.length) {
918
- const list = el("dl", "k-result-waves");
919
- for (const w of untraced) list.append(el("dt", null, `Wave ${w.wave}`), el("dd", null, w.words));
920
- host.appendChild(list);
921
- }
922
- if (rows.length) {
944
+ // behold#571: a row for every wave, in wave order: its trace as one bar of its phases (a click opens the whole trace),
945
+ // else its numbers, else a quiet line until they land. Never fewer rows than the count says.
946
+ const bars = new Map(miniWaterfall(s.waveTraces || {}).map((r) => [r.wave, r]));
947
+ const order = [...new Set([...model.waves.map((w) => w.wave), ...bars.keys()])].sort((x, y) => x - y);
948
+ if (order.length) {
923
949
  const wf = el("div", "k-wf");
924
- for (const r of rows) {
950
+ for (const n of order) {
951
+ const r = bars.get(n);
952
+ const w = model.waves.find((x) => x.wave === n);
953
+ if (!r) {
954
+ const row = el("div", "k-wf-row k-wf-plain");
955
+ row.append(el("span", "k-wf-wave", `Wave ${n}`), el("span", w && w.words ? "k-wf-words" : "k-wf-words k-result-soon", w && w.words ? w.words : NUMBERS_SOON));
956
+ wf.appendChild(row);
957
+ continue;
958
+ }
925
959
  const row = el("button", "k-wf-row");
926
960
  row.type = "button";
927
961
  const held = r.bars.find((b) => b.phase === "held");
@@ -938,16 +972,20 @@ function drawResult(host, model, s) {
938
972
  row.addEventListener("click", () => s.openWave && s.openWave(r.wave, "trace"));
939
973
  wf.appendChild(row);
940
974
  }
941
- const key = el("p", "k-wf-key");
942
- for (const [cls, words] of PHASE_KEY) {
943
- const k = el("span");
944
- k.append(el("i", `k-wf-sw k-wf-${cls}`), words);
945
- key.appendChild(k);
975
+ if (bars.size) {
976
+ const key = el("p", "k-wf-key");
977
+ for (const [cls, words] of PHASE_KEY) {
978
+ const k = el("span");
979
+ k.append(el("i", `k-wf-sw k-wf-${cls}`), words);
980
+ key.appendChild(k);
981
+ }
982
+ wf.appendChild(key);
946
983
  }
947
- wf.appendChild(key);
948
984
  host.appendChild(wf);
949
985
  }
950
986
  }
987
+ /** behold#571: a wave's row on the result card before its numbers land. */
988
+ export const NUMBERS_SOON = "its numbers land in a moment";
951
989
  /** behold#571: the words of a trace's links, and the phases' key. */
952
990
  export const TRACE_LINK_WORDS = "Trace";
953
991
  export const TRACE_OPEN_WORDS = "Open this wave's trace";
@@ -1063,6 +1101,11 @@ function fade(b) {
1063
1101
  b.classList.toggle("k-more-above", b.scrollTop > 1);
1064
1102
  }
1065
1103
 
1104
+ /** behold#571 (#631): how often a tool's recorded step order is read again. */
1105
+ export const STRIP_REREAD_MS = 600_000;
1106
+
1107
+ /** behold#571: how often a run view that is behind the step is read again. */
1108
+ export const FRESH_RUN_MS = 4_000;
1066
1109
  /** behold#571: how often a cycle's run's traces are read again, and how long after a run ends they still are. */
1067
1110
  export const TRACE_POLL_MS = 8_000;
1068
1111
  export const TRACE_SETTLE_MS = 90_000;
@@ -1093,6 +1136,10 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1093
1136
  s.shot = null;
1094
1137
  // behold#571: event-help, started further down once what it reads is in place.
1095
1138
  let ehApi = null;
1139
+ // behold#571: the run view as the cycle has seen it (steadyRun), and when a read behind the step last asked again.
1140
+ let runMemo = null;
1141
+ let freshAt = 0;
1142
+ s.steady = null;
1096
1143
  // behold#571: each wave's trace, from Tempo (web/kiosk-wave-traces.js).
1097
1144
  s.waveTraces = {};
1098
1145
  // behold#571: the frame loading out of sight while the shown one stays up (openFrame), and a message to both.
@@ -1312,6 +1359,14 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1312
1359
  tellHover(s.hover);
1313
1360
  }
1314
1361
  whatText();
1362
+ // behold#571: the run view as the cycle has seen it, for the result card and the trail; a read behind the step asks again.
1363
+ const sr = steadyRun(runMemo, s.progress, s.demo && s.demo.demo);
1364
+ runMemo = sr.memo;
1365
+ s.steady = sr.progress;
1366
+ if (behindStep(s.demo && s.demo.demo, s.progress) && now().getTime() - freshAt > FRESH_RUN_MS) {
1367
+ freshAt = now().getTime();
1368
+ void progress(true);
1369
+ }
1315
1370
  // behold#571: Watch's overlays, then the shot they leave room for.
1316
1371
  holdTick();
1317
1372
  drawWatch(shownNow());
@@ -1456,7 +1511,7 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1456
1511
  if (drawer) drawDrawer(watch.drawer, tail, badgeTitle(nums[drawerOn]), open);
1457
1512
  if (drawer) traceDrawer(d, drawerOn);
1458
1513
  // A drawer the viewer opened on a wave takes the card's place beside the graph until it folds.
1459
- const result = shot.kind === "result" && !opened ? resultModel(d, s.metrics, s.progress) : null;
1514
+ const result = shot.kind === "result" && !opened ? resultModel(d, s.metrics, s.steady) : null;
1460
1515
  watch.result.hidden = !result;
1461
1516
  if (result) drawResult(watch.result, result, s);
1462
1517
  // On a phone the delivery numbers stack under the rest, where the header has no room for them.
@@ -1498,8 +1553,9 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1498
1553
  const tr = s.waveTraces[wave];
1499
1554
  if (!host || !d || !d.repo || (!tr && (!runDoc || !w))) return;
1500
1555
  // The wave's own trace when Tempo has it (its run and job: a resumed run applies waves in one job), else its job in the drawer's run.
1501
- const target = tr ? { project: d.repo, run: tr.run, job: tr.job } : { project: d.repo, run: String(runDoc.id), job: w.job };
1502
- const key = `${target.project}|${target.run}|${target.job}`;
1556
+ // The wave's own attempt of its job: a resumed run's job applies several waves, and a wave may run twice.
1557
+ const target = tr ? { project: d.repo, run: tr.run, job: tr.job, wave, start: tr.trace.start } : { project: d.repo, run: String(runDoc.id), job: w.job, wave, start: null };
1558
+ const key = `${target.project}|${target.run}|${target.job}|${target.wave}|${target.start}`;
1503
1559
  if (trace && trace.key === key) return;
1504
1560
  if (trace) trace.api.update(target);
1505
1561
  else trace = { api: mountTrace(host, { ...target, fetchJson: fetchServed }) };
@@ -1641,7 +1697,7 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1641
1697
  return {
1642
1698
  demo: d,
1643
1699
  answer: s.answer,
1644
- progress: s.progress,
1700
+ progress: s.steady,
1645
1701
  runDoc: runsApi && runsApi.run ? runsApi.run.doc : null,
1646
1702
  // The cycle's runs the approval panel reads, for the failures of runs the pane no longer shows.
1647
1703
  runDocs: ap.list,
@@ -1655,8 +1711,10 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1655
1711
  replay: s.mode === "replay",
1656
1712
  approveLine: appr ? appr.approve : null,
1657
1713
  label: d.label || "",
1658
- result: resultModel(d, s.metrics, s.progress),
1714
+ result: resultModel(d, s.metrics, s.steady),
1659
1715
  waveTraces: s.waveTraces,
1716
+ strip: s.stripReady() ? s.strip : null,
1717
+ stripReady: s.stripReady(),
1660
1718
  };
1661
1719
  },
1662
1720
  })
@@ -1728,6 +1786,38 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1728
1786
  };
1729
1787
  setInterval(() => void readTraces(), 2_000);
1730
1788
 
1789
+ // behold#571 (#631): the strip in the running tool's own order, from its recorded cycle's steps; the default until it is read.
1790
+ const strips = new Map();
1791
+ s.strip = null;
1792
+ /** Whether the running tool's step order has been read (or there is none to read), so the story can be told in it. */
1793
+ s.stripReady = () => {
1794
+ const d = s.demo && s.demo.demo;
1795
+ const t = vendor ? tool : d && typeof d.tool === "string" ? d.tool : null;
1796
+ const r = t ? strips.get(t) : null;
1797
+ if (r && r.done) s.strip = r.strip;
1798
+ return !t || !!(r && r.done);
1799
+ };
1800
+ const readStrip = async () => {
1801
+ const d = s.demo && s.demo.demo;
1802
+ const t = vendor ? tool : d && typeof d.tool === "string" ? d.tool : null;
1803
+ if (!t) return;
1804
+ const had = strips.get(t);
1805
+ if (had && now().getTime() - had.at < STRIP_REREAD_MS) {
1806
+ if (s.strip !== had.strip) {
1807
+ s.strip = had.strip;
1808
+ draw();
1809
+ }
1810
+ return;
1811
+ }
1812
+ strips.set(t, { at: now().getTime(), strip: had ? had.strip : null, done: had ? had.done : false });
1813
+ const a = await fetchServed(`/api/terragucci/cycles/${encodeURIComponent(t)}`);
1814
+ const strip = a && a.cycle && Array.isArray(a.cycle.steps) ? stripFromSteps(a.cycle.steps.map((x) => x.step)) : null;
1815
+ strips.set(t, { at: now().getTime(), strip: strip || (had ? had.strip : null), done: true });
1816
+ s.strip = strips.get(t).strip;
1817
+ draw();
1818
+ };
1819
+ setInterval(() => void readStrip(), 2_000);
1820
+
1731
1821
  s.setMetrics = (m) => {
1732
1822
  s.metrics = m;
1733
1823
  draw();
package/web/kiosk.test.js CHANGED
@@ -481,3 +481,21 @@ describe("the lead block's step rail (behold#571)", () => {
481
481
  expect(["waiting", "failed", "stalled", "applied", "applying", "planned", "resumed", "reset"].map(stepTone)).toEqual(["wait", "bad", "bad", "ok", "busy", "busy", "busy", "idle"]);
482
482
  });
483
483
  });
484
+
485
+ describe("kiosk: the strip in a scenario's own order (behold#571, #631)", async () => {
486
+ const { stripFromSteps, stripStops, STRIP } = await import("./kiosk.js");
487
+ it("puts chant's approval between planned and merged, and lights it while the plan waits", () => {
488
+ const chant = stripFromSteps(["pull-request", "planned", "waiting", "approved", "merged", "applying", "applied", "reset"]);
489
+ expect(chant.map((x) => x.words)).toEqual(["pull request", "planned", "approval", "merged", "waves", "applied", "reset"]);
490
+ expect(stripStops("waiting", chant).find((x) => x.state === "current").words).toBe("approval");
491
+ expect(stripStops("applying", chant).find((x) => x.state === "current").words).toBe("waves");
492
+ });
493
+ it("keeps terragucci's waves, a hold after the merge part of them, and the default strip without steps", () => {
494
+ const tg = stripFromSteps(["pull-request", "planned", "merged", "applying", "failed", "resumed", "waiting", "approved", "resumed", "applied", "reset"]);
495
+ expect(tg.map((x) => x.id)).toEqual(STRIP.map((x) => x.id));
496
+ expect(stripStops("waiting", tg).find((x) => x.state === "current").words).toBe("waves");
497
+ expect(stripFromSteps([])).toBeNull();
498
+ // A run that applied in one go (no wait at all) still shows its waves stop.
499
+ expect(stripFromSteps(["pull-request", "planned", "merged", "applying", "applied", "reset"]).map((x) => x.id)).toEqual(STRIP.map((x) => x.id));
500
+ });
501
+ });