tagreeve 0.4.0-rc.2 → 0.4.0-rc.3
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 +2 -2
- package/dist/{chunk-2QH7GCQL.js → chunk-XDYUCYGC.js} +77 -23
- 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.3`).** 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,7 +17,7 @@ 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.
|
|
20
|
+
> **In 0.4.0-rc.3** (install with `npm i -g tagreeve@next` until 0.4.0): the `payment` step types into the exact card frame it checked, skips hidden duplicate frames, and keeps the reason when a card field cannot be filled; the declaration hint names the failed step's provider and shows only an entry the allowlist file accepts. 0.4.0-rc.2 added test-mode declarations for payment hosts, the `earlyIdentifiers` check and better baselines. What is still open is in [CHANGELOG.md](CHANGELOG.md) under "Known in 0.4.0-rc.3".
|
|
21
21
|
>
|
|
22
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".
|
|
23
23
|
>
|
|
@@ -6915,9 +6915,9 @@ var RUNTIME = {
|
|
|
6915
6915
|
marker: "#pw-test-mode",
|
|
6916
6916
|
cardHost: "127.0.0.1",
|
|
6917
6917
|
fields: [
|
|
6918
|
-
{ kind: "number", frame: "#card-frame", input: "#cc-number" },
|
|
6919
|
-
{ kind: "expiry", frame: "#card-frame", input: "#cc-exp" },
|
|
6920
|
-
{ kind: "cvc", frame: "#card-frame", input: "#cc-csc" }
|
|
6918
|
+
{ kind: "number", frame: "#card-frame, #card-frame-number", input: "#cc-number" },
|
|
6919
|
+
{ kind: "expiry", frame: "#card-frame, #card-frame-exp", input: "#cc-exp" },
|
|
6920
|
+
{ kind: "cvc", frame: "#card-frame, #card-frame-csc", input: "#cc-csc" }
|
|
6921
6921
|
]
|
|
6922
6922
|
}
|
|
6923
6923
|
};
|
|
@@ -6941,15 +6941,24 @@ function hostOf5(url) {
|
|
|
6941
6941
|
}
|
|
6942
6942
|
}
|
|
6943
6943
|
async function cardFrameServed(page2, field, cardHost, deadline) {
|
|
6944
|
+
let reason = "not found";
|
|
6944
6945
|
for (; ; ) {
|
|
6945
6946
|
try {
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6947
|
+
let hidden = false;
|
|
6948
|
+
let elsewhere = false;
|
|
6949
|
+
for (const element of await page2.locator(field.frame).elementHandles()) {
|
|
6950
|
+
const frame = await element.contentFrame();
|
|
6951
|
+
if (!frame) continue;
|
|
6952
|
+
const served = hostOf5(frame.url()) === cardHost;
|
|
6953
|
+
if (served && await element.isVisible()) return { element, frame };
|
|
6954
|
+
if (served) hidden = true;
|
|
6955
|
+
else elsewhere = true;
|
|
6956
|
+
}
|
|
6957
|
+
reason = hidden ? "not visible" : elsewhere ? "served from another host" : "not found";
|
|
6949
6958
|
} catch {
|
|
6950
|
-
return
|
|
6959
|
+
return reason;
|
|
6951
6960
|
}
|
|
6952
|
-
if (Date.now() >= deadline) return
|
|
6961
|
+
if (Date.now() >= deadline) return reason;
|
|
6953
6962
|
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
6954
6963
|
}
|
|
6955
6964
|
}
|
|
@@ -6989,23 +6998,59 @@ async function runPayment(page2, recorder, value, identity, testPayment, record,
|
|
|
6989
6998
|
const declared = testPayment.declaredProviders?.includes(provider.id) === true;
|
|
6990
6999
|
const wait = Math.min(timeout, MARKER_TIMEOUT_MS);
|
|
6991
7000
|
const deadline = Date.now() + wait;
|
|
6992
|
-
const
|
|
7001
|
+
const found = [];
|
|
6993
7002
|
for (const field of runtime.fields) {
|
|
6994
|
-
const
|
|
6995
|
-
if (
|
|
6996
|
-
|
|
7003
|
+
const result = await cardFrameServed(page2, field, runtime.cardHost, deadline);
|
|
7004
|
+
if (typeof result === "string") throw new Error(`card frame not found (${field.kind}): ${result}`);
|
|
7005
|
+
found.push(result);
|
|
6997
7006
|
}
|
|
6998
|
-
if (!declared && !await markerInCardContainer(
|
|
7007
|
+
if (!declared && !await markerInCardContainer(found.map((f) => f.element), runtime.marker, wait)) throw new Error("test mode not detected");
|
|
6999
7008
|
recorder.holdRedaction();
|
|
7009
|
+
const typed = typedValues(provider, card, identity);
|
|
7000
7010
|
for (const [index, field] of runtime.fields.entries()) {
|
|
7001
7011
|
try {
|
|
7002
|
-
await
|
|
7003
|
-
} catch {
|
|
7004
|
-
throw new Error(`card field ${field.kind} could not be filled`);
|
|
7012
|
+
await fillVerified(found[index].element, field, runtime.cardHost, valueOf(field.kind, provider, card, identity), timeout);
|
|
7013
|
+
} catch (error) {
|
|
7014
|
+
throw new Error(`card field ${field.kind} could not be filled: ${reasonOf(error, typed)}`);
|
|
7005
7015
|
}
|
|
7006
7016
|
if (index === 0) record.payment = { provider: provider.id, mode: "test", testMode: declared ? "declared" : "marker" };
|
|
7007
7017
|
}
|
|
7008
7018
|
}
|
|
7019
|
+
async function frameStillServed(element, cardHost) {
|
|
7020
|
+
const frame = await element.contentFrame();
|
|
7021
|
+
if (!frame || hostOf5(frame.url()) !== cardHost) throw new OwnReason("the card frame is gone or not served from the card host");
|
|
7022
|
+
return frame;
|
|
7023
|
+
}
|
|
7024
|
+
async function fillVerified(element, field, cardHost, value, timeout) {
|
|
7025
|
+
const deadline = Date.now() + timeout;
|
|
7026
|
+
for (; ; ) {
|
|
7027
|
+
const frame = await frameStillServed(element, cardHost);
|
|
7028
|
+
const inputs = frame.locator(field.input).filter({ visible: true });
|
|
7029
|
+
const count = await inputs.count();
|
|
7030
|
+
if (count === 1) {
|
|
7031
|
+
await frameStillServed(element, cardHost);
|
|
7032
|
+
await inputs.fill(value, { timeout: Math.max(1, deadline - Date.now()) });
|
|
7033
|
+
return;
|
|
7034
|
+
}
|
|
7035
|
+
if (Date.now() >= deadline) throw new OwnReason(`${count} visible inputs match`);
|
|
7036
|
+
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
7037
|
+
}
|
|
7038
|
+
}
|
|
7039
|
+
function typedValues(provider, card, identity) {
|
|
7040
|
+
const values = [card, provider.expiry, provider.cvc, identity.firstName, identity.lastName, `${identity.firstName} ${identity.lastName}`];
|
|
7041
|
+
return values.filter((v) => v.length > 0).sort((a, b) => b.length - a.length);
|
|
7042
|
+
}
|
|
7043
|
+
var OwnReason = class extends Error {
|
|
7044
|
+
};
|
|
7045
|
+
function reasonOf(error, typed) {
|
|
7046
|
+
if (error instanceof OwnReason) return error.message;
|
|
7047
|
+
const first = (error instanceof Error ? error.message : String(error)).split("\n")[0] ?? "";
|
|
7048
|
+
const pattern = (value) => {
|
|
7049
|
+
const escaped = value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7050
|
+
return new RegExp(value.length < 4 ? `(?<!\\d)${escaped}(?!\\d)` : escaped, "g");
|
|
7051
|
+
};
|
|
7052
|
+
return typed.reduce((text2, value) => text2.replace(pattern(value), "[value]"), first).trim() || "unknown error";
|
|
7053
|
+
}
|
|
7009
7054
|
|
|
7010
7055
|
// packages/recorder/src/steps.ts
|
|
7011
7056
|
var bannerConsentHandler = async (answer, { recorder, page: page2, timeoutMs }) => {
|
|
@@ -7409,6 +7454,11 @@ function testPaymentHostsPath(env = process.env, home = homedir()) {
|
|
|
7409
7454
|
const base2 = xdg && isAbsolute(xdg) ? xdg : join5(home, ".config");
|
|
7410
7455
|
return join5(base2, "tagreeve", FILE_NAME);
|
|
7411
7456
|
}
|
|
7457
|
+
function acceptsDeclaration(host, testMode, loopbackHosted = loopbackIsHostedForTests()) {
|
|
7458
|
+
const loopback = isLoopbackHost(normalizeHost(host));
|
|
7459
|
+
if (testMode === "fixture") return loopback && loopbackHosted;
|
|
7460
|
+
return !loopback;
|
|
7461
|
+
}
|
|
7412
7462
|
function entryError(path, index, reason) {
|
|
7413
7463
|
return new Error(`${path}: entry ${index} ${reason}.`);
|
|
7414
7464
|
}
|
|
@@ -7421,8 +7471,7 @@ function parseEntry3(path, entry, index, loopbackHosted) {
|
|
|
7421
7471
|
}
|
|
7422
7472
|
const normalized = normalizeHost(host);
|
|
7423
7473
|
if (!findPaymentProvider(testMode)) throw entryError(path, index, "names a testMode that is not a payment provider");
|
|
7424
|
-
|
|
7425
|
-
if (!testOnly && (testMode === "fixture" || isLoopbackHost(normalized))) {
|
|
7474
|
+
if (!acceptsDeclaration(normalized, testMode, loopbackHosted)) {
|
|
7426
7475
|
throw entryError(path, index, "declares a loopback host or the fixture provider, which only tests may do");
|
|
7427
7476
|
}
|
|
7428
7477
|
return { host: normalized, testMode };
|
|
@@ -7719,10 +7768,15 @@ async function labelRecord(path, variant, out) {
|
|
|
7719
7768
|
function markerNotDetected(message) {
|
|
7720
7769
|
return /test mode not detected(?! \()/.test(message);
|
|
7721
7770
|
}
|
|
7722
|
-
function declarationHint(spec) {
|
|
7723
|
-
|
|
7724
|
-
|
|
7725
|
-
|
|
7771
|
+
function declarationHint(spec, label) {
|
|
7772
|
+
if (!spec.testPayment) return void 0;
|
|
7773
|
+
const payments = spec.parsed.steps.flatMap((s) => s.kind === "payment" ? [s] : []);
|
|
7774
|
+
const failed = label === void 0 ? void 0 : payments.find((s) => s.label === label);
|
|
7775
|
+
const providers = failed ? [failed.value.provider] : [...new Set(payments.map((s) => s.value.provider))];
|
|
7776
|
+
const host = spec.testPayment.host;
|
|
7777
|
+
const hints = providers.filter((provider) => acceptsDeclaration(host, provider)).map((provider) => `{ "host": "${host}", "testMode": "${provider}" }`);
|
|
7778
|
+
if (hints.length === 0) return void 0;
|
|
7779
|
+
return `Declare it in ${testPaymentHostsPath()} with ${hints.join(" or ")} if this store is in test mode.`;
|
|
7726
7780
|
}
|
|
7727
7781
|
async function executeRun(spec, rawIo) {
|
|
7728
7782
|
const { parsed, gtmOverride, variant } = spec;
|
|
@@ -7767,7 +7821,7 @@ async function executeRun(spec, rawIo) {
|
|
|
7767
7821
|
if (MISSING_BROWSER.test(message)) return failed("Chromium is not installed. Run `tagreeve install-browser`.\n");
|
|
7768
7822
|
let text2 = `Run failed: ${error instanceof GtmOverrideFailure ? `GTM override: ${message}` : message}
|
|
7769
7823
|
`;
|
|
7770
|
-
const declareHint = spec.testPayment && markerNotDetected(message) && declarationHint(spec);
|
|
7824
|
+
const declareHint = spec.testPayment && markerNotDetected(message) && declarationHint(spec, error instanceof StepError ? error.label : void 0);
|
|
7771
7825
|
if (declareHint) text2 += `${declareHint}
|
|
7772
7826
|
`;
|
|
7773
7827
|
const written = (error instanceof StepError || error instanceof GtmOverrideFailure) && error.run ? error.run.path : void 0;
|
package/dist/cli.js
CHANGED
package/dist/pingwright.js
CHANGED