@intentius/behold 0.30.2 → 0.31.0

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 (92) hide show
  1. package/AGENTS.md +444 -15
  2. package/README.md +14 -13
  3. package/demos.json +14 -9
  4. package/dist/cli.js +53928 -26475
  5. package/example-carve/README.md +19 -23
  6. package/example-carve/app/package.json +1 -1
  7. package/example-carve/app/src/carved.ts +3 -3
  8. package/example-carve/carve-report.json +1 -1
  9. package/example-carve/{legacy-tf → tf-root}/terraform.tfstate +1 -1
  10. package/example-choudoufu-estate/README.md +7 -0
  11. package/example-choudoufu-estate/chant.workspace.json +1 -1
  12. package/example-choudoufu-estate/scripts/choudoufu-down.sh +2 -1
  13. package/example-choudoufu-estate/scripts/choudoufu-up.sh +10 -3
  14. package/example-terraform-estate/README.md +32 -5
  15. package/example-terraform-estate/chant.workspace.json +1 -1
  16. package/example-terraform-estate/recorded/adoption/platform.json +72 -0
  17. package/example-terraform-estate/recorded/adoption/prod.json +224 -0
  18. package/example-three-cloud/README.md +111 -18
  19. package/example-three-cloud/aws/Pulumi.yaml +15 -0
  20. package/example-three-cloud/aws/index.ts +174 -0
  21. package/example-three-cloud/aws/package-lock.json +2725 -0
  22. package/example-three-cloud/aws/package.json +14 -0
  23. package/example-three-cloud/aws/tsconfig.json +17 -0
  24. package/example-three-cloud/azure/main.tf +48 -0
  25. package/example-three-cloud/azure/site.tf +104 -0
  26. package/example-three-cloud/chant.config.json +9 -0
  27. package/example-three-cloud/chant.workspace.json +30 -4
  28. package/example-three-cloud/dns/chant.config.ts +26 -1
  29. package/example-three-cloud/dns/src/records.component.ts +32 -6
  30. package/example-three-cloud/package-lock.json +48 -27
  31. package/example-three-cloud/package.json +8 -6
  32. package/example-three-cloud/scripts/emulators-up.sh +28 -1
  33. package/example-three-cloud/scripts/front-door.ts +679 -86
  34. package/package.json +13 -6
  35. package/web/adopt-pulumi.js +114 -0
  36. package/web/adopt-pulumi.test.js +28 -0
  37. package/web/adopt.js +203 -0
  38. package/web/adopt.test.js +27 -0
  39. package/web/app.js +358 -10
  40. package/web/carve-steps.js +1 -1
  41. package/web/carve-steps.test.js +2 -2
  42. package/web/change-set-overlay.js +12 -5
  43. package/web/change-set-overlay.test.js +22 -0
  44. package/web/drift-stream.js +241 -0
  45. package/web/drift-stream.test.js +146 -0
  46. package/web/edge-weight.d.ts +1 -1
  47. package/web/edge-weight.js +5 -1
  48. package/web/edge-weight.test.js +19 -0
  49. package/web/graph-query.js +180 -0
  50. package/web/graph-query.test.js +49 -0
  51. package/web/graph.html +107 -0
  52. package/web/index-diff.js +109 -0
  53. package/web/index-diff.test.js +39 -0
  54. package/web/index.html +37 -0
  55. package/web/kiosk-ask-tips.js +15 -5
  56. package/web/kiosk-ask-tips.test.js +14 -1
  57. package/web/kiosk-estate-scene.js +72 -8
  58. package/web/kiosk-light-frame.js +1 -0
  59. package/web/kiosk-light.js +41 -3
  60. package/web/kiosk-member-kind.test.js +140 -0
  61. package/web/kiosk-popover.js +4 -1
  62. package/web/kiosk-side.js +296 -0
  63. package/web/kiosk-side.test.js +249 -0
  64. package/web/kiosk-watch.js +12 -0
  65. package/web/kiosk-watch.test.js +15 -1
  66. package/web/kiosk.html +47 -1
  67. package/web/kiosk.js +106 -7
  68. package/web/member-kind.js +31 -0
  69. package/web/template-apps.js +245 -0
  70. package/web/template-apps.test.js +252 -0
  71. package/web/templates.js +285 -0
  72. package/web/templates.test.js +155 -0
  73. package/web/terragucci-lifecycle.js +112 -62
  74. package/web/terragucci-lifecycle.test.js +29 -1
  75. package/web/terragucci-timeline.js +39 -2
  76. package/web/terragucci-timeline.test.js +42 -1
  77. package/example-three-cloud/aws/chant.config.ts +0 -8
  78. package/example-three-cloud/aws/site.component.ts +0 -13
  79. package/example-three-cloud/aws/src/site.ts +0 -27
  80. package/example-three-cloud/azure/chant.config.ts +0 -1
  81. package/example-three-cloud/azure/src/site.component.ts +0 -13
  82. package/example-three-cloud/azure/src/site.ts +0 -18
  83. /package/example-carve/{legacy-tf → tf-root}/cdn.tf +0 -0
  84. /package/example-carve/{legacy-tf → tf-root}/compute.tf +0 -0
  85. /package/example-carve/{legacy-tf → tf-root}/floci-override.tf.disabled +0 -0
  86. /package/example-carve/{legacy-tf → tf-root}/modules/cdn/main.tf +0 -0
  87. /package/example-carve/{legacy-tf → tf-root}/naming.tf +0 -0
  88. /package/example-carve/{legacy-tf → tf-root}/network.tf +0 -0
  89. /package/example-carve/{legacy-tf → tf-root}/observability.tf +0 -0
  90. /package/example-carve/{legacy-tf → tf-root}/outputs.tf +0 -0
  91. /package/example-carve/{legacy-tf → tf-root}/storage.tf +0 -0
  92. /package/example-carve/{legacy-tf → tf-root}/versions.tf +0 -0
