@intentius/behold 0.29.46 → 0.29.48

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.
@@ -4,9 +4,11 @@
4
4
  // each root's init, plan and apply, and OpenTofu's own spans under them.
5
5
  //
6
6
  // It shows what Tempo holds and nothing else: a job with no trace has no
7
- // Trace view. Deep levels start folded; a click on a row opens or folds it.
8
- // The spans that make up the job's critical path are lit, and so is a wait:
9
- // the gate, or a state lock.
7
+ // Trace view. Deep levels start folded, except the critical path and the way
8
+ // down to an error, which start open all the way to the binary's own spans
9
+ // (behold#788); a click on a row opens or folds it, and one control opens or
10
+ // folds them all. The spans that make up the job's critical path are lit, and
11
+ // so is a wait: the gate, or a state lock.
10
12
  //
11
13
  // Two ways in, both GET only:
12
14
  // - `traceSource({ fetchJson })`: the kiosk's job pane asks it, on every
@@ -17,7 +19,7 @@
17
19
 
18
20
  /** How often a run's traces are asked for again. The route shares one read of Tempo for 10 s. */
19
21
  export const TRACE_POLL_MS = 15_000;
20
- /** Rows deeper than this start folded: the stage, its phases and the roots show; the binary's spans wait for a click. */
22
+ /** Rows deeper than this start folded: the stage, its phases and the roots show. A row on the critical path, or over an error, starts open at any depth (behold#788). */
21
23
  export const OPEN_DEPTH = 3;
22
24
  /** Two spans closer than this, in ms, count as touching on the critical path. */
23
25
  const EPS = 0.5;
@@ -132,23 +134,37 @@ export function spanWords(s) {
132
134
  return { label: s.name, sub: "" };
133
135
  }
134
136
 
137
+ /** behold#788: the spans with an error somewhere under them: the way down to each error opens by default. */
138
+ export function overErrors(spans) {
139
+ const parent = new Map(spans.map((s) => [s.id, s.parent]));
140
+ const over = new Set();
141
+ for (const s of spans) {
142
+ if (!s.error) continue;
143
+ for (let p = parent.get(s.id); p && parent.has(p) && !over.has(p); p = parent.get(p)) over.add(p);
144
+ }
145
+ return over;
146
+ }
147
+
135
148
  /**
136
149
  * The rows a trace draws, top to bottom: each visible span with its depth,
137
150
  * its place on the job's time line (0..1), and whether it is on the critical
138
- * path, a wait or failed. `open` is the set of span ids a viewer opened past
139
- * OPEN_DEPTH, `shut` the ones they folded above it.
151
+ * path, a wait or failed. A row starts open (`byDefault`) above OPEN_DEPTH,
152
+ * on the critical path, or over an error; `open` is the set of span ids a
153
+ * viewer opened of the rest, `shut` the ones they folded of those.
140
154
  */
