@geonosis/walk 3.1.0 → 3.3.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 (46) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +41 -10
  3. package/dist/browser.d.ts +2 -18
  4. package/dist/config.d.ts +3 -2
  5. package/dist/config.js +65 -15
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +11 -2
  8. package/dist/options.d.ts +2 -11
  9. package/dist/options.js +4 -1
  10. package/dist/probes/buy-box-above-fold.d.ts +1 -14
  11. package/dist/probes/buy-box-above-fold.js +3 -5
  12. package/dist/probes/define.d.ts +7 -0
  13. package/dist/probes/define.js +12 -0
  14. package/dist/probes/empty-section.d.ts +1 -16
  15. package/dist/probes/empty-section.js +3 -3
  16. package/dist/probes/error-page-status.d.ts +1 -20
  17. package/dist/probes/error-page-status.js +8 -31
  18. package/dist/probes/fabricated-claim.d.ts +1 -14
  19. package/dist/probes/fabricated-claim.js +6 -23
  20. package/dist/probes/fake-session.d.ts +1 -14
  21. package/dist/probes/fake-session.js +3 -4
  22. package/dist/probes/index.d.ts +1 -5
  23. package/dist/probes/light-on-light.d.ts +1 -15
  24. package/dist/probes/light-on-light.js +3 -3
  25. package/dist/probes/link-integrity.d.ts +2 -14
  26. package/dist/probes/link-integrity.js +19 -12
  27. package/dist/probes/money-format.d.ts +1 -14
  28. package/dist/probes/money-format.js +3 -3
  29. package/dist/probes/ops-leakage.d.ts +1 -13
  30. package/dist/probes/ops-leakage.js +6 -23
  31. package/dist/probes/orphan-url.d.ts +1 -13
  32. package/dist/probes/orphan-url.js +3 -3
  33. package/dist/probes/placeholder-asset.d.ts +1 -14
  34. package/dist/probes/placeholder-asset.js +3 -4
  35. package/dist/probes/stub-only-entity.d.ts +1 -14
  36. package/dist/probes/stub-only-entity.js +3 -3
  37. package/dist/probes/text-probe.d.ts +12 -0
  38. package/dist/probes/text-probe.js +37 -0
  39. package/dist/probes/thin-page.d.ts +1 -14
  40. package/dist/probes/thin-page.js +3 -3
  41. package/dist/types.d.ts +18 -55
  42. package/dist/types.js +11 -1
  43. package/dist/walk-cli.js +31 -8
  44. package/dist/walk.d.ts +5 -13
  45. package/dist/walk.js +81 -28
  46. package/package.json +19 -4
package/dist/types.d.ts CHANGED
@@ -1,27 +1,9 @@
1
1
  import type { Page } from 'playwright';
2
- /**
3
- * The ten defect classes the walk is mechanical about.
4
- *
5
- * Six are a storefront CX audit's own groups, generalised; `light-on-light` is that audit's
6
- * browser-proof probe (a cream chip on a cream page reads as broken, and the screenshot says it is
7
- * fine), `buy-box-above-fold` is one of its groups promoted to a class, and `error-page-status`
8
- * came from an error surface served with a 200, which every health check read as healthy.
9
- * `content-integrity` is the tenth: a page that renders correctly and says nothing — a section with
10
- * a heading and no body, a price in a shape the repo does not write, a page nothing links to. Four
11
- * of an audit's own defects were filed under `fabricated-claim`'s forbidden-string engine for want
12
- * of it, which is a class borrowing another class's mechanism. What the ten do NOT cover — a number that disagrees with a number on another page, copy
13
- * that promises a control nobody built, four levels of taxonomy for fourteen products — is in
14
- * `docs/walk-review-inventory-2026-08-30.md`, and stays the walker's judgement. A green walk report
15
- * is not a clean surface.
16
- */
2
+ /** A green walk is not a clean surface: what these classes do not cover is in docs/walk-review-inventory-2026-08-30.md. */
17
3
  export type DefectClass = 'buy-box-above-fold' | 'content-integrity' | 'error-page-status' | 'fabricated-claim' | 'fake-session' | 'light-on-light' | 'link-integrity' | 'ops-leakage' | 'placeholder-asset' | 'stub-only-entity';