@@ -0,0 +1,285 @@
1
+ // behold#1035: the Templates tab. One row per template the repo's catalog
2
+ // offers (GET /api/templates, terragucci templates list --json): its title,
3
+ // kind, newest version a request may name and that version's attestation. A
4
+ // row's Request button opens a form with one field per input, labelled from
5
+ // the template's template.yml; Submit posts POST /api/templates/request, which
6
+ // dispatches terragucci's request workflow. The run in CI opens the pull
7
+ // request; behold writes nothing. The tab is drawn only on a terragucci repo
8
+ // that sets templates, and never in a public view, an embed or a static export.
9
+ //
10
+ // behold#1036: an app's Add an add-on opens the tab for that app (`forApp`):
11
+ // only add-on templates are listed, each with Request, and the request posts
12
+ // `app` beside the add-on's name. terragucci adds the add-on to the app's root.
13
+
14
+ /** The tab's first line. */
15
+ export const TEMPLATES_LEGEND =
16
+ "Apps this repo can make from a template. Fill in a template's form and Request: behold asks terragucci's request workflow to open a pull request that adds the app, and the pipeline plans it there for review. Nothing changes until that pull request is merged.";
17
+
18
+ /** What Submit says once the dispatch is accepted. */
19
+ export const REQUESTED_WORDS = "Requested. terragucci is opening the pull request.";
20
+
21
+ /** An add-on value naming an output of the app's own module. */
22
+ export const APP_OUTPUT_REF = /^app\.[A-Za-z_][A-Za-z0-9_-]*$/;
23
+
24
+ /** An app name, as chant's template request takes it. */
25
+ export const NAME_PATTERN = /^[a-z][a-z0-9-]{0,39}$/;
26
+
27
+ /** The catalog's rows from the envelope GET /api/templates answers, or []. */
28
+ export function templateRows(answer) {
29
+ return (answer && Array.isArray(answer.results) && answer.results) || [];
30
+ }
31
+
32
+ /** One row's line: title, kind, newest version and its attestation. */
33
+ export function rowFacts(row) {
34
+ const newest = (row.versions || []).find((v) => v.version === row.latest) || (row.versions || [])[0];
35
+ return { title: row.description || row.template, template: row.template, kind: row.kind, version: row.latest, attestation: newest ? newest.attestation : "unknown" };
36
+ }
37
+
38
+ /** The control a field is drawn with: text, number, checkbox, lines (one per line) or json. */
39
+ export function fieldControl(field) {
40
+ if (field.kind === "number") return "number";
41
+ if (field.kind === "bool") return "checkbox";
42
+ if (field.kind === "list" && (!field.of || field.of === "string")) return "lines";
43
+ if (field.kind === "list" || field.kind === "map" || field.kind === "object") return "json";
44
+ return "text";
45
+ }
46
+
47
+ /** The fields a form asks for: a sensitive one is the app's secret store's, never the form's. */
48
+ export function formFields(row) {
49
+ return (row.fields || []).filter((f) => !f.sensitive);
50
+ }
51
+
52
+ const blank = (v) => v === undefined || v === null || v === "";
53
+
54
+ /**
55
+ * The request's inputs from the form's raw values (strings, and a boolean for
56
+ * a checkbox): a number as a number, lines as a list, a JSON field parsed. An
57
+ * empty optional field is left out, so the template's default holds. With
58
+ * `appRefs` (an add-on's form) a value `app.<output>` stays as written: it
59
+ * names an output of the app's own module, whatever the field's kind.
60
+ */
61
+ export function formInputs(fields, raw, { appRefs = false } = {}) {
62
+ const out = {};
63
+ for (const f of fields) {
64
+ const v = raw[f.name];
65
+ const c = fieldControl(f);
66
+ if (c === "checkbox") {
67
+ if (v !== undefined) out[f.name] = !!v;
68
+ continue;
69
+ }
70
+ if (blank(v)) continue;
71
+ if (appRefs && APP_OUTPUT_REF.test(String(v).trim())) out[f.name] = String(v).trim();
72
+ else if (c === "number") out[f.name] = Number(v);
73
+ else if (c === "lines") out[f.name] = String(v).split("\n").map((s) => s.trim()).filter(Boolean);
74
+ else if (c === "json") {
75
+ try {
76
+ out[f.name] = JSON.parse(String(v));
77
+ } catch {
78
+ out[f.name] = String(v);
79
+ }
80
+ } else out[f.name] = String(v);
81
+ }
82
+ return out;
83
+ }
84
+
85
+ /** Whether Submit may be pressed: a name, and a value in every required field. */
86
+ export function canSubmit(fields, raw, name) {
87
+ if (!NAME_PATTERN.test(name || "")) return false;
88
+ return fields.every((f) => !f.required || fieldControl(f) === "checkbox" || !blank(raw[f.name]));
89
+ }
90
+
91
+ /**
92
+ * What the form says under Submit: `answer` is the POST's, `record` the
93
+ * request's state from GET /api/templates/requests/:id. A pull request is a
94
+ * link to `#<n>`; a refusal is its reason code and words.
95
+ */
96
+ export function requestWords(answer, record) {
97
+ if (!answer) return { text: "" };
98
+ if (answer.error) return { text: `${answer.code ? `${answer.code}: ` : ""}${answer.error}${answer.command ? ` Run: ${answer.command}` : ""}`, refused: true };
99
+ if (record && record.state === "ended") {
100
+ if (typeof record.pull_request === "number") return { text: "terragucci opened the pull request", link: { href: record.url || "", text: `#${record.pull_request}` } };
101
+ return { text: `The request run ended (${record.conclusion || "unknown"}) and no pull request is on ${record.branch}.${record.runUrl ? " The run's log says why." : ""}`, refused: true, ...(record.runUrl ? { link: { href: record.runUrl, text: "the run" } } : {}) };
102
+ }
103
+ return { text: REQUESTED_WORDS };
104
+ }
105
+
106
+ /** The rows the tab lists: every template, or for an app (`forApp`) its add-on templates only. */
107
+ export function listedRows(rows, forApp) {
108
+ return forApp ? rows.filter((r) => r.kind === "addon") : rows;
109
+ }
110
+
111
+ /** The legend's line when the tab is open for one app. */
112
+ export const addonLegend = (app) => `Add-ons for ${app}. An add-on goes into ${app}'s own root, so the two are planned and applied together. Request one, and terragucci opens a pull request that adds it.`;
113
+
114
+ /** Draw the tab into `host`. `doc` is the document (a test hands in its own). */
115
+ export function renderTemplates(host, s, ui, doc = document) {
116
+ const el = (tag, cls, text) => {
117
+ const n = doc.createElement(tag);
118
+ if (cls) n.className = cls;
119
+ if (text !== undefined) n.textContent = text;
120
+ return n;
121
+ };
122
+ host.replaceChildren();
123
+ host.appendChild(el("div", "tg-legend", TEMPLATES_LEGEND));
124
+ const a = s.answer;
125
+ if (!a) return void host.appendChild(el("div", "tg-legend", "reading the templates"));
126
+ if (a.error && !a.results) return void host.appendChild(el("div", "tg-refusal", `${a.code ? `${a.code}: ` : ""}${a.error}`));
127
+ if (s.forApp) {
128
+ host.appendChild(el("div", "tg-legend tp-for-app", addonLegend(s.forApp)));
129
+ const all = el("button", "tp-all", "Show every template");
130
+ all.type = "button";
131
+ all.addEventListener("click", () => ui.forApp(null));
132
+ host.appendChild(all);
133
+ }
134
+ const rows = listedRows(templateRows(a), s.forApp);
135
+ if (!rows.length) host.appendChild(el("div", "tg-legend", s.forApp ? "The catalog offers no add-on template with a version a request may name." : "The catalog offers no template with a version a request may name."));
136
+ for (const row of rows) {
137
+ const f = rowFacts(row);
138
+ const card = el("div", "ad-card");
139
+ card.appendChild(el("h3", null, f.title));
140
+ card.appendChild(el("div", "tg-legend", `${f.template} · ${f.kind} · ${f.version} · ${f.attestation}`));
141
+ const open = s.open === row.template;
142
+ if ((s.forApp ? f.kind === "addon" : f.kind === "app") && !open) {
143
+ const b = el("button", "tp-request", "Request");
144
+ b.type = "button";
145
+ b.addEventListener("click", () => ui.open(row.template));
146
+ card.appendChild(b);
147
+ }
148
+ if (open) card.appendChild(renderForm(row, s, ui, el));
149
+ host.appendChild(card);
150
+ }
151
+ }
152
+
153
+ function renderForm(row, s, ui, el) {
154
+ const fields = formFields(row);
155
+ const form = el("form", "tp-form");
156
+ const submit = el("button", "tp-submit", s.sending ? "Requesting" : "Submit");
157
+ submit.type = "submit";
158
+ const refresh = () => {
159
+ submit.disabled = !!s.sending || !canSubmit(fields, s.raw, s.name);
160
+ };
161
+ const label = (text, required) => el("label", "ad-label", required ? `${text} (required)` : text);
162
+
163
+ if (s.forApp) form.appendChild(el("div", "tg-legend tp-app", `into the app ${s.forApp}`));
164
+ form.appendChild(label(s.forApp ? "Add-on name" : "App name", true));
165
+ const name = el("input", "tp-name");
166
+ name.type = "text";
167
+ name.name = "name";
168
+ name.required = true;
169
+ name.value = s.name || "";
170
+ name.placeholder = "a lowercase letter, then letters, digits and -";
171
+ name.addEventListener("input", () => {
172
+ s.name = name.value;
173
+ refresh();
174
+ });
175
+ form.appendChild(name);
176
+
177
+ for (const f of fields) {
178
+ const c = fieldControl(f);
179
+ form.appendChild(label(f.label || f.name, !!f.required && c !== "checkbox"));
180
+ let input;
181
+ if (c === "lines" || c === "json") {
182
+ input = el("textarea", "tp-field");
183
+ if (c === "lines") input.placeholder = "one per line";
184
+ } else {
185
+ input = el("input", "tp-field");
186
+ input.type = c;
187
+ }
188
+ input.name = f.name;
189
+ if (f.required && c !== "checkbox") input.required = true;
190
+ if (f.description) input.title = f.description;
191
+ const raw = s.raw[f.name];
192
+ if (c === "checkbox") {
193
+ input.checked = raw !== undefined ? !!raw : f.default === true;
194
+ input.addEventListener("change", () => {
195
+ s.raw[f.name] = input.checked;
196
+ refresh();
197
+ });
198
+ } else {
199
+ input.value = raw !== undefined ? String(raw) : "";
200
+ if (f.default !== undefined && c !== "lines") input.placeholder = `default ${typeof f.default === "string" ? f.default : JSON.stringify(f.default)}`;
201
+ input.addEventListener("input", () => {
202
+ s.raw[f.name] = input.value;
203
+ refresh();
204
+ });
205
+ }
206
+ form.appendChild(input);
207
+ }
208
+
209
+ const row2 = el("div", "ad-row");
210
+ row2.appendChild(submit);
211
+ const cancel = el("button", null, "Cancel");
212
+ cancel.type = "button";
213
+ cancel.addEventListener("click", () => ui.close());
214
+ row2.appendChild(cancel);
215
+ form.appendChild(row2);
216
+ form.addEventListener("submit", (e) => {
217
+ if (e && e.preventDefault) e.preventDefault();
218
+ if (submit.disabled) return;
219
+ ui.submit(row, formInputs(fields, s.raw, { appRefs: !!s.forApp }));
220
+ });
221
+ refresh();
222
+
223
+ const words = requestWords(s.answerOf, s.record);
224
+ if (words.text) {
225
+ const out = el("div", words.refused ? "tg-refusal tp-result" : "tg-legend tp-result", words.text);
226
+ if (words.link) {
227
+ const a = el("a", "tp-pr", words.link.text);
228
+ a.href = words.link.href;
229
+ a.target = "_blank";
230
+ a.rel = "noopener";
231
+ out.appendChild(el("span", null, " "));
232
+ out.appendChild(a);
233
+ }
234
+ form.appendChild(out);
235
+ }
236
+ return form;
237
+ }
238
+
239
+ /** Mount the tab. `fetchJson(url, init)` answers parsed JSON. */
240
+ export function startTemplates(host, { fetchJson, events, toast = () => {}, doc }) {
241
+ const s = { answer: null, open: null, name: "", raw: {}, sending: false, answerOf: null, record: null, forApp: null };
242
+ const redraw = () => renderTemplates(host, s, ui, doc);
243
+ const read = async () => {
244
+ s.answer = await fetchJson("/api/templates").catch((e) => ({ error: String(e) }));
245
+ redraw();
246
+ };
247
+ const readRecord = async () => {
248
+ const id = s.answerOf && s.answerOf.id;
249
+ if (!id) return;
250
+ s.record = await fetchJson(`/api/templates/requests/${encodeURIComponent(id)}`).catch(() => s.record);
251
+ redraw();
252
+ };
253
+ const ui = {
254
+ open: (template) => {
255
+ Object.assign(s, { open: template, name: "", raw: {}, answerOf: null, record: null });
256
+ redraw();
257
+ },
258
+ close: () => {
259
+ s.open = null;
260
+ redraw();
261
+ },
262
+ // behold#1036: the tab for one app's add-ons, or with null every template again.
263
+ forApp: (app) => {
264
+ Object.assign(s, { forApp: app || null, open: null, name: "", raw: {}, answerOf: null, record: null });
265
+ redraw();
266
+ },
267
+ submit: async (row, inputs) => {
268
+ s.sending = true;
269
+ redraw();
270
+ const body = { template: row.template, version: row.latest, name: s.name, ...(s.forApp ? { app: s.forApp } : {}), inputs };
271
+ s.answerOf = await fetchJson("/api/templates/request", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }).catch((e) => ({ error: String(e) }));
272
+ s.sending = false;
273
+ s.record = null;
274
+ if (s.answerOf && s.answerOf.error) toast(`✗ request ${s.name}: ${s.answerOf.error}`, false);
275
+ else toast(`▶ ${REQUESTED_WORDS}`, true);
276
+ redraw();
277
+ await readRecord();
278
+ },
279
+ };
280
+ if (events) events.addEventListener("template-request", (e) => {
281
+ if (s.answerOf && s.answerOf.id === e.data) readRecord();
282
+ });
283
+ read();
284
+ return { reload: read, state: s, ui };
285
+ }
@@ -0,0 +1,155 @@
1
+ // behold#1035: the Templates tab. The pure half is tested as data; the form is
2
+ // drawn into a small stand-in document (no DOM library in this repo), enough
3
+ // to read each control's tag and type, type into it and press Submit.
4
+ import { describe, expect, it } from "vitest";
5
+ import { canSubmit, fieldControl, formInputs, renderTemplates, requestWords, REQUESTED_WORDS, rowFacts, startTemplates } from "./templates.js";
6
+
7
+ class Node {
8
+ constructor(tag) {
9
+ this.tagName = tag.toUpperCase();
10
+ this.children = [];
11
+ this.listeners = {};
12
+ this.textContent = "";
13
+ this.className = "";
14
+ this.value = "";
15
+ this.checked = false;
16
+ this.disabled = false;
17
+ }
18
+ appendChild(n) {
19
+ this.children.push(n);
20
+ return n;
21
+ }
22
+ replaceChildren(...n) {
23
+ this.children = n;
24
+ }
25
+ addEventListener(type, f) {
26
+ (this.listeners[type] ||= []).push(f);
27
+ }
28
+ fire(type) {
29
+ for (const f of this.listeners[type] || []) f({ preventDefault() {} });
30
+ }
31
+ /** Every node below this one, depth first. */
32
+ all() {
33
+ return this.children.flatMap((c) => [c, ...c.all()]);
34
+ }
35
+ text() {
36
+ return [this.textContent, ...this.children.map((c) => c.text())].join("");
37
+ }
38
+ }
39
+ const doc = { createElement: (tag) => new Node(tag) };
40
+
41
+ const row = {
42
+ template: "acme/bucket/aws",
43
+ kind: "app",
44
+ description: "A private bucket for one app's data",
45
+ latest: "1.2.0",
46
+ versions: [{ version: "1.2.0", attestation: "signed" }],
47
+ fields: [
48
+ { name: "bucket_name", kind: "string", label: "Bucket name", required: true },
49
+ { name: "retention_days", kind: "number", label: "Days to keep objects", default: 30, required: false },
50
+ { name: "versioned", kind: "bool", label: "Keep old versions", default: false, required: false },
51
+ { name: "kms_key", kind: "string", label: "KMS key", required: false, sensitive: true },
52
+ ],
53
+ };
54
+ const answer = { schema: 1, command: "templates", exit: 0, status: "ok", results: [row] };
55
+
56
+ const inputs = (host) => host.all().filter((n) => n.tagName === "INPUT" || n.tagName === "TEXTAREA");
57
+ const submitOf = (host) => host.all().find((n) => n.className === "tp-submit");
58
+ const formOf = (host) => host.all().find((n) => n.tagName === "FORM");
59
+
60
+ /** fetchJson answering the catalog, the dispatch's 202 and the run's record. */
61
+ function server(record) {
62
+ const posts = [];
63
+ const fetchJson = async (url, init) => {
64
+ if (url === "/api/templates") return answer;
65
+ if (url === "/api/templates/request") {
66
+ posts.push(JSON.parse(init.body));
67
+ return { dispatched: true, id: "r1", branch: "request/bucket/orders" };
68
+ }
69
+ if (url === "/api/templates/requests/r1") return record();
70
+ throw new Error(url);
71
+ };
72
+ return { fetchJson, posts };
73
+ }
74
+
75
+ describe("the Templates tab (behold#1035)", () => {
76
+ it("lists a row with the template's title, kind, newest version and attestation", () => {
77
+ expect(rowFacts(row)).toEqual({ title: "A private bucket for one app's data", template: "acme/bucket/aws", kind: "app", version: "1.2.0", attestation: "signed" });
78
+ const host = new Node("section");
79
+ renderTemplates(host, { answer, open: null, raw: {} }, { open() {} }, doc);
80
+ expect(host.text()).toContain("acme/bucket/aws · app · 1.2.0 · signed");
81
+ expect(host.all().some((n) => n.tagName === "BUTTON" && n.textContent === "Request")).toBe(true);
82
+ });
83
+
84
+ it("draws a text input for a string, a number input for a number and a checkbox for a bool, and no field for a sensitive input", async () => {
85
+ const host = new Node("section");
86
+ const { fetchJson } = server(() => ({}));
87
+ const t = startTemplates(host, { fetchJson, doc });
88
+ await new Promise((r) => setTimeout(r, 0));
89
+ t.ui.open("acme/bucket/aws");
90
+ const fields = inputs(host).filter((n) => n.name !== "name");
91
+ expect(fields.map((n) => [n.name, n.tagName, n.type])).toEqual([
92
+ ["bucket_name", "INPUT", "text"],
93
+ ["retention_days", "INPUT", "number"],
94
+ ["versioned", "INPUT", "checkbox"],
95
+ ]);
96
+ expect(host.text()).toContain("Bucket name (required)");
97
+ expect(host.text()).not.toContain("KMS key");
98
+ expect(fieldControl({ kind: "list", of: "string" })).toBe("lines");
99
+ });
100
+
101
+ it("keeps Submit disabled until the required field has a value, then posts typed inputs; a 202 and a run with pull_request 7 show a link to #7", async () => {
102
+ let record = { id: "r1", state: "dispatched", branch: "request/bucket/orders" };
103
+ const host = new Node("section");
104
+ const { fetchJson, posts } = server(() => record);
105
+ const t = startTemplates(host, { fetchJson, doc });
106
+ await new Promise((r) => setTimeout(r, 0));
107
+ t.ui.open("acme/bucket/aws");
108
+ const byName = (n) => inputs(host).find((x) => x.name === n);
109
+ const type = (n, v) => {
110
+ byName(n).value = v;
111
+ byName(n).fire("input");
112
+ };
113
+ expect(submitOf(host).disabled).toBe(true);
114
+ type("name", "orders");
115
+ expect(submitOf(host).disabled).toBe(true);
116
+ type("bucket_name", "orders-data");
117
+ expect(submitOf(host).disabled).toBe(false);
118
+ type("bucket_name", "");
119
+ expect(submitOf(host).disabled).toBe(true);
120
+ type("bucket_name", "orders-data");
121
+ type("retention_days", "7");
122
+
123
+ formOf(host).fire("submit");
124
+ await new Promise((r) => setTimeout(r, 0));
125
+ expect(posts).toEqual([{ template: "acme/bucket/aws", version: "1.2.0", name: "orders", inputs: { bucket_name: "orders-data", retention_days: 7 } }]);
126
+ expect(host.text()).toContain(REQUESTED_WORDS);
127
+
128
+ record = { id: "r1", state: "ended", conclusion: "success", branch: "request/bucket/orders", pull_request: 7, url: "https://github.com/acme/infra/pull/7" };
129
+ const listeners = {};
130
+ // The run's end arrives as a template-request event naming the request.
131
+ const events = { addEventListener: (type, f) => (listeners[type] = f) };
132
+ const host2 = new Node("section");
133
+ const t2 = startTemplates(host2, { fetchJson, events, doc });
134
+ await new Promise((r) => setTimeout(r, 0));
135
+ t2.ui.open("acme/bucket/aws");
136
+ Object.assign(t2.state, { name: "orders", raw: { bucket_name: "orders-data" } });
137
+ await t2.ui.submit(row, { bucket_name: "orders-data" });
138
+ listeners["template-request"]({ data: "r1" });
139
+ await new Promise((r) => setTimeout(r, 0));
140
+ const link = host2.all().find((n) => n.tagName === "A");
141
+ expect(link.textContent).toBe("#7");
142
+ expect(link.href).toBe("https://github.com/acme/infra/pull/7");
143
+ });
144
+
145
+ it("words a refusal with its reason code", () => {
146
+ expect(requestWords({ error: "inputs.bucket_name is required", code: "missing-input" }, null)).toEqual({ text: "missing-input: inputs.bucket_name is required", refused: true });
147
+ expect(requestWords({ dispatched: true, id: "r1" }, { state: "running" })).toEqual({ text: REQUESTED_WORDS });
148
+ });
149
+
150
+ it("reads the form's values by kind, leaving an empty optional field to its default", () => {
151
+ const f = [...row.fields, { name: "readers", kind: "list", of: "string", required: false }];
152
+ expect(formInputs(f, { bucket_name: "b", retention_days: "", versioned: true, readers: "a\n\n b \n" })).toEqual({ bucket_name: "b", versioned: true, readers: ["a", "b"] });
153
+ expect(canSubmit(f, { bucket_name: "b" }, "Orders")).toBe(false);
154
+ });
155
+ });
@@ -126,6 +126,53 @@ export function laneGateCards(lane, now = new Date()) {
126
126
  });
