@intentius/behold 0.30.2 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +444 -15
- package/README.md +14 -13
- package/demos.json +14 -9
- package/dist/cli.js +53928 -26475
- package/example-carve/README.md +19 -23
- package/example-carve/app/package.json +1 -1
- package/example-carve/app/src/carved.ts +3 -3
- package/example-carve/carve-report.json +1 -1
- package/example-carve/{legacy-tf → tf-root}/terraform.tfstate +1 -1
- package/example-choudoufu-estate/README.md +7 -0
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-choudoufu-estate/scripts/choudoufu-down.sh +2 -1
- package/example-choudoufu-estate/scripts/choudoufu-up.sh +10 -3
- package/example-terraform-estate/README.md +32 -5
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/recorded/adoption/platform.json +72 -0
- package/example-terraform-estate/recorded/adoption/prod.json +224 -0
- package/example-three-cloud/README.md +111 -18
- package/example-three-cloud/aws/Pulumi.yaml +15 -0
- package/example-three-cloud/aws/index.ts +174 -0
- package/example-three-cloud/aws/package-lock.json +2725 -0
- package/example-three-cloud/aws/package.json +14 -0
- package/example-three-cloud/aws/tsconfig.json +17 -0
- package/example-three-cloud/azure/main.tf +48 -0
- package/example-three-cloud/azure/site.tf +104 -0
- package/example-three-cloud/chant.config.json +9 -0
- package/example-three-cloud/chant.workspace.json +30 -4
- package/example-three-cloud/dns/chant.config.ts +26 -1
- package/example-three-cloud/dns/src/records.component.ts +32 -6
- package/example-three-cloud/package-lock.json +48 -27
- package/example-three-cloud/package.json +8 -6
- package/example-three-cloud/scripts/emulators-up.sh +28 -1
- package/example-three-cloud/scripts/front-door.ts +679 -86
- package/package.json +13 -6
- package/web/adopt-pulumi.js +114 -0
- package/web/adopt-pulumi.test.js +28 -0
- package/web/adopt.js +203 -0
- package/web/adopt.test.js +27 -0
- package/web/app.js +358 -10
- package/web/carve-steps.js +1 -1
- package/web/carve-steps.test.js +2 -2
- package/web/change-set-overlay.js +12 -5
- package/web/change-set-overlay.test.js +22 -0
- package/web/drift-stream.js +241 -0
- package/web/drift-stream.test.js +146 -0
- package/web/edge-weight.d.ts +1 -1
- package/web/edge-weight.js +5 -1
- package/web/edge-weight.test.js +19 -0
- package/web/graph-query.js +180 -0
- package/web/graph-query.test.js +49 -0
- package/web/graph.html +107 -0
- package/web/index-diff.js +109 -0
- package/web/index-diff.test.js +39 -0
- package/web/index.html +37 -0
- package/web/kiosk-ask-tips.js +15 -5
- package/web/kiosk-ask-tips.test.js +14 -1
- package/web/kiosk-estate-scene.js +72 -8
- package/web/kiosk-light-frame.js +1 -0
- package/web/kiosk-light.js +41 -3
- package/web/kiosk-member-kind.test.js +140 -0
- package/web/kiosk-popover.js +4 -1
- package/web/kiosk-side.js +296 -0
- package/web/kiosk-side.test.js +249 -0
- package/web/kiosk-watch.js +12 -0
- package/web/kiosk-watch.test.js +15 -1
- package/web/kiosk.html +47 -1
- package/web/kiosk.js +106 -7
- package/web/member-kind.js +31 -0
- package/web/template-apps.js +245 -0
- package/web/template-apps.test.js +252 -0
- package/web/templates.js +285 -0
- package/web/templates.test.js +155 -0
- package/web/terragucci-lifecycle.js +112 -62
- package/web/terragucci-lifecycle.test.js +29 -1
- package/web/terragucci-timeline.js +39 -2
- package/web/terragucci-timeline.test.js +42 -1
- package/example-three-cloud/aws/chant.config.ts +0 -8
- package/example-three-cloud/aws/site.component.ts +0 -13
- package/example-three-cloud/aws/src/site.ts +0 -27
- package/example-three-cloud/azure/chant.config.ts +0 -1
- package/example-three-cloud/azure/src/site.component.ts +0 -13
- package/example-three-cloud/azure/src/site.ts +0 -18
- /package/example-carve/{legacy-tf → tf-root}/cdn.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/compute.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/floci-override.tf.disabled +0 -0
- /package/example-carve/{legacy-tf → tf-root}/modules/cdn/main.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/naming.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/network.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/observability.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/outputs.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/storage.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/versions.tf +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// behold#998: streamed drift, the page's half.
|
|
2
|
+
//
|
|
3
|
+
// The server narrates one run of chant's drift stream as `drift` frames on
|
|
4
|
+
// /api/events (src/drift-stream.ts): begin, start (the addresses a read
|
|
5
|
+
// expects), one record per instance as it arrives, settle (with a
|
|
6
|
+
// not-reached record already sent for every expected address no record
|
|
7
|
+
// answered), failed, end. This module folds a frame into the graph IR on
|
|
8
|
+
// screen, the same way web/pending.js folds a `member` frame: in place, the
|
|
9
|
+
// node set never changes, and it returns the ids that moved so the caller
|
|
10
|
+
// repaints only those.
|
|
11
|
+
//
|
|
12
|
+
// Reading is not a status. A card a started read has not reported yet keeps
|
|
13
|
+
// its `_status` and gains `_driftReading`, which the page draws dimmed and
|
|
14
|
+
// dashed, never filled. Only a record changes `_status`.
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The addresses of a member's cards, for the start request. A stack card
|
|
18
|
+
* (`attrs._stackOf`, src/stack-lens.ts, an estate's default zoom) is titled
|
|
19
|
+
* `<kind> ×<n>`, which is no address: the cards it holds are asked about
|
|
20
|
+
* instead, each by its id inside the member.
|
|
21
|
+
*/
|
|
22
|
+
export function memberAddresses(ir, member) {
|
|
23
|
+
const prefix = member + "/";
|
|
24
|
+
const out = [];
|
|
25
|
+
const add = (a) => {
|
|
26
|
+
if (a && !out.includes(a)) out.push(a);
|
|
27
|
+
};
|
|
28
|
+
for (const n of (ir && ir.nodes) || []) {
|
|
29
|
+
if (!n.id || !n.id.startsWith(prefix)) continue;
|
|
30
|
+
const held = n.attrs && n.attrs._stackOf;
|
|
31
|
+
if (Array.isArray(held)) {
|
|
32
|
+
for (const m of held) {
|
|
33
|
+
const id = typeof m === "string" ? m : m && typeof m.id === "string" ? m.id : "";
|
|
34
|
+
if (id.startsWith(prefix)) add(id.slice(prefix.length));
|
|
35
|
+
}
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
add(n.attrs && typeof n.attrs.address === "string" ? n.attrs.address : n.id.slice(prefix.length));
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The id of one `_stackOf` entry: a string, or an object's `id`. */
|
|
44
|
+
const heldId = (m) => (typeof m === "string" ? m : m && typeof m.id === "string" ? m.id : "");
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* behold#1021: the card a stack holds that a record or an expected address
|
|
48
|
+
* names, by the same match as a card of its own (its id, `<member>/<address>`
|
|
49
|
+
* or the record's node), or undefined. A held card's `address` is not carried
|
|
50
|
+
* on `_stackOf`, which is why memberAddresses asks about each by its id.
|
|
51
|
+
*/
|
|
52
|
+
function heldMatch(n, prefix, address, node) {
|
|
53
|
+
const held = n.attrs && n.attrs._stackOf;
|
|
54
|
+
if (!Array.isArray(held)) return undefined;
|
|
55
|
+
for (const m of held) {
|
|
56
|
+
const id = heldId(m);
|
|
57
|
+
if (!id.startsWith(prefix)) continue;
|
|
58
|
+
if ((node && (id === node || id === prefix + node)) || id === prefix + address) return id;
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The cards a record or an expected address lands on: the record's graph
|
|
65
|
+
* node when chant mapped one, else the card whose id or `address` is the
|
|
66
|
+
* address, inside the member. behold#1021: a stack card (`_stackOf`) that
|
|
67
|
+
* holds such a card is one too, so the default stacked view colours.
|
|
68
|
+
*/
|
|
69
|
+
export function cardsFor(ir, member, address, node) {
|
|
70
|
+
const prefix = member + "/";
|
|
71
|
+
const ids = [];
|
|
72
|
+
for (const n of (ir && ir.nodes) || []) {
|
|
73
|
+
if (!n.id || !n.id.startsWith(prefix)) continue;
|
|
74
|
+
const own = n.attrs && n.attrs.address;
|
|
75
|
+
// chant's workspace drift composes `node` with the member in front (`<member>/<root>/<path>`), as workspace graph does; a bare one is prefixed.
|
|
76
|
+
if ((node && (n.id === node || n.id === prefix + node)) || n.id === prefix + address || own === address || heldMatch(n, prefix, address, node)) ids.push(n.id);
|
|
77
|
+
}
|
|
78
|
+
return ids;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* behold#1021: the tones a record paints (src/drift-tone.ts `CardTone`),
|
|
83
|
+
* worst first. A stack card takes the worst of its cards' records: one drifted
|
|
84
|
+
* card in a stack of ten makes the stack drifted. `neutral` (not observed, or
|
|
85
|
+
* a record behold does not know) ranks above `runtime` and `good`, so a stack
|
|
86
|
+
* is never green while a card in it went unseen.
|
|
87
|
+
*/
|
|
88
|
+
export const TONES_WORST_FIRST = ["warn", "accent", "neutral", "runtime", "good"];
|
|
89
|
+
|
|
90
|
+
/** The worst of `tones`, by {@link TONES_WORST_FIRST}; a tone outside it ranks as neutral. */
|
|
91
|
+
export function worstTone(tones) {
|
|
92
|
+
let best = -1;
|
|
93
|
+
for (const t of tones) {
|
|
94
|
+
const i = TONES_WORST_FIRST.indexOf(t);
|
|
95
|
+
const rank = i < 0 ? TONES_WORST_FIRST.indexOf("neutral") : i;
|
|
96
|
+
if (best < 0 || rank < best) best = rank;
|
|
97
|
+
}
|
|
98
|
+
return best < 0 ? undefined : TONES_WORST_FIRST[best];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A record frame as the `_drift` a card keeps. */
|
|
102
|
+
function driftOf(frame) {
|
|
103
|
+
return {
|
|
104
|
+
status: frame.status,
|
|
105
|
+
read: frame.read,
|
|
106
|
+
label: frame.label,
|
|
107
|
+
run: frame.run,
|
|
108
|
+
...(frame.reason ? { reason: frame.reason } : {}),
|
|
109
|
+
...(frame.notReached ? { notReached: true } : {}),
|
|
110
|
+
...(frame.unknown ? { unknown: true } : {}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* behold#1021: a stack card's state for one run, `attrs._driftHeld`: the
|
|
116
|
+
* cards a start expected and the record each has had, by held id. A new run
|
|
117
|
+
* starts it afresh.
|
|
118
|
+
*/
|
|
119
|
+
function heldState(a, run) {
|
|
120
|
+
if (!a._driftHeld || a._driftHeld.run !== run) a._driftHeld = { run, expected: [], records: {} };
|
|
121
|
+
return a._driftHeld;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Paint a stack card from its held records: `_status` the worst tone, `_drift`
|
|
126
|
+
* that record's with the count in its label, each `_stackOf` entry's status
|
|
127
|
+
* the tone its record painted (the inspect pane lists them), and reading
|
|
128
|
+
* while a held card a start expected has not reported. The worst tone so far
|
|
129
|
+
* only gets worse as records arrive, so a warn, accent or neutral one paints
|
|
130
|
+
* at once; a good or runtime one waits for the last expected card, so a
|
|
131
|
+
* stack is never green while a card in it is still being read.
|
|
132
|
+
*/
|
|
133
|
+
function paintStack(a, state) {
|
|
134
|
+
const records = Object.values(state.records);
|
|
135
|
+
const worst = worstTone(records.map((r) => r.tone));
|
|
136
|
+
const atWorst = records.filter((r) => worstTone([r.tone]) === worst);
|
|
137
|
+
const held = Array.isArray(a._stackOf) ? a._stackOf : [];
|
|
138
|
+
const pending = state.expected.some((id) => !state.records[id]);
|
|
139
|
+
if (atWorst.length && (!pending || TONES_WORST_FIRST.indexOf(worst) <= TONES_WORST_FIRST.indexOf("neutral"))) {
|
|
140
|
+
const top = atWorst[0].drift;
|
|
141
|
+
const of = held.length || records.length;
|
|
142
|
+
a._status = worst;
|
|
143
|
+
a._drift = { ...top, label: `${top.label}: ${atWorst.length} of ${of} card${of === 1 ? "" : "s"}${records.length < of ? `, ${records.length} reported` : ""}` };
|
|
144
|
+
if (records.every((r) => r.drift.status === "not-observed")) a._unobserved = { reason: top.reason || "read-failed" };
|
|
145
|
+
else delete a._unobserved;
|
|
146
|
+
}
|
|
147
|
+
for (const m of held) if (m && typeof m === "object" && state.records[m.id]) m.status = state.records[m.id].tone;
|
|
148
|
+
if (pending) a._driftReading = state.run;
|
|
149
|
+
else delete a._driftReading;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function nodeById(ir) {
|
|
153
|
+
return new Map(((ir && ir.nodes) || []).map((n) => [n.id, n]));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Fold one `drift` frame into `ir`. Returns `{ moved, reading }`: the ids
|
|
158
|
+
* whose paint changed, and how many cards of this run are still reading.
|
|
159
|
+
*/
|
|
160
|
+
export function applyDriftFrame(ir, frame) {
|
|
161
|
+
const moved = [];
|
|
162
|
+
if (!ir || !frame || !frame.kind || !frame.member) return { moved, reading: 0 };
|
|
163
|
+
const byId = nodeById(ir);
|
|
164
|
+
const attrsOf = (id) => {
|
|
165
|
+
const n = byId.get(id);
|
|
166
|
+
return n ? n.attrs || (n.attrs = {}) : null;
|
|
167
|
+
};
|
|
168
|
+
if (frame.kind === "start") {
|
|
169
|
+
const prefix = frame.member + "/";
|
|
170
|
+
for (const address of frame.expected || []) {
|
|
171
|
+
for (const id of cardsFor(ir, frame.member, address, null)) {
|
|
172
|
+
const a = attrsOf(id);
|
|
173
|
+
if (!a) continue;
|
|
174
|
+
const held = heldMatch(byId.get(id), prefix, address, null);
|
|
175
|
+
if (held) {
|
|
176
|
+
const state = heldState(a, frame.run);
|
|
177
|
+
if (!state.expected.includes(held)) state.expected.push(held);
|
|
178
|
+
}
|
|
179
|
+
if (a._driftReading === frame.run) continue;
|
|
180
|
+
a._driftReading = frame.run;
|
|
181
|
+
moved.push(id);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
} else if (frame.kind === "record") {
|
|
185
|
+
const prefix = frame.member + "/";
|
|
186
|
+
for (const id of cardsFor(ir, frame.member, frame.address, frame.node)) {
|
|
187
|
+
const a = attrsOf(id);
|
|
188
|
+
if (!a) continue;
|
|
189
|
+
// behold#1021: a stack card keeps each held card's record and paints the worst.
|
|
190
|
+
const held = heldMatch(byId.get(id), prefix, frame.address, frame.node);
|
|
191
|
+
if (held) {
|
|
192
|
+
const state = heldState(a, frame.run);
|
|
193
|
+
state.records[held] = { tone: frame.tone, drift: driftOf(frame) };
|
|
194
|
+
paintStack(a, state);
|
|
195
|
+
moved.push(id);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
delete a._driftReading;
|
|
199
|
+
a._status = frame.tone;
|
|
200
|
+
a._drift = driftOf(frame);
|
|
201
|
+
if (frame.status === "not-observed") a._unobserved = { reason: frame.reason || "read-failed" };
|
|
202
|
+
else delete a._unobserved;
|
|
203
|
+
moved.push(id);
|
|
204
|
+
}
|
|
205
|
+
} else if (frame.kind === "failed" || frame.kind === "end") {
|
|
206
|
+
// Nothing more is coming for these cards: they stop reading and keep the
|
|
207
|
+
// colour they had. A settle has already resolved every card it expected.
|
|
208
|
+
for (const n of (ir && ir.nodes) || []) {
|
|
209
|
+
if (n.attrs && n.attrs._driftReading === frame.run && n.id.startsWith(frame.member + "/")) {
|
|
210
|
+
delete n.attrs._driftReading;
|
|
211
|
+
moved.push(n.id);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
let reading = 0;
|
|
216
|
+
for (const n of (ir && ir.nodes) || []) if (n.attrs && n.attrs._driftReading === frame.run) reading++;
|
|
217
|
+
return { moved, reading };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** The now-line for a frame, or null when the frame says nothing a person needs. */
|
|
221
|
+
export function driftLine(frame, reading) {
|
|
222
|
+
if (!frame) return null;
|
|
223
|
+
switch (frame.kind) {
|
|
224
|
+
case "begin":
|
|
225
|
+
return frame.plan === "per-resource"
|
|
226
|
+
? `↻ streaming drift for ${frame.member}, one resource at a time (${frame.resources.length})`
|
|
227
|
+
: `↻ streaming drift for ${frame.member}`;
|
|
228
|
+
case "start":
|
|
229
|
+
return `↻ ${frame.member}: reading ${frame.resource || "the member"} (${reading} card${reading === 1 ? "" : "s"} reading)`;
|
|
230
|
+
case "settle":
|
|
231
|
+
return frame.notReached && frame.notReached.length
|
|
232
|
+
? `↻ ${frame.member}: ${frame.resource || "the read"} settled, ${frame.notReached.length} not reached`
|
|
233
|
+
: null;
|
|
234
|
+
case "failed":
|
|
235
|
+
return `✗ ${frame.member}${frame.resource ? ` ${frame.resource}` : ""}: ${frame.error}`;
|
|
236
|
+
case "end":
|
|
237
|
+
return `■ drift stream for ${frame.member} done`;
|
|
238
|
+
default:
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { applyDriftFrame, cardsFor, memberAddresses, worstTone } from "./drift-stream.js";
|
|
3
|
+
|
|
4
|
+
// behold#998/#1014: the addresses the page sends to POST /api/workspace/drift/stream.
|
|
5
|
+
describe("memberAddresses", () => {
|
|
6
|
+
it("names each card of the member by its address, once", () => {
|
|
7
|
+
const ir = {
|
|
8
|
+
nodes: [
|
|
9
|
+
{ id: "monolith/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
|
|
10
|
+
{ id: "monolith/aws_iam_policy.team_a", attrs: {} },
|
|
11
|
+
{ id: "team-a/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
|
|
12
|
+
{ id: "monolith/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
|
|
13
|
+
],
|
|
14
|
+
};
|
|
15
|
+
expect(memberAddresses(ir, "monolith")).toEqual(["aws_iam_role.team_a", "aws_iam_policy.team_a"]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("asks about the cards a stack holds, never the stack's `<kind> ×<n>` title", () => {
|
|
19
|
+
// An estate's default zoom stacks alike cards (src/stack-lens.ts); the
|
|
20
|
+
// stack's address is its title, which the server's resourceBlocks drops,
|
|
21
|
+
// so before this the start named no resource and ended at once.
|
|
22
|
+
const ir = {
|
|
23
|
+
nodes: [
|
|
24
|
+
{
|
|
25
|
+
id: "monolith/aws_iam_policy ×3",
|
|
26
|
+
attrs: {
|
|
27
|
+
address: "aws_iam_policy ×3",
|
|
28
|
+
_stackOf: [{ id: "monolith/aws_iam_policy.team_a" }, { id: "monolith/aws_iam_policy.team_b", status: "ok" }, "monolith/aws_iam_policy.team_c"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{ id: "monolith/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
|
|
32
|
+
{ id: "team-b/aws_iam_policy ×3", attrs: { _stackOf: [{ id: "team-b/aws_iam_policy.x" }] } },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
expect(memberAddresses(ir, "monolith")).toEqual([
|
|
36
|
+
"aws_iam_policy.team_a",
|
|
37
|
+
"aws_iam_policy.team_b",
|
|
38
|
+
"aws_iam_policy.team_c",
|
|
39
|
+
"aws_iam_role.team_a",
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// behold#1021: in the default stacked view a record colours the stack card that holds its card, worst tone wins.
|
|
45
|
+
describe("streamed drift on a stack card", () => {
|
|
46
|
+
const stacked = () => ({
|
|
47
|
+
nodes: [
|
|
48
|
+
{
|
|
49
|
+
id: "monolith/aws_iam_policy ×3",
|
|
50
|
+
attrs: {
|
|
51
|
+
address: "aws_iam_policy ×3",
|
|
52
|
+
_status: "neutral",
|
|
53
|
+
_stackOf: [{ id: "monolith/aws_iam_policy.team_a" }, { id: "monolith/aws_iam_policy.team_b" }, "monolith/aws_iam_policy.team_c"],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{ id: "monolith/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
|
|
57
|
+
{ id: "team-a/aws_iam_policy ×3", attrs: { _stackOf: [{ id: "team-a/aws_iam_policy.team_a" }] } },
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
const ADDRS = ["aws_iam_policy.team_a", "aws_iam_policy.team_b", "aws_iam_policy.team_c", "aws_iam_role.team_a"];
|
|
61
|
+
const start = (ir) => applyDriftFrame(ir, { run: 7, kind: "start", member: "monolith", expected: ADDRS });
|
|
62
|
+
const record = (ir, address, tone, status, extra = {}) =>
|
|
63
|
+
applyDriftFrame(ir, { run: 7, kind: "record", member: "monolith", address, node: null, status, read: "ownership", tone, label: status, ...extra });
|
|
64
|
+
|
|
65
|
+
it("cardsFor finds the stack card that holds the address, in its own member only", () => {
|
|
66
|
+
const ir = stacked();
|
|
67
|
+
expect(cardsFor(ir, "monolith", "aws_iam_policy.team_c", null)).toEqual(["monolith/aws_iam_policy ×3"]);
|
|
68
|
+
expect(cardsFor(ir, "monolith", "x", "monolith/aws_iam_policy.team_b")).toEqual(["monolith/aws_iam_policy ×3"]);
|
|
69
|
+
expect(cardsFor(ir, "monolith", "x", "aws_iam_policy.team_a")).toEqual(["monolith/aws_iam_policy ×3"]);
|
|
70
|
+
expect(cardsFor(ir, "monolith", "aws_iam_role.team_a", null)).toEqual(["monolith/aws_iam_role.team_a"]);
|
|
71
|
+
expect(cardsFor(ir, "team-a", "aws_iam_policy.team_b", null)).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("a start marks the stack reading; it reads until every held card reported", () => {
|
|
75
|
+
const ir = stacked();
|
|
76
|
+
expect(start(ir).reading).toBe(2);
|
|
77
|
+
const stack = ir.nodes[0].attrs;
|
|
78
|
+
expect(stack._driftReading).toBe(7);
|
|
79
|
+
record(ir, "aws_iam_policy.team_a", "good", "in-sync");
|
|
80
|
+
record(ir, "aws_iam_policy.team_b", "good", "in-sync");
|
|
81
|
+
expect(stack._driftReading).toBe(7);
|
|
82
|
+
// A green so far is no claim while a card is unread: the stack keeps its colour.
|
|
83
|
+
expect(stack._status).toBe("neutral");
|
|
84
|
+
expect(stack._drift).toBeUndefined();
|
|
85
|
+
const { moved } = record(ir, "aws_iam_policy.team_c", "good", "in-sync");
|
|
86
|
+
expect(moved).toEqual(["monolith/aws_iam_policy ×3"]);
|
|
87
|
+
expect(stack._driftReading).toBeUndefined();
|
|
88
|
+
expect(stack._status).toBe("good");
|
|
89
|
+
expect(stack._drift.label).toBe("in-sync: 3 of 3 cards");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("worst tone wins, and paints as soon as it arrives", () => {
|
|
93
|
+
const ir = stacked();
|
|
94
|
+
start(ir);
|
|
95
|
+
const stack = ir.nodes[0].attrs;
|
|
96
|
+
record(ir, "aws_iam_policy.team_a", "good", "in-sync");
|
|
97
|
+
record(ir, "aws_iam_policy.team_b", "warn", "drifted");
|
|
98
|
+
expect(stack._status).toBe("warn");
|
|
99
|
+
expect(stack._drift.status).toBe("drifted");
|
|
100
|
+
expect(stack._drift.label).toBe("drifted: 1 of 3 cards, 2 reported");
|
|
101
|
+
expect(stack._driftReading).toBe(7);
|
|
102
|
+
record(ir, "aws_iam_policy.team_c", "accent", "pending");
|
|
103
|
+
expect(stack._status).toBe("warn");
|
|
104
|
+
expect(stack._driftReading).toBeUndefined();
|
|
105
|
+
// The pane's list carries each held card's tone; a bare-string entry stays a string.
|
|
106
|
+
expect(stack._stackOf).toEqual([
|
|
107
|
+
{ id: "monolith/aws_iam_policy.team_a", status: "good" },
|
|
108
|
+
{ id: "monolith/aws_iam_policy.team_b", status: "warn" },
|
|
109
|
+
"monolith/aws_iam_policy.team_c",
|
|
110
|
+
]);
|
|
111
|
+
// The lone card is untouched by the stack's records.
|
|
112
|
+
expect(ir.nodes[1].attrs._status).toBeUndefined();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("an unobserved card keeps a stack from green; all unobserved marks the stack unobserved", () => {
|
|
116
|
+
const ir = stacked();
|
|
117
|
+
start(ir);
|
|
118
|
+
const stack = ir.nodes[0].attrs;
|
|
119
|
+
record(ir, "aws_iam_policy.team_a", "good", "in-sync");
|
|
120
|
+
record(ir, "aws_iam_policy.team_b", "neutral", "not-observed", { reason: "read-failed", notReached: true });
|
|
121
|
+
record(ir, "aws_iam_policy.team_c", "good", "in-sync");
|
|
122
|
+
expect(stack._status).toBe("neutral");
|
|
123
|
+
expect(stack._unobserved).toBeUndefined();
|
|
124
|
+
const all = stacked();
|
|
125
|
+
start(all);
|
|
126
|
+
for (const a of ADDRS.slice(0, 3)) record(all, a, "neutral", "not-observed", { reason: "not-reached", notReached: true });
|
|
127
|
+
expect(all.nodes[0].attrs._unobserved).toEqual({ reason: "not-reached" });
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("a new run starts the stack afresh", () => {
|
|
131
|
+
const ir = stacked();
|
|
132
|
+
start(ir);
|
|
133
|
+
for (const a of ADDRS.slice(0, 3)) record(ir, a, "warn", "drifted");
|
|
134
|
+
applyDriftFrame(ir, { run: 8, kind: "start", member: "monolith", expected: ADDRS });
|
|
135
|
+
for (const a of ADDRS.slice(0, 3)) applyDriftFrame(ir, { run: 8, kind: "record", member: "monolith", address: a, node: null, status: "in-sync", read: "ownership", tone: "good", label: "in-sync" });
|
|
136
|
+
expect(ir.nodes[0].attrs._status).toBe("good");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("worstTone ranks warn, accent, neutral, runtime, good; an unknown tone as neutral", () => {
|
|
140
|
+
expect(worstTone(["good", "runtime"])).toBe("runtime");
|
|
141
|
+
expect(worstTone(["good", "neutral", "accent"])).toBe("accent");
|
|
142
|
+
expect(worstTone(["good", "bogus"])).toBe("neutral");
|
|
143
|
+
expect(worstTone([])).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
package/web/edge-weight.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Types for src/stack-lens.ts, which keeps the traffic path's lines when a card carries a count instead (#877).
|
|
2
2
|
export const WEIGHTS: Record<string, string>;
|
|
3
3
|
export function isWired(e: { viaAttr?: string }): boolean;
|
|
4
|
-
export function edgeWeights(edges?: Array<{ from: string; to: string; kind?: string; viaAttr?: string; inferred?: boolean }>, kindOf?: Map<string, string | undefined>): Map<string, string>;
|
|
4
|
+
export function edgeWeights(edges?: Array<{ from: string; to: string; kind?: string; viaAttr?: string; inferred?: boolean; origin?: string }>, kindOf?: Map<string, string | undefined>): Map<string, string>;
|
|
5
5
|
export function weightLegend(weights: Map<string, string>): Array<{ weight: string; label: string; title: string; count: number }>;
|
package/web/edge-weight.js
CHANGED
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
// put together. Plumbing that more than two cards share (one role for half
|
|
10
10
|
// the estate) says nothing at all, so it draws no edge.
|
|
11
11
|
//
|
|
12
|
+
// An edge chant derived (`origin: "derived"` with the `rule` that drew it,
|
|
13
|
+
// chant#4522/#4523, behold#1030) is a match chant made, not a declaration, so
|
|
14
|
+
// it weighs as an inferred one does.
|
|
15
|
+
//
|
|
12
16
|
// Only references are weighed: a CI edge (needs, calls, triggers, …) keeps its
|
|
13
17
|
// own kind's style (./edge-kind.js).
|
|
14
18
|
|
|
@@ -52,7 +56,7 @@ export function edgeWeights(edges = [], kindOf = new Map()) {
|
|
|
52
56
|
if (plumbing(e)) {
|
|
53
57
|
const hub = PLUMBING_KIND.test(kindOf.get(e.to) || "") ? e.to : e.from;
|
|
54
58
|
w = (sharers.get(hub)?.size ?? 0) > 2 ? "hidden" : "plumbing";
|
|
55
|
-
} else if (e.inferred) w = "inferred";
|
|
59
|
+
} else if (e.inferred || e.origin === "derived") w = "inferred";
|
|
56
60
|
else if (isWired(e)) w = "wired";
|
|
57
61
|
else w = "reference";
|
|
58
62
|
out.set(`${e.from}→${e.to}`, w);
|
package/web/edge-weight.test.js
CHANGED
|
@@ -47,3 +47,22 @@ describe("edgeWeights (#878)", () => {
|
|
|
47
47
|
expect(weightLegend(new Map([["x→y", "reference"]]))).toEqual([]);
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
|
+
|
|
51
|
+
describe("edgeWeights over chant's derived edges (behold#1030)", () => {
|
|
52
|
+
it("weighs an edge chant derived as inferred, as the matcher's were", () => {
|
|
53
|
+
const kindOf = new Map([
|
|
54
|
+
["db", "AWS::RDS::DBInstance"],
|
|
55
|
+
["group", "AWS::RDS::DBSubnetGroup"],
|
|
56
|
+
]);
|
|
57
|
+
const w = edgeWeights(
|
|
58
|
+
[{ from: "db", to: "group", kind: "ref", viaAttr: "DBSubnetGroupName", origin: "derived", rule: "aws:AWS::RDS::DBInstance:DBSubnetGroupName" }],
|
|
59
|
+
kindOf,
|
|
60
|
+
);
|
|
61
|
+
expect(w.get("db→group")).toBe("inferred");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("keeps a declared edge a reference", () => {
|
|
65
|
+
const w = edgeWeights([{ from: "db", to: "group", kind: "ref", viaAttr: "DBSubnetGroupName", origin: "declared" }], new Map());
|
|
66
|
+
expect(w.get("db→group")).toBe("reference");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* behold#1027: the graph pane's page logic (web/graph.html).
|
|
3
|
+
*
|
|
4
|
+
* A Cypher box over GET /api/graphdb/query, a resolve box over
|
|
5
|
+
* GET /api/graphdb/resolve with the templates that apply to the node it lands
|
|
6
|
+
* on, and a small drawing of each answer: its nodes and the REF edges among
|
|
7
|
+
* them, derived edges dashed and labelled with their rule. Every answer shows
|
|
8
|
+
* when each source was read. The page only reads: every request it makes is a
|
|
9
|
+
* GET.
|
|
10
|
+
*
|
|
11
|
+
* The pure helpers are exported for web/graph-query.test.js; `initGraphPane`
|
|
12
|
+
* wires them to the page.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** The route URL for a Cypher query and its parameters. */
|
|
16
|
+
export function queryUrl(cypher, params) {
|
|
17
|
+
const q = new URLSearchParams({ cypher });
|
|
18
|
+
if (params && Object.keys(params).length) q.set("params", JSON.stringify(params));
|
|
19
|
+
return `/api/graphdb/query?${q}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The route URL for resolving a resource. */
|
|
23
|
+
export function resolveUrl(ref) {
|
|
24
|
+
return `/api/graphdb/resolve?${new URLSearchParams({ ref })}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The route URL for one template on one node. */
|
|
28
|
+
export function templateUrl(name, node, inputs = {}) {
|
|
29
|
+
const q = new URLSearchParams({ name, node });
|
|
30
|
+
for (const [k, v] of Object.entries(inputs)) q.set(`in.${k}`, v);
|
|
31
|
+
return `/api/graphdb/template?${q}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** One line per source: what it is and when it was read ("declared" when nothing was read live). */
|
|
35
|
+
export function sourceLines(sources) {
|
|
36
|
+
return (sources ?? []).map((s) => {
|
|
37
|
+
const what = `${s.member ? `${s.member}: ` : ""}${s.name}${s.version ? ` ${s.version}` : ""} (${s.source}, ${s.scopeKey})`;
|
|
38
|
+
const when = s.observedAt ? `observed ${s.observedAt}` : "declared source, not observed";
|
|
39
|
+
return `${what}: ${when}; loaded ${s.readAt}; ${s.nodes} nodes, ${s.edges} edges`;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Node positions on a circle, in answer order; small answers get a readable radius. */
|
|
44
|
+
export function circleLayout(nodes, size = 520) {
|
|
45
|
+
const n = nodes.length;
|
|
46
|
+
const r = n <= 1 ? 0 : Math.min(size / 2 - 60, 40 + n * 14);
|
|
47
|
+
const c = size / 2;
|
|
48
|
+
const at = {};
|
|
49
|
+
nodes.forEach((node, i) => {
|
|
50
|
+
const a = (2 * Math.PI * i) / Math.max(n, 1) - Math.PI / 2;
|
|
51
|
+
at[node.key] = { x: Math.round(c + r * Math.cos(a)), y: Math.round(c + r * Math.sin(a)) };
|
|
52
|
+
});
|
|
53
|
+
return at;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const esc = (s) => String(s).replace(/[&<>"']/g, (ch) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[ch]);
|
|
57
|
+
|
|
58
|
+
/** The answer's drawing as SVG text. */
|
|
59
|
+
export function drawSvg(draw, size = 520) {
|
|
60
|
+
const nodes = draw?.nodes ?? [];
|
|
61
|
+
if (!nodes.length) return "";
|
|
62
|
+
const at = circleLayout(nodes, size);
|
|
63
|
+
const edges = (draw.edges ?? [])
|
|
64
|
+
.filter((e) => at[e.from] && at[e.to])
|
|
65
|
+
.map((e) => {
|
|
66
|
+
const a = at[e.from];
|
|
67
|
+
const b = at[e.to];
|
|
68
|
+
const derived = e.origin === "derived";
|
|
69
|
+
const title = `${e.from} -> ${e.to}${e.viaAttr ? ` via ${e.viaAttr}` : ""}${derived ? ` (derived: ${e.rule})` : ""}`;
|
|
70
|
+
return `<line class="g-edge${derived ? " derived" : ""}" x1="${a.x}" y1="${a.y}" x2="${b.x}" y2="${b.y}" marker-end="url(#g-arrow)"><title>${esc(title)}</title></line>`;
|
|
71
|
+
})
|
|
72
|
+
.join("");
|
|
73
|
+
const dots = nodes
|
|
74
|
+
.map((n) => {
|
|
75
|
+
const p = at[n.key];
|
|
76
|
+
const label = n.name || n.key;
|
|
77
|
+
return `<g class="g-node ${esc(n.source)}"><circle cx="${p.x}" cy="${p.y}" r="7"><title>${esc(`${n.key} (${n.kind}, ${n.scopeKey})`)}</title></circle><text x="${p.x + 10}" y="${p.y + 4}">${esc(label.length > 32 ? `${label.slice(0, 29)}...` : label)}</text></g>`;
|
|
78
|
+
})
|
|
79
|
+
.join("");
|
|
80
|
+
return `<svg viewBox="0 0 ${size} ${size}" role="img" aria-label="answer graph"><defs><marker id="g-arrow" viewBox="0 0 10 10" refX="16" refY="5" markerWidth="6" markerHeight="6" orient="auto"><path d="M0,0 L10,5 L0,10 z" class="g-arrowhead"/></marker></defs>${edges}${dots}</svg>`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A table of the answer's rows as HTML text. */
|
|
84
|
+
export function rowsTable(columns, rows) {
|
|
85
|
+
if (!rows?.length) return "<p class=\"g-muted\">No rows.</p>";
|
|
86
|
+
const cell = (v) => esc(typeof v === "string" ? v : JSON.stringify(v));
|
|
87
|
+
const head = columns.map((c) => `<th>${esc(c)}</th>`).join("");
|
|
88
|
+
const body = rows.map((r) => `<tr>${columns.map((c) => `<td>${cell(r[c])}</td>`).join("")}</tr>`).join("");
|
|
89
|
+
return `<table><thead><tr>${head}</tr></thead><tbody>${body}</tbody></table>`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The refusal text a failed answer shows: the error, and the install line when the peer is missing. */
|
|
93
|
+
export function refusalText(body) {
|
|
94
|
+
if (!body) return "No answer.";
|
|
95
|
+
const lines = [body.error ?? "Refused."];
|
|
96
|
+
if (body.code === "graph-peer-missing") lines.push(`Install: ${body.install}`, ...(body.stillWorks ?? []).map((w) => `Still works: ${w}`));
|
|
97
|
+
else if (body.remedy) lines.push(body.remedy);
|
|
98
|
+
return lines.join("\n");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* c8 ignore start: the DOM half, driven by the page */
|
|
102
|
+
export function initGraphPane(doc = document, fetchJson = (u) => fetch(u, { headers: { accept: "application/json" } }).then(async (r) => ({ status: r.status, body: await r.json().catch(() => ({})) }))) {
|
|
103
|
+
const $ = (id) => doc.getElementById(id);
|
|
104
|
+
const show = (answer) => {
|
|
105
|
+
const { status, body } = answer;
|
|
106
|
+
$("g-error").textContent = status === 200 ? "" : refusalText(body);
|
|
107
|
+
$("g-draw").innerHTML = status === 200 ? drawSvg(body.draw) : "";
|
|
108
|
+
$("g-rows").innerHTML = status === 200 && body.columns ? rowsTable(body.columns, body.rows) : "";
|
|
109
|
+
$("g-sources").textContent = sourceLines(body.sources).join("\n");
|
|
110
|
+
const link = $("g-link");
|
|
111
|
+
if (status === 200 && body.link) {
|
|
112
|
+
link.href = body.link;
|
|
113
|
+
link.hidden = false;
|
|
114
|
+
} else link.hidden = true;
|
|
115
|
+
};
|
|
116
|
+
const status = async () => {
|
|
117
|
+
const s = await fetchJson("/api/graphdb");
|
|
118
|
+
if (s.status !== 200) return show(s);
|
|
119
|
+
const peer = s.body.peer;
|
|
120
|
+
$("g-peer").textContent = peer?.available ? `LadybugDB ${peer.version ?? ""}`.trim() : refusalText(peer?.refusal);
|
|
121
|
+
$("g-counts").textContent = `${s.body.counts.resources} resources, ${s.body.counts.refs} edges (${s.body.counts.derived} derived), ${s.body.counts.cloudIds} cloud ids`;
|
|
122
|
+
$("g-sources").textContent = sourceLines(s.body.sources).join("\n");
|
|
123
|
+
$("g-notes").textContent = (s.body.notes ?? []).join("\n");
|
|
124
|
+
};
|
|
125
|
+
$("g-cypher-form").addEventListener("submit", async (ev) => {
|
|
126
|
+
ev.preventDefault();
|
|
127
|
+
let params;
|
|
128
|
+
const raw = $("g-params").value.trim();
|
|
129
|
+
if (raw) {
|
|
130
|
+
try {
|
|
131
|
+
params = JSON.parse(raw);
|
|
132
|
+
} catch {
|
|
133
|
+
$("g-error").textContent = "Parameters are a JSON object.";
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
show(await fetchJson(queryUrl($("g-cypher").value, params)));
|
|
138
|
+
});
|
|
139
|
+
$("g-resolve-form").addEventListener("submit", async (ev) => {
|
|
140
|
+
ev.preventDefault();
|
|
141
|
+
const r = await fetchJson(resolveUrl($("g-ref").value));
|
|
142
|
+
show(r);
|
|
143
|
+
const list = $("g-candidates");
|
|
144
|
+
list.innerHTML = "";
|
|
145
|
+
if (r.status !== 200) return;
|
|
146
|
+
for (const c of r.body.candidates) {
|
|
147
|
+
const li = doc.createElement("li");
|
|
148
|
+
li.textContent = `${c.key} (${c.kind}, ${c.source}, matched by ${c.matchedBy})`;
|
|
149
|
+
list.append(li);
|
|
150
|
+
}
|
|
151
|
+
const menu = $("g-templates");
|
|
152
|
+
menu.innerHTML = "";
|
|
153
|
+
const node = r.body.resolved ? r.body.candidates[0].key : null;
|
|
154
|
+
for (const t of r.body.templates ?? []) {
|
|
155
|
+
const b = doc.createElement("button");
|
|
156
|
+
b.type = "button";
|
|
157
|
+
b.textContent = `${t.title}${t.language === "cypher" ? " (Cypher)" : ""}`;
|
|
158
|
+
b.disabled = !t.available;
|
|
159
|
+
if (!t.available) b.title = `${t.refusal} ${t.install}`;
|
|
160
|
+
b.addEventListener("click", async () => {
|
|
161
|
+
const inputs = {};
|
|
162
|
+
for (const i of t.inputs) {
|
|
163
|
+
const v = globalThis.prompt?.(`${t.title}: ${i.description}`);
|
|
164
|
+
if (!v) return;
|
|
165
|
+
inputs[i.name] = v;
|
|
166
|
+
}
|
|
167
|
+
const a = await fetchJson(templateUrl(t.name, node, inputs));
|
|
168
|
+
if (a.status === 200 && a.body.search) {
|
|
169
|
+
// A search template draws in behold's own view, through the q key.
|
|
170
|
+
globalThis.location.href = a.body.link;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
show(a);
|
|
174
|
+
});
|
|
175
|
+
menu.append(b);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
status();
|
|
179
|
+
}
|
|
180
|
+
/* c8 ignore stop */
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// behold#1027: the graph pane page's pure helpers.
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { circleLayout, drawSvg, queryUrl, refusalText, resolveUrl, rowsTable, sourceLines, templateUrl } from "./graph-query.js";
|
|
4
|
+
|
|
5
|
+
describe("the routes the page asks", () => {
|
|
6
|
+
it("are GETs with the query in the URL", () => {
|
|
7
|
+
expect(queryUrl("MATCH (r) RETURN r", { k: "x" })).toBe(`/api/graphdb/query?${new URLSearchParams({ cypher: "MATCH (r) RETURN r", params: '{"k":"x"}' })}`);
|
|
8
|
+
expect(queryUrl("MATCH (r) RETURN r")).not.toContain("params");
|
|
9
|
+
expect(resolveUrl("arn:aws:s3:::b")).toBe("/api/graphdb/resolve?ref=arn%3Aaws%3As3%3A%3A%3Ab");
|
|
10
|
+
expect(templateUrl("paths-to-kind", "web/a", { kind: "aws_vpc" })).toBe("/api/graphdb/template?name=paths-to-kind&node=web%2Fa&in.kind=aws_vpc");
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("what an answer shows", () => {
|
|
15
|
+
it("one line per source, saying when it was observed or that it is declared", () => {
|
|
16
|
+
const lines = sourceLines([
|
|
17
|
+
{ scopeKey: "chant/web", source: "chant", name: "chant", member: "web", observedAt: null, readAt: "r", nodes: 2, edges: 1 },
|
|
18
|
+
{ scopeKey: "engine/choudoufu/web", source: "engine", name: "choudoufu", version: "0.33.0", observedAt: "2026-10-26T12:00:00Z", readAt: "r", nodes: 6, edges: 2 },
|
|
19
|
+
]);
|
|
20
|
+
expect(lines[0]).toMatch(/^web: chant .*declared source, not observed/);
|
|
21
|
+
expect(lines[1]).toMatch(/choudoufu 0.33.0 .*observed 2026-10-26T12:00:00Z/);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("draws nodes and the edges among them, derived edges dashed with their rule", () => {
|
|
25
|
+
const svg = drawSvg({
|
|
26
|
+
nodes: [
|
|
27
|
+
{ key: "a", kind: "k", name: "a", source: "chant", scopeKey: "chant/x" },
|
|
28
|
+
{ key: "b", kind: "k", name: "b", source: "engine", scopeKey: "engine/y" },
|
|
29
|
+
],
|
|
30
|
+
edges: [{ from: "a", to: "b", viaAttr: "arn", origin: "derived", rule: "identity:arn" }],
|
|
31
|
+
});
|
|
32
|
+
expect(svg).toContain('class="g-edge derived"');
|
|
33
|
+
expect(svg).toContain("identity:arn");
|
|
34
|
+
expect(svg.match(/<circle/g)).toHaveLength(2);
|
|
35
|
+
expect(drawSvg({ nodes: [], edges: [] })).toBe("");
|
|
36
|
+
expect(Object.keys(circleLayout([{ key: "a" }, { key: "b" }, { key: "c" }]))).toEqual(["a", "b", "c"]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("escapes what it draws", () => {
|
|
40
|
+
expect(rowsTable(["k"], [{ k: "<script>" }])).toContain("<script>");
|
|
41
|
+
expect(drawSvg({ nodes: [{ key: "<x>", kind: "k", name: "<x>", source: "chant", scopeKey: "s" }], edges: [] })).not.toContain("<x>");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("a refusal without the peer shows the install line and what still works", () => {
|
|
45
|
+
const t = refusalText({ error: "needs the peer", code: "graph-peer-missing", install: "npm i -g @ladybugdb/core", stillWorks: ["chant search"] });
|
|
46
|
+
expect(t).toContain("Install: npm i -g @ladybugdb/core");
|
|
47
|
+
expect(t).toContain("Still works: chant search");
|
|
48
|
+
});
|
|
49
|
+
});
|