@geonosis/walk 3.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @geonosis/walk
2
2
 
3
+ ## 3.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - fb08b28: `walk.versionKey` and `--version-key <key>` send `Cloudflare-Workers-Version-Key` with every request to the origin of each walked page (#64). During a gradual deployment on Workers each request is otherwise routed to a version by chance, so a walk can read HTML from one version and ask the other for its content-hashed assets. The header goes on the page's own requests through a route scoped to that origin, and on the HEAD and GET requests `link-integrity` makes to it (`ProbeContext.headers`); another origin's requests are left alone, because a custom header sends them through a CORS preflight.
8
+ - fb08b28: A page that answers 400 or worse is walked instead of aborting the run (#61). `walk()` threw for any status of 400 or more before a probe ran, so the run exited 2 with no report, the pages already walked lost their findings, and `error-page-status`'s `honestFrom` could never take effect. Every page that answered is now walked, each probe is handed the status, and the report records it per page (`status`). The status a page must answer is declared in the config, `walk.urls: [{ "url": …, "status": 404 }]`, and a page that answers anything else is a finding: `link-integrity` for a broken link in the walk list (an undeclared 400 or worse, or a declared 200 that answered an error) and `error-page-status` for a soft 404 (a declared error that answered 200). Exit 2 stays for a page that answered nothing or could not be opened; that stops the walk, names the URL, and writes the pages walked so far to `<report>.partial.json` while the report the ratchet reads stays absent. `walk()` takes `expected`, throws `WalkStopped` (a `WalkError` carrying the partial report), and `PageReport` gains `status`.
9
+
10
+ ### Patch Changes
11
+
12
+ - fb08b28: The published manifests no longer declare `engines.bun`, which yarn 1 warned about once per installed package (`The engine "bun" appears to be invalid`). A package that starts its bins on bun now names it in `devEngines.runtime`, the same list the kit's root declares; measured on yarn 1.22.22, npm 11.13.0, pnpm 11.8.0 and 12.10.1 and bun 1.4.2, none of them warns on that field in a dependency. A test over every published manifest holds that `engines` has only keys yarn 1 knows and that the list equals the root's, and a yarn 1 install of those manifests prints no engine line (#46).
13
+ - Updated dependencies [fb08b28]
14
+ - @geonosis/base@3.3.0
15
+
3
16
  ## 3.2.0
4
17
 
5
18
  ### Patch Changes
package/README.md CHANGED
@@ -20,12 +20,30 @@ npx geonosis-walk https://example.test/ https://example.test/products/x --report
20
20
  ```
21
21
  0 the walk ran and found nothing
22
22
  1 the walk ran and found something
23
- 2 the walk did not run — no browser, a URL that did not answer, a probe with no list to look for
23
+ 2 the walk did not run — no browser, a page that could not be opened, a probe with no list to look for
24
24
  ```
25
25
 
26
26
  Two is why there are three. A tool that answered "no findings" for a browser it could not launch
27
27
  would pass hardest exactly when it was broken.
28
28
 
29
+ **A page that answers is walked, whatever its status.** A 404 is a page a customer sees: every probe
30
+ runs on it with the status passed through, so `error-page-status`'s `honestFrom` takes effect (a
31
+ status at or above it is honest and the probe skips the page). What the status ought to be is
32
+ declared per URL, and a page that answers anything else is a finding, not a crash:
33
+
34
+ | the walk list says | the page answers | finding |
35
+ |---|---|---|
36
+ | nothing | 200 | none |
37
+ | nothing | 400 or worse | `link-integrity`, blocking: a broken link in the walk list |
38
+ | `{ "url": …, "status": 404 }` | 404 | none: the healthy answer of a deliberate not-found page |
39
+ | `{ "url": …, "status": 404 }` | 200 | `error-page-status`, blocking: a soft 404, which every health check reads as healthy |
40
+ | `{ "url": …, "status": 200 }` | 404 | `link-integrity`, blocking |
41
+
42
+ Exit 2 stays for a page that answered nothing or could not be opened. It stops the walk, and the
43
+ pages walked before it are not thrown away: they are written beside the report as
44
+ `<report>.partial.json` (`stoppedAt` names the URL), and the report itself, the one a ratchet
45
+ counter reads, is left absent.
46
+
29
47
  ## The thirteen probes
30
48
 
31
49
  | id | What it reads | Needs |
@@ -62,7 +80,12 @@ Everything lives in the `walk` block of `geonosis.json`; the command line wins w
62
80
  ```json
63
81
  {
64
82
  "walk": {
65
- "urls": ["http://localhost:3000/", "http://localhost:3000/products/kraft-mailer-box"],
83
+ "urls": [
84
+ "http://localhost:3000/",
85
+ "http://localhost:3000/products/kraft-mailer-box",
86
+ { "url": "http://localhost:3000/does-not-exist/", "status": 404 }
87
+ ],
88
+ "versionKey": "release-check",
66
89
  "viewport": { "width": 1440, "height": 900 },
67
90
  "report": ".geonosis/walk-report.json",
68
91
  "probes": ["light-on-light", "placeholder-asset", "link-integrity", "fabricated-claim"],
@@ -76,9 +99,16 @@ Everything lives in the `walk` block of `geonosis.json`; the command line wins w
76
99
  ```
77
100
 
78
101
  ```
79
- geonosis-walk [url…] [--report <path>] [--config <path>] [--viewport WIDTHxHEIGHT] [--probe <id>]…
102
+ geonosis-walk [url…] [--report <path>] [--config <path>] [--viewport WIDTHxHEIGHT] [--probe <id>]… [--version-key <key>]
80
103
  ```
81
104
 
105
+ `versionKey` (or `--version-key`) sends `Cloudflare-Workers-Version-Key: <key>` with every request
106
+ to the origin of each walked page, including the HEAD requests `link-integrity` makes, and to no
107
+ other origin. During a gradual deployment on Workers, Cloudflare routes each request to a version by
108
+ chance unless the key pins the client, so a walk without one can read HTML from one version and its
109
+ assets from the other
110
+ ([Version affinity](https://developers.cloudflare.com/workers/versions-and-deployments/gradual-deployments/version-affinity/)).
111
+
82
112
  With no `probes` the walk runs the three that need no list. A mobile pass is the same command with
83
113
  `--viewport 390x844`.
84
114
 
@@ -90,7 +120,7 @@ With no `probes` the walk runs the three that need no list. A mobile pass is the
90
120
  "viewport": { "width": 390, "height": 844 },
91
121
  "probes": ["buy-box-above-fold"],
92
122
  "counts": { "buy-box-above-fold": 1 },
93
- "pages": [{ "url": "…", "findings": [
123
+ "pages": [{ "url": "…", "status": 200, "findings": [
94
124
  { "class": "buy-box-above-fold", "severity": "major", "url": "…",
95
125
  "selector": "[data-testid=\"buy-box\"]",
96
126
  "evidence": "the buy box starts at 900px, below the fold at 844px" }
package/dist/config.d.ts CHANGED
@@ -1,14 +1,17 @@
1
1
  import type { Viewport } from './types.js';
2
2
  export type WalkConfig = {
3
+ expected: Record<string, number>;
3
4
  options: Record<string, Record<string, unknown>>;
4
5
  probes: string[];
5
6
  report: string;
6
7
  urls: string[];
8
+ versionKey?: string;
7
9
  viewport: Viewport;
8
10
  };
9
11
  export declare const WALK_REPORT = ".geonosis/walk-report.json";
10
12
  export declare const WALK_DEFAULT: WalkConfig;
11
13
  export declare const configShape: () => string;
12
14
  export declare const parseViewport: (value: string) => Viewport;
15
+ export declare const partialReportPath: (report: string) => string;
13
16
  export declare const loadWalkConfig: (file: string) => WalkConfig;
14
17
  export declare const configPath: (cwd: string, given?: string) => string;
package/dist/config.js CHANGED
@@ -7,6 +7,7 @@ import { WalkError } from "./types.js";
7
7
  var VIEWPORT = { height: 900, width: 1440 };
8
8
  var WALK_REPORT = ".geonosis/walk-report.json";
9
9
  var WALK_DEFAULT = {
10
+ expected: {},
10
11
  options: {},
11
12
  probes: DEFAULT_PROBES.map((one) => one.id),
12
13
  report: WALK_REPORT,
@@ -17,7 +18,8 @@ var ABOUT = {
17
18
  options: "object? keyed by probe id; each probe validates its own",
18
19
  probes: "string[]? the probe ids to run",
19
20
  report: "string? where the JSON report is written",
20
- urls: "string[]? the pages to walk",
21
+ urls: "(string | { url, status? })[]? the pages to walk, and the status a page must answer",
22
+ versionKey: "string? sent as Cloudflare-Workers-Version-Key on every request to a walked origin",
21
23
  viewport: 'object? { "width": <number>, "height": <number> }'
22
24
  };
23
25
  var KNOWN = new Set(Object.keys(ABOUT));
@@ -67,6 +69,41 @@ var readStrings = (value, name, fallback) => {
67
69
  }
68
70
  return value;
69
71
  };
72
+ var URL_ENTRY = 'expected a URL, or { "url": <string>, "status"?: <100-599> }';
73
+ var readUrls = (value) => {
74
+ if (value === undefined)
75
+ return { expected: {}, urls: [] };
76
+ if (!Array.isArray(value))
77
+ throw new WalkError(`walk.urls must be a list — ${URL_ENTRY}`);
78
+ const expected = {};
79
+ const urls = [];
80
+ for (const [index, entry] of value.entries()) {
81
+ const at = `walk.urls[${index}]`;
82
+ if (typeof entry === "string") {
83
+ urls.push(entry);
84
+ continue;
85
+ }
86
+ if (!isRecord(entry))
87
+ throw new WalkError(`${at} must be a string or an object — ${URL_ENTRY}`);
88
+ const unknown = Object.keys(entry).find((key) => key !== "status" && key !== "url");
89
+ if (unknown !== undefined)
90
+ throw new WalkError(`${at}.${unknown} is not a key it takes — ${URL_ENTRY}`);
91
+ const url = entry.url;
92
+ if (typeof url !== "string" || url === "") {
93
+ throw new WalkError(`${at}.url must be the page to walk — ${URL_ENTRY}`);
94
+ }
95
+ const status = entry.status;
96
+ if (status !== undefined) {
97
+ if (typeof status !== "number" || !Number.isInteger(status) || status < 100 || status > 599) {
98
+ throw new WalkError(`${at}.status must be an HTTP status, 100 to 599 — ${URL_ENTRY}`);
99
+ }
100
+ expected[url] = status;
101
+ }
102
+ urls.push(url);
103
+ }
104
+ return { expected, urls };
105
+ };
106
+ var partialReportPath = (report) => report.endsWith(".json") ? `${report.slice(0, -".json".length)}.partial.json` : `${report}.partial`;
70
107
  var loadWalkConfig = (file) => {
71
108
  if (!existsSync(file))
72
109
  return WALK_DEFAULT;
@@ -87,11 +124,17 @@ var loadWalkConfig = (file) => {
87
124
  if (!KNOWN.has(key))
88
125
  throw new WalkError(`walk.${key} is not a key of the walk block`);
89
126
  }
127
+ const { expected, urls } = readUrls(block.urls);
128
+ if (block.versionKey !== undefined && (typeof block.versionKey !== "string" || block.versionKey === "")) {
129
+ throw new WalkError("walk.versionKey must be the value to send as Cloudflare-Workers-Version-Key");
130
+ }
90
131
  return {
132
+ expected,
91
133
  options: readOptions(block.options),
92
134
  probes: readStrings(block.probes, "probes", WALK_DEFAULT.probes),
93
135
  report: typeof block.report === "string" ? block.report : WALK_REPORT,
94
- urls: readStrings(block.urls, "urls", []),
136
+ urls,
137
+ ...block.versionKey === undefined ? {} : { versionKey: block.versionKey },
95
138
  viewport: readViewport(block.viewport)
96
139
  };
97
140
  };
@@ -102,5 +145,6 @@ export {
102
145
  configPath,
103
146
  configShape,
104
147
  loadWalkConfig,
105
- parseViewport
148
+ parseViewport,
149
+ partialReportPath
106
150
  };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type { WalkConfig } from './config.js';
2
- export { configPath, loadWalkConfig, parseViewport, WALK_DEFAULT, WALK_REPORT } from './config.js';
2
+ export { configPath, loadWalkConfig, parseViewport, partialReportPath, WALK_DEFAULT, WALK_REPORT } from './config.js';
3
3
  export { DEFAULT_PROBES, PROBES, probeById } from './probes/index.js';
4
4
  export type { DefectClass, Finding, PageReport, Probe, ProbeContext, Severity, Viewport, WalkReport } from './types.js';
5
- export { WalkError } from './types.js';
5
+ export { WalkError, WalkStopped } from './types.js';
6
6
  export type { WalkInput } from './walk.js';
7
7
  export { findingsIn, walk } from './walk.js';
package/dist/index.js CHANGED
@@ -1,7 +1,14 @@
1
1
  // src/index.ts
2
- import { configPath, loadWalkConfig, parseViewport, WALK_DEFAULT, WALK_REPORT } from "./config.js";
2
+ import {
3
+ configPath,
4
+ loadWalkConfig,
5
+ parseViewport,
6
+ partialReportPath,
7
+ WALK_DEFAULT,
8
+ WALK_REPORT
9
+ } from "./config.js";
3
10
  import { DEFAULT_PROBES, PROBES, probeById } from "./probes/index.js";
4
- import { WalkError } from "./types.js";
11
+ import { WalkError, WalkStopped } from "./types.js";
5
12
  import { findingsIn, walk } from "./walk.js";
6
13
  export {
7
14
  DEFAULT_PROBES,
@@ -9,10 +16,12 @@ export {
9
16
  WALK_DEFAULT,
10
17
  WALK_REPORT,
11
18
  WalkError,
19
+ WalkStopped,
12
20
  configPath,
13
21
  findingsIn,
14
22
  loadWalkConfig,
15
23
  parseViewport,
24
+ partialReportPath,
16
25
  probeById,
17
26
  walk
18
27
  };
@@ -7,7 +7,7 @@ var DEAD = ["", "#"];
7
7
  var linkIntegrity = defineProbe({
8
8
  class: "link-integrity",
9
9
  id: "link-integrity",
10
- run: async (page, { memo, options, url }) => {
10
+ run: async (page, { headers, memo, options, url }) => {
11
11
  const dead = stringsOption(options, "deadHrefs", DEAD);
12
12
  const ignore = stringsOption(options, "ignore", []);
13
13
  assertPatterns("link-integrity", ignore, "");
@@ -36,7 +36,7 @@ var linkIntegrity = defineProbe({
36
36
  continue;
37
37
  if (!checkExternal && new URL(target).origin !== origin)
38
38
  continue;
39
- const status = await statusOf(page, memo, target);
39
+ const status = await statusOf(page, memo, target, new URL(target).origin === origin ? headers : undefined);
40
40
  if (status < 400)
41
41
  continue;
42
42
  found.push({
@@ -54,15 +54,16 @@ var unreachable = (memo, target) => {
54
54
  return typeof why === "string" ? `${target} could not be reached: ${why}` : undefined;
55
55
  };
56
56
  var statusKey = (target) => `link-integrity:${target}`;
57
- var statusOf = async (page, memo, target) => {
57
+ var statusOf = async (page, memo, target, headers) => {
58
58
  const key = statusKey(target);
59
59
  const seen = memo.get(key);
60
60
  if (typeof seen === "number")
61
61
  return seen;
62
62
  let status;
63
63
  try {
64
- const head = await page.request.head(target, { failOnStatusCode: false });
65
- status = head.status() === 405 || head.status() === 501 ? (await page.request.get(target, { failOnStatusCode: false })).status() : head.status();
64
+ const options = { failOnStatusCode: false, ...headers === undefined ? {} : { headers } };
65
+ const head = await page.request.head(target, options);
66
+ status = head.status() === 405 || head.status() === 501 ? (await page.request.get(target, options)).status() : head.status();
66
67
  } catch (error) {
67
68
  status = 599;
68
69
  memo.set(`${key}:why`, errorMessage(error));
package/dist/types.d.ts CHANGED
@@ -16,6 +16,7 @@ export type Viewport = {
16
16
  width: number;
17
17
  };
18
18
  export type ProbeContext = {
19
+ headers?: Record<string, string>;
19
20
  /** One memo per walk: `link-integrity` would otherwise HEAD the same footer link once per page. */
20
21
  memo: Map<string, unknown>;
21
22
  options: Record<string, unknown>;
@@ -40,6 +41,7 @@ export type FinishContext = {
40
41
  };
41
42
  export type PageReport = {
42
43
  findings: Finding[];
44
+ status: number;
43
45
  url: string;
44
46
  };
45
47
  export type WalkReport = {
@@ -49,9 +51,17 @@ export type WalkReport = {
49
51
  pages: PageReport[];
50
52
  probes: string[];
51
53
  startedAt: string;
54
+ stoppedAt?: {
55
+ url: string;
56
+ why: string;
57
+ };
52
58
  viewport: Viewport;
53
59
  };
54
60
  /** The walk could not run (exit 2), as distinct from a run that found nothing. */
55
61
  export declare class WalkError extends Error {
56
62
  constructor(message: string);
57
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
@@ -3,9 +3,9 @@ import { mkdirSync, writeFileSync } from "node:fs";
3
3
  import { dirname, resolve } from "node:path";
4
4
  import { parseArgs } from "node:util";
5
5
  import { errorMessage } from "@geonosis/base";
6
- import { configPath, configShape, loadWalkConfig, parseViewport } from "./config.js";
6
+ import { configPath, configShape, loadWalkConfig, parseViewport, partialReportPath } from "./config.js";
7
7
  import { PROBES, probeById } from "./probes/index.js";
8
- import { WalkError } from "./types.js";
8
+ import { WalkError, WalkStopped } from "./types.js";
9
9
  import { findingsIn, walk } from "./walk.js";
10
10
  var parse = (argv) => {
11
11
  try {
@@ -16,6 +16,7 @@ var parse = (argv) => {
16
16
  config: { type: "string" },
17
17
  probe: { multiple: true, type: "string" },
18
18
  report: { type: "string" },
19
+ "version-key": { type: "string" },
19
20
  viewport: { type: "string" }
20
21
  },
21
22
  strict: true
@@ -25,13 +26,14 @@ var parse = (argv) => {
25
26
  probes: values.probe ?? [],
26
27
  ...values.report === undefined ? {} : { report: values.report },
27
28
  urls: positionals,
29
+ ...values["version-key"] === undefined ? {} : { versionKey: values["version-key"] },
28
30
  ...values.viewport === undefined ? {} : { viewport: values.viewport }
29
31
  };
30
32
  } catch (error) {
31
33
  throw new WalkError(`${errorMessage(error)} — run geonosis-walk --help`);
32
34
  }
33
35
  };
34
- 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>]
35
37
 
36
38
  Walks the URLs this repo declares and runs the accessibility, correctness and dead-end probes
37
39
  against each. URLs and probes named on the command line replace the configured ones.
@@ -40,11 +42,17 @@ against each. URLs and probes named on the command line replace the configured o
40
42
  --probe <id> run this probe (repeatable); default: the probes the config names
41
43
  --viewport <WxH> the viewport to render at, e.g. 1280x800
42
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
43
46
  --help, -h this text
44
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
+
45
51
  Exit codes: 0 the walk ran and found nothing · 1 the walk ran and found something · 2 the walk did
46
52
  not run. The report is written for 0 and 1, and never for 2 — a tool that reported an empty result
47
- 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.`;
48
56
  var line = (finding) => `${finding.severity} ${finding.class} ${finding.url}${finding.selector === undefined ? "" : ` ${finding.selector}`}
49
57
  ${finding.evidence}`;
50
58
  var denominator = (report) => {
@@ -82,13 +90,27 @@ var main = async () => {
82
90
  throw new WalkError(errorMessage(error));
83
91
  }
84
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");
85
97
  const report = await walk({
98
+ expected: config.expected,
86
99
  options: config.options,
87
100
  probes,
88
101
  urls: argv.urls.length > 0 ? argv.urls : config.urls,
102
+ ...versionKey === undefined ? {} : { versionKey },
89
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;
90
113
  });
91
- const at = resolve(cwd, argv.report ?? config.report);
92
114
  mkdirSync(dirname(at), { recursive: true });
93
115
  writeFileSync(at, `${JSON.stringify(report, null, 2)}
94
116
  `);
package/dist/walk.d.ts CHANGED
@@ -2,11 +2,14 @@ import type { Browser } from 'playwright';
2
2
  import type { Probe, Viewport, WalkReport } from './types.js';
3
3
  export type WalkInput = {
4
4
  browser?: Browser;
5
+ expected?: Record<string, number>;
5
6
  options?: Record<string, Record<string, unknown>>;
6
7
  probes: Probe[];
7
8
  urls: string[];
9
+ versionKey?: string;
8
10
  viewport: Viewport;
9
11
  };
10
- /** Each page gets its own context with no cookies or storage, which is what gives `fake-session` meaning. Refusals come before the browser opens and an unanswered page stops the walk. */
11
- 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>;
12
15
  export declare const findingsIn: (report: WalkReport) => number;
package/dist/walk.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/walk.ts
2
2
  import { errorMessage } from "@geonosis/base";
3
- import { WalkError } from "./types.js";
3
+ import { WalkError, WalkStopped } from "./types.js";
4
4
  var launch = async () => {
5
5
  let chromium;
6
6
  try {
@@ -14,11 +14,72 @@ var launch = async () => {
14
14
  throw new WalkError(`chromium would not launch — \`npx playwright install chromium\`: ${errorMessage(error)}`);
15
15
  }
16
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
+ };
17
76
  var walk = async ({
18
77
  browser,
78
+ expected = {},
19
79
  options = {},
20
80
  probes,
21
81
  urls,
82
+ versionKey,
22
83
  viewport
23
84
  }) => {
24
85
  if (urls.length === 0)
@@ -29,30 +90,35 @@ var walk = async ({
29
90
  const own = browser ?? await launch();
30
91
  const memo = new Map;
31
92
  const pages = [];
93
+ const stoppedAt = (url, why) => new WalkStopped(`${url} ${why}`, reportOf({ pages, probes, startedAt, stoppedAt: { url, why }, viewport }));
32
94
  try {
33
95
  for (const url of urls) {
34
96
  const context = await own.newContext({ viewport });
35
97
  try {
36
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
+ }
37
104
  const response = await page.goto(url).catch((error) => {
38
- throw new WalkError(`${url} could not be opened: ${error.message}`);
105
+ throw stoppedAt(url, `could not be opened: ${errorMessage(error)}`);
39
106
  });
40
107
  if (response === null)
41
- throw new WalkError(`${url} answered nothing`);
42
- if (response.status() >= 400) {
43
- throw new WalkError(`${url} answered ${response.status()}`);
44
- }
45
- const findings = [];
108
+ throw stoppedAt(url, "answered nothing");
109
+ const status = response.status();
110
+ const findings = statusFindings(url, status, expected[url]);
46
111
  for (const probe of probes) {
47
112
  findings.push(...await probe.run(page, {
113
+ ...headers === undefined ? {} : { headers },
48
114
  memo,
49
115
  options: options[probe.id] ?? {},
50
- status: response.status(),
116
+ status,
51
117
  url,
52
118
  viewport
53
119
  }));
54
120
  }
55
- pages.push({ findings, url });
121
+ pages.push({ findings, status, url });
56
122
  } finally {
57
123
  await context.close();
58
124
  }
@@ -65,30 +131,16 @@ var walk = async ({
65
131
  for (const finding of probe.finish?.({ memo, options: options[probe.id] ?? {}, urls }) ?? []) {
66
132
  const page = pages.find((one) => one.url === finding.url);
67
133
  if (page === undefined)
68
- pages.push({ findings: [finding], url: finding.url });
134
+ pages.push({ findings: [finding], status: 0, url: finding.url });
69
135
  else
70
136
  page.findings.push(finding);
71
137
  }
72
138
  }
73
- const counts = {};
74
- for (const probe of probes)
75
- counts[probe.class] = 0;
76
- for (const page of pages) {
77
- for (const finding of page.findings) {
78
- counts[finding.class] = (counts[finding.class] ?? 0) + 1;
79
- }
80
- }
81
- return {
82
- counts,
83
- finishedAt: new Date().toISOString(),
84
- pages,
85
- probes: probes.map((one) => one.id),
86
- startedAt,
87
- viewport
88
- };
139
+ return reportOf({ pages, probes, startedAt, viewport });
89
140
  };
90
141
  var findingsIn = (report) => report.pages.reduce((total, page) => total + page.findings.length, 0);
91
142
  export {
143
+ VERSION_KEY,
92
144
  findingsIn,
93
145
  walk
94
146
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geonosis/walk",
3
- "version": "3.2.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": [
@@ -36,7 +36,7 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@geonosis/base": "3.2.0"
39
+ "@geonosis/base": "3.3.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "playwright": ">=1.40.0"
@@ -50,8 +50,20 @@
50
50
  "playwright": "1.64.0"
51
51
  },
52
52
  "engines": {
53
- "node": ">=22",
54
- "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
+ ]
55
67
  },
56
68
  "publishConfig": {
57
69
  "access": "public"