127
127
  }
128
128
 
129
+ const ACTION_TITLE = {
130
+ waiting: (a) => `${a.name} on ${a.root} waits for an approval${a.requester ? ` by someone other than ${a.requester}` : ""}`,
131
+ expired: (a) => `${a.name} on ${a.root}: the request for an approval expired`,
132
+ approved: (a) => `${a.name} on ${a.root} approved by ${a.approval.by}, not run yet`,
133
+ applied: (a) => (a.applied && a.applied.result ? `${a.name} on ${a.root} ran: ${a.applied.result}` : `${a.name} on ${a.root} ran (outcome not recorded)`),
134
+ failed: (a) => `${a.name} on ${a.root} failed`,
135
+ refused: (a) => `${a.name} on ${a.root} refused: an approval stands for another plan`,
136
+ };
137
+
138
+ const ACTION_NOTE = "An action runs only once a person other than the one who asked approves its plan digest: that person runs the line at their shell. behold does not approve, and does not run the action.";
139
+
140
+ /**
141
+ * behold#1037: each day-2 action's gate as a card, in the shape of a wave's:
142
+ * who asked, its state, the digest, who approved and how the run ended, and
143
+ * while it waits the `terragucci approve action` line a second person runs.
144
+ * `root` keeps one app's. No button but Copy.
145
+ */
146
+ export function laneActionCards(lane, now = new Date(), { root = null } = {}) {
147
+ if (!lane || !lane.found || !Array.isArray(lane.actions)) return [];
148
+ return lane.actions
149
+ .filter((a) => !root || a.root === root)
150
+ .map((a) => {
151
+ const facts = [];
152
+ if (a.pending) facts.push(`asked${a.requester ? ` by ${a.requester}` : ""} ${clock(a.pending.timestamp, now)}, ${ago(a.pending.timestamp, now)}`);
153
+ if (a.approval) facts.push(`${a.state === "refused" ? `approved for plan ${short(a.refused && a.refused.digest) || "(none)"} by` : "approved by"} ${approvalWords(a.approval, now)}`);
154
+ if (a.applied) facts.push(`${a.applied.result === "failed" ? "failed" : "ran"} ${clock(a.applied.finished || a.applied.at, now)}, ${ago(a.applied.finished || a.applied.at, now)}${typeof a.applied.exit === "number" ? `, exit ${a.applied.exit}` : ""}`);
155
+ if (a.digest) facts.push(`plan ${short(a.digest)}`);
156
+ facts.push(a.address);
157
+ if (modeWords(a)) facts.push(modeWords(a));
158
+ const uncounted = (a.uncounted || []).map((u) => `${u.approval.by}'s approval of this plan does not count: ${u.reason}`);
159
+ const job = a.pending && a.pending.url ? a.pending.url : null;
160
+ return {
161
+ gate: a.gate,
162
+ root: a.root,
163
+ name: a.name,
164
+ state: a.state,
165
+ tone: a.state === "waiting" ? "wave" : a.state === "failed" || a.state === "refused" ? "failed" : a.state === "expired" ? "none" : "ok",
166
+ title: ACTION_TITLE[a.state] ? ACTION_TITLE[a.state](a) : `${a.name} on ${a.root}: ${a.state}`,
167
+ facts: facts.join(" · "),
168
+ ...(uncounted.length ? { uncounted } : {}),
169
+ source: sourceWords(a.source, now),
170
+ ...(a.command ? { command: a.command, note: ACTION_NOTE } : {}),
171
+ ...(job ? { job } : {}),
172
+ };
173
+ });
174
+ }
175
+
129
176
  /** Each locked root: who holds it and since when, and the commit it was read from. */
