@intentius/behold 0.31.0 → 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.
@@ -13,6 +13,13 @@
13
13
  // chant#4522/#4523, behold#1030) is a match chant made, not a declaration, so
14
14
  // it weighs as an inferred one does.
15
15
  //
16
+ // behold#1080: a catalog rule chant drew an edge by (chant#5097) is an exact
17
+ // match, not a guess, so it is "joined" and apart from "inferred", with the
18
+ // rule in its tooltip. A reference that names no node is drawn to a dashed
19
+ // placeholder card ("dangling"), and one that names several gets a dotted edge
20
+ // to each candidate ("ambiguous"). src/catalog-draw.ts adds the card and the
21
+ // edges and marks them (`dangling: true`, `ambiguous: { of, rule, value }`).
22
+ //
16
23
  // Only references are weighed: a CI edge (needs, calls, triggers, …) keeps its
17
24
  // own kind's style (./edge-kind.js).
18
25
 
@@ -20,10 +27,30 @@
20
27
  export const WEIGHTS = {
21
28
  wired: "wired: the traffic path",
22
29
  reference: "reference: names another",
30
+ joined: "joined: exact match by rule",
23
31
  inferred: "inferred: matched by name",
24
32
  plumbing: "plumbing: identity, keys, logs",
33
+ dangling: "dangling: names nothing declared (dashed card)",
34
+ ambiguous: "ambiguous: one of several candidates (dotted)",
25
35
  };
26
36
 
37
+ /** The weights chant's catalog adds. A key with one of these is worth a row when it is the only weight drawn. */
38
+ export const CATALOG_WEIGHTS = ["joined", "dangling", "ambiguous"];
39
+
40
+ /** The rules that drew an edge that is neither a behold pass nor chant's identity-match pass. */
41
+ const NOT_CATALOG_RULE = /^(behold:|identity-match:)/;
42
+
43
+ /**
44
+ * Whether an edge was drawn by a catalog rule. `rules` is the catalog's rule
45
+ * table (ids as keys) when the graph has one; without it, an edge chant stamped
46
+ * with a `relation` (chant#5097 gives every catalog edge one) counts.
47
+ */
48
+ export function isCatalogEdge(e, rules) {
49
+ if (e.origin !== "derived" || typeof e.rule !== "string" || !e.rule || NOT_CATALOG_RULE.test(e.rule)) return false;
50
+ if (rules && Object.keys(rules).length) return Object.prototype.hasOwnProperty.call(rules, e.rule);
51
+ return typeof e.relation === "string";
52
+ }
53
+
27
54
  /** Kinds whose incoming references are plumbing, not traffic. */
28
55
  const PLUMBING_KIND = /(::IAM::|::Iam::|::KMS::|::Kms::|::Logs::|::SecretsManager::|::SecretManager::|::SSM::|ManagedIdentity\/|OperationalInsights\/|KeyVault\/|Microsoft\.Authorization\/|::Logging::|::Monitoring::|::CloudWatch::Alarm)/;
29
56
 
