@intentius/behold 0.29.47 → 0.29.49

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.
@@ -113,6 +113,38 @@ describe("what the popover says about a root, in Components (behold#571)", () =>
113
113
  expect(rootPopover(answer(), "other", [{ kind: "terraform_data", id: "other/terraform_data.backup_schedule" }]).head).toBe(WORDS.noRootChange);
114
114
  expect(rootPopover(answer(), "other", []).head).toBe(WORDS.noResources);
115
115
  });
116
+
117
+ it("lists a create the plan holds but the checkout does not declare yet, first, as a create (behold#796)", () => {
118
+ const resources = [
119
+ { kind: "terraform_remote_state", id: "cluster-a/data.terraform_remote_state.network" },
120
+ { kind: "aws_dynamodb_table", id: "cluster-a/aws_dynamodb_table.jobs" },
121
+ ];
122
+ const a = answer({
123
+ roots: [{ member: "repo", name: "cluster-a", path: "cluster-a", plan: { changes: 1 } }],
124
+ pull_request: { roots: ["cluster-a"] },
125
+ unmatched: {
126
+ roots: [],
127
+ changes: [
128
+ { root: "cluster-a", address: "aws_sqs_queue.events", action: "create", verdict: "plan" },
129
+ { root: "cluster-a", address: "aws_sqs_queue.events", action: "create", verdict: "wave" },
130
+ { root: "cluster-a", address: "aws_s3_bucket.logs", action: "delete", verdict: "drift" },
131
+ { root: "cluster-b", address: "aws_sqs_queue.other", action: "create", verdict: "plan" },
132
+ ],
133
+ },
134
+ });
135
+ const p = rootPopover(a, "cluster-a", resources);
136
+ expect(p.head).toBe("1 of 3 resources change.");
137
+ expect(p.changed).toBe(1);
138
+ expect(p.rows).toEqual([
139
+ { address: "aws_sqs_queue.events", state: "change", words: "to create" },
140
+ { address: "data.terraform_remote_state.network", state: "same", words: "no change" },
141
+ { address: "aws_dynamodb_table.jobs", state: "same", words: "no change" },
142
+ ]);
143
+ // An answer from before behold#796 carries no action: it still counts as a change.
144
+ const old = rootPopover(answer({ roots: a.roots, unmatched: { roots: [], changes: [{ root: "cluster-a", address: 'aws_sqs_queue.q["a"]' }] } }), "cluster-a", []);
145
+ expect(old.rows).toEqual([{ address: "aws_sqs_queue.q", state: "change", words: "changes" }]);
146
+ expect(old.head).toBe("1 of 1 resource changes.");
147
+ });
116
148
  });
117
149
 
