@intentius/behold 0.30.1 → 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 (129) hide show
  1. package/AGENTS.md +475 -16
  2. package/README.md +25 -19
  3. package/demos.json +14 -9
  4. package/dist/cli.js +54900 -26771
  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-terralith/README.md +1 -1
  19. package/example-three-cloud/README.md +111 -18
  20. package/example-three-cloud/aws/Pulumi.yaml +15 -0
  21. package/example-three-cloud/aws/index.ts +174 -0
  22. package/example-three-cloud/aws/package-lock.json +2725 -0
  23. package/example-three-cloud/aws/package.json +14 -0
  24. package/example-three-cloud/aws/tsconfig.json +17 -0
  25. package/example-three-cloud/azure/main.tf +48 -0
  26. package/example-three-cloud/azure/site.tf +104 -0
  27. package/example-three-cloud/chant.config.json +9 -0
  28. package/example-three-cloud/chant.workspace.json +30 -4
  29. package/example-three-cloud/dns/chant.config.ts +26 -1
  30. package/example-three-cloud/dns/src/records.component.ts +32 -6
  31. package/example-three-cloud/package-lock.json +48 -27
  32. package/example-three-cloud/package.json +8 -6
  33. package/example-three-cloud/scripts/emulators-up.sh +28 -1
  34. package/example-three-cloud/scripts/front-door.ts +679 -86
  35. package/package.json +13 -6
  36. package/web/adopt-pulumi.js +114 -0
  37. package/web/adopt-pulumi.test.js +28 -0
  38. package/web/adopt.js +203 -0
  39. package/web/adopt.test.js +27 -0
  40. package/web/app.js +614 -19
  41. package/web/carve-steps.js +1 -1
  42. package/web/carve-steps.test.js +2 -2
  43. package/web/change-set-overlay.js +12 -5
  44. package/web/change-set-overlay.test.js +22 -0
  45. package/web/drift-stream.js +241 -0
  46. package/web/drift-stream.test.js +146 -0
  47. package/web/edge-weight.d.ts +1 -1
  48. package/web/edge-weight.js +5 -1
  49. package/web/edge-weight.test.js +19 -0
  50. package/web/embed.js +2 -2
  51. package/web/event-help-modal.js +18 -12
  52. package/web/event-help-modal.test.js +28 -1
  53. package/web/graph-query.js +180 -0
  54. package/web/graph-query.test.js +49 -0
  55. package/web/graph.html +107 -0
  56. package/web/index-diff.js +109 -0
  57. package/web/index-diff.test.js +39 -0
  58. package/web/index.html +55 -0
  59. package/web/kiosk-ask-layout.js +85 -0
  60. package/web/kiosk-ask-layout.test.js +83 -0
  61. package/web/kiosk-ask-tips.js +477 -0
  62. package/web/kiosk-ask-tips.test.js +372 -0
  63. package/web/kiosk-ask.js +774 -0
  64. package/web/kiosk-ask.test.js +593 -0
  65. package/web/kiosk-banner.js +108 -0
  66. package/web/kiosk-banner.test.js +72 -0
  67. package/web/kiosk-center-cards.test.js +110 -0
  68. package/web/kiosk-estate-scene.js +267 -0
  69. package/web/kiosk-estate-scene.test.js +21 -0
  70. package/web/kiosk-event-help.js +4 -1
  71. package/web/kiosk-graph-pane.js +63 -0
  72. package/web/kiosk-graph-pane.test.js +105 -0
  73. package/web/kiosk-light-frame.js +197 -0
  74. package/web/kiosk-light.js +547 -0
  75. package/web/kiosk-light.test.js +297 -0
  76. package/web/kiosk-member-kind.test.js +140 -0
  77. package/web/kiosk-metrics.js +7 -4
  78. package/web/kiosk-modal-sticky.test.js +2 -1
  79. package/web/kiosk-popover.js +4 -1
  80. package/web/kiosk-refit.test.js +81 -0
  81. package/web/kiosk-reset.js +49 -0
  82. package/web/kiosk-reset.test.js +11 -0
  83. package/web/kiosk-shot.js +40 -2
  84. package/web/kiosk-shot.test.js +23 -1
  85. package/web/kiosk-side.js +296 -0
  86. package/web/kiosk-side.test.js +249 -0
  87. package/web/kiosk-vendor.js +85 -7
  88. package/web/kiosk-vendor.test.js +9 -9
  89. package/web/kiosk-watch.js +20 -4
  90. package/web/kiosk-watch.test.js +15 -1
  91. package/web/kiosk.html +153 -1
  92. package/web/kiosk.js +252 -27
  93. package/web/kiosk.test.js +25 -1
  94. package/web/member-kind.js +31 -0
  95. package/web/small-stage.test.js +4 -0
  96. package/web/template-apps.js +245 -0
  97. package/web/template-apps.test.js +252 -0
  98. package/web/templates.js +285 -0
  99. package/web/templates.test.js +155 -0
  100. package/web/terragucci-change.js +30 -13
  101. package/web/terragucci-lifecycle.js +112 -62
  102. package/web/terragucci-lifecycle.test.js +29 -1
  103. package/web/terragucci-timeline.js +39 -2
  104. package/web/terragucci-timeline.test.js +42 -1
  105. package/web/tool-mark.js +4 -4
  106. package/web/tool-mark.test.js +1 -1
  107. package/web/vendors/atmos.svg +1 -0
  108. package/web/vendors/chant.svg +1 -0
  109. package/web/vendors/choudoufu.svg +1 -0
  110. package/web/vendors/terragrunt.svg +9 -0
  111. package/web/vendors/terragucci.svg +1 -0
  112. package/example-three-cloud/aws/chant.config.ts +0 -8
  113. package/example-three-cloud/aws/site.component.ts +0 -13
  114. package/example-three-cloud/aws/src/site.ts +0 -27
  115. package/example-three-cloud/azure/chant.config.ts +0 -1
  116. package/example-three-cloud/azure/src/site.component.ts +0 -13
  117. package/example-three-cloud/azure/src/site.ts +0 -18
  118. package/web/vendors/choudoufu-128.png +0 -0
  119. package/web/vendors/choudoufu-64.png +0 -0
  120. /package/example-carve/{legacy-tf → tf-root}/cdn.tf +0 -0
  121. /package/example-carve/{legacy-tf → tf-root}/compute.tf +0 -0
  122. /package/example-carve/{legacy-tf → tf-root}/floci-override.tf.disabled +0 -0
  123. /package/example-carve/{legacy-tf → tf-root}/modules/cdn/main.tf +0 -0
  124. /package/example-carve/{legacy-tf → tf-root}/naming.tf +0 -0
  125. /package/example-carve/{legacy-tf → tf-root}/network.tf +0 -0
  126. /package/example-carve/{legacy-tf → tf-root}/observability.tf +0 -0
  127. /package/example-carve/{legacy-tf → tf-root}/outputs.tf +0 -0
  128. /package/example-carve/{legacy-tf → tf-root}/storage.tf +0 -0
  129. /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
