@intentius/behold 0.29.39 → 0.29.41

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.
Files changed (49) hide show
  1. package/AGENTS.md +148 -10
  2. package/README.md +6 -2
  3. package/dist/cli.js +15965 -13076
  4. package/example-writes/README.md +1 -1
  5. package/example-writes/chant.config.ts +0 -6
  6. package/package.json +5 -2
  7. package/web/app.js +327 -21
  8. package/web/carve-export.js +142 -0
  9. package/web/carve-narration.js +268 -0
  10. package/web/carve-narration.test.js +18 -0
  11. package/web/change-set-overlay.js +147 -0
  12. package/web/change-set-overlay.test.js +83 -0
  13. package/web/dots-border.js +66 -0
  14. package/web/dots-border.test.js +27 -0
  15. package/web/dots-kiosk.js +279 -0
  16. package/web/dots-kiosk.test.js +60 -0
  17. package/web/dots-layout.d.ts +10 -0
  18. package/web/dots-layout.js +201 -0
  19. package/web/dots-live.js +316 -0
  20. package/web/dots-live.test.js +220 -0
  21. package/web/dots-lod.js +122 -0
  22. package/web/dots-lod.test.js +78 -0
  23. package/web/dots-recording.d.ts +7 -0
  24. package/web/dots-recording.js +247 -0
  25. package/web/dots-recording.test.js +71 -0
  26. package/web/dots-scene.js +294 -0
  27. package/web/dots-scene.test.js +118 -0
  28. package/web/dots-timeline.js +128 -0
  29. package/web/dots-timeline.test.js +83 -0
  30. package/web/dots-tour.js +153 -0
  31. package/web/dots.js +2124 -0
  32. package/web/dots.test.js +15 -0
  33. package/web/index.html +29 -0
  34. package/web/kiosk-carve.js +219 -0
  35. package/web/kiosk-carve.test.js +26 -0
  36. package/web/kiosk-event-help-ui.js +6 -0
  37. package/web/kiosk.html +2 -1
  38. package/web/kiosk.js +21 -6
  39. package/web/operator.js +1 -1
  40. package/web/run-playhead.js +102 -19
  41. package/web/run-playhead.test.js +81 -11
  42. package/web/tour-player.js +204 -0
  43. package/web/tour-player.test.js +115 -0
  44. package/web/tours/behold.tour.v1.schema.json +182 -0
  45. package/web/tours/terralith.json +330 -0
  46. package/web/trunk-lane.js +254 -0
  47. package/web/trunk-lane.test.js +117 -0
  48. package/web/workspace-gates.js +29 -4
  49. package/web/workspace-gates.test.js +23 -2