118
150
  describe("when the popover shows (behold#571)", () => {
@@ -0,0 +1,79 @@
1
+ // behold#787: on /kiosk a visitor replays a step already past, or the failure, and goes back to live.
2
+ import { describe, expect, it } from "vitest";
3
+ import { BACK_WORDS, FAILURE_WORDS, REPLAY_IDLE_MS, askedLine, drawResult, replayOver, viewerReplay } from "./kiosk.js";
4
+ import { REPLAY_LAST_HOLD_MS } from "./kiosk-vendor.js";
5
+
6
+ const fakeDocument = () => {
7
+ const make = (tag) => {
8
+ const n = { tagName: tag, className: "", textContent: "", children: [], dataset: {}, style: {}, hidden: false, attrs: {}, on: {} };
9
+ n.appendChild = (c) => (n.children.push(c), c);
10
+ n.append = (...cs) => cs.forEach((c) => n.children.push(c));
11
+ n.replaceChildren = () => (n.children = []);
12
+ n.setAttribute = (k, v) => (n.attrs[k] = v);
13
+ n.addEventListener = (ev, fn) => (n.on[ev] = fn);
14
+ return n;
15
+ };
16
+ return { createElement: make };
17
+ };
18
+ const withDocument = (fn) => {
19
+ const was = globalThis.document;
20
+ globalThis.document = fakeDocument();
21
+ try {
22
+ return fn();
23
+ } finally {
24
+ globalThis.document = was;
25
+ }
26
+ };
27
+
28
+ const steps = [
29
+ { at: "2026-10-19T20:05:36Z", step: "pull-request" },
30
+ { at: "2026-10-19T20:06:47Z", step: "applying" },
31
+ { at: "2026-10-19T20:08:30Z", step: "failed" },
32
+ { at: "2026-10-19T20:12:12Z", step: "applied" },
33
+ { at: "2026-10-19T20:14:09Z", step: "reset" },
34
+ ];
35
+
36
+ describe("a replay the viewer asked for (behold#787)", () => {
37
+ it("is the one the live poll leaves alone; a tool page's own replay is not", () => {
38
+ expect(viewerReplay({ mode: "replay", replay: { asked: true } })).toBe(true);
39
+ expect(viewerReplay({ mode: "replay", replay: { asked: false } })).toBe(false);
40
+ expect(viewerReplay({ mode: "live", replay: null })).toBe(false);
41
+ expect(viewerReplay(null)).toBe(false);
42
+ });
43
+
44
+ it("ends at the cycle's end, or after a while with no input", () => {
45
+ const toApplied = Date.parse(steps[3].at) - Date.parse(steps[0].at);
46
+ const toReset = Date.parse(steps[4].at) - Date.parse(steps[0].at);
47
+ expect(replayOver(steps, toApplied, 0)).toBe(false);
48
+ expect(replayOver(steps, toReset, 0)).toBe(true);
49
+ expect(replayOver(steps, toReset + REPLAY_LAST_HOLD_MS - 1, 0)).toBe(true);
50
+ expect(replayOver(steps, 0, REPLAY_IDLE_MS)).toBe(false);
51
+ expect(replayOver(steps, 0, REPLAY_IDLE_MS + 1)).toBe(true);
52
+ expect(replayOver([], 0, 0)).toBe(true);
53
+ });
54
+
55
+ it("says it is a replay, with a button back to live", () =>
56
+ withDocument(() => {
57
+ let back = 0;
58
+ const p = askedLine({ replay: { banner: "Replay of the run at 20:05 UTC" }, backToLive: () => back++ });
59
+ expect(p.className).toBe("k-replay k-replay-asked");
60
+ expect(p.children.map((c) => c.textContent)).toEqual(["Replay of the run at 20:05 UTC", BACK_WORDS]);
61
+ p.children[1].on.click();
62
+ expect(back).toBe(1);
63
+ }));
64
+
65
+ it("puts a Replay the failure chip on the done card when the cycle failed", () =>
66
+ withDocument(() => {
67
+ const host = document.createElement("aside");
68
+ const model = { head: "Applied", counts: ["3 waves applied"], waves: [] };
69
+ let seek = null;
70
+ drawResult(host, model, { waveTraces: {}, failureAt: () => "2026-10-19T20:08:00Z", seekTo: (at) => (seek = at) });
71
+ const chip = host.children.find((c) => c.className === "k-result-replay");
72
+ expect(chip.textContent).toBe(FAILURE_WORDS);
73
+ host.on.click({ target: { closest: (sel) => (sel === ".k-result-replay" ? chip : null) } });
74
+ expect(seek).toBe("2026-10-19T20:08:00Z");
75
+ // A cycle with no failure: no chip.
76
+ drawResult(host, model, { waveTraces: {}, failureAt: () => null });
77
+ expect(host.children.some((c) => c.className === "k-result-replay")).toBe(false);
78
+ }));
79
+ });
@@ -0,0 +1,36 @@
1
+ // behold#782: Watch's result card at the applied step, drawn with a DOM just big enough for it.
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ describe("kiosk: the result card says Applied once (behold#782)", () => {
5
+ const fakeDocument = () => {
6
+ const make = (tag) => {
7
+ const n = { tagName: tag, className: "", textContent: "", children: [], dataset: {}, style: {}, hidden: false };
8
+ n.appendChild = (c) => (n.children.push(c), c);
9
+ n.append = (...cs) => cs.forEach((c) => n.children.push(typeof c === "string" ? { tagName: "#text", textContent: c, children: [] } : c));
10
+ n.replaceChildren = () => (n.children = []);
11
+ n.addEventListener = () => {};
12
+ return n;
13
+ };
14
+ return { createElement: make };
15
+ };
16
+
17
+ it("leads with its first count and leaves the step's line to the caption", async () => {
18
+ const { drawResult } = await import("./kiosk.js");
19
+ const was = globalThis.document;
20
+ globalThis.document = fakeDocument();
21
+ try {
22
+ const host = document.createElement("aside");
23
+ const model = { head: "Applied", line: "All fifteen roots are in.", counts: ["3 waves applied", "1 created, 6 updated"], waves: [] };
24
+ drawResult(host, model, { waveTraces: {} });
25
+ expect(host.children.map((c) => [c.className, c.textContent || c.children.map((x) => x.textContent).join(" | ")])).toEqual([
26
+ ["k-result-head", "3 waves applied"],
27
+ ["k-result-counts", "1 created, 6 updated"],
28
+ ]);
29
+ // No count: the head says the step.
30
+ drawResult(host, { ...model, counts: [] }, { waveTraces: {} });
31
+ expect(host.children.map((c) => c.textContent)).toEqual(["Applied"]);
32
+ } finally {
33
+ globalThis.document = was;
34
+ }
35
+ });
36
+ });
package/web/kiosk-runs.js CHANGED
@@ -571,6 +571,18 @@ export function renderRun(host, answer, ui, { now = new Date(), pickJob = () =>
571
571
  }
572
572
  if (j.needs && j.needs.length) li.appendChild(el("span", "r-job-needs", `after ${j.needs.join(", ")}`));
573
573
  li.appendChild(el("span", "r-dur", j.status === "waiting" ? "held at the gate" : durationWords(j.started_at, j.ended_at, now) || STATUS_WORDS[j.status] || ""));
574
+ // behold#801: a job with a trace says so on its row, one click from it.
575
+ if (trace && trace.has(j.name)) {
576
+ const go = el("button", "r-job-trace", "Trace");
577
+ go.type = "button";
578
+ go.title = `${j.name}: open its trace`;
579
+ go.addEventListener("click", (e) => {
580
+ e.stopPropagation();
581
+ pickJob(j.name);
582
+ pickView("trace");
583
+ });
584
+ li.appendChild(go);
585
+ }
574
586
  li.addEventListener("click", () => pickJob(j.name));
575
587
  jobsBox.appendChild(li);
576
588
  }
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { storyGate, whatLine, whatParts, whatTool } from "./kiosk.js";
2
+ import { WHAT_TEXT, WHAT_TEXT_CHANT, introLine, storyGate, whatLine, whatParts, whatTextFor, whatTool } from "./kiosk.js";
3
3
 
4
4
  // behold#741: the #740 kiosk features (track, chapters, wedge, waiting modal,
5
5
  // pacing, wave blocks, applied earlier, one tip at a time, the title line)
@@ -42,3 +42,24 @@ describe("a terragucci story's title line (behold#741)", () => {
42
42
  expect(whatLine({ scenario: "fan-out" }, "forgejo")).toBe("chant's pull-request pipeline · on Forgejo · fan-out · live demo");
43
43
  });
44
44
  });