130
177
  export function laneLockRows(lane, now = new Date()) {
131
178
  if (!lane || !lane.found) return [];
@@ -158,68 +205,7 @@ export function renderLane(host, lane, polled, now, ui) {
158
205
  e.textContent = `the reports' index could not be checked: ${polled.reports.error}`;
159
206
  host.appendChild(e);
160
207
  }
161
- for (const g of laneGateCards(lane, now)) {
162
- const box = document.createElement("div");
163
- box.className = `ws-gate tg-lane-gate tg-${g.tone}`;
164
- const title = document.createElement("div");
165
- title.className = "ws-gate-title";
166
- title.textContent = g.title;
167
- const facts = document.createElement("div");
168
- facts.className = "ws-gate-facts";
169
- facts.textContent = g.facts;
170
- const src = document.createElement("div");
171
- src.className = "ws-gate-note";
172
- src.textContent = `from ${g.source}`;
173
- box.append(title, facts);
174
- for (const u of g.uncounted || []) {
175
- const why = document.createElement("div");
176
- why.className = "ws-gate-note";
177
- why.textContent = u;
178
- box.appendChild(why);
179
- }
180
- box.appendChild(src);
181
- for (const o of g.overrides || []) {
182
- const what = document.createElement("div");
183
- what.className = "ws-gate-note";
184
- what.textContent = o.text;
185
- const cmd = document.createElement("code");
186
- cmd.className = "tg-command";
187
- cmd.textContent = o.command;
188
- const copy = ui.button("Copy", "", () => ui.copy(o.command, copy));
189
- copy.title = "Copy the line. Run it at your shell, with your reason: the override is yours.";
190
- box.append(what, cmd, copy);
191
- if (o.job) {
192
- const links = document.createElement("div");
193
- links.className = "ws-gate-note";
194
- links.appendChild(ui.link("job", o.job));
195
- box.appendChild(links);
196
- }
197
- }
198
- if (g.overrideNote) {
199
- const n = document.createElement("div");
200
- n.className = "ws-gate-note";
201
- n.textContent = g.overrideNote;
202
- box.appendChild(n);
203
- }
204
- if (g.command) {
205
- const cmd = document.createElement("code");
206
- cmd.className = "tg-command";
207
- cmd.textContent = g.command;
208
- const copy = ui.button("Copy", "", () => ui.copy(g.command, copy));
209
- copy.title = "Copy the line. Run it at your shell: the approval or answer is yours.";
210
- const note = document.createElement("div");
211
- note.className = "ws-gate-note";
212
- note.textContent = g.note;
213
- box.append(cmd, copy, note);
214
- }
215
- if (g.job) {
216
- const links = document.createElement("div");
217
- links.className = "ws-gate-note";
218
- links.appendChild(ui.link("job", g.job));
219
- box.appendChild(links);
220
- }
221
- host.appendChild(box);
222
- }
208
+ for (const g of [...laneGateCards(lane, now), ...laneActionCards(lane, now)]) host.appendChild(gateCardElement(g, ui));
223
209
  for (const l of laneLockRows(lane, now)) {
224
210
  const row = document.createElement("div");
225
211
  row.className = "tg-root tg-lock";
@@ -233,3 +219,67 @@ export function renderLane(host, lane, polled, now, ui) {
233
219
  host.appendChild(row);
234
220
  }
235
221
  }
222
+
223
+ /** One card from laneGateCards or laneActionCards as DOM: title, facts, source, and the line to copy. `doc` is the document (a test hands in its own). */
224
+ export function gateCardElement(g, ui, doc = document) {
225
+ const box = doc.createElement("div");
226
+ box.className = `ws-gate tg-lane-gate tg-${g.tone}`;
227
+ const title = doc.createElement("div");
228
+ title.className = "ws-gate-title";
229
+ title.textContent = g.title;
230
+ const facts = doc.createElement("div");
231
+ facts.className = "ws-gate-facts";
232
+ facts.textContent = g.facts;
233
+ const src = doc.createElement("div");
234
+ src.className = "ws-gate-note";
235
+ src.textContent = `from ${g.source}`;
236
+ box.append(title, facts);
237
+ for (const u of g.uncounted || []) {
238
+ const why = doc.createElement("div");
239
+ why.className = "ws-gate-note";
240
+ why.textContent = u;
241
+ box.appendChild(why);
242
+ }
243
+ box.appendChild(src);
244
+ for (const o of g.overrides || []) {
245
+ const what = doc.createElement("div");
246
+ what.className = "ws-gate-note";
247
+ what.textContent = o.text;
248
+ const cmd = doc.createElement("code");
249
+ cmd.className = "tg-command";
250
+ cmd.textContent = o.command;
251
+ const copy = ui.button("Copy", "", () => ui.copy(o.command, copy));
252
+ copy.title = "Copy the line. Run it at your shell, with your reason: the override is yours.";
253
+ box.append(what, cmd, copy);
254
+ if (o.job) {
255
+ const links = doc.createElement("div");
256
+ links.className = "ws-gate-note";
257
+ links.appendChild(ui.link("job", o.job));
258
+ box.appendChild(links);
259
+ }
260
+ }
261
+ if (g.overrideNote) {
262
+ const n = doc.createElement("div");
263
+ n.className = "ws-gate-note";
264
+ n.textContent = g.overrideNote;
265
+ box.appendChild(n);
266
+ }
267
+ if (g.command) {
268
+ const cmd = doc.createElement("code");
269
+ cmd.className = "tg-command";
270
+ cmd.textContent = g.command;
271
+ const copy = ui.button("Copy", "", () => ui.copy(g.command, copy));
272
+ copy.title = "Copy the line. Run it at your shell: the approval or answer is yours.";
273
+ const note = doc.createElement("div");
274
+ note.className = "ws-gate-note";
275
+ note.textContent = g.note;
276
+ box.append(cmd, copy, note);
277
+ }
278
+ if (g.job) {
279
+ const links = doc.createElement("div");
280
+ links.className = "ws-gate-note";
281
+ links.appendChild(ui.link("job", g.job));
282
+ box.appendChild(links);
283
+ }
284
+ return box;
285
+ }
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { holderWords, laneGateCards, laneLegend, laneLockRows, sourceWords } from "./terragucci-lifecycle.js";
2
+ import { holderWords, laneActionCards, laneGateCards, laneLegend, laneLockRows, sourceWords } from "./terragucci-lifecycle.js";
3
3
 
4
4
  const NOW = new Date("2026-10-09T12:00:00Z");
5
5
  const source = { branch: "chant/lifecycle", commit: "1a2b3c4d5e6f7a8b", committed: "2026-10-09T10:00:00Z", path: "_gates/tf-apply.jsonl" };
@@ -93,3 +93,31 @@ describe("the chant/lifecycle lane, dated (#505)", () => {
93
93
  expect(l.title).toContain("chant/lifecycle 1a2b3c4d5e6f");
94
94
  });
95
95
  });
