@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.
- package/AGENTS.md +444 -15
- package/README.md +14 -13
- package/demos.json +14 -9
- package/dist/cli.js +53928 -26475
- package/example-carve/README.md +19 -23
- package/example-carve/app/package.json +1 -1
- package/example-carve/app/src/carved.ts +3 -3
- package/example-carve/carve-report.json +1 -1
- package/example-carve/{legacy-tf → tf-root}/terraform.tfstate +1 -1
- package/example-choudoufu-estate/README.md +7 -0
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-choudoufu-estate/scripts/choudoufu-down.sh +2 -1
- package/example-choudoufu-estate/scripts/choudoufu-up.sh +10 -3
- package/example-terraform-estate/README.md +32 -5
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/recorded/adoption/platform.json +72 -0
- package/example-terraform-estate/recorded/adoption/prod.json +224 -0
- package/example-three-cloud/README.md +111 -18
- package/example-three-cloud/aws/Pulumi.yaml +15 -0
- package/example-three-cloud/aws/index.ts +174 -0
- package/example-three-cloud/aws/package-lock.json +2725 -0
- package/example-three-cloud/aws/package.json +14 -0
- package/example-three-cloud/aws/tsconfig.json +17 -0
- package/example-three-cloud/azure/main.tf +48 -0
- package/example-three-cloud/azure/site.tf +104 -0
- package/example-three-cloud/chant.config.json +9 -0
- package/example-three-cloud/chant.workspace.json +30 -4
- package/example-three-cloud/dns/chant.config.ts +26 -1
- package/example-three-cloud/dns/src/records.component.ts +32 -6
- package/example-three-cloud/package-lock.json +48 -27
- package/example-three-cloud/package.json +8 -6
- package/example-three-cloud/scripts/emulators-up.sh +28 -1
- package/example-three-cloud/scripts/front-door.ts +679 -86
- package/package.json +13 -6
- package/web/adopt-pulumi.js +114 -0
- package/web/adopt-pulumi.test.js +28 -0
- package/web/adopt.js +203 -0
- package/web/adopt.test.js +27 -0
- package/web/app.js +358 -10
- package/web/carve-steps.js +1 -1
- package/web/carve-steps.test.js +2 -2
- package/web/change-set-overlay.js +12 -5
- package/web/change-set-overlay.test.js +22 -0
- package/web/drift-stream.js +241 -0
- package/web/drift-stream.test.js +146 -0
- package/web/edge-weight.d.ts +1 -1
- package/web/edge-weight.js +5 -1
- package/web/edge-weight.test.js +19 -0
- package/web/graph-query.js +180 -0
- package/web/graph-query.test.js +49 -0
- package/web/graph.html +107 -0
- package/web/index-diff.js +109 -0
- package/web/index-diff.test.js +39 -0
- package/web/index.html +37 -0
- package/web/kiosk-ask-tips.js +15 -5
- package/web/kiosk-ask-tips.test.js +14 -1
- package/web/kiosk-estate-scene.js +72 -8
- package/web/kiosk-light-frame.js +1 -0
- package/web/kiosk-light.js +41 -3
- package/web/kiosk-member-kind.test.js +140 -0
- package/web/kiosk-popover.js +4 -1
- package/web/kiosk-side.js +296 -0
- package/web/kiosk-side.test.js +249 -0
- package/web/kiosk-watch.js +12 -0
- package/web/kiosk-watch.test.js +15 -1
- package/web/kiosk.html +47 -1
- package/web/kiosk.js +106 -7
- package/web/member-kind.js +31 -0
- package/web/template-apps.js +245 -0
- package/web/template-apps.test.js +252 -0
- package/web/templates.js +285 -0
- package/web/templates.test.js +155 -0
- package/web/terragucci-lifecycle.js +112 -62
- package/web/terragucci-lifecycle.test.js +29 -1
- package/web/terragucci-timeline.js +39 -2
- package/web/terragucci-timeline.test.js +42 -1
- package/example-three-cloud/aws/chant.config.ts +0 -8
- package/example-three-cloud/aws/site.component.ts +0 -13
- package/example-three-cloud/aws/src/site.ts +0 -27
- package/example-three-cloud/azure/chant.config.ts +0 -1
- package/example-three-cloud/azure/src/site.component.ts +0 -13
- package/example-three-cloud/azure/src/site.ts +0 -18
- /package/example-carve/{legacy-tf → tf-root}/cdn.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/compute.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/floci-override.tf.disabled +0 -0
- /package/example-carve/{legacy-tf → tf-root}/modules/cdn/main.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/naming.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/network.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/observability.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/outputs.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/storage.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/versions.tf +0 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// behold#1036: an app made from a template, the way its owner thinks of it.
|
|
2
|
+
// GET /api/templates/apps (terragucci templates apps --json) names each app's
|
|
3
|
+
// root, its template and version, and its add-ons. An app and its add-ons are
|
|
4
|
+
// one root, planned and applied together (ruling C of INTENTIUS/chant#4642):
|
|
5
|
+
// `module "app"` is the app's template and each `module "<addon>"` an add-on.
|
|
6
|
+
// So on the graph their cards draw inside one frame, titled with the app's
|
|
7
|
+
// name and template, and the frame's header counts the cards terragucci's
|
|
8
|
+
// reports mark as drifted. The marks stay on the cards themselves.
|
|
9
|
+
//
|
|
10
|
+
// The app's inspect pane offers the requests that change it: Add an add-on
|
|
11
|
+
// (the Templates form, filtered to add-on templates, with the app set) and
|
|
12
|
+
// Upgrade to <version> when the catalog has a newer active version, which
|
|
13
|
+
// dispatches terragucci's rollout workflow. behold applies nothing. Neither
|
|
14
|
+
// button is drawn in a public view, an embed or a static export.
|
|
15
|
+
//
|
|
16
|
+
// behold#1037: the pane also lists the actions the app's templates offer
|
|
17
|
+
// (`actions` in the apps read), one button each, named by the action. A
|
|
18
|
+
// button dispatches terragucci's action workflow and nothing more: the run
|
|
19
|
+
// asks for an approval, the gate card below shows the digest, the waiting
|
|
20
|
+
// state and the `terragucci approve action` line for a person other than the
|
|
21
|
+
// one who asked, and the history lists each request, who approved it and how
|
|
22
|
+
// it ended. On a root whose engine has no action invocation (OpenTofu,
|
|
23
|
+
// choudoufu) the buttons stay, disabled, with the refusal beside them.
|
|
24
|
+
//
|
|
25
|
+
// Pure, apart from renderAppSection, which draws into the document it is handed.
|
|
26
|
+
|
|
27
|
+
import { laneActionCards } from "./terragucci-lifecycle.js";
|
|
28
|
+
import { laneRows } from "./terragucci-timeline.js";
|
|
29
|
+
|
|
30
|
+
/** The apps from the envelope GET /api/templates/apps answers, or []. */
|
|
31
|
+
export function appRows(answer) {
|
|
32
|
+
return (answer && Array.isArray(answer.results) && answer.results) || [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A template's short name, as a request branch names it: `bucket` for `acme/bucket/aws`. */
|
|
36
|
+
export function templateShort(template) {
|
|
37
|
+
const parts = String(template || "").split("/").filter(Boolean);
|
|
38
|
+
return (parts.length >= 3 ? parts[parts.length - 2] : parts[parts.length - 1]) || String(template || "");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The frame's title: `orders (bucket 1.2.0)`. */
|
|
42
|
+
export function frameTitle(app) {
|
|
43
|
+
return `${app.app} (${templateShort(app.template)}${app.version ? ` ${app.version}` : ""})`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The module calls of an app's root: `module.app` and each add-on's. */
|
|
47
|
+
export function appModules(app) {
|
|
48
|
+
return ["app", ...(app.addons || []).map((a) => a.name)].map((n) => `module.${n}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The card-id prefix of an app's root: `<member>/<root name>/`. The roots
|
|
53
|
+
* table (/api/terragucci's `roots`, each `{member, name, path}`) names it when
|
|
54
|
+
* there is one; else a card whose `attrs.root` is the root's last path
|
|
55
|
+
* segment, or its path with `-` for `/`, as behold names a root it discovers.
|
|
56
|
+
*/
|
|
57
|
+
export function rootPrefix(app, roots, nodes) {
|
|
58
|
+
const hit = (roots || []).find((r) => r.path === app.root);
|
|
59
|
+
if (hit) return `${hit.member}/${hit.name}/`;
|
|
60
|
+
const names = [app.root.split("/").pop(), app.root.split("/").join("-")];
|
|
61
|
+
for (const n of nodes || []) {
|
|
62
|
+
const root = n.attrs && n.attrs.root;
|
|
63
|
+
if (typeof root !== "string" || !names.includes(root)) continue;
|
|
64
|
+
const at = n.id.indexOf(`/${root}/`);
|
|
65
|
+
if (at >= 0) return n.id.slice(0, at + root.length + 2);
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Whether a card mark says drift. */
|
|
71
|
+
const drifted = (marks) => (marks || []).some((m) => m.verdict === "drift");
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* One frame per app whose cards are on the graph: the app, its title, the
|
|
75
|
+
* card ids of `module.app` and its add-ons, how many of them carry a drift
|
|
76
|
+
* mark (`cards` is /api/terragucci's marks by card id), and the header's
|
|
77
|
+
* words. An app none of whose cards is drawn gets no frame.
|
|
78
|
+
*/
|
|
79
|
+
export function appFrames(apps, nodes, { roots = [], cards = {} } = {}) {
|
|
80
|
+
const out = [];
|
|
81
|
+
for (const app of apps || []) {
|
|
82
|
+
const prefix = rootPrefix(app, roots, nodes);
|
|
83
|
+
if (!prefix) continue;
|
|
84
|
+
const modules = appModules(app);
|
|
85
|
+
const ids = (nodes || [])
|
|
86
|
+
.map((n) => n.id)
|
|
87
|
+
.filter((id) => id.startsWith(prefix) && modules.some((m) => id.slice(prefix.length) === m || id.slice(prefix.length).startsWith(`${m}/`)));
|
|
88
|
+
if (!ids.length) continue;
|
|
89
|
+
const drift = ids.filter((id) => drifted(cards[id])).length;
|
|
90
|
+
const title = frameTitle(app);
|
|
91
|
+
out.push({ app, title, prefix, ids, drifted: drift, header: drift ? `${title} · ${drift} drifted` : title, ...(drift ? { drift: `${drift} drifted` } : {}) });
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The frame a card is in, or null. */
|
|
97
|
+
export function frameOf(frames, id) {
|
|
98
|
+
return (frames || []).find((f) => f.ids.includes(id)) || null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The buttons an app's inspect pane draws, in order: Add an add-on, then
|
|
103
|
+
* Upgrade to <version> when the catalog offers one, then one per action the
|
|
104
|
+
* app's templates offer (behold#1037). None in a public view, an embed or a
|
|
105
|
+
* static export. Each is `{id, label, title}`, plus what its request sends.
|
|
106
|
+
* With `actionRefusal` (ruling E) an action button is `disabled` and its
|
|
107
|
+
* title is the refusal.
|
|
108
|
+
*/
|
|
109
|
+
export function appButtons(app, { publicMode = false, embed = false, staticMode = false, actionRefusal = null } = {}) {
|
|
110
|
+
if (publicMode || embed || staticMode || !app) return [];
|
|
111
|
+
const out = [{ id: "addon", label: "Add an add-on", title: `Open the Templates form with only add-on templates, for ${app.app}. terragucci opens the pull request that adds the add-on to ${app.root}.` }];
|
|
112
|
+
if (typeof app.upgrade === "string" && app.upgrade) {
|
|
113
|
+
out.push({
|
|
114
|
+
id: "upgrade",
|
|
115
|
+
label: `Upgrade to ${app.upgrade}`,
|
|
116
|
+
title: `Start the rollout of ${app.template} ${app.upgrade}: terragucci opens one pull request per wave, and every app on ${templateShort(app.template)} moves with it. Each wave is planned, reviewed and applied by the pipeline.`,
|
|
117
|
+
body: { app: app.app, version: app.upgrade },
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
for (const a of app.actions || []) {
|
|
121
|
+
if (!a || typeof a.address !== "string") continue;
|
|
122
|
+
const name = a.name || a.address.split(".").pop();
|
|
123
|
+
out.push({
|
|
124
|
+
id: "action",
|
|
125
|
+
label: name,
|
|
126
|
+
title: actionRefusal
|
|
127
|
+
? actionRefusal
|
|
128
|
+
: `Ask terragucci to run ${name} (${a.address}) on ${app.root}. The run asks for an approval; a person other than you approves it with terragucci approve action, and only then does it run. behold approves nothing.`,
|
|
129
|
+
body: { root: app.root, address: a.address },
|
|
130
|
+
...(actionRefusal ? { disabled: true } : {}),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** What the pane says once an action button was pressed: the POST's answer, or a refusal's code and words. */
|
|
137
|
+
export function actionWords(answer) {
|
|
138
|
+
if (!answer) return { text: "" };
|
|
139
|
+
if (answer.error) return { text: `${answer.code ? `${answer.code}: ` : ""}${answer.error}${answer.command ? ` Run: ${answer.command}` : ""}`, refused: true };
|
|
140
|
+
return { text: `${answer.action} asked for on ${answer.root}: terragucci's run asks for an approval, and the gate card shows its digest and the line a person other than you runs.` };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The app root's action gate cards and action history: `lane` is /api/terragucci/lifecycle, `timeline` /api/terragucci/timeline. */
|
|
144
|
+
export function appActions(app, { lane = null, timeline = null, now = new Date() } = {}) {
|
|
145
|
+
const cards = laneActionCards(lane, now, { root: app.root });
|
|
146
|
+
const history = timeline && Array.isArray(timeline.entries) ? laneRows({ ...timeline, entries: timeline.entries.filter((e) => e.kind === "action" || e.kind === "action-requested") }, { root: app.root, now }) : [];
|
|
147
|
+
return { cards, history };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The app's facts, one line each: template and version, add-ons, drift, a yanked pin. */
|
|
151
|
+
export function appFacts(frame) {
|
|
152
|
+
const a = frame.app;
|
|
153
|
+
const lines = [`${a.template} ${a.version || "unpinned"}${a.yanked ? " (yanked)" : ""} · ${a.root}`];
|
|
154
|
+
const addons = (a.addons || []).map((x) => `${x.name} (${templateShort(x.template)}${x.version ? ` ${x.version}` : ""})`);
|
|
155
|
+
lines.push(addons.length ? `add-ons: ${addons.join(", ")}` : "no add-ons");
|
|
156
|
+
if (frame.drifted) lines.push(`${frame.drifted} card${frame.drifted === 1 ? "" : "s"} drifted, from terragucci's reports`);
|
|
157
|
+
return lines;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** What the pane says once Upgrade was pressed: the POST's answer, or a refusal's code and words. */
|
|
161
|
+
export function upgradeWords(answer) {
|
|
162
|
+
if (!answer) return { text: "" };
|
|
163
|
+
if (answer.error) return { text: `${answer.code ? `${answer.code}: ` : ""}${answer.error}${answer.command ? ` Run: ${answer.command}` : ""}`, refused: true };
|
|
164
|
+
return { text: `Upgrade started: terragucci opens the first wave's pull request for ${answer.template} ${answer.version}, and the rollout carries the rest wave by wave.` };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Draw the app's part of the inspect pane into `host`: its title, facts and
|
|
169
|
+
* buttons. `ui.addAddon(app)` and `ui.upgrade(app, body)` are what the buttons
|
|
170
|
+
* call; `said` is the last upgrade's answer, for its words. `doc` is the
|
|
171
|
+
* document (a test hands in its own).
|
|
172
|
+
*/
|
|
173
|
+
export function renderAppSection(host, frame, ui, opts = {}, doc = document) {
|
|
174
|
+
const el = (tag, cls, text) => {
|
|
175
|
+
const n = doc.createElement(tag);
|
|
176
|
+
if (cls) n.className = cls;
|
|
177
|
+
if (text !== undefined) n.textContent = text;
|
|
178
|
+
return n;
|
|
179
|
+
};
|
|
180
|
+
const box = el("section", "tpl-app");
|
|
181
|
+
box.appendChild(el("h3", null, `app ${frame.title}`));
|
|
182
|
+
for (const line of appFacts(frame)) box.appendChild(el("p", "tpl-app-fact", line));
|
|
183
|
+
const buttons = appButtons(frame.app, opts);
|
|
184
|
+
if (buttons.length) {
|
|
185
|
+
const row = el("div", "tpl-app-buttons");
|
|
186
|
+
for (const b of buttons) {
|
|
187
|
+
const n = el("button", `tpl-app-${b.id}`, b.label);
|
|
188
|
+
n.type = "button";
|
|
189
|
+
n.title = b.title;
|
|
190
|
+
if (b.disabled) n.disabled = true;
|
|
191
|
+
n.setAttribute("data-action", b.id);
|
|
192
|
+
n.addEventListener("click", () => {
|
|
193
|
+
if (b.id === "addon") ui.addAddon(frame.app);
|
|
194
|
+
else if (b.id === "upgrade") ui.upgrade(frame.app, b.body);
|
|
195
|
+
else if (ui.action) ui.action(frame.app, b);
|
|
196
|
+
});
|
|
197
|
+
row.appendChild(n);
|
|
198
|
+
}
|
|
199
|
+
box.appendChild(row);
|
|
200
|
+
}
|
|
201
|
+
const words = upgradeWords(opts.said);
|
|
202
|
+
if (words.text) box.appendChild(el("p", words.refused ? "tg-refusal tpl-app-result" : "tg-legend tpl-app-result", words.text));
|
|
203
|
+
// behold#1037: ruling E said beside the buttons, then what the last action press answered.
|
|
204
|
+
if (opts.actionRefusal && buttons.some((b) => b.id === "action")) box.appendChild(el("p", "tg-refusal tpl-app-action-refusal", opts.actionRefusal));
|
|
205
|
+
const asked = actionWords(opts.actionSaid);
|
|
206
|
+
if (asked.text) box.appendChild(el("p", asked.refused ? "tg-refusal tpl-app-result" : "tg-legend tpl-app-result", asked.text));
|
|
207
|
+
// The action gate cards and the action history for this app's root.
|
|
208
|
+
if (!opts.publicMode && !opts.embed && !opts.staticMode && (opts.lane || opts.timeline)) {
|
|
209
|
+
const { cards, history } = appActions(frame.app, { lane: opts.lane, timeline: opts.timeline, now: opts.now || new Date() });
|
|
210
|
+
if (cards.length && ui.gateCard) {
|
|
211
|
+
box.appendChild(el("h4", null, "actions waiting or run"));
|
|
212
|
+
for (const c of cards) box.appendChild(ui.gateCard(c));
|
|
213
|
+
}
|
|
214
|
+
if (history.length) {
|
|
215
|
+
box.appendChild(el("h4", null, "action history"));
|
|
216
|
+
for (const r of history) {
|
|
217
|
+
const p = el("p", `tg-entry tg-${r.tone} tpl-app-history`);
|
|
218
|
+
p.title = r.title;
|
|
219
|
+
p.appendChild(el("span", "tg-when", r.when));
|
|
220
|
+
p.appendChild(el("span", null, ` ${r.text}`));
|
|
221
|
+
for (const l of r.links) {
|
|
222
|
+
const a = el("a", null, l.text);
|
|
223
|
+
a.href = l.href;
|
|
224
|
+
a.target = "_blank";
|
|
225
|
+
a.rel = "noopener";
|
|
226
|
+
p.appendChild(el("span", null, " · "));
|
|
227
|
+
p.appendChild(a);
|
|
228
|
+
}
|
|
229
|
+
box.appendChild(p);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
host.appendChild(box);
|
|
234
|
+
return box;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Press an action button: POST /api/templates/action with the root and address. `fetchJson(url, init)` answers parsed JSON. */
|
|
238
|
+
export function postAction(fetchJson, body) {
|
|
239
|
+
return fetchJson("/api/templates/action", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }).catch((e) => ({ error: String(e) }));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Press Upgrade: POST /api/templates/upgrade with the app and the version the pane showed. `fetchJson(url, init)` answers parsed JSON. */
|
|
243
|
+
export function postUpgrade(fetchJson, body) {
|
|
244
|
+
return fetchJson("/api/templates/upgrade", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }).catch((e) => ({ error: String(e) }));
|
|
245
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// behold#1036: an app and its add-ons in one frame, and the app's two
|
|
2
|
+
// requests in its inspect pane. The frame is data; the pane and the Templates
|
|
3
|
+
// form are drawn into a small stand-in document (no DOM library in this repo).
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { actionWords, appButtons, appFrames, frameOf, frameTitle, postAction, postUpgrade, renderAppSection, templateShort } from "./template-apps.js";
|
|
6
|
+
import { startTemplates } from "./templates.js";
|
|
7
|
+
|
|
8
|
+
class Node {
|
|
9
|
+
constructor(tag) {
|
|
10
|
+
this.tagName = tag.toUpperCase();
|
|
11
|
+
this.children = [];
|
|
12
|
+
this.listeners = {};
|
|
13
|
+
this.attributes = {};
|
|
14
|
+
this.textContent = "";
|
|
15
|
+
this.className = "";
|
|
16
|
+
this.value = "";
|
|
17
|
+
this.checked = false;
|
|
18
|
+
this.disabled = false;
|
|
19
|
+
}
|
|
20
|
+
appendChild(n) {
|
|
21
|
+
this.children.push(n);
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
replaceChildren(...n) {
|
|
25
|
+
this.children = n;
|
|
26
|
+
}
|
|
27
|
+
setAttribute(k, v) {
|
|
28
|
+
this.attributes[k] = String(v);
|
|
29
|
+
}
|
|
30
|
+
addEventListener(type, f) {
|
|
31
|
+
(this.listeners[type] ||= []).push(f);
|
|
32
|
+
}
|
|
33
|
+
fire(type) {
|
|
34
|
+
for (const f of this.listeners[type] || []) f({ preventDefault() {} });
|
|
35
|
+
}
|
|
36
|
+
all() {
|
|
37
|
+
return this.children.flatMap((c) => [c, ...c.all()]);
|
|
38
|
+
}
|
|
39
|
+
text() {
|
|
40
|
+
return [this.textContent, ...this.children.map((c) => c.text())].join("");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const doc = { createElement: (tag) => new Node(tag) };
|
|
44
|
+
const buttons = (host) => host.all().filter((n) => n.tagName === "BUTTON");
|
|
45
|
+
|
|
46
|
+
const orders = {
|
|
47
|
+
app: "orders",
|
|
48
|
+
root: "apps/orders",
|
|
49
|
+
template: "acme/bucket/aws",
|
|
50
|
+
version: "1.2.0",
|
|
51
|
+
upgrade: "1.3.0",
|
|
52
|
+
yanked: false,
|
|
53
|
+
addons: [{ name: "cache", template: "acme/cache/aws", version: "0.3.0", upgrade: null, yanked: false }],
|
|
54
|
+
actions: [],
|
|
55
|
+
};
|
|
56
|
+
const apps = { schema: 1, command: "templates", exit: 0, status: "ok", results: [orders] };
|
|
57
|
+
|
|
58
|
+
// chant's graph of the checkout: the root `apps/orders` is member `infra`'s root `orders`.
|
|
59
|
+
const roots = [{ member: "infra", name: "orders", path: "apps/orders" }];
|
|
60
|
+
const node = (id) => ({ id, kind: "aws_s3_bucket", attrs: { root: id.split("/")[1] } });
|
|
61
|
+
const nodes = [
|
|
62
|
+
node("infra/orders/module.app/aws_s3_bucket.this"),
|
|
63
|
+
node("infra/orders/module.app/aws_s3_bucket_versioning.this"),
|
|
64
|
+
node("infra/orders/module.cache/aws_elasticache_cluster.this"),
|
|
65
|
+
node("infra/orders/aws_iam_role.extra"),
|
|
66
|
+
node("infra/billing/module.app/aws_s3_bucket.this"),
|
|
67
|
+
];
|
|
68
|
+
const drift = { verdict: "drift", action: "update", words: "changed outside Terraform", addresses: ["module.cache.aws_elasticache_cluster.this"], run: { stage: "tf-drift", finished: "2026-10-28T06:04:00Z" } };
|
|
69
|
+
|
|
70
|
+
describe("an app's frame on the graph (behold#1036)", () => {
|
|
71
|
+
it("draws one frame titled `orders (bucket 1.2.0)` holding the module.app and module.cache cards", () => {
|
|
72
|
+
const frames = appFrames(apps.results, nodes, { roots });
|
|
73
|
+
expect(frames).toHaveLength(1);
|
|
74
|
+
expect(frames[0].title).toBe("orders (bucket 1.2.0)");
|
|
75
|
+
expect(frames[0].ids).toEqual(["infra/orders/module.app/aws_s3_bucket.this", "infra/orders/module.app/aws_s3_bucket_versioning.this", "infra/orders/module.cache/aws_elasticache_cluster.this"]);
|
|
76
|
+
expect(frames[0].header).toBe("orders (bucket 1.2.0)");
|
|
77
|
+
expect(frameTitle({ app: "x", template: "acme/bucket/aws", version: null })).toBe("x (bucket)");
|
|
78
|
+
expect(templateShort("acme/cache/aws")).toBe("cache");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("reads `1 drifted` in the header when a module.cache card carries a drift mark", () => {
|
|
82
|
+
const cards = { "infra/orders/module.cache/aws_elasticache_cluster.this": [drift], "infra/orders/aws_iam_role.extra": [drift] };
|
|
83
|
+
const [f] = appFrames(apps.results, nodes, { roots, cards });
|
|
84
|
+
expect(f.drifted).toBe(1);
|
|
85
|
+
expect(f.drift).toBe("1 drifted");
|
|
86
|
+
expect(f.header).toBe("orders (bucket 1.2.0) · 1 drifted");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("finds the root by the cards' attrs.root without a roots table, and draws no frame for an app with no card", () => {
|
|
90
|
+
expect(appFrames(apps.results, nodes)[0].ids).toHaveLength(3);
|
|
91
|
+
expect(appFrames([{ ...orders, app: "search", root: "apps/search" }], nodes, { roots })).toEqual([]);
|
|
92
|
+
expect(frameOf(appFrames(apps.results, nodes, { roots }), "infra/orders/module.cache/aws_elasticache_cluster.this").app.app).toBe("orders");
|
|
93
|
+
expect(frameOf(appFrames(apps.results, nodes, { roots }), "infra/orders/aws_iam_role.extra")).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("the app's inspect pane (behold#1036)", () => {
|
|
98
|
+
const frame = () => appFrames(apps.results, nodes, { roots })[0];
|
|
99
|
+
|
|
100
|
+
it("shows Add an add-on; clicking it opens the Templates form with only add-on templates and app=orders set", async () => {
|
|
101
|
+
const catalog = {
|
|
102
|
+
schema: 1,
|
|
103
|
+
command: "templates",
|
|
104
|
+
exit: 0,
|
|
105
|
+
status: "ok",
|
|
106
|
+
results: [
|
|
107
|
+
{ template: "acme/bucket/aws", kind: "app", latest: "1.2.0", versions: [{ version: "1.2.0", attestation: "signed" }], fields: [{ name: "bucket_name", kind: "string", required: true }] },
|
|
108
|
+
{ template: "acme/cache/aws", kind: "addon", description: "A cache beside an app", latest: "0.3.0", versions: [{ version: "0.3.0", attestation: "signed" }], fields: [{ name: "subnet_ids", kind: "list", of: "string", required: true }] },
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
const posts = [];
|
|
112
|
+
const fetchJson = async (url, init) => {
|
|
113
|
+
if (url === "/api/templates") return catalog;
|
|
114
|
+
if (url === "/api/templates/request") {
|
|
115
|
+
posts.push(JSON.parse(init.body));
|
|
116
|
+
return { dispatched: true, id: "r1", branch: "request/cache/orders/cache" };
|
|
117
|
+
}
|
|
118
|
+
return { id: "r1", state: "dispatched" };
|
|
119
|
+
};
|
|
120
|
+
const tab = new Node("section");
|
|
121
|
+
const t = startTemplates(tab, { fetchJson, doc });
|
|
122
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
123
|
+
|
|
124
|
+
const pane = new Node("div");
|
|
125
|
+
renderAppSection(pane, frame(), { addAddon: (a) => t.ui.forApp(a.app), upgrade() {} }, {}, doc);
|
|
126
|
+
const add = buttons(pane).find((b) => b.textContent === "Add an add-on");
|
|
127
|
+
expect(add).toBeTruthy();
|
|
128
|
+
add.fire("click");
|
|
129
|
+
|
|
130
|
+
expect(t.state.forApp).toBe("orders");
|
|
131
|
+
expect(tab.text()).toContain("acme/cache/aws");
|
|
132
|
+
expect(tab.text()).not.toContain("acme/bucket/aws");
|
|
133
|
+
const request = buttons(tab).filter((b) => b.textContent === "Request");
|
|
134
|
+
expect(request).toHaveLength(1);
|
|
135
|
+
request[0].fire("click");
|
|
136
|
+
expect(tab.text()).toContain("into the app orders");
|
|
137
|
+
expect(tab.text()).toContain("Add-on name (required)");
|
|
138
|
+
const field = (n) => tab.all().find((x) => (x.tagName === "INPUT" || x.tagName === "TEXTAREA") && x.name === n);
|
|
139
|
+
for (const [n, v] of [["name", "cache"], ["subnet_ids", "app.private_subnets"]]) {
|
|
140
|
+
field(n).value = v;
|
|
141
|
+
field(n).fire("input");
|
|
142
|
+
}
|
|
143
|
+
tab.all().find((n) => n.tagName === "FORM").fire("submit");
|
|
144
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
145
|
+
expect(posts).toEqual([{ template: "acme/cache/aws", version: "0.3.0", name: "cache", app: "orders", inputs: { subnet_ids: "app.private_subnets" } }]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("with upgrade 1.3.0 shows Upgrade to 1.3.0, which posts the app and version; without upgrade there is no button", async () => {
|
|
149
|
+
const pane = new Node("div");
|
|
150
|
+
const pressed = [];
|
|
151
|
+
renderAppSection(pane, frame(), { addAddon() {}, upgrade: (a, body) => pressed.push(body) }, {}, doc);
|
|
152
|
+
const up = buttons(pane).find((b) => b.textContent === "Upgrade to 1.3.0");
|
|
153
|
+
expect(up).toBeTruthy();
|
|
154
|
+
up.fire("click");
|
|
155
|
+
expect(pressed).toEqual([{ app: "orders", version: "1.3.0" }]);
|
|
156
|
+
|
|
157
|
+
const seen = [];
|
|
158
|
+
await postUpgrade(async (url, init) => (seen.push([url, init.method, JSON.parse(init.body)]), { dispatched: true }), pressed[0]);
|
|
159
|
+
expect(seen).toEqual([["/api/templates/upgrade", "POST", { app: "orders", version: "1.3.0" }]]);
|
|
160
|
+
|
|
161
|
+
const none = new Node("div");
|
|
162
|
+
renderAppSection(none, { ...frame(), app: { ...orders, upgrade: null } }, { addAddon() {}, upgrade() {} }, {}, doc);
|
|
163
|
+
expect(buttons(none).map((b) => b.textContent)).toEqual(["Add an add-on"]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("draws neither button in a public view, an embed or a static export", () => {
|
|
167
|
+
for (const opts of [{ publicMode: true }, { embed: true }, { staticMode: true }]) {
|
|
168
|
+
expect(appButtons(orders, opts)).toEqual([]);
|
|
169
|
+
const pane = new Node("div");
|
|
170
|
+
renderAppSection(pane, frame(), { addAddon() {}, upgrade() {} }, opts, doc);
|
|
171
|
+
expect(buttons(pane)).toEqual([]);
|
|
172
|
+
expect(pane.text()).toContain("orders (bucket 1.2.0)");
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// behold#1037: the app's actions, their gate card and their history.
|
|
178
|
+
describe("an app's day-2 actions (behold#1037)", () => {
|
|
179
|
+
const ROTATE = "module.app.action.aws_lambda_invoke.rotate";
|
|
180
|
+
const DA = `sha256:${"a".repeat(64)}`;
|
|
181
|
+
const withRotate = { ...orders, actions: [{ module: "app", type: "aws_lambda_invoke", name: "rotate", address: ROTATE }] };
|
|
182
|
+
const frameOfRotate = () => appFrames([withRotate], nodes, { roots })[0];
|
|
183
|
+
const source = { branch: "chant/lifecycle", commit: "1a2b3c4d5e6f7a8b", committed: "2026-10-28T10:00:00Z", path: "_gates/tf-action.jsonl" };
|
|
184
|
+
const lane = {
|
|
185
|
+
found: true,
|
|
186
|
+
gates: [],
|
|
187
|
+
locks: [],
|
|
188
|
+
actions: [
|
|
189
|
+
{ op: "tf-action", gate: `apps/orders:${ROTATE}`, root: "apps/orders", address: ROTATE, name: "rotate", requester: "lee", state: "waiting", digest: DA, pending: { timestamp: "2026-10-28T10:00:00Z", expiresAt: "2099-01-01T00:00:00Z" }, command: `npx terragucci approve action apps/orders --plan ${DA}`, approvalMode: { mode: "ledger", from: "base" }, source },
|
|
190
|
+
{ op: "tf-action", gate: `apps/search:${ROTATE}`, root: "apps/search", address: ROTATE, name: "rotate", state: "waiting", digest: DA, command: "npx terragucci approve action apps/search", approvalMode: { mode: "ledger", from: "base" }, source },
|
|
191
|
+
],
|
|
192
|
+
};
|
|
193
|
+
const timeline = {
|
|
194
|
+
files: "/api/terragucci/file?key=",
|
|
195
|
+
entries: [
|
|
196
|
+
{ id: "act", kind: "action", at: "2026-10-28T11:00:00.000Z", who: "dana", what: `apps/orders:${ROTATE}`, digest: DA, result: "ok", roots: ["apps/orders"], run: { run_id: "402" }, evidence: { source: "ledger", url: `https://github.com/acme/shop/commit/${"b".repeat(40)}` }, detail: { root: "apps/orders", address: ROTATE } },
|
|
197
|
+
{ id: "apply", kind: "apply", at: "2026-10-28T09:00:00.000Z", who: "dana", what: "wave-1", digest: null, result: "applied", roots: ["apps/orders"], run: {}, evidence: { source: "report" } },
|
|
198
|
+
],
|
|
199
|
+
};
|
|
200
|
+
const NOW = new Date("2026-10-28T12:00:00Z");
|
|
201
|
+
|
|
202
|
+
it("shows one button rotate for the template's action; clicking it posts the root and address", async () => {
|
|
203
|
+
const pane = new Node("div");
|
|
204
|
+
const pressed = [];
|
|
205
|
+
renderAppSection(pane, frameOfRotate(), { addAddon() {}, upgrade() {}, action: (a, b) => pressed.push(b.body) }, {}, doc);
|
|
206
|
+
const rotate = buttons(pane).filter((b) => b.textContent === "rotate");
|
|
207
|
+
expect(rotate).toHaveLength(1);
|
|
208
|
+
expect(rotate[0].attributes["data-action"]).toBe("action");
|
|
209
|
+
expect(rotate[0].title).toContain("a person other than you approves it with terragucci approve action");
|
|
210
|
+
rotate[0].fire("click");
|
|
211
|
+
expect(pressed).toEqual([{ root: "apps/orders", address: ROTATE }]);
|
|
212
|
+
const seen = [];
|
|
213
|
+
await postAction(async (url, init) => (seen.push([url, init.method, JSON.parse(init.body)]), { dispatched: true }), pressed[0]);
|
|
214
|
+
expect(seen).toEqual([["/api/templates/action", "POST", { root: "apps/orders", address: ROTATE }]]);
|
|
215
|
+
// An app whose templates offer no action has no action button.
|
|
216
|
+
expect(appButtons(orders).filter((b) => b.id === "action")).toEqual([]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("keeps the button on an engine with no action invocation, disabled, with the refusal beside it (ruling E)", () => {
|
|
220
|
+
const why = "apps/orders: an action runs on Terraform 1.14 or newer, and this root runs OpenTofu (tofu, from binary in terragucci.yml), which has no action invocation";
|
|
221
|
+
const pane = new Node("div");
|
|
222
|
+
renderAppSection(pane, frameOfRotate(), { addAddon() {}, upgrade() {} }, { actionRefusal: why }, doc);
|
|
223
|
+
const rotate = buttons(pane).find((b) => b.textContent === "rotate");
|
|
224
|
+
expect(rotate.disabled).toBe(true);
|
|
225
|
+
expect(rotate.title).toBe(why);
|
|
226
|
+
expect(pane.text()).toContain("OpenTofu");
|
|
227
|
+
expect(actionWords({ error: "an action runs on Terraform 1.14 or newer", code: "action-engine" }).text).toBe("action-engine: an action runs on Terraform 1.14 or newer");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("draws the app root's waiting gate card with its approve line, and its action history", () => {
|
|
231
|
+
const pane = new Node("div");
|
|
232
|
+
const cards = [];
|
|
233
|
+
renderAppSection(pane, frameOfRotate(), { addAddon() {}, upgrade() {}, gateCard: (c) => (cards.push(c), new Node("div")) }, { lane, timeline, now: NOW, actionSaid: { dispatched: true, action: "rotate", root: "apps/orders" } }, doc);
|
|
234
|
+
expect(cards).toHaveLength(1);
|
|
235
|
+
expect(cards[0]).toMatchObject({ root: "apps/orders", state: "waiting", command: `npx terragucci approve action apps/orders --plan ${DA}` });
|
|
236
|
+
expect(pane.text()).toContain("rotate on apps/orders, approved by dana, ok");
|
|
237
|
+
expect(pane.text()).not.toContain("wave-1");
|
|
238
|
+
expect(pane.all().some((n) => n.tagName === "A" && n.href === "https://github.com/acme/shop/actions/runs/402")).toBe(true);
|
|
239
|
+
expect(pane.text()).toContain("rotate asked for on apps/orders");
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("draws no action button, card or history in a public view, an embed or a static export", () => {
|
|
243
|
+
for (const opts of [{ publicMode: true }, { embed: true }, { staticMode: true }]) {
|
|
244
|
+
const pane = new Node("div");
|
|
245
|
+
const cards = [];
|
|
246
|
+
renderAppSection(pane, frameOfRotate(), { addAddon() {}, upgrade() {}, gateCard: (c) => (cards.push(c), new Node("div")) }, { ...opts, lane, timeline, now: NOW }, doc);
|
|
247
|
+
expect(buttons(pane)).toEqual([]);
|
|
248
|
+
expect(cards).toEqual([]);
|
|
249
|
+
expect(pane.text()).not.toContain("approved by dana");
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
});
|