@intentius/behold 0.29.39 → 0.29.41
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 +148 -10
- package/README.md +6 -2
- package/dist/cli.js +15965 -13076
- package/example-writes/README.md +1 -1
- package/example-writes/chant.config.ts +0 -6
- package/package.json +5 -2
- package/web/app.js +327 -21
- package/web/carve-export.js +142 -0
- package/web/carve-narration.js +268 -0
- package/web/carve-narration.test.js +18 -0
- package/web/change-set-overlay.js +147 -0
- package/web/change-set-overlay.test.js +83 -0
- package/web/dots-border.js +66 -0
- package/web/dots-border.test.js +27 -0
- package/web/dots-kiosk.js +279 -0
- package/web/dots-kiosk.test.js +60 -0
- package/web/dots-layout.d.ts +10 -0
- package/web/dots-layout.js +201 -0
- package/web/dots-live.js +316 -0
- package/web/dots-live.test.js +220 -0
- package/web/dots-lod.js +122 -0
- package/web/dots-lod.test.js +78 -0
- package/web/dots-recording.d.ts +7 -0
- package/web/dots-recording.js +247 -0
- package/web/dots-recording.test.js +71 -0
- package/web/dots-scene.js +294 -0
- package/web/dots-scene.test.js +118 -0
- package/web/dots-timeline.js +128 -0
- package/web/dots-timeline.test.js +83 -0
- package/web/dots-tour.js +153 -0
- package/web/dots.js +2124 -0
- package/web/dots.test.js +15 -0
- package/web/index.html +29 -0
- package/web/kiosk-carve.js +219 -0
- package/web/kiosk-carve.test.js +26 -0
- package/web/kiosk-event-help-ui.js +6 -0
- package/web/kiosk.html +2 -1
- package/web/kiosk.js +21 -6
- package/web/operator.js +1 -1
- package/web/run-playhead.js +102 -19
- package/web/run-playhead.test.js +81 -11
- package/web/tour-player.js +204 -0
- package/web/tour-player.test.js +115 -0
- package/web/tours/behold.tour.v1.schema.json +182 -0
- package/web/tours/terralith.json +330 -0
- package/web/trunk-lane.js +254 -0
- package/web/trunk-lane.test.js +117 -0
- package/web/workspace-gates.js +29 -4
- package/web/workspace-gates.test.js +23 -2
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { LOD, bandT, smooth, cardMorph, discMorph, morphPoint, discRadius, levelOf, caption, railMarks, railPos } from "./dots-lod.js";
|
|
3
|
+
|
|
4
|
+
describe("dots level of detail (#712)", () => {
|
|
5
|
+
it("is a card at or above the card size and a dot at or below the dot size", () => {
|
|
6
|
+
expect(cardMorph(LOD.cardPx)).toBe(0);
|
|
7
|
+
expect(cardMorph(200)).toBe(0);
|
|
8
|
+
expect(cardMorph(LOD.dotPx)).toBe(1);
|
|
9
|
+
expect(cardMorph(5)).toBe(1);
|
|
10
|
+
});
|
|
11
|
+
it("morphs in between by the zoom, monotonically, with no jump at either end", () => {
|
|
12
|
+
let prev = 0;
|
|
13
|
+
for (let px = 90; px >= 24; px -= 0.5) {
|
|
14
|
+
const t = cardMorph(px);
|
|
15
|
+
expect(t).toBeGreaterThanOrEqual(prev);
|
|
16
|
+
expect(t - prev).toBeLessThan(0.05);
|
|
17
|
+
prev = t;
|
|
18
|
+
}
|
|
19
|
+
expect(cardMorph(89.9)).toBeLessThan(0.001);
|
|
20
|
+
expect(cardMorph(24.1)).toBeGreaterThan(0.999);
|
|
21
|
+
});
|
|
22
|
+
it("is a function of the size alone, so stopping halfway stays halfway and zooming back reverses it", () => {
|
|
23
|
+
const mid = Math.sqrt(90 * 24);
|
|
24
|
+
expect(cardMorph(mid)).toBeCloseTo(0.5, 5);
|
|
25
|
+
expect(cardMorph(mid)).toBe(cardMorph(mid));
|
|
26
|
+
});
|
|
27
|
+
it("switches at a threshold with no in-between under reduced motion", () => {
|
|
28
|
+
const vals = new Set();
|
|
29
|
+
for (let px = 100; px > 10; px -= 1) vals.add(cardMorph(px, { reduced: true }));
|
|
30
|
+
expect([...vals].sort()).toEqual([0, 1]);
|
|
31
|
+
expect(discMorph(LOD.discPx - 1, { reduced: true })).toBe(1);
|
|
32
|
+
expect(discMorph(LOD.discPx + 1, { reduced: true })).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
it("condenses an estate's dots into a disc below the disc size", () => {
|
|
35
|
+
expect(discMorph(LOD.discFromPx)).toBe(0);
|
|
36
|
+
expect(discMorph(LOD.discPx)).toBe(1);
|
|
37
|
+
expect(discMorph((LOD.discFromPx + LOD.discPx) / 2)).toBeGreaterThan(0);
|
|
38
|
+
});
|
|
39
|
+
it("bandT and smooth stay in [0, 1]", () => {
|
|
40
|
+
expect(bandT(0, 90, 24)).toBe(1);
|
|
41
|
+
expect(bandT(NaN, 90, 24)).toBe(1);
|
|
42
|
+
expect(smooth(-1)).toBe(0);
|
|
43
|
+
expect(smooth(2)).toBe(1);
|
|
44
|
+
});
|
|
45
|
+
it("interpolates a dot from its card through its slot to its disc", () => {
|
|
46
|
+
const card = { x: 0, y: 0 };
|
|
47
|
+
const slot = { x: 10, y: 0 };
|
|
48
|
+
const disc = { x: 10, y: 10 };
|
|
49
|
+
expect(morphPoint(card, slot, disc, 0, 0)).toEqual({ x: 0, y: 0 });
|
|
50
|
+
expect(morphPoint(card, slot, disc, 1, 0)).toEqual({ x: 10, y: 0 });
|
|
51
|
+
expect(morphPoint(card, slot, disc, 0.5, 0)).toEqual({ x: 5, y: 0 });
|
|
52
|
+
expect(morphPoint(card, slot, disc, 1, 1)).toEqual({ x: 10, y: 10 });
|
|
53
|
+
expect(morphPoint(null, slot, disc, 0, 0)).toEqual({ x: 10, y: 0 });
|
|
54
|
+
});
|
|
55
|
+
it("sizes a disc so its area is proportional to its resource count", () => {
|
|
56
|
+
const a = (n) => Math.PI * discRadius(n, 1) ** 2;
|
|
57
|
+
expect(a(400) / a(100)).toBeCloseTo(4, 6);
|
|
58
|
+
expect(discRadius(0, 1)).toBe(0);
|
|
59
|
+
});
|
|
60
|
+
it("names the level and the marks", () => {
|
|
61
|
+
expect(levelOf(0, [])).toBe("cards");
|
|
62
|
+
expect(levelOf(0.4, [0])).toBe("cards-dots");
|
|
63
|
+
expect(levelOf(1, [0, 0])).toBe("dots");
|
|
64
|
+
expect(levelOf(1, [0, 1])).toBe("dots-discs");
|
|
65
|
+
expect(levelOf(1, [1, 1])).toBe("discs");
|
|
66
|
+
expect(caption("dots")).toMatch(/each dot is a resource/);
|
|
67
|
+
expect(caption("discs")).toMatch(/each disc is an estate, sized by resources/);
|
|
68
|
+
});
|
|
69
|
+
it("orders the rail's marks and places the camera on them", () => {
|
|
70
|
+
const m = railMarks({ paneW: 1000, paneH: 800, cardW: 300, sceneW: 20000, sceneH: 8000, smallestBox: 2000, largestBox: 6000 });
|
|
71
|
+
expect(m.cards).toBeLessThan(m.resources);
|
|
72
|
+
expect(m.resources).toBeLessThan(m.estates);
|
|
73
|
+
expect(railPos(m.cards, m)).toBe(0);
|
|
74
|
+
expect(railPos(m.resources, m)).toBeCloseTo(0.5, 6);
|
|
75
|
+
expect(railPos(m.estates, m)).toBe(1);
|
|
76
|
+
expect(railPos(m.estates * 10, m)).toBe(1);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Types for src/dots-preview.ts, which reads sources with the page's own reader (#712).
|
|
2
|
+
export function readCarve(text: string): any;
|
|
3
|
+
export function ownersAt(rec: any, upto: number, parents: Map<string, string>): Map<string, string>;
|
|
4
|
+
export function carveShow(rec: any, parents: Map<string, string>): any;
|
|
5
|
+
export function walkthroughShow(model: any): any;
|
|
6
|
+
export function ownersAtTime(show: any, t: number): Map<string, string>;
|
|
7
|
+
export function phaseAt(show: any, t: number): { id: string; t: number } | null;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// The dots layer's recorded data (#712; the live driver is web/dots-live.js, #715): a carve recording (#457's JSON Lines,
|
|
2
|
+
// scripts/dot-bench/record-carve.mjs) or the terralith walkthrough's
|
|
3
|
+
// snapshots (src/terralith-demo.ts readTerralith), read into one "show":
|
|
4
|
+
//
|
|
5
|
+
// { kind, source, estates[], roster[], owners0, ownersEnd, events[], threads[], t0, t1 }
|
|
6
|
+
//
|
|
7
|
+
// Every event is a line of the recording or a fact of a snapshot. Nothing is
|
|
8
|
+
// made up: a recording's times are its own stamps; the snapshots carry one
|
|
9
|
+
// time per phase, so their events are spaced evenly inside it and the show
|
|
10
|
+
// says so (`spaced: true`). Pure: text or JSON in, plain data out.
|
|
11
|
+
|
|
12
|
+
import { recordedClock } from "./dots-timeline.js";
|
|
13
|
+
|
|
14
|
+
/** A carve recording's lines -> { header, end, roster, estates, keyframes, timeline } (after #457's recording.js). */
|
|
15
|
+
export function readCarve(text) {
|
|
16
|
+
// Each record keeps its line in the file, for a timeline mark or a dot's provenance to name it.
|
|
17
|
+
const lines = text
|
|
18
|
+
.split("\n")
|
|
19
|
+
.map((l, i) => (l.trim() ? { ...JSON.parse(l), line: i + 1 } : null))
|
|
20
|
+
.filter(Boolean);
|
|
21
|
+
const header = lines.find((l) => l.kind === "header");
|
|
22
|
+
const keyframes = lines.filter((l) => l.kind === "keyframe");
|
|
23
|
+
if (!header || !keyframes.length) throw new Error("not a carve recording: no header or no keyframe");
|
|
24
|
+
const rosterLine = lines.find((l) => l.kind === "roster");
|
|
25
|
+
const byAddress = new Map();
|
|
26
|
+
if (rosterLine) {
|
|
27
|
+
for (const i of rosterLine.instances) byAddress.set(i.address, { address: i.address, type: i.type, taggable: i.rung === "tag-governable", rung: i.rung });
|
|
28
|
+
} else {
|
|
29
|
+
for (const doc of Object.values(keyframes[0].estates)) {
|
|
30
|
+
for (const it of doc.items ?? []) if (it.address && !byAddress.has(it.address)) byAddress.set(it.address, { address: it.address, type: it.type, taggable: true });
|
|
31
|
+
for (const g of doc.gaps ?? []) if (!byAddress.has(g.address)) byAddress.set(g.address, { address: g.address, type: g.type, taggable: false });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const owners = (kf) => {
|
|
35
|
+
const o = new Map();
|
|
36
|
+
for (const [estate, doc] of Object.entries(kf.estates)) for (const it of doc.items ?? []) if (it.address) o.set(it.address, estate);
|
|
37
|
+
return o;
|
|
38
|
+
};
|
|
39
|
+
const timeline = lines
|
|
40
|
+
.filter((l) => l.kind === "move")
|
|
41
|
+
.map((m) => {
|
|
42
|
+
const end = Date.parse(m.t);
|
|
43
|
+
const seconds = Number.isFinite(m.seconds) ? m.seconds : 0;
|
|
44
|
+
return {
|
|
45
|
+
seq: m.seq,
|
|
46
|
+
t: end,
|
|
47
|
+
start: end - seconds * 1000,
|
|
48
|
+
address: m.address,
|
|
49
|
+
from: m.doc?.from?.estate ?? header.source,
|
|
50
|
+
to: m.estate,
|
|
51
|
+
ok: m.exit === 0 && !!m.doc && m.doc.written !== false,
|
|
52
|
+
refusal: m.doc?.refusal?.code ?? (m.exit !== 0 ? "exit" : undefined),
|
|
53
|
+
...(m.doc?.refusal?.summary ? { refusalSummary: m.doc.refusal.summary } : {}),
|
|
54
|
+
followers: (m.doc?.followers ?? []).map((f) => f.address),
|
|
55
|
+
line: m.line,
|
|
56
|
+
};
|
|
57
|
+
})
|
|
58
|
+
.sort((a, b) => a.seq - b.seq);
|
|
59
|
+
return {
|
|
60
|
+
header,
|
|
61
|
+
end: lines.find((l) => l.kind === "end"),
|
|
62
|
+
roster: [...byAddress.values()],
|
|
63
|
+
estates: [header.source, ...(header.destinations ?? [])],
|
|
64
|
+
keyframes: keyframes.map((k) => ({ seq: k.seq, t: Date.parse(k.t), owners: owners(k), line: k.line })),
|
|
65
|
+
timeline,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Owner of every address after `upto` moves: the nearest keyframe at or before
|
|
71
|
+
* it, then the landed moves between (each carries its followers). A child no
|
|
72
|
+
* keyframe lists takes its parent's owner.
|
|
73
|
+
*/
|
|
74
|
+
export function ownersAt(rec, upto, parents) {
|
|
75
|
+
let kf = rec.keyframes[0];
|
|
76
|
+
for (const k of rec.keyframes) if (k.seq <= upto && k.seq >= kf.seq) kf = k;
|
|
77
|
+
const owner = new Map(kf.owners);
|
|
78
|
+
for (const m of rec.timeline) {
|
|
79
|
+
if (m.seq <= kf.seq || m.seq > upto || !m.ok) continue;
|
|
80
|
+
owner.set(m.address, m.to);
|
|
81
|
+
for (const f of m.followers) owner.set(f, m.to);
|
|
82
|
+
}
|
|
83
|
+
for (const r of rec.roster) {
|
|
84
|
+
if (owner.has(r.address)) continue;
|
|
85
|
+
const p = parents.get(r.address);
|
|
86
|
+
owner.set(r.address, (p && owner.get(p)) || rec.header.source);
|
|
87
|
+
}
|
|
88
|
+
return owner;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A carve recording as a show: one `write` event per live-mv line. */
|
|
92
|
+
export function carveShow(rec, parents) {
|
|
93
|
+
const last = rec.keyframes.reduce((a, k) => (k.seq > a.seq ? k : a), rec.keyframes[0]);
|
|
94
|
+
const events = rec.timeline.map((m) => ({
|
|
95
|
+
kind: "write",
|
|
96
|
+
t: m.t,
|
|
97
|
+
start: Math.min(m.start, m.t),
|
|
98
|
+
address: m.address,
|
|
99
|
+
followers: m.followers,
|
|
100
|
+
from: m.from,
|
|
101
|
+
to: m.to,
|
|
102
|
+
ok: m.ok,
|
|
103
|
+
...(m.refusal ? { refusal: m.refusal } : {}),
|
|
104
|
+
...(m.refusalSummary ? { refusalSummary: m.refusalSummary } : {}),
|
|
105
|
+
seq: m.seq,
|
|
106
|
+
line: m.line,
|
|
107
|
+
}));
|
|
108
|
+
const t0 = Math.min(rec.keyframes[0].t, ...events.map((e) => e.start));
|
|
109
|
+
const t1 = Math.max(last.t, ...events.map((e) => e.t));
|
|
110
|
+
return {
|
|
111
|
+
kind: "carve",
|
|
112
|
+
title: rec.header.source,
|
|
113
|
+
recordedAt: Date.parse(rec.header.t) || t0,
|
|
114
|
+
source: rec.header.source,
|
|
115
|
+
estates: rec.estates,
|
|
116
|
+
roster: rec.roster,
|
|
117
|
+
owners0: ownersAt(rec, 0, parents),
|
|
118
|
+
ownersEnd: ownersAt(rec, last.seq, parents),
|
|
119
|
+
events,
|
|
120
|
+
threads: [],
|
|
121
|
+
phases: [],
|
|
122
|
+
parents,
|
|
123
|
+
t0,
|
|
124
|
+
t1,
|
|
125
|
+
spaced: false,
|
|
126
|
+
// A recording of a real event stream: its replay runs on the recording's own clock (web/dots-timeline.js).
|
|
127
|
+
timeline: recordedClock(events.flatMap((e) => [e.start, e.t]).concat(rec.keyframes.map((k) => k.t)), t0, t1),
|
|
128
|
+
records: {
|
|
129
|
+
header: { t: Date.parse(rec.header.t) || null, line: rec.header.line, source: rec.header.source || null, plan: rec.header.plan || null },
|
|
130
|
+
keyframes: rec.keyframes.map((k) => ({ t: k.t, line: k.line })),
|
|
131
|
+
end: rec.end && Date.parse(rec.end.t) ? { t: Date.parse(rec.end.t), line: rec.end.line } : null,
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The walkthrough's four phases (readTerralith's model) as a show:
|
|
138
|
+
* adopt each card live-import stamped (identity.marked) leaves a ring;
|
|
139
|
+
* split each card that moved recolours, with a comet toward its estate;
|
|
140
|
+
* plan each card a root's plan read glows dimly, a planned change
|
|
141
|
+
* brighter, and each planned output is a thread from its estate to
|
|
142
|
+
* its readers, with a pulse handed along it (wave 1 to wave 2).
|
|
143
|
+
*/
|
|
144
|
+
export function walkthroughShow(model) {
|
|
145
|
+
const phases = model.phases ?? [];
|
|
146
|
+
const stock = phases.find((p) => p.id === "stock") ?? phases[0];
|
|
147
|
+
if (!stock) throw new Error("no phases in the walkthrough's snapshots");
|
|
148
|
+
const adopt = phases.find((p) => p.id === "adopt");
|
|
149
|
+
const split = phases.find((p) => p.id === "split");
|
|
150
|
+
const plan = phases.find((p) => p.id === "plan");
|
|
151
|
+
const source = stock.boxes[0]?.id ?? "terralith";
|
|
152
|
+
const marked = new Map();
|
|
153
|
+
for (const b of adopt?.boxes ?? []) for (const c of b.cards) marked.set(c.id, !!c.identity?.marked);
|
|
154
|
+
const roster = stock.boxes
|
|
155
|
+
.flatMap((b) => b.cards)
|
|
156
|
+
.map((c) => ({ address: c.id, type: c.type, taggable: adopt ? !!marked.get(c.id) : true }));
|
|
157
|
+
const at = (p, i) => Date.parse(p?.at ?? "") || i * 10_000;
|
|
158
|
+
const times = phases.map((p, i) => at(p, i));
|
|
159
|
+
// A phase runs from its stamp to the next one's; the last gets the mean length.
|
|
160
|
+
const spanOf = (i) => (i + 1 < times.length ? times[i + 1] - times[i] : Math.max(10_000, (times.at(-1) - times[0]) / Math.max(1, times.length - 1)));
|
|
161
|
+
const iOf = (p) => phases.indexOf(p);
|
|
162
|
+
const spread = (p, items, mk) => {
|
|
163
|
+
const i = iOf(p);
|
|
164
|
+
const t = times[i];
|
|
165
|
+
const span = spanOf(i) * 0.8;
|
|
166
|
+
return items.map((it, k) => mk(it, t + (span * (k + 0.5)) / items.length, span / Math.max(1, items.length)));
|
|
167
|
+
};
|
|
168
|
+
const events = [];
|
|
169
|
+
if (adopt) {
|
|
170
|
+
const cards = adopt.boxes.flatMap((b) => b.cards).filter((c) => c.identity?.marked);
|
|
171
|
+
events.push(...spread(adopt, cards, (c, t, d) => ({ kind: "adopt", t, start: t - d * 0.6, address: c.id, source: c.identity.source })));
|
|
172
|
+
}
|
|
173
|
+
const owners0 = new Map(roster.map((r) => [r.address, source]));
|
|
174
|
+
const ownersEnd = new Map(owners0);
|
|
175
|
+
if (split) {
|
|
176
|
+
const cards = split.boxes.flatMap((b) => b.cards).filter((c) => c.moved && !c.moved.follows);
|
|
177
|
+
const followers = new Map();
|
|
178
|
+
for (const b of split.boxes) for (const c of b.cards) if (c.moved?.follows) followers.set(c.moved.follows, [...(followers.get(c.moved.follows) ?? []), c.id]);
|
|
179
|
+
events.push(
|
|
180
|
+
...spread(split, cards, (c, t, d) => ({ kind: "write", t, start: t - d * 0.6, address: c.id, followers: followers.get(c.id) ?? [], from: c.moved.from, to: c.moved.to, ok: true })),
|
|
181
|
+
);
|
|
182
|
+
for (const b of split.boxes) for (const c of b.cards) ownersEnd.set(c.id, b.estate ?? b.id);
|
|
183
|
+
}
|
|
184
|
+
const threads = [];
|
|
185
|
+
if (plan) {
|
|
186
|
+
const i = iOf(plan);
|
|
187
|
+
const t = times[i];
|
|
188
|
+
const span = spanOf(i) * 0.8;
|
|
189
|
+
for (const b of plan.boxes) {
|
|
190
|
+
const whole = !!(b.plan?.fallback || (b.plan?.cone && b.plan.cone.full && b.plan.cone.kind !== "empty-cone"));
|
|
191
|
+
for (const c of b.cards) {
|
|
192
|
+
if (c.planned) events.push({ kind: "planned", t: t + span * 0.55, start: t + span * 0.3, address: c.id, actions: c.planned.actions });
|
|
193
|
+
if (whole || c.inCone || c.planned) events.push({ kind: "read", t: t + span * 0.5, start: t + span * 0.25, address: c.id, root: b.id });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
for (const o of plan.plan?.outputs ?? []) {
|
|
197
|
+
for (const r of o.readers) {
|
|
198
|
+
threads.push({ from: o.estate, to: r, name: o.name, known: o.known });
|
|
199
|
+
events.push({ kind: "handoff", t: t + span * 0.35, start: t + span * 0.1, from: o.estate, to: r, name: o.name });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
events.sort((a, b) => a.start - b.start);
|
|
204
|
+
const estates = [source, ...new Set([...ownersEnd.values()].filter((e) => e !== source))];
|
|
205
|
+
return {
|
|
206
|
+
kind: "walkthrough",
|
|
207
|
+
title: `${source} walkthrough`,
|
|
208
|
+
recordedAt: times[0],
|
|
209
|
+
source,
|
|
210
|
+
estates,
|
|
211
|
+
roster,
|
|
212
|
+
owners0,
|
|
213
|
+
ownersEnd,
|
|
214
|
+
events,
|
|
215
|
+
threads,
|
|
216
|
+
parents: new Map(),
|
|
217
|
+
phases: phases.map((p, k) => ({ id: p.id, t: times[k] })),
|
|
218
|
+
t0: times[0],
|
|
219
|
+
t1: times[times.length - 1] + spanOf(times.length - 1),
|
|
220
|
+
spaced: true,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Owners at show time `t`: every landed write that has finished by then. */
|
|
225
|
+
export function ownersAtTime(show, t) {
|
|
226
|
+
const o = new Map(show.owners0);
|
|
227
|
+
const touched = new Set();
|
|
228
|
+
for (const e of show.events) {
|
|
229
|
+
if (e.kind !== "write" || !e.ok || e.t > t) continue;
|
|
230
|
+
o.set(e.address, e.to);
|
|
231
|
+
touched.add(e.address);
|
|
232
|
+
for (const f of e.followers ?? []) {
|
|
233
|
+
o.set(f, e.to);
|
|
234
|
+
touched.add(f);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// A child no follower record names goes where its parent went.
|
|
238
|
+
for (const [child, parent] of show.parents ?? []) if (!touched.has(child) && touched.has(parent)) o.set(child, o.get(parent));
|
|
239
|
+
return o;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The phase a show is in at `t` (walkthrough only), or null. */
|
|
243
|
+
export function phaseAt(show, t) {
|
|
244
|
+
let at = null;
|
|
245
|
+
for (const p of show.phases) if (p.t <= t) at = p;
|
|
246
|
+
return at;
|
|
247
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { gunzipSync } from "node:zlib";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { readCarve, ownersAt, carveShow, walkthroughShow, ownersAtTime, phaseAt } from "./dots-recording.js";
|
|
6
|
+
import { parentsOf } from "./dots-layout.js";
|
|
7
|
+
|
|
8
|
+
// #457's committed recording of the terralith-14 carve, and the walkthrough's
|
|
9
|
+
// snapshots as src/terralith-demo.ts reads them (src/dots-preview.test.ts
|
|
10
|
+
// checks the server hands the page the same model).
|
|
11
|
+
const text = gunzipSync(readFileSync(fileURLToPath(new URL("../scripts/dot-bench/carve-terralith-14.jsonl.gz", import.meta.url)))).toString("utf8");
|
|
12
|
+
|
|
13
|
+
describe("the carve recording reader (#712)", () => {
|
|
14
|
+
const rec = readCarve(text);
|
|
15
|
+
it("reads the roster, the keyframes and every move", () => {
|
|
16
|
+
expect(rec.roster).toHaveLength(1041);
|
|
17
|
+
expect(rec.roster.filter((r) => r.taggable)).toHaveLength(467);
|
|
18
|
+
expect(rec.keyframes.map((k) => k.seq)).toEqual([0, 100, 200, 300, 400, 463]);
|
|
19
|
+
expect(rec.timeline).toHaveLength(463);
|
|
20
|
+
expect(rec.timeline.filter((m) => !m.ok)).toHaveLength(14);
|
|
21
|
+
expect(rec.estates).toHaveLength(9);
|
|
22
|
+
expect(rec.timeline.every((m) => m.start <= m.t)).toBe(true);
|
|
23
|
+
expect(rec.timeline.find((m) => !m.ok).refusal).toBe("plan_changes_more_than_tags");
|
|
24
|
+
});
|
|
25
|
+
it("refuses a file that is not a recording", () => {
|
|
26
|
+
expect(() => readCarve('{"kind":"move"}\n')).toThrow(/not a carve recording/);
|
|
27
|
+
});
|
|
28
|
+
it("starts with every resource in the source and ends in the last keyframe's owners", () => {
|
|
29
|
+
const parents = parentsOf(rec.roster);
|
|
30
|
+
const start = ownersAt(rec, 0, parents);
|
|
31
|
+
expect(new Set(start.values())).toEqual(new Set([rec.header.source]));
|
|
32
|
+
const end = ownersAt(rec, 463, parents);
|
|
33
|
+
expect(new Set(end.values()).size).toBe(9);
|
|
34
|
+
});
|
|
35
|
+
it("replays its moves to the account's own answer at the end", () => {
|
|
36
|
+
const parents = parentsOf(rec.roster);
|
|
37
|
+
const show = carveShow(rec, parents);
|
|
38
|
+
const replayed = ownersAtTime(show, Infinity);
|
|
39
|
+
const differ = rec.roster.filter((r) => replayed.get(r.address) !== show.ownersEnd.get(r.address));
|
|
40
|
+
expect(differ).toEqual([]);
|
|
41
|
+
expect(show.events.filter((e) => e.kind === "write")).toHaveLength(463);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("the walkthrough reader (#712)", async () => {
|
|
46
|
+
const { readTerralith } = await import("../src/terralith-demo.ts");
|
|
47
|
+
const model = readTerralith(fileURLToPath(new URL("../src/__fixtures__/terralith", import.meta.url)));
|
|
48
|
+
const show = walkthroughShow(model);
|
|
49
|
+
it("takes the roster from the stock phase and its events from the snapshots", () => {
|
|
50
|
+
expect(show.roster).toHaveLength(23);
|
|
51
|
+
expect(show.events.filter((e) => e.kind === "adopt")).toHaveLength(17);
|
|
52
|
+
expect(show.events.filter((e) => e.kind === "write")).toHaveLength(15);
|
|
53
|
+
expect(show.events.filter((e) => e.kind === "planned")).toHaveLength(3);
|
|
54
|
+
expect(show.threads).toEqual([
|
|
55
|
+
{ from: "terralith", to: "team-a", name: "log_retention_days", known: true },
|
|
56
|
+
{ from: "terralith", to: "team-b", name: "log_retention_days", known: true },
|
|
57
|
+
{ from: "terralith", to: "team-c", name: "log_retention_days", known: true },
|
|
58
|
+
]);
|
|
59
|
+
expect(show.spaced).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
it("ends with the split's owners, followers included", () => {
|
|
62
|
+
const end = ownersAtTime(show, Infinity);
|
|
63
|
+
expect(end.get("aws_iam_role_policy.team_a_inline")).toBe("team-a");
|
|
64
|
+
expect(end.get("aws_vpc.main")).toBe("terralith");
|
|
65
|
+
for (const r of show.roster) expect(end.get(r.address)).toBe(show.ownersEnd.get(r.address));
|
|
66
|
+
});
|
|
67
|
+
it("knows its phase at a time", () => {
|
|
68
|
+
expect(phaseAt(show, show.t0).id).toBe("stock");
|
|
69
|
+
expect(phaseAt(show, show.t1).id).toBe("plan");
|
|
70
|
+
});
|
|
71
|
+
});
|