+ });
@@ -22,6 +22,7 @@
22
22
 
23
23
  import { ago, clock, hrefOf } from "./terragucci.js";
24
24
  import { coneFact, coneOf, coneResourceLines, fallbackWhy } from "./cone.js";
25
+ import { COVERED_WORDS } from "./kiosk-light.js";
25
26
 
26
27
  export const STATE_WORDS = {
27
28
  "not-started": "queued",
@@ -60,17 +61,27 @@ export function readEdges(answer, progress) {
60
61
  const estate = (from, to) => (bin[from] === "choudoufu" && bin[to] === "choudoufu" ? { estate: true } : {});
61
62
  if (stage === "pull-request") {
62
63
  const run = answer.pull_request.compose && answer.pull_request.compose.wave;
63
- return answer.pull_request.reads.map((r) => ({
64
- from: r.root,
65
- to: r.upstream,
66
- data: r.data,
67
- outputs: r.outputs,
68
- unknown: r.unknown || [],
69
- ...(r.why ? { why: r.why } : {}),
70
- ...(r.composed && run !== undefined ? { composed: run } : {}),
71
- ...estate(r.root, r.upstream),
72
- stage,
73
- }));
64
+ // One line per pair: a root that reads another through two data blocks (an estate's outputs, and a second block
65
+ // for the outputs new in the change) is one read, named by its first block, with every block's unknown outputs.
66
+ const byPair = new Map();
67
+ for (const r of answer.pull_request.reads) {
68
+ const e = {
69
+ from: r.root,
70
+ to: r.upstream,
71
+ data: r.data,
72
+ outputs: r.outputs,
73
+ unknown: r.unknown || [],
74
+ ...(r.why ? { why: r.why } : {}),
75
+ ...(r.composed && run !== undefined ? { composed: run } : {}),
76
+ ...estate(r.root, r.upstream),
77
+ stage,
78
+ };
79
+ const key = `${e.from}\u0000${e.to}`;
80
+ const was = byPair.get(key);
81
+ if (!was) byPair.set(key, e);
82
+ else byPair.set(key, { ...was, unknown: [...new Set([...was.unknown, ...e.unknown])] });
83
+ }
84
+ return [...byPair.values()];
74
85
  }
75
86
  if (stage === "apply") {
76
87
  const runOf = new Map(progress.reads.filter((r) => r.composed).map((r) => [r.root, r.composed.wave]));
@@ -705,6 +716,7 @@ export function rootStates(answer, progress, { story = false } = {}) {
705
716
  const totals = totalsLine(w.totals);
706
717
  const together = new Set([...w.roots, ...(c ? c.roots : []), ...inRun]).size > 1;
707
718
  const composedHere = !!c && (c.roots.includes(root) || inRun.includes(root));
719
+ if (m && m.covered) facts.push(COVERED_WORDS); // behold#969: chant's first approval covered this stack's re-plan
708
720
  if (m && m.apply) facts.push(memberApplyLine(m).replace(`${root}: `, "")); // this root's own part, not the wave's
709
721
  else if (c && !composedHere) {
710
722
  // Beside a composed run in its wave: the wave's figures are the run's, not this root's.
@@ -764,9 +776,14 @@ export function planFitsPin(pr, pin) {
764
776
  export function pinnedAnswer(answer, run, pull = null) {
765
777
  if (!answer || answer.error) return answer;
766
778
  const pin = pullPin(run);
767
- if (run === "base" || (pin && !planFitsPin(answer.pull_request, pin))) return { ...answer, pull_request: null };
779
+ // behold#940: the estate scene is the plan's resources and what applied, so it goes where the plan does.
780
+ const none = () => {
781
+ const { estateScene: _scene, ...rest } = answer;
782
+ return { ...rest, pull_request: null };
783
+ };
784
+ if (run === "base" || (pin && !planFitsPin(answer.pull_request, pin))) return none();
768
785
  // A commit's run is the merge of the cycle's pull request (`pull`): another cycle's plan is never drawn for it.
769
- if (pull && pinsCommit(run) && !mergedPull(answer.pull_request, pull)) return { ...answer, pull_request: null };
786
+ if (pull && pinsCommit(run) && !mergedPull(answer.pull_request, pull)) return none();
770
787
  return answer;
771
788
  }
772
789