@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/behold",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "behold — a live control plane on chant. See your whole estate (every substrate in one graph), coloured by drift; act through delegated, gated Ops.",
|
|
@@ -41,31 +41,38 @@
|
|
|
41
41
|
"preview:tour": "tsx scripts/tour-preview.ts",
|
|
42
42
|
"tsc": "tsc --noEmit",
|
|
43
43
|
"test": "vitest run",
|
|
44
|
-
"
|
|
44
|
+
"generate:graph-layout": "tsx src/graph-db/generate-layout.ts",
|
|
45
|
+
"check:graph-layout": "tsx src/graph-db/generate-layout.ts --check",
|
|
46
|
+
"build": "tsx src/graph-db/generate-layout.ts && esbuild src/cli.ts --bundle --platform=node --format=esm --external:hono --external:@hono/node-server --external:@intentius/pinhole --external:@kubernetes/client-node --external:ajv --external:@modelcontextprotocol/sdk --external:@ladybugdb/core --outfile=dist/cli.js && chmod +x dist/cli.js",
|
|
45
47
|
"prepare": "npm run build",
|
|
46
48
|
"prepublishOnly": "npm run build"
|
|
47
49
|
},
|
|
48
50
|
"dependencies": {
|
|
49
51
|
"@cdktn/hcl2json": "^0.24.0",
|
|
50
52
|
"@hono/node-server": "^2.0.5",
|
|
51
|
-
"@intentius/chant": "^0.124.
|
|
52
|
-
"@intentius/chant-k8s-client": "^0.124.
|
|
53
|
-
"@intentius/chant-lexicon-terraform": "^0.124.
|
|
53
|
+
"@intentius/chant": "^0.124.58",
|
|
54
|
+
"@intentius/chant-k8s-client": "^0.124.58",
|
|
55
|
+
"@intentius/chant-lexicon-terraform": "^0.124.58",
|
|
54
56
|
"@intentius/pinhole": "^0.5.0",
|
|
55
57
|
"@modelcontextprotocol/sdk": "1.30.1",
|
|
56
58
|
"ajv": "^8.20.0",
|
|
57
59
|
"hono": "^4.13.13"
|
|
58
60
|
},
|
|
59
61
|
"peerDependencies": {
|
|
62
|
+
"@ladybugdb/core": ">=0.22.0",
|
|
60
63
|
"playwright-core": "^1.62.0"
|
|
61
64
|
},
|
|
62
65
|
"peerDependenciesMeta": {
|
|
63
66
|
"playwright-core": {
|
|
64
67
|
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"@ladybugdb/core": {
|
|
70
|
+
"optional": true
|
|
65
71
|
}
|
|
66
72
|
},
|
|
67
73
|
"devDependencies": {
|
|
68
|
-
"@intentius/chant-lexicon-
|
|
74
|
+
"@intentius/chant-lexicon-pulumi": "^0.124.58",
|
|
75
|
+
"@intentius/chant-lexicon-sql": "^0.124.58",
|
|
69
76
|
"@types/node": "^26.4.1",
|
|
70
77
|
"esbuild": "^0.28.0",
|
|
71
78
|
"playwright": "^1.62.1",
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// behold#999, the Pulumi half: a stock Pulumi stack member's card in the
|
|
2
|
+
// Adopt tab. The report is plunge stack adopt's classification without --yes:
|
|
3
|
+
// every resource with the ownership plunge would give it, or plunge's reasons
|
|
4
|
+
// for refusing the whole adoption, and nothing written. Start runs that same
|
|
5
|
+
// classification and shows the confirm command, which a person runs: behold
|
|
6
|
+
// never passes --yes (src/pulumi-adoption.ts).
|
|
7
|
+
|
|
8
|
+
const FATE_WORDS = { claimed: "claimed", unknown: "unknown ownership" };
|
|
9
|
+
const OWNERSHIP_ORDER = ["marker", "record", "pending"];
|
|
10
|
+
|
|
11
|
+
/** The classification's rows grouped by ownership (marker, record, pending, then any other), each group in plunge's order. */
|
|
12
|
+
export function pulumiGroups(report) {
|
|
13
|
+
const entries = (report && Array.isArray(report.entries) && report.entries) || [];
|
|
14
|
+
const seen = [...OWNERSHIP_ORDER, ...entries.map((e) => e.ownership).filter((o) => !OWNERSHIP_ORDER.includes(o))];
|
|
15
|
+
const groups = [];
|
|
16
|
+
for (const own of [...new Set(seen)]) {
|
|
17
|
+
const rows = entries.filter((e) => e.ownership === own);
|
|
18
|
+
if (rows.length) groups.push({ ownership: own, title: `${FATE_WORDS[rows[0].fate] || rows[0].fate}, by ${own} (${rows.length})`, rows });
|
|
19
|
+
}
|
|
20
|
+
return groups;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** One line counting what is claimed, by ownership. */
|
|
24
|
+
export function pulumiSummary(report) {
|
|
25
|
+
if (!report) return "";
|
|
26
|
+
const by = Object.entries(report.byOwnership || {}).map(([k, n]) => `${n} by ${k}`);
|
|
27
|
+
return `${report.claimed} of ${report.total} resource(s) claimed${by.length ? ` (${by.join(", ")})` : ""}.`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Draw one pulumi member's card into `card`. `h` is the tab's helpers ({el, code}). */
|
|
31
|
+
export function renderPulumiCard(card, o, s, ui, refusal, h) {
|
|
32
|
+
const { el, code } = h;
|
|
33
|
+
const list = (title, items) => {
|
|
34
|
+
card.appendChild(el("div", "ad-label", title));
|
|
35
|
+
const ul = el("ul", "ad-list");
|
|
36
|
+
for (const g of items || []) ul.appendChild(el("li", null, g));
|
|
37
|
+
card.appendChild(ul);
|
|
38
|
+
};
|
|
39
|
+
list("What it gains", o.gains);
|
|
40
|
+
list("What it does not", o.limits);
|
|
41
|
+
if (!o.start || !o.start.offered) card.appendChild(el("div", "tg-legend", (o.start && o.start.why) || o.stateHint || ""));
|
|
42
|
+
if (o.backend) card.appendChild(el("div", "tg-legend", `Stack ${o.stack.name} (${o.stack.from === "export" ? "from stack-export.json" : "asked"}), at ${o.backend.url}.`));
|
|
43
|
+
|
|
44
|
+
const row = el("div", "ad-row");
|
|
45
|
+
const read = el("button", null, s.reports[o.member] ? "Classify again" : "Classify");
|
|
46
|
+
read.type = "button";
|
|
47
|
+
read.disabled = !!refusal || !!s.reading[o.member] || !o.command;
|
|
48
|
+
read.title = o.command ? `Runs ${o.command}, without --yes: plunge lists every resource and writes nothing.` : "";
|
|
49
|
+
read.addEventListener("click", () => ui.read(o.member));
|
|
50
|
+
row.appendChild(read);
|
|
51
|
+
const start = el("button", null, "Start adoption");
|
|
52
|
+
start.type = "button";
|
|
53
|
+
start.disabled = !!refusal || !(o.start && o.start.offered) || !!s.starting;
|
|
54
|
+
start.title = o.start && o.start.offered ? "Runs the classification; nothing is written. A person confirms it with the command shown." : (o.start && o.start.why) || "";
|
|
55
|
+
start.addEventListener("click", () => ui.start(o.member));
|
|
56
|
+
row.appendChild(start);
|
|
57
|
+
card.appendChild(row);
|
|
58
|
+
if (o.command) {
|
|
59
|
+
card.appendChild(el("div", "ad-label", "What behold runs (classify only)"));
|
|
60
|
+
card.appendChild(code(o.command));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const drawAnswer = (r) => {
|
|
64
|
+
if (r.error) return void card.appendChild(el("div", "tg-refusal", r.remedy ? `${r.error} ${r.remedy}` : r.error));
|
|
65
|
+
card.appendChild(el("div", "tg-legend", r.words || ""));
|
|
66
|
+
if (r.refused && r.refused.length) {
|
|
67
|
+
card.appendChild(el("div", "ad-label", `Refused (${r.refused.length})`));
|
|
68
|
+
const ul = el("ul", "ad-list ad-refused");
|
|
69
|
+
for (const x of r.refused) ul.appendChild(el("li", null, x.reason));
|
|
70
|
+
card.appendChild(ul);
|
|
71
|
+
}
|
|
72
|
+
if (r.report) {
|
|
73
|
+
card.appendChild(el("div", "ad-summary", pulumiSummary(r.report)));
|
|
74
|
+
const t = el("table", "ad-table");
|
|
75
|
+
for (const g of pulumiGroups(r.report)) {
|
|
76
|
+
const th = el("tr", "ad-group");
|
|
77
|
+
const cell = el("th", null, g.title);
|
|
78
|
+
cell.colSpan = 4;
|
|
79
|
+
th.appendChild(cell);
|
|
80
|
+
t.appendChild(th);
|
|
81
|
+
for (const e of g.rows) {
|
|
82
|
+
const tr = el("tr", `ad-${e.fate}`);
|
|
83
|
+
const addr = el("td", "ad-addr", e.name);
|
|
84
|
+
addr.title = e.urn;
|
|
85
|
+
tr.appendChild(addr);
|
|
86
|
+
tr.appendChild(el("td", null, e.type));
|
|
87
|
+
tr.appendChild(el("td", "ad-status", e.ownership));
|
|
88
|
+
const why = el("td", null, e.detail ? `${e.why}. plunge: ${e.detail}` : e.why);
|
|
89
|
+
tr.appendChild(why);
|
|
90
|
+
t.appendChild(tr);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
card.appendChild(t);
|
|
94
|
+
}
|
|
95
|
+
if (r.confirm) {
|
|
96
|
+
card.appendChild(el("div", "ad-label", "Confirm it (a person, not behold)"));
|
|
97
|
+
card.appendChild(code(r.confirm));
|
|
98
|
+
if (r.after) card.appendChild(el("div", "tg-legend", r.after));
|
|
99
|
+
}
|
|
100
|
+
if (r.backOut) {
|
|
101
|
+
card.appendChild(el("div", "ad-label", "Back out"));
|
|
102
|
+
card.appendChild(code(r.backOut));
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const r = s.reports[o.member];
|
|
107
|
+
if (r) drawAnswer(r);
|
|
108
|
+
const run = s.runs[o.member];
|
|
109
|
+
if (run) {
|
|
110
|
+
card.appendChild(el("div", "ad-label", `Started ${run.started_at || ""}`));
|
|
111
|
+
if (run.outcome === "running" || run.error) card.appendChild(el("div", "tg-legend", run.words || run.error || ""));
|
|
112
|
+
else drawAnswer(run);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { pulumiGroups, pulumiSummary } from "./adopt-pulumi.js";
|
|
3
|
+
|
|
4
|
+
// behold#999: the Adopt tab's grouping of plunge stack adopt's classification.
|
|
5
|
+
const report = {
|
|
6
|
+
claimed: 4,
|
|
7
|
+
total: 5,
|
|
8
|
+
byOwnership: { pending: 2, marker: 1, record: 1, borrowed: 1 },
|
|
9
|
+
entries: [
|
|
10
|
+
{ urn: "u:bucket", ownership: "pending", fate: "claimed" },
|
|
11
|
+
{ urn: "u:dep", ownership: "marker", fate: "claimed" },
|
|
12
|
+
{ urn: "u:role", ownership: "record", fate: "claimed" },
|
|
13
|
+
{ urn: "u:odd", ownership: "borrowed", fate: "unknown" },
|
|
14
|
+
{ urn: "u:fn", ownership: "pending", fate: "claimed" },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe("the Adopt tab's pulumi card (behold#999)", () => {
|
|
19
|
+
it("groups every entry by ownership, marker first, an unknown ownership last, none dropped", () => {
|
|
20
|
+
const g = pulumiGroups(report);
|
|
21
|
+
expect(g.map((x) => x.title)).toEqual(["claimed, by marker (1)", "claimed, by record (1)", "claimed, by pending (2)", "unknown ownership, by borrowed (1)"]);
|
|
22
|
+
expect(g.flatMap((x) => x.rows.map((r) => r.urn))).toEqual(["u:dep", "u:role", "u:bucket", "u:fn", "u:odd"]);
|
|
23
|
+
});
|
|
24
|
+
it("counts what is claimed, by ownership", () => {
|
|
25
|
+
expect(pulumiSummary(report)).toBe("4 of 5 resource(s) claimed (2 by pending, 1 by marker, 1 by record, 1 by borrowed).");
|
|
26
|
+
expect(pulumiSummary(null)).toBe("");
|
|
27
|
+
});
|
|
28
|
+
});
|
package/web/adopt.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// behold#999: "adopt this root". A stock Terraform root member is offered
|
|
2
|
+
// adoption into choudoufu through chant workspace promote: what it gains, what
|
|
3
|
+
// it does not, the report of every resource with its fate (GET
|
|
4
|
+
// /api/adopt/report, promote's --dry-run), and the gated command. Start (POST
|
|
5
|
+
// /api/adopt/start) runs that command; chant's gate holds it, and nothing is
|
|
6
|
+
// written until a person approves the patch's digest. behold never approves
|
|
7
|
+
// here: the approve line is shown to copy. The tab is never drawn in a public
|
|
8
|
+
// view, an embed, a static export or a guarded repo (src/adoption.ts).
|
|
9
|
+
//
|
|
10
|
+
// A stock Pulumi stack member is offered adoption into plunge the same way,
|
|
11
|
+
// through plunge stack adopt (web/adopt-pulumi.js draws its card): the report
|
|
12
|
+
// is plunge's classification without --yes, Start runs that same
|
|
13
|
+
// classification, and the confirm command is shown for a person to run. The
|
|
14
|
+
// answer's refusal (the Terraform half's chant floor) never holds a pulumi card.
|
|
15
|
+
import { renderPulumiCard } from "./adopt-pulumi.js";
|
|
16
|
+
|
|
17
|
+
/** The tab's first line. */
|
|
18
|
+
export const ADOPT_LEGEND =
|
|
19
|
+
"Adopt a stock member into its engine tier. A Terraform root goes to choudoufu with chant workspace promote: the report is promote's dry run (a throwaway worktree, no gate recorded, nothing written), and Start runs the gated command, which writes nothing until the patch is approved. A Pulumi stack goes to plunge with plunge stack adopt: Classify runs it without --yes, so plunge lists every resource and writes nothing, and the confirm is a command a person runs.";
|
|
20
|
+
|
|
21
|
+
const FATE_WORDS = { claimed: "claimed", "left-out": "left out", unknown: "unknown status" };
|
|
22
|
+
|
|
23
|
+
/** The report's rows grouped by fate, claimed first, each group in the order chant gave them. */
|
|
24
|
+
export function reportGroups(report) {
|
|
25
|
+
const entries = (report && Array.isArray(report.entries) && report.entries) || [];
|
|
26
|
+
const groups = [];
|
|
27
|
+
for (const fate of ["claimed", "left-out", "unknown"]) {
|
|
28
|
+
const rows = entries.filter((e) => e.fate === fate);
|
|
29
|
+
if (rows.length) groups.push({ fate, title: `${FATE_WORDS[fate]} (${rows.length})`, rows });
|
|
30
|
+
}
|
|
31
|
+
return groups;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** One line counting what is claimed and what is left out, by status. */
|
|
35
|
+
export function reportSummary(report) {
|
|
36
|
+
if (!report) return "";
|
|
37
|
+
const left = Object.entries(report.leftOut || {}).map(([k, n]) => `${n} ${k}`);
|
|
38
|
+
return `${report.claimed} of ${report.total} resource instance(s) claimed${left.length ? `; left out: ${left.join(", ")}` : ""}.`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const el = (tag, cls, text) => {
|
|
42
|
+
const n = document.createElement(tag);
|
|
43
|
+
if (cls) n.className = cls;
|
|
44
|
+
if (text !== undefined) n.textContent = text;
|
|
45
|
+
return n;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const code = (text) => {
|
|
49
|
+
const c = el("code", "ad-cmd", text);
|
|
50
|
+
c.title = "click to copy";
|
|
51
|
+
c.tabIndex = 0;
|
|
52
|
+
c.addEventListener("click", () => navigator.clipboard?.writeText(text).catch(() => {}));
|
|
53
|
+
return c;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Draw the tab. `s.answer` is GET /api/adopt; `s.reports[member]` a report
|
|
58
|
+
* answer; `s.runs[member]` the newest adoption started for it.
|
|
59
|
+
*/
|
|
60
|
+
export function renderAdopt(host, s, ui) {
|
|
61
|
+
host.replaceChildren();
|
|
62
|
+
host.appendChild(el("div", "tg-legend", ADOPT_LEGEND));
|
|
63
|
+
const a = s.answer;
|
|
64
|
+
if (!a) return void host.appendChild(el("div", "tg-legend", "reading what each member is offered"));
|
|
65
|
+
if (a.error) return void host.appendChild(el("div", "tg-refusal", a.error));
|
|
66
|
+
if (a.refusal) {
|
|
67
|
+
const r = el("div", "tg-refusal", a.refusal.error);
|
|
68
|
+
if (a.refusal.remedy) r.title = a.refusal.remedy;
|
|
69
|
+
host.appendChild(r);
|
|
70
|
+
}
|
|
71
|
+
if (a.recorded) host.appendChild(el("div", "tg-legend ad-recorded", a.recorded));
|
|
72
|
+
const offers = a.offers || [];
|
|
73
|
+
if (!offers.length) host.appendChild(el("div", "tg-legend", "No member here is offered adoption: behold offers it for a terraform or a pulumi member."));
|
|
74
|
+
for (const o of offers) {
|
|
75
|
+
const card = el("div", "ad-card");
|
|
76
|
+
card.appendChild(el("h3", null, `${o.member} · ${o.kind}${o.engine ? ` to ${o.engine}` : ""} · ${o.dir}`));
|
|
77
|
+
if (!o.offered) {
|
|
78
|
+
card.appendChild(el("div", "tg-legend", o.waits || "not offered"));
|
|
79
|
+
host.appendChild(card);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (o.kind === "pulumi") {
|
|
83
|
+
renderPulumiCard(card, o, s, ui, null, { el, code });
|
|
84
|
+
host.appendChild(card);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const gains = el("ul", "ad-list");
|
|
88
|
+
for (const g of o.gains || []) gains.appendChild(el("li", null, g));
|
|
89
|
+
card.appendChild(el("div", "ad-label", "What it gains"));
|
|
90
|
+
card.appendChild(gains);
|
|
91
|
+
const limits = el("ul", "ad-list");
|
|
92
|
+
for (const g of o.limits || []) limits.appendChild(el("li", null, g));
|
|
93
|
+
card.appendChild(el("div", "ad-label", "What it does not"));
|
|
94
|
+
card.appendChild(limits);
|
|
95
|
+
if (!o.recorded && o.state && !o.state.present) card.appendChild(el("div", "tg-legend", o.stateHint || ""));
|
|
96
|
+
|
|
97
|
+
const row = el("div", "ad-row");
|
|
98
|
+
const read = el("button", null, s.reports[o.member] ? "Read the report again" : "Read the report");
|
|
99
|
+
read.type = "button";
|
|
100
|
+
read.disabled = !!a.refusal || !!s.reading[o.member] || (!o.recorded && o.state && !o.state.present);
|
|
101
|
+
read.addEventListener("click", () => ui.read(o.member));
|
|
102
|
+
row.appendChild(read);
|
|
103
|
+
const start = el("button", null, "Start adoption");
|
|
104
|
+
start.type = "button";
|
|
105
|
+
start.disabled = !!a.refusal || !(o.start && o.start.offered) || !!s.starting;
|
|
106
|
+
start.title = o.start && o.start.offered ? `Runs ${o.command}. chant records a pending gate; nothing is written before approval.` : (o.start && o.start.why) || "";
|
|
107
|
+
start.addEventListener("click", () => ui.start(o.member));
|
|
108
|
+
row.appendChild(start);
|
|
109
|
+
card.appendChild(row);
|
|
110
|
+
card.appendChild(el("div", "ad-label", "The command"));
|
|
111
|
+
card.appendChild(code(o.command));
|
|
112
|
+
|
|
113
|
+
const r = s.reports[o.member];
|
|
114
|
+
if (r) {
|
|
115
|
+
if (r.error) card.appendChild(el("div", "tg-refusal", r.remedy ? `${r.error} ${r.remedy}` : r.error));
|
|
116
|
+
else {
|
|
117
|
+
if (r.recorded) card.appendChild(el("div", "tg-legend ad-recorded", "recorded"));
|
|
118
|
+
card.appendChild(el("div", "tg-legend", r.words));
|
|
119
|
+
if (r.failed && r.failed.output) card.appendChild(el("pre", "ad-out", r.failed.output));
|
|
120
|
+
if (r.report) {
|
|
121
|
+
card.appendChild(el("div", "ad-summary", reportSummary(r.report)));
|
|
122
|
+
const t = el("table", "ad-table");
|
|
123
|
+
for (const g of reportGroups(r.report)) {
|
|
124
|
+
const th = el("tr", "ad-group");
|
|
125
|
+
const cell = el("th", null, g.title);
|
|
126
|
+
cell.colSpan = 4;
|
|
127
|
+
th.appendChild(cell);
|
|
128
|
+
t.appendChild(th);
|
|
129
|
+
for (const e of g.rows) {
|
|
130
|
+
const tr = el("tr", `ad-${e.fate}`);
|
|
131
|
+
tr.appendChild(el("td", "ad-addr", e.address));
|
|
132
|
+
tr.appendChild(el("td", null, e.type));
|
|
133
|
+
tr.appendChild(el("td", "ad-status", e.status));
|
|
134
|
+
const why = el("td", null, e.why);
|
|
135
|
+
why.title = e.detail || "";
|
|
136
|
+
tr.appendChild(why);
|
|
137
|
+
t.appendChild(tr);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
card.appendChild(t);
|
|
141
|
+
} else if (r.absent) card.appendChild(el("div", "tg-legend", r.absent));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const run = s.runs[o.member];
|
|
145
|
+
if (run) {
|
|
146
|
+
card.appendChild(el("div", "ad-label", `Started ${run.started_at || ""}`));
|
|
147
|
+
card.appendChild(el("div", "tg-legend", run.words || run.error || ""));
|
|
148
|
+
if (run.approve) {
|
|
149
|
+
card.appendChild(el("div", "ad-label", "Approve it (a person, not behold)"));
|
|
150
|
+
card.appendChild(code(run.approve));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
host.appendChild(card);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Mount the tab. `fetchJson(url, init)` answers parsed JSON. */
|
|
158
|
+
export function startAdopt(host, { fetchJson, events, toast = () => {} }) {
|
|
159
|
+
const s = { answer: null, reports: {}, reading: {}, runs: {}, starting: false };
|
|
160
|
+
const ids = {};
|
|
161
|
+
const redraw = () => renderAdopt(host, s, ui);
|
|
162
|
+
const readOffer = async () => {
|
|
163
|
+
s.answer = await fetchJson("/api/adopt").catch((e) => ({ error: String(e) }));
|
|
164
|
+
redraw();
|
|
165
|
+
};
|
|
166
|
+
const readRun = async (member) => {
|
|
167
|
+
const id = ids[member];
|
|
168
|
+
if (!id) return;
|
|
169
|
+
s.runs[member] = await fetchJson(`/api/adopt/runs/${encodeURIComponent(id)}`).catch((e) => ({ error: String(e) }));
|
|
170
|
+
redraw();
|
|
171
|
+
};
|
|
172
|
+
const ui = {
|
|
173
|
+
read: async (member) => {
|
|
174
|
+
s.reading[member] = true;
|
|
175
|
+
redraw();
|
|
176
|
+
s.reports[member] = await fetchJson(`/api/adopt/report?member=${encodeURIComponent(member)}`).catch((e) => ({ error: String(e) }));
|
|
177
|
+
s.reading[member] = false;
|
|
178
|
+
redraw();
|
|
179
|
+
},
|
|
180
|
+
start: async (member) => {
|
|
181
|
+
s.starting = true;
|
|
182
|
+
redraw();
|
|
183
|
+
const r = await fetchJson("/api/adopt/start", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ member }) }).catch((e) => ({ error: String(e) }));
|
|
184
|
+
s.starting = false;
|
|
185
|
+
if (r.error) {
|
|
186
|
+
toast(`✗ adopt ${member}: ${r.error}`, false);
|
|
187
|
+
s.runs[member] = { error: r.remedy ? `${r.error} ${r.remedy}` : r.error };
|
|
188
|
+
redraw();
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
toast(`▶ ${r.command}`, true);
|
|
192
|
+
ids[member] = r.id;
|
|
193
|
+
await readRun(member);
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
if (events) {
|
|
197
|
+
events.addEventListener("adopt-run", (e) => {
|
|
198
|
+
for (const [member, id] of Object.entries(ids)) if (id === e.data) readRun(member);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
readOffer();
|
|
202
|
+
return { reload: readOffer };
|
|
203
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { reportGroups, reportSummary } from "./adopt.js";
|
|
3
|
+
|
|
4
|
+
// behold#999: the Adopt tab's grouping of promote's report.
|
|
5
|
+
const report = {
|
|
6
|
+
claimed: 2,
|
|
7
|
+
total: 4,
|
|
8
|
+
leftOut: { MISSING: 1, UNTAGGABLE: 1 },
|
|
9
|
+
entries: [
|
|
10
|
+
{ address: "a.one", fate: "claimed", status: "VERIFIED" },
|
|
11
|
+
{ address: "a.two", fate: "left-out", status: "MISSING" },
|
|
12
|
+
{ address: "a.three", fate: "claimed", status: "DRIFTED" },
|
|
13
|
+
{ address: "a.four", fate: "left-out", status: "UNTAGGABLE" },
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe("the Adopt tab (behold#999)", () => {
|
|
18
|
+
it("groups every entry by fate, claimed first, none dropped", () => {
|
|
19
|
+
const g = reportGroups(report);
|
|
20
|
+
expect(g.map((x) => x.title)).toEqual(["claimed (2)", "left out (2)"]);
|
|
21
|
+
expect(g.flatMap((x) => x.rows.map((r) => r.address))).toEqual(["a.one", "a.three", "a.two", "a.four"]);
|
|
22
|
+
});
|
|
23
|
+
it("counts what is claimed and what is left out, by status", () => {
|
|
24
|
+
expect(reportSummary(report)).toBe("2 of 4 resource instance(s) claimed; left out: 1 MISSING, 1 UNTAGGABLE.");
|
|
25
|
+
expect(reportSummary(null)).toBe("");
|
|
26
|
+
});
|
|
27
|
+
});
|