tagreeve 0.5.0-rc.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +9 -7
  2. package/dist/cli.js +49 -26
  3. 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.5 (`0.5.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. 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. 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.5 (`0.5.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. 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,13 +17,15 @@ 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.5.0-rc.2** (install with `npm i -g tagreeve@next` until 0.5.0): the `payment` step finds Shopify card fields by `name` or `autocomplete` and frame path; a server container call just after a handoff is stored without its body and query values; summaries show query names only; hit and cookie rules take `from: <step label>`; every command has its own `--help`; and `--by-page` masks more value-like path segments. What is still open is in [CHANGELOG.md](CHANGELOG.md) under "Known in 0.5.0-rc.2".
20
+ > **In 0.5.0:** a hit rule takes `sentBy: browser` or `sentBy: server`, so a rule on a Google host can ignore the server container's own forwarding; a missing `tagreeve-sgtm` image stops a suite before any scenario starts, and the message lists the local tags; the server container guide shows how to test an unpublished server workspace through its preview environment; and the text and `--json` summaries show query names only and mask value-like path segments, for every form of URL. Records keep the full detail. What is still open is in [CHANGELOG.md](CHANGELOG.md) under "Known in 0.5.0".
21
21
  >
22
- > **In 0.5.0-rc.1** (install with `npm i -g tagreeve@next` until 0.5.0): `run` and `suite` take `--server-container` and `--server-container-config`, which run your own published server container in Docker, route the browser's requests for your `serverHosts` to it, and record every call it makes to a vendor, decoded and checked like browser hits; `tagreeve server-container build` builds the image; a `meta-capi` decoder; `suite --stores` runs each scenario against several stores; `platformHost` flags Shopify infrastructure requests; `unloadGap` also covers the end of a run; `--by-page` keys mask value-like path segments; and the old command alias is gone.
22
+ > **In 0.5.0-rc.2:** the `payment` step finds Shopify card fields by `name` or `autocomplete` and frame path; a server container call just after a handoff is stored without its body and query values; summaries show query names only; hit and cookie rules take `from: <step label>`; every command has its own `--help`; and `--by-page` masks more value-like path segments.
23
+ >
24
+ > **In 0.5.0-rc.1:** `run` and `suite` take `--server-container` and `--server-container-config`, which run your own published server container in Docker, route the browser's requests for your `serverHosts` to it, and record every call it makes to a vendor, decoded and checked like browser hits; `tagreeve server-container build` builds the image; a `meta-capi` decoder; `suite --stores` runs each scenario against several stores; `platformHost` flags Shopify infrastructure requests; `unloadGap` also covers the end of a run; `--by-page` keys mask value-like path segments; and the old command alias is gone.
23
25
  >
24
26
  > **In 0.4.0-rc.3:** the `payment` step types into the exact card frame it checked, and the declaration hint names the failed step's provider. 0.4.0-rc.2 added test-mode declarations for payment hosts, the `earlyIdentifiers` check and better baselines.
25
27
  >
26
- > **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".
28
+ > **In 0.4.0-rc.1:** 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".
27
29
  >
28
30
  > **Not built yet:** the tag-firing reporter templates and `expectedTags`, `tagreeve init`, 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`.
29
31
 
@@ -78,15 +80,15 @@ tagreeve run scenarios/undecided-visitor.yml --site https://staging.example.com
78
80
  ## Install
79
81
 
80
82
  ```bash
81
- npm i -g tagreeve@next
83
+ npm i -g tagreeve
82
84
  tagreeve install-browser
83
85
  ```
84
86
 
85
- Node 22.18 or later. `npm i -g tagreeve@next` installs the newest 0.5 release candidate. Other ways to install, from a git tag or a tarball, are in [docs/cli.md](docs/cli.md).
87
+ Node 22.18 or later. `npm i -g tagreeve` installs the newest release. Other ways to install, from a git tag or a tarball, are in [docs/cli.md](docs/cli.md).
86
88
 
87
89
  ## Quick start
88
90
 
89
- 1. `npm i -g tagreeve@next`
91
+ 1. `npm i -g tagreeve`
90
92
  2. `tagreeve install-browser`
91
93
  3. Write `scenario.yml`:
92
94
 
package/dist/cli.js CHANGED
@@ -688,6 +688,11 @@ function looksLikeValueToken(segment) {
688
688
  if (HEX_TOKEN.test(segment) || LONG_DIGITS.test(segment) || mostlyDigits(segment)) return true;
689
689
  return DIGEST_TOKEN.test(segment) && /[A-Z]/.test(segment) && /[a-z]/.test(segment) && /\d/.test(segment);
690
690
  }
691
+ function isValueSegment(segment) {
692
+ if (looksLikeValueToken(segment) || looksLikeValueToken(segment.replaceAll("-", ""))) return true;
693
+ if (segment.includes("@") || /%[0-9a-fA-F]{2}/.test(segment)) return true;
694
+ return valueKinds(segment).size > 0;
695
+ }
691
696
  function looksLikeValue(segment) {
692
697
  return !NAME_CHARS.test(segment) || looksLikeValueToken(segment);
693
698
  }
@@ -867,6 +872,13 @@ function isSandboxPageUrl(page2) {
867
872
  function stripSandboxPrefix(path) {
868
873
  return path.replace(SANDBOX_PREFIX, "") || "/";
869
874
  }
875
+ function maskValuePath(path, mask) {
876
+ const maskSegments = (part) => part.split("/").map((segment) => isValueSegment(segment) ? mask : segment).join("/");
877
+ const prefix = SANDBOX_PREFIX.exec(path);
878
+ if (!prefix) return maskSegments(path);
879
+ const end = prefix.index + prefix[0].length;
880
+ return maskSegments(path.slice(0, prefix.index)) + prefix[0] + maskSegments(path.slice(end));
881
+ }
870
882
 
871
883
  // packages/decoders/src/ga4.ts
872
884
  function parseUrl(url) {
@@ -1787,7 +1799,7 @@ var ScenarioError = class extends Error {
1787
1799
  this.issues = issues;
1788
1800
  }
1789
1801
  };
1790
- var VENDOR_KEYS = /* @__PURE__ */ new Set(["vendor", "event", "page", "transport", "host", "outcome", "count", "before", "in", "after", "from"]);
1802
+ var VENDOR_KEYS = /* @__PURE__ */ new Set(["vendor", "event", "page", "transport", "host", "outcome", "count", "before", "in", "after", "from", "sentBy"]);
1791
1803
  var GROUP_KEYS = ["consent", "ids", "params", "identity", "body"];
1792
1804
  var COOKIE_RULE_KEYS = ["cookie", "before", "in", "after", "from"];
1793
1805
  var BODY_KEYS = ["has", "only", "ignore"];
@@ -2228,6 +2240,9 @@ function parseScenario(text2, extraVendorKeys = []) {
2228
2240
  } else if (k === "event" || k === "transport" || k === "host") {
2229
2241
  const l = list2(k, v);
2230
2242
  if (l) filter[k] = l;
2243
+ } else if (k === "sentBy") {
2244
+ if (v === "browser" || v === "server") filter.sentBy = v;
2245
+ else fail(p, "must be browser or server");
2231
2246
  } else if (k === "outcome") {
2232
2247
  const l = list2(k, v, OUTCOMES);
2233
2248
  if (l) filter.outcome = l;
@@ -2406,10 +2421,12 @@ function evaluate(records, scenario, options = {}) {
2406
2421
  const runId = runRecord?.id ?? records.find((r) => "runId" in r)?.runId ?? newId("run");
2407
2422
  const allHits = records.filter((r) => r.type === "hit");
2408
2423
  const allRequests = new Map(records.filter((r) => r.type === "request").map((r) => [r.id, r]));
2424
+ const index = judgeIndex(allHits, allRequests);
2409
2425
  const ctx = {
2410
2426
  hits: allHits,
2411
2427
  requests: allRequests,
2412
- index: judgeIndex(allHits, allRequests),
2428
+ index,
2429
+ serverHitIds: new Set(allHits.filter((h) => isServerHit(h, index)).map((h) => h.id)),
2413
2430
  epochs: records.filter((r) => r.type === "consentEpoch").sort((a, b) => a.startT - b.startT),
2414
2431
  steps: records.filter((r) => r.type === "step"),
2415
2432
  responses: records.filter((r) => r.type === "response"),
@@ -2760,6 +2777,7 @@ function describeSelector(filter) {
2760
2777
  filter.transport && "transport",
2761
2778
  filter.page && "page",
2762
2779
  filter.outcome && "outcome",
2780
+ filter.sentBy && "sentBy",
2763
2781
  Object.keys(filter.ids).length > 0 && "ids",
2764
2782
  Object.keys(filter.params).length > 0 && "params",
2765
2783
  Object.keys(filter.consent).length > 0 && "consent"
@@ -2803,6 +2821,7 @@ function matchesFilter(hit, f, ctx) {
2803
2821
  if (hit.page === null) return false;
2804
2822
  if ("equals" in f.page ? hit.page !== f.page.equals : !new RegExp(f.page.matches).test(hit.page)) return false;
2805
2823
  }
2824
+ if (f.sentBy && ctx.serverHitIds.has(hit.id) !== (f.sentBy === "server")) return false;
2806
2825
  if (f.transport && !f.transport.includes(hit.transport)) return false;
2807
2826
  for (const [name, want] of Object.entries(f.params)) if (hit.params[name] !== want) return false;
2808
2827
  if (f.host || f.outcome) {
@@ -3089,10 +3108,10 @@ function checkHashes(hits, ctx) {
3089
3108
  function pageWithoutQuery(page2) {
3090
3109
  if (!page2) return "";
3091
3110
  try {
3092
- const url = new URL(page2);
3093
- return `${url.host}${url.pathname}`;
3111
+ const url = new URL(page2.startsWith("//") ? `http:${page2}` : page2);
3112
+ return `${url.host}${maskValuePath(url.pathname, "(other)")}`;
3094
3113
  } catch {
3095
- return page2.split(/[?#]/)[0];
3114
+ return maskValuePath(page2.split(/[?#]/)[0], "(other)");
3096
3115
  }
3097
3116
  }
3098
3117
  function flagHost(flag2, ctx) {
@@ -3740,11 +3759,6 @@ function groupHits(run, options) {
3740
3759
  }
3741
3760
  return groups;
3742
3761
  }
3743
- function isValueSegment(segment) {
3744
- if (looksLikeValueToken(segment) || looksLikeValueToken(segment.replaceAll("-", ""))) return true;
3745
- if (segment.includes("@") || /%[0-9a-fA-F]{2}/.test(segment)) return true;
3746
- return valueKinds(segment).size > 0;
3747
- }
3748
3762
  function pagePath(page2) {
3749
3763
  if (page2 === null) return "";
3750
3764
  let path;
@@ -3753,7 +3767,7 @@ function pagePath(page2) {
3753
3767
  } catch {
3754
3768
  path = stripSandboxPrefix(page2);
3755
3769
  }
3756
- return path.split("/").map((segment) => isValueSegment(segment) ? "*" : segment).join("/");
3770
+ return maskValuePath(path, "*");
3757
3771
  }
3758
3772
  function consentChanges(a, b) {
3759
3773
  const changes = [];
@@ -5813,9 +5827,17 @@ async function checkServerContainerHost(options) {
5813
5827
  throw new ServerContainerError("egressOpen", `Docker Engine ${docker.serverVersion} forwards DNS from internal networks (CVE-2024-29018). Upgrade Docker to ${MIN_ENGINE_MAJOR} or newer.`);
5814
5828
  }
5815
5829
  if ((await runDocker(["image", "inspect", "--format", "{{.Id}}", options.image], { env })).code !== 0) {
5816
- throw new ServerContainerError("imageMissing", `The image ${options.image} is not available. Run: tagreeve server-container build`);
5830
+ throw new ServerContainerError("imageMissing", await imageMissingMessage(options.image, env));
5817
5831
  }
5818
5832
  }
5833
+ async function imageMissingMessage(image, env) {
5834
+ const plain = `The image ${image} is not available. Run: tagreeve server-container build`;
5835
+ if (!image.startsWith(`${IMAGE_REPOSITORY}:`)) return plain;
5836
+ const list2 = await runDocker(["image", "ls", "--format", "{{.Tag}}", IMAGE_REPOSITORY], { env, timeoutMs: 3e4 });
5837
+ if (list2.code !== 0) return plain;
5838
+ const tags = list2.stdout.split("\n").map((line) => line.trim()).filter((tag) => tag !== "" && tag !== "<none>");
5839
+ return `The image ${image} is not available. Local ${IMAGE_REPOSITORY} images: ${tags.length > 0 ? tags.join(", ") : "none"}. Run: tagreeve server-container build`;
5840
+ }
5819
5841
  async function startServerContainer(options) {
5820
5842
  const env = options.env ?? process.env;
5821
5843
  const standIn = resolveStandInCommand(env, options.serverHosts);
@@ -8735,7 +8757,7 @@ var WORST_FIRST = ["leak", "unchecked", "mixed", "early", "full", "ping"];
8735
8757
  var CONSENT_FIELDS = ["analytics", "ads", "adUserData", "adPersonalization"];
8736
8758
  var MAX_EVIDENCE = 5;
8737
8759
  var MAX_VALUE = 80;
8738
- var SHOWN_VALUE_KEYS = /* @__PURE__ */ new Set(["vendor", "event", "in", "before", "after", "from", "host", "count", "outcome", "transport", "cookie"]);
8760
+ var SHOWN_VALUE_KEYS = /* @__PURE__ */ new Set(["vendor", "event", "in", "before", "after", "from", "host", "count", "outcome", "transport", "sentBy", "cookie"]);
8739
8761
  var MIXED_HIT = "some signals denied";
8740
8762
  function flatten2(entry) {
8741
8763
  const flat = {};
@@ -9497,7 +9519,7 @@ function formatFlags(flags2) {
9497
9519
  if (f.kind === "platformHost" && platformOf(f)) continue;
9498
9520
  const target = groupTarget(f);
9499
9521
  if (!target) {
9500
- lines.push(` ${f.kind}: ${redactFlagDetail(f.detail)}`);
9522
+ lines.push(` ${f.kind}: ${f.detail}`);
9501
9523
  continue;
9502
9524
  }
9503
9525
  const { label, url } = target;
@@ -9517,23 +9539,24 @@ function formatFlags(flags2) {
9517
9539
  return lines;
9518
9540
  }
9519
9541
  var URL_TOKEN = /[a-z][a-z0-9+.-]*:\/\/\S+/gi;
9520
- var URL_PARTS = /^([a-z][a-z0-9+.-]*:\/\/)([^/?#]*)([^?#]*)(?:\?([^#]*))?(?:#.*)?$/i;
9542
+ var URL_PARTS = /^(?:(?:([a-z][a-z0-9+.-]*:)?\/\/)([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#.*)?$/is;
9543
+ var RECEIVED_PAGE = /^(\S+ received )(.+)( as the page)$/s;
9544
+ var URL_AT_END = /^(.*?(?:\b[A-Z]+ |: ))((?:[a-z][a-z0-9+.-]*:)?\/\/.*|\/.*)$/s;
9521
9545
  function queryName(pair) {
9522
- const raw = pair.split("=")[0];
9523
- try {
9524
- return guardFieldName(decodeURIComponent(raw));
9525
- } catch {
9526
- return guardFieldName(raw);
9527
- }
9546
+ const eq = pair.indexOf("=");
9547
+ return eq < 0 ? OTHER_NAME : guardFieldName(pair.slice(0, eq));
9528
9548
  }
9529
- function redactUrl(token) {
9530
- const parts = URL_PARTS.exec(token);
9531
- if (!parts) return token.split(/[?#]/)[0];
9532
- const [, scheme, authority, path, query] = parts;
9549
+ function redactUrl(raw) {
9550
+ const [, scheme = "", authority, path = "", query] = URL_PARTS.exec(raw);
9551
+ const origin = authority === void 0 ? "" : `${scheme}//${authority.slice(authority.lastIndexOf("@") + 1).replace(/\s/g, "")}`;
9533
9552
  const names = new Set((query ?? "").split("&").filter(Boolean).map(queryName));
9534
- return `${scheme}${authority.slice(authority.lastIndexOf("@") + 1)}${path}${names.size > 0 ? `?${[...names].join("&")}` : ""}`;
9553
+ return `${origin}${maskValuePath(path.replace(/\s/g, "%20"), OTHER_NAME)}${names.size > 0 ? `?${[...names].join("&")}` : ""}`;
9535
9554
  }
9536
9555
  function redactFlagDetail(detail) {
9556
+ const page2 = RECEIVED_PAGE.exec(detail);
9557
+ if (page2) return `${page2[1]}${redactUrl(page2[2])}${page2[3]}`;
9558
+ const tail = URL_AT_END.exec(detail);
9559
+ if (tail) return `${tail[1]}${redactUrl(tail[2])}`;
9537
9560
  return detail.replace(URL_TOKEN, redactUrl);
9538
9561
  }
9539
9562
  function groupTarget(flag2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tagreeve",
3
- "version": "0.5.0-rc.2",
3
+ "version": "0.5.0",
4
4
  "description": "Agent-first testing for website tracking and consent.",
5
5
  "license": "MIT",
6
6
  "repository": {