@intentius/behold 0.29.57 → 0.30.1
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 +388 -57
- package/README.md +67 -50
- package/demos.json +1 -1
- package/dist/cli.js +9958 -3080
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/README.md +10 -10
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-three-cloud/README.md +17 -9
- package/example-three-cloud/aws/chant.config.ts +1 -1
- package/example-three-cloud/aws/site.component.ts +13 -0
- package/example-three-cloud/azure/chant.config.ts +1 -1
- package/example-three-cloud/azure/src/site.component.ts +13 -0
- package/example-three-cloud/azure/src/site.ts +5 -7
- package/example-three-cloud/dns/chant.config.ts +1 -1
- package/example-three-cloud/dns/src/records.component.ts +14 -0
- package/example-three-cloud/dns/src/route53.ts +4 -5
- package/example-three-cloud/gcp/chant.config.ts +1 -1
- package/example-three-cloud/gcp/src/site.component.ts +13 -0
- package/example-three-cloud/gcp/src/site.ts +7 -7
- package/example-three-cloud/package-lock.json +19 -19
- package/example-three-cloud/package.json +4 -4
- package/example-three-cloud/scripts/front-door.ts +89 -15
- package/package.json +10 -11
- package/web/agent-move.js +60 -0
- package/web/agent-move.test.js +55 -0
- package/web/app.js +622 -79
- package/web/dots-lod.js +1 -1
- package/web/embed.d.ts +3 -0
- package/web/embed.js +5 -3
- package/web/embed.test.js +8 -0
- package/web/index.html +64 -9
- package/web/layout-store.js +3 -3
- package/web/panel.js +28 -4
- package/web/release.js +6 -4
- package/web/release.test.js +2 -2
- package/web/search-view.d.ts +27 -0
- package/web/search-view.js +213 -0
- package/web/search-view.test.js +144 -0
- package/web/shot-frame.d.ts +5 -0
- package/web/shot-frame.js +116 -0
- package/web/shot-frame.test.js +90 -0
- package/web/themes.js +1 -1
- package/web/view-url.d.ts +18 -0
- package/web/view-url.js +153 -6
- package/web/view-url.test.js +72 -1
- package/example-three-cloud/azure/composites/container-app-site.ts +0 -77
- package/example-three-cloud/dns/composites/latency-entry.ts +0 -73
- package/example-three-cloud/gcp/composites/public-cloud-run.ts +0 -102
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { groupMarks, queryLine, queryMarks, searchKey, searchUrl, stackIndex, uncapturedLine } from "./search-view.js";
|
|
3
|
+
|
|
4
|
+
// behold#913: how the page draws a query's answer (GET /api/search's `draw`).
|
|
5
|
+
|
|
6
|
+
const answer = (draw, document = {}) => ({ q: "q", document, draw: { lit: [], onPath: [], edges: [], unobserved: {}, nearMisses: [], provenance: "declared only · no observation", failure: null, notSearched: [], ...draw } });
|
|
7
|
+
const cards = ["web", "subnet", "vpc", "db", "cache"];
|
|
8
|
+
const edges = [
|
|
9
|
+
{ from: "web", to: "subnet" },
|
|
10
|
+
{ from: "vpc", to: "subnet" }, // drawn the other way round from the hop
|
|
11
|
+
{ from: "db", to: "cache" },
|
|
12
|
+
{ from: "web", to: "db" },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
describe("searchUrl and searchKey", () => {
|
|
16
|
+
it("asks for the query in the view's env and snapshot, and keys the answer on all three", () => {
|
|
17
|
+
expect(searchUrl({ q: "->kind:aws_vpc" })).toBe("/api/search?q=-%3Ekind%3Aaws_vpc");
|
|
18
|
+
expect(searchUrl({ q: "a", env: "prod", snapshot: "latest" })).toBe("/api/search?env=prod&q=a&snapshot=latest");
|
|
19
|
+
expect(searchUrl({ q: "a", snapshot: "latest" })).toBe("/api/search?q=a");
|
|
20
|
+
expect(searchKey({ q: null })).toBeNull();
|
|
21
|
+
expect(searchKey({ q: "a", env: "prod" })).not.toBe(searchKey({ q: "a" }));
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("queryMarks", () => {
|
|
26
|
+
it("lights the matches, keeps the path at full weight, and dims the rest; nothing is hidden", () => {
|
|
27
|
+
const m = queryMarks(answer({ lit: ["web"], onPath: ["subnet", "vpc"], edges: [{ from: "web", to: "subnet" }, { from: "subnet", to: "vpc" }] }), cards, edges);
|
|
28
|
+
expect(Object.fromEntries(m.cardMarks)).toEqual({ web: "lit", subnet: "path", vpc: "path", db: "dim", cache: "dim" });
|
|
29
|
+
expect(m.edgeMarks).toEqual(["path", "path", "dim", "dim"]);
|
|
30
|
+
expect(m.state).toBe("drawn");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("before paths (chant#4359), an edge between two lit cards stays lit but is not a path", () => {
|
|
34
|
+
const m = queryMarks(answer({ lit: ["web", "db"] }), cards, edges);
|
|
35
|
+
expect(m.edgeMarks).toEqual(["dim", "dim", "dim", "lit"]);
|
|
36
|
+
expect([...m.cardMarks.values()].filter((x) => x === "path")).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("no matches dims the whole graph and outlines the near-misses, never an empty stage", () => {
|
|
40
|
+
const m = queryMarks(answer({ nearMisses: [{ id: "db", fails: "kind:nope" }, { id: "gone", fails: "kind:nope" }] }), cards, edges);
|
|
41
|
+
expect([...m.cardMarks.values()].every((x) => x === "dim")).toBe(true);
|
|
42
|
+
expect(m.cardMarks.size).toBe(cards.length);
|
|
43
|
+
expect(Object.fromEntries(m.near)).toEqual({ db: "kind:nope" });
|
|
44
|
+
expect(m.state).toBe("no-matches");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("a failed live read lights the rows with the unobserved ring and reports failed", () => {
|
|
48
|
+
const m = queryMarks(answer({ lit: ["web"], unobserved: { web: "read-failed" }, failure: { kind: "live", message: "live read failed (terraform: denied)" } }), cards, edges);
|
|
49
|
+
expect(m.cardMarks.get("web")).toBe("lit");
|
|
50
|
+
expect([...m.unobserved]).toEqual(["web"]);
|
|
51
|
+
expect(m.state).toBe("failed");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("a query chant refuses, or a refusal, lights and dims nothing", () => {
|
|
55
|
+
const refused = queryMarks(answer({ failure: { kind: "query", code: "query-invalid", message: "not a term" } }), cards, edges);
|
|
56
|
+
expect(refused.cardMarks.size).toBe(0);
|
|
57
|
+
expect(refused.state).toBe("failed");
|
|
58
|
+
const old = queryMarks({ error: "Search needs chant 0.124.46 or newer.", code: "chant-too-old" }, cards, edges);
|
|
59
|
+
expect(old.cardMarks.size).toBe(0);
|
|
60
|
+
expect(old.edgeMarks).toEqual([null, null, null, null]);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("matches inside a stack (#908 stage 3)", () => {
|
|
65
|
+
// The default zoom stacks look-alike cards (attrs._stackOf); chant answers the ids they hold.
|
|
66
|
+
const nodes = [
|
|
67
|
+
{ id: "web", attrs: {} },
|
|
68
|
+
{ id: "roles ×3", attrs: { _stackOf: [{ id: "role.a" }, { id: "role.b" }, "role.pod"] } },
|
|
69
|
+
{ id: "unused ×2", attrs: { _stackOf: [{ id: "x.a" }, { id: "x.b" }] } },
|
|
70
|
+
];
|
|
71
|
+
const drawn = ["web", "roles ×3", "db"];
|
|
72
|
+
const stackOf = stackIndex(nodes, drawn);
|
|
73
|
+
const sEdges = [{ from: "web", to: "roles ×3" }, { from: "roles ×3", to: "db" }];
|
|
74
|
+
|
|
75
|
+
it("maps a stack's members to the drawn stack, and only for stacks that are drawn", () => {
|
|
76
|
+
expect([...stackOf]).toEqual([["role.a", "roles ×3"], ["role.b", "roles ×3"], ["role.pod", "roles ×3"]]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("lights a stack holding a match, draws a hop through it, and counts its matches as drawn", () => {
|
|
80
|
+
const a = answer({ lit: ["role.a", "role.b"], onPath: ["web"], edges: [{ from: "web", to: "role.a" }] });
|
|
81
|
+
const m = queryMarks(a, drawn, sEdges, stackOf);
|
|
82
|
+
expect(Object.fromEntries(m.cardMarks)).toEqual({ web: "path", "roles ×3": "lit", db: "dim" });
|
|
83
|
+
expect(m.edgeMarks).toEqual(["path", "dim"]);
|
|
84
|
+
expect(m.litDrawn).toBe(2);
|
|
85
|
+
expect(queryLine({ q: "kind:aws_iam_role" }, a, m).text).not.toContain("not drawn at this zoom");
|
|
86
|
+
// Without the index the stack stays dim and its matches read as not drawn.
|
|
87
|
+
expect(queryMarks(a, drawn, sEdges).cardMarks.get("roles ×3")).toBe("dim");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("groups a stack with the first group holding its cards, and labels a group on a card no earlier group labelled, when there is one", () => {
|
|
91
|
+
const a = answer({
|
|
92
|
+
lit: ["role.a", "role.b", "role.pod", "web"],
|
|
93
|
+
counts: { by: "module", total: 4, groups: [{ group: "(root)", count: 3, ids: ["role.a", "role.b", "web"] }, { group: "module.pod", count: 1, ids: ["role.pod"] }] },
|
|
94
|
+
});
|
|
95
|
+
const g = groupMarks(a, drawn, stackOf);
|
|
96
|
+
expect(g.groups.map((x) => [x.group, x.drawn, x.label])).toEqual([
|
|
97
|
+
["(root)", ["roles ×3", "web"], "roles ×3"],
|
|
98
|
+
["module.pod", ["roles ×3"], "roles ×3"],
|
|
99
|
+
]);
|
|
100
|
+
expect(Object.fromEntries(g.cardGroup)).toEqual({ "roles ×3": 0, web: 0 });
|
|
101
|
+
expect(queryMarks(a, drawn, sEdges, stackOf).cardMarks.get("roles ×3")).toBe("lit");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("queryLine", () => {
|
|
106
|
+
const view = { q: "kind:aws_instance" };
|
|
107
|
+
|
|
108
|
+
it("says the query and chant's provenance in one line", () => {
|
|
109
|
+
const a = answer({ lit: ["web", "gone"], edges: [{ from: "web", to: "subnet" }] });
|
|
110
|
+
const l = queryLine(view, a, queryMarks(a, cards, edges));
|
|
111
|
+
expect(l.text).toBe('"kind:aws_instance": 2 matches, 1 not drawn at this zoom, path edges drawn · declared only · no observation');
|
|
112
|
+
expect(l.tone).toBe("ok");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("no matches says so, with the universe count", () => {
|
|
116
|
+
const a = answer({ nearMisses: [{ id: "db", fails: "kind:aws_instance" }] }, { explain: { universe: { matched: 0, of: 64, kinds: [] } } });
|
|
117
|
+
const l = queryLine(view, a, queryMarks(a, cards, edges));
|
|
118
|
+
expect(l.text).toContain('no matches for "kind:aws_instance", 0 of 64 nodes; near misses outlined (1)');
|
|
119
|
+
expect(l.tone).toBe("empty");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("a failed live read is a failure, naming the lexicon", () => {
|
|
123
|
+
const a = answer({ lit: ["web"], failure: { kind: "live", message: "live read failed (terraform: denied): 1/1 rows unobserved. The rows shown are what the source declares." } });
|
|
124
|
+
const l = queryLine(view, a, queryMarks(a, cards, edges));
|
|
125
|
+
expect(l.tone).toBe("failed");
|
|
126
|
+
expect(l.text).toMatch(/^live read failed \(terraform: denied\)/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("names the members chant did not search on a second line", () => {
|
|
130
|
+
const a = answer({ lit: ["east/web"], notSearched: [{ member: "west", status: "failed", code: "member-chant-too-old", message: "old chant" }] });
|
|
131
|
+
expect(queryLine(view, a, queryMarks(a, cards, edges)).notSearched).toBe("not searched: west (member-chant-too-old: old chant)");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("a refused query carries chant's message and hint; a refusal its error and remedy", () => {
|
|
135
|
+
const a = answer({ failure: { kind: "query", message: "not a term", hint: "say attr:x=y" } });
|
|
136
|
+
expect(queryLine(view, a, null).text).toBe('"kind:aws_instance" was refused by chant: not a term. say attr:x=y');
|
|
137
|
+
expect(queryLine(view, { error: "Search needs chant 0.124.46 or newer.", remedy: "Upgrade." }, null)).toMatchObject({ tone: "failed", text: '"kind:aws_instance" not searched: Search needs chant 0.124.46 or newer. Upgrade.' });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("an export names the queries it captured when asked for another", () => {
|
|
141
|
+
expect(uncapturedLine("b", ["a", "c"])).toBe('"b" not searched: this export answers 2 captured queries, and this is not one of them: "a", "c".');
|
|
142
|
+
expect(uncapturedLine("b", undefined)).toMatch(/captured no queries/);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// behold#915: the page `behold shot` photographs. `frame=matches` is an embed
|
|
2
|
+
// parameter, not a view key (a reload never writes it back): in a bare frame
|
|
3
|
+
// it lights what the view asks for, dims the rest, frames the lit cards with
|
|
4
|
+
// the kiosk's own arithmetic (web/kiosk-shot.js shotViewBox), draws one
|
|
5
|
+
// caption line, and says it is ready by setting `data-behold-shot` on <html>
|
|
6
|
+
// to `drawn`, `no-matches` or `failed`. The driver (src/shot.ts) waits for
|
|
7
|
+
// that attribute and never photographs a page that did not set it.
|
|
8
|
+
//
|
|
9
|
+
// Pure logic, no DOM: app.js measures the cards and boxes, this decides.
|
|
10
|
+
|
|
11
|
+
/** The attribute on <html> the driver waits for. */
|
|
12
|
+
export const SHOT_ATTR = "data-behold-shot";
|
|
13
|
+
|
|
14
|
+
/** What the attribute can say. */
|
|
15
|
+
export const SHOT_STATES = ["drawn", "no-matches", "failed"];
|
|
16
|
+
|
|
17
|
+
/** Room kept under the framed cards for the caption line, in px. */
|
|
18
|
+
export const SHOT_CAPTION_PX = 30;
|
|
19
|
+
|
|
20
|
+
/** How faint an unlit card is drawn. */
|
|
21
|
+
export const SHOT_DIM = 0.22;
|
|
22
|
+
|
|
23
|
+
/** The shot frame a query asks for: "matches" in a bare embed frame with `frame=matches`, else null. */
|
|
24
|
+
export function readShotFrame(search) {
|
|
25
|
+
const q = new URLSearchParams(search || "");
|
|
26
|
+
const on = (k) => /^(1|true|on|yes)$/i.test(q.get(k) || "");
|
|
27
|
+
if (!on("embed") || !on("bare")) return null;
|
|
28
|
+
return (q.get("frame") || "").trim() === "matches" ? "matches" : null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const centreIn = (c, b) => {
|
|
32
|
+
const x = (c.x + c.x2) / 2;
|
|
33
|
+
const y = (c.y + c.y2) / 2;
|
|
34
|
+
return x > b.x && x < b.x2 && y > b.y && y < b.y2;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The cards a shot lights. `cards` and `groups` are `[{id, box}]` as drawn
|
|
39
|
+
* (boxes in svg units). `matches` is the lit set a query answered: behold#913
|
|
40
|
+
* passes its rows' node ids here once `q` is a view key, and this function
|
|
41
|
+
* needs no other change. Until then the view's own selection stands in:
|
|
42
|
+
* `node` lights that card, `focus` the cards inside the named boxes (or the
|
|
43
|
+
* cards it names). `{ids, asked, label}`: `asked` is false when the view asks
|
|
44
|
+
* for nothing, and then the whole graph is the shot.
|
|
45
|
+
*/
|
|
46
|
+
export function shotLit(view, cards, groups, matches = null) {
|
|
47
|
+
const have = new Set((cards || []).map((c) => c.id));
|
|
48
|
+
if (Array.isArray(matches)) {
|
|
49
|
+
return { ids: matches.filter((id) => have.has(id)), asked: true, label: null };
|
|
50
|
+
}
|
|
51
|
+
const v = view || {};
|
|
52
|
+
if (typeof v.node === "string" && v.node) {
|
|
53
|
+
return { ids: have.has(v.node) ? [v.node] : [], asked: true, label: `node ${v.node}` };
|
|
54
|
+
}
|
|
55
|
+
if (typeof v.focus === "string" && v.focus) {
|
|
56
|
+
const names = new Set(v.focus.split(",").map((s) => s.trim()).filter(Boolean));
|
|
57
|
+
const boxes = (groups || []).filter((g) => names.has(g.id) && g.box);
|
|
58
|
+
const ids = (cards || []).filter((c) => names.has(c.id) || (c.box && boxes.some((g) => centreIn(c.box, g.box)))).map((c) => c.id);
|
|
59
|
+
return { ids, asked: true, label: `focus ${[...names].join(", ")}` };
|
|
60
|
+
}
|
|
61
|
+
return { ids: [], asked: false, label: null };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* With a query answered, what the shot lights and frames, from the marks
|
|
66
|
+
* drawQuery put on the drawn cards (`[{id, mark}]`, mark "lit" | "path" |
|
|
67
|
+
* "dim"). The lit cards are the matches, a stack holding one among them; the
|
|
68
|
+
* frame takes in the path cards too. Found in #908's stage 3 run: framed on
|
|
69
|
+
* chant's lit ids alone, `cap:internet-reachable(22)` zoomed onto the bastion
|
|
70
|
+
* and left its route to the internet gateway out of the picture, and a match
|
|
71
|
+
* inside a stack was not a drawn card at all.
|
|
72
|
+
*/
|
|
73
|
+
export function queryFrame(cards) {
|
|
74
|
+
const lit = [];
|
|
75
|
+
const frame = [];
|
|
76
|
+
for (const c of cards || []) {
|
|
77
|
+
if (c.mark === "lit") lit.push(c.id);
|
|
78
|
+
if (c.mark === "lit" || c.mark === "path") frame.push(c.id);
|
|
79
|
+
}
|
|
80
|
+
return { lit, frame };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The state a drawn shot reports: a graph that failed, a question with no answer on the graph, or drawn. */
|
|
84
|
+
export function shotState({ failed = false, lit }) {
|
|
85
|
+
if (failed) return "failed";
|
|
86
|
+
return lit && lit.asked && !lit.ids.length ? "no-matches" : "drawn";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Where the picture's facts come from, in a few words: the source graph, or the env's live read (and its snapshot). */
|
|
90
|
+
/** What a plan-depth answer says about itself, in the tab's query line and the shot's caption alike. */
|
|
91
|
+
export const PLAN_DEPTH_NOTE = "at the plan depth";
|
|
92
|
+
|
|
93
|
+
export function shotProvenance(view) {
|
|
94
|
+
const v = view || {};
|
|
95
|
+
if (!v.env) return "source graph";
|
|
96
|
+
return v.snapshot ? `env ${v.env}, snapshot ${v.snapshot}` : `env ${v.env}, live`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The caption's one line: what was asked (the query, or the stand-in
|
|
101
|
+
* selection), where the picture comes from, and when. A failure line comes
|
|
102
|
+
* first when there is one. Control characters become spaces, so it stays one line.
|
|
103
|
+
*/
|
|
104
|
+
export function shotCaption({ query = null, label = null, provenance = "", at = new Date(), failure = null, state = "drawn", counts = null, plan = false } = {}) {
|
|
105
|
+
const one = (s) => String(s).replace(/[\u0000-\u001f\u007f]+/g, " ").trim();
|
|
106
|
+
const asked = query ? (query === "the whole graph" ? query : `"${one(query)}"`) : label ? one(label) : "the whole graph";
|
|
107
|
+
const parts = [];
|
|
108
|
+
if (failure) parts.push(one(failure));
|
|
109
|
+
parts.push(state === "no-matches" ? `no matches for ${asked}` : asked);
|
|
110
|
+
if (counts) parts.push(one(counts)); // behold#922: chant's groups and total
|
|
111
|
+
if (provenance) parts.push(one(provenance));
|
|
112
|
+
if (plan) parts.push(PLAN_DEPTH_NOTE);
|
|
113
|
+
const t = at instanceof Date && !Number.isNaN(at.getTime()) ? at.toISOString().replace(/\.\d+Z$/, "Z") : "";
|
|
114
|
+
if (t) parts.push(t);
|
|
115
|
+
return parts.join(" · ");
|
|
116
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { queryFrame, readShotFrame, shotCaption, shotLit, shotProvenance, shotState } from "./shot-frame.js";
|
|
3
|
+
|
|
4
|
+
const box = (x, y, w = 100, h = 60) => ({ x, y, x2: x + w, y2: y + h });
|
|
5
|
+
const cards = [
|
|
6
|
+
{ id: "a", box: box(0, 0) },
|
|
7
|
+
{ id: "b", box: box(200, 0) },
|
|
8
|
+
{ id: "c", box: box(0, 300) },
|
|
9
|
+
];
|
|
10
|
+
const groups = [{ id: "top", box: { x: -10, y: -10, x2: 320, y2: 80 } }];
|
|
11
|
+
|
|
12
|
+
describe("readShotFrame (behold#915)", () => {
|
|
13
|
+
it("is on only in a bare embed frame that asks for frame=matches", () => {
|
|
14
|
+
expect(readShotFrame("?embed=1&bare=1&frame=matches")).toBe("matches");
|
|
15
|
+
expect(readShotFrame("?embed=1&frame=matches")).toBeNull();
|
|
16
|
+
expect(readShotFrame("?bare=1&frame=matches")).toBeNull();
|
|
17
|
+
expect(readShotFrame("?embed=1&bare=1&frame=whole")).toBeNull();
|
|
18
|
+
expect(readShotFrame("")).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("shotLit", () => {
|
|
23
|
+
it("lights a query's matches when they are given, whatever the view selects", () => {
|
|
24
|
+
expect(shotLit({ node: "a" }, cards, groups, ["b", "c", "gone"])).toEqual({ ids: ["b", "c"], asked: true, label: null });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("lights the node the view names, and nothing for a card the graph lacks", () => {
|
|
28
|
+
expect(shotLit({ node: "b" }, cards, groups).ids).toEqual(["b"]);
|
|
29
|
+
expect(shotLit({ node: "zzz" }, cards, groups)).toMatchObject({ ids: [], asked: true });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("lights the cards inside the boxes focus names, or the cards it names", () => {
|
|
33
|
+
expect(shotLit({ focus: "top" }, cards, groups).ids).toEqual(["a", "b"]);
|
|
34
|
+
expect(shotLit({ focus: "c, nope" }, cards, groups).ids).toEqual(["c"]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("asks for nothing with no selection", () => {
|
|
38
|
+
expect(shotLit({}, cards, groups)).toEqual({ ids: [], asked: false, label: null });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("shotState", () => {
|
|
43
|
+
it("says failed, no-matches or drawn", () => {
|
|
44
|
+
expect(shotState({ failed: true, lit: { ids: ["a"], asked: true } })).toBe("failed");
|
|
45
|
+
expect(shotState({ lit: { ids: [], asked: true } })).toBe("no-matches");
|
|
46
|
+
expect(shotState({ lit: { ids: ["a"], asked: true } })).toBe("drawn");
|
|
47
|
+
expect(shotState({ lit: { ids: [], asked: false } })).toBe("drawn");
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("the caption", () => {
|
|
52
|
+
const at = new Date("2026-10-23T14:02:11.250Z");
|
|
53
|
+
it("says a plan-depth answer is at the plan depth, in the words of the tab's query line", () => {
|
|
54
|
+
const line = shotCaption({ query: "attr:planAction=replace", provenance: "observed live · bound 1/1", at, plan: true });
|
|
55
|
+
expect(line).toBe('"attr:planAction=replace" · observed live · bound 1/1 · at the plan depth · 2026-10-23T14:02:11Z');
|
|
56
|
+
expect(shotCaption({ query: "a", at })).not.toContain("plan depth");
|
|
57
|
+
});
|
|
58
|
+
it("is one line: what was asked, from where, when", () => {
|
|
59
|
+
expect(shotCaption({ query: "kind:Bucket", provenance: shotProvenance({ env: "prod" }), at })).toBe('"kind:Bucket" · env prod, live · 2026-10-23T14:02:11Z');
|
|
60
|
+
expect(shotCaption({ label: "node a", provenance: shotProvenance({}), at, state: "no-matches" })).toBe("no matches for node a · source graph · 2026-10-23T14:02:11Z");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("puts a failure first, and never breaks the line", () => {
|
|
64
|
+
const line = shotCaption({ query: "a\nb", failure: "graph failed: chant\nexited 1", provenance: shotProvenance({ env: "prod", snapshot: "latest" }), at, state: "failed" });
|
|
65
|
+
expect(line).not.toContain("\n");
|
|
66
|
+
expect(line.startsWith("graph failed: chant exited 1")).toBe(true);
|
|
67
|
+
expect(line).toContain("env prod, snapshot latest");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("queryFrame (#908 stage 3)", () => {
|
|
72
|
+
it("lights the lit cards and frames them with the path cards, leaving the dimmed out", () => {
|
|
73
|
+
const marks = [
|
|
74
|
+
{ id: "bastion", mark: "lit" },
|
|
75
|
+
{ id: "subnet", mark: "path" },
|
|
76
|
+
{ id: "igw", mark: "path" },
|
|
77
|
+
{ id: "vpc", mark: "dim" },
|
|
78
|
+
{ id: "roles ×31", mark: "lit" },
|
|
79
|
+
{ id: "plain", mark: null },
|
|
80
|
+
];
|
|
81
|
+
expect(queryFrame(marks)).toEqual({ lit: ["bastion", "roles ×31"], frame: ["bastion", "subnet", "igw", "roles ×31"] });
|
|
82
|
+
expect(shotState({ lit: shotLit({}, marks, [], queryFrame(marks).lit) })).toBe("drawn");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("frames nothing and reports no matches when nothing is lit", () => {
|
|
86
|
+
const marks = [{ id: "vpc", mark: "dim" }];
|
|
87
|
+
expect(queryFrame(marks)).toEqual({ lit: [], frame: [] });
|
|
88
|
+
expect(shotState({ lit: shotLit({}, marks, [], queryFrame(marks).lit) })).toBe("no-matches");
|
|
89
|
+
});
|
|
90
|
+
});
|
package/web/themes.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// All Ghostty themes from mbadolato/iTerm2-Color-Schemes @ 982a5345.
|
|
3
3
|
// Regenerate: node test/make-themes.ts
|
|
4
4
|
export const THEMES_SOURCE = "https://raw.githubusercontent.com/mbadolato/iTerm2-Color-Schemes/982a5345c3ac4075320598100aa4155fdf8193fd/ghostty/";
|
|
5
|
-
export const DEFAULT_THEME = "
|
|
5
|
+
export const DEFAULT_THEME = "GitHub Light Colorblind";
|
|
6
6
|
export const THEMES = {
|
|
7
7
|
"0x96f": { name: "0x96f", dark: true, bg: '#262427', fg: '#fcfcfa', cursor: '#fcfcfa', selection: '#fcfcfa', palette: ['#262427', '#ff666d', '#b3e03a', '#ffc739', '#00cde8', '#a392e8', '#9deaf6', '#fcfcfa', '#545452', '#ff7e83', '#bee55e', '#ffd05e', '#1bd5eb', '#b0a3eb', '#acedf8', '#fcfcfa'] },
|
|
8
8
|
"12-bit Rainbow": { name: "12-bit Rainbow", dark: true, bg: '#040404', fg: '#feffff', cursor: '#e0d000', selection: '#606060', palette: ['#000000', '#a03050', '#40d080', '#e09040', '#3060b0', '#603090', '#0090c0', '#dbded8', '#685656', '#c06060', '#90d050', '#e0d000', '#00b0c0', '#801070', '#20b0c0', '#ffffff'] },
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Types for src/view-move.ts, which settles an agent's view with the same checks the URL uses (#914).
|
|
2
|
+
export type Refusal = { key: string; value: unknown; reason: string };
|
|
3
|
+
export type Want = Record<string, unknown>;
|
|
4
|
+
export const VIEW_KEYS: string[];
|
|
5
|
+
export const ZOOMS: string[];
|
|
6
|
+
export const LENSES: string[];
|
|
7
|
+
export const QUERY_MAX: number;
|
|
8
|
+
export function isEnvName(env: unknown): boolean;
|
|
9
|
+
export function checkQuery(v: unknown): { ok: true; value: string | null } | { ok: false; reason: string };
|
|
10
|
+
export function checkSnapshot(v: unknown): { ok: true; value: string | null } | { ok: false; reason: string };
|
|
11
|
+
export function checkCountBy(v: unknown): { ok: true; value: string | null } | { ok: false; reason: string };
|
|
12
|
+
export const PLAN_SNAPSHOT_REASON: string;
|
|
13
|
+
export function readViewQuery(search: string): Want;
|
|
14
|
+
export function writeViewQuery(search: string, state: Want, defaults?: { env?: string | null; lens?: string }): string;
|
|
15
|
+
export function settleView(want: Want, offer: { zooms?: string[]; envs?: string[]; tiers?: string[]; lenses?: string[]; env?: string | null }): { apply: Want; refused: Refusal[] };
|
|
16
|
+
export function viewFromObject(d: unknown): { want: Want; refused: Refusal[] };
|
|
17
|
+
export function refusalLine(refused: Refusal[]): string;
|
|
18
|
+
export function restoreViewQuery(search: string, defaults?: { env?: string | null; lens?: string }): Want;
|
package/web/view-url.js
CHANGED
|
@@ -16,8 +16,64 @@
|
|
|
16
16
|
* `run` (#569) pins which terragucci run the view draws: a commit's run view,
|
|
17
17
|
* `none` (no run view: the newest pull request's plan), `pull-<n>[-<sha>]`
|
|
18
18
|
* (no run view, and only that pull request's plan, of that commit) or `base`
|
|
19
|
-
* (nothing in flight); absent, the newest.
|
|
20
|
-
|
|
19
|
+
* (nothing in flight); absent, the newest. `plan` (behold#922) is the plan
|
|
20
|
+
* read: the cards carry each Terraform root's plan facts and `q` is answered
|
|
21
|
+
* at the plan depth. `countBy` (behold#922) groups `q`'s matches the way
|
|
22
|
+
* chant's `--count-by` does, and the view lights each group with its count. */
|
|
23
|
+
export const VIEW_KEYS = ["member", "zoom", "env", "tier", "lens", "node", "radial", "alike", "gates", "focus", "run", "pull", "q", "snapshot", "plan", "countBy"];
|
|
24
|
+
|
|
25
|
+
/** #914: the zooms behold has, whatever the estate. The server settles an
|
|
26
|
+
* agent's view against these (it doesn't know which the tab's estate offers);
|
|
27
|
+
* the tab settles it again against its own `availableZooms()`. */
|
|
28
|
+
export const ZOOMS = ["components", "logical", "composites", "resources", "attributes", "runtime", "ops", "stacks"];
|
|
29
|
+
|
|
30
|
+
/** #913/#914: the longest `q` behold passes on. */
|
|
31
|
+
export const QUERY_MAX = 2000;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* #913/#914: `q`, a question in chant's search grammar. behold never parses
|
|
35
|
+
* the terms (a second parser would drift from chant's); it checks only what
|
|
36
|
+
* has to hold before the value reaches a process or the now line: a string,
|
|
37
|
+
* trimmed, 1 to QUERY_MAX characters, no control characters. null or "" clears
|
|
38
|
+
* it. Quotes, `!`, `->`, `<-`, `:` and `=` pass through untouched.
|
|
39
|
+
*/
|
|
40
|
+
export function checkQuery(v) {
|
|
41
|
+
if (v === null || v === undefined) return { ok: true, value: null };
|
|
42
|
+
if (typeof v !== "string") return { ok: false, reason: "q is a string" };
|
|
43
|
+
const t = v.trim();
|
|
44
|
+
if (!t) return { ok: true, value: null };
|
|
45
|
+
if (t.length > QUERY_MAX) return { ok: false, reason: `q is at most ${QUERY_MAX} characters` };
|
|
46
|
+
if (/[\u0000-\u001f\u007f]/.test(t)) return { ok: false, reason: "q holds no control characters" };
|
|
47
|
+
return { ok: true, value: t };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* #914 (behold#908's read-contract ruling): `snapshot`, a recorded lifecycle
|
|
52
|
+
* snapshot to read the env at, `latest` or a snapshot ref. It is not `at`:
|
|
53
|
+
* `at` is a git revision of the workspace in chant's read contract. null or ""
|
|
54
|
+
* clears it.
|
|
55
|
+
*/
|
|
56
|
+
export function checkSnapshot(v) {
|
|
57
|
+
if (v === null || v === undefined || v === "") return { ok: true, value: null };
|
|
58
|
+
if (typeof v !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(v.trim())) return { ok: false, reason: "snapshot is latest or a snapshot ref (letters, digits, '.', '_', ':', '@' and '-')" };
|
|
59
|
+
return { ok: true, value: v.trim() };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* behold#922: `countBy`, chant's `--count-by` grouping: `kind`, `module` or
|
|
64
|
+
* `attr:<name>`. A closed list of three spellings, so behold checks them (chant
|
|
65
|
+
* checks again and says the same). null or "" clears it.
|
|
66
|
+
*/
|
|
67
|
+
export function checkCountBy(v) {
|
|
68
|
+
if (v === null || v === undefined || v === "") return { ok: true, value: null };
|
|
69
|
+
if (typeof v !== "string") return { ok: false, reason: "countBy is kind, module or attr:<name>" };
|
|
70
|
+
const t = v.trim();
|
|
71
|
+
if (t === "kind" || t === "module" || /^attr:[A-Za-z0-9_.@-]{1,128}$/.test(t)) return { ok: true, value: t };
|
|
72
|
+
return { ok: false, reason: "countBy is kind, module or attr:<name>" };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** behold#922: the refusal for a view that asks for the plan and a snapshot at once. */
|
|
76
|
+
export const PLAN_SNAPSHOT_REASON = "plan and snapshot can't be asked together: a plan is read now, a snapshot replays what was recorded";
|
|
21
77
|
|
|
22
78
|
/** An env name as the server takes one (src/workspace-gates.ts isEnvName). */
|
|
23
79
|
export function isEnvName(env) {
|
|
@@ -39,7 +95,7 @@ export function readViewQuery(search) {
|
|
|
39
95
|
for (const k of VIEW_KEYS) {
|
|
40
96
|
if (!q.has(k)) continue;
|
|
41
97
|
const v = (q.get(k) || "").trim();
|
|
42
|
-
if (k === "radial" || k === "alike") {
|
|
98
|
+
if (k === "radial" || k === "alike" || k === "plan") {
|
|
43
99
|
if (/^(1|true|on|yes)$/i.test(v)) want[k] = true;
|
|
44
100
|
else if (/^(0|false|off|no)$/i.test(v)) want[k] = false;
|
|
45
101
|
else want[k] = v; // left for settleView to name
|
|
@@ -49,7 +105,7 @@ export function readViewQuery(search) {
|
|
|
49
105
|
want.env = v || null;
|
|
50
106
|
continue;
|
|
51
107
|
}
|
|
52
|
-
if (k === "focus" || k === "run" || k === "pull") {
|
|
108
|
+
if (k === "focus" || k === "run" || k === "pull" || k === "q" || k === "snapshot" || k === "countBy") {
|
|
53
109
|
want[k] = v || null;
|
|
54
110
|
continue;
|
|
55
111
|
}
|
|
@@ -58,6 +114,65 @@ export function readViewQuery(search) {
|
|
|
58
114
|
return want;
|
|
59
115
|
}
|
|
60
116
|
|
|
117
|
+
/**
|
|
118
|
+
* #914: the whole view a URL holds, for going back to it (popstate). Unlike
|
|
119
|
+
* readViewQuery, a key the URL leaves out is set to what its absence means,
|
|
120
|
+
* so a move back clears what the move forward set: no `q` is no question, no
|
|
121
|
+
* `env` is the default env, no `lens` is the saved lens. `defaults` is
|
|
122
|
+
* writeViewQuery's.
|
|
123
|
+
*/
|
|
124
|
+
export function restoreViewQuery(search, defaults = {}) {
|
|
125
|
+
const want = readViewQuery(search);
|
|
126
|
+
const out = { member: null, gates: null, focus: null, run: null, pull: null, q: null, snapshot: null, countBy: null, radial: false, plan: false, ...want };
|
|
127
|
+
if (!("env" in want)) out.env = defaults.env || null;
|
|
128
|
+
if (!("lens" in want)) out.lens = defaults.lens || "drift";
|
|
129
|
+
if (!("alike" in want)) out.alike = true;
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* #914: a view sent as JSON (POST /api/view's `view`, and the `view` event the
|
|
135
|
+
* tab receives), reduced to the view keys. Unlike a host's message, a key that
|
|
136
|
+
* isn't a view key, or a value of the wrong type, is named in `refused`
|
|
137
|
+
* rather than dropped. `at` gets its own reason, because the ruling on
|
|
138
|
+
* behold#908 keeps it for the git revision.
|
|
139
|
+
*/
|
|
140
|
+
export function viewFromObject(d) {
|
|
141
|
+
const want = {};
|
|
142
|
+
const refused = [];
|
|
143
|
+
if (!d || typeof d !== "object" || Array.isArray(d)) return { want, refused: [{ key: "view", value: String(d), reason: "the view is a JSON object of view keys" }] };
|
|
144
|
+
for (const [k, v] of Object.entries(d)) {
|
|
145
|
+
if (!VIEW_KEYS.includes(k)) {
|
|
146
|
+
const reason = k === "at" ? "at is a git revision; a recorded snapshot is `snapshot`" : `the view keys are ${VIEW_KEYS.join(", ")}`;
|
|
147
|
+
refused.push({ key: k, value: show(v), reason });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (k === "radial" || k === "alike" || k === "plan") {
|
|
151
|
+
if (typeof v === "boolean") want[k] = v;
|
|
152
|
+
else refused.push({ key: k, value: show(v), reason: `${k} is true or false` });
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (k === "env" || k === "gates" || k === "focus" || k === "run" || k === "pull" || k === "member" || k === "q" || k === "snapshot" || k === "countBy") {
|
|
156
|
+
if (v === null || v === "") want[k] = null;
|
|
157
|
+
else if (typeof v === "string" || k === "q") want[k] = v; // a non-string q is checkQuery's to name
|
|
158
|
+
else refused.push({ key: k, value: show(v), reason: `${k} is a string or null` });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (typeof v === "string" && v) want[k] = v;
|
|
162
|
+
else refused.push({ key: k, value: show(v), reason: `${k} is a non-empty string` });
|
|
163
|
+
}
|
|
164
|
+
return { want, refused };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function show(v) {
|
|
168
|
+
try {
|
|
169
|
+
const s = typeof v === "string" ? v : JSON.stringify(v);
|
|
170
|
+
return s === undefined ? String(v) : s.length > 80 ? s.slice(0, 80) + "..." : s;
|
|
171
|
+
} catch {
|
|
172
|
+
return String(v);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
61
176
|
/**
|
|
62
177
|
* The query string for a view, keeping every parameter that isn't a view key.
|
|
63
178
|
* Defaults are left out so a plain view keeps a plain URL. `defaults` says
|
|
@@ -80,11 +195,15 @@ export function writeViewQuery(search, state, defaults = {}) {
|
|
|
80
195
|
if (s.lens && s.lens !== lensDefault) q.set("lens", s.lens);
|
|
81
196
|
if (s.node) q.set("node", s.node);
|
|
82
197
|
if (s.radial) q.set("radial", "1");
|
|
83
|
-
if (s.alike) q.set("alike", "
|
|
198
|
+
if (s.alike === false) q.set("alike", "0"); // stacked is the default
|
|
84
199
|
if (s.gates) q.set("gates", s.gates);
|
|
85
200
|
if (s.focus) q.set("focus", s.focus);
|
|
86
201
|
if (s.run) q.set("run", s.run);
|
|
87
202
|
if (s.pull) q.set("pull", s.pull);
|
|
203
|
+
if (s.q) q.set("q", s.q);
|
|
204
|
+
if (s.snapshot) q.set("snapshot", s.snapshot);
|
|
205
|
+
if (s.plan) q.set("plan", "1");
|
|
206
|
+
if (s.countBy) q.set("countBy", s.countBy);
|
|
88
207
|
const out = q.toString();
|
|
89
208
|
return out ? `?${out}` : "";
|
|
90
209
|
}
|
|
@@ -146,7 +265,35 @@ export function settleView(want, offer) {
|
|
|
146
265
|
if (want.pull === null || /^\d+$/.test(String(want.pull))) apply.pull = want.pull;
|
|
147
266
|
else refused.push({ key: "pull", value: want.pull, reason: "pull is a pull request's number" });
|
|
148
267
|
}
|
|
149
|
-
if (want
|
|
268
|
+
if ("q" in want) {
|
|
269
|
+
const c = checkQuery(want.q);
|
|
270
|
+
if (c.ok) apply.q = c.value;
|
|
271
|
+
else refused.push({ key: "q", value: typeof want.q === "string" ? want.q.slice(0, 80) : String(want.q), reason: c.reason });
|
|
272
|
+
}
|
|
273
|
+
if ("snapshot" in want) {
|
|
274
|
+
const c = checkSnapshot(want.snapshot);
|
|
275
|
+
// A snapshot is of an env: on the source graph there is nothing recorded to read.
|
|
276
|
+
const env = "env" in want ? want.env : o.env;
|
|
277
|
+
if (!c.ok) refused.push({ key: "snapshot", value: want.snapshot, reason: c.reason });
|
|
278
|
+
else if (c.value && !env) refused.push({ key: "snapshot", value: want.snapshot, reason: "a snapshot is of an env; name one with env" });
|
|
279
|
+
else apply.snapshot = c.value;
|
|
280
|
+
}
|
|
281
|
+
if ("plan" in want) {
|
|
282
|
+
if (typeof want.plan !== "boolean") refused.push({ key: "plan", value: want.plan, reason: "plan is 1 or 0" });
|
|
283
|
+
// behold#922: the two observations are named together, and neither is applied.
|
|
284
|
+
else if (want.plan && apply.snapshot) {
|
|
285
|
+
refused.push({ key: "plan", value: "1", reason: PLAN_SNAPSHOT_REASON });
|
|
286
|
+
refused.push({ key: "snapshot", value: apply.snapshot, reason: PLAN_SNAPSHOT_REASON });
|
|
287
|
+
delete apply.snapshot;
|
|
288
|
+
} else apply.plan = want.plan;
|
|
289
|
+
}
|
|
290
|
+
if ("countBy" in want) {
|
|
291
|
+
const c = checkCountBy(want.countBy);
|
|
292
|
+
if (c.ok) apply.countBy = c.value;
|
|
293
|
+
else refused.push({ key: "countBy", value: typeof want.countBy === "string" ? want.countBy.slice(0, 80) : String(want.countBy), reason: c.reason });
|
|
294
|
+
}
|
|
295
|
+
if (want.member === null) apply.member = null;
|
|
296
|
+
else if (want.member) apply.member = want.member;
|
|
150
297
|
if (want.node) apply.node = want.node;
|
|
151
298
|
return { apply, refused };
|
|
152
299
|
}
|