@intentius/behold 0.29.43 → 0.29.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +77 -0
- package/dist/cli.js +4065 -1918
- package/package.json +1 -1
- package/web/app.js +1469 -74
- package/web/carve-narration.js +33 -1
- package/web/chant-live-pace.js +138 -0
- package/web/chant-live-pace.test.js +116 -0
- package/web/chant-pr-marks.js +417 -39
- package/web/chant-pr-marks.test.js +208 -4
- package/web/collision-marks.js +124 -0
- package/web/collision-marks.test.js +89 -0
- package/web/cone.js +269 -0
- package/web/cone.test.js +213 -0
- package/web/dots-live.test.js +151 -1
- package/web/dots-lod.js +20 -0
- package/web/dots-lod.test.js +19 -1
- package/web/dots-scene.js +110 -10
- package/web/dots.js +144 -31
- package/web/embed.js +1 -1
- package/web/event-help-modal.js +98 -3
- package/web/event-help-modal.test.js +85 -1
- package/web/feature-flags.js +143 -0
- package/web/feature-flags.test.js +96 -0
- package/web/index.html +33 -0
- package/web/kiosk-carve.js +59 -6
- package/web/kiosk-demo-frame.test.js +27 -0
- package/web/kiosk-event-help-ui.js +186 -20
- package/web/kiosk-event-help.js +175 -15
- package/web/kiosk-event-help.test.js +58 -1
- package/web/kiosk-highlight.test.js +249 -0
- package/web/kiosk-metrics.js +4 -3
- package/web/kiosk-runs.js +8 -5
- package/web/kiosk-shot.js +157 -3
- package/web/kiosk-shot.test.js +223 -1
- package/web/kiosk-source.js +43 -0
- package/web/kiosk-source.test.js +39 -0
- package/web/kiosk-story-gate.test.js +44 -0
- package/web/kiosk-track.js +312 -0
- package/web/kiosk-track.test.js +148 -0
- package/web/kiosk-unknown-step.test.js +58 -0
- package/web/kiosk-vendor.js +73 -4
- package/web/kiosk-vendor.test.js +103 -3
- package/web/kiosk-watch.js +154 -1
- package/web/kiosk-watch.test.js +53 -1
- package/web/kiosk.html +57 -22
- package/web/kiosk.js +583 -53
- package/web/kiosk.test.js +2 -1
- package/web/small-stage.test.js +150 -0
- package/web/terragucci-blocked.test.js +192 -0
- package/web/terragucci-change.js +197 -17
- package/web/terragucci-components-live.js +189 -13
- package/web/terragucci-live-pace.js +92 -0
- package/web/terragucci-wave-results.test.js +125 -0
- package/web/terralith.html +7 -7
- package/web/tg-outside.js +124 -0
- package/web/tg-outside.test.js +100 -0
- package/web/tg-read-pills.js +145 -0
- package/web/tg-read-pills.test.js +158 -0
- package/web/theme.js +13 -1
- package/web/theme.test.js +21 -1
- package/web/tooltip.js +19 -7
- package/web/tooltip.test.js +15 -0
- package/web/tours/terralith.json +4 -4
- package/web/trunk-lane.test.js +1 -1
- package/web/view-url.js +8 -2
- package/web/why.js +129 -1
- package/web/why.test.js +113 -1
package/web/kiosk-event-help.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { STRIP, matchingPull, matchingRun } from "./kiosk.js";
|
|
16
16
|
import { defaultStep } from "./kiosk-runs.js";
|
|
17
17
|
import { traceReadyWords } from "./kiosk-wave-traces.js";
|
|
18
|
+
import { resultBlocked, resultFailed, resultWords, waveResultOf } from "./terragucci-change.js";
|
|
18
19
|
|
|
19
20
|
export { EH_STORE, ehStore, ehStored } from "./event-help-store.js";
|
|
20
21
|
|
|
@@ -63,20 +64,35 @@ const jobLines = (job) => (job && Array.isArray(job.steps) ? job.steps.flatMap((
|
|
|
63
64
|
* `waves` is the declared waves (`{ job, wave, roots }`), so a job names its
|
|
64
65
|
* wave and a wave its roots.
|
|
65
66
|
*/
|
|
66
|
-
export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc = null, runDocs = [], approval = null, metrics = null, waveTraces = {}, waves = [], failed = [], strip = null } = {}) {
|
|
67
|
+
export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc = null, runDocs = [], approval = null, metrics = null, waveTraces = {}, waves = [], failed = [], strip = null, chant = false } = {}) {
|
|
67
68
|
if (!demo) return null;
|
|
68
69
|
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
70
|
const run = matchingRun(progress, demo);
|
|
70
71
|
const jobs = runDoc && Array.isArray(runDoc.jobs) && (!demo.cycle || runDoc.cycle === undefined || runDoc.cycle === demo.cycle) ? runDoc.jobs : [];
|
|
72
|
+
// behold#751: a wave's result by its own report, of the commit the run applied: its job's status is no witness to it,
|
|
73
|
+
// since terragucci fails the job of a wave that applied what it planned and blocked the rest (terragucci#1161).
|
|
74
|
+
const resultOf = (commit, name, started) => {
|
|
75
|
+
const n = waveOfJob(name, waves);
|
|
76
|
+
return n === null ? null : waveResultOf(answer, commit, n, { after: started || null });
|
|
77
|
+
};
|
|
78
|
+
// The cycle's earlier runs' wave jobs that ended as failures, each with its report's word on the wave when there is one.
|
|
79
|
+
const pastJobs = (runDocs || [])
|
|
80
|
+
.filter((d) => d && d.id !== (runDoc && runDoc.id) && (!demo.cycle || d.cycle === undefined || d.cycle === demo.cycle) && Array.isArray(d.jobs))
|
|
81
|
+
.flatMap((d) => d.jobs.filter((j) => j.status === "failure" && waveOfJob(j.name, waves) !== null).map((j) => ({ wave: waveOfJob(j.name, waves), job: j.name, run: d.id, refusal: yodelRefusal(jobLines(j)), result: resultOf(d.commit, j.name, j.started_at) })));
|
|
71
82
|
return {
|
|
72
83
|
cycle: demo.cycle,
|
|
84
|
+
// behold#631: a chant repo's pull-request loop: a cycle may hold a fix's pull request after the first, each told as its own run of beats.
|
|
85
|
+
chant: !!chant,
|
|
86
|
+
// A scenario told in beats (the terralith: stock, adopt, split, team, cross) runs each beat's steps in one cycle.
|
|
87
|
+
beat: demo.beat || null,
|
|
73
88
|
step: demo.step,
|
|
74
89
|
pull: demo.pull,
|
|
75
90
|
label: demo.label || "",
|
|
76
91
|
plan: pr ? { totals: pr.totals || null, roots: pr.roots || [], reads: pr.reads || [] } : null,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
// behold#751: each wave with its report's result, of the run view's commit.
|
|
93
|
+
states: run ? (progress.states || []).map((s) => ({ ...s, result: waveResultOf(answer, run.commit, s.number) })) : [],
|
|
94
|
+
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, result: resultOf(runDoc.commit, j.name, j.started_at) })) } : null,
|
|
95
|
+
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 || "")) })), ...(Array.isArray(approval.chantWaves) ? { chantWaves: approval.chantWaves } : {}) } : null,
|
|
80
96
|
// The numbers of this cycle's merge only: from the merge on, and only for its commit.
|
|
81
97
|
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
98
|
// Each wave's trace, once Tempo has it (web/kiosk-wave-traces.js): `{ wave, run, job, words }`.
|
|
@@ -87,9 +103,9 @@ export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc
|
|
|
87
103
|
// The waves this cycle saw fail, kept by the kiosk: a re-run is news only against a failure seen before it.
|
|
88
104
|
failed: [...new Set(failed)],
|
|
89
105
|
// The cycle's earlier runs' failures (the approval panel reads them): a viewer who arrives after the re-run still gets the refusal.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
// behold#751: a failed job whose wave's report says it applied and blocked roots is no failure of the wave: it is `pastBlocked`.
|
|
107
|
+
pastFailures: pastJobs.filter((f) => !f.result || resultFailed(f.result)).map(({ result, ...f }) => f),
|
|
108
|
+
pastBlocked: pastJobs.filter((f) => f.result && !resultFailed(f.result) && resultBlocked(f.result)),
|
|
93
109
|
};
|
|
94
110
|
}
|
|
95
111
|
|
|
@@ -120,6 +136,12 @@ const stepRank = (step, strip = STRIP) => (strip || STRIP).findIndex((s) => s.st
|
|
|
120
136
|
* landing pops a tip but is not a beat of the story); `critical` is a wave
|
|
121
137
|
* held for an approval, a wave that failed, and the cycle applied.
|
|
122
138
|
*/
|
|
139
|
+
/** The story a snapshot belongs to: its cycle, and its beat when the scenario is told in beats. */
|
|
140
|
+
export function storyKey(snap) {
|
|
141
|
+
if (!snap) return null;
|
|
142
|
+
return snap.beat ? `${snap.cycle}:${snap.beat}` : snap.cycle;
|
|
143
|
+
}
|
|
144
|
+
|
|
123
145
|
export function cycleFacts(snap) {
|
|
124
146
|
if (!snap) return [];
|
|
125
147
|
const out = [];
|
|
@@ -127,19 +149,24 @@ export function cycleFacts(snap) {
|
|
|
127
149
|
const strip = snap.strip || STRIP;
|
|
128
150
|
const at = stepRank(snap.step, strip);
|
|
129
151
|
const rank = (step) => stepRank(step, strip);
|
|
130
|
-
|
|
152
|
+
// Each beat of a cycle is a story of its own: the adopt beat's "applied" is not the split's.
|
|
153
|
+
// A chant cycle's second pull request (the fix) is its own run of beats: its ids and its place follow the pull request.
|
|
154
|
+
const c = snap.chant && snap.pull !== null && snap.pull !== undefined ? `${storyKey(snap)}|pr${snap.pull}` : storyKey(snap);
|
|
131
155
|
const runId = snap.run ? snap.run.id : null;
|
|
132
156
|
// The pull request and its plan.
|
|
133
157
|
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 : [] } });
|
|
134
158
|
if (snap.plan && snap.plan.totals && at >= rank("planned")) {
|
|
135
159
|
add({ id: `${c}|plan`, kind: "planned", text: planWords(snap.plan.totals), order: 1, subjects: { roots: snap.plan.roots } });
|
|
136
160
|
}
|
|
137
|
-
|
|
161
|
+
// chant's gate comes before its merge: there the merge is said only once its step is reached.
|
|
162
|
+
const merged = snap.chant ? ["merged", "applying", "failed", "resumed", "applied"].includes(snap.step) : at >= rank("merged");
|
|
163
|
+
if (merged && snap.pull !== null && snap.pull !== undefined) add({ id: `${c}|merged`, kind: "merged", text: `pull request #${snap.pull} merged`, order: 2 });
|
|
138
164
|
// Each wave, from the run view; a wave's job, from the pipeline's run.
|
|
139
165
|
const jobOf = (n) => (snap.run ? snap.run.jobs.find((j) => j.wave === n) : null);
|
|
140
166
|
const approved = snap.approval ? snap.approval.rows.find((r) => r.id === "approved") : null;
|
|
141
167
|
const states = [...snap.states].sort((a, b) => a.number - b.number);
|
|
142
|
-
|
|
168
|
+
// behold#751: a wave an earlier run left roots of blocked runs again, as a failed one does.
|
|
169
|
+
const failedBefore = new Set([...(snap.failed || []), ...(snap.pastFailures || []).map((f) => f.wave), ...(snap.pastBlocked || []).map((f) => f.wave)]);
|
|
143
170
|
for (const s of states) {
|
|
144
171
|
const n = s.number;
|
|
145
172
|
const roots = rootsOfWave(n, snap.waves, states);
|
|
@@ -148,7 +175,9 @@ export function cycleFacts(snap) {
|
|
|
148
175
|
const base = 10 + n * 10;
|
|
149
176
|
if (["applying", "waiting", "applied", "failed", "refused"].includes(s.state)) add({ id: `${c}|w${n}|start`, kind: "started", text: `wave ${n} started`, order: base, subjects, trail: false });
|
|
150
177
|
// A failure the run view no longer shows (the re-run moved on) is still the pipeline's run's.
|
|
151
|
-
|
|
178
|
+
// behold#751: unless the wave's report says otherwise: a wave that applied what it planned and blocked the rest ends its
|
|
179
|
+
// job as a failure (terragucci#1161), and is no failed wave. The job's status speaks only where no report of the wave does.
|
|
180
|
+
const failedJob = job && job.status === "failure" && !(job.result && !resultFailed(job.result)) ? job : null;
|
|
152
181
|
const past = (snap.pastFailures || []).find((f) => f.wave === n);
|
|
153
182
|
if (s.state === "failed" || s.state === "refused" || failedJob || past) {
|
|
154
183
|
failedBefore.add(n);
|
|
@@ -167,7 +196,16 @@ export function cycleFacts(snap) {
|
|
|
167
196
|
}
|
|
168
197
|
}
|
|
169
198
|
if (failedBefore.has(n) && (s.state === "applying" || s.state === "applied") && !failedJob) add({ id: `${c}|w${n}|rerun`, kind: "rerun", text: `wave ${n} runs again`, order: base + 6, subjects });
|
|
170
|
-
|
|
199
|
+
// behold#751: what the wave's report says it held back, once the run view settles it, or an earlier run of the cycle did:
|
|
200
|
+
// "wave 3 applied 6, 6 blocked by cluster-a", "wave 3: 6 blocked by cluster-a" for one that ran nothing.
|
|
201
|
+
const nowHeld = ["applied", "blocked"].includes(s.state) ? [s.result, job && job.result].find((r) => r && !resultFailed(r) && resultBlocked(r)) : null;
|
|
202
|
+
const pastHeld = (snap.pastBlocked || []).find((f) => f.wave === n);
|
|
203
|
+
const held = nowHeld || (pastHeld && pastHeld.result);
|
|
204
|
+
if (held) {
|
|
205
|
+
const words = resultWords(held);
|
|
206
|
+
add({ id: `${c}|w${n}|blocked`, kind: "blocked", text: held.state === "applied" ? `wave ${n} ${words}` : `wave ${n}: ${words}`, order: base + 7, subjects: pastHeld && !(job && job.status === "failure") ? { ...subjects, job: pastHeld.job, run: pastHeld.run } : subjects });
|
|
207
|
+
}
|
|
208
|
+
if (s.state === "applied" && !nowHeld) {
|
|
171
209
|
const changed = changedWords(s.totals);
|
|
172
210
|
const under = approved && snap.approval.wave === n && approved.actor ? ` under ${approved.actor}'s approval` : "";
|
|
173
211
|
add({ id: `${c}|w${n}|applied`, kind: "applied-wave", text: `wave ${n} applied${under || (changed ? `: ${changed}` : "")}`, order: base + 7, subjects });
|
|
@@ -186,7 +224,35 @@ export function cycleFacts(snap) {
|
|
|
186
224
|
if (snap.approval && !Number.isInteger(snap.approval.wave)) {
|
|
187
225
|
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
226
|
const ok = snap.approval.rows.find((r) => r.id === "approved");
|
|
189
|
-
|
|
227
|
+
// A chant kiosk names the reviewer alone: "forgejo@forgejo:3000:demo-reviewer, signed" is a principal, not a person.
|
|
228
|
+
if (ok) add({ id: `${c}|approved`, kind: "approved", text: snap.chant ? (ok.actor ? `approved by ${ok.actor.replace(/^.*:/, "")}` : "approved") : ok.actor ? `approved by ${ok.actor}${ok.signed ? ", signed" : ""}` : "approved, signed", order: 9.5 });
|
|
229
|
+
}
|
|
230
|
+
// behold#631: chant's pull-request apply, wave by wave from its run events: started, failed with the reason, applied, and what it left blocked.
|
|
231
|
+
for (const w of snap.approval && Array.isArray(snap.approval.chantWaves) ? snap.approval.chantWaves : []) {
|
|
232
|
+
const n = w.wave;
|
|
233
|
+
const base = 10 + n * 10;
|
|
234
|
+
const subjects = { roots: w.components || [], wave: n, run: runId };
|
|
235
|
+
if (["running", "applied", "failed"].includes(w.state)) add({ id: `${c}|w${n}|start`, kind: "started", text: `wave ${n} started`, order: base, subjects, trail: false });
|
|
236
|
+
// The cards of this wave and the next: what a failure's modal must leave in view (the half that went ahead too).
|
|
237
|
+
const next = snap.approval.chantWaves.find((x) => x.wave === n + 1);
|
|
238
|
+
const inView = [...(w.components || []), ...(next ? next.components || [] : [])];
|
|
239
|
+
for (const f of w.failed || []) {
|
|
240
|
+
// The step's label says why in words ("cluster-a failed: SQS refuses …"); CloudFormation's own words stay in the tooltip.
|
|
241
|
+
const said = typeof snap.label === "string" && snap.label.startsWith(`${f.component} failed:`) ? snap.label.split(/\.\s/)[0].replace(/\.$/, "") : null;
|
|
242
|
+
// The raw error rides along for a tooltip; the roots are the failed card and what it blocked.
|
|
243
|
+
add({ id: `${c}|w${n}|failed|${f.component}`, kind: "failed", text: said || `${f.component} failed`, order: base + 1, subjects: { ...subjects, roots: [f.component, ...(f.blocks || [])] }, critical: true, chant: true, avoid: [...new Set([f.component, ...(f.blocks || []), ...inView])], ...(f.error ? { raw: `${f.component} failed: ${f.error}` } : {}) });
|
|
244
|
+
}
|
|
245
|
+
if (w.state === "applied" || (w.state === "failed" && w.applied)) {
|
|
246
|
+
// A wave with a failure says both halves, by name when there are few: "wave 2: cluster-b applied, cluster-a failed".
|
|
247
|
+
const failedNames = (w.failed || []).map((f) => f.component);
|
|
248
|
+
const appliedNames = w.appliedNames || [];
|
|
249
|
+
const both = appliedNames.length && appliedNames.length <= 2 && failedNames.length <= 2 ? `wave ${n}: ${list(appliedNames)} applied, ${list(failedNames)} failed` : `wave ${n}: ${w.applied} applied, ${failedNames.length} failed`;
|
|
250
|
+
add({ id: `${c}|w${n}|applied`, kind: "applied-wave", text: w.state === "failed" ? both : w.blocked ? `wave ${n} applied ${w.applied}; ${w.blocked} blocked` : `wave ${n} applied`, order: base + 7, subjects });
|
|
251
|
+
}
|
|
252
|
+
if (w.blocked) {
|
|
253
|
+
const by = w.blockedBy && w.blockedBy.length ? ` by ${list(w.blockedBy)}` : "";
|
|
254
|
+
add({ id: `${c}|w${n}|blocked`, kind: "blocked", text: `${w.blocked} in wave ${n} blocked${by}: they did not run`, order: base + 8, subjects });
|
|
255
|
+
}
|
|
190
256
|
}
|
|
191
257
|
// A gate on the whole change (chant's pull-request loop): the plan waits, no wave named.
|
|
192
258
|
// A repo with declared waves names its held wave once the run view has it; this is for a repo without them.
|
|
@@ -203,9 +269,14 @@ export function cycleFacts(snap) {
|
|
|
203
269
|
const i = strip.findIndex((x) => x.id === id);
|
|
204
270
|
return i >= 0 ? i : strip.findIndex((x) => x.id === "waves");
|
|
205
271
|
};
|
|
206
|
-
|
|
272
|
+
// chant's gate comes before the merge: without its own stop it sits with the plan, not after the merge.
|
|
273
|
+
const gateStop = strip.some((x) => x.id === "approval") ? "approval" : snap.chant ? "planned" : "waves";
|
|
207
274
|
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
|
-
|
|
275
|
+
// A chant cycle's pull requests in turn: each one's beats after the one before's, whatever their stops.
|
|
276
|
+
const segment = snap.chant && Number.isInteger(snap.pull) ? snap.pull * 100_000 : 0;
|
|
277
|
+
return [...byId.values()]
|
|
278
|
+
.map((f) => ({ ...f, stop: stopOf(f), order: segment + Math.max(0, stopIndex(stopOf(f))) * 1000 + f.order, ...(snap.chant ? { pull: snap.pull } : {}) }))
|
|
279
|
+
.sort((a, b) => a.order - b.order);
|
|
209
280
|
}
|
|
210
281
|
|
|
211
282
|
/** The story trail: the cycle's facts that are beats of its story. */
|
|
@@ -240,6 +311,22 @@ export function tipsQueue(state, { add = [], now = 0, max = TIPS_AT_ONCE, ms = T
|
|
|
240
311
|
return { shown, waiting };
|
|
241
312
|
}
|
|
242
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Whether the caption already says what a critical modal would, so the modal
|
|
316
|
+
* stays shut: on a held small stage in Watch (`held`) nothing overlays the
|
|
317
|
+
* graph (web/kiosk-watch.js watchOverlays), and the caption says each step
|
|
318
|
+
* (the applied counts, a held wave's approval, a failure's label). Any other
|
|
319
|
+
* stage, and Inspect, open them as they always have.
|
|
320
|
+
*/
|
|
321
|
+
export function modalShownElsewhere(event, { watch = false, held = false } = {}) {
|
|
322
|
+
return !!watch && !!held && !!event;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Whether Tips' bubbles show: everywhere but a held small stage in Watch, where nothing overlays the graph; the trail over the caption stays. */
|
|
326
|
+
export function tipsShown({ watch = false, held = false } = {}) {
|
|
327
|
+
return !(watch && held);
|
|
328
|
+
}
|
|
329
|
+
|
|
243
330
|
/**
|
|
244
331
|
* The critical modals' queue: one at a time, never while a viewer is at the
|
|
245
332
|
* page (a pointer or a key within `quietMs`), and only the newest of each
|
|
@@ -253,3 +340,76 @@ export function modalQueue(state, { add = [], now = 0, lastInput = -Infinity, qu
|
|
|
253
340
|
if (open || !queue.length || now - lastInput < quietMs) return { next: null, waiting: queue };
|
|
254
341
|
return { next: queue[0], waiting: queue.slice(1) };
|
|
255
342
|
}
|
|
343
|
+
|
|
344
|
+
// ---------------------------------------------------------------------------
|
|
345
|
+
// behold#757: a step's highlight. The scenario's driver says what is special
|
|
346
|
+
// about a step (demo.json's or demo-step/v1's `highlight: { title, body }`,
|
|
347
|
+
// terragucci#1176, chant#4106) on the step where it happens; Watch opens it as
|
|
348
|
+
// a modal once per cycle, step and title. The driver writes a step more than
|
|
349
|
+
// once (an apply, its holds) with the same highlight, which opens once; a step
|
|
350
|
+
// can gain one partway through (choudoufu's operator, on one write of the
|
|
351
|
+
// applying step), which opens when it first appears; and a replay that loops
|
|
352
|
+
// round to its step opens it again.
|
|
353
|
+
|
|
354
|
+
/** How long a highlight stays up, longer than a tip: it is a paragraph to read. It goes sooner when its step does. */
|
|
355
|
+
export const HIGHLIGHT_MS = 12_000;
|
|
356
|
+
|
|
357
|
+
/** A demo step's highlight, `{ title, body }`, or null unless both are non-empty strings (the server's floor, again). */
|
|
358
|
+
export function stepHighlight(demo) {
|
|
359
|
+
const h = demo && demo.highlight;
|
|
360
|
+
if (!h || typeof h !== "object" || Array.isArray(h)) return null;
|
|
361
|
+
const title = typeof h.title === "string" ? h.title.trim() : "";
|
|
362
|
+
const body = typeof h.body === "string" ? h.body.trim() : "";
|
|
363
|
+
return title && body ? { title, body } : null;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** The step a highlight's modal stays with: its cycle, beat, pull request and step. It closes when the step moves on. */
|
|
367
|
+
export function highlightStepKey(demo) {
|
|
368
|
+
if (!demo) return null;
|
|
369
|
+
return [demo.cycle, demo.beat || "", demo.pull === null || demo.pull === undefined ? "" : demo.pull, demo.step].join("|");
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** What a highlight opens once for: its cycle (and beat), its step and its title (terragucci#1176). */
|
|
373
|
+
export const highlightId = (demo, h) => [demo.cycle, demo.beat || "", demo.step, h.title].join("|");
|
|
374
|
+
|
|
375
|
+
/** When a step was written: a replay's step its `at`, a live one its `started_at`. A time that goes back is a replay looping round. */
|
|
376
|
+
const writtenAt = (demo) => {
|
|
377
|
+
const t = Date.parse((demo && (demo.at || demo.started_at)) || "");
|
|
378
|
+
return Number.isFinite(t) ? t : null;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* The highlight's state after a look at `demo`: `{ step, seen, at, pending }`.
|
|
383
|
+
* `pending` is the step's highlight while it has not opened (`{ id, key,
|
|
384
|
+
* title, body }`), to open once nothing stops it; `seen` the ids opened this
|
|
385
|
+
* pass of the cycle, so a highlight written again is not opened again. A step
|
|
386
|
+
* that goes takes a pending highlight with it; a replay looping round (its
|
|
387
|
+
* step's time going back) starts a new pass.
|
|
388
|
+
*/
|
|
389
|
+
export function highlightTurn(state, demo) {
|
|
390
|
+
const at = writtenAt(demo);
|
|
391
|
+
const looped = !!state && state.at !== null && at !== null && at < state.at;
|
|
392
|
+
const seen = !state || looped ? new Set() : state.seen;
|
|
393
|
+
const step = highlightStepKey(demo);
|
|
394
|
+
const h = stepHighlight(demo);
|
|
395
|
+
const id = h ? highlightId(demo, h) : null;
|
|
396
|
+
const kept = state && !looped && state.pending && state.pending.id === id && state.step === step ? state.pending : null;
|
|
397
|
+
const pending = h && !seen.has(id) ? kept || { id, key: step, ...h } : null;
|
|
398
|
+
if (state && !looped && state.step === step && state.pending === pending && state.at === at) return state;
|
|
399
|
+
return { step, seen, at, pending };
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** The state once its pending highlight has opened: seen for the rest of the pass. */
|
|
403
|
+
export function highlightShown(state) {
|
|
404
|
+
if (!state || !state.pending) return state;
|
|
405
|
+
return { ...state, seen: new Set([...state.seen, state.pending.id]), pending: null };
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Whether a pending highlight opens now: Tips on, in Watch, not on a held
|
|
410
|
+
* small stage (nothing overlays the graph there), and no modal up but a
|
|
411
|
+
* "Waiting on…" one, which it replaces. A critical modal up keeps it waiting.
|
|
412
|
+
*/
|
|
413
|
+
export function highlightOpens({ pending = null, on = true, watch = false, held = false, modal = null } = {}) {
|
|
414
|
+
return !!pending && !!on && !!watch && !held && (!modal || modal === "waiting");
|
|
415
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// the queues that keep tips and modals calm.
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
5
|
import { stripFromSteps } from "./kiosk.js";
|
|
6
|
-
import { EH_STORE, cycleFacts, ehSnapshot, ehStore, ehStored, modalQueue, newEvents, storyTrail, tipsQueue, yodelRefusal } from "./kiosk-event-help.js";
|
|
6
|
+
import { EH_STORE, cycleFacts, ehSnapshot, ehStore, ehStored, modalQueue, newEvents, storyKey, storyTrail, tipsQueue, yodelRefusal } from "./kiosk-event-help.js";
|
|
7
7
|
|
|
8
8
|
const C = "9f3c2a71d04e5b8c6a1f2e3d4c5b6a7980716253";
|
|
9
9
|
const P = "1111111111111111111111111111111111111111";
|
|
@@ -80,6 +80,48 @@ describe("event-help: a cycle told in order", () => {
|
|
|
80
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
81
|
});
|
|
82
82
|
|
|
83
|
+
it("tells a chant cycle's pull requests in turn: the gate before the merge, the reviewer by name, the fix's beats after the first's (#631)", () => {
|
|
84
|
+
// The strip as the kiosk had it: no approval stop of its own.
|
|
85
|
+
const approval = { wave: null, rows: [{ id: "approved", state: "lit", text: "forgejo@forgejo:3000:demo-reviewer approved this exact digest.", seal: { ok: null, text: "signed" } }] };
|
|
86
|
+
const chant = (step, pull) => cycleFacts(ehSnapshot({ demo: { ...demo(step), pull, scenario: "fan-out", tool: "chant" }, answer: null, approval, chant: true }));
|
|
87
|
+
const first = chant("merged", 7);
|
|
88
|
+
expect(storyTrail(first).map((f) => f.text)).toEqual(["pull request #7 opened", "the plan waits for an approval", "approved by demo-reviewer", "pull request #7 merged"]);
|
|
89
|
+
// The fix's gate waits before its merge: no merge chip for it yet.
|
|
90
|
+
expect(chant("waiting", 8).some((f) => f.kind === "merged")).toBe(false);
|
|
91
|
+
const fix = chant("planned", 8);
|
|
92
|
+
expect(fix.find((f) => f.kind === "pull-request")).toMatchObject({ id: "7|pr8|pr", text: "pull request #8 opened", pull: 8 });
|
|
93
|
+
// Every beat of the fix sorts after every beat of the first.
|
|
94
|
+
expect(Math.min(...fix.map((f) => f.order))).toBeGreaterThan(Math.max(...first.map((f) => f.order)));
|
|
95
|
+
// A terragucci cycle keeps its ids and words.
|
|
96
|
+
expect(cycleFacts(ehSnapshot({ demo: demo("merged"), answer, approval })).find((f) => f.kind === "approved").text).toBe("approved by forgejo@forgejo:3000:demo-reviewer, signed");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("tells chant's apply wave by wave from its run events: the failure with its reason, and what it left blocked (#631)", () => {
|
|
100
|
+
const strip = stripFromSteps(["pull-request", "planned", "waiting", "approved", "merged", "applying", "failed", "applied", "reset"]);
|
|
101
|
+
const chantWaves = [
|
|
102
|
+
{ wave: 1, state: "applied", components: ["network"], applied: 1, failed: [], blocked: 0, blockedBy: [] },
|
|
103
|
+
{ wave: 2, state: "failed", components: ["cluster-a", "cluster-b"], applied: 1, failed: [{ component: "cluster-a", reason: "The name of a FIFO queue can only end with '.fifo'" }], blocked: 0, blockedBy: [] },
|
|
104
|
+
{ wave: 3, state: "applied", components: ["app-01", "app-07"], applied: 6, failed: [], blocked: 6, blockedBy: ["cluster-a"] },
|
|
105
|
+
];
|
|
106
|
+
const approval = { wave: null, rows: [{ id: "approved", state: "lit", text: "demo-reviewer approved this exact digest.", seal: { ok: null, text: "signed" } }], chantWaves };
|
|
107
|
+
const f = cycleFacts(ehSnapshot({ demo: { ...demo("failed"), scenario: "fan-out", tool: "chant" }, answer: null, approval, strip }));
|
|
108
|
+
// The step's label does not give the reason here, so the chip says the failure alone; CloudFormation's words never reach it.
|
|
109
|
+
expect(f.find((x) => x.kind === "failed")).toMatchObject({ text: "cluster-a failed", critical: true, chant: true, subjects: { wave: 2, roots: ["cluster-a"] } });
|
|
110
|
+
// A modal for it must leave wave 2 and wave 3 in view.
|
|
111
|
+
expect(f.find((x) => x.kind === "failed").avoid).toEqual(["cluster-a", "cluster-b", "app-01", "app-07"]);
|
|
112
|
+
expect(f.find((x) => x.id === "7|w3|applied")).toMatchObject({ kind: "applied-wave", text: "wave 3 applied 6; 6 blocked" });
|
|
113
|
+
expect(f.find((x) => x.kind === "blocked")).toMatchObject({ text: "6 in wave 3 blocked by cluster-a: they did not run", subjects: { wave: 3 } });
|
|
114
|
+
// A wave with a failure says both halves; by name when the wave says them.
|
|
115
|
+
expect(f.find((x) => x.id === "7|w2|applied")).toMatchObject({ text: "wave 2: 1 applied, 1 failed" });
|
|
116
|
+
const named = cycleFacts(ehSnapshot({ demo: { ...demo("failed"), scenario: "fan-out", tool: "chant" }, answer: null, approval: { ...approval, chantWaves: chantWaves.map((w) => (w.wave === 2 ? { ...w, appliedNames: ["cluster-b"] } : w)) }, strip }));
|
|
117
|
+
expect(named.find((x) => x.id === "7|w2|applied").text).toBe("wave 2: cluster-b applied, cluster-a failed");
|
|
118
|
+
// With the step's label giving the reason, the chip says it in the label's words.
|
|
119
|
+
const said = cycleFacts(ehSnapshot({ demo: { ...demo("failed"), label: "cluster-a failed: SQS refuses a FIFO queue whose name lacks .fifo. Its six apps are held." }, answer: null, approval, strip }));
|
|
120
|
+
expect(said.find((x) => x.kind === "failed").text).toBe("cluster-a failed: SQS refuses a FIFO queue whose name lacks .fifo");
|
|
121
|
+
// A terragucci repo's approval carries no chant waves, so none of these.
|
|
122
|
+
expect(cycleFacts(ehSnapshot({ demo: demo("failed"), answer, waves })).some((x) => x.kind === "blocked")).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
83
125
|
it("names each event's subjects, so the kiosk can place it", () => {
|
|
84
126
|
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: [] }] } });
|
|
85
127
|
expect(held.find((f) => f.kind === "held")).toMatchObject({ critical: true, subjects: { roots: ["app"], wave: 2, job: "apply-wave-2", run: 4801 } });
|
|
@@ -160,3 +202,18 @@ describe("event-help: calm queues", () => {
|
|
|
160
202
|
expect(modalQueue({ waiting: [held] }, { now: 30_000, open: true }).next).toBeNull();
|
|
161
203
|
});
|
|
162
204
|
});
|
|
205
|
+
|
|
206
|
+
describe("a cycle told in beats", () => {
|
|
207
|
+
it("keeps each beat's story apart, so one beat's applied is never another's", () => {
|
|
208
|
+
const adopt = cycleFacts(ehSnapshot({ demo: demo("applied", { beat: "adopt" }) }));
|
|
209
|
+
const split = cycleFacts(ehSnapshot({ demo: demo("merged", { beat: "split" }) }));
|
|
210
|
+
const ids = new Set(adopt.map((f) => f.id));
|
|
211
|
+
expect(adopt.find((f) => f.kind === "applied").id).toBe("7:adopt|applied");
|
|
212
|
+
expect(split.some((f) => ids.has(f.id))).toBe(false);
|
|
213
|
+
expect(split.some((f) => f.kind === "applied")).toBe(false);
|
|
214
|
+
expect(storyKey({ cycle: 7, beat: "split" })).not.toBe(storyKey({ cycle: 7, beat: "adopt" }));
|
|
215
|
+
// A scenario with no beats keeps the cycle as its story, as before.
|
|
216
|
+
expect(storyKey({ cycle: 7, beat: null })).toBe(7);
|
|
217
|
+
expect(cycleFacts(ehSnapshot({ demo: demo("applied") })).find((f) => f.kind === "applied").id).toBe("7|applied");
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// behold#757: a step's highlight, what is special about it in the driver's
|
|
2
|
+
// words, opened in Watch as a modal when its step arrives: once per arrival,
|
|
3
|
+
// at the same moment in a replay, never with Tips off, and nothing at all for
|
|
4
|
+
// a step without one.
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { HIGHLIGHT_KICKER, modeLine, openEventModal } from "./event-help-modal.js";
|
|
7
|
+
import { HIGHLIGHT_MS, ehStore, highlightOpens, highlightShown, highlightStepKey, highlightTurn, stepHighlight } from "./kiosk-event-help.js";
|
|
8
|
+
import { startEventHelp } from "./kiosk-event-help-ui.js";
|
|
9
|
+
import { replayAt, scrubDemo } from "./kiosk-vendor.js";
|
|
10
|
+
|
|
11
|
+
const HL = { title: "Same orchestration as the commercial platforms", body: "Fifteen OpenTofu states, applied in dependency order. This is the stack-dependency orchestration Terraform automation platforms sell, run here by terragucci on plain OpenTofu and Forgejo." };
|
|
12
|
+
const demo = (step, more = {}) => ({ cycle: 9, scenario: "fan-out", title: "t", step, label: `the ${step} line`, started_at: "2026-10-18T00:00:00Z", next: null, pull: 3, commit: null, ...more });
|
|
13
|
+
|
|
14
|
+
describe("highlight: the floor", () => {
|
|
15
|
+
it("is a title and a body, both non-empty strings, else nothing", () => {
|
|
16
|
+
expect(stepHighlight(demo("failed", { highlight: HL }))).toEqual(HL);
|
|
17
|
+
for (const v of [null, undefined, "x", [], {}, { title: "t" }, { title: "", body: "b" }, { title: "t", body: " " }, { title: 2, body: "b" }]) expect(stepHighlight(demo("failed", { highlight: v }))).toBeNull();
|
|
18
|
+
expect(stepHighlight(null)).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("highlight: once per cycle, step and title (terragucci#1176)", () => {
|
|
23
|
+
it("comes with its step, once, and goes with it", () => {
|
|
24
|
+
let s = highlightTurn(null, demo("applying"));
|
|
25
|
+
expect(s.pending).toBeNull();
|
|
26
|
+
s = highlightTurn(s, demo("failed", { highlight: HL }));
|
|
27
|
+
expect(s.pending).toMatchObject({ key: highlightStepKey(demo("failed")), ...HL });
|
|
28
|
+
// Opened: the same step looked at again brings nothing back.
|
|
29
|
+
s = highlightShown(s);
|
|
30
|
+
expect(s.pending).toBeNull();
|
|
31
|
+
expect(highlightTurn(s, demo("failed", { highlight: HL }))).toBe(s);
|
|
32
|
+
// A step that goes takes a highlight not yet opened with it.
|
|
33
|
+
const waiting = highlightTurn(null, demo("failed", { highlight: HL }));
|
|
34
|
+
expect(highlightTurn(waiting, demo("resumed")).pending).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
it("opens once though the driver writes its step again, around a hold", () => {
|
|
37
|
+
const w = (step, t) => demo(step, { started_at: `2026-10-18T00:00:${t}Z`, highlight: step === "applying" ? HL : null });
|
|
38
|
+
let s = highlightShown(highlightTurn(null, w("applying", 10)));
|
|
39
|
+
s = highlightTurn(s, w("waiting", 20));
|
|
40
|
+
s = highlightTurn(s, w("applying", 30));
|
|
41
|
+
expect(s.pending).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
it("opens when a step gains one partway through, as choudoufu's operator's apply does", () => {
|
|
44
|
+
let s = highlightTurn(null, demo("applying", { started_at: "2026-10-18T00:00:10Z" }));
|
|
45
|
+
expect(s.pending).toBeNull();
|
|
46
|
+
s = highlightTurn(s, demo("applying", { started_at: "2026-10-18T00:00:10Z", highlight: HL }));
|
|
47
|
+
expect(s.pending).toMatchObject(HL);
|
|
48
|
+
});
|
|
49
|
+
it("a fix's step opens its own title, not the same one again; the next cycle opens it again", () => {
|
|
50
|
+
const opened = highlightShown(highlightTurn(null, demo("planned", { highlight: HL })));
|
|
51
|
+
expect(highlightTurn(opened, demo("planned", { pull: 4, highlight: HL })).pending).toBeNull();
|
|
52
|
+
expect(highlightTurn(opened, demo("planned", { pull: 4, highlight: { title: "Only what was blocked", body: "b" } })).pending).toMatchObject({ title: "Only what was blocked" });
|
|
53
|
+
expect(highlightTurn(opened, demo("planned", { cycle: 10, highlight: HL })).pending).not.toBeNull();
|
|
54
|
+
});
|
|
55
|
+
it("opens in Watch with Tips on, over a Waiting modal but not over a critical one, nor on a held small stage", () => {
|
|
56
|
+
const pending = { key: "k", ...HL };
|
|
57
|
+
expect(highlightOpens({ pending, on: true, watch: true })).toBe(true);
|
|
58
|
+
expect(highlightOpens({ pending, on: true, watch: true, modal: "waiting" })).toBe(true);
|
|
59
|
+
expect(highlightOpens({ pending, on: false, watch: true })).toBe(false);
|
|
60
|
+
expect(highlightOpens({ pending, on: true, watch: false })).toBe(false);
|
|
61
|
+
expect(highlightOpens({ pending, on: true, watch: true, held: true })).toBe(false);
|
|
62
|
+
expect(highlightOpens({ pending, on: true, watch: true, modal: "failed" })).toBe(false);
|
|
63
|
+
expect(highlightOpens({ pending: null, on: true, watch: true })).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
it("in a replay, arrives when the replay's clock reaches its step, and again each time the replay loops round", () => {
|
|
66
|
+
const steps = [demo("applying", { at: "2026-10-18T00:00:00Z" }), demo("failed", { at: "2026-10-18T00:00:20Z", highlight: HL }), demo("reset", { at: "2026-10-18T00:00:40Z" })];
|
|
67
|
+
let s = null;
|
|
68
|
+
const opened = [];
|
|
69
|
+
for (let t = 0; t < 130_000; t += 1_000) {
|
|
70
|
+
const d = steps[replayAt(steps, t).index];
|
|
71
|
+
s = highlightTurn(s, d);
|
|
72
|
+
if (s.pending) {
|
|
73
|
+
opened.push(t);
|
|
74
|
+
s = highlightShown(s);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const loop = replayAt(steps, 0).loop;
|
|
78
|
+
expect(opened).toEqual([20_000, 20_000 + loop, 20_000 + 2 * loop].filter((t) => t < 130_000));
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("highlight: on a tool's page", () => {
|
|
83
|
+
it("goes whole when it names a rival of the page's tool, as the step's line does", () => {
|
|
84
|
+
expect(scrubDemo(demo("failed", { highlight: HL }), "tofu-fanout").highlight).toEqual(HL);
|
|
85
|
+
expect(scrubDemo(demo("failed", { highlight: HL }), "chant-fanout").highlight).toBeNull();
|
|
86
|
+
expect("highlight" in scrubDemo(demo("failed"), "tofu-fanout")).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/** Just enough of a DOM for Tips and its modal. */
|
|
91
|
+
function fakeDoc() {
|
|
92
|
+
const listeners = {};
|
|
93
|
+
const make = (tag) => {
|
|
94
|
+
const n = {
|
|
95
|
+
tagName: tag.toUpperCase(),
|
|
96
|
+
children: [],
|
|
97
|
+
handlers: {},
|
|
98
|
+
textContent: "",
|
|
99
|
+
className: "",
|
|
100
|
+
dataset: {},
|
|
101
|
+
style: { setProperty() {} },
|
|
102
|
+
classList: { toggle() {}, add() {}, remove() {} },
|
|
103
|
+
appendChild(c) {
|
|
104
|
+
c.parent = n;
|
|
105
|
+
n.children.push(c);
|
|
106
|
+
return c;
|
|
107
|
+
},
|
|
108
|
+
append(...cs) {
|
|
109
|
+
cs.forEach((c) => typeof c === "object" && n.appendChild(c));
|
|
110
|
+
},
|
|
111
|
+
prepend(c) {
|
|
112
|
+
n.appendChild(c);
|
|
113
|
+
},
|
|
114
|
+
replaceChildren() {
|
|
115
|
+
n.children = [];
|
|
116
|
+
},
|
|
117
|
+
setAttribute() {},
|
|
118
|
+
addEventListener(ev, fn) {
|
|
119
|
+
(n.handlers[ev] ||= []).push(fn);
|
|
120
|
+
},
|
|
121
|
+
querySelector: () => null,
|
|
122
|
+
remove() {
|
|
123
|
+
if (n.parent) n.parent.children = n.parent.children.filter((x) => x !== n);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
return n;
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
createElement: make,
|
|
130
|
+
head: make("head"),
|
|
131
|
+
body: make("body"),
|
|
132
|
+
getElementById: () => null,
|
|
133
|
+
querySelectorAll: () => [],
|
|
134
|
+
addEventListener: (ev, fn) => ((listeners[ev] ||= []).push(fn)),
|
|
135
|
+
removeEventListener() {},
|
|
136
|
+
fire: (ev, e) => (listeners[ev] || []).forEach((fn) => fn(e)),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const all = (n) => [n, ...n.children.flatMap(all)];
|
|
140
|
+
const find = (root, cls) => all(root).find((n) => n.className && n.className.split(" ").includes(cls));
|
|
141
|
+
/** The Tips switch's shelf, on or off (event-help-store.js). */
|
|
142
|
+
const shelf = (on = true) => {
|
|
143
|
+
const m = new Map();
|
|
144
|
+
ehStore({ setItem: (k, v) => m.set(k, v) }, on);
|
|
145
|
+
return { getItem: (k) => (m.has(k) ? m.get(k) : null), setItem: (k, v) => m.set(k, v) };
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
describe("highlight: Tips draws it", () => {
|
|
149
|
+
let t;
|
|
150
|
+
beforeEach(() => {
|
|
151
|
+
vi.useFakeTimers();
|
|
152
|
+
t = 1_000_000;
|
|
153
|
+
});
|
|
154
|
+
afterEach(() => vi.useRealTimers());
|
|
155
|
+
const start = ({ on = true, watch = true, replay = false } = {}) => {
|
|
156
|
+
const doc = fakeDoc();
|
|
157
|
+
const view = { demo: demo("applying"), watch, replay };
|
|
158
|
+
const api = startEventHelp({ doc, store: shelf(on), tipsHost: doc.body, modalHost: doc.body, now: () => t, get: () => ({ ...view, strip: null, stripReady: true }), reduced: () => true });
|
|
159
|
+
const modal = () => find(doc.body, "eh-modal");
|
|
160
|
+
const step = (d, ms = 0) => {
|
|
161
|
+
view.demo = d;
|
|
162
|
+
t += ms;
|
|
163
|
+
vi.advanceTimersByTime(ms);
|
|
164
|
+
api.tick();
|
|
165
|
+
};
|
|
166
|
+
return { api, doc, view, modal, step };
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
it("opens with its step in Watch, with its kicker, title and body, and no button", () => {
|
|
170
|
+
const k = start();
|
|
171
|
+
k.step(demo("applying"));
|
|
172
|
+
expect(k.modal()).toBeUndefined();
|
|
173
|
+
k.step(demo("failed", { highlight: HL }), 1_000);
|
|
174
|
+
const m = k.modal();
|
|
175
|
+
expect(m.className).toContain("eh-modal-highlight");
|
|
176
|
+
expect(find(m, "eh-modal-mode").textContent).toBe(HIGHLIGHT_KICKER);
|
|
177
|
+
expect(find(m, "eh-modal-title").textContent).toBe(HL.title);
|
|
178
|
+
expect(find(m, "eh-modal-line").textContent).toBe(HL.body);
|
|
179
|
+
expect(find(m, "eh-modal-act")).toBeUndefined();
|
|
180
|
+
expect(k.api.state.modal.kind).toBe("highlight");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("stays HIGHLIGHT_MS, then goes, and does not come back for the same step", () => {
|
|
184
|
+
const k = start();
|
|
185
|
+
k.step(demo("failed", { highlight: HL }));
|
|
186
|
+
k.step(demo("failed", { highlight: HL }), HIGHLIGHT_MS - 1_000);
|
|
187
|
+
expect(k.modal()).toBeDefined();
|
|
188
|
+
k.step(demo("failed", { highlight: HL }), 1_500);
|
|
189
|
+
expect(k.modal()).toBeUndefined();
|
|
190
|
+
k.step(demo("failed", { highlight: HL }), 5_000);
|
|
191
|
+
expect(k.modal()).toBeUndefined();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("goes with its step, and closes with Esc", () => {
|
|
195
|
+
const k = start();
|
|
196
|
+
k.step(demo("failed", { highlight: HL }));
|
|
197
|
+
k.step(demo("resumed"), 2_000);
|
|
198
|
+
expect(k.modal()).toBeUndefined();
|
|
199
|
+
k.step(demo("applied", { highlight: HL }), 2_000);
|
|
200
|
+
expect(k.modal()).toBeDefined();
|
|
201
|
+
k.doc.fire("keydown", { key: "Escape" });
|
|
202
|
+
expect(k.modal()).toBeUndefined();
|
|
203
|
+
k.step(demo("applied", { highlight: HL }), 1_000);
|
|
204
|
+
expect(k.modal()).toBeUndefined();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("shows nothing with Tips off, nor in Inspect, nor for a step without one", () => {
|
|
208
|
+
const off = start({ on: false });
|
|
209
|
+
off.step(demo("failed", { highlight: HL }));
|
|
210
|
+
expect(off.modal()).toBeUndefined();
|
|
211
|
+
const inspect = start({ watch: false });
|
|
212
|
+
inspect.step(demo("failed", { highlight: HL }));
|
|
213
|
+
expect(inspect.modal()).toBeUndefined();
|
|
214
|
+
const none = start();
|
|
215
|
+
none.step(demo("failed"));
|
|
216
|
+
none.step(demo("failed", { highlight: { title: "", body: "b" } }), 1_000);
|
|
217
|
+
expect(none.modal()).toBeUndefined();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("in a replay, opens as the replay reaches its step, marked a replay", () => {
|
|
221
|
+
const k = start({ replay: true });
|
|
222
|
+
k.step(demo("applying"));
|
|
223
|
+
expect(k.modal()).toBeUndefined();
|
|
224
|
+
k.step(demo("failed", { highlight: HL }), 20_000);
|
|
225
|
+
expect(k.modal().className).toContain("eh-mode-replay");
|
|
226
|
+
expect(find(k.modal(), "eh-modal-mode").textContent).toBe(HIGHLIGHT_KICKER);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("highlight: the modal", () => {
|
|
231
|
+
it("says its kicker in every mode", () => {
|
|
232
|
+
for (const mode of ["narrated", "replay", "live"]) expect(modeLine(mode, "highlight", {})).toBe(HIGHLIGHT_KICKER);
|
|
233
|
+
});
|
|
234
|
+
it("closes after `closeAfter`, and holds while hovered", () => {
|
|
235
|
+
let now = 0;
|
|
236
|
+
const timers = [];
|
|
237
|
+
const doc = fakeDoc();
|
|
238
|
+
const m = openEventModal(doc.body, { mode: "narrated", kind: "highlight", data: { title: HL.title, lines: [{ text: HL.body }], closeAfter: 12_000 }, doc, now: () => now, setTimer: (fn) => timers.push(fn), clearTimer() {} });
|
|
239
|
+
const box = find(doc.body, "eh-modal");
|
|
240
|
+
box.handlers.pointerenter.forEach((fn) => fn());
|
|
241
|
+
now = 13_000;
|
|
242
|
+
timers.forEach((fn) => fn());
|
|
243
|
+
expect(m.state.closed).toBe(false);
|
|
244
|
+
box.handlers.pointerleave.forEach((fn) => fn());
|
|
245
|
+
now = 16_000;
|
|
246
|
+
timers.forEach((fn) => fn());
|
|
247
|
+
expect(m.state.closed).toBe(true);
|
|
248
|
+
});
|
|
249
|
+
});
|