45
+
46
+ // behold#777: a phone names behold and whose pipeline it watches in one line under the title, and "What is this?" agrees.
47
+ describe("the phone's intro line and What is this? (behold#777)", () => {
48
+ it("names behold and terragucci for a terragucci repo, in the popover too", () => {
49
+ const line = introLine({ tg: true });
50
+ expect(line).toMatch(/^behold, a live view of infrastructure/);
51
+ expect(line).toMatch(/terragucci/);
52
+ const pop = whatTextFor({ tg: true });
53
+ expect(pop).toMatch(/^This is behold, a live view of infrastructure/);
54
+ expect(pop).toMatch(/terragucci/);
55
+ });
56
+ it("keeps chant's words for chant's pipeline, and the plain words elsewhere", () => {
57
+ expect(whatTextFor({ chant: true, tg: true })).toBe(WHAT_TEXT_CHANT);
58
+ expect(whatTextFor({})).toBe(WHAT_TEXT);
59
+ expect(introLine({ chant: true })).toMatch(/chant's pull-request pipeline/);
60
+ expect(introLine({})).toMatch(/^behold, a live view of infrastructure/);
61
+ });
62
+ it("says nothing on a tool's page, which may not name the others", () => {
63
+ expect(introLine({ tg: true, vendor: true })).toBeNull();
64
+ });
65
+ });
@@ -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" });