@@ -0,0 +1,254 @@
1
+ // #680: the trunk lane. Pure words from /api/workspace/lane, and one render.
2
+ // First the trunk's recent commits, each green, revoked or undecided, with its
3
+ // work items and runs and where it is now. Then one lane per environment in
4
+ // the promotion order chant declares: what the environment runs, and the
5
+ // gates waiting there, each with the approve button the gate strip uses
6
+ // (approveAffordance, #690), and the change set it binds as the link that
7
+ // draws it on the graph (#681). Nothing here is behold's own state.
8
+
9
+ import { ago, clock } from "./terragucci.js";
10
+ import { approveAffordance, HOST_APPROVES, overrideCard } from "./workspace-gates.js";
11
+
12
+ const short = (s) => (s ? String(s).replace(/^(jcs1-)?sha256:/, "").slice(0, 12) : "");
13
+ const sha7 = (s) => (s ? String(s).slice(0, 7) : "");
14
+ const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
15
+
16
+ /** The note under the legend: chant ci list reads local tags only. */
17
+ export const UNDECIDED_NOTE = "undecided: no ci tag yet. chant ci list reads local tags, so a commit that failed without ever going green also reads undecided.";
18
+
19
+ /** The lane's first line: what was read, or why it wasn't. */
20
+ export function laneLegend(a, now = new Date()) {
21
+ if (!a || a.error) return { text: `lane not read${a && a.error ? `: ${a.error}` : ""}`, title: "", tone: "refusal" };
22
+ if (a.refusal) return { text: `lane not read: ${a.refusal.error}`, title: a.refusal.remedy || "", tone: "refusal" };
23
+ const when = a.read ? ` · read ${ago(a.read.at, now)}` : "";
24
+ if (!a.trunk) return { text: `trunk not read: ${a.trunkRefusal ? a.trunkRefusal.error : "chant ci list gave no answer"}${when}`, title: (a.trunkRefusal && a.trunkRefusal.remedy) || "", tone: "refusal" };
25
+ const span = a.trunk.since ? `after ${sha7(a.trunk.since)}` : `within ${a.trunk.window}`;
26
+ return { text: `trunk ${a.trunk.branch} · ${plural(a.commits.length, "commit")} ${span}${when}`, title: UNDECIDED_NOTE, tone: "quiet" };
27
+ }
28
+
29
+ /** A commit's work items in words, as chant#4029 links them; null when chant said nothing. */
30
+ export function workWords(work) {
31
+ if (!work) return null;
32
+ if (work.state === "linked") return { text: `work ${work.ids.join(", ")}`, title: "" };
33
+ if (work.state === "unlinked") return { text: "no work item", title: "No Chant-Record or Chant-Lease trailer names one." };
34
+ if (work.state === "wrong") return { text: "names a work item that does not exist", title: work.problems.map((p) => `${p.trailer}: ${p.message}`).join("\n") };
35
+ if (work.state === "merge") return { text: "merge commit", title: "Its work is the commits it brings." };
36
+ return null;
37
+ }
38
+
39
+ /** Where a commit is, in words: "runs in staging, waits in prod". */
40
+ export function whereWords(where) {
41
+ return (where || []).map((w) => (w.what === "runs" ? `runs in ${w.env}` : `waits in ${w.env}`)).join(", ");
42
+ }
43
+
44
+ /** The runs behind a commit's state, each a link: every phase's runs, and the run a revoked tag names. */
45
+ export function commitRuns(c) {
46
+ const out = [];
47
+ const seen = new Set();
48
+ const add = (r) => {
49
+ if (!r || !r.url || seen.has(r.url)) return;
50
+ seen.add(r.url);
51
+ out.push({ text: r.name, href: r.url, title: r.conclusion ? `${r.name}: ${r.conclusion}` : r.name });
52
+ };
53
+ for (const p of c.phases || []) for (const r of p.runs) add(r);
54
+ if (c.revoked) add(c.revoked.run);
55
+ return out;
56
+ }
57
+
58
+ /** One trunk commit's row. */
59
+ export function commitRow(c, now = new Date()) {
60
+ const facts = [];
61
+ const work = workWords(c.work);
62
+ if (c.revoked) facts.push({ text: `revoked: ${c.revoked.phase || "a phase"} failed`, title: "" });
63
+ if (work) facts.push(work);
64
+ if (c.ignored && c.ignored.length) facts.push({ text: `${plural(c.ignored.length, "ci tag")} not counted`, title: c.ignored.map((t) => `${t.tag} (${t.status}): ${t.reason}`).join("\n") });
65
+ return {
66
+ sha: c.sha,
67
+ head: `${sha7(c.sha)} ${c.state}`,
68
+ state: c.state,
69
+ when: ago(c.committed, now),
70
+ title: `${c.sha}\ncommitted ${clock(c.committed, now)}${c.state === "undecided" ? `\n${UNDECIDED_NOTE}` : ""}`,
71
+ where: whereWords(c.where),
72
+ facts,
73
+ runs: commitRuns(c),
74
+ };
75
+ }
76
+
77
+ /** What one environment runs, line by line; `no deploy record` when chant has none. */
78
+ export function runsLines(e, now = new Date()) {
79
+ const lines = [];
80
+ for (const r of e.releases || []) {
81
+ lines.push({
82
+ text: `runs ${r.label || short(r.releaseDigest)}, cut from ${sha7(r.commit)}${r.listed ? "" : " (older than the trunk list)"} · ${r.components.join(", ")}`,
83
+ title: [`release ${r.releaseDigest} of ${r.member}`, r.cutBy ? `cut by ${r.cutBy}${r.cutAt ? ` ${clock(r.cutAt, now)}` : ""}` : "", r.approver ? `deploy approved by ${r.approver}` : ""].filter(Boolean).join("\n"),
84
+ });
85
+ }
86
+ for (const d of e.deploys || []) {
87
+ lines.push({
88
+ text: `runs ${d.component} ${short(d.digest)} from ${sha7(d.gitSha)}${d.listed ? "" : " (older than the trunk list)"}`,
89
+ title: `deploy record of ${d.member}, run ${d.runId}, by ${d.actor} ${ago(d.timestamp, now)}${d.approver ? `, approved by ${d.approver}` : ""}`,
90
+ });
91
+ }
92
+ if (!lines.length) lines.push({ text: "no deploy record", title: "chant has no deploy record for this environment, so behold does not say what runs here." });
93
+ return lines;
94
+ }
95
+
96
+ /** One waiting gate as a card, with the gate strip's approve button (or the note in its place). */
97
+ export function laneGateCard(g, answer, { embed = false } = {}) {
98
+ if (g.override) {
99
+ const o = overrideCard(g);
100
+ return { key: g.key, title: o.title, facts: o.facts, note: o.note, command: o.command };
101
+ }
102
+ const facts = [];
103
+ facts.push(g.gitSha ? `for ${sha7(g.gitSha)}${g.commitState ? ` (${g.commitState})` : ""}` : "commit unknown");
104
+ facts.push(`${g.approvals.length} of ${plural(g.needed, "approval")}`);
105
+ if (g.runId) facts.push(`run ${g.runId}`);
106
+ if (g.releaseDigest) facts.push(`release ${short(g.releaseDigest)}`);
107
+ if (g.approvals.length) facts.push(`approved by ${g.approvals.map((a) => a.principal).join(", ")}`);
108
+ const show = g.changeSet ? `chant change-set show ${g.changeSet} --member ${g.member}` : null;
109
+ const card = {
110
+ key: g.key,
111
+ title: `${g.member}: ${g.op} waits at gate ${g.gate}`,
112
+ facts: facts.join(" · "),
113
+ command: show ? `${g.approve}\n${show}` : g.approve,
114
+ };
115
+ // #681: the change set is a link that draws it on the graph.
116
+ if (g.changeSet) card.changeSet = { text: `change set ${short(g.changeSet)}`, title: `Draw this change set on the graph, as a preview.\n${show}` };
117
+ if (embed) card.note = HOST_APPROVES;
118
+ else Object.assign(card, approveAffordance(g, answer));
119
+ return card;
120
+ }
121
+
122
+ /** The whole lane as words: the legend, the commits, and a lane per environment. Pure. */
123
+ export function laneView(a, now = new Date(), opts = {}) {
124
+ const legend = laneLegend(a, now);
125
+ if (!a || a.error || a.refusal) return { legend, notes: [], commits: [], environments: [] };
126
+ const notes = [];
127
+ if (a.order === "env" && a.environments.length) notes.push(`no member declares a promotion order, so this is ${a.environments[0].env} alone`);
128
+ for (const r of a.releaseRefusals || []) notes.push(`releases of ${r.member} not read: ${r.refusal.error}`);
129
+ return {
130
+ legend,
131
+ notes,
132
+ commits: (a.commits || []).map((c) => commitRow(c, now)),
133
+ empty: a.trunk && !(a.commits || []).length ? `no commits ${a.trunk.since ? `after ${sha7(a.trunk.since)}` : `within ${a.trunk.window}`}` : null,
134
+ environments: (a.environments || []).map((e) => ({
135
+ env: e.env,
136
+ heading: e.canary ? `${e.env} (canary)` : e.env,
137
+ refusal: e.refusal ? `not read: ${e.refusal.error}` : null,
138
+ runs: e.refusal ? [] : runsLines(e, now),
139
+ gates: (e.waiting || []).filter((g) => g.state === "pending" || g.override).map((g) => laneGateCard(g, a, opts)),
140
+ })),
141
+ };
142
+ }
143
+
144
+ /**
145
+ * Render into `host`. `ui.button(label, cls, onClick)` and `ui.link(text,
146
+ * href)` are app.js's; `ui.approve(key, env, button)` posts the approval;
147
+ * `ui.embed` and `ui.canApprove` say whether a button may be drawn;
148
+ * `ui.openChangeSet(key, env)` draws a gate's change set on the graph (#681).
149
+ */
150
+ export function renderTrunkLane(host, a, now, ui) {
151
+ host.replaceChildren();
152
+ const v = laneView(a, now, { embed: !!(ui && ui.embed) });
153
+ const line = (cls, text, title) => {
154
+ const d = document.createElement("div");
155
+ d.className = cls;
156
+ d.textContent = text;
157
+ if (title) d.title = title;
158
+ host.appendChild(d);
159
+ return d;
160
+ };
161
+ line(v.legend.tone === "refusal" ? "tg-refusal" : "tg-legend", v.legend.text, v.legend.title);
162
+ for (const n of v.notes) line("tg-legend", n);
163
+ if (!v.commits.length && !v.environments.length) return;
164
+
165
+ const h = document.createElement("h3");
166
+ h.textContent = "trunk";
167
+ host.appendChild(h);
168
+ if (v.empty) line("tg-legend", v.empty);
169
+ for (const c of v.commits) {
170
+ const row = document.createElement("div");
171
+ row.className = "lane-commit";
172
+ row.dataset.sha = c.sha;
173
+ row.title = c.title;
174
+ const head = document.createElement("div");
175
+ const state = document.createElement("span");
176
+ state.className = `lane-sha lane-${c.state}`;
177
+ state.textContent = c.head;
178
+ head.append(state, document.createTextNode(` · ${c.when}`));
179
+ if (c.where) {
180
+ const where = document.createElement("span");
181
+ where.className = "lane-where";
182
+ where.textContent = ` · ${c.where}`;
183
+ head.appendChild(where);
184
+ }
185
+ row.appendChild(head);
186
+ if (c.facts.length || c.runs.length) {
187
+ const facts = document.createElement("div");
188
+ facts.className = "lane-facts";
189
+ c.facts.forEach((f, i) => {
190
+ const s = document.createElement("span");
191
+ s.textContent = `${i ? " · " : ""}${f.text}`;
192
+ if (f.title) s.title = f.title;
193
+ facts.appendChild(s);
194
+ });
195
+ for (const r of c.runs) {
196
+ if (facts.childNodes.length) facts.appendChild(document.createTextNode(" · "));
197
+ const a = ui && ui.link ? ui.link(r.text, r.href) : document.createTextNode(r.text);
198
+ if (a.title !== undefined) a.title = r.title;
199
+ facts.appendChild(a);
200
+ }
201
+ row.appendChild(facts);
202
+ }
203
+ host.appendChild(row);
204
+ }
205
+
206
+ for (const e of v.environments) {
207
+ const eh = document.createElement("h3");
208
+ eh.textContent = e.heading;
209
+ host.appendChild(eh);
210
+ if (e.refusal) line("tg-refusal", e.refusal);
211
+ for (const r of e.runs) line("lane-runs", r.text, r.title);
212
+ for (const g of e.gates) {
213
+ const box = document.createElement("div");
214
+ box.className = "ws-gate";
215
+ box.dataset.gate = g.key;
216
+ const title = document.createElement("div");
217
+ title.className = "ws-gate-title";
218
+ title.textContent = g.title;
219
+ const facts = document.createElement("div");
220
+ facts.className = "ws-gate-facts";
221
+ facts.textContent = g.facts;
222
+ facts.title = g.command;
223
+ // #681: the change set the gate binds, as the link that opens the overlay.
224
+ if (g.changeSet) {
225
+ facts.appendChild(document.createTextNode(" · "));
226
+ if (ui && ui.openChangeSet) {
227
+ const a = document.createElement("a");
228
+ a.href = "#";
229
+ a.className = "lane-change-set";
230
+ a.textContent = g.changeSet.text;
231
+ a.title = g.changeSet.title;
232
+ a.addEventListener("click", (ev) => {
233
+ ev.preventDefault();
234
+ ui.openChangeSet(g.key, e.env);
235
+ });
236
+ facts.appendChild(a);
237
+ } else facts.appendChild(document.createTextNode(g.changeSet.text));
238
+ }
239
+ box.append(title, facts);
240
+ if (g.note) {
241
+ const note = document.createElement("div");
242
+ note.className = "ws-gate-note";
243
+ note.textContent = g.note;
244
+ box.appendChild(note);
245
+ }
246
+ if (g.button && ui && ui.canApprove && ui.button && ui.approve) {
247
+ const b = ui.button(g.button.label, "approve", () => ui.approve(g.key, e.env, b));
248
+ b.title = g.button.title;
249
+ box.appendChild(b);
250
+ }
251
+ host.appendChild(box);
252
+ }
253
+ }
254
+ }
@@ -0,0 +1,117 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { commitRow, laneGateCard, laneLegend, laneView, runsLines, UNDECIDED_NOTE, whereWords, workWords } from "./trunk-lane.js";
3
+
4
+ const NOW = new Date("2026-10-05T10:00:00Z");
5
+ const C1 = "6828a7f5b398ea48543fe27c018ba302ce2aba14";
6
+ const C2 = "a14610e4f51778c969efcc77694a360412c34d88";
7
+ const C3 = "9c4250fa1ed203aa9c61eca708c8f0bbf4a06ddd";
8
+ const C4 = "0c7c85ae8cca01463f304a3bd69bc3e977899d5f";
9
+ const run = (id, conclusion) => ({ name: "test", url: `https://github.com/acme/app/actions/runs/${id}`, conclusion });
10
+
11
+ // The shape /api/workspace/lane answers for the #680 fixture workspace.
12
+ const gate = {
13
+ key: "web/web/promote",
14
+ member: "web",
15
+ op: "web",
16
+ gate: "promote",
17
+ env: "prod",
18
+ planDigest: "sha256:4b5e57f6eb2f42b9039b3d1e13929295f231749c510cbe341cd68036d9af97e2",
19
+ approvals: [],
20
+ needed: 1,
21
+ signed: false,
22
+ state: "pending",
23
+ approve: "chant approve web promote --env prod --plan sha256:4b5e57f6eb2f",
24
+ gitSha: C2,
25
+ runId: "run-9",
26
+ changeSet: "sha256:4b5e57f6eb2f42b9039b3d1e13929295f231749c510cbe341cd68036d9af97e2",
27
+ commitState: "green",
28
+ };
29
+ const answer = {
30
+ workspace: true,
31
+ chant: "0.124.28",
32
+ approver: "alex",
33
+ approverIdentity: { principal: "alex", source: "process", forge: false, signs: false },
34
+ read: { at: "2026-10-05T09:59:58Z" },
35
+ order: "promotion",
36
+ trunk: { branch: "main", ref: "refs/heads/main", window: "3650d", since: null, require: ["test"] },
37
+ commits: [
38
+ { sha: C4, committed: "2026-10-04T10:00:00Z", state: "undecided", phases: [{ phase: "test", result: "unrecorded", runs: [] }], revoked: null, work: { state: "linked", ids: ["task:12"], problems: [] }, ignored: [], where: [] },
39
+ { sha: C3, committed: "2026-10-03T10:00:00Z", state: "revoked", phases: [{ phase: "test", result: "fail", runs: [run(113, "failure")] }], revoked: { phase: "test", run: run(113, "failure") }, work: { state: "unlinked", ids: [], problems: [] }, ignored: [], where: [] },
40
+ { sha: C2, committed: "2026-10-02T10:00:00Z", state: "green", phases: [{ phase: "test", result: "pass", runs: [run(102, "success")] }], revoked: null, work: null, ignored: [], where: [{ env: "staging", what: "runs" }, { env: "prod", what: "waits", gate: "web/web/promote" }] },
41
+ { sha: C1, committed: "2026-10-01T10:00:00Z", state: "green", phases: [{ phase: "test", result: "pass", runs: [run(101, "success")] }], revoked: null, work: null, ignored: [], where: [{ env: "prod", what: "runs" }] },
42
+ ],
43
+ environments: [
44
+ { env: "staging", canary: false, members: ["web"], releases: [{ member: "web", label: "v2", releaseDigest: "jcs1-sha256:1a23268fa8b1fc419cffde4c1780f4387ff0346495f97bd9e22b0508bef99f9d", commit: C2, listed: true, components: ["web"], cutBy: "github:alice", cutAt: "2026-10-03T09:00:00Z", approver: null }], deploys: [], waiting: [] },
45
+ { env: "prod", canary: false, members: ["web"], releases: [{ member: "web", label: "v1", releaseDigest: "jcs1-sha256:e3956171ab72fcab2d812cbd3621ef18c04a46c96a9f1e1a8590dae0d9279185", commit: C1, listed: true, components: ["web"], cutBy: "github:alice", cutAt: "2026-10-02T09:00:00Z", approver: "github:alice" }], deploys: [], waiting: [gate] },
46
+ ],
47
+ releaseRefusals: [],
48
+ };
49
+
50
+ describe("laneLegend (#680)", () => {
51
+ it("names the branch, the count and the window, and carries the undecided caveat", () => {
52
+ expect(laneLegend(answer, NOW)).toEqual({ text: "trunk main · 4 commits within 3650d · read just now", title: UNDECIDED_NOTE, tone: "quiet" });
53
+ });
54
+ it("says why when the lane or the trunk wasn't read", () => {
55
+ const refusal = { error: "Trunk commits needs chant 0.124.28 or newer. This project has chant 0.124.24.", code: "chant-too-old", remedy: "Upgrade @intentius/chant to 0.124.28 or newer in the project." };
56
+ expect(laneLegend({ workspace: true, refusal }, NOW)).toEqual({ text: `lane not read: ${refusal.error}`, title: refusal.remedy, tone: "refusal" });
57
+ const noGreen = { ...answer, trunk: null, commits: [], trunkRefusal: { error: "chant ci list: the workspace declares no ci.green", code: "ci-green-undeclared", remedy: "Declare ci.green" } };
58
+ expect(laneLegend(noGreen, NOW)).toMatchObject({ text: "trunk not read: chant ci list: the workspace declares no ci.green · read just now", tone: "refusal" });
59
+ });
60
+ });
61
+
62
+ describe("a trunk commit (#680)", () => {
63
+ it("says its state, where it is, its work and its runs", () => {
64
+ const green = commitRow(answer.commits[2], NOW);
65
+ expect(green).toMatchObject({ head: "a14610e green", when: "3d ago", where: "runs in staging, waits in prod", facts: [] });
66
+ expect(green.runs).toEqual([{ text: "test", href: "https://github.com/acme/app/actions/runs/102", title: "test: success" }]);
67
+ const revoked = commitRow(answer.commits[1], NOW);
68
+ expect(revoked.facts.map((f) => f.text)).toEqual(["revoked: test failed", "no work item"]);
69
+ expect(revoked.runs).toHaveLength(1);
70
+ const undecided = commitRow(answer.commits[0], NOW);
71
+ expect(undecided.facts.map((f) => f.text)).toEqual(["work task:12"]);
72
+ expect(undecided.title).toContain(UNDECIDED_NOTE);
73
+ });
74
+ it("words each work state chant#4029 defines, and nothing when chant said nothing", () => {
75
+ expect(workWords(null)).toBeNull();
76
+ expect(workWords({ state: "merge", ids: [], problems: [] }).text).toBe("merge commit");
77
+ expect(workWords({ state: "wrong", ids: [], problems: [{ trailer: "Chant-Record: task:99", message: "no task record 99 exists" }] })).toEqual({ text: "names a work item that does not exist", title: "Chant-Record: task:99: no task record 99 exists" });
78
+ expect(whereWords([])).toBe("");
79
+ });
80
+ });
81
+
82
+ describe("an environment's lane (#680)", () => {
83
+ it("says what it runs and the commit it was cut from", () => {
84
+ expect(runsLines(answer.environments[0], NOW)).toEqual([{ text: "runs v2, cut from a14610e · web", title: expect.stringContaining("cut by github:alice") }]);
85
+ expect(runsLines(answer.environments[1], NOW)[0].title).toContain("deploy approved by github:alice");
86
+ });
87
+ it("says plainly when there is no deploy record, and names a deploy no release covers", () => {
88
+ expect(runsLines({ env: "dev", releases: [], deploys: [] }, NOW)).toEqual([{ text: "no deploy record", title: expect.any(String) }]);
89
+ const d = { member: "web", component: "api", digest: "sha256:0123456789abcdef", gitSha: C1, listed: false, timestamp: "2026-10-04T10:00:00Z", actor: "ci", approver: null, runId: "r" };
90
+ expect(runsLines({ env: "dev", releases: [], deploys: [d] }, NOW)[0].text).toBe("runs api 0123456789ab from 6828a7f (older than the trunk list)");
91
+ });
92
+ it("draws a waiting gate with its commit, run and change set, and the approve button that names the approver", () => {
93
+ const card = laneGateCard(gate, answer);
94
+ expect(card).toMatchObject({
95
+ title: "web: web waits at gate promote",
96
+ facts: "for a14610e (green) · 0 of 1 approval · run run-9",
97
+ changeSet: { text: "change set 4b5e57f6eb2f", title: expect.stringContaining("Draw this change set on the graph") },
98
+ button: { label: "Approve as alex" },
99
+ });
100
+ expect(card.command).toContain("chant change-set show sha256:4b5e57f6");
101
+ expect(card.changeSet.title).toContain("chant change-set show sha256:4b5e57f6eb2f42b9039b3d1e13929295f231749c510cbe341cd68036d9af97e2 --member web");
102
+ // #681: a release gate names the release its change set was planned for.
103
+ expect(laneGateCard({ ...gate, op: "release", releaseDigest: "jcs1-sha256:1a23268fa8b1fc419cffde4c1780f4387ff0346495f97bd9e22b0508bef99f9d" }, answer).facts).toBe("for a14610e (green) · 0 of 1 approval · run run-9 · release 1a23268fa8b1");
104
+ expect(laneGateCard({ ...gate, gitSha: undefined, commitState: null, changeSet: undefined }, answer)).toMatchObject({ facts: "commit unknown · 0 of 1 approval · run run-9" });
105
+ expect(laneGateCard({ ...gate, changeSet: undefined }, answer).changeSet).toBeUndefined();
106
+ expect(laneGateCard(gate, answer, { embed: true }).button).toBeUndefined();
107
+ });
108
+ it("lays the environments out in the order the answer gives", () => {
109
+ const v = laneView(answer, NOW);
110
+ expect(v.environments.map((e) => [e.heading, e.gates.length])).toEqual([
111
+ ["staging", 0],
112
+ ["prod", 1],
113
+ ]);
114
+ expect(v.notes).toEqual([]);
115
+ expect(laneView({ ...answer, order: "env", environments: [answer.environments[1]] }, NOW).notes).toEqual(["no member declares a promotion order, so this is prod alone"]);
116
+ });
117
+ });
@@ -3,8 +3,17 @@
3
3
  //
