@intentius/behold 0.29.25 → 0.29.27

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.
Files changed (33) hide show
  1. package/AGENTS.md +3 -1
  2. package/demos.json +15 -0
  3. package/dist/cli.js +697 -371
  4. package/example-choudoufu-estate/README.md +2 -2
  5. package/example-choudoufu-estate/scripts/choudoufu-up.sh +2 -2
  6. package/example-terralith/README.md +33 -0
  7. package/example-terralith/phases/adopt/migrations/adopt.yml +12 -0
  8. package/example-terralith/phases/adopt/terralith/main.tf +138 -0
  9. package/example-terralith/phases/plan/team-a/main.tf +58 -0
  10. package/example-terralith/phases/plan/team-b/main.tf +58 -0
  11. package/example-terralith/phases/plan/team-c/main.tf +58 -0
  12. package/example-terralith/phases/plan/terralith/main.tf +32 -0
  13. package/example-terralith/phases/split/migrations/split.yml +29 -0
  14. package/example-terralith/phases/split/team-a/main.tf +52 -0
  15. package/example-terralith/phases/split/team-b/main.tf +52 -0
  16. package/example-terralith/phases/split/team-c/main.tf +52 -0
  17. package/example-terralith/phases/split/terralith/main.tf +27 -0
  18. package/example-terralith/scripts/lib.sh +65 -0
  19. package/example-terralith/scripts/terralith-down.sh +9 -0
  20. package/example-terralith/scripts/terralith-step.sh +139 -0
  21. package/example-terralith/scripts/terralith-up.sh +50 -0
  22. package/example-terralith/terralith/main.tf +141 -0
  23. package/package.json +2 -1
  24. package/web/app.js +83 -9
  25. package/web/identity-mark.js +61 -0
  26. package/web/identity-mark.test.js +32 -0
  27. package/web/pending.js +54 -0
  28. package/web/pending.test.js +47 -1
  29. package/web/terralith-steps.js +142 -0
  30. package/web/terralith-steps.test.js +97 -0
  31. package/web/terralith.html +125 -0
  32. package/web/terralith.js +301 -0
  33. /package/example-choudoufu-estate/monolith/{carve.json → split.json} +0 -0
