@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
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/behold",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "Your infrastructure repo as a graph, from the files. Draws Terraform roots, no state needed.",
|
|
7
7
|
"bin": {
|
|
8
8
|
"behold": "./bin/behold.js"
|
|
9
9
|
},
|
|
10
|
+
"mcpName": "io.github.INTENTIUS/behold",
|
|
10
11
|
"files": [
|
|
11
12
|
"bin",
|
|
12
13
|
"dist",
|
|
14
|
+
"schemas",
|
|
13
15
|
"web",
|
|
14
16
|
"example-writes",
|
|
15
17
|
"example-k8s",
|
|
@@ -41,31 +43,47 @@
|
|
|
41
43
|
"preview:tour": "tsx scripts/tour-preview.ts",
|
|
42
44
|
"tsc": "tsc --noEmit",
|
|
43
45
|
"test": "vitest run",
|
|
44
|
-
"
|
|
46
|
+
"generate:graph-layout": "tsx src/graph-db/generate-layout.ts",
|
|
47
|
+
"check:graph-layout": "tsx src/graph-db/generate-layout.ts --check",
|
|
48
|
+
"generate:icons": "tsx src/generate-icons.ts",
|
|
49
|
+
"check:icons": "tsx src/generate-icons.ts --check",
|
|
50
|
+
"check:browser-bundle": "tsx scripts/check-browser-bundle.mts",
|
|
51
|
+
"build": "tsx src/graph-db/generate-layout.ts && tsx src/generate-icons.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 && npm run build:graph",
|
|
52
|
+
"build:graph": "esbuild index=src/graph-package.ts cli=src/graph-bin.ts --bundle --splitting --platform=node --format=esm --external:@intentius/pinhole --external:@intentius/chant-k8s-client --external:@kubernetes/client-node --external:ajv --outdir=packages/graph/dist",
|
|
53
|
+
"check:graph-package": "tsx scripts/graph-package-check.ts",
|
|
54
|
+
"build:viewer": "tsx scripts/build-viewer.mts",
|
|
45
55
|
"prepare": "npm run build",
|
|
46
56
|
"prepublishOnly": "npm run build"
|
|
47
57
|
},
|
|
48
58
|
"dependencies": {
|
|
49
59
|
"@cdktn/hcl2json": "^0.24.0",
|
|
50
60
|
"@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.
|
|
54
|
-
"@intentius/pinhole": "^0.
|
|
61
|
+
"@intentius/chant": "^0.124.98",
|
|
62
|
+
"@intentius/chant-k8s-client": "^0.124.98",
|
|
63
|
+
"@intentius/chant-lexicon-terraform": "^0.124.98",
|
|
64
|
+
"@intentius/pinhole": "^0.6.0",
|
|
55
65
|
"@modelcontextprotocol/sdk": "1.30.1",
|
|
56
66
|
"ajv": "^8.20.0",
|
|
57
67
|
"hono": "^4.13.13"
|
|
58
68
|
},
|
|
59
69
|
"peerDependencies": {
|
|
70
|
+
"@ladybugdb/core": ">=0.22.0",
|
|
60
71
|
"playwright-core": "^1.62.0"
|
|
61
72
|
},
|
|
62
73
|
"peerDependenciesMeta": {
|
|
63
74
|
"playwright-core": {
|
|
64
75
|
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"@ladybugdb/core": {
|
|
78
|
+
"optional": true
|
|
65
79
|
}
|
|
66
80
|
},
|
|
67
81
|
"devDependencies": {
|
|
68
|
-
"@intentius/chant-lexicon-
|
|
82
|
+
"@intentius/chant-lexicon-k8s": "0.124.98",
|
|
83
|
+
"@intentius/chant-lexicon-otel": "0.124.98",
|
|
84
|
+
"@intentius/chant-lexicon-prometheus": "0.124.98",
|
|
85
|
+
"@intentius/chant-lexicon-pulumi": "^0.124.98",
|
|
86
|
+
"@intentius/chant-lexicon-sql": "^0.124.98",
|
|
69
87
|
"@types/node": "^26.4.1",
|
|
70
88
|
"esbuild": "^0.28.0",
|
|
71
89
|
"playwright": "^1.62.1",
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://intentius.io/behold/schemas/graph/v1/graph.schema.json",
|
|
4
|
+
"title": "behold-graph/1",
|
|
5
|
+
"description": "A behold graph as flat node and edge lists (behold#1066). Field names follow Grafana's node graph panel: a node has id, title, subtitle, mainstat, secondarystat, color and detail__* fields, and an edge has id, source and target, so the panel reads the lists with no transform. Every edge's source and target is the id of a node in the same document. No field holds an absolute path: files are relative to the repository root. Within behold-graph/1 fields are only ever added, and a reader ignores the fields it does not know. A change a reader could not ignore is behold-graph/2, which a behold-graph/1 reader refuses.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["schema", "generator", "origin", "cut", "nodes", "edges", "groups", "notes"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"schema": { "const": "behold-graph/1", "description": "The document's version. A reader refuses one it does not know." },
|
|
10
|
+
"generator": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"description": "The behold that wrote the document and the chant that read the graph.",
|
|
13
|
+
"required": ["behold"],
|
|
14
|
+
"properties": {
|
|
15
|
+
"behold": { "type": "string" },
|
|
16
|
+
"chant": { "type": "string" }
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"origin": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"description": "What was read.",
|
|
22
|
+
"required": ["dir"],
|
|
23
|
+
"properties": {
|
|
24
|
+
"dir": { "$ref": "#/$defs/relativePath", "description": "The directory read, relative to the repository root. '.' is the root." },
|
|
25
|
+
"rev": { "type": "string", "description": "The revision the graph was read at, when it was not read from the working tree." }
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"cut": {
|
|
29
|
+
"type": "object",
|
|
30
|
+
"description": "Which part of the graph the document holds. 'whole' is every card the view draws; a cut such as 'around' or 'changed' carries its parameters beside kind.",
|
|
31
|
+
"required": ["kind"],
|
|
32
|
+
"properties": { "kind": { "type": "string", "minLength": 1 } }
|
|
33
|
+
},
|
|
34
|
+
"nodes": { "type": "array", "items": { "$ref": "#/$defs/node" } },
|
|
35
|
+
"edges": { "type": "array", "items": { "$ref": "#/$defs/edge" } },
|
|
36
|
+
"groups": { "type": "array", "items": { "$ref": "#/$defs/group" } },
|
|
37
|
+
"notes": { "type": "array", "items": { "$ref": "#/$defs/note" } },
|
|
38
|
+
"layout": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"description": "Positions a host can draw without laying the graph out again.",
|
|
41
|
+
"required": ["nodes"],
|
|
42
|
+
"properties": {
|
|
43
|
+
"nodes": { "type": "object", "additionalProperties": { "$ref": "#/$defs/point" } },
|
|
44
|
+
"groups": { "type": "object", "additionalProperties": { "$ref": "#/$defs/rect" } }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"$defs": {
|
|
49
|
+
"relativePath": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"minLength": 1,
|
|
52
|
+
"not": { "pattern": "^(/|[A-Za-z]:[\\\\/]|\\.\\.(/|$))" }
|
|
53
|
+
},
|
|
54
|
+
"status": { "enum": ["good", "warn", "accent", "neutral", "runtime"] },
|
|
55
|
+
"node": {
|
|
56
|
+
"type": "object",
|
|
57
|
+
"required": ["id", "title", "subtitle", "kind", "lexicon", "attrs"],
|
|
58
|
+
"properties": {
|
|
59
|
+
"id": { "type": "string", "minLength": 1, "description": "The graph IR's node id, unique in the document." },
|
|
60
|
+
"title": { "type": "string", "description": "What the card is titled." },
|
|
61
|
+
"subtitle": { "type": "string", "description": "The tool that declares it: terraform, kubernetes, helm, choudoufu, or the chant lexicon." },
|
|
62
|
+
"kind": { "type": "string", "description": "The resource type." },
|
|
63
|
+
"lexicon": { "type": "string" },
|
|
64
|
+
"box": { "type": "string", "description": "The id of the innermost group the card is drawn in." },
|
|
65
|
+
"file": { "$ref": "#/$defs/relativePath", "description": "The declaring file, relative to the repository root. Absent when behold cannot place it there." },
|
|
66
|
+
"seed": { "type": "boolean", "description": "In an 'around' cut, true on the cards the cut was asked for." },
|
|
67
|
+
"diff": { "enum": ["added", "removed", "changed", "neighbour"], "description": "In a 'changed' cut, what happened to the card between the two revisions, or neighbour for a card kept for being near one that did." },
|
|
68
|
+
"changedAttrs": { "type": "array", "items": { "type": "string" }, "description": "On a changed card, the attribute keys whose values differ between the revisions." },
|
|
69
|
+
"line": { "type": "integer", "minimum": 1 },
|
|
70
|
+
"change": { "type": "string", "description": "What a plan would do to it (create, update, replace, delete), when a plan was read and it changes." },
|
|
71
|
+
"status": { "$ref": "#/$defs/status" },
|
|
72
|
+
"color": { "type": "string", "pattern": "^#[0-9A-Fa-f]{6}$", "description": "A colour for status." },
|
|
73
|
+
"mainstat": { "type": ["string", "number"], "description": "The status in words." },
|
|
74
|
+
"secondarystat": { "type": ["string", "number"] },
|
|
75
|
+
"icon": { "type": "string" },
|
|
76
|
+
"stackOf": { "type": "array", "items": { "type": "string" }, "description": "On a stacked card, the ids of the cards it stands for." },
|
|
77
|
+
"detail__member": { "type": "string", "description": "The workspace member it belongs to." },
|
|
78
|
+
"detail__root": { "type": "string", "description": "The Terraform root that applies it." },
|
|
79
|
+
"detail__namespace": { "type": "string", "description": "The Kubernetes namespace it lives in." },
|
|
80
|
+
"detail__release": { "type": "string", "description": "The Helm release that installs it." },
|
|
81
|
+
"attrs": { "type": "object", "description": "The graph IR's attributes. 'source' is present only when it was asked for." }
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"edge": {
|
|
85
|
+
"type": "object",
|
|
86
|
+
"required": ["id", "source", "target", "kind", "inferred"],
|
|
87
|
+
"properties": {
|
|
88
|
+
"id": { "type": "string", "minLength": 1, "description": "Deterministic, unique in the document." },
|
|
89
|
+
"source": { "type": "string", "description": "The id of the node holding the reference." },
|
|
90
|
+
"target": { "type": "string", "description": "The id of the node it names." },
|
|
91
|
+
"kind": { "type": "string", "description": "The graph IR's edge kind: ref, needs, calls, triggers, includes, extends, or one added later." },
|
|
92
|
+
"inferred": { "type": "boolean", "description": "True when behold or chant joined the two rather than a reader stating it." },
|
|
93
|
+
"rule": { "type": "string", "description": "On an inferred edge, the join that drew it: behold:<pass>, or chant's catalog rule id. On the edge to a placeholder card (a reference that names nothing) and on each edge of a reference that names several candidates, the rule of that reference." },
|
|
94
|
+
"via": { "type": "string", "description": "The consumer-side attribute the reference flows through." },
|
|
95
|
+
"diff": { "enum": ["added", "removed"], "description": "In a 'changed' cut, set when the edge exists in one revision only." }
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"group": {
|
|
99
|
+
"type": "object",
|
|
100
|
+
"required": ["id", "title", "kind"],
|
|
101
|
+
"properties": {
|
|
102
|
+
"id": { "type": "string", "pattern": "^[a-z]+:", "description": "<kind>:<key>, never a node id." },
|
|
103
|
+
"title": { "type": "string" },
|
|
104
|
+
"kind": { "type": "string", "description": "stack (a workspace member or a Terraform root), wave, pipeline, container, or one added later." },
|
|
105
|
+
"parent": { "type": "string", "description": "The group this one is drawn inside." }
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"note": {
|
|
109
|
+
"type": "object",
|
|
110
|
+
"required": ["kind", "text"],
|
|
111
|
+
"properties": {
|
|
112
|
+
"kind": { "type": "string" },
|
|
113
|
+
"text": { "type": "string" },
|
|
114
|
+
"short": { "type": "string" },
|
|
115
|
+
"box": { "type": "string" },
|
|
116
|
+
"count": { "type": "integer", "minimum": 0 }
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"point": {
|
|
120
|
+
"type": "object",
|
|
121
|
+
"required": ["x", "y"],
|
|
122
|
+
"properties": {
|
|
123
|
+
"x": { "type": "number" },
|
|
124
|
+
"y": { "type": "number" },
|
|
125
|
+
"width": { "type": "number" },
|
|
126
|
+
"height": { "type": "number" }
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"rect": {
|
|
130
|
+
"type": "object",
|
|
131
|
+
"required": ["x", "y", "width", "height"],
|
|
132
|
+
"properties": {
|
|
133
|
+
"x": { "type": "number" },
|
|
134
|
+
"y": { "type": "number" },
|
|
135
|
+
"width": { "type": "number" },
|
|
136
|
+
"height": { "type": "number" }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -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
|
+
});
|