4
4
  // One approve path per gate. Framed in a host (#476), behold draws the gate
5
5
  // and no button: the host knows who is looking and records it. Standalone, the
6
- // button stays, and the card says the approval is recorded as the user running
7
- // behold, since behold has no other identity to give chant.
6
+ // button stays, and its label names who chant records the approval as (#690):
7
+ // the person behold's proxy signed in, the one `--as` names, or else the user
8
+ // running behold. A gate that needs a signed approval gets a button only when
9
+ // behold holds that person's key.
10
+
11
+ /** Where the approver's name came from, in the words a button's tooltip uses. */
12
+ const SOURCE_WORDS = {
13
+ header: "from your sign-in",
14
+ configured: "set when behold started",
15
+ process: "the user running behold",
16
+ };
8
17
 
9
18
  /** The words a framed card uses instead of a button. */
10
19
  export const HOST_APPROVES = "approve in the host that framed this graph";
@@ -31,14 +40,30 @@ export function gateCards(answer, { embed = false, member = null } = {}) {
31
40
  command: g.approve,
32
41
  };
33
42
  if (embed) card.note = HOST_APPROVES;
34
- else if (g.signed) card.note = `wants a signed approval; run ${g.approve}`;
35
- else card.button = { label: `Approve as ${answer.approver || "you"}`, title: `${g.approve}, run by behold. chant records the approval as ${answer.approver || "the user running behold"}.` };
43
+ else Object.assign(card, approveAffordance(g, answer));
36
44
  return card;
