@intentius/behold 0.30.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +475 -16
- package/README.md +25 -19
- package/demos.json +14 -9
- package/dist/cli.js +54900 -26771
- package/example-carve/README.md +19 -23
- package/example-carve/app/package.json +1 -1
- package/example-carve/app/src/carved.ts +3 -3
- package/example-carve/carve-report.json +1 -1
- package/example-carve/{legacy-tf → tf-root}/terraform.tfstate +1 -1
- package/example-choudoufu-estate/README.md +7 -0
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-choudoufu-estate/scripts/choudoufu-down.sh +2 -1
- package/example-choudoufu-estate/scripts/choudoufu-up.sh +10 -3
- package/example-terraform-estate/README.md +32 -5
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/recorded/adoption/platform.json +72 -0
- package/example-terraform-estate/recorded/adoption/prod.json +224 -0
- package/example-terralith/README.md +1 -1
- package/example-three-cloud/README.md +111 -18
- package/example-three-cloud/aws/Pulumi.yaml +15 -0
- package/example-three-cloud/aws/index.ts +174 -0
- package/example-three-cloud/aws/package-lock.json +2725 -0
- package/example-three-cloud/aws/package.json +14 -0
- package/example-three-cloud/aws/tsconfig.json +17 -0
- package/example-three-cloud/azure/main.tf +48 -0
- package/example-three-cloud/azure/site.tf +104 -0
- package/example-three-cloud/chant.config.json +9 -0
- package/example-three-cloud/chant.workspace.json +30 -4
- package/example-three-cloud/dns/chant.config.ts +26 -1
- package/example-three-cloud/dns/src/records.component.ts +32 -6
- package/example-three-cloud/package-lock.json +48 -27
- package/example-three-cloud/package.json +8 -6
- package/example-three-cloud/scripts/emulators-up.sh +28 -1
- package/example-three-cloud/scripts/front-door.ts +679 -86
- package/package.json +13 -6
- package/web/adopt-pulumi.js +114 -0
- package/web/adopt-pulumi.test.js +28 -0
- package/web/adopt.js +203 -0
- package/web/adopt.test.js +27 -0
- package/web/app.js +614 -19
- package/web/carve-steps.js +1 -1
- package/web/carve-steps.test.js +2 -2
- package/web/change-set-overlay.js +12 -5
- package/web/change-set-overlay.test.js +22 -0
- package/web/drift-stream.js +241 -0
- package/web/drift-stream.test.js +146 -0
- package/web/edge-weight.d.ts +1 -1
- package/web/edge-weight.js +5 -1
- package/web/edge-weight.test.js +19 -0
- package/web/embed.js +2 -2
- package/web/event-help-modal.js +18 -12
- package/web/event-help-modal.test.js +28 -1
- package/web/graph-query.js +180 -0
- package/web/graph-query.test.js +49 -0
- package/web/graph.html +107 -0
- package/web/index-diff.js +109 -0
- package/web/index-diff.test.js +39 -0
- package/web/index.html +55 -0
- package/web/kiosk-ask-layout.js +85 -0
- package/web/kiosk-ask-layout.test.js +83 -0
- package/web/kiosk-ask-tips.js +477 -0
- package/web/kiosk-ask-tips.test.js +372 -0
- package/web/kiosk-ask.js +774 -0
- package/web/kiosk-ask.test.js +593 -0
- package/web/kiosk-banner.js +108 -0
- package/web/kiosk-banner.test.js +72 -0
- package/web/kiosk-center-cards.test.js +110 -0
- package/web/kiosk-estate-scene.js +267 -0
- package/web/kiosk-estate-scene.test.js +21 -0
- package/web/kiosk-event-help.js +4 -1
- package/web/kiosk-graph-pane.js +63 -0
- package/web/kiosk-graph-pane.test.js +105 -0
- package/web/kiosk-light-frame.js +197 -0
- package/web/kiosk-light.js +547 -0
- package/web/kiosk-light.test.js +297 -0
- package/web/kiosk-member-kind.test.js +140 -0
- package/web/kiosk-metrics.js +7 -4
- package/web/kiosk-modal-sticky.test.js +2 -1
- package/web/kiosk-popover.js +4 -1
- package/web/kiosk-refit.test.js +81 -0
- package/web/kiosk-reset.js +49 -0
- package/web/kiosk-reset.test.js +11 -0
- package/web/kiosk-shot.js +40 -2
- package/web/kiosk-shot.test.js +23 -1
- package/web/kiosk-side.js +296 -0
- package/web/kiosk-side.test.js +249 -0
- package/web/kiosk-vendor.js +85 -7
- package/web/kiosk-vendor.test.js +9 -9
- package/web/kiosk-watch.js +20 -4
- package/web/kiosk-watch.test.js +15 -1
- package/web/kiosk.html +153 -1
- package/web/kiosk.js +252 -27
- package/web/kiosk.test.js +25 -1
- package/web/member-kind.js +31 -0
- package/web/small-stage.test.js +4 -0
- package/web/template-apps.js +245 -0
- package/web/template-apps.test.js +252 -0
- package/web/templates.js +285 -0
- package/web/templates.test.js +155 -0
- package/web/terragucci-change.js +30 -13
- package/web/terragucci-lifecycle.js +112 -62
- package/web/terragucci-lifecycle.test.js +29 -1
- package/web/terragucci-timeline.js +39 -2
- package/web/terragucci-timeline.test.js +42 -1
- package/web/tool-mark.js +4 -4
- package/web/tool-mark.test.js +1 -1
- package/web/vendors/atmos.svg +1 -0
- package/web/vendors/chant.svg +1 -0
- package/web/vendors/choudoufu.svg +1 -0
- package/web/vendors/terragrunt.svg +9 -0
- package/web/vendors/terragucci.svg +1 -0
- package/example-three-cloud/aws/chant.config.ts +0 -8
- package/example-three-cloud/aws/site.component.ts +0 -13
- package/example-three-cloud/aws/src/site.ts +0 -27
- package/example-three-cloud/azure/chant.config.ts +0 -1
- package/example-three-cloud/azure/src/site.component.ts +0 -13
- package/example-three-cloud/azure/src/site.ts +0 -18
- package/web/vendors/choudoufu-128.png +0 -0
- package/web/vendors/choudoufu-64.png +0 -0
- /package/example-carve/{legacy-tf → tf-root}/cdn.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/compute.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/floci-override.tf.disabled +0 -0
- /package/example-carve/{legacy-tf → tf-root}/modules/cdn/main.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/naming.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/network.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/observability.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/outputs.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/storage.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/versions.tf +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { badgeWords, bare, cardTitle, dependentsOf, lightMessage, planOf, producerOf, selectLight, slotState, startKioskLight, stateFile, stateMarks, unknownSlots } from "./kiosk-light.js";
|
|
5
|
+
|
|
6
|
+
// The three-root estate of behold#937 (src/__fixtures__/terragucci-demo-ask): network creates a subnet,
|
|
7
|
+
// app puts four resources in it, edge reads an address of app's. The answer is built the way the
|
|
8
|
+
// overlay builds /api/terragucci from the report: one card per changed resource, a mark on each.
|
|
9
|
+
const FIX = join(import.meta.dirname, "..", "src", "__fixtures__", "terragucci-demo-ask");
|
|
10
|
+
const read = (f) => JSON.parse(readFileSync(join(FIX, f), "utf8"));
|
|
11
|
+
const report = read("report-pull-request.json");
|
|
12
|
+
|
|
13
|
+
function answerOf(r) {
|
|
14
|
+
const roots = r.roots.map((x) => ({ member: "demo", name: x.path, path: x.path }));
|
|
15
|
+
const cards = {};
|
|
16
|
+
for (const root of r.roots) {
|
|
17
|
+
for (const c of root.changes) {
|
|
18
|
+
cards[`demo/${root.path}/${c.address}`] = [{ verdict: "plan", action: c.action, addresses: [c.address], values: (c.attributes || []).map((a) => ({ ...a, address: c.address })) }];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const reads = r.roots.flatMap((x) => (x.reads || []).map((rd) => ({ ...rd, root: x.path })));
|
|
22
|
+
return { roots, cards, unmatched: { roots: [], changes: [] }, pull_request: { roots: r.roots.map((x) => x.path), reads, blast: r.blast, waves: r.waves } };
|
|
23
|
+
}
|
|
24
|
+
const answer = answerOf(report);
|
|
25
|
+
const progressOf = (run) => ({ states: run.waves.map((w) => ({ number: w.number, state: w.state, roots: w.roots, composed: w.composed })), reads: run.roots.map((x) => ({ root: x.root, wave: x.wave, reads: x.reads, stateKey: x.state && x.state.key })) });
|
|
26
|
+
|
|
27
|
+
describe("which resources a step lights (behold#937)", () => {
|
|
28
|
+
const plan = planOf(answer);
|
|
29
|
+
|
|
30
|
+
it("reads the changed resources as <root>/<address>, with the card each is", () => {
|
|
31
|
+
expect([...plan.resources.keys()].sort()).toEqual(["app/terraform_data.queue", "app/terraform_data.schedule", "app/terraform_data.service", "app/terraform_data.worker", "edge/terraform_data.route", "network/terraform_data.subnet"]);
|
|
32
|
+
expect(plan.resources.get("network/terraform_data.subnet")).toMatchObject({ cardId: "demo/network/terraform_data.subnet", name: "subnet", type: "terraform_data", action: "create" });
|
|
33
|
+
expect(plan.edges).toEqual([{ from: "network", to: "app" }, { from: "app", to: "edge" }]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("lights the named nodes alone when the step has no paths", () => {
|
|
37
|
+
const sel = selectLight(plan, { light: ["network/terraform_data.subnet"] });
|
|
38
|
+
expect(sel).toMatchObject({ seeds: ["network/terraform_data.subnet"], dependents: 0, cardIds: ["demo/network/terraform_data.subnet"], roots: ["network"] });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("follows the reads and the blast radius downstream with paths, and counts what depends on the seed", () => {
|
|
42
|
+
const sel = selectLight(plan, { light: ["network/terraform_data.subnet"], paths: true });
|
|
43
|
+
expect(sel.dependents).toBe(5);
|
|
44
|
+
expect(sel.lit.sort()).toEqual([...plan.resources.keys()].sort());
|
|
45
|
+
expect(sel.cardIds).toHaveLength(6);
|
|
46
|
+
expect(sel.roots.sort()).toEqual(["app", "edge", "network"]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("lights only what is downstream of a seed in the middle", () => {
|
|
50
|
+
const sel = selectLight(plan, { light: ["app/terraform_data.service"], paths: true });
|
|
51
|
+
expect(sel.roots.sort()).toEqual(["app", "edge"]);
|
|
52
|
+
expect(sel.lit).toContain("edge/terraform_data.route");
|
|
53
|
+
expect(sel.lit).not.toContain("network/terraform_data.subnet");
|
|
54
|
+
expect(selectLight(plan, { light: ["edge/terraform_data.route"], paths: true }).dependents).toBe(0);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("skips an address that matches nothing, never an error, and lights nothing when none match", () => {
|
|
58
|
+
const sel = selectLight(plan, { light: ["network/terraform_data.nope", "network/terraform_data.subnet"] });
|
|
59
|
+
expect(sel.skipped).toEqual(["network/terraform_data.nope"]);
|
|
60
|
+
expect(sel.seeds).toEqual(["network/terraform_data.subnet"]);
|
|
61
|
+
expect(selectLight(plan, { light: ["network/terraform_data.nope"], paths: true })).toBeNull();
|
|
62
|
+
expect(selectLight(plan, { prompt: "x" })).toBeNull();
|
|
63
|
+
expect(selectLight(plan, null)).toBeNull();
|
|
64
|
+
expect(selectLight(planOf(null), { light: ["a/b"] })).toBeNull();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("matches an address with or without its instance key", () => {
|
|
68
|
+
const withKey = planOf({ ...answer, cards: { ...answer.cards, "demo/app/terraform_data.service": [{ verdict: "plan", action: "create", addresses: ['terraform_data.service["a"]'], values: [] }] } });
|
|
69
|
+
expect(selectLight(withKey, { light: ["app/terraform_data.service"] }).seeds).toEqual(['app/terraform_data.service["a"]']);
|
|
70
|
+
expect(bare('x.y["a.b"]')).toBe("x.y");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("gives {dependents} only for a step with paths", () => {
|
|
74
|
+
expect(dependentsOf(answer, null, { light: ["network/terraform_data.subnet"], paths: true })).toBe(5);
|
|
75
|
+
expect(dependentsOf(answer, null, { light: ["network/terraform_data.subnet"], paths: true, reply: "x" })).toBe(5);
|
|
76
|
+
expect(dependentsOf(answer, null, { light: ["network/terraform_data.subnet"] })).toBeNull();
|
|
77
|
+
expect(dependentsOf(answer, null, { light: ["nope/x"], paths: true })).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("counts a change that has no card yet (a resource the checkout does not declare)", () => {
|
|
81
|
+
const a = { ...answer, cards: {}, unmatched: { roots: [], changes: [{ root: "network", address: "terraform_data.subnet", action: "create", verdict: "plan" }, { root: "app", address: "terraform_data.service", action: "create", verdict: "plan" }, { root: "app", address: "terraform_data.old", action: "update", verdict: "drift" }] } };
|
|
82
|
+
const sel = selectLight(planOf(a), { light: ["network/terraform_data.subnet"], paths: true });
|
|
83
|
+
expect(sel).toMatchObject({ dependents: 1, cardIds: [] });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("names a card by its resource first and its type second", () => {
|
|
87
|
+
expect(cardTitle("terraform_data.subnet")).toEqual({ name: "subnet", type: "terraform_data" });
|
|
88
|
+
expect(cardTitle('module.m.aws_s3_bucket.logs["eu"]')).toEqual({ name: 'logs["eu"]', type: "aws_s3_bucket" });
|
|
89
|
+
expect(cardTitle("data.terraform_remote_state.network")).toEqual({ name: "network", type: "terraform_remote_state" });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("the pane's events (behold#936 and behold#937)", () => {
|
|
94
|
+
const fake = () => {
|
|
95
|
+
const t = new EventTarget();
|
|
96
|
+
t.sent = [];
|
|
97
|
+
return t;
|
|
98
|
+
};
|
|
99
|
+
const ev = (type, ask) => new CustomEvent(type, { detail: { ask, step: "planned", scenario: "compose-create" } });
|
|
100
|
+
|
|
101
|
+
it("sets the tokens at ask-start, lights at ask-done and clears at ask-clear", () => {
|
|
102
|
+
const win = fake();
|
|
103
|
+
const sent = [];
|
|
104
|
+
startKioskLight({ post: (m) => sent.push(m), getAnswer: () => answer, getProgress: () => null, win });
|
|
105
|
+
const ask = { prompt: "Show me", light: ["network/terraform_data.subnet"], paths: true, ghost: false };
|
|
106
|
+
win.dispatchEvent(ev("behold:ask-start", ask));
|
|
107
|
+
expect(win.beholdAskTokens).toEqual({ dependents: 5 });
|
|
108
|
+
expect(sent).toEqual([{ type: "behold:hold" }]); // the graph holds still until the reply is done
|
|
109
|
+
sent.length = 0;
|
|
110
|
+
win.dispatchEvent(ev("behold:ask-done", ask));
|
|
111
|
+
expect(sent).toHaveLength(1);
|
|
112
|
+
expect(sent[0]).toMatchObject({ type: "behold:light", labels: true, lit: true, ghost: false });
|
|
113
|
+
expect(sent[0].ids).toHaveLength(6);
|
|
114
|
+
win.dispatchEvent(ev("behold:ask-clear", null));
|
|
115
|
+
expect(sent[1]).toMatchObject({ lit: false, ids: [], ghost: false });
|
|
116
|
+
expect(win.beholdAskTokens).toEqual({});
|
|
117
|
+
expect(sent[1].token).not.toBe(sent[0].token);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("lights at ask-light, as the reply starts, and does not light the same beat again at ask-done", () => {
|
|
121
|
+
const win = fake();
|
|
122
|
+
const sent = [];
|
|
123
|
+
startKioskLight({ post: (m) => sent.push(m), getAnswer: () => answer, getProgress: () => null, win });
|
|
124
|
+
const ask = { prompt: "Show me", light: ["network/terraform_data.subnet"], paths: true, ghost: false };
|
|
125
|
+
win.dispatchEvent(ev("behold:ask-start", ask));
|
|
126
|
+
sent.length = 0;
|
|
127
|
+
win.dispatchEvent(ev("behold:ask-light", ask));
|
|
128
|
+
expect(sent).toHaveLength(1);
|
|
129
|
+
expect(sent[0]).toMatchObject({ type: "behold:light", lit: true });
|
|
130
|
+
win.dispatchEvent(ev("behold:ask-done", ask));
|
|
131
|
+
expect(sent).toHaveLength(1);
|
|
132
|
+
// A beat whose light never came is still lit when its reply is done.
|
|
133
|
+
const other = { prompt: "And?", light: ["network/terraform_data.subnet"] };
|
|
134
|
+
win.dispatchEvent(ev("behold:ask-done", other));
|
|
135
|
+
expect(sent).toHaveLength(2);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("holds the graph when a step begins, so a status-only step lets nothing through (turns)", () => {
|
|
139
|
+
const win = fake();
|
|
140
|
+
const sent = [];
|
|
141
|
+
startKioskLight({ post: (m) => sent.push(m), getAnswer: () => answer, getProgress: () => null, win });
|
|
142
|
+
win.dispatchEvent(ev("behold:ask-hold", null));
|
|
143
|
+
expect(sent).toEqual([{ type: "behold:hold" }]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("clears the lighting on a beat without light, and passes the ghost through", () => {
|
|
147
|
+
const win = fake();
|
|
148
|
+
const sent = [];
|
|
149
|
+
startKioskLight({ post: (m) => sent.push(m), getAnswer: () => answer, getProgress: () => null, win });
|
|
150
|
+
win.dispatchEvent(ev("behold:ask-done", { prompt: "Now", ghost: true }));
|
|
151
|
+
expect(sent[0]).toMatchObject({ lit: false, ghost: true });
|
|
152
|
+
win.dispatchEvent(ev("behold:ask-start", { prompt: "Now" }));
|
|
153
|
+
expect(win.beholdAskTokens).toEqual({});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("lights the moment its reads are in: asks again soon rather than waiting for a poll (behold#940)", () => {
|
|
157
|
+
const win = fake();
|
|
158
|
+
const timers = [];
|
|
159
|
+
win.setTimeout = (fn, ms) => timers.push({ fn, ms });
|
|
160
|
+
const sent = [];
|
|
161
|
+
let held = { roots: answer.roots, cards: {}, unmatched: { roots: [], changes: [] } };
|
|
162
|
+
startKioskLight({ post: (m) => sent.push(m), getAnswer: () => held, getProgress: () => null, win });
|
|
163
|
+
win.dispatchEvent(ev("behold:ask-done", { light: ["network/terraform_data.subnet"], paths: true }));
|
|
164
|
+
expect(sent).toHaveLength(1);
|
|
165
|
+
expect(sent[0]).toMatchObject({ lit: false });
|
|
166
|
+
expect(timers).toHaveLength(1);
|
|
167
|
+
// The reads arrive; the next look lights, and stops looking.
|
|
168
|
+
held = answer;
|
|
169
|
+
timers.shift().fn();
|
|
170
|
+
expect(sent).toHaveLength(2);
|
|
171
|
+
expect(sent[1]).toMatchObject({ lit: true });
|
|
172
|
+
expect(sent[1].token).not.toBe(sent[0].token);
|
|
173
|
+
expect(timers).toHaveLength(0);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("stops looking when a newer beat has come (behold#940)", () => {
|
|
177
|
+
const win = fake();
|
|
178
|
+
const timers = [];
|
|
179
|
+
win.setTimeout = (fn, ms) => timers.push({ fn, ms });
|
|
180
|
+
const sent = [];
|
|
181
|
+
startKioskLight({ post: (m) => sent.push(m), getAnswer: () => ({ roots: answer.roots, cards: {}, unmatched: { roots: [], changes: [] } }), getProgress: () => null, win });
|
|
182
|
+
win.dispatchEvent(ev("behold:ask-done", { light: ["network/terraform_data.subnet"] }));
|
|
183
|
+
win.dispatchEvent(ev("behold:ask-clear", null));
|
|
184
|
+
const before = sent.length;
|
|
185
|
+
timers.shift().fn();
|
|
186
|
+
expect(sent).toHaveLength(before);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("tells a frame that reloaded the last message when it has drawn", () => {
|
|
190
|
+
const win = fake();
|
|
191
|
+
const sent = [];
|
|
192
|
+
startKioskLight({ post: (m) => sent.push(m), getAnswer: () => answer, getProgress: () => null, win });
|
|
193
|
+
win.dispatchEvent(new MessageEvent("message", { data: { type: "behold:drawn" } }));
|
|
194
|
+
expect(sent).toEqual([]);
|
|
195
|
+
win.dispatchEvent(ev("behold:ask-done", { light: ["network/terraform_data.subnet"] }));
|
|
196
|
+
win.dispatchEvent(new MessageEvent("message", { data: { type: "behold:drawn" } }));
|
|
197
|
+
expect(sent).toHaveLength(2);
|
|
198
|
+
expect(lightMessage(null, null, 3)).toMatchObject({ lit: false, ids: [], roots: [] });
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("each state's file, written mark and look (behold#937)", () => {
|
|
203
|
+
it("names a state by its backend key from run.json, else from the root's path", () => {
|
|
204
|
+
const p = progressOf(read("run-applied.json"));
|
|
205
|
+
expect(stateFile("network", p)).toEqual({ file: "network/terraform.tfstate", from: "run" });
|
|
206
|
+
expect(stateFile("network", null)).toEqual({ file: "network.tfstate", from: "path" });
|
|
207
|
+
expect(stateFile("envs/prod/app", { reads: [] })).toEqual({ file: "app.tfstate", from: "path" });
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("marks every state written and applied when the run applied", () => {
|
|
211
|
+
const m = stateMarks(answer, progressOf(read("run-applied.json")));
|
|
212
|
+
for (const root of ["network", "app", "edge"]) expect(m[root]).toMatchObject({ written: true, look: "applied" });
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("gives a failed composed run three looks: applied, partly applied, not applied", () => {
|
|
216
|
+
const m = stateMarks(answer, progressOf(read("run-failed.json")));
|
|
217
|
+
expect(m.network).toMatchObject({ look: "applied", written: true });
|
|
218
|
+
expect(m.app).toMatchObject({ look: "partial", written: true });
|
|
219
|
+
expect(m.edge).toMatchObject({ look: "not-applied", written: false });
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("shows no look and no mark while the apply has not ended or has not started", () => {
|
|
223
|
+
for (const f of ["run-applying.json", "run-waiting.json"]) {
|
|
224
|
+
const m = stateMarks(answer, progressOf(read(f)));
|
|
225
|
+
for (const root of ["network", "app", "edge"]) expect(m[root]).toMatchObject({ look: null, written: false });
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("labels the states from the path before any run exists", () => {
|
|
230
|
+
const m = stateMarks(answer, null);
|
|
231
|
+
expect(m.app).toMatchObject({ file: "app.tfstate", from: "path", written: false, look: null });
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe("the unknown slot and its filling (behold#937)", () => {
|
|
236
|
+
const plan = planOf(answer);
|
|
237
|
+
|
|
238
|
+
it("marks app's inputs as not known until the subnet exists", () => {
|
|
239
|
+
const slots = unknownSlots(plan);
|
|
240
|
+
const app = slots.filter((s) => s.root === "app");
|
|
241
|
+
expect(app.map((s) => s.address).sort()).toEqual(["terraform_data.queue", "terraform_data.schedule", "terraform_data.service", "terraform_data.worker"]);
|
|
242
|
+
for (const s of app) expect(s).toMatchObject({ path: "input", producer: "network/terraform_data.subnet", text: "not known until subnet exists" });
|
|
243
|
+
// The subnet's own id is a slot it fills itself; a known before and after (edge's route) is no slot.
|
|
244
|
+
expect(slots.find((s) => s.root === "network")).toMatchObject({ path: "output", producer: "network/terraform_data.subnet" });
|
|
245
|
+
expect(slots.some((s) => s.root === "edge")).toBe(false);
|
|
246
|
+
expect(producerOf(plan, plan.resources.get("network/terraform_data.subnet")).key).toBe("network/terraform_data.subnet");
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("falls back to the created resource of the root it reads when the report has no blast radius", () => {
|
|
250
|
+
const a = { ...answer, pull_request: { ...answer.pull_request, blast: undefined } };
|
|
251
|
+
const p = planOf(a);
|
|
252
|
+
expect(unknownSlots(p).find((s) => s.address === "terraform_data.worker").producer).toBe("network/terraform_data.subnet");
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("is empty until the producer's root has applied, then filled with no value when only run.json says so", () => {
|
|
256
|
+
const slot = unknownSlots(plan).find((s) => s.root === "app");
|
|
257
|
+
expect(slotState(slot, answer, progressOf(read("run-waiting.json")))).toEqual({ filled: false });
|
|
258
|
+
expect(slotState(slot, answer, progressOf(read("run-applying.json")))).toEqual({ filled: false });
|
|
259
|
+
expect(slotState(slot, answer, progressOf(read("run-applied.json")))).toEqual({ filled: true });
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("shows the applied value when an apply-time report states one", () => {
|
|
263
|
+
const slot = unknownSlots(plan).find((s) => s.address === "terraform_data.service");
|
|
264
|
+
const a = { ...answer, applied: { [slot.cardId]: { values: [{ path: "input", after: "subnet-0a1b", address: slot.address }], run: {} } } };
|
|
265
|
+
expect(slotState(slot, a, progressOf(read("run-applied.json")))).toEqual({ filled: true, value: "subnet-0a1b" });
|
|
266
|
+
expect(slotState(slot, a, progressOf(read("run-applying.json")))).toEqual({ filled: false });
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("finds no applied value in the fixtures' run.json or apply report (recorded on behold#937)", () => {
|
|
270
|
+
const run = read("run-applied.json");
|
|
271
|
+
expect(JSON.stringify(run)).not.toMatch(/"(after|value|values|outputs)"/);
|
|
272
|
+
const apply = read("../terragucci-demo-composed/report-apply-wave-1-failed.json");
|
|
273
|
+
for (const r of apply.roots) for (const c of r.changes) for (const at of c.attributes || []) if (at.unknown === true) expect(at).not.toHaveProperty("after");
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe("ask mode's badge and a producer's own value (behold#940)", () => {
|
|
278
|
+
const composed = { state: "planned", words: "wave 1 \u00b7 planned, composed" };
|
|
279
|
+
const done = { states: [{ number: 1, state: "applied", roots: ["network"], composed: { members: [{ root: "network", apply: "applied", state: "written" }] } }], reads: [] };
|
|
280
|
+
|
|
281
|
+
it("says planned together, then applied together, with no wave in it", () => {
|
|
282
|
+
expect(badgeWords(composed, "network", null)).toBe("planned together");
|
|
283
|
+
// The badge follows the root's outcome even where the wave's own state still reads planned.
|
|
284
|
+
expect(badgeWords(composed, "network", done)).toBe("applied together");
|
|
285
|
+
expect(badgeWords({ state: "applied", words: "wave 1 \u00b7 applied, composed" }, "app", null)).toBe("applied together");
|
|
286
|
+
expect(badgeWords({ state: "planned", words: "wave 2 \u00b7 planned" }, "app", null)).toBe("planned");
|
|
287
|
+
expect(badgeWords({ state: "unchanged", words: "wave 1 \u00b7 unchanged" }, "app", null)).toBe("unchanged");
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("shows the subnet's own id when the exact attribute is not stated, and nothing invented for another card", () => {
|
|
291
|
+
const own = { key: "network/terraform_data.subnet", cardId: "c", path: "output", producer: "network/terraform_data.subnet", producerRoot: "network" };
|
|
292
|
+
const a = { applied: { c: { values: [{ address: "x", path: "id", after: "subnet-0a1b2c" }] } } };
|
|
293
|
+
expect(slotState(own, a, done)).toEqual({ filled: true, value: "subnet-0a1b2c", path: "id" });
|
|
294
|
+
const other = { ...own, key: "app/terraform_data.service", producer: "network/terraform_data.subnet" };
|
|
295
|
+
expect(slotState(other, a, done)).toEqual({ filled: true });
|
|
296
|
+
});
|
|
297
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { composedReportOf, composedView } from "../src/chant-compose.ts";
|
|
5
|
+
import { drawScene, sceneModel } from "./kiosk-estate-scene.js";
|
|
6
|
+
import { readingRows } from "./kiosk.js";
|
|
7
|
+
import { planOf } from "./kiosk-light.js";
|
|
8
|
+
import { HOLE_WORDS, KIND_ROWS, KIND_TAGS, memberKinds } from "./member-kind.js";
|
|
9
|
+
|
|
10
|
+
// behold#1008: a composed chant run draws a hole member's box and a previewed member's box differently, and the
|
|
11
|
+
// kiosk's "How to read this" says what each mark means. The run is behold#969's create plan
|
|
12
|
+
// (src/__fixtures__/chant-compose/create-plan.json): network creates subnetB, app reads its id unknown (previewed),
|
|
13
|
+
// edge reads app's known values (plain). As src/chant-compose.test.ts does, edge is made a hole.
|
|
14
|
+
const FIX = join(import.meta.dirname, "..", "src", "__fixtures__", "chant-compose");
|
|
15
|
+
const plan = () => JSON.parse(readFileSync(join(FIX, "create-plan.json"), "utf8"));
|
|
16
|
+
const REASON = "no preview: CloudFormation refused the stand-in";
|
|
17
|
+
const OPEN = { width: 1900, height: 740 };
|
|
18
|
+
|
|
19
|
+
function withHole(entriesToo) {
|
|
20
|
+
const doc = plan();
|
|
21
|
+
doc.changeSet.members.find((m) => m.member === "edge").holes = [{ address: "allowlist", reason: REASON }];
|
|
22
|
+
if (!entriesToo) doc.changeSet.entries = doc.changeSet.entries.filter((e) => e.member !== "edge");
|
|
23
|
+
return composedView(composedReportOf(doc), undefined);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// A stand-in for the svg drawScene writes into: elements with attributes, children and text, enough to walk.
|
|
27
|
+
function fakeNode(tag) {
|
|
28
|
+
const n = {
|
|
29
|
+
tagName: tag,
|
|
30
|
+
attrs: {},
|
|
31
|
+
children: [],
|
|
32
|
+
parent: null,
|
|
33
|
+
textContent: "",
|
|
34
|
+
setAttribute: (k, v) => void (n.attrs[k] = v),
|
|
35
|
+
getAttribute: (k) => (k in n.attrs ? n.attrs[k] : null),
|
|
36
|
+
hasAttribute: (k) => k in n.attrs,
|
|
37
|
+
appendChild: (c) => {
|
|
38
|
+
if (c.parent) c.remove();
|
|
39
|
+
c.parent = n;
|
|
40
|
+
n.children.push(c);
|
|
41
|
+
return c;
|
|
42
|
+
},
|
|
43
|
+
remove: () => {
|
|
44
|
+
if (!n.parent) return;
|
|
45
|
+
n.parent.children = n.parent.children.filter((x) => x !== n);
|
|
46
|
+
n.parent = null;
|
|
47
|
+
},
|
|
48
|
+
querySelectorAll: (sel) => {
|
|
49
|
+
const m = /^:scope > \[([\w-]+)\]$/.exec(sel);
|
|
50
|
+
return m ? n.children.filter((c) => c.hasAttribute(m[1])) : [];
|
|
51
|
+
},
|
|
52
|
+
querySelector: (sel) => n.querySelectorAll(sel)[0] || null,
|
|
53
|
+
};
|
|
54
|
+
return n;
|
|
55
|
+
}
|
|
56
|
+
const walk = (n) => [n, ...n.children.flatMap(walk)];
|
|
57
|
+
const drawn = (model) => {
|
|
58
|
+
const svg = fakeNode("svg");
|
|
59
|
+
drawScene(svg, model);
|
|
60
|
+
return walk(svg);
|
|
61
|
+
};
|
|
62
|
+
const withAttr = (nodes, k, v) => nodes.filter((n) => n.attrs[k] === v);
|
|
63
|
+
|
|
64
|
+
let was;
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
was = globalThis.document;
|
|
67
|
+
globalThis.document = { createElementNS: (_ns, tag) => fakeNode(tag) };
|
|
68
|
+
});
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
globalThis.document = was;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("a hole member and a previewed member, drawn apart (behold#1008)", () => {
|
|
74
|
+
it("reads each member's kind from the composed answer", () => {
|
|
75
|
+
const v = withHole(true);
|
|
76
|
+
expect([...memberKinds(v.answer)].map(([m, k]) => [m, k.kind])).toEqual([["app", "previewed"], ["edge", "hole"], ["network", "plain"]]);
|
|
77
|
+
expect(memberKinds(v.answer).get("edge").reasons).toEqual([REASON]);
|
|
78
|
+
expect(memberKinds(null).size).toBe(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("puts one hole mark on edge's box and the previewed mark on app's, and none on network's", () => {
|
|
82
|
+
const v = withHole(true);
|
|
83
|
+
const nodes = drawn(sceneModel(v.answer, planOf(v.answer), null, OPEN));
|
|
84
|
+
const boxes = nodes.filter((n) => n.hasAttribute("data-layout-box"));
|
|
85
|
+
expect(boxes.map((b) => [b.attrs["data-layout-box"], b.attrs["data-member-kind"]])).toEqual([
|
|
86
|
+
["box:network", "plain"],
|
|
87
|
+
["box:app", "previewed"],
|
|
88
|
+
["box:edge", "hole"],
|
|
89
|
+
]);
|
|
90
|
+
const holes = withAttr(nodes, "data-kl-kind-mark", "hole");
|
|
91
|
+
const previewed = withAttr(nodes, "data-kl-kind-mark", "previewed");
|
|
92
|
+
expect(holes).toHaveLength(1);
|
|
93
|
+
expect(previewed).toHaveLength(1);
|
|
94
|
+
expect(holes[0].parent.attrs["data-layout-box"]).toBe("box:edge");
|
|
95
|
+
expect(previewed[0].parent.attrs["data-layout-box"]).toBe("box:app");
|
|
96
|
+
expect(walk(holes[0]).some((n) => n.textContent === KIND_TAGS.hole)).toBe(true);
|
|
97
|
+
expect(walk(previewed[0]).some((n) => n.textContent === KIND_TAGS.previewed)).toBe(true);
|
|
98
|
+
// The hole's box is dashed; the others are not.
|
|
99
|
+
const outline = (name) => nodes.find((n) => n.attrs["data-group-id"] === name);
|
|
100
|
+
expect(outline("edge").attrs["stroke-dasharray"]).toBeTruthy();
|
|
101
|
+
expect(outline("app").attrs["stroke-dasharray"]).toBeUndefined();
|
|
102
|
+
expect(outline("network").attrs["stroke-dasharray"]).toBeUndefined();
|
|
103
|
+
// Every member's cards are still there: network's subnet, app's interface, edge's allowlist.
|
|
104
|
+
expect(nodes.filter((n) => n.hasAttribute("data-node-id")).map((n) => n.attrs["data-node-id"])).toEqual(["chant/network/subnetB", "chant/app/workerInterface", "chant/edge/allowlist"]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("keeps a hole's box when nothing was previewed in it, with an empty slot saying so and why", () => {
|
|
108
|
+
const v = withHole(false);
|
|
109
|
+
const m = sceneModel(v.answer, planOf(v.answer), null, OPEN);
|
|
110
|
+
expect(m.roots.map((r) => [r.path, r.kind, r.cards.length])).toEqual([["network", "plain", 1], ["app", "previewed", 1], ["edge", "hole", 0]]);
|
|
111
|
+
const edge = m.roots[2];
|
|
112
|
+
expect(edge.hole).toMatchObject({ words: HOLE_WORDS, reasons: [REASON] });
|
|
113
|
+
expect(edge.hole.y).toBeGreaterThanOrEqual(edge.y);
|
|
114
|
+
expect(edge.hole.y + edge.hole.h).toBeLessThanOrEqual(edge.y + edge.h);
|
|
115
|
+
const nodes = drawn(m);
|
|
116
|
+
const slot = nodes.filter((n) => n.attrs["data-kl-hole"] === "edge");
|
|
117
|
+
expect(slot).toHaveLength(1);
|
|
118
|
+
expect(walk(slot[0]).map((n) => n.textContent)).toContain(HOLE_WORDS);
|
|
119
|
+
expect(walk(slot[0]).map((n) => n.textContent)).toContain(REASON);
|
|
120
|
+
expect(withAttr(nodes, "data-kl-kind-mark", "hole")).toHaveLength(1);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("draws no mark on a run with no kinds (a composed choudoufu run)", () => {
|
|
124
|
+
const v = withHole(true);
|
|
125
|
+
const answer = { ...v.answer, chant: undefined };
|
|
126
|
+
const nodes = drawn(sceneModel(answer, planOf(answer), null, OPEN));
|
|
127
|
+
expect(nodes.filter((n) => n.hasAttribute("data-member-kind"))).toEqual([]);
|
|
128
|
+
expect(nodes.filter((n) => n.hasAttribute("data-kl-kind-mark"))).toEqual([]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("says in the legend what the hole mark and the previewed mark mean, on chant's composed page alone", () => {
|
|
132
|
+
const rows = readingRows("resources", "chant-compose");
|
|
133
|
+
expect(rows.filter((r) => r.mark === "hole")).toEqual([KIND_ROWS[0]]);
|
|
134
|
+
expect(rows.filter((r) => r.mark === "previewed")).toEqual([KIND_ROWS[1]]);
|
|
135
|
+
expect(KIND_ROWS[0].words).toMatch(/^Dashed box: a stack no preview could be made of\.$/);
|
|
136
|
+
expect(KIND_ROWS[1].words).toMatch(/^Tag previewed: some values known after apply\.$/);
|
|
137
|
+
for (const r of KIND_ROWS) expect(r.words.length, r.words).toBeLessThanOrEqual(50);
|
|
138
|
+
for (const tool of [null, "chant", "terragrunt", "choudoufu-compose"]) for (const view of ["components", "resources"]) expect(readingRows(view, tool).some((r) => r.mark === "hole" || r.mark === "previewed")).toBe(false);
|
|
139
|
+
});
|
|
140
|
+
});
|
package/web/kiosk-metrics.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// The delivery numbers on the demo are the loop's own (terragucci's
|
|
14
14
|
// stack/demo.sh runs terragucci estate after each cycle's audit): demo.json's
|
|
15
15
|
// `delivery` line says so over them, and the section shows no line without one.
|
|
16
|
+
import { composedRun } from "./kiosk-light.js";
|
|
16
17
|
|
|
17
18
|
/** The localStorage key of the viewer's fold. */
|
|
18
19
|
export const METRICS_STORE = "behold.kiosk.metrics";
|
|
@@ -146,11 +147,12 @@ export function metricsModel(answer, delivery = null, asked = null) {
|
|
|
146
147
|
if (rows.length) dora = rows;
|
|
147
148
|
}
|
|
148
149
|
if (!run && !dora) return null;
|
|
149
|
-
const
|
|
150
|
+
const composed = composedRun(answer);
|
|
151
|
+
const n = run && !composed ? run.waves.length : 0;
|
|
150
152
|
const count = [n ? `${n} ${n === 1 ? "wave" : "waves"}` : null, dora ? `${dora.length} delivery` : null].filter(Boolean).join(" · ");
|
|
151
153
|
const note = dora && typeof delivery === "string" && delivery.trim() ? delivery.trim() : null;
|
|
152
154
|
const span = dora ? spanWords(answer.dora.span_seconds) : null;
|
|
153
|
-
return { count, run, dora, ...(note ? { note } : {}), ...(span ? { window: `last ${span}`, windowNote: windowNote(span) } : {}) };
|
|
155
|
+
return { count, run, dora, ...(composed ? { composed } : {}), ...(note ? { note } : {}), ...(span ? { window: `last ${span}`, windowNote: windowNote(span) } : {}) };
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
/**
|
|
@@ -169,9 +171,10 @@ export function steadyModel(prev, next, { same = false, failed = false } = {}) {
|
|
|
169
171
|
const note = next.note || (next.dora ? null : prev.note) || null;
|
|
170
172
|
// The window goes with the numbers it is about.
|
|
171
173
|
const span = next.dora ? next : prev;
|
|
172
|
-
const
|
|
174
|
+
const composed = next.composed || prev.composed || false;
|
|
175
|
+
const n = run && !composed ? run.waves.length : 0;
|
|
173
176
|
const count = [n ? `${n} ${n === 1 ? "wave" : "waves"}` : null, dora ? `${dora.length} delivery` : null].filter(Boolean).join(" · ");
|
|
174
|
-
return { count, run, dora, ...(note ? { note } : {}), ...(span.window ? { window: span.window, windowNote: span.windowNote } : {}) };
|
|
177
|
+
return { count, run, dora, ...(composed ? { composed } : {}), ...(note ? { note } : {}), ...(span.window ? { window: span.window, windowNote: span.windowNote } : {}) };
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
/** The viewer's fold: true open, false folded, null when they never chose. */
|
|
@@ -281,8 +281,9 @@ function fakeDoc() {
|
|
|
281
281
|
prepend(c) {
|
|
282
282
|
n.appendChild(c);
|
|
283
283
|
},
|
|
284
|
-
replaceChildren() {
|
|
284
|
+
replaceChildren(...kids) {
|
|
285
285
|
n.children = [];
|
|
286
|
+
for (const k of kids) n.appendChild(k);
|
|
286
287
|
},
|
|
287
288
|
setAttribute() {},
|
|
288
289
|
addEventListener(ev, fn) {
|
package/web/kiosk-popover.js
CHANGED
|
@@ -59,8 +59,11 @@ export function valueWords(v, max = 40) {
|
|
|
59
59
|
return s.length > max ? `${s.slice(0, max - 3)}...` : s;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
/** The instance part of an address beyond its block (`[0]`, `["a"]`), or "".
|
|
62
|
+
/** The instance part of an address beyond its block (`[0]`, `["a"]`), or "". An address
|
|
63
|
+
* under an expanded module call (`module.app[0].aws_eip.pool[1]`, chant#4486) gives "",
|
|
64
|
+
* so the line shows the whole address: `[1]` alone would not say which module instance. */
|
|
63
65
|
function instanceKey(address) {
|
|
66
|
+
if (/\]\./.test(address || "")) return "";
|
|
64
67
|
const m = /(\[[^\]]*\])$/.exec(address || "");
|
|
65
68
|
return m ? m[1] : "";
|
|
66
69
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { PAGE_TIMERS, REFIT_WAIT_MS, afterFrames, debounced } from "./kiosk-shot.js";
|
|
3
|
+
|
|
4
|
+
const fakeTimers = () => {
|
|
5
|
+
let now = 0;
|
|
6
|
+
let next = 1;
|
|
7
|
+
const pending = new Map();
|
|
8
|
+
return {
|
|
9
|
+
set: (fn, ms) => (pending.set(next, { fn, at: now + ms }), next++),
|
|
10
|
+
clear: (id) => pending.delete(id),
|
|
11
|
+
advance(ms) {
|
|
12
|
+
now += ms;
|
|
13
|
+
for (const [id, t] of [...pending]) if (t.at <= now) (pending.delete(id), t.fn());
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe("refit trigger", () => {
|
|
19
|
+
it("runs once, after the last size change of a burst", () => {
|
|
20
|
+
const t = fakeTimers();
|
|
21
|
+
const runs = [];
|
|
22
|
+
const refit = debounced(() => runs.push(1), REFIT_WAIT_MS, t);
|
|
23
|
+
refit();
|
|
24
|
+
t.advance(60);
|
|
25
|
+
refit();
|
|
26
|
+
t.advance(60);
|
|
27
|
+
refit();
|
|
28
|
+
t.advance(REFIT_WAIT_MS - 1);
|
|
29
|
+
expect(runs).toHaveLength(0);
|
|
30
|
+
t.advance(1);
|
|
31
|
+
expect(runs).toHaveLength(1);
|
|
32
|
+
t.advance(1000);
|
|
33
|
+
expect(runs).toHaveLength(1);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("cancel drops a pending run", () => {
|
|
37
|
+
const t = fakeTimers();
|
|
38
|
+
const runs = [];
|
|
39
|
+
const refit = debounced(() => runs.push(1), 100, t);
|
|
40
|
+
refit();
|
|
41
|
+
refit.cancel();
|
|
42
|
+
t.advance(500);
|
|
43
|
+
expect(runs).toHaveLength(0);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("afterFrames waits two animation frames by default", () => {
|
|
47
|
+
const queue = [];
|
|
48
|
+
const raf = (fn) => queue.push(fn);
|
|
49
|
+
let done = 0;
|
|
50
|
+
afterFrames(raf, () => done++);
|
|
51
|
+
expect(done).toBe(0);
|
|
52
|
+
queue.shift()();
|
|
53
|
+
expect(done).toBe(0);
|
|
54
|
+
queue.shift()();
|
|
55
|
+
expect(done).toBe(1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("runs on the page's own timers by default (a bare setTimeout in the timers object threw Illegal invocation)", () => {
|
|
59
|
+
vi.useFakeTimers();
|
|
60
|
+
try {
|
|
61
|
+
const runs = [];
|
|
62
|
+
const refit = debounced(() => runs.push(1));
|
|
63
|
+
expect(() => refit()).not.toThrow();
|
|
64
|
+
vi.advanceTimersByTime(REFIT_WAIT_MS);
|
|
65
|
+
expect(runs).toHaveLength(1);
|
|
66
|
+
refit();
|
|
67
|
+
refit.cancel();
|
|
68
|
+
vi.advanceTimersByTime(1000);
|
|
69
|
+
expect(runs).toHaveLength(1);
|
|
70
|
+
} finally {
|
|
71
|
+
vi.useRealTimers();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("the default timers are methods that work detached from a window", () => {
|
|
76
|
+
// What throws in a browser: timers.set(...) with `this` the timers object. Calling through a plain object proves it.
|
|
77
|
+
const holder = { set: PAGE_TIMERS.set, clear: PAGE_TIMERS.clear };
|
|
78
|
+
const id = holder.set(() => {}, 5);
|
|
79
|
+
expect(() => holder.clear(id)).not.toThrow();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prompt demo's reset (behold#935). Between acts the driver puts every estate back to its base, outside the
|
|
3
|
+
* story the person drives. In ask mode the reset step shows one modal over the page, "Resetting", so a viewer knows
|
|
4
|
+
* what the wait is; it goes when the next step arrives. Nothing in the pane or the graph changes for it.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Whether the reset modal shows for this step: a reset while the page is in ask mode. */
|
|
8
|
+
export function resetShown(demo, askOn) {
|
|
9
|
+
return !!askOn && !!demo && demo.step === "reset";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const STYLE_ID = "k-reset-style";
|
|
13
|
+
const STYLE = `
|
|
14
|
+
#k-reset { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.55); opacity: 0; pointer-events: none; transition: opacity 300ms ease; }
|
|
15
|
+
#k-reset.on { opacity: 1; pointer-events: auto; }
|
|
16
|
+
#k-reset .k-reset-card { background: var(--panel, #1f2335); color: var(--fg, #cdd6f4); border: 1px solid var(--accent, #89b4fa); border-radius: 10px; padding: 22px 30px; text-align: center; max-width: min(90vw, 420px); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4); }
|
|
17
|
+
#k-reset .k-reset-title { font: 700 1.4rem/1.2 system-ui, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; display: flex; align-items: center; justify-content: center; gap: 0.6em; }
|
|
18
|
+
#k-reset .k-reset-spin { width: 0.9em; height: 0.9em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: k-reset-spin 900ms linear infinite; }
|
|
19
|
+
#k-reset .k-reset-line { margin-top: 10px; font: 0.95rem/1.4 system-ui, sans-serif; color: var(--muted, #a6adc8); }
|
|
20
|
+
@keyframes k-reset-spin { to { transform: rotate(360deg); } }
|
|
21
|
+
@media (prefers-reduced-motion: reduce) { #k-reset { transition: none; } #k-reset .k-reset-spin { animation: none; } }
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
/** The modal, made once in `doc`; `set(on)` shows or hides it. */
|
|
25
|
+
export function mountResetModal(doc = document) {
|
|
26
|
+
if (!doc.getElementById(STYLE_ID)) {
|
|
27
|
+
const style = doc.createElement("style");
|
|
28
|
+
style.id = STYLE_ID;
|
|
29
|
+
style.textContent = STYLE;
|
|
30
|
+
doc.head.appendChild(style);
|
|
31
|
+
}
|
|
32
|
+
let el = doc.getElementById("k-reset");
|
|
33
|
+
if (!el) {
|
|
34
|
+
el = doc.createElement("div");
|
|
35
|
+
el.id = "k-reset";
|
|
36
|
+
el.setAttribute("role", "status");
|
|
37
|
+
el.setAttribute("aria-live", "polite");
|
|
38
|
+
el.innerHTML =
|
|
39
|
+
'<div class="k-reset-card"><div class="k-reset-title"><span class="k-reset-spin" aria-hidden="true"></span>Resetting</div>' +
|
|
40
|
+
'<div class="k-reset-line">Network, app and edge go back to how they started.</div></div>';
|
|
41
|
+
doc.body.appendChild(el);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
set(on) {
|
|
45
|
+
el.classList.toggle("on", !!on);
|
|
46
|
+
el.setAttribute("aria-hidden", on ? "false" : "true");
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { resetShown } from "./kiosk-reset.js";
|
|
3
|
+
|
|
4
|
+
describe("the reset modal", () => {
|
|
5
|
+
it("shows for a reset step in ask mode, and for nothing else", () => {
|
|
6
|
+
expect(resetShown({ step: "reset" }, true)).toBe(true);
|
|
7
|
+
expect(resetShown({ step: "reset" }, false)).toBe(false);
|
|
8
|
+
expect(resetShown({ step: "applied" }, true)).toBe(false);
|
|
9
|
+
expect(resetShown(null, true)).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
});
|