tagreeve 0.9.0 → 0.9.1

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.1
4
+
5
+ `npm i -g tagreeve` installs this release. 0.9.1 is a patch release after 0.9.0. It has no new command, option or record field. The record stays at schema version 5. A 0.9.0 record reads as before.
6
+
7
+ ### Fixes in 0.9.1
8
+
9
+ - Variables: a `{name}` inside a variable value is now filled, three levels deep too, in the start URL and in every visit path. A variable cycle exits 2 before the recorder starts and names the place and the variables, never a value. A canary run plants the canaries on the fully filled start (#1666, #1671).
10
+ - `identifierRoute`: a padded Base64 SHA-256 digest of a canary or of the identity email now reads transform `sha256`, as the unpadded digest does. A canary followed by `=` reads `plain` (#1667, #1670).
11
+
12
+ ### Upgrading from 0.9.0
13
+
14
+ - **A nested variable now opens the filled page, so checks can fail where they passed.** A start URL or visit path that used a variable holding a `{name}` opened the literal `%7Bname%7D` path in 0.9.0, and the run could exit 0 on the wrong page. It now opens the filled page, and the rules run against that page.
15
+ - **A variable cycle exits 2.** A cycle made by `{a}` and `{b}` pointing at each other, in the config or in a `--var` value, stops the run before the recorder starts.
16
+ - **A `#` in a used variable now runs.** 0.9.0 refused a canary run when a used variable held a `#` and another variable held a `{name}`. It now runs, with the canaries planted before the `#`.
17
+ - **A padded digest reads `sha256` and a canary followed by `=` reads `plain`.** Report rows and route lines that were split between `other` and the plain form now merge. No verdict changes.
18
+ - **A new release needs a new server image.** On arm64 (Apple silicon), run `tagreeve server-container build` after `npm i -g tagreeve`. A run with `--server-container` exits 2 with "The image tagreeve-sgtm:<version> is not available" until the image for that version exists. On amd64 the command builds nothing.
19
+
20
+ ### Known in 0.9.1
21
+
22
+ Issues still open that you can meet, in addition to those in 0.7.0:
23
+
24
+ - The canary search reads only the forms it lists. It skips gzip and binary bodies, bodies cut at 64 KiB and net-log requests with no body, and it does not search headers. A pass means no planted value was found in the searched forms.
25
+ - The Stape loader unwrap covers `/g/collect` and `/data`. Stape's hosting layer may act on a loader request in other ways, and the record says so in fixed text.
26
+
3
27
  ## 0.9.0
4
28
 
5
29
  `npm i -g tagreeve` installs this release. 0.9.0 is the final release after 0.9.0-rc.1, with no changes since the candidate. It has no new command or option. The record stays at schema version 5, and a 0.8 record reads as before. It was field-tested on a real store with no regressions.
@@ -31,8 +55,6 @@ Issues still open that you can meet, in addition to those in 0.7.0:
31
55
 
32
56
  - The canary search reads only the forms it lists. It skips gzip and binary bodies, bodies cut at 64 KiB and net-log requests with no body, and it does not search headers. A pass means no planted value was found in the searched forms.
33
57
  - The Stape loader unwrap covers `/g/collect` and `/data`. Stape's hosting layer may act on a loader request in other ways, and the record says so in fixed text.
34
- - A `{placeholder}` inside a variable value is never filled, because the start URL is filled in one pass (#1666). The browser opens the literal `%7Bname%7D` path, and the run can exit 0.
35
- - A padded Base64 SHA-256 match reads transform `other`, not `sha256`, in the route line and the report rows (#1667). The verdict is not affected.
36
58
 
37
59
  ## 0.8.1
38
60
 
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. Web tag reports (which GTM web tags fired) come from a GTM template you install. Server tag reports are planned.
11
11
 
12
- > **Status: 0.9 (`0.9.0`).** 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. 0.5 adds `--server-container`, which runs your own server container in Docker and records what it sends to each vendor, a Conversions API decoder, several stores in one suite and platform hosts for Shopify. 0.6.0-rc.1 adds path defaults, `tagreeve init`, `tagreeve/config.yml`, `--label`, default baseline paths and `suite --baseline`, exact links between server container calls and browser hits by client ID, and the frame of each `dataLayer` push. 0.6.0-rc.2 adds web tag reports, `tagreeve template web`, `tag` rules, `expectedTags`, masked `dataLayer` push shapes in `diff` and baselines, and the `consentModeSetup` check. 0.6.0-rc.3 fixes the reporter in real GTM, keeps the `dataLayer` hook working when a page replaces `push`, adds push kinds and a `dataLayerIncomplete` flag, and sends handoff text to stderr. 0.6.0 is rc.3 with the release prep and no code change; it was field-tested on a real store with a real GTM web container in a workspace preview (rc.2 and rc.3). 0.7.0 adds the `earlyIdentityPush`, `idHandover` and `serverContainerRejected` checks and `dataLayer:` rules. 0.8.0-rc.1 adds a consent audit: `suite --consent`, identifier canaries and the `identifierRoute` check. 0.8.0 is rc.4 with the release prep and no code change; it was field-tested on a real Shopify store with a first-party server container (rc.1 to rc.4). 0.9.0-rc.1 fixes server container links, canaries, consent matrix names and `dataLayer` loaders, and decodes Pinterest Conversions API calls. 0.9.0 is rc.1 with the release prep and no code change; it was field-tested on a real store with no regressions. 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.
12
+ > **Status: 0.9 (`0.9.1`).** 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. 0.5 adds `--server-container`, which runs your own server container in Docker and records what it sends to each vendor, a Conversions API decoder, several stores in one suite and platform hosts for Shopify. 0.6.0-rc.1 adds path defaults, `tagreeve init`, `tagreeve/config.yml`, `--label`, default baseline paths and `suite --baseline`, exact links between server container calls and browser hits by client ID, and the frame of each `dataLayer` push. 0.6.0-rc.2 adds web tag reports, `tagreeve template web`, `tag` rules, `expectedTags`, masked `dataLayer` push shapes in `diff` and baselines, and the `consentModeSetup` check. 0.6.0-rc.3 fixes the reporter in real GTM, keeps the `dataLayer` hook working when a page replaces `push`, adds push kinds and a `dataLayerIncomplete` flag, and sends handoff text to stderr. 0.6.0 is rc.3 with the release prep and no code change; it was field-tested on a real store with a real GTM web container in a workspace preview (rc.2 and rc.3). 0.7.0 adds the `earlyIdentityPush`, `idHandover` and `serverContainerRejected` checks and `dataLayer:` rules. 0.8.0-rc.1 adds a consent audit: `suite --consent`, identifier canaries and the `identifierRoute` check. 0.8.0 is rc.4 with the release prep and no code change; it was field-tested on a real Shopify store with a first-party server container (rc.1 to rc.4). 0.9.0-rc.1 fixes server container links, canaries, consent matrix names and `dataLayer` loaders, and decodes Pinterest Conversions API calls. 0.9.0 is rc.1 with the release prep and no code change; it was field-tested on a real store with no regressions. 0.9.1 fixes nested variables and the transform of a padded digest. 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.9.1:** a patch release after 0.9.0, with no new command, option or record field. A `{name}` inside a variable value is now filled, so a start URL or visit path that uses a nested variable opens the filled page, and a variable cycle exits 2. A padded Base64 SHA-256 digest of a canary reads transform `sha256` in an `identifierRoute` flag. The record stays at schema version 5, and a 0.9.0 record reads as before. `npm i -g tagreeve` installs it. On arm64, run `tagreeve server-container build` after the upgrade. What is new is in [CHANGELOG.md](CHANGELOG.md) under 0.9.1.
21
+ >
20
22
  > **In 0.9.0:** the final 0.9.0, the same as 0.9.0-rc.1 with no changes since the candidate, and with no new command or option. A server call that arrives up to 2000 ms after its answered same-key hit now links exactly, so a rule that only warned can now fail the run. Pinterest Conversions API calls are decoded as `pinterest-capi` and link to browser hits by event ID. Fixes to canaries, consent matrix event names and `dataLayer` iframe loaders. The record stays at schema version 5. `npm i -g tagreeve` installs it. On arm64, run `tagreeve server-container build` after the upgrade. What is new is in [CHANGELOG.md](CHANGELOG.md) under 0.9.0.
21
23
  >
22
24
  > **In 0.8.1:** a patch release with no new command or option. `tagreeve diff --by-page` prints only the path of a recorded page, so a fake canary value in a page URL no longer reaches the text or `diff --json`. The `identifierRoute` pass message is true when every route went to an allowed host. The record stays at schema version 5. `npm i -g tagreeve` installs it. On arm64, run `tagreeve server-container build` after the upgrade. What is new is in [CHANGELOG.md](CHANGELOG.md) under 0.8.1.
package/dist/cli.js CHANGED
@@ -778,6 +778,31 @@ function isServerContainerRequest(req, serverHosts) {
778
778
  return !isLibraryLoadPath(url.pathname) && !LOAD_RESOURCE_TYPES.has(req.resourceType);
779
779
  }
780
780
 
781
+ // packages/core/src/vars.ts
782
+ var VarCycleError = class extends Error {
783
+ names;
784
+ constructor(names) {
785
+ super(`variables ${names.join(", ")} use each other in a cycle`);
786
+ this.name = "VarCycleError";
787
+ this.names = names;
788
+ }
789
+ };
790
+ function fillVars(text2, vars) {
791
+ const done = /* @__PURE__ */ new Map();
792
+ const fill = (value, stack) => value.replace(/\{(\w+)\}/g, (match, name) => {
793
+ if (!Object.hasOwn(vars, name)) return match;
794
+ const at = stack.indexOf(name);
795
+ if (at >= 0) throw new VarCycleError(stack.slice(at));
796
+ let filled = done.get(name);
797
+ if (filled === void 0) {
798
+ filled = fill(vars[name], [...stack, name]);
799
+ done.set(name, filled);
800
+ }
801
+ return filled;
802
+ });
803
+ return fill(text2, []);
804
+ }
805
+
781
806
  // packages/decoders/src/decoder.ts
782
807
  var defaultHitId = () => newId("hit");
783
808
  var vendorKeys = ["ga4", "google-ads", "meta", "meta-capi", "pinterest", "pinterest-capi", "sgtm"];
@@ -7561,8 +7586,8 @@ function scan2(text2, pool, transforms, depth = 0) {
7561
7586
  const layers = readings(text2);
7562
7587
  const name = pool.match(text2);
7563
7588
  if (name !== void 0) {
7564
- const read = layers.find((layer) => transforms.has(layer));
7565
- found.set(name, { name, transform: read === void 0 ? "other" : transforms.get(read) });
7589
+ const read = layers.map((layer) => transforms.get(layer) ?? transforms.get(layer.replace(/=+$/, ""))).find((t) => t !== void 0);
7590
+ found.set(name, { name, transform: read ?? "other" });
7566
7591
  }
7567
7592
  if (depth < MAX_DEPTH4) {
7568
7593
  for (const layer of layers) {
@@ -10814,7 +10839,7 @@ function fillValue(value, identity) {
10814
10839
  }
10815
10840
  function resolveSitePath(path, site, vars) {
10816
10841
  const base2 = new URL(site);
10817
- const filled = path.replace(/\{(\w+)\}/g, (_m, name) => vars[name] ?? `{${name}}`);
10842
+ const filled = fillVars(path, vars);
10818
10843
  const url = new URL(filled, base2);
10819
10844
  if (url.origin !== base2.origin) throw new Error(`"${path}" leaves the site ${base2.origin}`);
10820
10845
  return url.href;
@@ -13543,27 +13568,12 @@ function queryNames(start) {
13543
13568
  }
13544
13569
  });
13545
13570
  }
13546
- function usedVarValues(start, vars) {
13547
- const seen = /* @__PURE__ */ new Set();
13548
- const queue = [start];
13549
- while (queue.length) {
13550
- for (const m of queue.pop().matchAll(/\{(\w+)\}/g)) {
13551
- const name = m[1];
13552
- if (!Object.hasOwn(vars, name) || seen.has(name)) continue;
13553
- seen.add(name);
13554
- queue.push(vars[name]);
13555
- }
13556
- }
13557
- return [...seen].map((name) => vars[name]);
13558
- }
13559
- function withCanaries(start, canaries, probe2 = start) {
13571
+ function withCanaries(start, canaries) {
13560
13572
  const hash = start.indexOf("#");
13561
13573
  const base2 = hash < 0 ? start : start.slice(0, hash);
13562
13574
  const tail = hash < 0 ? "" : start.slice(hash);
13563
- const probeHash = probe2.indexOf("#");
13564
- const probeBase = probeHash < 0 ? probe2 : probe2.slice(0, probeHash);
13565
13575
  const added = canaries.map((c) => `${c.name}=${encodeURIComponent(c.value)}`).join("&");
13566
- return `${base2}${probeBase.includes("?") ? /[?&]$/.test(probeBase) ? "" : "&" : "?"}${added}${tail}`;
13576
+ return `${base2}${base2.includes("?") ? /[?&]$/.test(base2) ? "" : "&" : "?"}${added}${tail}`;
13567
13577
  }
13568
13578
  var nameCanaries = maskCanaries;
13569
13579
  async function scrubStepErrors(path, canaries) {
@@ -13586,19 +13596,26 @@ async function executeRun(spec, rawIo) {
13586
13596
  io.stderr(error);
13587
13597
  return { code: 2, error: scrubber ? scrubber.text(error) : error };
13588
13598
  };
13599
+ let filledStart = parsed.start;
13600
+ const places = [["start", parsed.start], ...parsed.steps.flatMap((s, i) => s.kind === "visit" ? [[`step ${i + 1}`, s.value]] : [])];
13601
+ for (const [place, text2] of places) {
13602
+ try {
13603
+ const filled = fillVars(text2, parsed.vars);
13604
+ if (place === "start") filledStart = filled;
13605
+ } catch (error) {
13606
+ if (!(error instanceof VarCycleError)) throw error;
13607
+ return failed(`${place}: ${error.message}. Break the cycle.
13608
+ `);
13609
+ }
13610
+ }
13589
13611
  if (parsed.options.canaries) {
13590
- const resolved = parsed.start.replace(/\{(\w+)\}/g, (m, name) => parsed.vars[name] ?? m);
13591
- const held = queryNames(resolved);
13612
+ const held = queryNames(filledStart);
13592
13613
  const taken = CANARY_NAMES.find((name) => held.includes(name));
13593
13614
  if (taken) return failed(`options.canaries: the start URL already holds the ${taken} parameter. Remove it from start, or turn canaries off.
13594
13615
  `);
13595
13616
  seed ??= parsed.options.seed ?? Math.floor(Math.random() * 2 ** 31);
13596
13617
  canaries = canaryValues(seed, spec.consentCell);
13597
- const refilled = [...resolved.matchAll(/\{(\w+)\}/g)].some((m) => Object.hasOwn(parsed.vars, m[1]));
13598
- if (refilled && usedVarValues(parsed.start, parsed.vars).some((v) => v.includes("#"))) {
13599
- return failed("options.canaries: a variable the start URL uses holds a #, while a variable holds a {placeholder} that is filled again, so the canary parameters could land in the URL fragment. Remove one, or turn canaries off.\n");
13600
- }
13601
- parsed = { ...parsed, start: refilled ? withCanaries(parsed.start, canaries, resolved) : withCanaries(resolved, canaries) };
13618
+ parsed = { ...parsed, start: withCanaries(filledStart, canaries) };
13602
13619
  }
13603
13620
  let records;
13604
13621
  let path;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tagreeve",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Agent-first testing for website tracking and consent.",
5
5
  "license": "MIT",
6
6
  "repository": {