18
4
  /** `blocking` breaks trust or the buy path; `major` confuses the buyer; `minor` is polish. */
19
5
  export type Severity = 'blocking' | 'major' | 'minor';
20
- /**
21
- * One defect, as the build plan's contract states it. `evidence` is the measured value — the two
22
- * colours and the ratio, the status code, the matched text — never a restatement of the class,
23
- * because the reader's next question is always "what did you actually see".
24
- */
6
+ /** `evidence` is the measured value (colours and ratio, status code, matched text), never a restatement of the class. */
25
7
  export type Finding = {
26
8
  class: DefectClass;
27
9
  evidence: string;
@@ -34,18 +16,11 @@ export type Viewport = {
34
16
  width: number;
35
17
  };
36
18
  export type ProbeContext = {
37
- /**
38
- * One walk, one memo. `link-integrity` would otherwise send a HEAD request for the same footer
39
- * link once per page, which is forty requests for one answer on a forty-page walk.
40
- */
19
+ headers?: Record<string, string>;
20
+ /** One memo per walk: `link-integrity` would otherwise HEAD the same footer link once per page. */
41
21
  memo: Map<string, unknown>;
42
- /** This probe's own block of the `options` map, already narrowed by id. */
43
22
  options: Record<string, unknown>;
44
- /**
45
- * The status the page's OWN response carried. Read from `page.goto`, because nothing on a loaded
46
- * page remembers it and a second request for it would ask a different question of a server that
47
- * may not answer twice the same way.
48
- */
23
+ /** From `page.goto`'s own response; nothing on a loaded page remembers it. */
49
24
  status: number;
50
25
  url: string;
51
26
  viewport: Viewport;
@@ -53,25 +28,12 @@ export type ProbeContext = {
53
28
  export type Probe = {
54
29
  class: DefectClass;
55
30
  id: string;
56
- /**
57
- * D-031, per probe: a probe that cannot mean anything without an option refuses the run when it
58
- * is missing, naming the option. Five of the eight have one — a claim list, an authoritative id
59
- * set, what "signed in" looks like, the operations patterns, the buy-box selector — because none
60
- * of those five can have a default that is true of a repo that has not configured it. A probe
61
- * that ran and reported nothing because nobody told it what to look for is indistinguishable
62
- * from a clean page.
63
- */
31
+ /** D-031: refuses the run when a required option is missing; a probe with nothing to look for is indistinguishable from a clean page. */
64
32
  needs?: (options: Record<string, unknown>) => void;
65
33
  run: (page: Page, context: ProbeContext) => Promise<Finding[]>;
66
- /**
67
- * The reading no single page can make. `orphan-url` is the reason it exists: whether anything
68
- * links to a page is a fact about the whole walk, and a probe handed one page at a time can only
69
- * record what it saw. Called once, after every page, with the pages walked; each finding is filed
70
- * against the page whose `url` it names.
71
- */
34
+ /** The reading no single page can make, called once after every page; each finding is filed against the page whose `url` it names. */
72
35
  finish?: (context: FinishContext) => Finding[];
73
36
  };
74
- /** What a probe knows once the walk is over: its own memo, its options, and where it went. */
75
37
  export type FinishContext = {
76
38
  memo: Map<string, unknown>;
77
39
  options: Record<string, unknown>;
@@ -79,26 +41,27 @@ export type FinishContext = {
79
41
  };
80
42
  export type PageReport = {
81
43
  findings: Finding[];
44
+ status: number;
82
45
  url: string;
83
46
  };
84
47
  export type WalkReport = {
85
- /**
86
- * Keyed by the classes that RAN. A zero therefore means "probed for, none found"; a class that is
87
- * absent was never looked for. All eight keys with five zeros would read as five clean gates
88
- * nobody enabled.
89
- */
48
+ /** Keyed by the classes that ran: a zero means probed for, none found; an absent class was never looked for. */
90
49
  counts: Partial<Record<DefectClass, number>>;
91
50
  finishedAt: string;
92
51
  pages: PageReport[];
93
52
  probes: string[];
94
53
  startedAt: string;
54
+ stoppedAt?: {
55
+ url: string;
56
+ why: string;
57
+ };
95
58
  viewport: Viewport;
96
59
  };
97
- /**
98
- * The walk could not run: no browser, no URL, a page that did not answer, a probe with no option it
99
- * needs. Distinct from "the walk ran and found nothing", which is a report with zeros in it — the
100
- * CLI turns this into exit 2 and that into exit 0.
101
- */
60
+ /** The walk could not run (exit 2), as distinct from a run that found nothing. */
102
61
  export declare class WalkError extends Error {
103
62
  constructor(message: string);
104
63
  }
64
+ export declare class WalkStopped extends WalkError {
65
+ readonly report: WalkReport;
66
+ constructor(message: string, report: WalkReport);
67
+ }
package/dist/types.js CHANGED
@@ -5,6 +5,16 @@ class WalkError extends Error {
5
5
  this.name = "WalkError";
6
6
  }
7
7
  }
8
+
9
+ class WalkStopped extends WalkError {
10
+ report;
11
+ constructor(message, report) {
12
+ super(message);
13
+ this.name = "WalkStopped";
14
+ this.report = report;
15
+ }
16
+ }
8
17
  export {
9
- WalkError
18
+ WalkError,
19
+ WalkStopped
10
20
  };
package/dist/walk-cli.js CHANGED
@@ -2,9 +2,10 @@
2
2
  import { mkdirSync, writeFileSync } from "node:fs";
3
3
  import { dirname, resolve } from "node:path";
4
4
  import { parseArgs } from "node:util";
5
- import { configPath, configShape, loadWalkConfig, parseViewport } from "./config.js";
5
+ import { errorMessage } from "@geonosis/base";
6
+ import { configPath, configShape, loadWalkConfig, parseViewport, partialReportPath } from "./config.js";
6
7
  import { PROBES, probeById } from "./probes/index.js";
7
- import { WalkError } from "./types.js";
8
+ import { WalkError, WalkStopped } from "./types.js";
8
9
  import { findingsIn, walk } from "./walk.js";
9
10
  var parse = (argv) => {
10
11
  try {
@@ -15,6 +16,7 @@ var parse = (argv) => {
15
16
  config: { type: "string" },
16
17
  probe: { multiple: true, type: "string" },
17
18
  report: { type: "string" },
19
+ "version-key": { type: "string" },
18
20
  viewport: { type: "string" }
19
21
  },
20
22
  strict: true
@@ -24,13 +26,14 @@ var parse = (argv) => {
24
26
  probes: values.probe ?? [],
25
27
  ...values.report === undefined ? {} : { report: values.report },
26
28
  urls: positionals,
29
+ ...values["version-key"] === undefined ? {} : { versionKey: values["version-key"] },
27
30
  ...values.viewport === undefined ? {} : { viewport: values.viewport }
28
31
  };
29
32
  } catch (error) {
30
- throw new WalkError(`${error instanceof Error ? error.message : String(error)} — run geonosis-walk --help`);
33
+ throw new WalkError(`${errorMessage(error)} — run geonosis-walk --help`);
31
34
  }
32
35
  };
33
- var USAGE = `geonosis-walk [url…] [--config <geonosis.json>] [--probe <id>] [--viewport <WxH>] [--report <path>]
36
+ var USAGE = `geonosis-walk [url…] [--config <geonosis.json>] [--probe <id>] [--viewport <WxH>] [--report <path>] [--version-key <key>]
34
37
 
35
38
  Walks the URLs this repo declares and runs the accessibility, correctness and dead-end probes
36
39
  against each. URLs and probes named on the command line replace the configured ones.
@@ -39,11 +42,17 @@ against each. URLs and probes named on the command line replace the configured o
39
42
  --probe <id> run this probe (repeatable); default: the probes the config names
40
43
  --viewport <WxH> the viewport to render at, e.g. 1280x800
41
44
  --report <path> where the JSON report is written (default: the config's)
45
+ --version-key <key> send Cloudflare-Workers-Version-Key: <key> with every request to a walked origin, so a walk during a gradual deployment sees one version
42
46
  --help, -h this text
43
47
 
48
+ A page that answers is walked whatever its status. An error status the config does not declare
49
+ (walk.urls: { "url", "status" }) is a finding, and so is a declared one the page does not answer.
50
+
44
51
  Exit codes: 0 the walk ran and found nothing · 1 the walk ran and found something · 2 the walk did
45
52
  not run. The report is written for 0 and 1, and never for 2 — a tool that reported an empty result
46
- for a browser it could not launch would pass hardest exactly when it is broken.`;
53
+ for a browser it could not launch would pass hardest exactly when it is broken. A walk that stops at
54
+ a page it could not open writes the pages before it beside the report as <report>.partial.json,
55
+ naming the URL; the gate's report stays absent.`;
47
56
  var line = (finding) => `${finding.severity} ${finding.class} ${finding.url}${finding.selector === undefined ? "" : ` ${finding.selector}`}
48
57
  ${finding.evidence}`;
49
58
  var denominator = (report) => {
@@ -78,16 +87,30 @@ var main = async () => {
78
87
  try {
79
88
  return probeById(id);
80
89
  } catch (error) {
81
- throw new WalkError(error.message);
90
+ throw new WalkError(errorMessage(error));
82
91
  }
83
92
  });
93
+ const at = resolve(cwd, argv.report ?? config.report);
94
+ const versionKey = argv.versionKey ?? config.versionKey;
95
+ if (versionKey === "")
96
+ throw new WalkError("--version-key needs the value to send");
84
97
  const report = await walk({
98
+ expected: config.expected,
85
99
  options: config.options,
86
100
  probes,
87
101
  urls: argv.urls.length > 0 ? argv.urls : config.urls,
102
+ ...versionKey === undefined ? {} : { versionKey },
88
103
  viewport: argv.viewport === undefined ? config.viewport : parseViewport(argv.viewport)
104
+ }).catch((error) => {
105
+ if (error instanceof WalkStopped) {
106
+ const partial = partialReportPath(at);
107
+ mkdirSync(dirname(partial), { recursive: true });
108
+ writeFileSync(partial, `${JSON.stringify(error.report, null, 2)}
109
+ `);
110
+ throw new WalkError(`${error.message} — the pages before it are in ${partial}`);
111
+ }
112
+ throw error;
89
113
  });
90
- const at = resolve(cwd, argv.report ?? config.report);
91
114
  mkdirSync(dirname(at), { recursive: true });
92
115
  writeFileSync(at, `${JSON.stringify(report, null, 2)}
93
116
  `);
@@ -99,7 +122,7 @@ ${at}
99
122
  main().then((code) => {
100
123
  process.exitCode = code;
101
124
  }, (error) => {
102
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}
125
+ process.stderr.write(`${errorMessage(error)}
103
126
  `);
104
127
  process.exitCode = 2;
105
128
  });
package/dist/walk.d.ts CHANGED
@@ -1,23 +1,15 @@
1
1
  import type { Browser } from 'playwright';
2
2
  import type { Probe, Viewport, WalkReport } from './types.js';
3
3
  export type WalkInput = {
4
- /** An already-open browser, for a walker driving a flow. Absent means launch one and close it. */
5
4
  browser?: Browser;
6
- /** Each probe's options, keyed by probe id. */
5
+ expected?: Record<string, number>;
7
6
  options?: Record<string, Record<string, unknown>>;
8
7
  probes: Probe[];
9
8
  urls: string[];
9
+ versionKey?: string;
10
10
  viewport: Viewport;
11
11
  };
12
- /**
13
- * Every URL, every probe, one report.
14
- *
15
- * Each page gets its OWN context, with no cookies and no storage. That is what makes `fake-session`
16
- * mean anything, and it is why `walk` is the stateless surface: a walker that has to reach a
17
- * checkout with a cart in it drives its own page and calls `probe.run(page, context)` directly.
18
- *
19
- * Refusals come BEFORE the browser opens, and a page that did not answer stops the walk. A report
20
- * with no findings in it must only ever mean the probes looked and found none.
21
- */
22
- export declare const walk: ({ browser, options, probes, urls, viewport }: WalkInput) => Promise<WalkReport>;
12
+ export declare const VERSION_KEY = "Cloudflare-Workers-Version-Key";
13
+ /** Each page gets its own context with no cookies or storage, which is what gives `fake-session` meaning. Refusals come before the browser opens, a page that answers is walked whatever its status, and a page that answers nothing stops the walk. */
14
+ export declare const walk: ({ browser, expected, options, probes, urls, versionKey, viewport }: WalkInput) => Promise<WalkReport>;
23
15
  export declare const findingsIn: (report: WalkReport) => number;
package/dist/walk.js CHANGED
@@ -1,23 +1,85 @@
1
1
  // src/walk.ts
2
- import { WalkError } from "./types.js";
2
+ import { errorMessage } from "@geonosis/base";
3
+ import { WalkError, WalkStopped } from "./types.js";
3
4
  var launch = async () => {
4
5
  let chromium;
5
6
  try {
6
7
  ({ chromium } = await import("playwright"));
7
8
  } catch (error) {
8
- throw new WalkError(`playwright is a peer dependency of @geonosis/walk and is not installed: ${error.message}`);
9
+ throw new WalkError(`playwright is a peer dependency of @geonosis/walk and is not installed: ${errorMessage(error)}`);
9
10
  }
10
11
  try {
11
12
  return await chromium.launch({ headless: true });
12
13
  } catch (error) {
13
- throw new WalkError(`chromium would not launch — \`npx playwright install chromium\`: ${error.message}`);
14
+ throw new WalkError(`chromium would not launch — \`npx playwright install chromium\`: ${errorMessage(error)}`);
14
15
  }
15
16
  };
17
+ var VERSION_KEY = "Cloudflare-Workers-Version-Key";
18
+ var originOf = (url) => {
19
+ try {
20
+ return new URL(url).origin;
21
+ } catch {
22
+ return;
23
+ }
24
+ };
25
+ var statusFindings = (url, status, declared) => {
26
+ if (declared === undefined) {
27
+ return status < 400 ? [] : [
28
+ {
29
+ class: "link-integrity",
30
+ evidence: `answered ${status}, and the walk list declares no status for it`,
31
+ severity: "blocking",
32
+ url
33
+ }
34
+ ];
35
+ }
36
+ if (status === declared)
37
+ return [];
38
+ if (status < 400 && declared >= 400) {
39
+ return [
40
+ {
41
+ class: "error-page-status",
42
+ evidence: `declared ${declared}, answered ${status} — a soft ${declared}: every health check reads it as healthy`,
43
+ severity: "blocking",
44
+ url
45
+ }
46
+ ];
47
+ }
48
+ return [
49
+ {
50
+ class: "link-integrity",
51
+ evidence: `declared ${declared}, answered ${status}`,
52
+ severity: "blocking",
53
+ url
54
+ }
55
+ ];
56
+ };
57
+ var reportOf = (input) => {
58
+ const counts = {};
59
+ for (const probe of input.probes)
60
+ counts[probe.class] = 0;
61
+ for (const page of input.pages) {
62
+ for (const finding of page.findings) {
63
+ counts[finding.class] = (counts[finding.class] ?? 0) + 1;
64
+ }
65
+ }
66
+ return {
67
+ counts,
68
+ finishedAt: new Date().toISOString(),
69
+ pages: input.pages,
70
+ probes: input.probes.map((one) => one.id),
71
+ startedAt: input.startedAt,
72
+ ...input.stoppedAt === undefined ? {} : { stoppedAt: input.stoppedAt },
73
+ viewport: input.viewport
74
+ };
75
+ };
16
76
  var walk = async ({
17
77
  browser,
78
+ expected = {},
18
79
  options = {},
19
80
  probes,
20
81
  urls,
82
+ versionKey,
21
83
  viewport
22
84
  }) => {
23
85
  if (urls.length === 0)
@@ -28,30 +90,35 @@ var walk = async ({
28
90
  const own = browser ?? await launch();
29
91
  const memo = new Map;
30
92
  const pages = [];
93
+ const stoppedAt = (url, why) => new WalkStopped(`${url} ${why}`, reportOf({ pages, probes, startedAt, stoppedAt: { url, why }, viewport }));
31
94
  try {
32
95
  for (const url of urls) {
33
96
  const context = await own.newContext({ viewport });
34
97
  try {
35
98
  const page = await context.newPage();
99
+ const headers = versionKey === undefined ? undefined : { [VERSION_KEY]: versionKey };
100
+ const origin = originOf(url);
101
+ if (headers !== undefined && origin !== undefined) {
102
+ await page.route((target) => target.origin === origin, (route) => route.continue({ headers: { ...route.request().headers(), ...headers } }));
103
+ }
36
104
  const response = await page.goto(url).catch((error) => {
37
- throw new WalkError(`${url} could not be opened: ${error.message}`);
105
+ throw stoppedAt(url, `could not be opened: ${errorMessage(error)}`);
38
106
  });
39
107
  if (response === null)
40
- throw new WalkError(`${url} answered nothing`);
41
- if (response.status() >= 400) {
42
- throw new WalkError(`${url} answered ${response.status()}`);
43
- }
44
- const findings = [];
108
+ throw stoppedAt(url, "answered nothing");
109
+ const status = response.status();
110
+ const findings = statusFindings(url, status, expected[url]);
45
111
  for (const probe of probes) {
46
112
  findings.push(...await probe.run(page, {
113
+ ...headers === undefined ? {} : { headers },
47
114
  memo,
48
115
  options: options[probe.id] ?? {},
49
- status: response.status(),
116
+ status,
50
117
  url,
51
118
  viewport
52
119
  }));
53
120
  }
54
- pages.push({ findings, url });
121
+ pages.push({ findings, status, url });
55
122
  } finally {
56
123
  await context.close();
57
124
  }
@@ -64,30 +131,16 @@ var walk = async ({
64
131
  for (const finding of probe.finish?.({ memo, options: options[probe.id] ?? {}, urls }) ?? []) {
65
132
  const page = pages.find((one) => one.url === finding.url);
66
133
  if (page === undefined)
67
- pages.push({ findings: [finding], url: finding.url });
134
+ pages.push({ findings: [finding], status: 0, url: finding.url });
68
135
  else
69
136
  page.findings.push(finding);
70
137
  }
71
138
  }
72
- const counts = {};
73
- for (const probe of probes)
74
- counts[probe.class] = 0;
75
- for (const page of pages) {
76
- for (const finding of page.findings) {
77
- counts[finding.class] = (counts[finding.class] ?? 0) + 1;
78
- }
79
- }
80
- return {
81
- counts,
82
- finishedAt: new Date().toISOString(),
83
- pages,
84
- probes: probes.map((one) => one.id),
85
- startedAt,
86
- viewport
87
- };
139
+ return reportOf({ pages, probes, startedAt, viewport });
88
140
  };
89
141
  var findingsIn = (report) => report.pages.reduce((total, page) => total + page.findings.length, 0);
90
142
  export {
143
+ VERSION_KEY,
91
144
  findingsIn,
92
145
  walk
93
146
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geonosis/walk",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "types": "./dist/index.d.ts",
5
5
  "description": "The customer walk as a gate: eight computed-DOM probes over a list of URLs, one JSON report, and an exit code that tells a could-not-run from a clean page.",
6
6
  "keywords": [
@@ -35,6 +35,9 @@
35
35
  "bin",
36
36
  "dist"
37
37
  ],
38
+ "dependencies": {
39
+ "@geonosis/base": "3.3.0"
40
+ },
38
41
  "peerDependencies": {
39
42
  "playwright": ">=1.40.0"
40
43
  },
@@ -44,11 +47,23 @@
44
47
  }
45
48
  },
46
49
  "devDependencies": {
47
- "playwright": "1.63.0"
50
+ "playwright": "1.64.0"
48
51
  },
49
52
  "engines": {
50
- "node": ">=22",
51
- "bun": "^1.4.2"
53
+ "node": ">=22"
54
+ },
55
+ "devEngines": {
56
+ "runtime": [
57
+ {
58
+ "name": "bun",
59
+ "version": "^1.4.2",
60
+ "onFail": "download"
61
+ },
62
+ {
63
+ "name": "node",
64
+ "onFail": "ignore"
65
+ }
66
+ ]
52
67
  },
53
68
  "publishConfig": {
54
69
  "access": "public"