96
+
97
+ describe("a day-2 action's gate card (behold#1037)", () => {
98
+ const DA = `sha256:${"a".repeat(64)}`;
99
+ const base = { op: "tf-action", gate: "apps/orders:module.app.action.aws_lambda_invoke.rotate", root: "apps/orders", address: "module.app.action.aws_lambda_invoke.rotate", name: "rotate", requester: "lee", digest: DA, approvalMode: { mode: "ledger", from: "base" }, source: { ...source, path: "_gates/tf-action.jsonl" } };
100
+ const waiting = { ...base, state: "waiting", pending: { timestamp: "2026-10-09T10:00:00Z", expiresAt: "2099-01-01T00:00:00Z", url: "https://github.com/acme/shop/actions/runs/401" }, command: `npx terragucci approve action apps/orders --plan ${DA}`, uncounted: [{ approval: { by: "lee", at: "2026-10-09T10:30:00Z", signed: false }, reason: "the requester's own approval never counts" }] };
101
+ const applied = { ...base, gate: "apps/search:module.app.action.aws_lambda_invoke.rotate", root: "apps/search", state: "applied", approval: { by: "dana", at: "2026-10-09T11:00:00Z", signed: false }, applied: { at: "2026-10-09T11:05:00Z", approvedAt: "2026-10-09T11:00:00Z", approvedBy: "dana", result: "ok", finished: "2026-10-09T11:06:00Z", exit: 0 } };
102
+
103
+ it("shows the digest, the waiting state and the approve line for a second person, with no button but Copy", () => {
104
+ const [c] = laneActionCards(lane({ actions: [waiting, applied] }), NOW, { root: "apps/orders" });
105
+ expect(c.title).toBe("rotate on apps/orders waits for an approval by someone other than lee");
106
+ expect(c.tone).toBe("wave");
107
+ expect(c.command).toBe(`npx terragucci approve action apps/orders --plan ${DA}`);
108
+ expect(c.note).toContain("a person other than the one who asked");
109
+ expect(c.facts).toContain(`plan ${"a".repeat(12)}`);
110
+ expect(c.uncounted).toEqual(["lee's approval of this plan does not count: the requester's own approval never counts"]);
111
+ expect(c.job).toBe("https://github.com/acme/shop/actions/runs/401");
112
+ });
113
+
114
+ it("shows a finished run's ok, and nothing for a lane without actions", () => {
115
+ const cards = laneActionCards(lane({ actions: [waiting, applied] }), NOW);
116
+ expect(cards.map((c) => c.root)).toEqual(["apps/orders", "apps/search"]);
117
+ expect(cards[1]).toMatchObject({ title: "rotate on apps/search ran: ok", tone: "ok" });
118
+ expect(cards[1].command).toBeUndefined();
119
+ expect(cards[1].facts).toContain("ran 11:06 UTC, 54m ago, exit 0");
120
+ expect(laneActionCards(lane(), NOW)).toEqual([]);
121
+ expect(laneActionCards(lane({ found: false, actions: [waiting] }), NOW)).toEqual([]);
122
+ });
123
+ });