@warlock.js/grimoire 5.63.1 → 5.65.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/CHANGELOG.md +61 -0
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +24 -2
- package/esm/book/build.mjs.map +1 -1
- package/esm/check/check-grimoire.d.mts.map +1 -1
- package/esm/check/check-grimoire.mjs +11 -1
- package/esm/check/check-grimoire.mjs.map +1 -1
- package/esm/check/rules/api-snapshot.mjs +39 -0
- package/esm/check/rules/api-snapshot.mjs.map +1 -0
- package/esm/check/rules/code-rules.mjs +45 -0
- package/esm/check/rules/code-rules.mjs.map +1 -0
- package/esm/check/rules/drift.mjs +54 -0
- package/esm/check/rules/drift.mjs.map +1 -0
- package/esm/check/rules/focused-tests.mjs +39 -0
- package/esm/check/rules/focused-tests.mjs.map +1 -0
- package/esm/check/rules/shows.mjs +52 -0
- package/esm/check/rules/shows.mjs.map +1 -0
- package/esm/codes/codes.d.mts +48 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +26 -1
- package/esm/codes/codes.mjs.map +1 -1
- package/esm/contracts/adapter.d.mts +6 -0
- package/esm/contracts/adapter.d.mts.map +1 -1
- package/esm/contracts/guard.d.mts +104 -0
- package/esm/contracts/guard.d.mts.map +1 -0
- package/esm/contracts/index.mjs +5 -0
- package/esm/contracts/matrix.d.mts +75 -0
- package/esm/contracts/matrix.d.mts.map +1 -0
- package/esm/contracts/scry.d.mts +42 -0
- package/esm/contracts/scry.d.mts.map +1 -1
- package/esm/contracts/settings.d.mts +71 -0
- package/esm/contracts/settings.d.mts.map +1 -0
- package/esm/contracts/settings.mjs +67 -0
- package/esm/contracts/settings.mjs.map +1 -0
- package/esm/contracts/shots.d.mts +146 -0
- package/esm/contracts/shots.d.mts.map +1 -0
- package/esm/contracts/snapshot.d.mts +10 -0
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/contracts/written.d.mts +13 -0
- package/esm/contracts/written.d.mts.map +1 -1
- package/esm/contracts/written.mjs +7 -1
- package/esm/contracts/written.mjs.map +1 -1
- package/esm/devtools/approvals.mjs +59 -0
- package/esm/devtools/approvals.mjs.map +1 -0
- package/esm/devtools/data.mjs +2 -0
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/graphs.mjs +13 -3
- package/esm/devtools/graphs.mjs.map +1 -1
- package/esm/devtools/index.d.mts +7 -0
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +33 -3
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/matrix.mjs +207 -0
- package/esm/devtools/matrix.mjs.map +1 -0
- package/esm/devtools/product-map.d.mts.map +1 -1
- package/esm/devtools/product-map.mjs +87 -1
- package/esm/devtools/product-map.mjs.map +1 -1
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +12 -3
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +13 -3
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/git/index.d.mts +20 -0
- package/esm/git/index.d.mts.map +1 -0
- package/esm/git/index.mjs +280 -0
- package/esm/git/index.mjs.map +1 -0
- package/esm/guard/api.mjs +70 -0
- package/esm/guard/api.mjs.map +1 -0
- package/esm/guard/assertions.mjs +18 -0
- package/esm/guard/assertions.mjs.map +1 -0
- package/esm/guard/collect.mjs +139 -0
- package/esm/guard/collect.mjs.map +1 -0
- package/esm/guard/format.mjs +27 -0
- package/esm/guard/format.mjs.map +1 -0
- package/esm/guard/glob.mjs +79 -0
- package/esm/guard/glob.mjs.map +1 -0
- package/esm/guard/index.mjs +9 -0
- package/esm/guard/rules.mjs +310 -0
- package/esm/guard/rules.mjs.map +1 -0
- package/esm/guard/scope.mjs +95 -0
- package/esm/guard/scope.mjs.map +1 -0
- package/esm/index.d.mts +10 -3
- package/esm/index.mjs +6 -2
- package/esm/paths/index.d.mts +15 -1
- package/esm/paths/index.d.mts.map +1 -1
- package/esm/paths/index.mjs +27 -3
- package/esm/paths/index.mjs.map +1 -1
- package/esm/proves/index.mjs +2 -1
- package/esm/proves/scan-proofs.mjs +1 -1
- package/esm/proves/scan-proofs.mjs.map +1 -1
- package/esm/proves/scan-shows.d.mts +21 -0
- package/esm/proves/scan-shows.d.mts.map +1 -0
- package/esm/proves/scan-shows.mjs +168 -0
- package/esm/proves/scan-shows.mjs.map +1 -0
- package/esm/releases/index.d.mts.map +1 -1
- package/esm/releases/index.mjs +5 -3
- package/esm/releases/index.mjs.map +1 -1
- package/esm/releases/stamp.mjs +121 -0
- package/esm/releases/stamp.mjs.map +1 -0
- package/esm/rules/focused.mjs +26 -0
- package/esm/rules/focused.mjs.map +1 -0
- package/esm/rules/index.mjs +88 -0
- package/esm/rules/index.mjs.map +1 -0
- package/esm/rules/logical-css.mjs +112 -0
- package/esm/rules/logical-css.mjs.map +1 -0
- package/esm/rules/no-js-imports.mjs +22 -0
- package/esm/rules/no-js-imports.mjs.map +1 -0
- package/esm/rules/scan.mjs +196 -0
- package/esm/rules/scan.mjs.map +1 -0
- package/esm/rules/specific-errors.mjs +51 -0
- package/esm/rules/specific-errors.mjs.map +1 -0
- package/esm/rules/type-discriminator.mjs +27 -0
- package/esm/rules/type-discriminator.mjs.map +1 -0
- package/esm/scry/also-changes.mjs +107 -0
- package/esm/scry/also-changes.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +35 -0
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +40 -2
- package/esm/scry/query.mjs.map +1 -1
- package/esm/scry/search.d.mts.map +1 -1
- package/esm/scry/search.mjs +43 -11
- package/esm/scry/search.mjs.map +1 -1
- package/esm/shots/approve.mjs +195 -0
- package/esm/shots/approve.mjs.map +1 -0
- package/esm/shots/drift.mjs +174 -0
- package/esm/shots/drift.mjs.map +1 -0
- package/esm/shots/png.mjs +166 -0
- package/esm/shots/png.mjs.map +1 -0
- package/esm/shots/state.mjs +43 -0
- package/esm/shots/state.mjs.map +1 -0
- package/esm/shots/store.mjs +66 -0
- package/esm/shots/store.mjs.map +1 -0
- package/esm/shots/touched.mjs +38 -0
- package/esm/shots/touched.mjs.map +1 -0
- package/esm/warlock/adapter.d.mts.map +1 -1
- package/esm/warlock/adapter.mjs +22 -2
- package/esm/warlock/adapter.mjs.map +1 -1
- package/esm/warlock/api-command.mjs +41 -0
- package/esm/warlock/api-command.mjs.map +1 -0
- package/esm/warlock/approve-command.mjs +80 -0
- package/esm/warlock/approve-command.mjs.map +1 -0
- package/esm/warlock/collect-off-thread.mjs +66 -0
- package/esm/warlock/collect-off-thread.mjs.map +1 -0
- package/esm/warlock/commands.d.mts +1 -1
- package/esm/warlock/commands.d.mts.map +1 -1
- package/esm/warlock/commands.mjs +61 -8
- package/esm/warlock/commands.mjs.map +1 -1
- package/esm/warlock/guard-command.mjs +116 -0
- package/esm/warlock/guard-command.mjs.map +1 -0
- package/esm/warlock/index.d.mts +2 -1
- package/esm/warlock/index.mjs +2 -1
- package/esm/warlock/languages.mjs +75 -0
- package/esm/warlock/languages.mjs.map +1 -0
- package/esm/warlock/mcp-tools.mjs +2 -2
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/warlock/release-command.mjs +65 -0
- package/esm/warlock/release-command.mjs.map +1 -0
- package/esm/warlock/shows.d.mts +35 -0
- package/esm/warlock/shows.d.mts.map +1 -0
- package/esm/warlock/shows.mjs +195 -0
- package/esm/warlock/shows.mjs.map +1 -0
- package/esm/workspace/cache.mjs +4 -1
- package/esm/workspace/cache.mjs.map +1 -1
- package/esm/workspace/derived.mjs +11 -6
- package/esm/workspace/derived.mjs.map +1 -1
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +8 -1
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/workspace/stored.mjs +4 -1
- package/esm/workspace/stored.mjs.map +1 -1
- package/esm/written/features.mjs +21 -5
- package/esm/written/features.mjs.map +1 -1
- package/esm/written/index.mjs +2 -1
- package/esm/written/parse-grimoire.d.mts.map +1 -1
- package/esm/written/parse-grimoire.mjs +16 -3
- package/esm/written/parse-grimoire.mjs.map +1 -1
- package/esm/written/settings.d.mts +11 -0
- package/esm/written/settings.d.mts.map +1 -0
- package/esm/written/settings.mjs +88 -0
- package/esm/written/settings.mjs.map +1 -0
- package/llms-full.txt +282 -39
- package/llms.txt +2 -0
- package/package.json +3 -3
- package/skills/backfill-a-grimoire/SKILL.md +4 -0
- package/skills/describe-an-app/SKILL.md +4 -1
- package/skills/guard-a-change/SKILL.md +85 -0
- package/skills/index.md +7 -3
- package/skills/record-a-change/SKILL.md +52 -16
- package/skills/review-a-change/SKILL.md +53 -0
- package/skills/use-the-grimoire/SKILL.md +27 -18
- package/skills/write-a-feature/SKILL.md +42 -1
- package/ui/grimoire-view.js +756 -40
- package/ui/grimoire.css +303 -28
- package/ui/product-map.css +43 -7
- package/ui/product-map.js +212 -37
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { GrimoireError } from "../codes/index.mjs";
|
|
2
|
+
import { GRIMOIRE_PATHS, criterionShotName } from "../paths/index.mjs";
|
|
3
|
+
import { currentFlows } from "./drift.mjs";
|
|
4
|
+
import { readBaseline, writeBaseline } from "./store.mjs";
|
|
5
|
+
import { optedOutFlows } from "./state.mjs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { copyFile, mkdir, readFile, rm } from "node:fs/promises";
|
|
9
|
+
|
|
10
|
+
//#region ../../packages/grimoire/src/shots/approve.ts
|
|
11
|
+
/**
|
|
12
|
+
* Approve and reject: the only code that writes `grimoire/approved/baseline.json`
|
|
13
|
+
* and the images under `grimoire/screenshots/approved/`.
|
|
14
|
+
*/
|
|
15
|
+
const FLOW_REF = /^[a-z0-9]+(?:-[a-z0-9]+)*\/[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
16
|
+
/**
|
|
17
|
+
* A path under `grimoire/screenshots/`. The parts come from the baseline and
|
|
18
|
+
* the capture index (files in the project), so a part that is empty, `.` or
|
|
19
|
+
* `..`, or holds a separator, is refused: approving never reads, copies or
|
|
20
|
+
* deletes a file outside that folder.
|
|
21
|
+
*/
|
|
22
|
+
function shotsRoot(root, ...parts) {
|
|
23
|
+
for (const part of parts) if (part === "" || part === "." || part === ".." || /[\\/:]/.test(part)) throw new GrimoireError("GR9010", `The screenshot path ${JSON.stringify(parts.join("/"))} is not a path under ${GRIMOIRE_PATHS.screenshots}; correct ${GRIMOIRE_PATHS.baseline} or run the browser tests again.`);
|
|
24
|
+
return path.join(root, ...GRIMOIRE_PATHS.screenshots.split("/"), ...parts);
|
|
25
|
+
}
|
|
26
|
+
function sha256(bytes) {
|
|
27
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The drift items a request names. `GR9010` when a target matches nothing.
|
|
31
|
+
* `all` with a language keeps only that language's shot items.
|
|
32
|
+
*/
|
|
33
|
+
function selectDrift(snapshot, request) {
|
|
34
|
+
const drift = snapshot.shots?.drift ?? [];
|
|
35
|
+
const chosen = /* @__PURE__ */ new Map();
|
|
36
|
+
if (request.targets.length === 0) throw new GrimoireError("GR9010", "Name what to approve: a change id, a <feature>/<flow>, or --all.");
|
|
37
|
+
for (const target of request.targets) {
|
|
38
|
+
const matches = target === "all" ? drift : drift.filter((entry) => entry.id === target || FLOW_REF.test(target) && entry.ref === target);
|
|
39
|
+
const narrowed = request.language === void 0 ? matches : matches.filter((entry) => entry.language === request.language);
|
|
40
|
+
if (narrowed.length === 0 && target !== "all") throw new GrimoireError("GR9010", `Nothing to approve or reject matches ${JSON.stringify(target)}${request.language === void 0 ? "" : ` in ${request.language}`}. Pass a change id from the Bird view or the check, a <feature>/<flow>, or --all.`);
|
|
41
|
+
for (const entry of narrowed) chosen.set(entry.id, entry);
|
|
42
|
+
}
|
|
43
|
+
return [...chosen.values()];
|
|
44
|
+
}
|
|
45
|
+
/** The baseline of the current state: every flow, proving test and passing capture. */
|
|
46
|
+
async function baselineFromCurrent(root, snapshot, now) {
|
|
47
|
+
const baseline = {
|
|
48
|
+
schemaVersion: 1,
|
|
49
|
+
approvedAt: now,
|
|
50
|
+
flows: currentFlows(snapshot.written),
|
|
51
|
+
proofs: currentProofs(snapshot),
|
|
52
|
+
shots: [],
|
|
53
|
+
rejected: []
|
|
54
|
+
};
|
|
55
|
+
const shown = new Set((snapshot.shots?.shows ?? []).filter((line) => line.call !== null).map((line) => `${line.ref} ${line.criterion}`));
|
|
56
|
+
const optedOut = new Set(optedOutFlows(snapshot.written));
|
|
57
|
+
for (const capture of snapshot.shots?.captures?.captures ?? []) if (capture.outcome === "pass" && capture.file !== null && shown.has(`${capture.ref} ${capture.criterion}`) && !optedOut.has(capture.ref)) baseline.shots.push(await approveImage(root, capture.ref, capture.criterion, capture.language, capture.file, now));
|
|
58
|
+
return baseline;
|
|
59
|
+
}
|
|
60
|
+
function currentProofs(snapshot) {
|
|
61
|
+
const seen = /* @__PURE__ */ new Set();
|
|
62
|
+
const proofs = [];
|
|
63
|
+
for (const proof of snapshot.proofs) {
|
|
64
|
+
if (proof.test === null) continue;
|
|
65
|
+
const key = `${proof.ref} ${proof.criterion} ${proof.at.file}`;
|
|
66
|
+
if (seen.has(key)) continue;
|
|
67
|
+
seen.add(key);
|
|
68
|
+
proofs.push({
|
|
69
|
+
ref: proof.ref,
|
|
70
|
+
criterion: proof.criterion,
|
|
71
|
+
testFile: proof.at.file,
|
|
72
|
+
testName: proof.test.name
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return proofs;
|
|
76
|
+
}
|
|
77
|
+
/** Copy `captured/…` to `approved/…` and describe it. */
|
|
78
|
+
async function approveImage(root, ref, criterion, language, captured, now) {
|
|
79
|
+
const source = shotsRoot(root, ...captured.split("/"));
|
|
80
|
+
const file = `approved/${criterionShotName(ref, criterion, language)}`;
|
|
81
|
+
const target = shotsRoot(root, ...file.split("/"));
|
|
82
|
+
let bytes;
|
|
83
|
+
try {
|
|
84
|
+
bytes = await readFile(source);
|
|
85
|
+
} catch {
|
|
86
|
+
throw new GrimoireError("GR9010", `The capture ${GRIMOIRE_PATHS.screenshots}/${captured} is missing; run the browser tests again, then approve.`);
|
|
87
|
+
}
|
|
88
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
89
|
+
await copyFile(source, target);
|
|
90
|
+
return {
|
|
91
|
+
ref,
|
|
92
|
+
criterion,
|
|
93
|
+
language,
|
|
94
|
+
file,
|
|
95
|
+
sha256: sha256(bytes),
|
|
96
|
+
approvedAt: now
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function upsertFlow(baseline, flow) {
|
|
100
|
+
baseline.flows = [...baseline.flows.filter((entry) => entry.ref !== flow.ref), flow].sort((left, right) => left.ref.localeCompare(right.ref));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Approve `items` (the baseline is created from the current state when there
|
|
104
|
+
* is none and `items` is empty with `createWhenMissing`). Returns the ids done.
|
|
105
|
+
*/
|
|
106
|
+
async function approveItems(snapshot, items, now = (/* @__PURE__ */ new Date()).toISOString(), options = {}) {
|
|
107
|
+
const root = snapshot.root;
|
|
108
|
+
const existing = await readBaseline(root) ?? snapshot.shots?.baseline ?? null;
|
|
109
|
+
if (existing === null) {
|
|
110
|
+
if (options.createWhenMissing !== true) throw new GrimoireError("GR9010", "Nothing is approved yet; approve everything first (--all).");
|
|
111
|
+
await writeBaseline(root, await baselineFromCurrent(root, snapshot, now));
|
|
112
|
+
return ["baseline"];
|
|
113
|
+
}
|
|
114
|
+
const baseline = structuredClone(existing);
|
|
115
|
+
const current = new Map(currentFlows(snapshot.written).map((flow) => [flow.ref, flow]));
|
|
116
|
+
const captures = new Map((snapshot.shots?.captures?.captures ?? []).map((capture) => [`${capture.ref} ${capture.criterion} ${capture.language}`, capture]));
|
|
117
|
+
const done = [];
|
|
118
|
+
const removedProofs = /* @__PURE__ */ new Set();
|
|
119
|
+
for (const item of items) {
|
|
120
|
+
const flow = current.get(item.ref);
|
|
121
|
+
const approvedFlow = baseline.flows.find((entry) => entry.ref === item.ref);
|
|
122
|
+
switch (item.type) {
|
|
123
|
+
case "shot-changed":
|
|
124
|
+
case "shot-added": {
|
|
125
|
+
const capture = captures.get(`${item.ref} ${item.criterion} ${item.language}`);
|
|
126
|
+
if (capture?.file == null) throw new GrimoireError("GR9010", `The capture for ${item.id} is missing; run the browser tests again.`);
|
|
127
|
+
const shot = await approveImage(root, item.ref, item.criterion ?? "", item.language ?? "", capture.file, now);
|
|
128
|
+
baseline.shots = [...baseline.shots.filter((entry) => !(entry.ref === shot.ref && entry.criterion === shot.criterion && entry.language === shot.language)), shot];
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case "shot-removed":
|
|
132
|
+
if (item.approvedShot !== null) await rm(shotsRoot(root, ...item.approvedShot.split("/")), { force: true });
|
|
133
|
+
baseline.shots = baseline.shots.filter((entry) => !(entry.ref === item.ref && entry.criterion === item.criterion && entry.language === item.language));
|
|
134
|
+
break;
|
|
135
|
+
case "flow-added":
|
|
136
|
+
if (flow) upsertFlow(baseline, structuredClone(flow));
|
|
137
|
+
break;
|
|
138
|
+
case "flow-removed":
|
|
139
|
+
baseline.flows = baseline.flows.filter((entry) => entry.ref !== item.ref);
|
|
140
|
+
baseline.proofs = baseline.proofs.filter((entry) => entry.ref !== item.ref);
|
|
141
|
+
break;
|
|
142
|
+
case "criterion-added":
|
|
143
|
+
case "criterion-changed": {
|
|
144
|
+
const text = flow?.criteria.find((entry) => entry.id === item.criterion);
|
|
145
|
+
if (!flow || !text) break;
|
|
146
|
+
if (!approvedFlow) upsertFlow(baseline, structuredClone(flow));
|
|
147
|
+
else approvedFlow.criteria = [...approvedFlow.criteria.filter((entry) => entry.id !== item.criterion), { ...text }].sort((left, right) => left.id.localeCompare(right.id, "en", { numeric: true }));
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case "criterion-removed":
|
|
151
|
+
if (approvedFlow) approvedFlow.criteria = approvedFlow.criteria.filter((entry) => entry.id !== item.criterion);
|
|
152
|
+
break;
|
|
153
|
+
case "case-added":
|
|
154
|
+
if (!flow) break;
|
|
155
|
+
if (!approvedFlow) upsertFlow(baseline, structuredClone(flow));
|
|
156
|
+
else if (item.case !== null && !approvedFlow.cases.includes(item.case)) approvedFlow.cases = [...approvedFlow.cases, item.case];
|
|
157
|
+
break;
|
|
158
|
+
case "case-removed":
|
|
159
|
+
if (approvedFlow) approvedFlow.cases = approvedFlow.cases.filter((entry) => entry !== item.case);
|
|
160
|
+
break;
|
|
161
|
+
case "proof-removed": removedProofs.add(`${item.ref} ${item.criterion}`);
|
|
162
|
+
}
|
|
163
|
+
done.push(item.id);
|
|
164
|
+
}
|
|
165
|
+
const proofs = currentProofs(snapshot);
|
|
166
|
+
const proven = new Set(proofs.map((proof) => `${proof.ref} ${proof.criterion}`));
|
|
167
|
+
baseline.proofs = [...proofs, ...baseline.proofs.filter((proof) => {
|
|
168
|
+
const key = `${proof.ref} ${proof.criterion}`;
|
|
169
|
+
return !proven.has(key) && !removedProofs.has(key);
|
|
170
|
+
})];
|
|
171
|
+
baseline.rejected = baseline.rejected.filter((entry) => !done.includes(entry.id));
|
|
172
|
+
baseline.approvedAt = now;
|
|
173
|
+
await writeBaseline(root, baseline);
|
|
174
|
+
return done;
|
|
175
|
+
}
|
|
176
|
+
/** Reject `items`: each stays an error (`GR4019`) while it is still there. Returns the ids done. */
|
|
177
|
+
async function rejectItems(snapshot, items, note, now = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
178
|
+
const existing = await readBaseline(snapshot.root) ?? snapshot.shots?.baseline ?? null;
|
|
179
|
+
if (existing === null) throw new GrimoireError("GR9010", "Nothing is approved yet, so there is no change to reject.");
|
|
180
|
+
const ids = items.map((item) => item.id);
|
|
181
|
+
const baseline = {
|
|
182
|
+
...structuredClone(existing),
|
|
183
|
+
rejected: [...existing.rejected.filter((entry) => !ids.includes(entry.id)), ...ids.map((id) => ({
|
|
184
|
+
id,
|
|
185
|
+
rejectedAt: now,
|
|
186
|
+
note
|
|
187
|
+
}))]
|
|
188
|
+
};
|
|
189
|
+
await writeBaseline(snapshot.root, baseline);
|
|
190
|
+
return ids;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
export { approveItems, rejectItems, selectDrift };
|
|
195
|
+
//# sourceMappingURL=approve.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approve.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/shots/approve.ts"],"sourcesContent":["/**\n * Approve and reject: the only code that writes `grimoire/approved/baseline.json`\n * and the images under `grimoire/screenshots/approved/`.\n */\nimport { createHash } from \"node:crypto\";\nimport { copyFile, mkdir, readFile, rm } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { GrimoireError } from \"../codes\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type {\n ApprovedBaseline,\n ApprovedFlow,\n ApprovedProof,\n ApprovedShot,\n DriftItem,\n} from \"../contracts/shots\";\nimport { criterionShotName, GRIMOIRE_PATHS } from \"../paths\";\nimport { currentFlows } from \"./drift\";\nimport { optedOutFlows } from \"./state\";\nimport { readBaseline, writeBaseline } from \"./store\";\n\n/** What to approve or reject. */\nexport type ApprovalRequest = {\n /** Drift ids, or `<feature>/<flow>` (every item of the flow), or `all`. */\n targets: string[];\n /** Keep only the shot items of this language. */\n language?: string;\n /** Why (reject only). */\n note?: string;\n};\n\nconst FLOW_REF = /^[a-z0-9]+(?:-[a-z0-9]+)*\\/[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n/**\n * A path under `grimoire/screenshots/`. The parts come from the baseline and\n * the capture index (files in the project), so a part that is empty, `.` or\n * `..`, or holds a separator, is refused: approving never reads, copies or\n * deletes a file outside that folder.\n */\nfunction shotsRoot(root: string, ...parts: string[]): string {\n for (const part of parts) {\n if (part === \"\" || part === \".\" || part === \"..\" || /[\\\\/:]/.test(part)) {\n throw new GrimoireError(\n \"GR9010\",\n `The screenshot path ${JSON.stringify(parts.join(\"/\"))} is not a path under ${GRIMOIRE_PATHS.screenshots}; correct ${GRIMOIRE_PATHS.baseline} or run the browser tests again.`,\n );\n }\n }\n\n return path.join(root, ...GRIMOIRE_PATHS.screenshots.split(\"/\"), ...parts);\n}\n\nfunction sha256(bytes: Uint8Array): string {\n return createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n\n/**\n * The drift items a request names. `GR9010` when a target matches nothing.\n * `all` with a language keeps only that language's shot items.\n */\nexport function selectDrift(snapshot: GrimoireSnapshot, request: ApprovalRequest): DriftItem[] {\n const drift = snapshot.shots?.drift ?? [];\n const chosen = new Map<string, DriftItem>();\n\n if (request.targets.length === 0) {\n throw new GrimoireError(\n \"GR9010\",\n \"Name what to approve: a change id, a <feature>/<flow>, or --all.\",\n );\n }\n\n for (const target of request.targets) {\n const matches =\n target === \"all\"\n ? drift\n : drift.filter(\n (entry) => entry.id === target || (FLOW_REF.test(target) && entry.ref === target),\n );\n const narrowed =\n request.language === undefined\n ? matches\n : matches.filter((entry) => entry.language === request.language);\n\n if (narrowed.length === 0 && target !== \"all\") {\n throw new GrimoireError(\n \"GR9010\",\n `Nothing to approve or reject matches ${JSON.stringify(target)}${request.language === undefined ? \"\" : ` in ${request.language}`}. Pass a change id from the Bird view or the check, a <feature>/<flow>, or --all.`,\n );\n }\n\n for (const entry of narrowed) chosen.set(entry.id, entry);\n }\n\n return [...chosen.values()];\n}\n\n/** The baseline of the current state: every flow, proving test and passing capture. */\nasync function baselineFromCurrent(\n root: string,\n snapshot: GrimoireSnapshot,\n now: string,\n): Promise<ApprovedBaseline> {\n const baseline: ApprovedBaseline = {\n schemaVersion: 1,\n approvedAt: now,\n flows: currentFlows(snapshot.written),\n proofs: currentProofs(snapshot),\n shots: [],\n rejected: [],\n };\n const shown = new Set(\n (snapshot.shots?.shows ?? [])\n .filter((line) => line.call !== null)\n .map((line) => `${line.ref} ${line.criterion}`),\n );\n const optedOut = new Set(optedOutFlows(snapshot.written));\n\n for (const capture of snapshot.shots?.captures?.captures ?? []) {\n if (\n capture.outcome === \"pass\" &&\n capture.file !== null &&\n shown.has(`${capture.ref} ${capture.criterion}`) &&\n !optedOut.has(capture.ref)\n ) {\n baseline.shots.push(\n await approveImage(\n root,\n capture.ref,\n capture.criterion,\n capture.language,\n capture.file,\n now,\n ),\n );\n }\n }\n\n return baseline;\n}\n\nfunction currentProofs(snapshot: GrimoireSnapshot): ApprovedProof[] {\n const seen = new Set<string>();\n const proofs: ApprovedProof[] = [];\n\n for (const proof of snapshot.proofs) {\n if (proof.test === null) continue;\n\n const key = `${proof.ref} ${proof.criterion} ${proof.at.file}`;\n\n if (seen.has(key)) continue;\n\n seen.add(key);\n proofs.push({\n ref: proof.ref,\n criterion: proof.criterion,\n testFile: proof.at.file,\n testName: proof.test.name,\n });\n }\n\n return proofs;\n}\n\n/** Copy `captured/…` to `approved/…` and describe it. */\nasync function approveImage(\n root: string,\n ref: string,\n criterion: string,\n language: string,\n captured: string,\n now: string,\n): Promise<ApprovedShot> {\n const source = shotsRoot(root, ...captured.split(\"/\"));\n const file = `approved/${criterionShotName(ref, criterion, language)}`;\n const target = shotsRoot(root, ...file.split(\"/\"));\n let bytes: Buffer;\n\n try {\n bytes = await readFile(source);\n } catch {\n throw new GrimoireError(\n \"GR9010\",\n `The capture ${GRIMOIRE_PATHS.screenshots}/${captured} is missing; run the browser tests again, then approve.`,\n );\n }\n\n await mkdir(path.dirname(target), { recursive: true });\n await copyFile(source, target);\n\n return { ref, criterion, language, file, sha256: sha256(bytes), approvedAt: now };\n}\n\nfunction upsertFlow(baseline: ApprovedBaseline, flow: ApprovedFlow): void {\n baseline.flows = [...baseline.flows.filter((entry) => entry.ref !== flow.ref), flow].sort(\n (left, right) => left.ref.localeCompare(right.ref),\n );\n}\n\n/**\n * Approve `items` (the baseline is created from the current state when there\n * is none and `items` is empty with `createWhenMissing`). Returns the ids done.\n */\nexport async function approveItems(\n snapshot: GrimoireSnapshot,\n items: readonly DriftItem[],\n now = new Date().toISOString(),\n options: { createWhenMissing?: boolean } = {},\n): Promise<string[]> {\n const root = snapshot.root;\n // Read from disk: the panel's snapshot may be a moment old, and an approval made since must not be lost.\n const existing = (await readBaseline(root)) ?? snapshot.shots?.baseline ?? null;\n\n if (existing === null) {\n if (options.createWhenMissing !== true) {\n throw new GrimoireError(\n \"GR9010\",\n \"Nothing is approved yet; approve everything first (--all).\",\n );\n }\n\n await writeBaseline(root, await baselineFromCurrent(root, snapshot, now));\n\n return [\"baseline\"];\n }\n\n const baseline: ApprovedBaseline = structuredClone(existing);\n const current = new Map(currentFlows(snapshot.written).map((flow) => [flow.ref, flow]));\n const captures = new Map(\n (snapshot.shots?.captures?.captures ?? []).map((capture) => [\n `${capture.ref} ${capture.criterion} ${capture.language}`,\n capture,\n ]),\n );\n const done: string[] = [];\n const removedProofs = new Set<string>();\n\n for (const item of items) {\n const flow = current.get(item.ref);\n const approvedFlow = baseline.flows.find((entry) => entry.ref === item.ref);\n\n switch (item.type) {\n case \"shot-changed\":\n case \"shot-added\": {\n const capture = captures.get(`${item.ref} ${item.criterion} ${item.language}`);\n\n if (capture?.file == null) {\n throw new GrimoireError(\n \"GR9010\",\n `The capture for ${item.id} is missing; run the browser tests again.`,\n );\n }\n\n const shot = await approveImage(\n root,\n item.ref,\n item.criterion ?? \"\",\n item.language ?? \"\",\n capture.file,\n now,\n );\n\n baseline.shots = [\n ...baseline.shots.filter(\n (entry) =>\n !(\n entry.ref === shot.ref &&\n entry.criterion === shot.criterion &&\n entry.language === shot.language\n ),\n ),\n shot,\n ];\n break;\n }\n case \"shot-removed\":\n if (item.approvedShot !== null) {\n await rm(shotsRoot(root, ...item.approvedShot.split(\"/\")), { force: true });\n }\n\n baseline.shots = baseline.shots.filter(\n (entry) =>\n !(\n entry.ref === item.ref &&\n entry.criterion === item.criterion &&\n entry.language === item.language\n ),\n );\n break;\n case \"flow-added\":\n if (flow) upsertFlow(baseline, structuredClone(flow));\n break;\n case \"flow-removed\":\n baseline.flows = baseline.flows.filter((entry) => entry.ref !== item.ref);\n baseline.proofs = baseline.proofs.filter((entry) => entry.ref !== item.ref);\n break;\n case \"criterion-added\":\n case \"criterion-changed\": {\n const text = flow?.criteria.find((entry) => entry.id === item.criterion);\n\n if (!flow || !text) break;\n\n if (!approvedFlow) upsertFlow(baseline, structuredClone(flow));\n else {\n approvedFlow.criteria = [\n ...approvedFlow.criteria.filter((entry) => entry.id !== item.criterion),\n { ...text },\n ].sort((left, right) => left.id.localeCompare(right.id, \"en\", { numeric: true }));\n }\n break;\n }\n case \"criterion-removed\":\n if (approvedFlow) {\n approvedFlow.criteria = approvedFlow.criteria.filter(\n (entry) => entry.id !== item.criterion,\n );\n }\n break;\n case \"case-added\":\n if (!flow) break;\n\n if (!approvedFlow) upsertFlow(baseline, structuredClone(flow));\n else if (item.case !== null && !approvedFlow.cases.includes(item.case)) {\n approvedFlow.cases = [...approvedFlow.cases, item.case];\n }\n break;\n case \"case-removed\":\n if (approvedFlow)\n approvedFlow.cases = approvedFlow.cases.filter((entry) => entry !== item.case);\n break;\n case \"proof-removed\":\n removedProofs.add(`${item.ref} ${item.criterion}`);\n break;\n }\n\n done.push(item.id);\n }\n\n // New proving tests are never drift; they join the baseline with the next approval.\n const proofs = currentProofs(snapshot);\n const proven = new Set(proofs.map((proof) => `${proof.ref} ${proof.criterion}`));\n\n baseline.proofs = [\n ...proofs,\n ...baseline.proofs.filter((proof) => {\n const key = `${proof.ref} ${proof.criterion}`;\n\n return !proven.has(key) && !removedProofs.has(key);\n }),\n ];\n baseline.rejected = baseline.rejected.filter((entry) => !done.includes(entry.id));\n baseline.approvedAt = now;\n\n await writeBaseline(root, baseline);\n\n return done;\n}\n\n/** Reject `items`: each stays an error (`GR4019`) while it is still there. Returns the ids done. */\nexport async function rejectItems(\n snapshot: GrimoireSnapshot,\n items: readonly DriftItem[],\n note: string | null,\n now = new Date().toISOString(),\n): Promise<string[]> {\n const existing = (await readBaseline(snapshot.root)) ?? snapshot.shots?.baseline ?? null;\n\n if (existing === null) {\n throw new GrimoireError(\"GR9010\", \"Nothing is approved yet, so there is no change to reject.\");\n }\n\n const ids = items.map((item) => item.id);\n const baseline: ApprovedBaseline = {\n ...structuredClone(existing),\n rejected: [\n ...existing.rejected.filter((entry) => !ids.includes(entry.id)),\n ...ids.map((id) => ({ id, rejectedAt: now, note })),\n ],\n };\n\n await writeBaseline(snapshot.root, baseline);\n\n return ids;\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,MAAM,WAAW;;;;;;;AAQjB,SAAS,UAAU,MAAc,GAAG,OAAyB;CAC3D,KAAK,MAAM,QAAQ,OACjB,IAAI,SAAS,MAAM,SAAS,OAAO,SAAS,QAAQ,SAAS,KAAK,IAAI,GACpE,MAAM,IAAI,cACR,UACA,uBAAuB,KAAK,UAAU,MAAM,KAAK,GAAG,CAAC,EAAE,uBAAuB,eAAe,YAAY,YAAY,eAAe,SAAS,iCAC/I;CAIJ,OAAO,KAAK,KAAK,MAAM,GAAG,eAAe,YAAY,MAAM,GAAG,GAAG,GAAG,KAAK;AAC3E;AAEA,SAAS,OAAO,OAA2B;CACzC,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,KAAK;AACxD;;;;;AAMA,SAAgB,YAAY,UAA4B,SAAuC;CAC7F,MAAM,QAAQ,SAAS,OAAO,SAAS,CAAC;CACxC,MAAM,yBAAS,IAAI,IAAuB;CAE1C,IAAI,QAAQ,QAAQ,WAAW,GAC7B,MAAM,IAAI,cACR,UACA,kEACF;CAGF,KAAK,MAAM,UAAU,QAAQ,SAAS;EACpC,MAAM,UACJ,WAAW,QACP,QACA,MAAM,QACH,UAAU,MAAM,OAAO,UAAW,SAAS,KAAK,MAAM,KAAK,MAAM,QAAQ,MAC5E;EACN,MAAM,WACJ,QAAQ,aAAa,SACj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B;CAGA,MAAM,SAAS,cAAc,QAAQ;CACrC,MAAM,SAAS,IAAI,IAAI,OAAO,KAAK,UAAU,GAAG,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC;CAE/E,SAAS,SAAS,CAChB,GAAG,QACH,GAAG,SAAS,OAAO,QAAQ,UAAU;EACnC,MAAM,MAAM,GAAG,MAAM,IAAI,GAAG,MAAM;EAElC,OAAO,CAAC,OAAO,IAAI,GAAG,KAAK,CAAC,cAAc,IAAI,GAAG;CACnD,CAAC,CACH;CACA,SAAS,WAAW,SAAS,SAAS,QAAQ,UAAU,CAAC,KAAK,SAAS,MAAM,EAAE,CAAC;CAChF,SAAS,aAAa;CAEtB,MAAM,cAAc,MAAM,QAAQ;CAElC,OAAO;AACT;;AAGA,eAAsB,YACpB,UACA,OACA,MACA,uBAAM,IAAI,KAAK,EAAC,CAAC,YAAY,GACV;CACnB,MAAM,WAAY,MAAM,aAAa,SAAS,IAAI,KAAM,SAAS,OAAO,YAAY;CAEpF,IAAI,aAAa,MACf,MAAM,IAAI,cAAc,UAAU,2DAA2D;CAG/F,MAAM,MAAM,MAAM,KAAK,SAAS,KAAK,EAAE;CACvC,MAAM,WAA6B;EACjC,GAAG,gBAAgB,QAAQ;EAC3B,UAAU,CACR,GAAG,SAAS,SAAS,QAAQ,UAAU,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC,GAC9D,GAAG,IAAI,KAAK,QAAQ;GAAE;GAAI,YAAY;GAAK;EAAK,EAAE,CACpD;CACF;CAEA,MAAM,cAAc,SAAS,MAAM,QAAQ;CAE3C,OAAO;AACT"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { GRIMOIRE_PATHS } from "../paths/index.mjs";
|
|
2
|
+
import { comparePng } from "./png.mjs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
|
|
6
|
+
//#region ../../packages/grimoire/src/shots/drift.ts
|
|
7
|
+
/**
|
|
8
|
+
* Drift: the current state of the flows, proving tests and captures against
|
|
9
|
+
* the approved baseline. Ids are `<type>:<feature>/<flow>[:<AC-n>][:<language>|:<case>]`.
|
|
10
|
+
*/
|
|
11
|
+
/** The flows of a written grimoire in the shape the baseline stores. */
|
|
12
|
+
function currentFlows(written) {
|
|
13
|
+
return written.features.flatMap((feature) => feature.flows).map((flow) => ({
|
|
14
|
+
ref: flow.ref,
|
|
15
|
+
criteria: flow.criteria.map((criterion) => ({
|
|
16
|
+
id: criterion.id,
|
|
17
|
+
text: criterion.text
|
|
18
|
+
})),
|
|
19
|
+
cases: [...new Set(flow.cases.map((entry) => entry.question))]
|
|
20
|
+
})).sort((left, right) => left.ref.localeCompare(right.ref));
|
|
21
|
+
}
|
|
22
|
+
/** The id of a drift item. */
|
|
23
|
+
function driftId(type, ref, criterion, extra) {
|
|
24
|
+
return [
|
|
25
|
+
type,
|
|
26
|
+
ref,
|
|
27
|
+
criterion,
|
|
28
|
+
extra === "" ? null : extra
|
|
29
|
+
].filter((part) => part !== null).join(":");
|
|
30
|
+
}
|
|
31
|
+
function item(baseline, fields) {
|
|
32
|
+
const criterion = fields.criterion ?? null;
|
|
33
|
+
const extra = fields.language ?? fields.case ?? null;
|
|
34
|
+
const id = driftId(fields.type, fields.ref, criterion, extra);
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
type: fields.type,
|
|
38
|
+
ref: fields.ref,
|
|
39
|
+
criterion,
|
|
40
|
+
language: fields.language ?? null,
|
|
41
|
+
case: fields.case ?? null,
|
|
42
|
+
before: fields.before ?? null,
|
|
43
|
+
after: fields.after ?? null,
|
|
44
|
+
approvedShot: fields.approvedShot ?? null,
|
|
45
|
+
capturedShot: fields.capturedShot ?? null,
|
|
46
|
+
rejected: baseline.rejected.find((entry) => entry.id === id) ?? null
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function readImage(root, file) {
|
|
50
|
+
try {
|
|
51
|
+
return await readFile(path.join(root, ...GRIMOIRE_PATHS.screenshots.split("/"), ...file.split("/")));
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** The differences of the current state from the approved baseline, in a stable order. */
|
|
57
|
+
async function computeDrift(input) {
|
|
58
|
+
const { baseline } = input;
|
|
59
|
+
const items = [];
|
|
60
|
+
const now = new Map(currentFlows(input.written).map((flow) => [flow.ref, flow]));
|
|
61
|
+
const approved = new Map(baseline.flows.map((flow) => [flow.ref, flow]));
|
|
62
|
+
for (const [ref, flow] of now) {
|
|
63
|
+
const before = approved.get(ref);
|
|
64
|
+
if (before === void 0) {
|
|
65
|
+
items.push(item(baseline, {
|
|
66
|
+
type: "flow-added",
|
|
67
|
+
ref
|
|
68
|
+
}));
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const beforeCriteria = new Map(before.criteria.map((criterion) => [criterion.id, criterion.text]));
|
|
72
|
+
const nowCriteria = new Map(flow.criteria.map((criterion) => [criterion.id, criterion.text]));
|
|
73
|
+
for (const [id, text] of nowCriteria) {
|
|
74
|
+
const old = beforeCriteria.get(id);
|
|
75
|
+
if (old === void 0) items.push(item(baseline, {
|
|
76
|
+
type: "criterion-added",
|
|
77
|
+
ref,
|
|
78
|
+
criterion: id,
|
|
79
|
+
after: text
|
|
80
|
+
}));
|
|
81
|
+
else if (old !== text) items.push(item(baseline, {
|
|
82
|
+
type: "criterion-changed",
|
|
83
|
+
ref,
|
|
84
|
+
criterion: id,
|
|
85
|
+
before: old,
|
|
86
|
+
after: text
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
for (const [id, text] of beforeCriteria) if (!nowCriteria.has(id)) items.push(item(baseline, {
|
|
90
|
+
type: "criterion-removed",
|
|
91
|
+
ref,
|
|
92
|
+
criterion: id,
|
|
93
|
+
before: text
|
|
94
|
+
}));
|
|
95
|
+
for (const question of flow.cases) if (!before.cases.includes(question)) items.push(item(baseline, {
|
|
96
|
+
type: "case-added",
|
|
97
|
+
ref,
|
|
98
|
+
case: question,
|
|
99
|
+
after: question
|
|
100
|
+
}));
|
|
101
|
+
for (const question of before.cases) if (!flow.cases.includes(question)) items.push(item(baseline, {
|
|
102
|
+
type: "case-removed",
|
|
103
|
+
ref,
|
|
104
|
+
case: question,
|
|
105
|
+
before: question
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
for (const ref of approved.keys()) if (!now.has(ref)) items.push(item(baseline, {
|
|
109
|
+
type: "flow-removed",
|
|
110
|
+
ref
|
|
111
|
+
}));
|
|
112
|
+
const proven = new Set(input.proofs.map((proof) => `${proof.ref} ${proof.criterion}`));
|
|
113
|
+
const seenProofs = /* @__PURE__ */ new Set();
|
|
114
|
+
for (const proof of baseline.proofs) {
|
|
115
|
+
const key = `${proof.ref} ${proof.criterion}`;
|
|
116
|
+
if (proven.has(key) || seenProofs.has(key)) continue;
|
|
117
|
+
seenProofs.add(key);
|
|
118
|
+
if (!now.get(proof.ref)?.criteria.some((criterion) => criterion.id === proof.criterion)) continue;
|
|
119
|
+
items.push(item(baseline, {
|
|
120
|
+
type: "proof-removed",
|
|
121
|
+
ref: proof.ref,
|
|
122
|
+
criterion: proof.criterion,
|
|
123
|
+
before: proof.testName ?? proof.testFile
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
items.push(...await shotDrift(input));
|
|
127
|
+
return items.sort((left, right) => left.ref.localeCompare(right.ref) || (left.criterion ?? "").localeCompare(right.criterion ?? "", "en", { numeric: true }) || left.id.localeCompare(right.id));
|
|
128
|
+
}
|
|
129
|
+
async function shotDrift(input) {
|
|
130
|
+
const { baseline } = input;
|
|
131
|
+
const items = [];
|
|
132
|
+
const shown = new Set(input.shows.filter((line) => line.call !== null).map((line) => `${line.ref} ${line.criterion}`));
|
|
133
|
+
const expected = input.languages.length > 0 ? input.languages : [""];
|
|
134
|
+
const approved = new Map(baseline.shots.map((shot) => [`${shot.ref} ${shot.criterion} ${shot.language}`, shot]));
|
|
135
|
+
const captured = new Map((input.captures?.captures ?? []).filter((capture) => capture.outcome === "pass" && capture.file !== null).map((capture) => [`${capture.ref} ${capture.criterion} ${capture.language}`, capture]));
|
|
136
|
+
for (const [key, capture] of captured) {
|
|
137
|
+
if (!shown.has(`${capture.ref} ${capture.criterion}`) || input.optedOut.includes(capture.ref)) continue;
|
|
138
|
+
const shot = approved.get(key);
|
|
139
|
+
const base = {
|
|
140
|
+
ref: capture.ref,
|
|
141
|
+
criterion: capture.criterion,
|
|
142
|
+
language: capture.language
|
|
143
|
+
};
|
|
144
|
+
if (shot === void 0) {
|
|
145
|
+
items.push(item(baseline, {
|
|
146
|
+
type: "shot-added",
|
|
147
|
+
...base,
|
|
148
|
+
capturedShot: capture.file
|
|
149
|
+
}));
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (capture.sha256 === shot.sha256) continue;
|
|
153
|
+
const [before, after] = await Promise.all([readImage(input.root, shot.file), readImage(input.root, capture.file ?? "")]);
|
|
154
|
+
if (after === null) continue;
|
|
155
|
+
if (before === null || comparePng(before, after).changed) items.push(item(baseline, {
|
|
156
|
+
type: "shot-changed",
|
|
157
|
+
...base,
|
|
158
|
+
approvedShot: shot.file,
|
|
159
|
+
capturedShot: capture.file
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
for (const [, shot] of approved) if (!shown.has(`${shot.ref} ${shot.criterion}`) || input.optedOut.includes(shot.ref) || !expected.includes(shot.language)) items.push(item(baseline, {
|
|
163
|
+
type: "shot-removed",
|
|
164
|
+
ref: shot.ref,
|
|
165
|
+
criterion: shot.criterion,
|
|
166
|
+
language: shot.language,
|
|
167
|
+
approvedShot: shot.file
|
|
168
|
+
}));
|
|
169
|
+
return items;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
export { computeDrift, currentFlows, driftId };
|
|
174
|
+
//# sourceMappingURL=drift.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/shots/drift.ts"],"sourcesContent":["/**\n * Drift: the current state of the flows, proving tests and captures against\n * the approved baseline. Ids are `<type>:<feature>/<flow>[:<AC-n>][:<language>|:<case>]`.\n */\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type {\n ApprovedBaseline,\n ApprovedFlow,\n DriftItem,\n DriftType,\n ShotCaptureIndex,\n ShowsLine,\n} from \"../contracts/shots\";\nimport type { ProofLine } from \"../contracts/test-results\";\nimport type { WrittenGrimoire } from \"../contracts/written\";\nimport { GRIMOIRE_PATHS } from \"../paths\";\nimport { comparePng } from \"./png\";\n\n/** Everything drift reads. */\nexport type DriftInput = {\n root: string;\n written: WrittenGrimoire;\n proofs: readonly ProofLine[];\n shows: readonly ShowsLine[];\n captures: ShotCaptureIndex | null;\n baseline: ApprovedBaseline;\n /** The languages scenes run in; `[]` for one unnamed language. */\n languages: readonly string[];\n /** Flows opted out of captures. */\n optedOut: readonly string[];\n};\n\n/** The flows of a written grimoire in the shape the baseline stores. */\nexport function currentFlows(written: WrittenGrimoire): ApprovedFlow[] {\n return written.features\n .flatMap((feature) => feature.flows)\n .map((flow) => ({\n ref: flow.ref,\n criteria: flow.criteria.map((criterion) => ({ id: criterion.id, text: criterion.text })),\n cases: [...new Set(flow.cases.map((entry) => entry.question))],\n }))\n .sort((left, right) => left.ref.localeCompare(right.ref));\n}\n\n/** The id of a drift item. */\nexport function driftId(\n type: DriftType,\n ref: string,\n criterion: string | null,\n extra: string | null,\n): string {\n return [type, ref, criterion, extra === \"\" ? null : extra]\n .filter((part) => part !== null)\n .join(\":\");\n}\n\nfunction item(\n baseline: ApprovedBaseline,\n fields: { type: DriftType; ref: string } & Partial<\n Omit<DriftItem, \"id\" | \"rejected\" | \"type\" | \"ref\">\n >,\n): DriftItem {\n const criterion = fields.criterion ?? null;\n const extra = fields.language ?? fields.case ?? null;\n const id = driftId(fields.type, fields.ref, criterion, extra);\n\n return {\n id,\n type: fields.type,\n ref: fields.ref,\n criterion,\n language: fields.language ?? null,\n case: fields.case ?? null,\n before: fields.before ?? null,\n after: fields.after ?? null,\n approvedShot: fields.approvedShot ?? null,\n capturedShot: fields.capturedShot ?? null,\n rejected: baseline.rejected.find((entry) => entry.id === id) ?? null,\n };\n}\n\nasync function readImage(root: string, file: string): Promise<Uint8Array | null> {\n try {\n return await readFile(\n path.join(root, ...GRIMOIRE_PATHS.screenshots.split(\"/\"), ...file.split(\"/\")),\n );\n } catch {\n return null;\n }\n}\n\n/** The differences of the current state from the approved baseline, in a stable order. */\nexport async function computeDrift(input: DriftInput): Promise<DriftItem[]> {\n const { baseline } = input;\n const items: DriftItem[] = [];\n const now = new Map(currentFlows(input.written).map((flow) => [flow.ref, flow]));\n const approved = new Map(baseline.flows.map((flow) => [flow.ref, flow]));\n\n for (const [ref, flow] of now) {\n const before = approved.get(ref);\n\n if (before === undefined) {\n items.push(item(baseline, { type: \"flow-added\", ref }));\n continue;\n }\n\n const beforeCriteria = new Map(\n before.criteria.map((criterion) => [criterion.id, criterion.text]),\n );\n const nowCriteria = new Map(flow.criteria.map((criterion) => [criterion.id, criterion.text]));\n\n for (const [id, text] of nowCriteria) {\n const old = beforeCriteria.get(id);\n\n if (old === undefined) {\n items.push(item(baseline, { type: \"criterion-added\", ref, criterion: id, after: text }));\n } else if (old !== text) {\n items.push(\n item(baseline, {\n type: \"criterion-changed\",\n ref,\n criterion: id,\n before: old,\n after: text,\n }),\n );\n }\n }\n\n for (const [id, text] of beforeCriteria) {\n if (!nowCriteria.has(id)) {\n items.push(item(baseline, { type: \"criterion-removed\", ref, criterion: id, before: text }));\n }\n }\n\n for (const question of flow.cases) {\n if (!before.cases.includes(question)) {\n items.push(item(baseline, { type: \"case-added\", ref, case: question, after: question }));\n }\n }\n\n for (const question of before.cases) {\n if (!flow.cases.includes(question)) {\n items.push(item(baseline, { type: \"case-removed\", ref, case: question, before: question }));\n }\n }\n }\n\n for (const ref of approved.keys()) {\n if (!now.has(ref)) items.push(item(baseline, { type: \"flow-removed\", ref }));\n }\n\n // A proving test is removed when the criterion has no `@proves` line left.\n const proven = new Set(input.proofs.map((proof) => `${proof.ref} ${proof.criterion}`));\n const seenProofs = new Set<string>();\n\n for (const proof of baseline.proofs) {\n const key = `${proof.ref} ${proof.criterion}`;\n\n if (proven.has(key) || seenProofs.has(key)) continue;\n\n seenProofs.add(key);\n // A removed flow or criterion is already reported by its own item.\n if (!now.get(proof.ref)?.criteria.some((criterion) => criterion.id === proof.criterion))\n continue;\n\n items.push(\n item(baseline, {\n type: \"proof-removed\",\n ref: proof.ref,\n criterion: proof.criterion,\n before: proof.testName ?? proof.testFile,\n }),\n );\n }\n\n items.push(...(await shotDrift(input)));\n\n return items.sort(\n (left, right) =>\n left.ref.localeCompare(right.ref) ||\n (left.criterion ?? \"\").localeCompare(right.criterion ?? \"\", \"en\", { numeric: true }) ||\n left.id.localeCompare(right.id),\n );\n}\n\nasync function shotDrift(input: DriftInput): Promise<DriftItem[]> {\n const { baseline } = input;\n const items: DriftItem[] = [];\n const shown = new Set(\n input.shows.filter((line) => line.call !== null).map((line) => `${line.ref} ${line.criterion}`),\n );\n const expected = input.languages.length > 0 ? input.languages : [\"\"];\n const approved = new Map(\n baseline.shots.map((shot) => [`${shot.ref} ${shot.criterion} ${shot.language}`, shot]),\n );\n const captured = new Map(\n (input.captures?.captures ?? [])\n .filter((capture) => capture.outcome === \"pass\" && capture.file !== null)\n .map((capture) => [`${capture.ref} ${capture.criterion} ${capture.language}`, capture]),\n );\n\n for (const [key, capture] of captured) {\n if (!shown.has(`${capture.ref} ${capture.criterion}`) || input.optedOut.includes(capture.ref)) {\n continue;\n }\n\n const shot = approved.get(key);\n const base = { ref: capture.ref, criterion: capture.criterion, language: capture.language };\n\n if (shot === undefined) {\n items.push(item(baseline, { type: \"shot-added\", ...base, capturedShot: capture.file }));\n continue;\n }\n\n if (capture.sha256 === shot.sha256) continue;\n\n const [before, after] = await Promise.all([\n readImage(input.root, shot.file),\n readImage(input.root, capture.file ?? \"\"),\n ]);\n\n // A capture whose file is gone proves nothing; an approved image that is gone cannot be compared.\n if (after === null) continue;\n\n if (before === null || comparePng(before, after).changed) {\n items.push(\n item(baseline, {\n type: \"shot-changed\",\n ...base,\n approvedShot: shot.file,\n capturedShot: capture.file,\n }),\n );\n }\n }\n\n for (const [, shot] of approved) {\n const gone =\n !shown.has(`${shot.ref} ${shot.criterion}`) ||\n input.optedOut.includes(shot.ref) ||\n !expected.includes(shot.language);\n\n if (gone) {\n items.push(\n item(baseline, {\n type: \"shot-removed\",\n ref: shot.ref,\n criterion: shot.criterion,\n language: shot.language,\n approvedShot: shot.file,\n }),\n );\n }\n }\n\n return items;\n}\n"],"mappings":";;;;;;;;;;;AAkCA,SAAgB,aAAa,SAA0C;CACrE,OAAO,QAAQ,SACZ,SAAS,YAAY,QAAQ,KAAK,CAAC,CACnC,KAAK,UAAU;EACd,KAAK,KAAK;EACV,UAAU,KAAK,SAAS,KAAK,eAAe;GAAE,IAAI,UAAU;GAAI,MAAM,UAAU;EAAK,EAAE;EACvF,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,MAAM,KAAK,UAAU,MAAM,QAAQ,CAAC,CAAC;CAC/D,EAAE,CAAC,CACF,MAAM,MAAM,UAAU,KAAK,IAAI,cAAc,MAAM,GAAG,CAAC;AAC5D;;AAGA,SAAgB,QACd,MACA,KACA,WACA,OACQ;CACR,OAAO;EAAC;EAAM;EAAK;EAAW,UAAU,KAAK,OAAO;CAAK,CAAC,CACvD,QAAQ,SAAS,SAAS,IAAI,CAAC,CAC/B,KAAK,GAAG;AACb;AAEA,SAAS,KACP,UACA,QAGW;CACX,MAAM,YAAY,OAAO,aAAa;CACtC,MAAM,QAAQ,OAAO,YAAY,OAAO,QAAQ;CAChD,MAAM,KAAK,QAAQ,OAAO,MAAM,OAAO,KAAK,WAAW,KAAK;CAE5D,OAAO;EACL;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACZ;EACA,UAAU,OAAO,YAAY;EA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E1F,IAAI,SAAS,QAAW;GACtB,MAAM,KAAK,KAAK,UAAU;IAAE,MAAM;IAAc,GAAG;IAAM,cAAc,QAAQ;GAAK,CAAC,CAAC;GACtF;EACF;EAEA,IAAI,QAAQ,WAAW,KAAK,QAAQ;EAEpC,MAAM,CAAC,QAAQ,SAAS,MAAM,QAAQ,IAAI,CACxC,UAAU,MAAM,MAAM,KAAK,IAAI,GAC/B,UAAU,MAAM,MAAM,QAAQ,QAAQ,EAAE,CAC1C,CAAC;EAGD,IAAI,UAAU,MAAM;EAEpB,IAAI,WAAW,QAAQ,WAAW,QAAQ,KAAK,CAAC,CAAC,SAC/C,MAAM,KACJ,KAAK,UAAU;GACb,MAAM;GACN,GAAG;GACH,cAAc,KAAK;GACnB,cAAc,QAAQ;EACxB,CAAC,CACH;CAEJ;CAEA,KAAK,MAAM,GAAG,SAAS,UAMrB,IAJE,CAAC,MAAM,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,WAAW,KAC1C,MAAM,SAAS,SAAS,KAAK,GAAG,KAChC,CAAC,SAAS,SAAS,KAAK,QAAQ,GAGhC,MAAM,KACJ,KAAK,UAAU;EACb,MAAM;EACN,KAAK,KAAK;EACV,WAAW,KAAK;EAChB,UAAU,KAAK;EACf,cAAc,KAAK;CACrB,CAAC,CACH;CAIJ,OAAO;AACT"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { inflateSync } from "node:zlib";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/grimoire/src/shots/png.ts
|
|
4
|
+
/**
|
|
5
|
+
* A small PNG decoder and comparer, `node:zlib` only. Chrome writes 8-bit,
|
|
6
|
+
* non-interlaced images (grey, grey+alpha, RGB or RGBA); anything else cannot
|
|
7
|
+
* be decoded here and the caller falls back to comparing the bytes.
|
|
8
|
+
*/
|
|
9
|
+
/** A pixel differs when any channel differs by more than this. */
|
|
10
|
+
const PIXEL_DELTA = 16;
|
|
11
|
+
/** An image changed when more than this share of its pixels differ (0.1%). */
|
|
12
|
+
const PIXEL_RATIO = .001;
|
|
13
|
+
const SIGNATURE = [
|
|
14
|
+
137,
|
|
15
|
+
80,
|
|
16
|
+
78,
|
|
17
|
+
71,
|
|
18
|
+
13,
|
|
19
|
+
10,
|
|
20
|
+
26,
|
|
21
|
+
10
|
|
22
|
+
];
|
|
23
|
+
const CHANNELS = {
|
|
24
|
+
0: 1,
|
|
25
|
+
2: 3,
|
|
26
|
+
4: 2,
|
|
27
|
+
6: 4
|
|
28
|
+
};
|
|
29
|
+
/** Decode a PNG, or `null` when it is not an 8-bit non-interlaced grey, RGB or RGBA image. */
|
|
30
|
+
function decodePng(bytes) {
|
|
31
|
+
if (bytes.length < 33 || SIGNATURE.some((value, index) => bytes[index] !== value)) return null;
|
|
32
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
33
|
+
let width = 0;
|
|
34
|
+
let height = 0;
|
|
35
|
+
let colorType = -1;
|
|
36
|
+
const chunks = [];
|
|
37
|
+
let offset = 8;
|
|
38
|
+
while (offset + 8 <= bytes.length) {
|
|
39
|
+
const length = view.getUint32(offset);
|
|
40
|
+
const type = String.fromCharCode(...bytes.subarray(offset + 4, offset + 8));
|
|
41
|
+
const body = bytes.subarray(offset + 8, offset + 8 + length);
|
|
42
|
+
if (type === "IHDR") {
|
|
43
|
+
if (length < 13) return null;
|
|
44
|
+
width = view.getUint32(offset + 8);
|
|
45
|
+
height = view.getUint32(offset + 12);
|
|
46
|
+
const depth = body[8];
|
|
47
|
+
colorType = body[9] ?? -1;
|
|
48
|
+
if (depth !== 8 || body[12] !== 0 || CHANNELS[colorType] === void 0) return null;
|
|
49
|
+
} else if (type === "IDAT") chunks.push(body);
|
|
50
|
+
else if (type === "IEND") break;
|
|
51
|
+
offset += 12 + length;
|
|
52
|
+
}
|
|
53
|
+
const channels = CHANNELS[colorType];
|
|
54
|
+
if (channels === void 0 || width === 0 || height === 0 || chunks.length === 0) return null;
|
|
55
|
+
let raw;
|
|
56
|
+
try {
|
|
57
|
+
raw = inflateSync(Buffer.concat(chunks));
|
|
58
|
+
} catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const stride = width * channels;
|
|
62
|
+
if (raw.length < height * (stride + 1)) return null;
|
|
63
|
+
const rows = new Uint8Array(height * stride);
|
|
64
|
+
for (let y = 0; y < height; y++) {
|
|
65
|
+
const filter = raw[y * (stride + 1)] ?? 0;
|
|
66
|
+
const source = y * (stride + 1) + 1;
|
|
67
|
+
const target = y * stride;
|
|
68
|
+
for (let x = 0; x < stride; x++) {
|
|
69
|
+
const value = raw[source + x] ?? 0;
|
|
70
|
+
const left = x >= channels ? rows[target + x - channels] ?? 0 : 0;
|
|
71
|
+
const up = y > 0 ? rows[target - stride + x] ?? 0 : 0;
|
|
72
|
+
const upLeft = y > 0 && x >= channels ? rows[target - stride + x - channels] ?? 0 : 0;
|
|
73
|
+
let predicted;
|
|
74
|
+
switch (filter) {
|
|
75
|
+
case 0:
|
|
76
|
+
predicted = 0;
|
|
77
|
+
break;
|
|
78
|
+
case 1:
|
|
79
|
+
predicted = left;
|
|
80
|
+
break;
|
|
81
|
+
case 2:
|
|
82
|
+
predicted = up;
|
|
83
|
+
break;
|
|
84
|
+
case 3:
|
|
85
|
+
predicted = left + up >> 1;
|
|
86
|
+
break;
|
|
87
|
+
case 4:
|
|
88
|
+
predicted = paeth(left, up, upLeft);
|
|
89
|
+
break;
|
|
90
|
+
default: return null;
|
|
91
|
+
}
|
|
92
|
+
rows[target + x] = value + predicted & 255;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const data = new Uint8Array(width * height * 4);
|
|
96
|
+
for (let pixel = 0; pixel < width * height; pixel++) {
|
|
97
|
+
const from = pixel * channels;
|
|
98
|
+
const to = pixel * 4;
|
|
99
|
+
if (channels === 4) data.set(rows.subarray(from, from + 4), to);
|
|
100
|
+
else if (channels === 3) {
|
|
101
|
+
data.set(rows.subarray(from, from + 3), to);
|
|
102
|
+
data[to + 3] = 255;
|
|
103
|
+
} else {
|
|
104
|
+
const grey = rows[from] ?? 0;
|
|
105
|
+
data[to] = grey;
|
|
106
|
+
data[to + 1] = grey;
|
|
107
|
+
data[to + 2] = grey;
|
|
108
|
+
data[to + 3] = channels === 2 ? rows[from + 1] ?? 255 : 255;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
width,
|
|
113
|
+
height,
|
|
114
|
+
data
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function paeth(left, up, upLeft) {
|
|
118
|
+
const estimate = left + up - upLeft;
|
|
119
|
+
const toLeft = Math.abs(estimate - left);
|
|
120
|
+
const toUp = Math.abs(estimate - up);
|
|
121
|
+
const toUpLeft = Math.abs(estimate - upLeft);
|
|
122
|
+
if (toLeft <= toUp && toLeft <= toUpLeft) return left;
|
|
123
|
+
return toUp <= toUpLeft ? up : upLeft;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Compare two images: changed when the size differs, or when more than 0.1%
|
|
127
|
+
* of the pixels differ by more than 16 in any channel. Equal bytes are never
|
|
128
|
+
* changed.
|
|
129
|
+
*/
|
|
130
|
+
function comparePng(before, after, limits = {}) {
|
|
131
|
+
if (Buffer.compare(before, after) === 0) return {
|
|
132
|
+
changed: false,
|
|
133
|
+
differing: 0,
|
|
134
|
+
ratio: 0
|
|
135
|
+
};
|
|
136
|
+
const left = decodePng(before);
|
|
137
|
+
const right = decodePng(after);
|
|
138
|
+
if (left === null || right === null) return {
|
|
139
|
+
changed: true,
|
|
140
|
+
differing: null,
|
|
141
|
+
ratio: null
|
|
142
|
+
};
|
|
143
|
+
if (left.width !== right.width || left.height !== right.height) return {
|
|
144
|
+
changed: true,
|
|
145
|
+
differing: null,
|
|
146
|
+
ratio: null
|
|
147
|
+
};
|
|
148
|
+
const delta = limits.delta ?? 16;
|
|
149
|
+
const allowed = limits.ratio ?? .001;
|
|
150
|
+
const pixels = left.width * left.height;
|
|
151
|
+
let differing = 0;
|
|
152
|
+
for (let pixel = 0; pixel < pixels; pixel++) {
|
|
153
|
+
const at = pixel * 4;
|
|
154
|
+
if (Math.abs((left.data[at] ?? 0) - (right.data[at] ?? 0)) > delta || Math.abs((left.data[at + 1] ?? 0) - (right.data[at + 1] ?? 0)) > delta || Math.abs((left.data[at + 2] ?? 0) - (right.data[at + 2] ?? 0)) > delta || Math.abs((left.data[at + 3] ?? 0) - (right.data[at + 3] ?? 0)) > delta) differing++;
|
|
155
|
+
}
|
|
156
|
+
const ratio = differing / pixels;
|
|
157
|
+
return {
|
|
158
|
+
changed: ratio > allowed,
|
|
159
|
+
differing,
|
|
160
|
+
ratio
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
export { PIXEL_RATIO, comparePng, decodePng };
|
|
166
|
+
//# sourceMappingURL=png.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"png.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/shots/png.ts"],"sourcesContent":["/**\n * A small PNG decoder and comparer, `node:zlib` only. Chrome writes 8-bit,\n * non-interlaced images (grey, grey+alpha, RGB or RGBA); anything else cannot\n * be decoded here and the caller falls back to comparing the bytes.\n */\nimport { inflateSync } from \"node:zlib\";\n\n/** A decoded image: 8-bit RGBA pixels, row after row. */\nexport type DecodedPng = { width: number; height: number; data: Uint8Array };\n\n/** How two images compare. */\nexport type PngComparison = {\n /** `true` when the size differs or more than `ratio` of the pixels differ by more than `delta` in a channel. */\n changed: boolean;\n /** Pixels that differ by more than the channel delta; `null` when the size differs. */\n differing: number | null;\n /** `differing` over the pixel count; `null` when the size differs. */\n ratio: number | null;\n};\n\n/** A pixel differs when any channel differs by more than this. */\nexport const PIXEL_DELTA = 16;\n/** An image changed when more than this share of its pixels differ (0.1%). */\nexport const PIXEL_RATIO = 0.001;\n\nconst SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];\nconst CHANNELS: Record<number, number> = { 0: 1, 2: 3, 4: 2, 6: 4 };\n\n/** Decode a PNG, or `null` when it is not an 8-bit non-interlaced grey, RGB or RGBA image. */\nexport function decodePng(bytes: Uint8Array): DecodedPng | null {\n if (bytes.length < 33 || SIGNATURE.some((value, index) => bytes[index] !== value)) return null;\n\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n let width = 0;\n let height = 0;\n let colorType = -1;\n const chunks: Uint8Array[] = [];\n let offset = 8;\n\n while (offset + 8 <= bytes.length) {\n const length = view.getUint32(offset);\n const type = String.fromCharCode(...bytes.subarray(offset + 4, offset + 8));\n const body = bytes.subarray(offset + 8, offset + 8 + length);\n\n if (type === \"IHDR\") {\n if (length < 13) return null;\n\n width = view.getUint32(offset + 8);\n height = view.getUint32(offset + 12);\n\n const depth = body[8];\n colorType = body[9] ?? -1;\n\n if (depth !== 8 || body[12] !== 0 || CHANNELS[colorType] === undefined) return null;\n } else if (type === \"IDAT\") {\n chunks.push(body);\n } else if (type === \"IEND\") {\n break;\n }\n\n offset += 12 + length;\n }\n\n const channels = CHANNELS[colorType];\n\n if (channels === undefined || width === 0 || height === 0 || chunks.length === 0) return null;\n\n let raw: Uint8Array;\n\n try {\n raw = inflateSync(Buffer.concat(chunks));\n } catch {\n return null;\n }\n\n const stride = width * channels;\n\n if (raw.length < height * (stride + 1)) return null;\n\n const rows = new Uint8Array(height * stride);\n\n for (let y = 0; y < height; y++) {\n const filter = raw[y * (stride + 1)] ?? 0;\n const source = y * (stride + 1) + 1;\n const target = y * stride;\n\n for (let x = 0; x < stride; x++) {\n const value = raw[source + x] ?? 0;\n const left = x >= channels ? (rows[target + x - channels] ?? 0) : 0;\n const up = y > 0 ? (rows[target - stride + x] ?? 0) : 0;\n const upLeft = y > 0 && x >= channels ? (rows[target - stride + x - channels] ?? 0) : 0;\n let predicted: number;\n\n switch (filter) {\n case 0:\n predicted = 0;\n break;\n case 1:\n predicted = left;\n break;\n case 2:\n predicted = up;\n break;\n case 3:\n predicted = (left + up) >> 1;\n break;\n case 4:\n predicted = paeth(left, up, upLeft);\n break;\n default:\n return null;\n }\n\n rows[target + x] = (value + predicted) & 0xff;\n }\n }\n\n const data = new Uint8Array(width * height * 4);\n\n for (let pixel = 0; pixel < width * height; pixel++) {\n const from = pixel * channels;\n const to = pixel * 4;\n\n if (channels === 4) {\n data.set(rows.subarray(from, from + 4), to);\n } else if (channels === 3) {\n data.set(rows.subarray(from, from + 3), to);\n data[to + 3] = 255;\n } else {\n const grey = rows[from] ?? 0;\n\n data[to] = grey;\n data[to + 1] = grey;\n data[to + 2] = grey;\n data[to + 3] = channels === 2 ? (rows[from + 1] ?? 255) : 255;\n }\n }\n\n return { width, height, data };\n}\n\nfunction paeth(left: number, up: number, upLeft: number): number {\n const estimate = left + up - upLeft;\n const toLeft = Math.abs(estimate - left);\n const toUp = Math.abs(estimate - up);\n const toUpLeft = Math.abs(estimate - upLeft);\n\n if (toLeft <= toUp && toLeft <= toUpLeft) return left;\n\n return toUp <= toUpLeft ? up : upLeft;\n}\n\n/**\n * Compare two images: changed when the size differs, or when more than 0.1%\n * of the pixels differ by more than 16 in any channel. Equal bytes are never\n * changed.\n */\nexport function comparePng(\n before: Uint8Array,\n after: Uint8Array,\n limits: { delta?: number; ratio?: number } = {},\n): PngComparison {\n if (Buffer.compare(before, after) === 0) return { changed: false, differing: 0, ratio: 0 };\n\n const left = decodePng(before);\n const right = decodePng(after);\n\n // Not decodable here: the bytes differ, so the image counts as changed.\n if (left === null || right === null) return { changed: true, differing: null, ratio: null };\n if (left.width !== right.width || left.height !== right.height) {\n return { changed: true, differing: null, ratio: null };\n }\n\n const delta = limits.delta ?? PIXEL_DELTA;\n const allowed = limits.ratio ?? PIXEL_RATIO;\n const pixels = left.width * left.height;\n let differing = 0;\n\n for (let pixel = 0; pixel < pixels; pixel++) {\n const at = pixel * 4;\n\n if (\n Math.abs((left.data[at] ?? 0) - (right.data[at] ?? 0)) > delta ||\n Math.abs((left.data[at + 1] ?? 0) - (right.data[at + 1] ?? 0)) > delta ||\n Math.abs((left.data[at + 2] ?? 0) - (right.data[at + 2] ?? 0)) > delta ||\n Math.abs((left.data[at + 3] ?? 0) - (right.data[at + 3] ?? 0)) > delta\n ) {\n differing++;\n }\n }\n\n const ratio = differing / pixels;\n\n return { changed: ratio > allowed, differing, ratio };\n}\n"],"mappings":";;;;;;;;;AAqBA,MAAa,cAAc;;AAE3B,MAAa,cAAc;AAE3B,MAAM,YAAY;CAAC;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI;AACjE,MAAM,WAAmC;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;;AAGlE,SAAgB,UAAU,OAAsC;CAC9D,IAAI,MAAM,SAAS,MAAM,UAAU,MAAM,OAAO,UAAU,MAAM,WAAW,KAAK,GAAG,OAAO;CAE1F,MAAM,OAAO,IAAI,SAAS,MAAM,QAAQ,MAAM,YAAY,MAAM,UAAU;CAC1E,IAAI,QAAQ;CACZ,IAAI,SAAS;CACb,IAAI,YAAY;CAChB,MAAM,SAAuB,CAAC;CAC9B,IAAI,SAAS;CAEb,OAAO,SAAS,KAAK,MAAM,QAAQ;EACjC,MAAM,SAAS,KAAK,UAAU,MAAM;EACpC,MAAM,OAAO,OAAO,aAAa,GAAG,MAAM,SAAS,SAAS,GAAG,SAAS,CAAC,CAAC;EAC1E,MAAM,OAAO,MAAM,SAAS,SAAS,GAAG,SAAS,IAAI,MAAM;EAE3D,IAAI,SAAS,QAAQ;GACnB,IAAI,SAAS,IAAI,OAAO;GAExB,QAAQ,KAAK,UAAU,SAAS,CAAC;GACjC,SAAS,KAAK,UAAU,SAAS,EAAE;GAEnC,MAAM,QAAQ,KAAK;GACnB,YAAY,KAAK,MAAM;GAEvB,IAAI,UAAU,KAAK,KAAK,QAAQ,KAAK,SAAS,eAAe,QAAW,OAAO;EACjF,OAAO,IAAI,SAAS,QAClB,OAAO,KAAK,IAAI;OACX,I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