@@ -39,7 +66,7 @@ export function isWired(e) {
39
66
  * The weight of each reference edge, keyed `from→to`. `kindOf` maps a node id
40
67
  * to its kind. A CI edge gets no entry.
41
68
  */
42
- export function edgeWeights(edges = [], kindOf = new Map()) {
69
+ export function edgeWeights(edges = [], kindOf = new Map(), rules = undefined) {
43
70
  const out = new Map();
44
71
  const plumbing = (e) => PLUMBING_KIND.test(kindOf.get(e.to) || "") || PLUMBING_KIND.test(kindOf.get(e.from) || "");
45
72
  const sharers = new Map();
@@ -53,10 +80,13 @@ export function edgeWeights(edges = [], kindOf = new Map()) {
53
80
  for (const e of edges) {
54
81
  if (e.kind && e.kind !== "ref") continue;
55
82
  let w;
56
- if (plumbing(e)) {
83
+ if (e.ambiguous) w = "ambiguous";
84
+ else if (e.dangling === true) w = "dangling";
85
+ else if (plumbing(e)) {
57
86
  const hub = PLUMBING_KIND.test(kindOf.get(e.to) || "") ? e.to : e.from;
58
87
  w = (sharers.get(hub)?.size ?? 0) > 2 ? "hidden" : "plumbing";
59
- } else if (e.inferred || e.origin === "derived") w = "inferred";
88
+ } else if (isCatalogEdge(e, rules)) w = "joined";
89
+ else if (e.inferred || e.origin === "derived") w = "inferred";
60
90
  else if (isWired(e)) w = "wired";
61
91
  else w = "reference";
62
92
  out.set(`${e.from}→${e.to}`, w);
@@ -68,7 +98,7 @@ export function edgeWeights(edges = [], kindOf = new Map()) {
68
98
  export function weightLegend(weights) {
69
99
  const counts = new Map();
70
100
  for (const w of weights.values()) if (w !== "hidden") counts.set(w, (counts.get(w) || 0) + 1);
71
- if (counts.size < 2) return [];
101
+ if (counts.size < 2 && !CATALOG_WEIGHTS.some((w) => counts.has(w))) return [];
72
102
  return Object.keys(WEIGHTS)
73
103
  .filter((w) => counts.has(w))
74
104
  .map((w) => ({ weight: w, label: w, title: WEIGHTS[w], count: counts.get(w) }));
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { edgeWeights, weightLegend } from "./edge-weight.js";
2
+ import { edgeWeights, weightLegend, WEIGHTS } from "./edge-weight.js";
3
3
 
4
4
  describe("edgeWeights (#878)", () => {
5
5
  const kindOf = new Map([
@@ -66,3 +66,38 @@ describe("edgeWeights over chant's derived edges (behold#1030)", () => {
66
66
  expect(w.get("db→group")).toBe("reference");
67
67
  });
68
68
  });
69
+
70
+ describe("edgeWeights over chant's catalog (behold#1080)", () => {
71
+ const rules = { "k8s:K8s::Apps::Deployment:spec.template.spec.serviceAccountName": { label: "runs as", relation: "reference" } };
72
+ const joined = { from: "app/web", to: "app/runner", kind: "ref", viaAttr: "spec", origin: "derived", rule: "k8s:K8s::Apps::Deployment:spec.template.spec.serviceAccountName", relation: "reference" };
73
+
74
+ it("weighs an edge with a catalog rule as joined, apart from inferred", () => {
75
+ const guess = { from: "a", to: "b", kind: "ref", origin: "derived", rule: "identity-match:name" };
76
+ const w = edgeWeights([joined, guess], new Map(), rules);
77
+ expect(w.get("app/web→app/runner")).toBe("joined");
78
+ expect(w.get("a→b")).toBe("inferred");
79
+ });
80
+
81
+ it("reads a catalog edge by its relation when the graph carries no rule table", () => {
82
+ expect(edgeWeights([joined], new Map()).get("app/web→app/runner")).toBe("joined");
83
+ expect(edgeWeights([{ ...joined, relation: undefined }], new Map()).get("app/web→app/runner")).toBe("inferred");
84
+ });
85
+
86
+ it("weighs the edge to a placeholder dangling and each edge of an ambiguous reference ambiguous", () => {
87
+ const w = edgeWeights(
88
+ [
89
+ { from: "h", to: "dangling:x", kind: "ref", dangling: true, rule: "r" },
90
+ { from: "h", to: "c1", kind: "ref", ambiguous: { of: 2, rule: "r", value: "v" }, rule: "r" },
91
+ { from: "h", to: "c2", kind: "ref", ambiguous: { of: 2, rule: "r", value: "v" }, rule: "r" },
92
+ ],
93
+ new Map(),
94
+ );
95
+ expect([...w.values()]).toEqual(["dangling", "ambiguous", "ambiguous"]);
96
+ });
97
+
98
+ it("gives each its legend row even when it is the only weight drawn", () => {
99
+ expect(weightLegend(new Map([["a→b", "joined"]])).map((r) => [r.weight, r.title, r.count])).toEqual([["joined", WEIGHTS.joined, 1]]);
100
+ expect(weightLegend(new Map([["a→b", "dangling"], ["c→d", "ambiguous"], ["c→e", "ambiguous"]])).map((r) => [r.weight, r.count])).toEqual([["dangling", 1], ["ambiguous", 2]]);
101
+ expect(WEIGHTS.joined).toBe("joined: exact match by rule");
102
+ });
103
+ });
package/web/index.html CHANGED
@@ -9,20 +9,7 @@
9
9
  applyTheme() keeps what it last painted under behold.theme.paint; this
10
10
  applies that record when it belongs to the stored theme. A blocked or
11
11
  empty store leaves the default as it is. -->
12
- <script>
13
- // The kiosk's frame (?bare=1) paints nothing until its theme is applied, so the kiosk's own ground shows through:
14
- // the stylesheet's default --bg is white, and a first load with no stored paint flashed it over a dark pane.
15
- try { if (/[?&]bare=1(&|$)/.test(location.search)) document.documentElement.style.setProperty("--bg", "transparent"); } catch (e) { /* the default paints */ }
16
- try {
17
- var beholdTheme = localStorage.getItem("behold.theme");
18
- var beholdPaint = beholdTheme && JSON.parse(localStorage.getItem("behold.theme.paint") || "null");
19
- if (beholdPaint && beholdPaint.name === beholdTheme && beholdPaint.vars) {
20
- var beholdRoot = document.documentElement;
21
- for (var k in beholdPaint.vars) if (k.slice(0, 2) === "--") beholdRoot.style.setProperty(k, beholdPaint.vars[k]);
22
- if (beholdPaint.scheme) beholdRoot.style.setProperty("color-scheme", beholdPaint.scheme);
23
- }
24
- } catch (e) { /* private mode or a bad record: the default paints */ }
25
- </script>
12
+ <script src="./theme-paint.js"></script>
26
13
  <title>behold</title>
27
14
  <!-- #393: "nothing in the browser console" includes the 404 every page
28
15
  load has always fetched for itself. behold ships no icon file and its
@@ -180,6 +167,12 @@
180
167
  /* behold#878: an edge weighed by how it was found (web/edge-weight.js). */
181
168
  :is(#graph, .edge-swatch) g[data-edge-weight="wired"] .pin-edge-line { stroke-width: 2.4px; }
182
169
  :is(#graph, .edge-swatch) g[data-edge-weight="inferred"] .pin-edge-line { stroke-dasharray: 1.5 4; stroke-linecap: round; }
170
+ /* behold#1080: chant's catalog (src/catalog-draw.ts): joined by rule, to a placeholder card, one of several. */
171
+ :is(#graph, .edge-swatch) g[data-edge-weight="joined"] .pin-edge-line { stroke-width: 2.2px; }
172
+ :is(#graph, .edge-swatch) g[data-edge-weight="dangling"] .pin-edge-line { stroke-dasharray: 6 4; }
173
+ :is(#graph, .edge-swatch) g[data-edge-weight="ambiguous"] .pin-edge-line { stroke-width: 2.4px; stroke-dasharray: 0.5 5; stroke-linecap: round; }
174
+ #graph g[data-node-dangling="true"] > rect:first-of-type { stroke-dasharray: 6 4; }
175
+ #graph g[data-legend="catalog"] { display: none; }
183
176
  :is(#graph, .edge-swatch) g[data-edge-weight="plumbing"] .pin-edge-line { stroke-width: 1px; stroke-dasharray: 4 3; stroke: var(--muted); }
184
177
  #graph g[data-edge-weight="hidden"] { display: none; }
185
178
  #graph-legend .gl-edge { flex: none; overflow: visible; width: 22px; height: 10px; }
@@ -1204,11 +1197,6 @@
1204
1197
  <div id="palette"><div class="box"><input id="pal-input" placeholder="type a command, or an address… (Esc to close)" autocomplete="off"><div id="pal-list"></div></div></div>
1205
1198
  <script type="module" src="./app.js"></script>
1206
1199
  <!-- behold#725: the shared beat paused in a hidden tab, and the shared tooltip for the graph's badges. -->
1207
- <script type="module">
1208
- import { installMotion } from "./motion.js";
1209
- import { installTooltips } from "./tooltip.js";
1210
- installMotion();
1211
- installTooltips(document);
1212
- </script>
1200
+ <script type="module" src="./boot-motion.js"></script>
1213
1201
  </body>
1214
1202
  </html>
@@ -0,0 +1,105 @@
1
+ // The neighbourhood of one Kubernetes object, cut from a graph the page
2
+ // already holds (#1081). A cluster UI (Headlamp, the Argo CD UI) shows one
3
+ // object; this answers "it, its neighbours in the cluster, and what it reaches
4
+ // outside" with no server to ask.
5
+ //
6
+ // Imports only ./cut-around.js, which imports nothing: no `node:*`, nothing
7
+ // from src/. `esbuild web/neighbourhood.js --bundle --platform=browser` takes
8
+ // it whole, and web/neighbourhood.test.js checks the module graph.
9
+ import { cutAround } from "./cut-around.js";
10
+
11
+ export { cutAround };
12
+
13
+ /** API group of a `K8s::<Segment>::` IR kind, for the segments that name one group. A node carrying `attrs.apiVersion` never reaches this table. */
14
+ const GROUP_OF_SEGMENT = {
15
+ Core: "",
16
+ Apps: "apps",
17
+ Batch: "batch",
18
+ Rbac: "rbac.authorization.k8s.io",
19
+ Networking: "networking.k8s.io",
20
+ Storage: "storage.k8s.io",
21
+ Policy: "policy",
22
+ Autoscaling: "autoscaling",
23
+ Apiextensions: "apiextensions.k8s.io",
24
+ Argo: "argoproj.io",
25
+ Monitoring: "monitoring.coreos.com",
26
+ };
27
+
28
+ /** Kinds with no namespace, so an identity without one still matches. */
29
+ const CLUSTER_SCOPED = new Set([
30
+ "Namespace",
31
+ "Node",
32
+ "PersistentVolume",
33
+ "StorageClass",
34
+ "ClusterRole",
35
+ "ClusterRoleBinding",
36
+ "CustomResourceDefinition",
37
+ "PriorityClass",
38
+ "IngressClass",
39
+ "RuntimeClass",
40
+ "ValidatingWebhookConfiguration",
41
+ "MutatingWebhookConfiguration",
42
+ "APIService",
43
+ "AppProject",
44
+ ]);
45
+
46
+ /** Whether a node is a Kubernetes object (the lexicon chant tags it with, else its kind). */
47
+ export function isK8sNode(node) {
48
+ return !!node && (node.lexicon === "k8s" || (typeof node.kind === "string" && node.kind.startsWith("K8s::")));
49
+ }
50
+
51
+ const str = (v) => (typeof v === "string" && v.length > 0 ? v : undefined);
52
+
53
+ /** `{ group, kind, namespace, name }` of a Kubernetes node, as far as it declares them. */
54
+ export function identityOf(node) {
55
+ const attrs = (node && node.attrs) || {};
56
+ const meta = attrs.metadata && typeof attrs.metadata === "object" ? attrs.metadata : {};
57
+ const parts = typeof node.kind === "string" ? node.kind.split("::") : [];
58
+ const kind = str(attrs.kind) || (parts[0] === "K8s" ? parts[parts.length - 1] : undefined);
59
+ let group;
60
+ const apiVersion = str(attrs.apiVersion);
61
+ if (apiVersion) group = apiVersion.includes("/") ? apiVersion.slice(0, apiVersion.indexOf("/")) : "";
62
+ else if (parts[0] === "K8s" && parts.length === 3 && parts[1] in GROUP_OF_SEGMENT) group = GROUP_OF_SEGMENT[parts[1]];
63
+ return { group, kind, namespace: str(meta.namespace), name: str(meta.name) };
64
+ }
65
+
66
+ /**
67
+ * The node for `{ group, kind, namespace, name }`, or null. `group` is the API
68
+ * group ("" or omitted for core, "apps" for Deployment). An object with no
69
+ * namespace joins `default`, as the apiserver defaults it (src/k8s-edges.ts),
70
+ * and a cluster-scoped kind matches without one. A group left out matches any
71
+ * group; one given never matches a node whose group is known and different.
72
+ */
73
+ export function findK8sNode(graph, { group, kind, namespace, name } = {}) {
74
+ if (!kind || !name) return null;
75
+ const wantNamespace = CLUSTER_SCOPED.has(kind) ? undefined : namespace || "default";
76
+ for (const node of (graph && graph.nodes) || []) {
77
+ if (!isK8sNode(node)) continue;
78
+ const id = identityOf(node);
79
+ if (id.kind !== kind || id.name !== name) continue;
80
+ if (group !== undefined && id.group !== undefined && id.group !== group) continue;
81
+ if (wantNamespace !== undefined && (id.namespace || "default") !== wantNamespace) continue;
82
+ return node;
83
+ }
84
+ return null;
85
+ }
86
+
87
+ /** "apps/Deployment default/web", the way a person names an object. */
88
+ export function describeIdentity({ group, kind, namespace, name } = {}) {
89
+ const k = group ? `${group}/${kind}` : `${kind}`;
90
+ return namespace ? `${k} ${namespace}/${name}` : `${k} ${name}`;
91
+ }
92
+
93
+ /**
94
+ * The cut around the object named by `identity`. Walks `depth` hops (default
95
+ * 1) between Kubernetes objects and `outside` hops (default 2) past the last
96
+ * one. An identity the graph does not hold returns no nodes and a `reason`
97
+ * naming it.
98
+ */
99
+ export function neighbourhoodOf(graph, identity, opts = {}) {
100
+ const start = findK8sNode(graph, identity);
101
+ if (!start) {
102
+ return { nodes: [], edges: [], groups: {}, seeds: [], reason: `the graph holds no Kubernetes object ${describeIdentity(identity)}` };
103
+ }
104
+ return cutAround(graph, [start.id], { depth: 1, outside: 2, ...opts, inside: isK8sNode });
105
+ }
@@ -0,0 +1,131 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { readFileSync } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { cutAround, findK8sNode, identityOf, neighbourhoodOf } from "./neighbourhood.js";
5
+
6
+ const k8s = (id, kind, apiVersion, name, namespace) => ({
7
+ id,
8
+ kind,
9
+ lexicon: "k8s",
10
+ attrs: { apiVersion, kind: kind.split("::").pop(), metadata: { name, ...(namespace ? { namespace } : {}) } },
11
+ });
12
+ const tf = (id, kind) => ({ id, kind, lexicon: "terraform", attrs: {} });
13
+ const edge = (from, to) => ({ from, to });
14
+
15
+ /** Deployment web -> ServiceAccount runner -> google_service_account -> project, plus a second Deployment on the same account. */
16
+ function fixture() {
17
+ return {
18
+ nodes: [
19
+ k8s("web", "K8s::Apps::Deployment", "apps/v1", "web"),
20
+ k8s("runner", "K8s::Core::ServiceAccount", "v1", "runner"),
21
+ k8s("other", "K8s::Apps::Deployment", "apps/v1", "other"),
22
+ tf("gsa", "google_service_account"),
23
+ tf("project", "google_project"),
24
+ tf("bucket", "google_storage_bucket"),
25
+ ],
26
+ edges: [edge("web", "runner"), edge("other", "runner"), edge("runner", "gsa"), edge("gsa", "project"), edge("bucket", "project")],
27
+ groups: { byStack: { cluster: ["web", "runner", "other"], cloud: ["gsa", "project", "bucket"] } },
28
+ };
29
+ }
30
+ const ids = (cut) => cut.nodes.map((n) => n.id).sort();
31
+
32
+ describe("neighbourhoodOf", () => {
33
+ it("keeps the Deployment, the account, the cloud identity and the project at outside 2", () => {
34
+ const cut = neighbourhoodOf(fixture(), { group: "apps", kind: "Deployment", name: "web" }, { depth: 1, outside: 2 });
35
+ expect(ids(cut)).toEqual(["gsa", "project", "runner", "web"]);
36
+ expect(cut.edges).toHaveLength(3);
37
+ expect(cut.seeds).toEqual(["web"]);
38
+ expect(cut.groups).toEqual({ byStack: { cluster: ["web", "runner"], cloud: ["gsa", "project"] } });
39
+ });
40
+
41
+ it("keeps the Deployment and the account only at outside 0", () => {
42
+ const cut = neighbourhoodOf(fixture(), { group: "apps", kind: "Deployment", name: "web" }, { depth: 1, outside: 0 });
43
+ expect(ids(cut)).toEqual(["runner", "web"]);
44
+ expect(cut.edges).toEqual([edge("web", "runner")]);
45
+ });
46
+
47
+ it("counts outside hops from the last Kubernetes node", () => {
48
+ const cut = neighbourhoodOf(fixture(), { group: "apps", kind: "Deployment", name: "web" }, { depth: 1, outside: 1 });
49
+ expect(ids(cut)).toEqual(["gsa", "runner", "web"]);
50
+ });
51
+
52
+ it("does not take a sibling that shares a dependency", () => {
53
+ const cut = neighbourhoodOf(fixture(), { group: "apps", kind: "Deployment", name: "web" }, { depth: 3 });
54
+ expect(ids(cut)).not.toContain("other");
55
+ expect(ids(cut)).not.toContain("bucket");
56
+ });
57
+
58
+ it("walks down from the account to what uses it", () => {
59
+ const cut = neighbourhoodOf(fixture(), { kind: "ServiceAccount", name: "runner" }, { depth: 1, up: false });
60
+ expect(ids(cut)).toEqual(["other", "runner", "web"]);
61
+ });
62
+
63
+ it("returns no nodes and a reason naming an identity that is not there", () => {
64
+ const cut = neighbourhoodOf(fixture(), { group: "apps", kind: "Deployment", namespace: "prod", name: "absent" });
65
+ expect(cut.nodes).toEqual([]);
66
+ expect(cut.edges).toEqual([]);
67
+ expect(cut.reason).toContain("apps/Deployment prod/absent");
68
+ });
69
+ });
70
+
71
+ describe("findK8sNode", () => {
72
+ it("joins an object with no namespace to default, and matches a cluster-scoped kind without one", () => {
73
+ const g = {
74
+ nodes: [
75
+ k8s("a", "K8s::Apps::Deployment", "apps/v1", "web", "default"),
76
+ k8s("b", "K8s::Apps::Deployment", "apps/v1", "web", "prod"),
77
+ k8s("ns", "K8s::Core::Namespace", "v1", "prod"),
78
+ ],
79
+ edges: [],
80
+ groups: {},
81
+ };
82
+ expect(findK8sNode(g, { group: "apps", kind: "Deployment", name: "web" }).id).toBe("a");
83
+ expect(findK8sNode(g, { group: "apps", kind: "Deployment", namespace: "prod", name: "web" }).id).toBe("b");
84
+ expect(findK8sNode(g, { group: "", kind: "Namespace", name: "prod" }).id).toBe("ns");
85
+ expect(findK8sNode(g, { group: "batch", kind: "Deployment", name: "web" })).toBeNull();
86
+ });
87
+
88
+ it("reads the group from the IR kind when the node carries no apiVersion", () => {
89
+ const g = { nodes: [{ id: "d", kind: "K8s::Apps::Deployment", lexicon: "k8s", attrs: { metadata: { name: "web" } } }], edges: [], groups: {} };
90
+ expect(identityOf(g.nodes[0])).toMatchObject({ group: "apps", kind: "Deployment", name: "web" });
91
+ expect(findK8sNode(g, { group: "apps", kind: "Deployment", name: "web" }).id).toBe("d");
92
+ });
93
+ });
94
+
95
+ describe("cutAround", () => {
96
+ const chain = () => ({ nodes: ["a", "b", "c"].map((id) => tf(id, "t")), edges: [edge("a", "b"), edge("b", "c")], groups: {} });
97
+
98
+ it("up keeps what the seed needs and down keeps what needs it", () => {
99
+ expect(ids(cutAround(chain(), ["b"], { depth: 5, down: false }))).toEqual(["b", "c"]);
100
+ expect(ids(cutAround(chain(), ["b"], { depth: 5, up: false }))).toEqual(["a", "b"]);
101
+ });
102
+
103
+ it("bounds the walk by depth over a graph with no inside predicate", () => {
104
+ expect(ids(cutAround(chain(), ["a"], { depth: 1 }))).toEqual(["a", "b"]);
105
+ expect(ids(cutAround(chain(), ["a"], { depth: 2 }))).toEqual(["a", "b", "c"]);
106
+ });
107
+
108
+ it("names the ids it could not find", () => {
109
+ const cut = cutAround(chain(), ["a", "zz"], { depth: 1 });
110
+ expect(cut.missing).toEqual(["zz"]);
111
+ expect(cutAround(chain(), ["zz"]).reason).toContain("zz");
112
+ });
113
+ });
114
+
115
+ describe("module graph", () => {
116
+ it("imports nothing from node: and nothing outside web/", () => {
117
+ const seen = new Set();
118
+ const walk = (file) => {
119
+ if (seen.has(file)) return;
120
+ seen.add(file);
121
+ const text = readFileSync(file, "utf8");
122
+ for (const m of text.matchAll(/(?:^|\n)\s*(?:import|export)\b[^;\n]*?from\s+["']([^"']+)["']|\bimport\s*\(\s*["']([^"']+)["']\s*\)|(?:^|\n)\s*import\s+["']([^"']+)["']/g)) {
123
+ const spec = m[1] || m[2] || m[3];
124
+ expect(spec.startsWith("./"), `${file} imports ${spec}`).toBe(true);
125
+ walk(resolve(dirname(file), spec));
126
+ }
127
+ };
128
+ walk(join(import.meta.dirname, "neighbourhood.js"));
129
+ expect([...seen].map((f) => f.split("/").pop()).sort()).toEqual(["cut-around.js", "neighbourhood.js"]);
130
+ });
131
+ });