@intentius/behold 0.30.2 → 0.32.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 +791 -16
- package/README.md +78 -23
- package/THIRD_PARTY.md +6 -5
- package/demos.json +14 -9
- package/dist/cli.js +51926 -20221
- 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 +26 -8
- package/schemas/graph/v1/graph.schema.json +140 -0
- 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 +367 -14
- package/web/boot-motion.js +6 -0
- 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/cut-around.d.ts +30 -0
- package/web/cut-around.js +138 -0
- package/web/drift-stream.js +241 -0
- package/web/drift-stream.test.js +146 -0
- package/web/edge-weight.d.ts +8 -2
- package/web/edge-weight.js +38 -4
- package/web/edge-weight.test.js +55 -1
- 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 +45 -20
- 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/neighbourhood.js +105 -0
- package/web/neighbourhood.test.js +131 -0
- package/web/outside-refs.js +515 -0
- package/web/outside-refs.test.js +249 -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/web/theme-paint.js +14 -0
- 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,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
|
+
});
|
package/web/templates.js
ADDED
|
@@ -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
|
+
}
|