37
45
  });
38
46
  const elsewhere = all.length - shown.length;
39
47
  return { cards, elsewhere, refusal: (answer && answer.refusal) || null };
40
48
  }
41
49
 
50
+ /**
51
+ * #690: the button, or the note in its place, for a standalone card. The label
52
+ * says who the approval is recorded as before the click.
53
+ */
54
+ export function approveAffordance(g, answer) {
55
+ const refusal = answer && answer.approverRefusal;
56
+ if (refusal) return { note: `can't approve here: ${refusal.error}. Run ${g.approve}` };
57
+ const id = (answer && answer.approverIdentity) || null;
58
+ const who = (answer && answer.approver) || "you";
59
+ const from = SOURCE_WORDS[id ? id.source : "process"] || SOURCE_WORDS.process;
60
+ if (g.signed) {
61
+ if (!id || !id.signs) return { note: `needs a signed approval, and behold has no key for ${who}. Run ${g.approve}` };
62
+ return { button: { label: `Approve as ${who}, signed`, title: `behold runs ${g.approve} with ${who}'s key. chant records ${who}, ${from}.` } };
63
+ }
64
+ return { button: { label: `Approve as ${who}`, title: `behold runs ${g.approve}. chant records ${who}, ${from}.` } };
65
+ }
66
+
42
67
  /**
43
68
  * #519: a policy denial. chant's override needs the denied rules and a
44
69
  * person's reason, so the card shows them and the command to run, and never a
@@ -26,9 +26,30 @@ describe("gateCards (#477)", () => {
26
26
  expect(cards.map((c) => c.key)).toEqual(["delivery/ship/approve-ship"]);
27
27
  expect(elsewhere).toBe(1);
28
28
  });
29
- it("sends a signed gate to the command line", () => {
29
+ it("sends a signed gate to the command line when behold holds no key", () => {
30
30
  const { cards } = gateCards({ ...answer, gates: [{ ...answer.gates[0], signed: true, approve: "chant approve ship approve-ship --sign" }] });
31
31
  expect(cards[0].button).toBeUndefined();
32
- expect(cards[0].note).toBe("wants a signed approval; run chant approve ship approve-ship --sign");
32
+ expect(cards[0].note).toBe("needs a signed approval, and behold has no key for alex. Run chant approve ship approve-ship --sign");
33
+ });
34
+ });
35
+
36
+ describe("who the approval is recorded as (#690)", () => {
37
+ const as = (identity) => ({ ...answer, approver: identity.principal, approverIdentity: identity });
38
+ const alice = { principal: "github:alice", source: "configured", forge: true, signs: false };
39
+ it("names the person on the button, and where the name came from in its title", () => {
40
+ const { cards } = gateCards(as(alice));
41
+ expect(cards[0].button).toEqual({ label: "Approve as github:alice", title: "behold runs chant approve ship approve-ship. chant records github:alice, set when behold started." });
42
+ const signedIn = gateCards(as({ ...alice, source: "header" })).cards[0];
43
+ expect(signedIn.button.title).toMatch(/github:alice, from your sign-in\.$/);
44
+ });
45
+ it("offers a signed gate when behold holds the person's key", () => {
46
+ const { cards } = gateCards({ ...as({ ...alice, signs: true }), gates: [{ ...answer.gates[0], signed: true, approve: "chant approve ship approve-ship --sign" }] });
47
+ expect(cards[0].button.label).toBe("Approve as github:alice, signed");
48
+ expect(cards[0].button.title).toBe("behold runs chant approve ship approve-ship --sign with github:alice's key. chant records github:alice, set when behold started.");
49
+ });
50
+ it("draws no button when behold can't tell who is asking", () => {
51
+ const { cards } = gateCards({ ...answer, approver: null, approverRefusal: { error: "behold reads who you are from the x-forwarded-user header, and this request has none", code: "no-identity" } });
52
+ expect(cards[0].button).toBeUndefined();
53
+ expect(cards[0].note).toBe("can't approve here: behold reads who you are from the x-forwarded-user header, and this request has none. Run chant approve ship approve-ship");
33
54
  });
34
55
  });