141
155
  export function waterfallRows(trace, { open = new Set(), shut = new Set() } = {}) {
142
156
  const spans = trace.spans || [];
143
157
  if (!spans.length) return [];
144
158
  const { kids, tops } = spanTree(spans);
145
159
  const crit = criticalPath(spans);
160
+ const errs = overErrors(spans);
146
161
  const t0 = Math.min(...spans.map((s) => s.start));
147
162
  const span = Math.max(1e-6, Math.max(...spans.map(end)) - t0);
148
163
  const rows = [];
149
164
  const visit = (s, depth) => {
150
165
  const children = kids.get(s.id) || [];
151
- const isOpen = children.length > 0 && (depth < OPEN_DEPTH ? !shut.has(s.id) : open.has(s.id));
166
+ const byDefault = children.length > 0 && (depth < OPEN_DEPTH || crit.has(s.id) || errs.has(s.id));
167
+ const isOpen = children.length > 0 && (byDefault ? !shut.has(s.id) : open.has(s.id));
152
168
  const words = spanWords(s);
153
169
  rows.push({
154
170
  id: s.id,
@@ -164,6 +180,7 @@ export function waterfallRows(trace, { open = new Set(), shut = new Set() } = {}
164
180
  error: s.error || null,
165
181
  kids: children.length,
166
182
  open: isOpen,
183
+ byDefault,
167
184
  });
168
185
  if (isOpen) for (const c of children) visit(c, depth + 1);
169
186
  };
@@ -228,11 +245,20 @@ const STYLE = `
228
245
  .t-sw.t-w { background: repeating-linear-gradient(135deg, var(--foreign) 0 4px, color-mix(in srgb, var(--foreign) 45%, transparent) 4px 8px); }
229
246
  .t-sw.t-b { background: color-mix(in srgb, var(--managed) 70%, transparent); }
230
247
  .t-note { color: var(--muted); padding: 0.3em 1em; font-size: 0.9em; }
248
+ .t-sec-row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6em; }
249
+ .t-all { font: 600 0.95em var(--font-ui); color: var(--pending); background: transparent; border: 1px solid var(--rule); border-radius: 999px; padding: 0.1em 0.8em; cursor: pointer; flex: none; }
250
+ .t-all:hover, .t-all:focus-visible { color: var(--fg); border-color: var(--pending); }
251
+ /* behold#788: on a phone a deep row steps in less, and no further than six levels, so the binary's spans keep the width to read; their names wrap. */
231
252
  @media (max-width: 600px) {
232
253
  .t-row { grid-template-columns: minmax(0, 1fr) 4.2em; grid-template-areas: "name ms" "track track"; row-gap: 0.15em; padding: 0.25em 0.8em; }
233
- .t-name { grid-area: name; }
254
+ .t-name { grid-area: name; padding-left: calc(min(var(--d, 0), 6) * 0.45em); }
255
+ .t-label { white-space: normal; overflow-wrap: anywhere; }
234
256
  .t-ms { grid-area: ms; }
235
- .t-track { grid-area: track; margin-left: calc(var(--d, 0) * 0.85em); }
257
+ .t-track { grid-area: track; margin-left: calc(min(var(--d, 0), 6) * 0.45em); }
258
+ }
259
+ /* behold#779: on a touch screen a row that opens and the Steps/Trace switch are at least 44px under the finger. */
260
+ @media (pointer: coarse) {
261
+ .t-row.t-can, .t-tab { min-height: 44px; }
236
262
  }
237
263
  `;
238
264
 
@@ -294,7 +320,11 @@ export function attemptWords(i, n, start) {
294
320
  return `Attempt ${i + 1} of ${n}, started at ${new Date(start).toISOString().slice(11, 16)} UTC`;
295
321
  }
296
322
 
297
- export function renderTrace(host, { traces, run = [], job }, { doc = document, toggle = () => {}, pickJob = null, open = new Set(), shut = new Set(), attempt = null, pickAttempt = null } = {}) {
323
+ /** behold#788: the words of the control that opens or folds every row. */
324
+ export const OPEN_ALL_WORDS = "Open all";
325
+ export const FOLD_ALL_WORDS = "Fold all";
326
+
327
+ export function renderTrace(host, { traces, run = [], job }, { doc = document, toggle = () => {}, pickJob = null, open = new Set(), shut = new Set(), attempt = null, pickAttempt = null, all = null } = {}) {
298
328
  traceStyle(doc);
299
329
  const box = el(doc, "div", "t-trace");
300
330
  const strip = runStrip(run);
@@ -316,6 +346,21 @@ export function renderTrace(host, { traces, run = [], job }, { doc = document, t
316
346
  // behold#571: asked about one attempt of several, it shows that one, with a switch to the others.
317
347
  const one = attempt !== null && attempt >= 0 && attempt < traces.length && traces.length > 1;
318
348
  const shown = one ? [traces[attempt]] : traces;
349
+ // behold#788: one control opens every row of the shown traces, or folds them all once every one is open.
350
+ const drawn = shown.map((t) => waterfallRows(t, { open, shut }));
351
+ const folding = drawn.flat().filter((r) => r.kids);
352
+ const allOpen = folding.length > 0 && folding.every((r) => r.open);
353
+ const allButton = () => {
354
+ const b = el(doc, "button", "t-all", allOpen ? FOLD_ALL_WORDS : OPEN_ALL_WORDS);
355
+ b.type = "button";
356
+ b.setAttribute("aria-label", allOpen ? "Fold every span" : "Open every span");
357
+ const ids = shown.flatMap((t) => {
358
+ const { kids } = spanTree(t.spans || []);
359
+ return [...kids.keys()];
360
+ });
361
+ b.addEventListener("click", () => all(ids, !allOpen));
362
+ return b;
363
+ };
319
364
  shown.forEach((t, k) => {
320
365
  const i = one ? attempt : k;
321
366
  const head = traces.length > 1 ? attemptWords(i, traces.length, t.start) : `This job · ${msWords(t.ms)}`;
@@ -335,9 +380,17 @@ export function renderTrace(host, { traces, run = [], job }, { doc = document, t
335
380
  });
336
381
  sec.appendChild(seg);
337
382
  box.appendChild(sec);
338
- } else box.appendChild(el(doc, "div", "t-sec", head));
383
+ if (all && folding.length) sec.appendChild(allButton());
384
+ } else {
385
+ const sec = el(doc, "div", "t-sec", head);
386
+ if (all && folding.length && k === 0) {
387
+ sec.classList.add("t-sec-row");
388
+ sec.replaceChildren(el(doc, "span", null, head), allButton());
389
+ }
390
+ box.appendChild(sec);
391
+ }
339
392
  const rows = el(doc, "div", "t-rows");
340
- for (const r of waterfallRows(t, { open, shut })) {
393
+ for (const r of drawn[k]) {
341
394
  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(" ");
342
395
  const row = el(doc, "div", cls);
343
396
  row.style.setProperty("--d", String(r.depth));
@@ -346,7 +399,7 @@ export function renderTrace(host, { traces, run = [], job }, { doc = document, t
346
399
  if (r.sub) name.appendChild(el(doc, "span", "t-sub", r.sub));
347
400
  row.title = [r.label, r.sub, msWords(r.ms), r.critical ? "on the critical path" : "", r.error ? `error: ${r.error}` : "", r.kids && !r.open ? `${r.kids} spans inside` : ""].filter(Boolean).join(" · ");
348
401
  row.append(name, bar(doc, r.at, r.width), el(doc, "div", "t-ms", msWords(r.ms)));
349
- if (r.kids) row.addEventListener("click", () => toggle(r.id, r.depth));
402
+ if (r.kids) row.addEventListener("click", () => toggle(r.id, r.byDefault));
350
403
  rows.appendChild(row);
351
404
  }
352
405
  box.appendChild(rows);
@@ -364,19 +417,29 @@ export function renderTrace(host, { traces, run = [], job }, { doc = document, t
364
417
  return box;
365
418
  }
366
419
 
367
- /** The viewer's folds: a click on a row opens it or folds it, whatever its depth. */
420
+ /**
421
+ * The viewer's folds: a click on a row opens it or folds it, whatever its
422
+ * depth. `byDefault` is whether the row starts open (waterfallRows says).
423
+ * behold#788: `all(ids, true)` opens every one of `ids`, `all(ids, false)`
424
+ * folds them all, and other jobs' folds stay; a click after either works as before.
425
+ */
368
426
  export function foldState() {
369
427
  const open = new Set();
370
428
  const shut = new Set();
371
429
  return {
372
430
  open,
373
431
  shut,
374
- toggle(id, depth) {
375
- if (depth < OPEN_DEPTH) {
376
- if (shut.has(id)) shut.delete(id);
377
- else shut.add(id);
378
- } else if (open.has(id)) open.delete(id);
379
- else open.add(id);
432
+ toggle(id, byDefault) {
433
+ const set = byDefault ? shut : open;
434
+ if (set.has(id)) set.delete(id);
435
+ else set.add(id);
436
+ },
437
+ all(ids, opened) {
438
+ for (const id of ids) {
439
+ open.delete(id);
440
+ shut.delete(id);
441
+ (opened ? open : shut).add(id);
442
+ }
380
443
  },
381
444
  };
382
445
  }
@@ -426,7 +489,7 @@ export function traceSource({ fetchJson, onChange = () => {}, now = () => Date.n
426
489
  traces: of,
427
490
  all: (repo, run) => (read(repo, run) || { traces: [] }).traces,
428
491
  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(); } });
492
+ 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, byDefault) => { folds.toggle(id, byDefault); onChange(); }, all: (ids, opened) => { folds.all(ids, opened); onChange(); } });
430
493
  },
431
494
  };
432
495
  }
@@ -69,7 +69,7 @@ describe("the waterfall", () => {
69
69
  expect([...early].sort()).toEqual(["p", "y"]);
70
70
  });
71
71
 
72
- it("shows the stage, its phases, the roots and their commands, and folds the binary's spans", () => {
72
+ it("shows the stage, its phases and the roots, and opens the critical path down to the binary's spans (behold#788)", () => {
73
73
  const rows = waterfallRows({ spans: SPANS });
74
74
  expect(rows.map((r) => `${" ".repeat(r.depth)}${r.label}`)).toEqual([
75
75
  "tf-apply, wave 1",
@@ -77,30 +77,76 @@ describe("the waterfall", () => {
77
77
  " root a",
78
78
  " root b",
79
79
  " tofu plan",
80
+ " OpenTofu",
81
+ " terraform_data.release",
80
82
  " gate",
81
83
  " apply",
82
84
  " root a",
83
85
  " root b",
84
86
  ]);
85
87
  const cmd = rows.find((r) => r.label === "tofu plan");
86
- expect(cmd).toMatchObject({ depth: OPEN_DEPTH, kids: 1, open: false, critical: true });
88
+ expect(cmd).toMatchObject({ depth: OPEN_DEPTH, kids: 1, open: true, byDefault: true, critical: true });
87
89
  const gate = rows.find((r) => r.label === "gate");
88
90
  expect(gate).toMatchObject({ wait: true, critical: true, sub: "approved after 40 s held", at: 0.4, width: 0.4 });
89
91
  expect(rows[0]).toMatchObject({ at: 0, width: 1, sub: "applied" });
90
92
  });
91
93
 
92
- it("opens a folded row on a click and folds an open one", () => {
94
+ // behold#788: a root that planned beside the slow one, with its own command under it.
95
+ const SIDE = [
96
+ ...SPANS,
97
+ sp("pa", "ra", "tofu plan", 120, 290),
98
+ sp("oa", "pa", "tofu", 130, 280, {}, "OpenTofu CLI"),
99
+ sp("ria", "oa", "Plan resource instance changes", 140, 200, { "opentofu.resource_instance.address": "aws_sqs_queue.a" }, "OpenTofu CLI"),
100
+ ];
101
+
102
+ it("keeps a branch off the critical path folded below the roots, and opens the way down to an error (behold#788)", () => {
103
+ let rows = waterfallRows({ spans: SIDE });
104
+ expect(rows.find((r) => r.id === "pa")).toMatchObject({ depth: OPEN_DEPTH, open: false, byDefault: false, critical: false });
105
+ expect(rows.some((r) => r.id === "oa")).toBe(false);
106
+ // The resource failed: every span over it opens, on the critical path or off it.
107
+ rows = waterfallRows({ spans: SIDE.map((s) => (s.id === "ria" ? { ...s, error: "QueueAlreadyExists" } : s)) });
108
+ expect(rows.find((r) => r.id === "pa")).toMatchObject({ open: true, byDefault: true });
109
+ expect(rows.find((r) => r.id === "ria")).toMatchObject({ label: "aws_sqs_queue.a", error: "QueueAlreadyExists", depth: 5 });
110
+ });
111
+
112
+ it("opens a folded row on a click and folds an open one, at any depth", () => {
93
113
  const folds = foldState();
94
- folds.toggle("pb", OPEN_DEPTH);
95
- folds.toggle("ob", OPEN_DEPTH + 1);
96
- let rows = waterfallRows({ spans: SPANS }, folds);
97
- expect(rows.find((r) => r.label === "OpenTofu")).toMatchObject({ depth: 4, service: "OpenTofu CLI", open: true });
98
- expect(rows.find((r) => r.label === "terraform_data.release")).toMatchObject({ sub: "plan", depth: 5 });
99
- folds.toggle("p", 1);
100
- rows = waterfallRows({ spans: SPANS }, folds);
114
+ folds.toggle("pa", false);
115
+ let rows = waterfallRows({ spans: SIDE }, folds);
116
+ expect(rows.find((r) => r.id === "oa")).toMatchObject({ depth: 4, service: "OpenTofu CLI", open: false, byDefault: false });
117
+ folds.toggle("oa", false);
118
+ rows = waterfallRows({ spans: SIDE }, folds);
119
+ expect(rows.find((r) => r.label === "aws_sqs_queue.a")).toMatchObject({ sub: "plan", depth: 5 });
120
+ // A row on the critical path folds on a click, and opens again on the next.
121
+ folds.toggle("ob", true);
122
+ rows = waterfallRows({ spans: SIDE }, folds);
123
+ expect(rows.find((r) => r.id === "ob")).toMatchObject({ open: false });
124
+ expect(rows.some((r) => r.id === "rib")).toBe(false);
125
+ folds.toggle("ob", true);
126
+ expect(waterfallRows({ spans: SIDE }, folds).some((r) => r.id === "rib")).toBe(true);
127
+ folds.toggle("p", true);
128
+ rows = waterfallRows({ spans: SIDE }, folds);
101
129
  expect(rows.some((r) => r.label === "root a" && r.depth === 2 && r.at < 0.5)).toBe(false);
102
130
  });
103
131
 
132
+ it("opens every row, or folds them all, with one control, and a click after works as before (behold#788)", () => {
133
+ const folds = foldState();
134
+ const ids = [...new Set(SIDE.filter((s) => s.parent).map((s) => s.parent))];
135
+ folds.all(ids, true);
136
+ let rows = waterfallRows({ spans: SIDE }, folds);
137
+ expect(rows).toHaveLength(SIDE.length);
138
+ expect(rows.filter((r) => r.kids).every((r) => r.open)).toBe(true);
139
+ folds.all(ids, false);
140
+ rows = waterfallRows({ spans: SIDE }, folds);
141
+ expect(rows.map((r) => r.id)).toEqual(["s"]);
142
+ folds.toggle("s", rows[0].byDefault);
143
+ expect(waterfallRows({ spans: SIDE }, folds).map((r) => r.label)).toEqual(["tf-apply, wave 1", "plan", "gate", "apply"]);
144
+ // Another job's folds stay as they were.
145
+ folds.toggle("other-job-span", false);
146
+ folds.all(ids, true);
147
+ expect(folds.open.has("other-job-span")).toBe(true);
148
+ });
149
+
104
150
  it("names OpenTofu's spans by what they act on", () => {
105
151
  expect(spanWords(sp("x", null, "Apply resource instance changes", 0, 1, { "opentofu.resource_instance.address": "terraform_data.x" }, "OpenTofu CLI"))).toEqual({ label: "terraform_data.x", sub: "apply" });
106
152
  expect(spanWords(sp("x", null, "Configure provider", 0, 1, { "opentofu.provider.source": "registry.opentofu.org/hashicorp/aws" }, "OpenTofu CLI"))).toEqual({ label: "Configure provider", sub: "hashicorp/aws" });
@@ -32,6 +32,30 @@ export const MIN_SHARE = 0.045;
32
32
  /** How long nothing must change before the "Waiting on…" modal shows. */
33
33
  export const WAITING_AFTER_MS = 3_000;
34
34
 
35
+ /** A job that has started, as the run's own document says it. */
36
+ const STARTED = new Set(["running", "waiting", "success", "failure"]);
37
+
38
+ /**
39
+ * behold#774: the apply jobs of this step's run that have started, from the
40
+ * run's own document (the forge's jobs): `[{ job, wave, status }]`. The run
41
+ * view moves a wave only once its job reports, a minute or two into a long
42
+ * apply, so "Waiting on the pipeline to start the apply" stayed up while
43
+ * apply-wave-3 ran. A job starting is the first sign the apply is under way.
44
+ * Empty for another commit's run (the change's, while the fix's merge starts).
45
+ */
46
+ export function applyJobs(runDoc, demo) {
47
+ if (!runDoc || !Array.isArray(runDoc.jobs) || !demo) return [];
48
+ const c = typeof runDoc.commit === "string" ? runDoc.commit : "";
49
+ const d = typeof demo.commit === "string" ? demo.commit : "";
50
+ if (!c || !d || !(c.startsWith(d) || d.startsWith(c))) return [];
51
+ return runDoc.jobs
52
+ .filter((j) => j && typeof j.name === "string" && /^apply/.test(j.name) && STARTED.has(j.status))
53
+ .map((j) => {
54
+ const m = /^apply-wave-(\d+)$/.exec(j.name);
55
+ return { job: j.name, wave: m ? Number(m[1]) : null, status: j.status };
56
+ });
57
+ }
58
+
35
59
  const ms = (a, b) => Math.max(0, Date.parse(b) - Date.parse(a));
36
60
  const secs = (n) => Math.max(1, Math.round(n / 1000));
37
61
 
@@ -102,9 +126,10 @@ export function chapterTitle(index, pull) {
102
126
  * The track as it stands now. `demo` is demo.json; `pulls` the pull requests
103
127
  * this cycle has opened, in order; `since` when the current segment began
104
128
  * (ms); `waves` the apply's waves as the paced graph shows them
105
- * ([{ wave, state }]), for the applying segment's ticks.
129
+ * ([{ wave, state }]), for the applying segment's ticks; `jobs` the apply
130
+ * jobs of this step's run that have started ({@link applyJobs}).
106
131
  */
107
- export function trackModel(track, { demo, pulls = [], since = null, now = Date.now(), waves = null } = {}) {
132
+ export function trackModel(track, { demo, pulls = [], since = null, now = Date.now(), waves = null, jobs = [] } = {}) {
108
133
  if (!track || !demo) return null;
109
134
  // Where the cycle is: the step's own story chapter when told in them; else the chapter of the current pull request
110
135
  // (the reset, the last). Then the segment holding the step.
@@ -137,8 +162,19 @@ export function trackModel(track, { demo, pulls = [], since = null, now = Date.n
137
162
  };
138
163
  }),
139
164
  }));
140
- const nowLine = nowWords({ demo, segment: current, expected, elapsed, overrun, waves, now, fix: track.byStory ? pulls.indexOf(demo.pull) > 0 : at.chapter > 0 });
141
- return { chapters, at, elapsed, expected, overrun, now: nowLine };
165
+ const nowLine = nowWords({ demo, segment: current, expected, elapsed, overrun, waves, jobs, now, fix: track.byStory ? pulls.indexOf(demo.pull) > 0 : at.chapter > 0 });
166
+ return { chapters, at, elapsed, expected, overrun, now: nowLine, here: hereWords(chapters, at) };
167
+ }
168
+
169
+ /**
170
+ * behold#778: the current step by name, "Step: applying, in 3 The fix", for a
171
+ * phone, whose segments are too narrow for their labels. Null when the cycle
172
+ * stands at no segment.
173
+ */
174
+ export function hereWords(chapters, at) {
175
+ const c = chapters && at ? chapters[at.chapter] : null;
176
+ const g = c && at.segment >= 0 ? c.segments[at.segment] : null;
177
+ return g ? `Step: ${g.label}, in ${c.title}` : null;
142
178
  }
143
179
 
144
180
  const typical = (expected, overrun) => (overrun ? "taking longer than usual…" : expected > 0 ? `usually about ${secs(expected)} s` : null);
@@ -148,7 +184,7 @@ const countdown = (demo, now) => {
148
184
  };
149
185
 
150
186
  /** What is happening now and what is waited on, in plain words: `{ text, waiting, why, expected, elapsed, overrun }`. */
151
- export function nowWords({ demo, segment, expected = 0, elapsed = 0, overrun = false, waves = null, now = Date.now(), fix = false } = {}) {
187
+ export function nowWords({ demo, segment, expected = 0, elapsed = 0, overrun = false, waves = null, jobs = [], now = Date.now(), fix = false } = {}) {
152
188
  if (!demo || !segment) return null;
153
189
  const why = firstSentence(demo.label);
154
190
  const base = { why, expected, elapsed, overrun };
@@ -156,6 +192,12 @@ export function nowWords({ demo, segment, expected = 0, elapsed = 0, overrun = f
156
192
  const running = Array.isArray(waves) ? waves.filter((w) => w.state === "running").map((w) => w.wave) : [];
157
193
  const wavesSeen = Array.isArray(waves) && waves.some((w) => w.state && w.state !== "waiting");
158
194
  const say = (text, waiting = null, timed = true) => ({ ...base, text: timed && typical(expected, overrun) ? `${text} · ${typical(expected, overrun)}` : text, waiting });
195
+ // behold#774: an apply job the run view has not caught up with yet: nothing waits on the pipeline any more.
196
+ const started = () => {
197
+ const ws = (jobs || []).filter((j) => j.status === "running" && Number.isInteger(j.wave)).map((j) => j.wave);
198
+ if (ws.length) return say(`Wave ${ws.join(" and ")} is applying`, null, false);
199
+ return (jobs || []).length ? say("The apply is under way", null, false) : null;
200
+ };
159
201
  switch (segment.label) {
160
202
  case "opened":
161
203
  case "fix opened":
@@ -165,11 +207,11 @@ export function nowWords({ demo, segment, expected = 0, elapsed = 0, overrun = f
165
207
  case "review":
166
208
  return say("Waiting for the reviewer", "the reviewer to approve the plan");
167
209
  case "merged":
168
- return say("The pipeline is starting the apply job", "the pipeline to start the apply");
210
+ return started() || say("The pipeline is starting the apply job", "the pipeline to start the apply");
169
211
  case "applying":
170
212
  if (running.length) return say(`Wave ${running.join(" and ")} is applying`, null, false);
171
213
  if (wavesSeen) return say("The apply is under way", null, false);
172
- return say("The pipeline is starting the apply job", "the pipeline to start the apply");
214
+ return started() || say("The pipeline is starting the apply job", "the pipeline to start the apply");
173
215
  case "failed":
174
216
  return { ...base, text: left !== null && left > 0 ? `The fix opens in ${left} s` : "The fix opens next", waiting: "the fix to open" };
175
217
  case "done":
@@ -240,10 +282,17 @@ body.k-watch #k-track { position: fixed; z-index: 7; left: 5px; right: 5px; }
240
282
  #k-track .kt-seg.kt-current .kt-fill::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, color-mix(in srgb, white 28%, transparent), transparent); background-size: 50% 100%; background-repeat: no-repeat; animation: kt-sheen 2.4s ease-in-out infinite; }
241
283
  @keyframes kt-sheen { from { background-position: -60% 0; } to { background-position: 160% 0; } }
242
284
  }
285
+ #k-track .kt-here { display: none; }
286
+ /* behold#778: a phone's segments are too narrow for their labels, so a line names the current step, and the chapters wrap to a new line instead of running off the right edge. */
243
287
  @media (max-width: 600px) {
244
288
  body.k-watch #k-track { position: static; }
289
+ #k-track { font-size: 1em; padding: 0.35em 16px 0.4em; }
290
+ #k-track .kt-row { flex-wrap: wrap; row-gap: 0.4em; }
291
+ #k-track .kt-chapter-title { font-size: 0.88em; }
245
292
  #k-track .kt-segs .kt-label { display: none; }
246
- #k-track .kt-seg { height: 0.8em; }
293
+ #k-track .kt-seg { height: 0.8em; min-width: 0.6em !important; }
294
+ #k-track .kt-here { display: block; margin: 0; color: var(--pending); font-size: 0.92em; }
295
+ #k-track .kt-now { font-size: 0.92em; white-space: normal; }
247
296
  }
248
297
  `;
249
298
 
@@ -304,6 +353,7 @@ export function drawTrack(host, model, doc = typeof document !== "undefined" ? d
304
353
  row.appendChild(ch);
305
354
  }
306
355
  host.appendChild(row);
356
+ if (model.here) host.appendChild(el("p", "kt-here", model.here));
307
357
  if (model.now && model.now.text) host.appendChild(el("p", "kt-now", model.now.text));
308
358
  // A label its segment cannot hold whole says its short form ("plan", "merge"); never a clipped word.
309
359
  for (const lab of host.querySelectorAll ? host.querySelectorAll(".kt-label") : []) {
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { FILL_CAP, cycleTrack, trackModel, waitingSpec } from "./kiosk-track.js";
2
+ import { FILL_CAP, applyJobs, cycleTrack, hereWords, trackModel, waitingSpec } from "./kiosk-track.js";
3
3
 
4
4
  // behold#631: chant-fanout's last finished cycle as cycles/chant-fanout/latest.json had it (cycle 499):
5
5
  // fifteen steps, two pull requests, from the change's open to the reset.
@@ -112,6 +112,12 @@ describe("the track in the story's four chapters (behold#631)", () => {
112
112
  const m = trackModel(track, { demo: { step: "applying", pull: 13, chapter: chapters[2] }, pulls: [12, 13], since: now - 2_000, now });
113
113
  expect(m.chapters.map((c) => [c.title, c.state])).toEqual([["1 The change goes out", "done"], ["2 cluster-a breaks", "done"], ["3 The fix", "current"], ["4 Done", "ahead"]]);
114
114
  expect(m.chapters[2].segments[4]).toMatchObject({ label: "applying", state: "current" });
115
+ // behold#778: and names the step in words, for a phone whose segments are too narrow for their labels.
116
+ expect(m.here).toBe("Step: applying, in 3 The fix");
117
+ });
118
+ it("names no step when the cycle stands at none (behold#778)", () => {
119
+ expect(hereWords([{ title: "1 The change", segments: [{ label: "opened" }] }], { chapter: 0, segment: -1 })).toBeNull();
120
+ expect(hereWords([{ title: "1 The change", segments: [{ label: "opened" }] }], { chapter: 0, segment: 0 })).toBe("Step: opened, in 1 The change");
115
121
  });
116
122
  it("names a chapter from its headline when the driver gives no short name", () => {
117
123
  const plain = cycleTrack({ ...cycle, steps: told.steps.map((s) => ({ ...s, chapter: { n: s.chapter.n, of: 4, headline: s.chapter.headline } })) });
@@ -146,3 +152,42 @@ describe("the Waiting on… modal (behold#631)", () => {
146
152
  expect(waitingSpec(at({ step: "planned", pull: 12 }, 1_000), { quietMs: 5_000 })).toBeNull();
147
153
  });
148
154
  });
155
+
156
+ // behold#774: on demo.intentius.io "Waiting on the pipeline to start the apply" stayed up about 2 minutes while
157
+ // apply-wave-3 ran: the run view moves a wave only once its job reports. The run's own jobs say it first.
158
+ describe("the apply's jobs end the wait (behold#774)", () => {
159
+ const track = cycleTrack(cycle);
160
+ const now = Date.parse(T("40:00"));
161
+ const C = "c27888c42a093b72166e924a339cf6f01a739547";
162
+ const doc = (jobs, commit = C) => ({ commit, jobs: jobs.map(([name, status]) => ({ name, status })) });
163
+ const run = doc([["check", "success"], ["plan", "skipped"], ["apply-comment", "skipped"], ["apply-wave-1", "success"], ["apply-wave-2", "success"], ["apply-wave-3", "running"], ["tips", "queued"]]);
164
+ it("reads the started apply jobs of this step's commit, by wave", () => {
165
+ expect(applyJobs(run, { commit: C })).toEqual([
166
+ { job: "apply-wave-1", wave: 1, status: "success" },
167
+ { job: "apply-wave-2", wave: 2, status: "success" },
168
+ { job: "apply-wave-3", wave: 3, status: "running" },
169
+ ]);
170
+ // A short commit either way matches.
171
+ expect(applyJobs(run, { commit: C.slice(0, 8) })).toHaveLength(3);
172
+ expect(applyJobs(doc([["apply-wave-1", "running"]], C.slice(0, 8)), { commit: C })).toHaveLength(1);
173
+ });
174
+ it("is empty for another commit's run, a queued job, or no run", () => {
175
+ expect(applyJobs(run, { commit: "298a730c2764cbbcc29b75360d12e8e5d03a8406" })).toEqual([]);
176
+ expect(applyJobs(doc([["apply-wave-1", "queued"]]), { commit: C })).toEqual([]);
177
+ expect(applyJobs(run, { commit: null })).toEqual([]);
178
+ expect(applyJobs(null, { commit: C })).toEqual([]);
179
+ expect(applyJobs({ commit: C }, { commit: C })).toEqual([]);
180
+ });
181
+ it("says which wave is applying, and opens no Waiting modal, once a job runs", () => {
182
+ const at = (step, jobs) => trackModel(track, { demo: { step, pull: 12, commit: C }, pulls: [12], since: now - 1_000, now, jobs });
183
+ const m = at("applying", applyJobs(run, { commit: C }));
184
+ expect(m.now).toMatchObject({ text: "Wave 3 is applying", waiting: null });
185
+ expect(waitingSpec(m, { quietMs: 60_000 })).toBeNull();
186
+ // The merged step, its first job already started.
187
+ expect(at("merged", [{ job: "apply-wave-1", wave: 1, status: "running" }]).now.text).toBe("Wave 1 is applying");
188
+ // Jobs that started and finished, none running now: under way.
189
+ expect(at("applying", [{ job: "apply-wave-1", wave: 1, status: "success" }]).now).toMatchObject({ text: "The apply is under way", waiting: null });
190
+ // No job yet: the wait stands.
191
+ expect(waitingSpec(at("applying", []), { quietMs: 5_000 }).what).toBe("the pipeline to start the apply");
192
+ });
193
+ });
@@ -235,8 +235,10 @@ export function badges(metrics) {
235
235
  export function doraLine(metrics) {
236
236
  const rows = metrics && metrics.dora;
237
237
  if (!rows || !rows.length) return null;
238
+ // behold#786: the deploy rate says the span it counts ("last 24 hours"), since the numbers are recounted each cycle.
239
+ const span = metrics.window ? ` (${metrics.window})` : "";
238
240
  const say = {
239
- Deploys: (v) => `${roundedWeek(v)} deploys a week`,
241
+ Deploys: (v) => `${roundedWeek(v)} deploys a week${span}`,
240
242
  "Lead time": (v) => `lead time ${v}`,
241
243
  "Change failure rate": (v) => `change failure rate ${v}`,
242
244
  "Time to restore": (v) => `time to restore ${v}`,
@@ -127,6 +127,8 @@ describe("kiosk watch: the numbers", () => {
127
127
  it("says the delivery numbers on one line, a large rate rounded", () => {
128
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
129
  expect(doraLine({ dora: [["Deploys", "4.5 a week"]] })).toBe("4.5 deploys a week");
130
+ // behold#786: with the span it counts.
131
+ expect(doraLine({ dora: [["Deploys", "1526 a week"], ["Lead time", "1 min 21 s"]], window: "last 24 hours" })).toBe("1,526 deploys a week (last 24 hours) · lead time 1 min 21 s");
130
132
  expect(doraLine({ dora: null })).toBeNull();
131
133
  });
132
134
 
@@ -0,0 +1,130 @@
1
+ // behold#776: a phone's Watch as a list. On a 390 px screen the components
2
+ // graph shrinks until its card labels are about 5 px, so Watch reads as
3
+ // coloured boxes. Under the graph a phone gets the same marks as words: each
4
+ // wave, how it stands, and each of its roots with its state; a tap on a root
5
+ // opens what its card's popover says (its resources and which of them change).
6
+ //
7
+ // The frame owns the marks (web/terragucci-components-live.js componentMarks,
8
+ // web/chant-pr-marks.js chantComponentMarks) and posts them as `behold:marks`
9
+ // in the form waveListOf makes; the kiosk draws them with drawWaveList.
10
+ //
11
+ // Pure apart from drawWaveList, which builds DOM from a list.
12
+
13
+ const TONES = new Set(["ok", "bad", "wait", "busy", "idle"]);
14
+ const toneOf = (t) => (TONES.has(t) ? t : "idle");
15
+ const words = (x) => (typeof x === "string" ? x.trim() : "");
16
+
17
+ /**
18
+ * The list from a draw's marks: `{ waves: [{ wave, words, tone, roots: [{ root, component, words, tone, facts, detail? }] }] }`,
19
+ * the waves in the order they apply (wave 1 first), each wave's roots by name.
20
+ * `details` maps a component to its popover's content (kiosk-popover.js rootPopover), when the frame has one.
21
+ * Null when the marks carry no cards.
22
+ */
23
+ export function waveListOf(marks, details = {}) {
24
+ const cards = marks && marks.cards && typeof marks.cards === "object" ? marks.cards : null;
25
+ if (!cards || !Object.keys(cards).length) return null;
26
+ const waveMarks = marks.waves && typeof marks.waves === "object" ? marks.waves : {};
27
+ const byWave = new Map();
28
+ for (const [component, c] of Object.entries(cards)) {
29
+ if (!c || typeof c.root !== "string") continue;
30
+ const n = Number.isInteger(c.wave) ? c.wave : null;
31
+ if (!byWave.has(n)) byWave.set(n, []);
32
+ const d = details && details[component];
33
+ byWave.get(n).push({
34
+ root: c.root,
35
+ component,
36
+ words: words(c.words) || words(c.short) || words(c.state),
37
+ tone: toneOf(c.tone),
38
+ facts: Array.isArray(c.facts) ? c.facts.filter((f) => typeof f === "string" && f) : [],
39
+ ...(d && typeof d.head === "string" ? { detail: { head: d.head, rows: (d.rows || []).map((r) => ({ address: r.address, state: r.state, words: r.words })), more: d.more || 0 } } : {}),
40
+ });
41
+ }
42
+ const waves = [...byWave.keys()]
43
+ .sort((a, b) => (a === null ? 1 : b === null ? -1 : a - b))
44
+ .map((n) => {
45
+ const w = n !== null ? waveMarks[n] : null;
46
+ const said = w ? words(w.status && w.status.words) || words(w.state) : "";
47
+ return { wave: n, words: said, tone: toneOf(w ? w.tone : "idle"), roots: byWave.get(n).sort((a, b) => a.root.localeCompare(b.root)) };
48
+ });
49
+ return { waves };
50
+ }
51
+
52
+ /** A list's identity, so the frame posts it and the kiosk redraws it only when it changes. */
53
+ export function waveListKey(list) {
54
+ return JSON.stringify(list || null);
55
+ }
56
+
57
+ /** A wave's heading: "Wave 2 · failed", "Wave 2" before any state, "Other roots" for roots in no wave. */
58
+ export function waveHead(w) {
59
+ const name = w.wave === null ? "Other roots" : `Wave ${w.wave}`;
60
+ return w.words ? `${name} · ${w.words}` : name;
61
+ }
62
+
63
+ /** What the list says it is, over its waves. */
64
+ export const LIST_WORDS = { title: "The waves", hint: "Tap a root for its resources." };
65
+
66
+ /**
67
+ * Draw the list into `host`. `open` is the set of roots whose details are
68
+ * shown; `onToggle(root)` is called on a tap. `paint(doc, root)` returns the
69
+ * node for a root's name (its colour dot), or null for the plain name.
70
+ */
71
+ export function drawWaveList(host, list, { doc = typeof document !== "undefined" ? document : null, open = new Set(), onToggle = () => {}, paint = null } = {}) {
72
+ if (!host || !doc) return;
73
+ const el = (tag, cls, text) => {
74
+ const n = doc.createElement(tag);
75
+ if (cls) n.className = cls;
76
+ if (text !== undefined && text !== null) n.textContent = text;
77
+ return n;
78
+ };
79
+ host.replaceChildren();
80
+ host.hidden = !list || !list.waves.length;
81
+ if (host.hidden) return;
82
+ const head = el("div", "k-wl-head");
83
+ head.append(el("h2", "k-wl-title", LIST_WORDS.title), el("span", "k-wl-hint", LIST_WORDS.hint));
84
+ host.appendChild(head);
85
+ for (const w of list.waves) {
86
+ const sec = el("section", "k-wl-wave");
87
+ sec.dataset.kTone = w.tone;
88
+ if (w.wave !== null) sec.dataset.kWave = String(w.wave);
89
+ sec.appendChild(el("h3", `k-wl-wave-head k-wl-${w.tone}`, waveHead(w)));
90
+ const ul = el("ul", "k-wl-roots");
91
+ for (const r of w.roots) {
92
+ const shown = open.has(r.root);
93
+ const li = el("li", `k-wl-root${shown ? " k-wl-open" : ""}`);
94
+ li.dataset.kTone = r.tone;
95
+ li.dataset.kRoot = r.root;
96
+ const b = el("button", "k-wl-row");
97
+ b.type = "button";
98
+ b.setAttribute("aria-expanded", String(shown));
99
+ const name = (paint && paint(doc, r.root)) || el("span", "k-wl-name", r.root);
100
+ if (name.classList) name.classList.add("k-wl-name");
101
+ b.append(name, el("span", `k-wl-state k-wl-${r.tone}`, r.words));
102
+ b.addEventListener("click", () => onToggle(r.root));
103
+ li.appendChild(b);
104
+ if (shown) li.appendChild(rootDetail(el, r));
105
+ ul.appendChild(li);
106
+ }
107
+ sec.appendChild(ul);
108
+ host.appendChild(sec);
109
+ }
110
+ }
111
+
112
+ /** A root's details under its row: its card's facts, then its resources as its popover lists them. */
113
+ function rootDetail(el, r) {
114
+ const box = el("div", "k-wl-detail");
115
+ for (const f of r.facts) box.appendChild(el("p", "k-wl-fact", f));
116
+ if (r.detail) {
117
+ box.appendChild(el("p", "k-wl-res-head", r.detail.head));
118
+ if (r.detail.rows.length) {
119
+ const ul = el("ul", "k-wl-res");
120
+ for (const x of r.detail.rows) {
121
+ const li = el("li", null, `${x.address} `);
122
+ li.appendChild(el("span", `k-wl-res-${x.state}`, x.words));
123
+ ul.appendChild(li);
124
+ }
125
+ if (r.detail.more > 0) ul.appendChild(el("li", "k-wl-res-more", `and ${r.detail.more} more`));
126
+ box.appendChild(ul);
127
+ }
128
+ } else if (!r.facts.length) box.appendChild(el("p", "k-wl-fact", "Its resources show once the plan's report is read."));
129
+ return box;
130
+ }