@@ -0,0 +1,61 @@
1
+ // The marker-vs-derived mark: how a card shows where its identity comes from.
2
+ //
3
+ // choudoufu keeps two facts apart, and so does the mark:
4
+ //
5
+ // - how the plan found the live object (`live-plan`'s `bound[].source`):
6
+ // `marker` when the estate-wide tag sweep bound it, `derived` when the
7
+ // configuration names it (an IAM role's name, a log group's name);
8
+ // - whether the object wears this estate's marker (`live-ls` lists it under
9
+ // the estate's tag).
10
+ //
11
+ // A stamped log group is derived AND marked; an inline policy is derived and
12
+ // has no tags argument to carry a marker. A stock root has neither: its
13
+ // identity is the state file's.
14
+ //
15
+ // The glyph is a tag: filled when the object wears the marker, outlined when
16
+ // it does not, absent for a stock root. Pure data and functions; app.js and
17
+ // terralith.js draw.
18
+
19
+ /** Every mark, keyed. `label` is the card's word, `tip` its hover. */
20
+ export const IDENTITY_MARKS = {
21
+ state: { label: "state file", glyph: "none", tip: "A stock root keeps this resource's identity in its state file." },
22
+ marker: { label: "marker", glyph: "solid", tip: "The tag sweep found it by the marker on the resource (tofu-estate, tofu-address)." },
23
+ "derived-marked": { label: "derived · marked", glyph: "solid", tip: "Its name in the code identifies it, and it wears the marker too." },
24
+ derived: { label: "derived", glyph: "outline", tip: "Matched by name alone; it has no tags argument to carry a marker." },
25
+ record: { label: "record", glyph: "outline", tip: "Its identity comes from the estate's record store." },
26
+ cache: { label: "cache", glyph: "outline", tip: "Answered from the local state cache." },
27
+ unbound: { label: "not bound yet", glyph: "outline", tip: "The plan has bound no live object to it yet." },
28
+ };
29
+
30
+ /** The mark's key for an identity `{source, marked}`, or null for none. */
31
+ export function identityKey(identity) {
32
+ if (!identity || typeof identity !== "object") return null;
33
+ const { source, marked } = identity;
34
+ if (source === "state") return "state";
35
+ if (source === "marker") return "marker";
36
+ if (source === "derived") return marked ? "derived-marked" : "derived";
37
+ if (source === "record" || source === "cache") return source;
38
+ if (source === "unbound") return "unbound";
39
+ return null;
40
+ }
41
+
42
+ /** The mark for an identity: `{key, label, glyph, tip}`, or null. */
43
+ export function identityMark(identity) {
44
+ const key = identityKey(identity);
45
+ return key ? { key, ...IDENTITY_MARKS[key] } : null;
46
+ }
47
+
48
+ /** The tag glyph as SVG markup at (x, y), `size` px tall, in `color`. */
49
+ export function tagGlyphSvg(glyph, x, y, size, color) {
50
+ if (glyph === "none") return "";
51
+ const s = size / 12;
52
+ const p = (px, py) => `${(x + px * s).toFixed(2)},${(y + py * s).toFixed(2)}`;
53
+ // A luggage tag: a pentagon pointing left, with its eyelet.
54
+ const body = [p(0, 6), p(4, 1), p(12, 1), p(12, 11), p(4, 11)].join(" ");
55
+ const fill = glyph === "solid" ? color : "none";
56
+ const hole = glyph === "solid" ? "var(--bg, #000)" : color;
57
+ return (
58
+ `<polygon points="${body}" fill="${fill}" stroke="${color}" stroke-width="${(1.2 * s).toFixed(2)}" stroke-linejoin="round"/>` +
59
+ `<circle cx="${(x + 4.6 * s).toFixed(2)}" cy="${(y + 6 * s).toFixed(2)}" r="${(1.2 * s).toFixed(2)}" fill="${hole}"/>`
60
+ );
61
+ }
@@ -0,0 +1,32 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { IDENTITY_MARKS, identityKey, identityMark, tagGlyphSvg } from "./identity-mark.js";
3
+
4
+ describe("the marker-vs-derived mark", () => {
5
+ it("tells a marker-found card from a derived one, and a derived one that wears the marker from one that does not", () => {
6
+ expect(identityKey({ source: "marker", marked: true })).toBe("marker");
7
+ expect(identityKey({ source: "derived", marked: true })).toBe("derived-marked");
8
+ expect(identityKey({ source: "derived", marked: false })).toBe("derived");
9
+ expect(identityKey({ source: "state", marked: false })).toBe("state");
10
+ });
11
+
12
+ it("fills the tag only when the object wears the marker", () => {
13
+ expect(identityMark({ source: "derived", marked: true }).glyph).toBe("solid");
14
+ expect(identityMark({ source: "derived", marked: false }).glyph).toBe("outline");
15
+ expect(identityMark({ source: "state", marked: false }).glyph).toBe("none");
16
+ });
17
+
18
+ it("has no mark for an identity it does not know", () => {
19
+ expect(identityMark(undefined)).toBeNull();
20
+ expect(identityMark({ source: "guess" })).toBeNull();
21
+ });
22
+
23
+ it("keeps every label short enough for a card's corner", () => {
24
+ for (const m of Object.values(IDENTITY_MARKS)) expect(m.label.length).toBeLessThanOrEqual(16);
25
+ });
26
+
27
+ it("draws a filled tag, an outlined tag, or nothing", () => {
28
+ expect(tagGlyphSvg("solid", 0, 0, 12, "red")).toContain('fill="red"');
29
+ expect(tagGlyphSvg("outline", 0, 0, 12, "red")).toContain('fill="none"');
30
+ expect(tagGlyphSvg("none", 0, 0, 12, "red")).toBe("");
31
+ });
32
+ });
package/web/pending.js CHANGED
@@ -37,6 +37,8 @@ export function applyMemberFrame(ir, frame) {
37
37
  // and not absent.
38
38
  if (frame.unobserved) attrs._unobserved = frame.unobserved;
39
39
  else delete attrs._unobserved;
40
+ // The identity mark (web/identity-mark.js), for a card that carries one.
41
+ if (frame.identities && frame.identities[node.id]) attrs._identity = frame.identities[node.id];
40
42
  if (was !== next) moved.push(node.id);
41
43
  }
42
44
  return moved;
@@ -65,3 +67,55 @@ export function pendingLine(pending, total) {
65
67
  const who = pending.length <= 3 ? ` — waiting on ${pending.join(", ")}` : "";
66
68
  return `${scope}${who}`;
67
69
  }
