@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
|
@@ -81,3 +81,25 @@ describe("a node's entries (#681)", () => {
|
|
|
81
81
|
expect(gapLines({ ...answer, gaps: [{ member: "api", status: "failed", error: "no credentials", holes: [] }] })).toEqual([{ text: "api did not plan: no credentials, so its changes are not drawn", title: "" }]);
|
|
82
82
|
});
|
|
83
83
|
});
|
|
84
|
+
|
|
85
|
+
// #996: a `count = 3` block's change set. Each instance's entry outlines its
|
|
86
|
+
// own card, `<blockNode>[k]`, and the block card carries the rollup. The
|
|
87
|
+
// entries name the block node, as chant maps them before INTENTIUS/chant#4454
|
|
88
|
+
// (src/instance-cards.test.ts shows the instance-node mapping gives the same).
|
|
89
|
+
describe("instance cards (#996)", () => {
|
|
90
|
+
const entry = (i, action) => ({ member: "tf", planner: "terraform", address: `aws_s3_bucket.logs[${i}]`, type: "aws_s3_bucket", action, attributes: [], node: "tf/app/aws_s3_bucket.logs" });
|
|
91
|
+
const doc = { changeSet: { digest: "jcs1-sha256:00", entries: [entry(0, "no-op"), entry(1, "update"), entry(2, "create")], members: [], graph: { member: "tf", at: null } } };
|
|
92
|
+
const counted = overlayFrom(gate, doc, new Date(0));
|
|
93
|
+
it("puts each instance's entry on its own card and all of them on the block", () => {
|
|
94
|
+
const marks = nodeMarks(counted);
|
|
95
|
+
expect(marks["tf/app/aws_s3_bucket.logs[1]"].tag).toBe("update");
|
|
96
|
+
expect(marks["tf/app/aws_s3_bucket.logs[2]"].tag).toBe("create");
|
|
97
|
+
expect(marks["tf/app/aws_s3_bucket.logs"].tag).toBe("create, update");
|
|
98
|
+
expect(entriesFor(counted, "tf/app/aws_s3_bucket.logs[2]").map((e) => e.head)).toEqual(["create aws_s3_bucket.logs[2]"]);
|
|
99
|
+
expect(entriesFor(counted, "tf/app/aws_s3_bucket.logs")).toHaveLength(2);
|
|
100
|
+
});
|
|
101
|
+
it("counts an instance whose card is not drawn as on the graph when its block is", () => {
|
|
102
|
+
expect(offGraph(counted, new Set(["tf/app/aws_s3_bucket.logs"])).notDrawn).toEqual([]);
|
|
103
|
+
expect(offGraph(counted, new Set()).notDrawn).toHaveLength(2);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Types for web/cut-around.js, for the TypeScript that wraps it (src/graph-cut.ts, #1067).
|
|
2
|
+
|
|
3
|
+
export interface CutGraph {
|
|
4
|
+
nodes: Array<{ id: string }>;
|
|
5
|
+
edges: Array<{ from: string; to: string }>;
|
|
6
|
+
groups?: unknown;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CutAroundOptions {
|
|
10
|
+
depth?: number;
|
|
11
|
+
up?: boolean;
|
|
12
|
+
down?: boolean;
|
|
13
|
+
outside?: number;
|
|
14
|
+
inside?: ((node: any) => boolean) | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CutAroundResult<N, E> {
|
|
18
|
+
nodes: N[];
|
|
19
|
+
edges: E[];
|
|
20
|
+
groups: Record<string, Record<string, string[]>>;
|
|
21
|
+
seeds: string[];
|
|
22
|
+
missing?: string[];
|
|
23
|
+
reason?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function cutAround<N extends { id: string }, E extends { from: string; to: string }>(
|
|
27
|
+
graph: { nodes: N[]; edges: E[]; groups?: unknown },
|
|
28
|
+
startIds: readonly string[],
|
|
29
|
+
opts?: CutAroundOptions,
|
|
30
|
+
): CutAroundResult<N, E>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// The one walk behind every "cut around" in behold (#1081, and #1067 over a
|
|
2
|
+
// behold-graph/1 document). Plain ESM, no imports at all: a browser host, a
|
|
3
|
+
// Node reader and a test load it the same way.
|
|
4
|
+
//
|
|
5
|
+
// A cut keeps the seeds, what they reach upstream, what reaches them
|
|
6
|
+
// downstream, and the groups (boxes) those nodes sit in. An edge runs from a
|
|
7
|
+
// consumer to what it needs (`from` needs `to`, as chant's IR draws it), so
|
|
8
|
+
// "up" follows `from -> to` and "down" follows `to -> from`. Each direction is
|
|
9
|
+
// its own closure, as chant's `blast:` lens does it: two things that merely
|
|
10
|
+
// share a dependency are not neighbours of each other.
|
|
11
|
+
//
|
|
12
|
+
// Two budgets bound the walk. `depth` counts hops between "inside" nodes. The
|
|
13
|
+
// host says what inside is with `inside(node)`; with none, every node is
|
|
14
|
+
// inside and `outside` never applies, which is the plain depth-bounded cut.
|
|
15
|
+
// `outside` counts hops past the last inside node, so a Kubernetes host can
|
|
16
|
+
// keep two hops beyond the cluster (a service account, the cloud identity it
|
|
17
|
+
// is bound to, the project that owns it) without a long walk through the
|
|
18
|
+
// cloud estate. A hop never goes from outside back to inside.
|
|
19
|
+
//
|
|
20
|
+
// #1067 wraps this: it turns a box id into its member ids, calls cutAround,
|
|
21
|
+
// and adds `cut` and `notes` to the document it returns. Nothing there should
|
|
22
|
+
// walk the graph a second time.
|
|
23
|
+
|
|
24
|
+
/** Adjacency for one direction: node id -> ids it leads to. */
|
|
25
|
+
function adjacency(edges, direction) {
|
|
26
|
+
const next = new Map();
|
|
27
|
+
for (const e of edges || []) {
|
|
28
|
+
const [a, b] = direction === "up" ? [e.from, e.to] : [e.to, e.from];
|
|
29
|
+
if (a === undefined || b === undefined) continue;
|
|
30
|
+
let list = next.get(a);
|
|
31
|
+
if (!list) next.set(a, (list = []));
|
|
32
|
+
list.push(b);
|
|
33
|
+
}
|
|
34
|
+
return next;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Ids reached walking one direction from `seeds`, seeds included. */
|
|
38
|
+
function reach(next, seeds, byId, depth, outside, inside) {
|
|
39
|
+
const kept = new Set(seeds);
|
|
40
|
+
const insideSeeds = seeds.filter((id) => inside(byId.get(id)));
|
|
41
|
+
const outsideSeeds = seeds.filter((id) => !inside(byId.get(id)));
|
|
42
|
+
// Inside phase: breadth-first to `depth` hops, over inside nodes only.
|
|
43
|
+
const insideKept = new Set(insideSeeds);
|
|
44
|
+
let layer = insideSeeds;
|
|
45
|
+
for (let hop = 0; hop < depth && layer.length; hop++) {
|
|
46
|
+
const following = [];
|
|
47
|
+
for (const id of layer) {
|
|
48
|
+
for (const m of next.get(id) || []) {
|
|
49
|
+
const node = byId.get(m);
|
|
50
|
+
if (!node || !inside(node) || insideKept.has(m)) continue;
|
|
51
|
+
insideKept.add(m);
|
|
52
|
+
following.push(m);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
layer = following;
|
|
56
|
+
}
|
|
57
|
+
for (const id of insideKept) kept.add(id);
|
|
58
|
+
// Outside phase: from every kept inside node and every outside seed, up to
|
|
59
|
+
// `outside` hops through outside nodes. Breadth-first from all of them at
|
|
60
|
+
// once, so a node is reached with the fewest outside hops it can be.
|
|
61
|
+
const seen = new Set(outsideSeeds);
|
|
62
|
+
const expand = (ids) => {
|
|
63
|
+
const following = [];
|
|
64
|
+
for (const id of ids) {
|
|
65
|
+
for (const m of next.get(id) || []) {
|
|
66
|
+
const node = byId.get(m);
|
|
67
|
+
if (!node || inside(node) || seen.has(m)) continue;
|
|
68
|
+
seen.add(m);
|
|
69
|
+
following.push(m);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return following;
|
|
73
|
+
};
|
|
74
|
+
let wave = expand([...insideKept, ...outsideSeeds]);
|
|
75
|
+
for (let hop = 1; hop <= outside && wave.length; hop++) {
|
|
76
|
+
for (const id of wave) kept.add(id);
|
|
77
|
+
wave = expand(wave);
|
|
78
|
+
}
|
|
79
|
+
return kept;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Cut `graph` (`{ nodes, edges, groups }`, the `ir` of /api/graph or a
|
|
84
|
+
* behold-graph/1 document) around `startIds`.
|
|
85
|
+
*
|
|
86
|
+
* Options: `depth` (default 1), `up` and `down` (default true), `outside`
|
|
87
|
+
* (default 2, used only when `inside` is given), `inside(node) -> boolean`.
|
|
88
|
+
*
|
|
89
|
+
* Returns `{ nodes, edges, groups, seeds }`. `seeds` are the start ids the
|
|
90
|
+
* graph holds, in the order given. An id the graph does not hold is not
|
|
91
|
+
* silently dropped: with none of them found, `nodes` is empty and `reason`
|
|
92
|
+
* names every missing id; with some found, `missing` lists the rest. Edges are
|
|
93
|
+
* kept only when both ends are kept. `groups` keeps, for each group key, the
|
|
94
|
+
* boxes that still hold a kept node, filtered to the kept ids.
|
|
95
|
+
*/
|
|
96
|
+
export function cutAround(graph, startIds, opts = {}) {
|
|
97
|
+
const { depth = 1, up = true, down = true, outside = 2, inside = null } = opts;
|
|
98
|
+
const isInside = typeof inside === "function" ? inside : () => true;
|
|
99
|
+
const nodes = (graph && graph.nodes) || [];
|
|
100
|
+
const edges = (graph && graph.edges) || [];
|
|
101
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
102
|
+
const wanted = [...new Set(startIds || [])];
|
|
103
|
+
const seeds = wanted.filter((id) => byId.has(id));
|
|
104
|
+
const missing = wanted.filter((id) => !byId.has(id));
|
|
105
|
+
if (!seeds.length) {
|
|
106
|
+
const reason = wanted.length ? `the graph holds no node ${missing.map((m) => `"${m}"`).join(", ")}` : "no start node was given";
|
|
107
|
+
return { nodes: [], edges: [], groups: {}, seeds: [], missing, reason };
|
|
108
|
+
}
|
|
109
|
+
const kept = new Set(seeds);
|
|
110
|
+
const budget = Math.max(0, Number.isFinite(depth) ? Math.floor(depth) : 0);
|
|
111
|
+
const out = Math.max(0, Number.isFinite(outside) ? Math.floor(outside) : 0);
|
|
112
|
+
if (up) for (const id of reach(adjacency(edges, "up"), seeds, byId, budget, out, isInside)) kept.add(id);
|
|
113
|
+
if (down) for (const id of reach(adjacency(edges, "down"), seeds, byId, budget, out, isInside)) kept.add(id);
|
|
114
|
+
const cut = {
|
|
115
|
+
nodes: nodes.filter((n) => kept.has(n.id)),
|
|
116
|
+
edges: edges.filter((e) => kept.has(e.from) && kept.has(e.to)),
|
|
117
|
+
groups: cutGroups(graph && graph.groups, kept),
|
|
118
|
+
seeds,
|
|
119
|
+
};
|
|
120
|
+
if (missing.length) cut.missing = missing;
|
|
121
|
+
return cut;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Each `{ key: { box: [ids] } }` group set, reduced to the kept ids; empty boxes drop. */
|
|
125
|
+
function cutGroups(groups, kept) {
|
|
126
|
+
const out = {};
|
|
127
|
+
for (const [key, boxes] of Object.entries(groups || {})) {
|
|
128
|
+
if (!boxes || typeof boxes !== "object" || Array.isArray(boxes)) continue;
|
|
129
|
+
const reduced = {};
|
|
130
|
+
for (const [box, ids] of Object.entries(boxes)) {
|
|
131
|
+
if (!Array.isArray(ids)) continue;
|
|
132
|
+
const keep = ids.filter((id) => kept.has(id));
|
|
133
|
+
if (keep.length) reduced[box] = keep;
|
|
134
|
+
}
|
|
135
|
+
if (Object.keys(reduced).length) out[key] = reduced;
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
@@ -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,11 @@
|
|
|
1
|
-
// Types for src/stack-lens.ts, which keeps the traffic path's lines when a card carries a count instead (#877).
|
|
1
|
+
// Types for src/stack-lens.ts, which keeps the traffic path's lines when a card carries a count instead (#877), and src/catalog-draw.ts (#1080).
|
|
2
2
|
export const WEIGHTS: Record<string, string>;
|
|
3
|
+
export const CATALOG_WEIGHTS: string[];
|
|
3
4
|
export function isWired(e: { viaAttr?: string }): boolean;
|
|
4
|
-
export function
|
|
5
|
+
export function isCatalogEdge(e: { origin?: string; rule?: string; relation?: string }, rules?: Record<string, unknown>): boolean;
|
|
6
|
+
export function edgeWeights(
|
|
7
|
+
edges?: Array<{ from: string; to: string; kind?: string; viaAttr?: string; inferred?: boolean; origin?: string; rule?: string; relation?: string; dangling?: boolean; ambiguous?: unknown }>,
|
|
8
|
+
kindOf?: Map<string, string | undefined>,
|
|
9
|
+
rules?: Record<string, unknown>,
|
|
10
|
+
): Map<string, string>;
|
|
5
11
|
export function weightLegend(weights: Map<string, string>): Array<{ weight: string; label: string; title: string; count: number }>;
|