tagreeve 0.4.0-rc.1 → 0.4.0-rc.2
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/README.md +5 -2
- package/dist/{chunk-HFTQRDHQ.js → chunk-2QH7GCQL.js} +505 -131
- package/dist/cli.js +1 -1
- package/dist/pingwright.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
Agent-first testing for tags and consent. Tagreeve plays a visitor in a real browser, records every tracking hit the site sends, and checks the result against what you expect. Tag-firing reports (which tags fired) are planned.
|
|
11
11
|
|
|
12
|
-
> **Status: 0.4 (`0.4.0-rc.
|
|
12
|
+
> **Status: 0.4 (`0.4.0-rc.2`).** Tagreeve plays a visitor in Chromium, records and decodes hits, answers the consent banner, checks YAML expectations and writes a JSONL record. 0.3 adds rules on payload fields and cookies, a `deniedIdentifiers` check, `tagreeve suite`, an HTML report, a Done control for handoff steps, role-based locators and a `select` step. 0.4 adds handoffs that end by themselves, an opt-in test payment step, baselines, a viewport option and fake identities by country. The rest of this README describes where Tagreeve is going, and marks what is not built yet. The design is in [docs/design.md](docs/design.md). Feedback is welcome in issues.
|
|
13
13
|
>
|
|
14
14
|
> **In 0.1:** `tagreeve run` with `stub` and `live` network modes; consent epochs, with withdrawals labelled apart from first rejects; seeded fake identities, hash checks and leak detection; decoders for GA4, Google Ads, Meta, Stape custom loader and a minimal server-container data client; banner handling through autoconsent; expectations; JSONL output.
|
|
15
15
|
>
|
|
@@ -17,6 +17,8 @@ Agent-first testing for tags and consent. Tagreeve plays a visitor in a real bro
|
|
|
17
17
|
>
|
|
18
18
|
> **In 0.3:** `body.has` and `body.only` rules on the field names of a hit; `cookie` rules; a `deniedIdentifiers` check that fails when an identifier goes out on a denied hit; `tagreeve suite` runs a folder of scenarios against several GTM builds; `tagreeve report` writes an HTML report of one run or a suite; a Done button in the handoff window; `click` and `wait` by role and name or from a list of selectors; a `select` step; the `server` network mode; record schema version 2. `deniedIdentifiers` fails by default, so a run that passed in 0.2 can exit 1. See [CHANGELOG.md](CHANGELOG.md).
|
|
19
19
|
>
|
|
20
|
+
> **In 0.4.0-rc.2** (install with `npm i -g tagreeve@next` until 0.4.0): a test payment host can declare its test mode in the allowlist, and the page marker must sit inside the card form; `possibleRealData` names the path of a value in a JSON or form body; baselines compare scenario names without the file extension, ignore key order, and warn when a hit moves across one consent answer; the `earlyIdentifiers` check warns about identifiers sent before the first answer; a usage error prints one line, not the full help. What is still open is in [CHANGELOG.md](CHANGELOG.md) under "Known in 0.4.0-rc.2".
|
|
21
|
+
>
|
|
20
22
|
> **In 0.4.0-rc.1** (install with `npm i -g tagreeve@next` until 0.4.0): a `handoff` step can end at a URL or an element (`until`, `settle`, `timeout`); a `payment` step types a provider's test card on a store you allow, with three opt-in checks; `tagreeve baseline save` and `run --baseline` catch drift in the shape of a run; `--viewport <W>x<H>`; `identity.country` picks the format of the fake identity (US, SE, GB, DE); optional `fill` entries; a `possibleRedirectHop` flag; and the rename to Tagreeve. What is still open is in [CHANGELOG.md](CHANGELOG.md) under "Known in 0.4.0-rc.1".
|
|
21
23
|
>
|
|
22
24
|
> **Not built yet:** the server tag reporter, several stores in one suite, a Shopify bridge, a full Microsoft UET decoder, a `mobile` viewport preset, Firefox and WebKit. There is no MCP server: Tagreeve is a CLI, and agents read `--json`.
|
|
@@ -161,6 +163,7 @@ options:
|
|
|
161
163
|
- `body.has` matches hits by the names of the fields they sent, and `body.only` is an allowlist of field names. They read names, never values.
|
|
162
164
|
- `cookie` checks which cookies were set, by name, before or after consent. In `stub` mode a stubbed endpoint sets no cookies, so use `--network server` with `options.serverHosts` to see the cookies of a server container.
|
|
163
165
|
- `deniedIdentifiers` is a built-in check. It fails when a hit carries `user_id`, `uid`, a hashed `user_data` field or another identifier while the matching consent signal is denied. It is `fail` by default. Set it to `warn` to keep the old exit code while you fix the cause.
|
|
166
|
+
- `earlyIdentifiers` is a built-in check. It warns when a hit sent before the first consent answer carries an identifier and its consent signal is unknown, for example a hashed email on a page with no Consent Mode default. It is `warn` by default, so the exit code stays the same. Set it to `fail` to fail the run.
|
|
164
167
|
- `click` and `wait` take `{ role, name }` or `{ any: [selectors] }`, so a theme change does not break every scenario. `select` chooses an option of a `<select>` by value, then by label, and reads it back.
|
|
165
168
|
|
|
166
169
|
## Tracker list
|
|
@@ -181,7 +184,7 @@ tagreeve run scenario.yml --site https://staging.example.com --tracker-list trac
|
|
|
181
184
|
|
|
182
185
|
- **Known collection endpoints are stubbed by default.** Scripts load normally, but requests to known collection endpoints are recorded and answered locally. Unknown destinations pass through, so test hits can still reach vendors that way. Requests to hosts outside the site's registrable domain are flagged when they are `fetch`, `xhr`, `ping` or `beacon` requests, or images or other requests that carry a query or a body. They are flagged as `unknownDestination`. Scripts, stylesheets, fonts and documents are not flagged. Requests a sandboxed `srcdoc` iframe sends while it loads can escape stubbing and recording (design §5.3). Tagreeve lets them through because blocking by host would stop vendor scripts from loading and make a broken setup look compliant. Use `--network live` to let everything through.
|
|
183
186
|
- **Fake identities.** Every run uses a generated test identity. Tagreeve flags any email, phone number or hashed identifier in a recording that does not belong to that identity.
|
|
184
|
-
- **No log-ins, and payments only as an opt-in test.** On a hosted site a log-in is always a handoff step for a person, who should use test accounts. A payment is a handoff step too, except for the opt-in `payment` step, which types a provider's documented test card after three checks: `--allow-test-payment <host>`, the host in your allowlist file, and the provider's test mode
|
|
187
|
+
- **No log-ins, and payments only as an opt-in test.** On a hosted site a log-in is always a handoff step for a person, who should use test accounts. A payment is a handoff step too, except for the opt-in `payment` step, which types a provider's documented test card after three checks: `--allow-test-payment <host>`, the host in your allowlist file, and the provider's test mode, which you declare for the host in that file or which the page shows inside the card form. Only loopback hosts, such as the fixture shop, may be automated through a fake payment form.
|
|
185
188
|
- **You own the data.** There is no Tagreeve-hosted service. When server-side reports are built, they will go to a sink you run: a tunnel to your machine, or a small Worker in your own Cloudflare account.
|
|
186
189
|
|
|
187
190
|
## For agents
|
|
@@ -373,18 +373,22 @@ function tryUrlDecode(text2) {
|
|
|
373
373
|
var utf8Lenient = new TextDecoder("utf-8");
|
|
374
374
|
var EDGE = 4;
|
|
375
375
|
var MIN_BYTES_FOR_EDGES = 12;
|
|
376
|
+
function binaryShare(text2) {
|
|
377
|
+
if (text2.length === 0) return 0;
|
|
378
|
+
let binary = 0;
|
|
379
|
+
for (let i = 0; i < text2.length; i++) {
|
|
380
|
+
const c = text2.charCodeAt(i);
|
|
381
|
+
if (c === 65533 || c < 32 && c !== 9 && c !== 10 && c !== 13 || c === 127) binary++;
|
|
382
|
+
}
|
|
383
|
+
return binary / text2.length;
|
|
384
|
+
}
|
|
376
385
|
function tryBase64Decode(token) {
|
|
377
386
|
const bytes = Buffer.from(token.replace(/-/g, "+").replace(/_/g, "/"), "base64");
|
|
378
387
|
if (bytes.length < 8) return void 0;
|
|
379
388
|
const text2 = utf8Lenient.decode(bytes);
|
|
380
389
|
const inner = bytes.length >= MIN_BYTES_FOR_EDGES ? [...text2].slice(EDGE, -EDGE) : [...text2];
|
|
381
390
|
if (inner.length < 4) return void 0;
|
|
382
|
-
|
|
383
|
-
for (const ch of inner) {
|
|
384
|
-
const c = ch.codePointAt(0);
|
|
385
|
-
if (c < 32 && c !== 9 && c !== 10 && c !== 13 || c === 127 || c === 65533) control++;
|
|
386
|
-
}
|
|
387
|
-
return control / inner.length <= 0.05 ? text2 : void 0;
|
|
391
|
+
return binaryShare(inner.join("")) <= 0.05 ? text2 : void 0;
|
|
388
392
|
}
|
|
389
393
|
function hasUrlEscapes(text2) {
|
|
390
394
|
const decoded = tryUrlDecode(text2);
|
|
@@ -531,30 +535,52 @@ function ownValues(identity) {
|
|
|
531
535
|
const extraPhones = extra.map((v) => v.replace(/\D/g, "")).filter((v) => v.length >= 8);
|
|
532
536
|
return { email, phoneDigits, nationalDigits: format.nationalDigits(phoneDigits), hashes, extraEmails, extraPhones };
|
|
533
537
|
}
|
|
534
|
-
function
|
|
535
|
-
const own = ownValues(identity);
|
|
536
|
-
const found = /* @__PURE__ */ new Map();
|
|
537
|
-
const add2 = (kind, value) => {
|
|
538
|
-
const key = `${kind}:${value}`;
|
|
539
|
-
if (!found.has(key)) found.set(key, { kind, value });
|
|
540
|
-
};
|
|
538
|
+
function* candidates(text2) {
|
|
541
539
|
for (const variant of variants(text2)) {
|
|
542
|
-
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
540
|
+
if (!hasUrlEscapes(variant)) {
|
|
541
|
+
for (const raw of variant.match(EMAIL) ?? []) {
|
|
542
|
+
const m = raw.slice(raw.lastIndexOf("+") + 1);
|
|
543
|
+
if (!m.includes("@") || FILE_EXTENSION.test(m)) continue;
|
|
544
|
+
const both = raw !== m && raw.indexOf("+") === raw.lastIndexOf("+") && !raw.startsWith("+");
|
|
545
|
+
yield { kind: "email", value: m, alternate: both ? raw : void 0, variant, index: 0 };
|
|
546
|
+
}
|
|
547
547
|
}
|
|
548
548
|
for (const m of variant.match(PHONE) ?? []) {
|
|
549
549
|
const digits = m.replace(/\D/g, "");
|
|
550
550
|
if (digits.length < 8 || digits.length > 15) continue;
|
|
551
551
|
if (/^\+\d+\+/.test(m) && !/^\+\d{1,3}\+/.test(m)) continue;
|
|
552
|
-
|
|
552
|
+
yield { kind: "phone", value: m, variant, index: 0 };
|
|
553
|
+
}
|
|
554
|
+
if (!hasUrlEscapes(variant)) {
|
|
555
|
+
for (const m of variant.matchAll(HASH)) yield { kind: "hash", value: m[0].toLowerCase(), variant, index: m.index };
|
|
553
556
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
function valueKinds(text2) {
|
|
560
|
+
const kinds = /* @__PURE__ */ new Set();
|
|
561
|
+
for (const c of candidates(text2)) kinds.add(c.kind);
|
|
562
|
+
return kinds;
|
|
563
|
+
}
|
|
564
|
+
function scan(text2, identity, options = {}) {
|
|
565
|
+
const own = ownValues(identity);
|
|
566
|
+
const found = /* @__PURE__ */ new Map();
|
|
567
|
+
const add2 = (kind, value) => {
|
|
568
|
+
const key = `${kind}:${value}`;
|
|
569
|
+
if (!found.has(key)) found.set(key, { kind, value });
|
|
570
|
+
};
|
|
571
|
+
for (const c of candidates(text2)) {
|
|
572
|
+
if (c.kind === "email") {
|
|
573
|
+
if (normalizeEmail(c.value).includes(own.email) || own.extraEmails.includes(normalizeEmail(c.value))) continue;
|
|
574
|
+
add2("email", c.value);
|
|
575
|
+
if (c.alternate) add2("email", c.alternate);
|
|
576
|
+
} else if (c.kind === "phone") {
|
|
577
|
+
const digits = c.value.replace(/\D/g, "");
|
|
578
|
+
if (!digits.includes(own.phoneDigits) && !digits.includes(own.nationalDigits) && !own.extraPhones.includes(digits)) add2("phone", c.value);
|
|
579
|
+
} else if (!own.hashes.has(c.value) && !options.stableHashes?.has(c.value) && !isNonPersonalKey(c.variant, c.index)) {
|
|
580
|
+
add2("hash", c.value);
|
|
557
581
|
}
|
|
582
|
+
}
|
|
583
|
+
for (const variant of variants(text2)) {
|
|
558
584
|
for (const token of hasUrlEscapes(variant) ? [] : keyedDigests(variant)) {
|
|
559
585
|
if (!own.hashes.has(token.replace(/=+$/, ""))) add2("hash", token);
|
|
560
586
|
}
|
|
@@ -646,7 +672,11 @@ function looksLikeValue(segment) {
|
|
|
646
672
|
}
|
|
647
673
|
function guardFieldName(name) {
|
|
648
674
|
if (name.includes("@")) return OTHER_NAME;
|
|
649
|
-
|
|
675
|
+
for (const reading of [name, name.replace(/\[\]/g, "")]) {
|
|
676
|
+
const kinds = valueKinds(reading);
|
|
677
|
+
if (kinds.has("email") || kinds.has("phone")) return OTHER_NAME;
|
|
678
|
+
}
|
|
679
|
+
return name.split(".").map((segment) => looksLikeValue(segment.replace(/\[\]/g, "")) ? OTHER_NAME : segment).join(".");
|
|
650
680
|
}
|
|
651
681
|
function queryEntries(params) {
|
|
652
682
|
const out = [];
|
|
@@ -674,6 +704,40 @@ function bodyEntries(req) {
|
|
|
674
704
|
}
|
|
675
705
|
return { entries: queryEntries(new URLSearchParams(text2)), parsed: true };
|
|
676
706
|
}
|
|
707
|
+
function splitMultipart(body, headers) {
|
|
708
|
+
const contentType = Object.entries(headers).find(([k]) => k.toLowerCase() === "content-type")?.[1] ?? "";
|
|
709
|
+
const m = /multipart\/form-data;.*?boundary=(?:"([^"]+)"|([^;\s]+))/i.exec(contentType);
|
|
710
|
+
const boundary = m?.[1] ?? m?.[2];
|
|
711
|
+
if (!boundary) return null;
|
|
712
|
+
const [preamble = "", ...rest] = body.split(`--${boundary}`);
|
|
713
|
+
const parts = [];
|
|
714
|
+
const epilogue = [];
|
|
715
|
+
const chunks = [{ raw: preamble, part: null }];
|
|
716
|
+
for (const raw of rest) {
|
|
717
|
+
const part = raw.startsWith("--") ? null : parseChunk(raw);
|
|
718
|
+
if (raw.startsWith("--")) epilogue.push(raw);
|
|
719
|
+
else if (part) parts.push(part);
|
|
720
|
+
chunks.push({ raw, part });
|
|
721
|
+
}
|
|
722
|
+
return { boundary, preamble, parts, epilogue: epilogue.join(`--${boundary}`), chunks };
|
|
723
|
+
}
|
|
724
|
+
function parseChunk(raw) {
|
|
725
|
+
const split = /\r?\n\r?\n/.exec(raw);
|
|
726
|
+
if (!split) return null;
|
|
727
|
+
const headers = {};
|
|
728
|
+
for (const line of raw.slice(0, split.index).split(/\r?\n/)) {
|
|
729
|
+
const colon = line.indexOf(":");
|
|
730
|
+
if (colon > 0) headers[line.slice(0, colon).trim().toLowerCase()] = line.slice(colon + 1).trim();
|
|
731
|
+
}
|
|
732
|
+
const bodyStart = split.index + split[0].length;
|
|
733
|
+
return { headers, body: raw.slice(bodyStart).replace(/\r?\n$/, ""), raw, bodyStart };
|
|
734
|
+
}
|
|
735
|
+
function multipartParts(body, headers) {
|
|
736
|
+
return splitMultipart(body, headers)?.parts ?? null;
|
|
737
|
+
}
|
|
738
|
+
function multipartPartName(part) {
|
|
739
|
+
return /\bname="([^"]*)"/i.exec(part.headers["content-disposition"] ?? "")?.[1];
|
|
740
|
+
}
|
|
677
741
|
function bodyComplete(req) {
|
|
678
742
|
if (req.postData === null) return !(req.captured === "netlog" && BODY_METHODS.has(req.method.toUpperCase()));
|
|
679
743
|
return req.postData.length < MAX_POST_DATA;
|
|
@@ -897,24 +961,17 @@ function isMetaTr(req) {
|
|
|
897
961
|
return false;
|
|
898
962
|
}
|
|
899
963
|
}
|
|
900
|
-
function
|
|
964
|
+
function bodyFields(req) {
|
|
965
|
+
const body = req.postData ?? "";
|
|
966
|
+
const parts = multipartParts(body, req.headers);
|
|
967
|
+
if (!parts) return new URLSearchParams(body);
|
|
901
968
|
const fields2 = [];
|
|
902
|
-
for (const part of
|
|
903
|
-
const
|
|
904
|
-
if (
|
|
905
|
-
const name = /content-disposition:[^\r\n]*?\bname="([^"]*)"/i.exec(part.slice(0, split.index))?.[1];
|
|
906
|
-
if (name === void 0) continue;
|
|
907
|
-
fields2.push([name, part.slice(split.index + split[0].length).replace(/\r?\n$/, "")]);
|
|
969
|
+
for (const part of parts) {
|
|
970
|
+
const name = multipartPartName(part);
|
|
971
|
+
if (name !== void 0) fields2.push([name, part.body]);
|
|
908
972
|
}
|
|
909
973
|
return fields2;
|
|
910
974
|
}
|
|
911
|
-
function bodyFields(req) {
|
|
912
|
-
const body = req.postData ?? "";
|
|
913
|
-
const contentType = Object.entries(req.headers).find(([k]) => k.toLowerCase() === "content-type")?.[1] ?? "";
|
|
914
|
-
const m = /multipart\/form-data;.*?boundary=(?:"([^"]+)"|([^;\s]+))/i.exec(contentType);
|
|
915
|
-
const boundary = m?.[1] ?? m?.[2];
|
|
916
|
-
return boundary ? multipartFields(body, boundary) : new URLSearchParams(body);
|
|
917
|
-
}
|
|
918
975
|
function allParams(req) {
|
|
919
976
|
const merged = new URLSearchParams(new URL(req.url).search);
|
|
920
977
|
if (req.method === "POST" && req.postData) {
|
|
@@ -1565,7 +1622,7 @@ function parseViewportText(text2) {
|
|
|
1565
1622
|
return isViewportSide(viewport.width) && isViewportSide(viewport.height) ? viewport : void 0;
|
|
1566
1623
|
}
|
|
1567
1624
|
var VIEWPORT_HINT = `a size such as 390x844, with each side from ${VIEWPORT_MIN} to ${VIEWPORT_MAX}`;
|
|
1568
|
-
var BUILTIN_NAMES = ["unknownDestination", "sandboxPageUrl", "possibleRealData", "deniedIdentifiers"];
|
|
1625
|
+
var BUILTIN_NAMES = ["unknownDestination", "sandboxPageUrl", "possibleRealData", "deniedIdentifiers", "earlyIdentifiers"];
|
|
1569
1626
|
var SEVERITIES = ["fail", "warn"];
|
|
1570
1627
|
var IDENTITY_FIELDS = ["firstName", "lastName", "email", "phone", "address1", "city", "zip", "country"];
|
|
1571
1628
|
var ScenarioError = class extends Error {
|
|
@@ -2209,7 +2266,7 @@ function evaluate(records, scenario, options = {}) {
|
|
|
2209
2266
|
function evaluateRule(rule, ctx) {
|
|
2210
2267
|
if (rule.cookie) return evaluateCookieRule(rule, rule.cookie, ctx);
|
|
2211
2268
|
let hits = ctx.hits.filter((h) => matchesFilter(h, rule.filter, ctx));
|
|
2212
|
-
const
|
|
2269
|
+
const total2 = hits.length;
|
|
2213
2270
|
const narrowed = [];
|
|
2214
2271
|
if (rule.before) {
|
|
2215
2272
|
hits = hits.filter((h) => isBeforeConsent(h, ctx));
|
|
@@ -2232,9 +2289,9 @@ function evaluateRule(rule, ctx) {
|
|
|
2232
2289
|
}
|
|
2233
2290
|
const where2 = narrowed.length ? ` ${narrowed.join(", ")}` : "";
|
|
2234
2291
|
const vacuous = rule.before ? vacuousBeforeConsent(rule, ctx) : void 0;
|
|
2235
|
-
if (rule.body) return evaluateBodyRule(rule, rule.body, hits, where2,
|
|
2292
|
+
if (rule.body) return evaluateBodyRule(rule, rule.body, hits, where2, total2, vacuous);
|
|
2236
2293
|
const ids = hits.map((h) => h.id);
|
|
2237
|
-
const found = `found ${hits.length} matching hit${hits.length === 1 ? "" : "s"}${narrowed.length ? ` (${
|
|
2294
|
+
const found = `found ${hits.length} matching hit${hits.length === 1 ? "" : "s"}${narrowed.length ? ` (${total2} before narrowing)` : ""}`;
|
|
2238
2295
|
if (rule.kind === "mustNot") {
|
|
2239
2296
|
return {
|
|
2240
2297
|
pass: hits.length === 0,
|
|
@@ -2328,7 +2385,7 @@ function inEpochAt(t, selector, ctx) {
|
|
|
2328
2385
|
}
|
|
2329
2386
|
function evaluateCookieRule(rule, patterns, ctx) {
|
|
2330
2387
|
let sightings = cookieSightings(patterns.map((p) => globToRegExp(p)), ctx);
|
|
2331
|
-
const
|
|
2388
|
+
const total2 = sightings.length;
|
|
2332
2389
|
const narrowed = [];
|
|
2333
2390
|
let from;
|
|
2334
2391
|
if (rule.after) {
|
|
@@ -2376,8 +2433,8 @@ function evaluateCookieRule(rule, patterns, ctx) {
|
|
|
2376
2433
|
const headerOnly = sources.length === 1 && sources[0] === "Set-Cookie";
|
|
2377
2434
|
const requests = new Set(sightings.map((s) => s.evidence)).size;
|
|
2378
2435
|
const storage = sightings.length ? storageText(sightings, ctx) : void 0;
|
|
2379
|
-
const count = headerOnly ? `${requests} request${requests === 1 ? "" : "s"}` : `${
|
|
2380
|
-
const found = sightings.length ? `found ${listNames(names)} from ${sources.join(" and ")} (${count})${storage ? `; ${storage.text}` : ""}${sources.some((s) => s !== "Set-Cookie") ? ". A checkpoint shows the cookie was present then, not when it was set" : ""}` : `found no matching cookie (${
|
|
2436
|
+
const count = headerOnly ? `${requests} request${requests === 1 ? "" : "s"}` : `${total2} before narrowing`;
|
|
2437
|
+
const found = sightings.length ? `found ${listNames(names)} from ${sources.join(" and ")} (${count})${storage ? `; ${storage.text}` : ""}${sources.some((s) => s !== "Set-Cookie") ? ". A checkpoint shows the cookie was present then, not when it was set" : ""}` : `found no matching cookie (${total2} before narrowing)`;
|
|
2381
2438
|
const expected = rule.kind === "must" ? `Expected a matching cookie${where2}` : `Expected no matching cookie${where2}`;
|
|
2382
2439
|
const stubbed = low && rule.kind === "mustNot" && ctx.networkMode === "stub";
|
|
2383
2440
|
return {
|
|
@@ -2414,7 +2471,7 @@ function nestedNames(plain, hits) {
|
|
|
2414
2471
|
for (const field of hit.fields ?? []) if (field.includes(".") && wanted.has(field.slice(field.lastIndexOf(".") + 1))) found.add(guardFieldName(field));
|
|
2415
2472
|
return [...found].sort();
|
|
2416
2473
|
}
|
|
2417
|
-
function evaluateBodyRule(rule, body, selected, where2,
|
|
2474
|
+
function evaluateBodyRule(rule, body, selected, where2, total2, vacuous) {
|
|
2418
2475
|
const tail = vacuous ? ` ${vacuous}` : "";
|
|
2419
2476
|
const narrowed = `${selected.length} selected hit${selected.length === 1 ? "" : "s"}${where2}`;
|
|
2420
2477
|
if (body.has) {
|
|
@@ -2440,7 +2497,7 @@ function evaluateBodyRule(rule, body, selected, where2, total, vacuous) {
|
|
|
2440
2497
|
const expected = rule.kind === "must" ? `Expected ${describeCount(count)} hits with body.has fields${where2}` : `Expected no hit with body.has fields${where2}`;
|
|
2441
2498
|
const nested = matching.length ? [] : nestedNames(body.has.filter((n) => !n.includes("*")), selected);
|
|
2442
2499
|
const nestedText = nested.length ? `; no top-level match; nested fields with this name: ${listNames(nested)}` : "";
|
|
2443
|
-
return { pass: low, evidence, message: `${expected}, ${found} (${
|
|
2500
|
+
return { pass: low, evidence, message: `${expected}, ${found} (${total2} before narrowing)${nestedText}.${tail}`, ...nested.length && { note: "nestedNameOnly" } };
|
|
2444
2501
|
}
|
|
2445
2502
|
const only = body.only;
|
|
2446
2503
|
const allowed = [...only, ...body.ignore ?? []].map(fieldGlob);
|
|
@@ -2664,16 +2721,24 @@ function checkHashes(hits, ctx) {
|
|
|
2664
2721
|
const wrongParams = /* @__PURE__ */ new Set();
|
|
2665
2722
|
const matchedFields = /* @__PURE__ */ new Set();
|
|
2666
2723
|
const unhashedFields = /* @__PURE__ */ new Set();
|
|
2724
|
+
const plainAddressFields = /* @__PURE__ */ new Set();
|
|
2725
|
+
const uncheckedFields = /* @__PURE__ */ new Set();
|
|
2667
2726
|
for (const hit of hits) {
|
|
2668
2727
|
let seen = false;
|
|
2669
2728
|
let bad = false;
|
|
2670
2729
|
let raw = false;
|
|
2730
|
+
if (hit.vendor === "meta") {
|
|
2731
|
+
for (const id of Object.keys(hit.ids)) if (id !== "hashedEmail" && id !== "hashedPhone") uncheckedFields.add(guardFieldName(id));
|
|
2732
|
+
}
|
|
2671
2733
|
for (const [name, value] of Object.entries(hit.params)) {
|
|
2672
2734
|
const field = FIELD_PARAMS[name]?.(identity);
|
|
2673
2735
|
const accepted = field === void 0 ? [] : [field, ...extra];
|
|
2674
2736
|
const known = EMAIL_PARAM.test(name) ? emailHashes : PHONE_PARAM.test(name) ? phoneHashes : field !== void 0 ? fieldHashes(...accepted) : void 0;
|
|
2675
2737
|
if (!known || !value) continue;
|
|
2676
|
-
if (PLAIN_ADDRESS_PARAMS.has(name) && !DIGEST_SHAPE.test(value))
|
|
2738
|
+
if (PLAIN_ADDRESS_PARAMS.has(name) && !DIGEST_SHAPE.test(value)) {
|
|
2739
|
+
plainAddressFields.add(fieldLabel(name));
|
|
2740
|
+
continue;
|
|
2741
|
+
}
|
|
2677
2742
|
seen = true;
|
|
2678
2743
|
if (known.has(value)) {
|
|
2679
2744
|
matchedFields.add(fieldLabel(name));
|
|
@@ -2704,6 +2769,20 @@ function checkHashes(hits, ctx) {
|
|
|
2704
2769
|
const message = `the hashed ${joinLabels(wrongFields)} values ${they} carried do not match the run identity${of(wrong.length)}. Not matching: ${[...wrongParams].join(", ")}.` + (matching.size ? ` Matching: ${joinLabels(matching)}.` : "");
|
|
2705
2770
|
return { pass: false, evidence: wrong, headline: UNMATCHED_HEADLINE, message };
|
|
2706
2771
|
}
|
|
2772
|
+
if (!withHash.length && uncheckedFields.size) {
|
|
2773
|
+
return {
|
|
2774
|
+
pass: false,
|
|
2775
|
+
evidence: hits.map((h) => h.id),
|
|
2776
|
+
message: `${several ? "none of the hits carried a" : "the hit carried no"} hashed email or phone, only ${joinLabels(uncheckedFields)} that Tagreeve does not check.`
|
|
2777
|
+
};
|
|
2778
|
+
}
|
|
2779
|
+
if (!withHash.length && plainAddressFields.size) {
|
|
2780
|
+
return {
|
|
2781
|
+
pass: false,
|
|
2782
|
+
evidence: hits.map((h) => h.id),
|
|
2783
|
+
message: `${several ? "none of the hits carried a" : "the hit carried no"} hashed identity field, only plain ${joinLabels(plainAddressFields)} that Tagreeve does not check.`
|
|
2784
|
+
};
|
|
2785
|
+
}
|
|
2707
2786
|
if (!withHash.length) {
|
|
2708
2787
|
return {
|
|
2709
2788
|
pass: false,
|
|
@@ -2732,8 +2811,9 @@ function countByHost(flags2, ctx) {
|
|
|
2732
2811
|
}
|
|
2733
2812
|
return [...counts].map(([host, n]) => `${host} x${n}`).join(", ");
|
|
2734
2813
|
}
|
|
2814
|
+
var DEFAULT_SEVERITY = { earlyIdentifiers: "warn" };
|
|
2735
2815
|
function builtInChecks(records, scenario, ctx, addResult) {
|
|
2736
|
-
const add2 = (name, pass, evidence2, message, note) => addResult(`builtin: ${name}`, pass, evidence2, message, scenario.options.builtins?.[name] ?? "fail", note);
|
|
2816
|
+
const add2 = (name, pass, evidence2, message, note) => addResult(`builtin: ${name}`, pass, evidence2, message, scenario.options.builtins?.[name] ?? DEFAULT_SEVERITY[name] ?? "fail", note);
|
|
2737
2817
|
const flags2 = records.filter((r) => r.type === "flag");
|
|
2738
2818
|
const unknown = flags2.filter((f) => f.kind === "unknownDestination");
|
|
2739
2819
|
const allow = scenario.options.allowUnknownDestination;
|
|
@@ -2755,6 +2835,7 @@ function builtInChecks(records, scenario, ctx, addResult) {
|
|
|
2755
2835
|
sandboxed.length === 0 ? "Expected no hit to carry a sandbox URL as its page, found none." : `Expected no hit to carry a sandbox URL as its page, found ${sandboxed.length}: ${sandboxed[0].page}.`
|
|
2756
2836
|
);
|
|
2757
2837
|
deniedIdentifiersCheck(scenario, ctx, add2);
|
|
2838
|
+
earlyIdentifiersCheck(scenario, ctx, add2);
|
|
2758
2839
|
const real = flags2.filter((f) => f.kind === "possibleRealData");
|
|
2759
2840
|
const flagged = new Set(real.flatMap((f) => f.recordIds));
|
|
2760
2841
|
const leaks = ctx.identity ? findForeignData(ctx.requests.values(), ctx.hits, ctx.identity).filter((l) => !flagged.has(l.requestId)) : [];
|
|
@@ -2779,6 +2860,11 @@ function builtInChecks(records, scenario, ctx, addResult) {
|
|
|
2779
2860
|
);
|
|
2780
2861
|
}
|
|
2781
2862
|
var DENIABLE = ["analytics", "ads", "adUserData"];
|
|
2863
|
+
function identifierClasses(idFields, fields2, extra) {
|
|
2864
|
+
const classes = new Map(idFields.map((n) => [n, identifierClass(n)]));
|
|
2865
|
+
for (const n of fields2) if (!classes.has(n) && extra.some((re) => re.test(n))) classes.set(n, "analytics");
|
|
2866
|
+
return classes;
|
|
2867
|
+
}
|
|
2782
2868
|
function deniedIdentifiersCheck(scenario, ctx, add2) {
|
|
2783
2869
|
const extra = (scenario.options.identifierFields ?? []).map(globToRegExp);
|
|
2784
2870
|
const leaking = [];
|
|
@@ -2791,8 +2877,7 @@ function deniedIdentifiersCheck(scenario, ctx, add2) {
|
|
|
2791
2877
|
unreadable.push(hit);
|
|
2792
2878
|
continue;
|
|
2793
2879
|
}
|
|
2794
|
-
const classes =
|
|
2795
|
-
for (const n of hit.fields) if (!classes.has(n) && extra.some((re) => re.test(n))) classes.set(n, "analytics");
|
|
2880
|
+
const classes = identifierClasses(hit.idFields, hit.fields, extra);
|
|
2796
2881
|
let flagged = false;
|
|
2797
2882
|
for (const [name, cls] of classes) {
|
|
2798
2883
|
const signal = identifierSignal(cls, state);
|
|
@@ -2831,6 +2916,57 @@ function deniedIdentifiersCheck(scenario, ctx, add2) {
|
|
|
2831
2916
|
add2("deniedIdentifiers", true, [], "Expected no identifiers on hits sent while consent is denied, found none.");
|
|
2832
2917
|
}
|
|
2833
2918
|
}
|
|
2919
|
+
function earlyIdentifiersCheck(scenario, ctx, add2) {
|
|
2920
|
+
const extra = (scenario.options.identifierFields ?? []).map(globToRegExp);
|
|
2921
|
+
const early = [];
|
|
2922
|
+
const unreadable = [];
|
|
2923
|
+
const found = /* @__PURE__ */ new Map();
|
|
2924
|
+
for (const hit of ctx.hits) {
|
|
2925
|
+
if (!isBeforeConsent(hit, ctx)) continue;
|
|
2926
|
+
if (!hit.idFields || !hit.fields) {
|
|
2927
|
+
unreadable.push(hit);
|
|
2928
|
+
continue;
|
|
2929
|
+
}
|
|
2930
|
+
const state = effectiveConsent(hit, ctx);
|
|
2931
|
+
let flagged = false;
|
|
2932
|
+
for (const [name, cls] of identifierClasses(hit.idFields, hit.fields, extra)) {
|
|
2933
|
+
const signal = identifierSignal(cls, state);
|
|
2934
|
+
if (signal.value !== "unknown") continue;
|
|
2935
|
+
flagged = true;
|
|
2936
|
+
const key = `${hit.vendor}\0${signal.field}`;
|
|
2937
|
+
found.set(key, (found.get(key) ?? /* @__PURE__ */ new Set()).add(name));
|
|
2938
|
+
}
|
|
2939
|
+
if (flagged) early.push(hit);
|
|
2940
|
+
else if (hit.fieldsComplete === false) unreadable.push(hit);
|
|
2941
|
+
}
|
|
2942
|
+
const hitsWord = (n) => `hit${n === 1 ? "" : "s"}`;
|
|
2943
|
+
if (early.length > 0) {
|
|
2944
|
+
const groups = [...found].map(([key, names]) => {
|
|
2945
|
+
const [vendor, signal] = key.split("\0");
|
|
2946
|
+
return `${vendor} ${listNames([...names].sort())} (${signal} unknown)`;
|
|
2947
|
+
});
|
|
2948
|
+
const shown2 = groups.slice(0, MAX_LISTED).join(", ");
|
|
2949
|
+
const more = groups.length > MAX_LISTED ? `, and ${groups.length - MAX_LISTED} more` : "";
|
|
2950
|
+
const cut = unreadable.length > 0 ? ` ${unreadable.length} more ${hitsWord(unreadable.length)} could not be read.` : "";
|
|
2951
|
+
add2(
|
|
2952
|
+
"earlyIdentifiers",
|
|
2953
|
+
false,
|
|
2954
|
+
early.map((h) => h.id),
|
|
2955
|
+
`${early.length} ${hitsWord(early.length)} ${early.length === 1 ? "carries" : "carry"} identifiers before the consent answer: ${shown2}${more}.${cut}`
|
|
2956
|
+
);
|
|
2957
|
+
} else if (unreadable.length > 0) {
|
|
2958
|
+
const notRecorded = unreadable.some((h) => !h.idFields || !h.fields);
|
|
2959
|
+
add2(
|
|
2960
|
+
"earlyIdentifiers",
|
|
2961
|
+
false,
|
|
2962
|
+
unreadable.map((h) => h.id),
|
|
2963
|
+
`${notRecorded ? NOT_RECORDED : BODY_CUT}: ${unreadable.length} ${hitsWord(unreadable.length)} sent before the consent answer.`,
|
|
2964
|
+
notRecorded ? "fieldsNotRecorded" : "cannotEvaluateBody"
|
|
2965
|
+
);
|
|
2966
|
+
} else {
|
|
2967
|
+
add2("earlyIdentifiers", true, [], "Expected no identifiers on hits sent before the consent answer, found none.");
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2834
2970
|
function identityOf(run) {
|
|
2835
2971
|
const id = run?.identity;
|
|
2836
2972
|
if (!id) return void 0;
|
|
@@ -2932,6 +3068,91 @@ function pathSegments(url) {
|
|
|
2932
3068
|
return [];
|
|
2933
3069
|
}
|
|
2934
3070
|
}
|
|
3071
|
+
var BINARY_CONTENT_TYPE = /^(?:application\/(?:octet-stream|gzip|x-gzip|zip|zlib|x-protobuf|protobuf|grpc|msgpack|x-msgpack)|image\/(?!svg\+xml)[^;\s]+|audio\/[^;\s]+|video\/[^;\s]+)\s*(?:;|$)/i;
|
|
3072
|
+
var BINARY_SHARE = 0.1;
|
|
3073
|
+
var BINARY_MIN_LENGTH = 16;
|
|
3074
|
+
function headersSayBinary(headers) {
|
|
3075
|
+
const header = (name) => Object.entries(headers).find(([k]) => k.toLowerCase() === name)?.[1]?.trim().toLowerCase() ?? "";
|
|
3076
|
+
const encoding = header("content-encoding");
|
|
3077
|
+
if (encoding !== "" && encoding !== "identity") return true;
|
|
3078
|
+
return BINARY_CONTENT_TYPE.test(header("content-type"));
|
|
3079
|
+
}
|
|
3080
|
+
function isBinaryBody(headers, body) {
|
|
3081
|
+
if (headersSayBinary(headers)) return true;
|
|
3082
|
+
return isBinaryText(body);
|
|
3083
|
+
}
|
|
3084
|
+
function isBinaryText(body) {
|
|
3085
|
+
if (body.length < BINARY_MIN_LENGTH) return false;
|
|
3086
|
+
return binaryShare(body) >= BINARY_SHARE;
|
|
3087
|
+
}
|
|
3088
|
+
function leafTexts(text2) {
|
|
3089
|
+
const out = [];
|
|
3090
|
+
const isJson = /^\s*[{[]/.test(text2);
|
|
3091
|
+
if (!isJson) {
|
|
3092
|
+
for (const segment of text2.split("&")) {
|
|
3093
|
+
const eq = segment.indexOf("=");
|
|
3094
|
+
if (eq < 0 || eq === segment.length - 1) continue;
|
|
3095
|
+
const rawName = segment.slice(0, eq).replace(/\[\]|%5B%5D/gi, "");
|
|
3096
|
+
const [decoded] = new URLSearchParams(segment).keys();
|
|
3097
|
+
out.push({ text: `${rawName}${segment.slice(eq)}`, where: decoded ? guardFieldName(decoded) : "the body", leaf: true });
|
|
3098
|
+
}
|
|
3099
|
+
return out;
|
|
3100
|
+
}
|
|
3101
|
+
const { entries, parsed } = bodyEntries({ postData: text2 });
|
|
3102
|
+
if (parsed) {
|
|
3103
|
+
for (const { name, value } of entries) {
|
|
3104
|
+
const path = name.split(".");
|
|
3105
|
+
path[path.length - 1] = path[path.length - 1].replace(/\[\]/g, "");
|
|
3106
|
+
const where2 = guardFieldName(name);
|
|
3107
|
+
if (path.length > 1) out.push({ text: path.slice(0, -1).join("."), where: where2, leaf: true });
|
|
3108
|
+
out.push({ text: `${path[path.length - 1]}=${value}`, where: where2, leaf: true });
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
return out;
|
|
3112
|
+
}
|
|
3113
|
+
function withoutBinaryParts(split, wholeIsBinary) {
|
|
3114
|
+
const cut = (part) => wholeIsBinary && isBinaryBody(part.headers, part.body);
|
|
3115
|
+
return split.chunks.map(({ raw, part }) => part && cut(part) ? raw.slice(0, part.bodyStart) : raw).join(`--${split.boundary}`);
|
|
3116
|
+
}
|
|
3117
|
+
function withoutBinaryLines(body) {
|
|
3118
|
+
if (!isBinaryText(body)) return body;
|
|
3119
|
+
return body.split(/(?<=\n)/).filter((line) => !isBinaryText(line.replace(/\r?\n$/, ""))).join("");
|
|
3120
|
+
}
|
|
3121
|
+
function bodyTexts(headers, body) {
|
|
3122
|
+
if (body === "" || headersSayBinary(headers)) return [];
|
|
3123
|
+
const split = splitMultipart(body, headers);
|
|
3124
|
+
if (split?.parts.length) {
|
|
3125
|
+
const named = split.parts.flatMap((part) => {
|
|
3126
|
+
const name = multipartPartName(part);
|
|
3127
|
+
if (isBinaryBody(part.headers, part.body)) return [];
|
|
3128
|
+
return name === void 0 ? leafTexts(part.body) : [{ text: `${name}=${part.body}`, where: guardFieldName(name), leaf: true }];
|
|
3129
|
+
});
|
|
3130
|
+
return [{ text: withoutBinaryParts(split, isBinaryText(body)), where: "the body" }, ...named];
|
|
3131
|
+
}
|
|
3132
|
+
const isJson = /^\s*[{[]/.test(body) && bodyEntries({ postData: body }).parsed;
|
|
3133
|
+
if (!isJson && /[\r\n]/.test(body.trim())) {
|
|
3134
|
+
const lines = body.split(/\r?\n/).filter((line) => line.trim() !== "" && !isBinaryText(line));
|
|
3135
|
+
return [{ text: withoutBinaryLines(body), where: "the body" }, ...lines.flatMap(leafTexts)];
|
|
3136
|
+
}
|
|
3137
|
+
return isBinaryText(body) ? [] : [{ text: body, where: "the body" }, ...leafTexts(body)];
|
|
3138
|
+
}
|
|
3139
|
+
function mergeEdgeReadings(found) {
|
|
3140
|
+
const best = (f) => Math.min(...f.where.values());
|
|
3141
|
+
const valueOf2 = (key, kind) => key.slice(kind.length + 1);
|
|
3142
|
+
const fields2 = [...found].filter(([, f]) => best(f) < 2);
|
|
3143
|
+
for (const [key, f] of [...found]) {
|
|
3144
|
+
if (best(f) < 2) continue;
|
|
3145
|
+
const value = valueOf2(key, f.kind);
|
|
3146
|
+
const twin = fields2.find(([k, other]) => {
|
|
3147
|
+
if (other.kind !== f.kind) return false;
|
|
3148
|
+
const v = valueOf2(k, other.kind);
|
|
3149
|
+
return v.includes(value) || value.includes(v);
|
|
3150
|
+
});
|
|
3151
|
+
if (!twin) continue;
|
|
3152
|
+
for (const [w, tier] of f.where) twin[1].where.set(w, Math.min(tier, twin[1].where.get(w) ?? tier));
|
|
3153
|
+
found.delete(key);
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
2935
3156
|
function findForeignData(requests, hits, identity) {
|
|
2936
3157
|
const byRequest = /* @__PURE__ */ new Map();
|
|
2937
3158
|
const slot = (key, stepId) => {
|
|
@@ -2946,7 +3167,7 @@ function findForeignData(requests, hits, identity) {
|
|
|
2946
3167
|
const url = scannedUrl(request, persisted.url, hitRequests.has(request.id));
|
|
2947
3168
|
const texts = slot(request.id, request.stepId).texts;
|
|
2948
3169
|
for (const text2 of [url, ...pathSegments(url)]) texts.push({ text: text2, where: "the URL" });
|
|
2949
|
-
texts.push(
|
|
3170
|
+
texts.push(...bodyTexts(request.headers, persisted.postData));
|
|
2950
3171
|
}
|
|
2951
3172
|
for (const hit of hits) {
|
|
2952
3173
|
const entry = slot(hit.requestId, hit.stepId);
|
|
@@ -2959,20 +3180,22 @@ function findForeignData(requests, hits, identity) {
|
|
|
2959
3180
|
const out = [];
|
|
2960
3181
|
for (const [requestId, entry] of byRequest) {
|
|
2961
3182
|
const found = /* @__PURE__ */ new Map();
|
|
2962
|
-
for (const { text: text2, where: where2 } of entry.texts) {
|
|
3183
|
+
for (const { text: text2, where: where2, leaf } of entry.texts) {
|
|
3184
|
+
const tier = where2 === "the URL" || where2 === "the body" ? 2 : leaf ? 1 : 0;
|
|
2963
3185
|
for (const m of scan(text2, identity, { stableHashes })) {
|
|
2964
3186
|
const key = `${m.kind}:${m.value}`;
|
|
2965
|
-
const seen = found.get(key) ?? { kind: m.kind, where: /* @__PURE__ */ new
|
|
2966
|
-
seen.where.
|
|
3187
|
+
const seen = found.get(key) ?? { kind: m.kind, where: /* @__PURE__ */ new Map() };
|
|
3188
|
+
seen.where.set(where2, Math.min(tier, seen.where.get(where2) ?? tier));
|
|
2967
3189
|
found.set(key, seen);
|
|
2968
3190
|
}
|
|
2969
3191
|
}
|
|
2970
3192
|
if (found.size === 0) continue;
|
|
3193
|
+
mergeEdgeReadings(found);
|
|
2971
3194
|
const kinds = [...new Set([...found.values()].map((f) => f.kind))].join(", ");
|
|
2972
3195
|
const places = /* @__PURE__ */ new Set();
|
|
2973
3196
|
for (const { where: where2 } of found.values()) {
|
|
2974
|
-
const
|
|
2975
|
-
for (const w of
|
|
3197
|
+
const best = Math.min(...where2.values());
|
|
3198
|
+
for (const [w, tier] of where2) if (tier === best) places.add(w);
|
|
2976
3199
|
}
|
|
2977
3200
|
const shown2 = [...places].sort();
|
|
2978
3201
|
const in_ = shown2.length > 5 ? `${shown2.slice(0, 5).join(", ")} and ${shown2.length - 5} more` : shown2.join(", ");
|
|
@@ -3033,10 +3256,10 @@ function hitShape(run, options = {}) {
|
|
|
3033
3256
|
const tuples = /* @__PURE__ */ new Map();
|
|
3034
3257
|
for (const hit of group.hits) {
|
|
3035
3258
|
const fields2 = shapeFields(hit);
|
|
3036
|
-
const
|
|
3037
|
-
const tuple = tuples.get(
|
|
3259
|
+
const tupleId2 = JSON.stringify(fields2);
|
|
3260
|
+
const tuple = tuples.get(tupleId2) ?? { ...fields2, count: 0 };
|
|
3038
3261
|
tuple.count += 1;
|
|
3039
|
-
tuples.set(
|
|
3262
|
+
tuples.set(tupleId2, tuple);
|
|
3040
3263
|
}
|
|
3041
3264
|
out.push({ key: group.key, tuples: [...tuples].sort(([x], [y]) => x < y ? -1 : x > y ? 1 : 0).map(([, t]) => t) });
|
|
3042
3265
|
}
|
|
@@ -3049,17 +3272,77 @@ function shapeFields(hit) {
|
|
|
3049
3272
|
const ids = [...idPresence(hit.ids)].filter(([, present]) => present).map(([name]) => name).sort();
|
|
3050
3273
|
return { consent, ids };
|
|
3051
3274
|
}
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3275
|
+
var keyId = (k) => JSON.stringify([k.epoch, k.vendor, k.event, k.page ?? null]);
|
|
3276
|
+
var groupId = (k) => JSON.stringify([k.vendor, k.event, k.page ?? null]);
|
|
3277
|
+
var tupleId = (t) => JSON.stringify([Object.entries(t.consent).sort(([x], [y]) => x < y ? -1 : x > y ? 1 : 0), t.ids]);
|
|
3278
|
+
var total = (k) => (k?.tuples ?? []).reduce((n, t) => n + t.count, 0);
|
|
3279
|
+
function tupleCounts(k) {
|
|
3280
|
+
const out = /* @__PURE__ */ new Map();
|
|
3281
|
+
for (const t of k?.tuples ?? []) out.set(tupleId(t), (out.get(tupleId(t)) ?? 0) + t.count);
|
|
3282
|
+
return out;
|
|
3283
|
+
}
|
|
3284
|
+
function contains(big, small) {
|
|
3285
|
+
for (const [id, n] of small) if ((big.get(id) ?? 0) < n) return false;
|
|
3286
|
+
return true;
|
|
3287
|
+
}
|
|
3288
|
+
function surplusByIds(k, other) {
|
|
3289
|
+
const out = /* @__PURE__ */ new Map();
|
|
3290
|
+
const rest = tupleCounts(other);
|
|
3291
|
+
for (const t of k?.tuples ?? []) {
|
|
3292
|
+
const id = tupleId(t);
|
|
3293
|
+
const used = Math.min(rest.get(id) ?? 0, t.count);
|
|
3294
|
+
rest.set(id, (rest.get(id) ?? 0) - used);
|
|
3295
|
+
const extra = t.count - used;
|
|
3296
|
+
if (extra > 0) out.set(JSON.stringify(t.ids), (out.get(JSON.stringify(t.ids)) ?? 0) + extra);
|
|
3297
|
+
}
|
|
3298
|
+
return out;
|
|
3299
|
+
}
|
|
3300
|
+
function sameCounts(x, y) {
|
|
3301
|
+
return x.size === y.size && contains(x, y) && contains(y, x);
|
|
3302
|
+
}
|
|
3303
|
+
function findMove(epochs, order) {
|
|
3304
|
+
const changed = [...epochs].filter(([, e]) => total(e.a) !== total(e.b));
|
|
3305
|
+
if (changed.length !== 2) return void 0;
|
|
3306
|
+
const [[e1, v1], [e2, v2]] = changed;
|
|
3307
|
+
const d1 = total(v1.b) - total(v1.a);
|
|
3308
|
+
if (d1 + total(v2.b) - total(v2.a) !== 0) return void 0;
|
|
3309
|
+
const [from, to] = d1 < 0 ? [[e1, v1], [e2, v2]] : [[e2, v2], [e1, v1]];
|
|
3310
|
+
const i = order.indexOf(from[0]);
|
|
3311
|
+
const j = order.indexOf(to[0]);
|
|
3312
|
+
if (i < 0 || j < 0 || Math.abs(i - j) !== 1) return void 0;
|
|
3313
|
+
if (order.filter((l) => l === from[0] || l === to[0]).length !== 2) return void 0;
|
|
3314
|
+
if (!contains(tupleCounts(from[1].a), tupleCounts(from[1].b))) return void 0;
|
|
3315
|
+
if (!contains(tupleCounts(to[1].b), tupleCounts(to[1].a))) return void 0;
|
|
3316
|
+
if (!sameCounts(surplusByIds(from[1].a, from[1].b), surplusByIds(to[1].b, to[1].a))) return void 0;
|
|
3317
|
+
return { from: from[0], to: to[0], count: Math.abs(d1) };
|
|
3318
|
+
}
|
|
3319
|
+
function diffShapes(a, b, options = {}) {
|
|
3320
|
+
const result = { added: [], removed: [], countChanges: [], moved: [], drift: false };
|
|
3321
|
+
const ia = new Map(a.map((k) => [keyId(k.key), k]));
|
|
3322
|
+
const ib = new Map(b.map((k) => [keyId(k.key), k]));
|
|
3323
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3324
|
+
for (const [side, index] of [["a", ia], ["b", ib]]) {
|
|
3325
|
+
for (const k of index.values()) {
|
|
3326
|
+
const epochs = groups.get(groupId(k.key)) ?? /* @__PURE__ */ new Map();
|
|
3327
|
+
epochs.set(k.key.epoch, { ...epochs.get(k.key.epoch), [side]: k });
|
|
3328
|
+
groups.set(groupId(k.key), epochs);
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
const skipped = /* @__PURE__ */ new Set();
|
|
3332
|
+
for (const epochs of groups.values()) {
|
|
3333
|
+
const move = findMove(epochs, options.epochOrder ?? []);
|
|
3334
|
+
if (!move) continue;
|
|
3335
|
+
const key = (epochs.get(move.from).a ?? epochs.get(move.from).b).key;
|
|
3336
|
+
result.moved.push({ vendor: key.vendor, event: key.event, ...key.page === void 0 ? {} : { page: key.page }, ...move });
|
|
3337
|
+
for (const label of [move.from, move.to]) skipped.add(keyId({ ...key, epoch: label }));
|
|
3338
|
+
}
|
|
3057
3339
|
for (const id of [.../* @__PURE__ */ new Set([...ia.keys(), ...ib.keys()])].sort()) {
|
|
3340
|
+
if (skipped.has(id)) continue;
|
|
3058
3341
|
const ka = ia.get(id);
|
|
3059
3342
|
const kb = ib.get(id);
|
|
3060
3343
|
const key = (ka ?? kb).key;
|
|
3061
|
-
const ta = new Map((ka?.tuples ?? []).map((t) => [
|
|
3062
|
-
const tb = new Map((kb?.tuples ?? []).map((t) => [
|
|
3344
|
+
const ta = new Map((ka?.tuples ?? []).map((t) => [tupleId(t), t]));
|
|
3345
|
+
const tb = new Map((kb?.tuples ?? []).map((t) => [tupleId(t), t]));
|
|
3063
3346
|
for (const [tid, t] of tb) {
|
|
3064
3347
|
const before = ta.get(tid);
|
|
3065
3348
|
if (!before) result.added.push({ key, consent: t.consent, ids: t.ids, wholeKey: !ka });
|
|
@@ -3184,11 +3467,17 @@ function flagChanges(a, b) {
|
|
|
3184
3467
|
|
|
3185
3468
|
// packages/cli/src/args.ts
|
|
3186
3469
|
var UsageError = class extends Error {
|
|
3187
|
-
|
|
3470
|
+
command;
|
|
3471
|
+
constructor(message, command) {
|
|
3188
3472
|
super(message);
|
|
3189
3473
|
this.name = "UsageError";
|
|
3474
|
+
this.command = command;
|
|
3190
3475
|
}
|
|
3191
3476
|
};
|
|
3477
|
+
var COMMANDS = ["run", "suite", "diff", "baseline", "report", "install-browser"];
|
|
3478
|
+
function usageHint(command) {
|
|
3479
|
+
return `Run tagreeve ${command ? `${command} ` : ""}--help for the options.`;
|
|
3480
|
+
}
|
|
3192
3481
|
var PUBLISHED_VARIANT = "published";
|
|
3193
3482
|
var VARIANT_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
3194
3483
|
var USAGE = `Usage:
|
|
@@ -3267,36 +3556,48 @@ function parseVariants(entries) {
|
|
|
3267
3556
|
}
|
|
3268
3557
|
return variants2;
|
|
3269
3558
|
}
|
|
3559
|
+
var OPTIONS = {
|
|
3560
|
+
site: { type: "string" },
|
|
3561
|
+
network: { type: "string" },
|
|
3562
|
+
out: { type: "string" },
|
|
3563
|
+
seed: { type: "string" },
|
|
3564
|
+
headed: { type: "boolean" },
|
|
3565
|
+
viewport: { type: "string" },
|
|
3566
|
+
"net-log": { type: "boolean" },
|
|
3567
|
+
"autoconsent-rules": { type: "string", multiple: true },
|
|
3568
|
+
"gtm-override": { type: "string" },
|
|
3569
|
+
"tracker-list": { type: "string" },
|
|
3570
|
+
baseline: { type: "string" },
|
|
3571
|
+
variant: { type: "string", multiple: true },
|
|
3572
|
+
"with-handoff": { type: "boolean" },
|
|
3573
|
+
"with-test-payment": { type: "boolean" },
|
|
3574
|
+
"allow-test-payment": { type: "string" },
|
|
3575
|
+
var: { type: "string", multiple: true },
|
|
3576
|
+
json: { type: "boolean" },
|
|
3577
|
+
html: { type: "string" },
|
|
3578
|
+
"by-page": { type: "boolean" },
|
|
3579
|
+
"all-flags": { type: "boolean" },
|
|
3580
|
+
version: { type: "boolean" },
|
|
3581
|
+
help: { type: "boolean", short: "h" }
|
|
3582
|
+
};
|
|
3270
3583
|
function parseCli(argv) {
|
|
3584
|
+
try {
|
|
3585
|
+
return parseCommand(argv);
|
|
3586
|
+
} catch (error) {
|
|
3587
|
+
if (error instanceof UsageError && error.command === void 0) {
|
|
3588
|
+
const first = parseArgs({ args: argv, allowPositionals: true, strict: false, options: OPTIONS }).positionals[0];
|
|
3589
|
+
if (first !== void 0 && COMMANDS.includes(first)) error.command = first;
|
|
3590
|
+
}
|
|
3591
|
+
throw error;
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
function parseCommand(argv) {
|
|
3271
3595
|
let parsed;
|
|
3272
3596
|
try {
|
|
3273
3597
|
parsed = parseArgs({
|
|
3274
3598
|
args: argv,
|
|
3275
3599
|
allowPositionals: true,
|
|
3276
|
-
options:
|
|
3277
|
-
site: { type: "string" },
|
|
3278
|
-
network: { type: "string" },
|
|
3279
|
-
out: { type: "string" },
|
|
3280
|
-
seed: { type: "string" },
|
|
3281
|
-
headed: { type: "boolean" },
|
|
3282
|
-
viewport: { type: "string" },
|
|
3283
|
-
"net-log": { type: "boolean" },
|
|
3284
|
-
"autoconsent-rules": { type: "string", multiple: true },
|
|
3285
|
-
"gtm-override": { type: "string" },
|
|
3286
|
-
"tracker-list": { type: "string" },
|
|
3287
|
-
baseline: { type: "string" },
|
|
3288
|
-
variant: { type: "string", multiple: true },
|
|
3289
|
-
"with-handoff": { type: "boolean" },
|
|
3290
|
-
"with-test-payment": { type: "boolean" },
|
|
3291
|
-
"allow-test-payment": { type: "string" },
|
|
3292
|
-
var: { type: "string", multiple: true },
|
|
3293
|
-
json: { type: "boolean" },
|
|
3294
|
-
html: { type: "string" },
|
|
3295
|
-
"by-page": { type: "boolean" },
|
|
3296
|
-
"all-flags": { type: "boolean" },
|
|
3297
|
-
version: { type: "boolean" },
|
|
3298
|
-
help: { type: "boolean", short: "h" }
|
|
3299
|
-
}
|
|
3600
|
+
options: OPTIONS
|
|
3300
3601
|
});
|
|
3301
3602
|
} catch (error) {
|
|
3302
3603
|
throw new UsageError(error instanceof Error ? error.message : String(error));
|
|
@@ -3466,22 +3767,36 @@ function tupleLabel(t) {
|
|
|
3466
3767
|
}
|
|
3467
3768
|
function describeDiff(diff) {
|
|
3468
3769
|
const lines = [];
|
|
3469
|
-
for (const c of diff.added) lines.push(c.wholeKey ? `added ${keyLabel(c.key)}` : `added tuple ${keyLabel(c.key)}: ${tupleLabel(c)}`);
|
|
3470
|
-
for (const c of diff.removed) lines.push(c.wholeKey ? `removed ${keyLabel(c.key)}` : `removed tuple ${keyLabel(c.key)}: ${tupleLabel(c)}`);
|
|
3471
|
-
for (const c of diff.countChanges) lines.push(`count ${keyLabel(c.key)}: ${c.a} -> ${c.b} (not drift)`);
|
|
3472
|
-
return
|
|
3770
|
+
for (const c of diff.added) lines.push(c.wholeKey ? `added ${keyLabel(c.key)}: ${tupleLabel(c)}` : `added tuple ${keyLabel(c.key)}: ${tupleLabel(c)}`);
|
|
3771
|
+
for (const c of diff.removed) lines.push(c.wholeKey ? `removed ${keyLabel(c.key)}: ${tupleLabel(c)}` : `removed tuple ${keyLabel(c.key)}: ${tupleLabel(c)}`);
|
|
3772
|
+
for (const c of diff.countChanges) lines.push(`count ${keyLabel(c.key)}: ${tupleLabel(c)}: ${c.a} -> ${c.b} (not drift)`);
|
|
3773
|
+
return lines;
|
|
3473
3774
|
}
|
|
3775
|
+
function describeMove(m) {
|
|
3776
|
+
const page2 = m.page === void 0 ? "" : ` on page ${m.page || "(none)"}`;
|
|
3777
|
+
const hits = m.count > 1 ? ` (${m.count} hits)` : "";
|
|
3778
|
+
const early = m.to === "undecided" ? " The hit now fires before the consent answer." : "";
|
|
3779
|
+
return `moved ${m.vendor} ${m.event || "(no event)"} from ${m.from} to ${m.to}${page2}${hits}. This is not drift.${early}`;
|
|
3780
|
+
}
|
|
3781
|
+
var scenarioName = (name) => name.replace(/\.ya?ml$/, "");
|
|
3474
3782
|
function compareBaseline(baseline, records) {
|
|
3475
3783
|
const warnings = [];
|
|
3476
|
-
if (baseline.scenario !== records.run.scenario) {
|
|
3784
|
+
if (scenarioName(baseline.scenario) !== scenarioName(records.run.scenario)) {
|
|
3477
3785
|
warnings.push(`The baseline is from scenario ${baseline.scenario}, and this run is ${records.run.scenario}.`);
|
|
3478
3786
|
}
|
|
3479
3787
|
const host = hostOf3(records.run.site);
|
|
3480
3788
|
if (baseline.site !== host) warnings.push(`The baseline is from site ${baseline.site || "(none)"}, and this run is ${host || "(none)"}.`);
|
|
3481
|
-
const
|
|
3482
|
-
const
|
|
3483
|
-
|
|
3484
|
-
return {
|
|
3789
|
+
const epochOrder = [...records.consentEpochs].sort((x, y) => x.startT - y.startT).map((e) => e.label);
|
|
3790
|
+
const diff = diffShapes(baseline.keys, hitShape(records, { byPage: baseline.byPage }), { epochOrder });
|
|
3791
|
+
warnings.push(...diff.moved.map(describeMove));
|
|
3792
|
+
return {
|
|
3793
|
+
drift: diff.drift,
|
|
3794
|
+
added: diff.added.length,
|
|
3795
|
+
removed: diff.removed.length,
|
|
3796
|
+
countChanges: diff.countChanges.length,
|
|
3797
|
+
warnings,
|
|
3798
|
+
changes: describeDiff(diff)
|
|
3799
|
+
};
|
|
3485
3800
|
}
|
|
3486
3801
|
async function baselineCommand(args, io) {
|
|
3487
3802
|
let records;
|
|
@@ -3689,18 +4004,23 @@ function expectationView(result) {
|
|
|
3689
4004
|
}
|
|
3690
4005
|
var RULE_LEAK = "named by a failed consent-scoped rule";
|
|
3691
4006
|
var IDENTIFIER_LEAK = "identifiers sent while denied";
|
|
4007
|
+
var IDENTIFIER_EARLY = "identifiers sent before an answer";
|
|
3692
4008
|
function namedLeaks(results) {
|
|
3693
4009
|
const named = /* @__PURE__ */ new Map();
|
|
3694
4010
|
for (const result of results) {
|
|
3695
4011
|
if (result.pass || result.note === "cannotEvaluateBody" || result.note === "fieldsNotRecorded") continue;
|
|
3696
4012
|
let label;
|
|
3697
4013
|
if (result.expectation === "builtin: deniedIdentifiers") label = IDENTIFIER_LEAK;
|
|
4014
|
+
else if (result.expectation === "builtin: earlyIdentifiers") label = IDENTIFIER_EARLY;
|
|
3698
4015
|
else {
|
|
3699
4016
|
const parsed = parseEntry2(result);
|
|
3700
4017
|
if (parsed?.kind !== "mustNot" || !consentScoped(parsed.entry)) continue;
|
|
3701
4018
|
label = RULE_LEAK;
|
|
3702
4019
|
}
|
|
3703
|
-
for (const id of result.evidence)
|
|
4020
|
+
for (const id of result.evidence) {
|
|
4021
|
+
const have = named.get(id);
|
|
4022
|
+
if (have !== IDENTIFIER_LEAK && !(have === IDENTIFIER_EARLY && label === RULE_LEAK)) named.set(id, label);
|
|
4023
|
+
}
|
|
3704
4024
|
}
|
|
3705
4025
|
return named;
|
|
3706
4026
|
}
|
|
@@ -3730,6 +4050,7 @@ function segmentOf(verdicts2) {
|
|
|
3730
4050
|
if ((mark === "full" || mark === "early") && has("full") && has("ping")) return { mark: "mixed", label: "granted and denied hits", hits };
|
|
3731
4051
|
const own = verdicts2.filter((v) => v.mark === mark);
|
|
3732
4052
|
let label = own.every((v) => v.label === own[0].label) ? own[0].label : "";
|
|
4053
|
+
if (!label && own.every((v) => v.label === IDENTIFIER_LEAK || v.label === IDENTIFIER_EARLY)) label = IDENTIFIER_LEAK;
|
|
3733
4054
|
if (mark === "mixed") label = MIXED_HIT;
|
|
3734
4055
|
return { mark, label, hits };
|
|
3735
4056
|
}
|
|
@@ -3849,7 +4170,7 @@ function addFindings(into, model) {
|
|
|
3849
4170
|
for (const row of model.rows) {
|
|
3850
4171
|
row.segments.forEach((segment, i) => {
|
|
3851
4172
|
if (segment.mark !== "leak") return;
|
|
3852
|
-
const target = segment.label === IDENTIFIER_LEAK ? into.identifiers : into.hits;
|
|
4173
|
+
const target = segment.label === IDENTIFIER_LEAK || segment.label === IDENTIFIER_EARLY ? into.identifiers : into.hits;
|
|
3853
4174
|
const label = model.columns[i].label;
|
|
3854
4175
|
const vendors = target.get(label) ?? /* @__PURE__ */ new Set();
|
|
3855
4176
|
vendors.add(row.vendor);
|
|
@@ -3883,7 +4204,7 @@ function findingsSentence(f, inRuns = false) {
|
|
|
3883
4204
|
for (const [label, vendors] of [...f.hits].sort(([a], [b]) => a.localeCompare(b))) parts.push(`${list(vendors)} ${vendors.size === 1 ? "sends" : "send"} hits in the ${label} state`);
|
|
3884
4205
|
for (const [label, vendors] of [...f.identifiers].sort(([a], [b]) => a.localeCompare(b))) parts.push(`identifiers go out to ${list(vendors)} in the ${label} state`);
|
|
3885
4206
|
const named = f.identifiers.size > 0;
|
|
3886
|
-
const shown2 = (checks) => new Map([...checks].filter(([name]) => !(named && name === "deniedIdentifiers")));
|
|
4207
|
+
const shown2 = (checks) => new Map([...checks].filter(([name]) => !(named && (name === "deniedIdentifiers" || name === "earlyIdentifiers"))));
|
|
3887
4208
|
if (parts.length === 0 && f.unchecked === 0) parts.push("no leaks");
|
|
3888
4209
|
if (f.failed > 0) parts.push(`${plural(f.failed, "rule")} failed`);
|
|
3889
4210
|
parts.push(...checkParts(shown2(f.failedChecks), "failed", inRuns));
|
|
@@ -3918,7 +4239,7 @@ var LEGEND = {
|
|
|
3918
4239
|
early: "hit sent before the person answered, with no consent default set",
|
|
3919
4240
|
ping: "hit sent while denied, no identifiers recorded",
|
|
3920
4241
|
nothing: "no hit",
|
|
3921
|
-
leak: "identifier names sent while their signal was denied, or named by a failed consent-scoped mustNot",
|
|
4242
|
+
leak: "identifier names sent while their signal was denied or before any answer, or named by a failed consent-scoped mustNot",
|
|
3922
4243
|
unchecked: "denied, but the body was not fully recorded, or identifier names whose consent signal is unknown, so the hit cannot be called clean",
|
|
3923
4244
|
mixed: "some signals denied, or granted and denied hits in one segment"
|
|
3924
4245
|
};
|
|
@@ -6624,14 +6945,29 @@ async function cardFrameServed(page2, field, cardHost, deadline) {
|
|
|
6624
6945
|
try {
|
|
6625
6946
|
const element = await page2.locator(field.frame).first().elementHandle({ timeout: Math.max(1, deadline - Date.now()) });
|
|
6626
6947
|
const frame = await element?.contentFrame();
|
|
6627
|
-
if (frame && hostOf5(frame.url()) === cardHost) return
|
|
6948
|
+
if (element && frame && hostOf5(frame.url()) === cardHost) return element;
|
|
6628
6949
|
} catch {
|
|
6629
|
-
return
|
|
6950
|
+
return void 0;
|
|
6630
6951
|
}
|
|
6631
|
-
if (Date.now() >= deadline) return
|
|
6952
|
+
if (Date.now() >= deadline) return void 0;
|
|
6632
6953
|
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
6633
6954
|
}
|
|
6634
6955
|
}
|
|
6956
|
+
async function markerInCardContainer(frames, marker, timeout) {
|
|
6957
|
+
try {
|
|
6958
|
+
const container = await frames[0].evaluateHandle((first, all) => {
|
|
6959
|
+
let node = first.parentElement;
|
|
6960
|
+
while (node && !all.every((f) => node.contains(f))) node = node.parentElement;
|
|
6961
|
+
return node;
|
|
6962
|
+
}, frames);
|
|
6963
|
+
const element = container.asElement();
|
|
6964
|
+
if (!element) return false;
|
|
6965
|
+
await element.waitForSelector(marker, { state: "visible", timeout });
|
|
6966
|
+
return true;
|
|
6967
|
+
} catch {
|
|
6968
|
+
return false;
|
|
6969
|
+
}
|
|
6970
|
+
}
|
|
6635
6971
|
function valueOf(kind, provider, card, identity) {
|
|
6636
6972
|
if (kind === "number") return card;
|
|
6637
6973
|
if (kind === "expiry") return provider.expiry;
|
|
@@ -6650,24 +6986,24 @@ async function runPayment(page2, recorder, value, identity, testPayment, record,
|
|
|
6650
6986
|
if (hostOf5(page2.url()) !== allowed || normalizeHost(siteHost) !== allowed) {
|
|
6651
6987
|
throw new Error("test mode not detected (the page is not on the allowed test payment host)");
|
|
6652
6988
|
}
|
|
6989
|
+
const declared = testPayment.declaredProviders?.includes(provider.id) === true;
|
|
6653
6990
|
const wait = Math.min(timeout, MARKER_TIMEOUT_MS);
|
|
6654
|
-
try {
|
|
6655
|
-
await page2.locator(runtime.marker).first().waitFor({ state: "visible", timeout: wait });
|
|
6656
|
-
} catch {
|
|
6657
|
-
throw new Error("test mode not detected");
|
|
6658
|
-
}
|
|
6659
6991
|
const deadline = Date.now() + wait;
|
|
6992
|
+
const frames = [];
|
|
6660
6993
|
for (const field of runtime.fields) {
|
|
6661
|
-
|
|
6994
|
+
const frame = await cardFrameServed(page2, field, runtime.cardHost, deadline);
|
|
6995
|
+
if (!frame) throw new Error(`card frame not found (${field.kind})`);
|
|
6996
|
+
frames.push(frame);
|
|
6662
6997
|
}
|
|
6663
|
-
|
|
6998
|
+
if (!declared && !await markerInCardContainer(frames, runtime.marker, wait)) throw new Error("test mode not detected");
|
|
6664
6999
|
recorder.holdRedaction();
|
|
6665
|
-
for (const field of runtime.fields) {
|
|
7000
|
+
for (const [index, field] of runtime.fields.entries()) {
|
|
6666
7001
|
try {
|
|
6667
7002
|
await page2.frameLocator(field.frame).locator(field.input).fill(valueOf(field.kind, provider, card, identity), { timeout });
|
|
6668
7003
|
} catch {
|
|
6669
7004
|
throw new Error(`card field ${field.kind} could not be filled`);
|
|
6670
7005
|
}
|
|
7006
|
+
if (index === 0) record.payment = { provider: provider.id, mode: "test", testMode: declared ? "declared" : "marker" };
|
|
6671
7007
|
}
|
|
6672
7008
|
}
|
|
6673
7009
|
|
|
@@ -7073,7 +7409,25 @@ function testPaymentHostsPath(env = process.env, home = homedir()) {
|
|
|
7073
7409
|
const base2 = xdg && isAbsolute(xdg) ? xdg : join5(home, ".config");
|
|
7074
7410
|
return join5(base2, "tagreeve", FILE_NAME);
|
|
7075
7411
|
}
|
|
7076
|
-
|
|
7412
|
+
function entryError(path, index, reason) {
|
|
7413
|
+
return new Error(`${path}: entry ${index} ${reason}.`);
|
|
7414
|
+
}
|
|
7415
|
+
function parseEntry3(path, entry, index, loopbackHosted) {
|
|
7416
|
+
if (typeof entry === "string") return { host: normalizeHost(entry) };
|
|
7417
|
+
const keys = entry && typeof entry === "object" && !Array.isArray(entry) ? Object.keys(entry) : [];
|
|
7418
|
+
const { host, testMode } = entry ?? {};
|
|
7419
|
+
if (typeof host !== "string" || typeof testMode !== "string" || keys.length !== 2) {
|
|
7420
|
+
throw entryError(path, index, 'must be a host name or an object with only "host" and "testMode"');
|
|
7421
|
+
}
|
|
7422
|
+
const normalized = normalizeHost(host);
|
|
7423
|
+
if (!findPaymentProvider(testMode)) throw entryError(path, index, "names a testMode that is not a payment provider");
|
|
7424
|
+
const testOnly = testMode === "fixture" && isLoopbackHost(normalized) && loopbackHosted;
|
|
7425
|
+
if (!testOnly && (testMode === "fixture" || isLoopbackHost(normalized))) {
|
|
7426
|
+
throw entryError(path, index, "declares a loopback host or the fixture provider, which only tests may do");
|
|
7427
|
+
}
|
|
7428
|
+
return { host: normalized, testMode };
|
|
7429
|
+
}
|
|
7430
|
+
async function readTestPaymentHosts(path, loopbackHosted = loopbackIsHostedForTests()) {
|
|
7077
7431
|
let mode;
|
|
7078
7432
|
try {
|
|
7079
7433
|
mode = (await stat(path)).mode;
|
|
@@ -7090,8 +7444,8 @@ async function readTestPaymentHosts(path) {
|
|
|
7090
7444
|
} catch {
|
|
7091
7445
|
throw new Error(`${path} is not valid JSON.`);
|
|
7092
7446
|
}
|
|
7093
|
-
if (!Array.isArray(json)
|
|
7094
|
-
return json.map(
|
|
7447
|
+
if (!Array.isArray(json)) throw new Error(`${path} must be a JSON array of host names or { "host", "testMode" } objects.`);
|
|
7448
|
+
return json.map((entry, index) => parseEntry3(path, entry, index, loopbackHosted));
|
|
7095
7449
|
}
|
|
7096
7450
|
async function checkTestPaymentGates(parsed, site, allow, env = process.env) {
|
|
7097
7451
|
const payments = parsed.steps.filter((s) => s.kind === "payment");
|
|
@@ -7107,16 +7461,18 @@ async function checkTestPaymentGates(parsed, site, allow, env = process.env) {
|
|
|
7107
7461
|
if (normalizeHost(allow) !== siteHost) {
|
|
7108
7462
|
return { ok: false, error: `--allow-test-payment must name the --site host (${siteHost}).` };
|
|
7109
7463
|
}
|
|
7110
|
-
let
|
|
7464
|
+
let entries;
|
|
7111
7465
|
try {
|
|
7112
|
-
|
|
7466
|
+
entries = await readTestPaymentHosts(testPaymentHostsPath(env));
|
|
7113
7467
|
} catch (error) {
|
|
7114
7468
|
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
7115
7469
|
}
|
|
7116
|
-
|
|
7470
|
+
const own = entries.filter((e) => e.host === siteHost);
|
|
7471
|
+
if (own.length === 0) {
|
|
7117
7472
|
return { ok: false, error: `${siteHost} is not in ${testPaymentHostsPath(env)}.` };
|
|
7118
7473
|
}
|
|
7119
|
-
|
|
7474
|
+
const declaredProviders = own.flatMap((e) => e.testMode ? [e.testMode] : []);
|
|
7475
|
+
return { ok: true, testPayment: { host: siteHost, ...declaredProviders.length && { declaredProviders } } };
|
|
7120
7476
|
}
|
|
7121
7477
|
|
|
7122
7478
|
// packages/cli/src/run.ts
|
|
@@ -7144,7 +7500,7 @@ function stateName(state) {
|
|
|
7144
7500
|
}
|
|
7145
7501
|
function testPaymentOf(records) {
|
|
7146
7502
|
const payment = (records.steps ?? []).find((s) => s.payment)?.payment;
|
|
7147
|
-
return payment && { provider: payment.provider, host: new URL(records.run.site).hostname };
|
|
7503
|
+
return payment && { provider: payment.provider, host: new URL(records.run.site).hostname, testMode: payment.testMode ?? "marker" };
|
|
7148
7504
|
}
|
|
7149
7505
|
function buildSummary(records, results, path) {
|
|
7150
7506
|
const testPayment = testPaymentOf(records);
|
|
@@ -7161,6 +7517,13 @@ function buildSummary(records, results, path) {
|
|
|
7161
7517
|
results: results.map((r) => ({ expectation: r.expectation, pass: r.pass, message: r.message, ...r.note && { note: r.note }, evidence: r.evidence, severity: r.severity ?? "fail" }))
|
|
7162
7518
|
};
|
|
7163
7519
|
}
|
|
7520
|
+
function applyBaseline(summary, baseline) {
|
|
7521
|
+
summary.baseline = baseline;
|
|
7522
|
+
if (baseline.drift) {
|
|
7523
|
+
summary.pass = false;
|
|
7524
|
+
summary.ok = false;
|
|
7525
|
+
}
|
|
7526
|
+
}
|
|
7164
7527
|
function passesGate(r) {
|
|
7165
7528
|
return r.pass || r.severity === "warn";
|
|
7166
7529
|
}
|
|
@@ -7221,7 +7584,10 @@ function formatDuration2(ms) {
|
|
|
7221
7584
|
}
|
|
7222
7585
|
function formatSummary(summary) {
|
|
7223
7586
|
const lines = [];
|
|
7224
|
-
if (summary.testPayment)
|
|
7587
|
+
if (summary.testPayment) {
|
|
7588
|
+
const { provider, host, testMode } = summary.testPayment;
|
|
7589
|
+
lines.push(`TEST PAYMENT: ${provider} on ${host} (test mode ${testMode === "declared" ? "declared" : "on page"})`);
|
|
7590
|
+
}
|
|
7225
7591
|
lines.push("Hits");
|
|
7226
7592
|
const vendors = Object.entries(summary.hits);
|
|
7227
7593
|
if (vendors.length === 0) lines.push(" none");
|
|
@@ -7350,6 +7716,14 @@ async function labelRecord(path, variant, out) {
|
|
|
7350
7716
|
await rename(path, target);
|
|
7351
7717
|
return target;
|
|
7352
7718
|
}
|
|
7719
|
+
function markerNotDetected(message) {
|
|
7720
|
+
return /test mode not detected(?! \()/.test(message);
|
|
7721
|
+
}
|
|
7722
|
+
function declarationHint(spec) {
|
|
7723
|
+
const step = spec.parsed.steps.find((s) => s.kind === "payment");
|
|
7724
|
+
if (!spec.testPayment || step?.kind !== "payment") return void 0;
|
|
7725
|
+
return `Declare it in ${testPaymentHostsPath()} with { "host": "${spec.testPayment.host}", "testMode": "${step.value.provider}" } if this store is in test mode.`;
|
|
7726
|
+
}
|
|
7353
7727
|
async function executeRun(spec, rawIo) {
|
|
7354
7728
|
const { parsed, gtmOverride, variant } = spec;
|
|
7355
7729
|
let io = rawIo;
|
|
@@ -7392,6 +7766,9 @@ async function executeRun(spec, rawIo) {
|
|
|
7392
7766
|
const message = error instanceof Error ? error.message : String(error);
|
|
7393
7767
|
if (MISSING_BROWSER.test(message)) return failed("Chromium is not installed. Run `tagreeve install-browser`.\n");
|
|
7394
7768
|
let text2 = `Run failed: ${error instanceof GtmOverrideFailure ? `GTM override: ${message}` : message}
|
|
7769
|
+
`;
|
|
7770
|
+
const declareHint = spec.testPayment && markerNotDetected(message) && declarationHint(spec);
|
|
7771
|
+
if (declareHint) text2 += `${declareHint}
|
|
7395
7772
|
`;
|
|
7396
7773
|
const written = (error instanceof StepError || error instanceof GtmOverrideFailure) && error.run ? error.run.path : void 0;
|
|
7397
7774
|
if (written) {
|
|
@@ -7501,11 +7878,8 @@ ${error.issues.map((i) => ` ${i}`).join("\n")}
|
|
|
7501
7878
|
if (!outcome.summary) return outcome.code;
|
|
7502
7879
|
let code = outcome.code === 1 ? 1 : 0;
|
|
7503
7880
|
if (baseline && outcome.path) {
|
|
7504
|
-
outcome.summary
|
|
7505
|
-
if (outcome.summary.baseline
|
|
7506
|
-
code = 1;
|
|
7507
|
-
outcome.summary.ok = false;
|
|
7508
|
-
}
|
|
7881
|
+
applyBaseline(outcome.summary, compareBaseline(baseline, await readRun(outcome.path)));
|
|
7882
|
+
if (outcome.summary.baseline?.drift) code = 1;
|
|
7509
7883
|
}
|
|
7510
7884
|
const output = args.json ? `${JSON.stringify(outcome.summary, null, 2)}
|
|
7511
7885
|
` : `${formatSummary(outcome.summary)}
|
|
@@ -8029,8 +8403,8 @@ async function main(argv, io = processIo) {
|
|
|
8029
8403
|
}
|
|
8030
8404
|
} catch (error) {
|
|
8031
8405
|
if (error instanceof UsageError) io.stderr(`${error.message}
|
|
8032
|
-
|
|
8033
|
-
|
|
8406
|
+
${usageHint(error.command)}
|
|
8407
|
+
`);
|
|
8034
8408
|
else io.stderr(`${error instanceof Error ? error.message : String(error)}
|
|
8035
8409
|
`);
|
|
8036
8410
|
return 2;
|
package/dist/cli.js
CHANGED
package/dist/pingwright.js
CHANGED