70
+
71
+ /**
72
+ * The frames of one progressive load, kept from the moment its request goes
73
+ * out until the answer is drawn.
74
+ *
75
+ * The live pass starts when the server takes the request, and with the
76
+ * overlay cache warm it can settle and broadcast every member before the
77
+ * answer reaches the page. A frame that lands then has no picture to fold
78
+ * into: the answer, drawn a moment later, paints every card pending again.
79
+ * So every frame is noted here (the newest per member wins), applied at once
80
+ * only when the picture it belongs to is already up, and replayed onto the
81
+ * picture right after it is drawn. A failed live pass is noted the same way.
82
+ */
83
+ export function createMemberFrames() {
84
+ let frames = new Map();
85
+ let failed = null;
86
+ let drawing = false;
87
+ let load = 0;
88
+ return {
89
+ /** A progressive request is going out: its frames start here. Returns the load's turn. */
90
+ begin() {
91
+ frames = new Map();
92
+ failed = null;
93
+ drawing = true;
94
+ return ++load;
95
+ },
96
+ /** Note a frame. True when it can be applied now, false when it waits for the draw. */
97
+ note(frame) {
98
+ if (!frame) return false;
99
+ if (frame.error) failed = frame.error;
100
+ else if (frame.member) frames.set(frame.member, frame);
101
+ return !drawing;
102
+ },
103
+ /** Load `turn`'s answer is drawn: fold every noted frame into it. Null when a newer load took over. */
104
+ replay(ir, pending, turn = load) {
105
+ if (turn !== load) return null;
106
+ drawing = false;
107
+ const moved = [];
108
+ let still = Array.isArray(pending) ? [...pending] : [];
109
+ for (const frame of frames.values()) {
110
+ moved.push(...applyMemberFrame(ir, frame));
111
+ still = stillPending(still, frame);
112
+ }
113
+ if (failed) still = [];
114
+ return { moved, pending: still, failed };
115
+ },
116
+ /** Load `turn` ended without drawing (an error, a newer view): stop holding frames back, unless a newer load holds them. */
117
+ cancel(turn = load) {
118
+ if (turn === load) drawing = false;
119
+ },
120
+ };
121
+ }
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { applyMemberFrame, pendingLine, stillPending } from "./pending.js";
2
+ import { applyMemberFrame, createMemberFrames, pendingLine, stillPending } from "./pending.js";
3
3
 
4
4
  const ir = () => ({
5
5
  nodes: [
@@ -21,6 +21,13 @@ describe("applyMemberFrame (#422)", () => {
21
21
  expect(graph.nodes[2].attrs).toEqual({ _pendingRead: true });
22
22
  });
23
23
 
24
+ it("carries a choudoufu card's identity mark when the frame has one", () => {
25
+ const graph = ir();
26
+ applyMemberFrame(graph, { member: "team-a", statuses: { "team-a/bucket": "good", "team-a/role": "good" }, identities: { "team-a/role": { source: "derived", marked: true } } });
27
+ expect(graph.nodes[1].attrs._identity).toEqual({ source: "derived", marked: true });
28
+ expect(graph.nodes[0].attrs._identity).toBeUndefined();
29
+ });
30
+
24
31
  it("carries a failed member's reason, which is not the same as pending", () => {
25
32
  const graph = ir();
26
33
  applyMemberFrame(graph, { member: "team-b", unobserved: "no credentials", statuses: { "team-b/bucket": "neutral" } });
@@ -60,3 +67,42 @@ describe("what is still arriving", () => {
60
67
  expect(pendingLine(undefined, 5)).toBeNull();
61
68
  });
62
69
  });
70
+
71
+ describe("createMemberFrames: frames that land before the draw (#422)", () => {
72
+ const frame = { member: "team-a", statuses: { "team-a/bucket": "good", "team-a/role": "warn" } };
73
+
74
+ it("holds a frame that lands while the answer is on the way, and replays it onto the drawn picture", () => {
75
+ const frames = createMemberFrames();
76
+ const turn = frames.begin();
77
+ expect(frames.note(frame)).toBe(false);
78
+ const graph = ir();
79
+ const r = frames.replay(graph, ["team-a", "team-b"], turn);
80
+ expect(r.moved.sort()).toEqual(["team-a/bucket", "team-a/role"]);
81
+ expect(r.pending).toEqual(["team-b"]);
82
+ expect(graph.nodes[0].attrs).toEqual({ _status: "good" });
83
+ // Once drawn, a later frame applies as it lands.
84
+ expect(frames.note({ member: "team-b", statuses: {} })).toBe(true);
85
+ });
86
+
87
+ it("keeps the newest frame per member, and a failed pass clears the pending list", () => {
88
+ const frames = createMemberFrames();
89
+ const turn = frames.begin();
90
+ frames.note({ member: "team-a", statuses: { "team-a/bucket": "warn" } });
91
+ frames.note({ member: "team-a", statuses: { "team-a/bucket": "good" } });
92
+ frames.note({ error: "live-plan exited 1" });
93
+ const graph = ir();
94
+ const r = frames.replay(graph, ["team-a", "team-b"], turn);
95
+ expect(graph.nodes[0].attrs._status).toBe("good");
96
+ expect(r).toMatchObject({ pending: [], failed: "live-plan exited 1" });
97
+ });
98
+
99
+ it("leaves a newer load's frames alone when an older load ends", () => {
100
+ const frames = createMemberFrames();
101
+ const older = frames.begin();
102
+ const newer = frames.begin();
103
+ frames.cancel(older);
104
+ expect(frames.note(frame)).toBe(false);
105
+ expect(frames.replay(ir(), [], older)).toBeNull();
106
+ expect(frames.replay(ir(), ["team-a"], newer).pending).toEqual([]);
107
+ });
108
+ });
@@ -0,0 +1,142 @@
1
+ // `behold demo terralith`'s walkthrough: what each phase says and how a card
2
+ // reads. Pure data and functions, tested next door; web/terralith.js draws.
3
+ //
4
+ // The model comes from GET /api/terralith (src/terralith-demo.ts), which reads
5
+ // the snapshot files the demo copy's scripts write. Nothing here runs a write:
6
+ // a phase that has not run yet shows the line that runs it, to copy.
7
+
8
+ import { IDENTITY_MARKS, identityKey } from "./identity-mark.js";
9
+
10
+ /** The phases, in order. `lead` is the phase's paragraph; `facts(phase)` its counted line. */
11
+ export const PHASES = [
12
+ {
13
+ id: "stock",
14
+ n: 1,
15
+ label: "Stock",
16
+ title: "A stock terralith",
17
+ lead: "One Terraform root holds a network and the IAM and logging of three teams. All 23 resources sit in one state file on S3, which is where each one's identity lives.",
18
+ facts: (p) => `${p.counts.cards} resources, ready to adopt.`,
19
+ },
20
+ {
21
+ id: "adopt",
22
+ n: 2,
23
+ label: "Adopt",
24
+ title: "Adopt",
25
+ lead: "This is terragucci's backends migration. The root's backend block becomes a live block, and choudoufu live-import reads the state once and writes the tofu-estate and tofu-address tags on each resource it verifies. The state file stays in the bucket as it was.",
26
+ facts: (p) =>
27
+ `${p.counts.marked} of ${p.counts.cards} resources now carry the marker. ` +
28
+ `The other ${p.counts.cards - p.counts.marked} have no tags argument, and ride the role they belong to.`,
29
+ },
30
+ {
31
+ id: "split",
32
+ n: 3,
33
+ label: "Split",
34
+ title: "Split",
35
+ lead: "This is terragucci's moves migration. Three team roots appear, and in each one choudoufu live-mv rewrites the tags on that team's resources so they belong to the team's estate. Each resource takes one tag write. Inline policies and attachments follow their role with no write of their own, and split.json holds the record.",
36
+ facts: (p) => {
37
+ const fresh = p.boxes.filter((b) => b.spawned).length;
38
+ return `${p.counts.moved} resources moved into ${fresh} new estate${fresh === 1 ? "" : "s"}. The terralith keeps the network.`;
39
+ },
40
+ },
41
+ {
42
+ id: "plan",
43
+ n: 4,
44
+ label: "Plan",
45
+ title: "Plan across the estates",
46
+ lead: "One pull request touches all four estates. The terralith publishes a shared setting as an output, and each team's first log group reads it through terraform_estate_outputs. It plans first. With -estate-outputs-from, each team root then plans against that planned value, so nothing waits for an apply. Last, live-summary folds the identical team changes into one group.",
47
+ facts: (p) => {
48
+ const groups = (p.plan && p.plan.groups) || [];
49
+ const folded = groups.reduce((n, g) => n + g.members.length, 0);
50
+ return `${p.counts.planned} planned changes in ${folded} estates, folded into ${groups.length} group${groups.length === 1 ? "" : "s"}. Nothing is applied.`;
51
+ },
52
+ },
53
+ ];
54
+
55
+ export const phaseById = (id) => PHASES.find((p) => p.id === id) || null;
56
+
57
+ /** Which phase to show: the one the URL names when it has run, else the newest. */
58
+ export function shownPhase(model, wanted) {
59
+ const ran = (model && model.phases) || [];
60
+ if (!ran.length) return null;
61
+ return ran.find((p) => p.id === wanted) || ran[ran.length - 1];
62
+ }
63
+
64
+ /** Each step of the stepper: ran, shown, or the one to run next. */
65
+ export function stepperItems(model, shownId) {
66
+ const ran = new Set(((model && model.phases) || []).map((p) => p.id));
67
+ const next = model && model.next ? model.next.id : null;
68
+ return PHASES.map((p) => ({ id: p.id, n: p.n, label: p.label, ran: ran.has(p.id), shown: p.id === shownId, next: p.id === next }));
69
+ }
70
+
71
+ /** A card's face: the type without its provider prefix, and the resource's name. */
72
+ export function cardFace(card) {
73
+ const [type, ...rest] = String(card.id).split(".");
74
+ return { kind: (card.type || type).replace(/^aws_/, ""), name: rest.join(".") || card.id };
75
+ }
76
+
77
+ /** The small word in a card's corner: the phase's own news about it. */
78
+ export function cardNews(card, phaseId) {
79
+ if (phaseId === "adopt" && card.ratified) return card.ratified;
80
+ if (phaseId === "split" && card.moved) return card.moved.follows ? "follows its role" : `from ${card.moved.from}`;
81
+ if (phaseId === "plan" && card.planned) return `${card.planned.actions.includes("update") ? "~" : card.planned.actions.join("/")} ${card.planned.attributes.join(", ")}`;
82
+ return "";
83
+ }
84
+
85
+ /** A box's subtitle. */
86
+ export function boxSubtitle(box) {
87
+ if (box.stock) return "stock root · state file on S3";
88
+ return `estate ${box.estate}${box.spawned ? " · new" : ""}`;
89
+ }
90
+
91
+ /** The legend: one row per mark the shown phase uses, in the marks' own order. */
92
+ export function legendFor(phase) {
93
+ const used = new Set();
94
+ for (const b of (phase && phase.boxes) || []) for (const c of b.cards) used.add(identityKey(c.identity));
95
+ return Object.keys(IDENTITY_MARKS)
96
+ .filter((k) => used.has(k))
97
+ .map((k) => ({ key: k, ...IDENTITY_MARKS[k] }));
98
+ }
99
+
100
+ /** FLIP: the translate that puts a card back where it was, from two rects. */
101
+ export function flipDelta(before, after) {
102
+ if (!before || !after) return null;
103
+ const dx = before.left - after.left;
104
+ const dy = before.top - after.top;
105
+ return Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5 ? null : { dx, dy };
106
+ }
107
+
108
+ /** Short words for a guard that planned a root in full, by choudoufu's guard kind. */
109
+ const FULL_PLAN_WORDS = {
110
+ "empty-cone": "planned in full: the change reaches no resource",
111
+ "estate-outputs-from": "planned in full: it reads planned outputs",
112
+ };
113
+
114
+ /** A box's plan badges: the cone, and the full plan when there was one. */
115
+ export function planBadges(box) {
116
+ const plan = box && box.plan;
117
+ if (!plan) return [];
118
+ const out = [];
119
+ if (plan.cone && !plan.cone.full) out.push({ kind: "cone", text: `cone ${plan.cone.coneBlocks} of ${plan.cone.blocks} blocks`, tip: "live-cone: the blocks this change reaches against the root's last commit." });
120
+ const full = plan.fallback || (plan.cone && plan.cone.full ? { kind: plan.cone.kind, reason: plan.cone.reason } : null);
121
+ if (full) out.push({ kind: "full", text: FULL_PLAN_WORDS[full.kind] || "planned in full", tip: full.reason || "" });
122
+ return out;
123
+ }
124
+
125
+ /** The folded group's one line, as live-summary prints it. */
126
+ export function groupLabel(group) {
127
+ const n = group.members.length;
128
+ const change = group.changes.length === 1 ? group.changes[0].line : `${group.changes.length} changes`;
129
+ return `${n} estates, one change: ${change}`;
130
+ }
131
+
132
+ /** A planned output's edge label. */
133
+ export function outputLabel(o) {
134
+ return o.known ? `${o.name} = ${JSON.stringify(o.value)} · planned` : `${o.name} · known after apply`;
135
+ }
136
+
137
+ /** Are these rects one row (the desktop layout) or stacked (the phone's)? */
138
+ export function oneRow(rects) {
139
+ if (rects.length < 2) return true;
140
+ const top = rects[0].top;
141
+ return rects.every((r) => Math.abs(r.top - top) < 4);
142
+ }
@@ -0,0 +1,97 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { PHASES, boxSubtitle, cardFace, cardNews, flipDelta, groupLabel, legendFor, oneRow, outputLabel, planBadges, shownPhase, stepperItems } from "./terralith-steps.js";
3
+
4
+ const card = (id, identity, extra = {}) => ({ id, type: id.split(".")[0], root: "terralith", identity, ...extra });
5
+ const phase = (id, boxes, counts = {}) => ({ id, n: PHASES.find((p) => p.id === id).n, boxes, counts: { cards: 0, marked: 0, moved: 0, ...counts }, notes: [] });
6
+
7
+ describe("the walkthrough's phases", () => {
8
+ const model = {
9
+ phases: [phase("stock", []), phase("adopt", [])],
10
+ next: { id: "split", n: 3, command: "bash scripts/terralith-step.sh split" },
11
+ };
12
+
13
+ it("shows the phase the URL names when it ran, else the newest", () => {
14
+ expect(shownPhase(model, "stock").id).toBe("stock");
15
+ expect(shownPhase(model, "split").id).toBe("adopt");
16
+ expect(shownPhase(model, null).id).toBe("adopt");
17
+ expect(shownPhase({ phases: [] }, "stock")).toBeNull();
18
+ });
19
+
20
+ it("marks each step ran, shown or next", () => {
21
+ expect(stepperItems(model, "adopt").map((s) => [s.id, s.ran, s.shown, s.next])).toEqual([
22
+ ["stock", true, false, false],
23
+ ["adopt", true, true, false],
24
+ ["split", false, false, true],
25
+ ["plan", false, false, false],
26
+ ]);
27
+ });
28
+
29
+ it("counts what each phase changed in its own line", () => {
30
+ const adopt = PHASES.find((p) => p.id === "adopt");
31
+ expect(adopt.facts(phase("adopt", [], { cards: 23, marked: 17 }))).toBe(
32
+ "17 of 23 resources now carry the marker. The other 6 have no tags argument, and ride the role they belong to.",
33
+ );
34
+ const split = PHASES.find((p) => p.id === "split");
35
+ const boxes = [{ spawned: false }, { spawned: true }, { spawned: true }, { spawned: true }];
36
+ expect(split.facts(phase("split", boxes, { moved: 21 }))).toBe("21 resources moved into 3 new estates. The terralith keeps the network.");
37
+ });
38
+ });
39
+
40
+ describe("a card", () => {
41
+ it("reads its type without the provider and its resource name", () => {
42
+ expect(cardFace(card("aws_iam_role_policy.team_a_inline", {}))).toEqual({ kind: "iam_role_policy", name: "team_a_inline" });
43
+ });
44
+
45
+ it("carries live-import's verdict in adopt, and its retag in split", () => {
46
+ const c = card("aws_iam_role.team_a", {}, { ratified: "verified", moved: { from: "terralith", to: "team-a" } });
47
+ expect(cardNews(c, "adopt")).toBe("verified");
48
+ expect(cardNews(c, "split")).toBe("from terralith");
49
+ expect(cardNews({ ...c, moved: { from: "terralith", to: "team-a", follows: "aws_iam_role.team_a" } }, "split")).toBe("follows its role");
50
+ expect(cardNews(c, "stock")).toBe("");
51
+ });
52
+ });
53
+
54
+ describe("boxes and the legend", () => {
55
+ it("says a stock root keeps a state file and a spawned estate is new", () => {
56
+ expect(boxSubtitle({ stock: true })).toBe("stock root · state file on S3");
57
+ expect(boxSubtitle({ stock: false, estate: "team-a", spawned: true })).toBe("estate team-a · new");
58
+ });
59
+
60
+ it("lists only the marks the phase uses", () => {
61
+ const p = phase("adopt", [{ cards: [card("aws_vpc.main", { source: "marker", marked: true }), card("aws_iam_role_policy.x", { source: "derived", marked: false })] }]);
62
+ expect(legendFor(p).map((l) => l.key)).toEqual(["marker", "derived"]);
63
+ });
64
+ });
65
+
66
+ describe("FLIP", () => {
67
+ it("is the offset back to where the card was, or nothing when it stayed", () => {
68
+ expect(flipDelta({ left: 10, top: 20 }, { left: 110, top: 20 })).toEqual({ dx: -100, dy: 0 });
69
+ expect(flipDelta({ left: 10, top: 20 }, { left: 10.2, top: 20 })).toBeNull();
70
+ expect(flipDelta(undefined, { left: 0, top: 0 })).toBeNull();
71
+ });
72
+ });
73
+
74
+ describe("the plan phase", () => {
75
+ it("badges a team root with its cone and the full plan it fell back to", () => {
76
+ const box = { plan: { cone: { full: false, blocks: 8, coneBlocks: 2 }, fallback: { kind: "estate-outputs-from", reason: "every reader of them is planned" }, changes: 1 } };
77
+ expect(planBadges(box).map((b) => [b.kind, b.text])).toEqual([
78
+ ["cone", "cone 2 of 8 blocks"],
79
+ ["full", "planned in full: it reads planned outputs"],
80
+ ]);
81
+ expect(planBadges({ plan: { cone: { full: true, kind: "empty-cone", reason: "the diff reaches no resource", blocks: 2, coneBlocks: 0 }, changes: 0 } }).map((b) => b.text)).toEqual(["planned in full: the change reaches no resource"]);
82
+ expect(planBadges({})).toEqual([]);
83
+ });
84
+
85
+ it("says a folded group once, and a planned output with its value", () => {
86
+ expect(groupLabel({ members: ["team-a", "team-b", "team-c"], changes: [{ line: "~ aws_cloudwatch_log_group.<estate>_0: retention_in_days" }] })).toBe(
87
+ "3 estates, one change: ~ aws_cloudwatch_log_group.<estate>_0: retention_in_days",
88
+ );
89
+ expect(outputLabel({ name: "log_retention_days", value: 14, known: true })).toBe("log_retention_days = 14 · planned");
90
+ expect(cardNews({ id: "x", planned: { actions: ["update"], attributes: ["retention_in_days"] } }, "plan")).toBe("~ retention_in_days");
91
+ });
92
+
93
+ it("tells a row of boxes from a stack", () => {
94
+ expect(oneRow([{ top: 10 }, { top: 11 }])).toBe(true);
95
+ expect(oneRow([{ top: 10 }, { top: 300 }])).toBe(false);
96
+ });
97
+ });
@@ -0,0 +1,125 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>behold · terralith</title>
7
+ <link
8
+ rel="icon"
9
+ href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6' fill='none' stroke='%23a6adc8' stroke-width='1.6'/%3E%3Ccircle cx='8' cy='8' r='2.2' fill='%23a6adc8'/%3E%3C/svg%3E"
10
+ />
11
+ <style>
12
+ /* The pre-paint fallback: Sea Shells' tokens (KIOSK_THEME in theme.js), which initTheme() replaces with the viewer's theme. */
13
+ :root {
14
+ --bg: #09141b; --panel: #1c2325; --line: #2c2e2d; --fg: #deb88d; --muted: #746a5c;
15
+ --edge: #4d483f; --managed: #027c9b; --foreign: #fca02f; --pending: #1e4950;
16
+ --degraded: #d15123; --neutral: #695e4e; --runtime: #50a3b5;
17
+ --rule: #3d4142; --focus: #364548; --active: #243235; --well: #01070d; --shadow: #010304;
18
+ --surface-box: #101b22; --surface-pane-a: #152128; --surface-pane-b: #1b272e; --soft: #deb88d; --muted-ink: #7c7365;
19
+ --managed-ink: #0e7f9e; --foreign-ink: #fca02f; --pending-ink: #567b82; --runtime-ink: #50a3b5;
20
+ --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
21
+ --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
22
+ --r-ctl: 6px; --t-body: 13px;
23
+ }
24
+ * { box-sizing: border-box; }
25
+ body { --fg: var(--soft); --muted: var(--muted-ink); --managed: var(--managed-ink); --foreign: var(--foreign-ink); --runtime: var(--runtime-ink); }
26
+ html, body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 var(--font-ui); }
27
+ main { max-width: 1400px; margin: 0 auto; padding: 18px 20px 40px; }
28
+ header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-bottom: 14px; }
29
+ h1 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: 0.01em; }
30
+ h1 small { font-weight: 450; color: var(--muted); font-size: 14px; margin-left: 6px; }
31
+ .t-theme { margin-left: auto; }
32
+ ol.t-steps { list-style: none; display: flex; gap: 6px; margin: 0; padding: 0; flex-wrap: wrap; }
33
+ .t-step { display: flex; align-items: center; gap: 7px; padding: 5px 12px 5px 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-box); color: var(--muted); font-size: 14px; cursor: default; }
34
+ .t-step b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font: 600 12px var(--font-mono); background: var(--well); color: var(--muted); }
35
+ .t-step.ran { color: var(--fg); cursor: pointer; }
36
+ .t-step.ran b { background: color-mix(in srgb, var(--managed) 35%, var(--well)); color: var(--fg); }
37
+ .t-step.shown { border-color: var(--managed); background: var(--active); }
38
+ .t-step.next { border-style: dashed; color: var(--fg); }
39
+ .t-lead { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 24rem); gap: 14px 20px; background: var(--surface-pane-a); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
40
+ .t-lead h2 { margin: 0 0 4px; font-size: 17px; }
41
+ .t-lead p { margin: 0 0 6px; }
42
+ .t-facts { color: var(--fg); font-weight: 550; }
43
+ .t-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; align-content: start; font-size: 13.5px; }
44
+ .t-legend li { display: grid; grid-template-columns: 16px auto; gap: 2px 8px; align-items: center; }
45
+ .t-legend span { color: var(--muted); grid-column: 2; font-size: 12.5px; }
46
+ .t-next { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 14px; padding: 10px 14px; border: 1px dashed var(--line); border-radius: 8px; background: var(--surface-box); }
47
+ .t-next[hidden], .t-notes[hidden] { display: none; }
48
+ .t-next code { font: 13.5px var(--font-mono); background: var(--well); padding: 4px 8px; border-radius: 5px; overflow-wrap: anywhere; }
49
+ .t-next .t-why { color: var(--muted); font-size: 13px; flex-basis: 100%; }
50
+ button.t-copy { font: 13px var(--font-ui); color: var(--fg); background: var(--active); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 4px 10px; cursor: pointer; }
51
+ .t-stage { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr)); gap: 14px; align-items: start; }
52
+ .t-box { background: var(--surface-pane-b); border: 1px solid var(--rule); border-radius: 10px; padding: 10px 10px 12px; }
53
+ .t-box.stock { border-style: dashed; }
54
+ .t-box.spawned { border-color: color-mix(in srgb, var(--managed) 70%, var(--rule)); }
55
+ .t-box-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin: 0 2px 8px; }
56
+ .t-box-head h3 { margin: 0; font-size: 15.5px; font: 600 15px var(--font-mono); }
57
+ .t-box-head span { color: var(--muted); font-size: 12.5px; }
58
+ .t-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.6rem, 1fr)); gap: 7px; }
59
+ .t-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px 6px; min-width: 0; }
60
+ .t-card .k { font: 11.5px var(--font-mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
61
+ .t-card .n { font: 600 13.5px var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 1px 0 4px; }
62
+ .t-card .m { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
63
+ .t-card .m svg { flex: none; }
64
+ .t-card .m.solid { color: var(--managed); }
65
+ .t-card .m .w { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
66
+ .t-card .news { font-size: 11.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
67
+ .t-card .news.drifted { color: var(--foreign); }
68
+ .t-card.moved { border-color: color-mix(in srgb, var(--managed) 55%, var(--line)); }
69
+ .t-stage { position: relative; }
70
+ .t-stage.planning { padding: 52px 0 40px; }
71
+ .t-overlay { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
72
+ .t-edge { fill: none; stroke: var(--runtime); stroke-width: 1.6; stroke-dasharray: 5 4; }
73
+ .t-edge-head { fill: var(--runtime); }
74
+ .t-edge-label { fill: var(--runtime); font: 12px var(--font-mono); }
75
+ .t-bracket { fill: none; stroke: var(--foreign); stroke-width: 2; }
76
+ .t-bracket-label { fill: var(--foreign); font: 12.5px var(--font-mono); }
77
+ .t-badges { display: flex; flex-wrap: wrap; gap: 5px; flex-basis: 100%; }
78
+ .t-badge { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
79
+ .t-badge.cone { border-color: var(--managed); color: var(--managed); }
80
+ .t-badge.full { border-style: dashed; }
81
+ .t-badge.group { border-color: var(--foreign); color: var(--foreign); }
82
+ .t-card.in-cone { outline: 2px dashed var(--managed); outline-offset: 2px; }
83
+ .t-card .news.change { color: var(--foreign); }
84
+ .t-groups, .t-groups[hidden] { display: none; }
85
+ .t-group { margin: 0; font: 13px var(--font-mono); color: var(--foreign); overflow-wrap: anywhere; }
86
+ .t-empty { color: var(--muted); padding: 30px 0; }
87
+ .t-notes { color: var(--foreign); font-size: 13px; margin-top: 10px; }
88
+ .t-foot { color: var(--muted); font-size: 12.5px; margin-top: 18px; }
89
+ @media (prefers-reduced-motion: no-preference) {
90
+ .t-box.spawning { animation: t-spawn 700ms cubic-bezier(.2,.7,.2,1) both; }
91
+ @keyframes t-spawn { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: none; } }
92
+ }
93
+ @media (max-width: 720px) {
94
+ main { padding: 12px 12px 30px; }
95
+ .t-lead { grid-template-columns: 1fr; padding: 12px; }
96
+ .t-theme { margin-left: 0; }
97
+ .t-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
98
+ .t-stage.planning { padding: 0 16px 24px 16px; }
99
+ .t-groups:not([hidden]) { display: block; margin: 0 0 10px; }
100
+ }
101
+ </style>
102
+ </head>
103
+ <body>
104
+ <main>
105
+ <header>
106
+ <h1>Terralith <small>behold demo terralith</small></h1>
107
+ <ol class="t-steps" id="t-steps" aria-label="Phases"></ol>
108
+ <div class="t-theme" id="t-theme"></div>
109
+ </header>
110
+ <section class="t-lead" id="t-lead" aria-live="polite"></section>
111
+ <section class="t-next" id="t-next" hidden></section>
112
+ <div class="t-groups" id="t-groups" hidden></div>
113
+ <section class="t-stage" id="t-stage"></section>
114
+ <div class="t-notes" id="t-notes" hidden></div>
115
+ <p class="t-foot">The scripts save choudoufu's own documents under <code>snapshots/</code>, and each phase is drawn from them.</p>
116
+ </main>
117
+ <script type="module">
118
+ import { initTheme, mountThemePicker, KIOSK_THEME } from "/theme.js";
119
+ import { startTerralith } from "/terralith.js";
120
+ initTheme(KIOSK_THEME);
121
+ mountThemePicker(document.getElementById("t-theme"));
122
+ startTerralith(document);
123
+ </script>
124
+ </body>
125
+ </html>