@geonosis/walk 3.8.3 → 3.9.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,19 @@
1
1
  # @geonosis/walk
2
2
 
3
+ ## 3.9.0
4
+
5
+ ### Patch Changes
6
+
7
+ - cac1a0c: `link-integrity` no longer requests a link to a place in the page it is on (#231). A skip link (`href="#main"`) on a page the walk list declares as a 404 was requested, answered the page's own 404, and was reported blocking. Such a link is now judged in the page: it passes when the page has an element with that id, or an `<a name>` of it, matched as written and percent-decoded, as the browser finds it. This widens the probe: a fragment that names no element on its page (`#delivery` with no `id="delivery"`) is a `major` finding, where it used to pass on the page's 200. `#top`, an empty fragment, a text fragment (`#:~:text=`) and a route after the hash (`#/cart`, `#!/cart`) are left alone. A link to another page's fragment is requested as before.
8
+ - 351ce36: A walk checks everything it needs before it opens a browser and names every missing piece in one refusal: each probe's option or peer, `playwright`, and Playwright's Chromium, read from `chromium.executablePath()` (#272). A pattern with an inline flag such as `(?i)` is refused saying that a pattern is a JavaScript `RegExp` source; the README names the `flags` option of the probes that take one.
9
+ - @geonosis/base@3.9.0
10
+
11
+ ## 3.8.4
12
+
13
+ ### Patch Changes
14
+
15
+ - @geonosis/base@3.8.4
16
+
3
17
  ## 3.8.3
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -50,7 +50,7 @@ counter reads, is left absent.
50
50
  |---|---|---|
51
51
  | `light-on-light` | An element with an opaque background of its own, no background image, no border, no shadow, no outline, whose box does not simply repaint the one behind it — and whose WCAG contrast against the painted ancestor background is under the floor. | nothing (`minContrast` defaults to 1.05) |
52
52
  | `placeholder-asset` | Asset signatures: an image's resolved `src`, an SVG's own shape geometry. Fires on a signature used in more slots than allowed, and on any signature or `alt`/`aria-label`/`title` matching the placeholder list. | nothing (`maxRepeats` defaults to 2) |
53
- | `link-integrity` | `href` absent, empty, `#` or `javascript:` — and, for same-origin links, a HEAD (GET on 405/501) that answers 400 or worse. | nothing |
53
+ | `link-integrity` | `href` absent, empty, `#` or `javascript:` — and, for same-origin links, a HEAD (GET on 405/501) that answers 400 or worse. A link to a place in the page it is on (`#main`) is not requested: it is judged by whether the page has an element with that id (or an `<a name>`), as the browser finds it; `#top`, an empty fragment and a route after the hash (`#/cart`, `#!/cart`) are left alone. | nothing |
54
54
  | `fabricated-claim` | The page's rendered text, against a list of claim patterns. Not the markup: a claim in a comment is a claim nobody was shown. | **`claims`** |
55
55
  | `stub-only-entity` | An element naming an entity, offering a way to buy it, whose id is in no authoritative set. | **`known`** |
56
56
  | `fake-session` | Anything that means "signed in", on a page loaded with no cookies and no storage. | **`selectors` or `text`** |
@@ -77,6 +77,15 @@ would report a clean page for every repo that never set one up.
77
77
  peer missing, the walk exits 2 naming the install command, `npm i -D @axe-core/playwright`, and does
78
78
  not skip the probe in silence. A walk that names no probes does not run it.
79
79
 
80
+ Everything a walk needs is checked before it opens a browser, and every missing piece is named in
81
+ one refusal: each probe's option or peer, `playwright`, and Playwright's Chromium, whose path is
82
+ read from `chromium.executablePath()` rather than found by a launch that fails.
83
+
84
+ A pattern is a JavaScript `RegExp` source. It takes no inline flag: `(?i)trusted by` is refused as
85
+ not a regular expression. `fabricated-claim`, `ops-leakage`, `error-page-status`, `money-format`
86
+ and `placeholder-asset` take their flags in a `flags` option, any of `i`, `m`, `s` and `u`
87
+ (`{ "claims": ["trusted by"], "flags": "i" }`).
88
+
80
89
  Four of the others are the `content-integrity` class: a page that renders correctly and says nothing.
81
90
  Four defects of one audit were filed under `fabricated-claim`'s forbidden-string engine for want of
82
91
  it, which is one class borrowing another's mechanism.
package/dist/browser.d.ts CHANGED
@@ -18,8 +18,13 @@ export type AssetHit = {
18
18
  selector: string;
19
19
  signature: string;
20
20
  };
21
+ export type InPageTarget = {
22
+ found: boolean;
23
+ name: string;
24
+ };
21
25
  export type LinkHit = {
22
26
  href: null | string;
27
+ inPage: InPageTarget | null;
23
28
  resolved: string;
24
29
  selector: string;
25
30
  text: string;
package/dist/browser.js CHANGED
@@ -1,6 +1,13 @@
1
1
  // src/browser.ts
2
2
  var inPage = (job) => {
3
3
  const dom = {
4
+ decoded: (text) => {
5
+ try {
6
+ return decodeURIComponent(text);
7
+ } catch {
8
+ return text;
9
+ }
10
+ },
4
11
  deepest: (root, needle) => {
5
12
  let node = root;
6
13
  let moved = true;
@@ -150,8 +157,28 @@ var inPage = (job) => {
150
157
  return hits;
151
158
  }
152
159
  if (job.kind === "links") {
160
+ const here = new URL(location.href);
161
+ here.hash = "";
162
+ const indicates = (name) => document.getElementById(name) !== null || [...document.getElementsByName(name)].some((one) => one.tagName === "A");
163
+ const targetIn = (resolved) => {
164
+ if (!URL.canParse(resolved))
165
+ return null;
166
+ const target = new URL(resolved);
167
+ if (target.hash === "")
168
+ return null;
169
+ const [name = ""] = target.hash.slice(1).split(":~:");
170
+ target.hash = "";
171
+ if (target.href !== here.href || name.startsWith("/") || name.startsWith("!"))
172
+ return null;
173
+ const readable = dom.decoded(name);
174
+ return {
175
+ found: name === "" || indicates(name) || indicates(readable) || readable.toLowerCase() === "top",
176
+ name
177
+ };
178
+ };
153
179
  return [...document.querySelectorAll(job.selector)].map((element) => ({
154
180
  href: element.getAttribute("href"),
181
+ inPage: targetIn(element.href ?? ""),
155
182
  resolved: element.href ?? "",
156
183
  selector: dom.selectorOf(element),
157
184
  text: dom.textOf(element).trim().slice(0, 80)
package/dist/options.js CHANGED
@@ -51,7 +51,7 @@ var assertPatterns = (probe, patterns, flags) => {
51
51
  try {
52
52
  RegExp(pattern, `${flags}g`);
53
53
  } catch {
54
- throw new WalkError(`${probe}: "${pattern}" is not a regular expression`);
54
+ throw new WalkError(`${probe}: "${pattern}" is not a regular expression — a pattern is a JavaScript RegExp source, with no inline flags such as (?i)`);
55
55
  }
56
56
  }
57
57
  };
@@ -34,6 +34,17 @@ var linkIntegrity = defineProbe({
34
34
  continue;
35
35
  if (ignore.some((pattern) => new RegExp(pattern).test(target)))
36
36
  continue;
37
+ if (hit.inPage !== null) {
38
+ if (!hit.inPage.found) {
39
+ found.push({
40
+ evidence: `#${hit.inPage.name} names no element on the page: the link goes nowhere`,
41
+ selector: hit.selector,
42
+ severity: "major",
43
+ url
44
+ });
45
+ }
46
+ continue;
47
+ }
37
48
  if (!checkExternal && new URL(target).origin !== origin)
38
49
  continue;
39
50
  const status = await statusOf(page, memo, target, new URL(target).origin === origin ? headers : undefined);
package/dist/walk.d.ts CHANGED
@@ -15,6 +15,13 @@ export type WalkInput = {
15
15
  /** Imported here, not at module top: a consumer without a browser gets a sentence naming what to install, and the ratchet importing this package's types must not drag one in. */
16
16
  export declare const launchBrowser: (gpu?: boolean) => Promise<Browser>;
17
17
  export declare const VERSION_KEY = "Cloudflare-Workers-Version-Key";
18
+ type ChromiumLocator = {
19
+ chromium: {
20
+ executablePath: () => string;
21
+ };
22
+ };
23
+ export declare const unmetBeforeLaunch: (probes: readonly Probe[], options: Record<string, Record<string, unknown>>, locate?: () => Promise<ChromiumLocator>) => Promise<string[]>;
18
24
  /** 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. */
19
25
  export declare const walk: ({ browser, expected, gpu, options, probes, ready, readyTimeoutMs, urls, versionKey, viewport }: WalkInput) => Promise<WalkReport>;
20
26
  export declare const findingsIn: (report: WalkReport) => number;
27
+ export {};
package/dist/walk.js CHANGED
@@ -1,9 +1,11 @@
1
1
  // src/walk.ts
2
+ import { existsSync } from "node:fs";
2
3
  import { errorMessage } from "@geonosis/base";
3
4
  import { classesOf, WalkError, WalkStopped } from "./types.js";
4
5
  import { readWebgl } from "./webgl.js";
5
6
  var READY_TIMEOUT_MS = 1e4;
6
7
  var NO_GPU_ARGS = ["--disable-gpu", "--use-angle=swiftshader"];
8
+ var INSTALL_CHROMIUM = "npx playwright install chromium";
7
9
  var launchBrowser = async (gpu = true) => {
8
10
  let chromium;
9
11
  try {
@@ -18,7 +20,7 @@ var launchBrowser = async (gpu = true) => {
18
20
  ...gpu ? {} : { args: NO_GPU_ARGS }
19
21
  });
20
22
  } catch (error) {
21
- throw new WalkError(`chromium would not launch — \`npx playwright install chromium\`: ${errorMessage(error)}`);
23
+ throw new WalkError(`chromium would not launch — \`${INSTALL_CHROMIUM}\`: ${errorMessage(error)}`);
22
24
  }
23
25
  };
24
26
  var VERSION_KEY = "Cloudflare-Workers-Version-Key";
@@ -63,6 +65,33 @@ var statusFindings = (url, status, declared) => {
63
65
  };
64
66
  var firstLine = (error) => errorMessage(error).split(`
65
67
  `)[0] ?? "";
68
+ var loadPlaywright = () => import("playwright");
69
+ var unmetBeforeLaunch = async (probes, options, locate) => {
70
+ const unmet = [];
71
+ for (const probe of probes) {
72
+ try {
73
+ await probe.needs?.(options[probe.id] ?? {});
74
+ } catch (error) {
75
+ if (!(error instanceof WalkError))
76
+ throw error;
77
+ unmet.push(error.message);
78
+ }
79
+ }
80
+ if (locate === undefined)
81
+ return unmet;
82
+ let located;
83
+ try {
84
+ located = await locate();
85
+ } catch (error) {
86
+ return [
87
+ ...unmet,
88
+ `playwright is a peer dependency of @geonosis/walk and is not installed — npm i -D playwright: ${firstLine(error)}`,
89
+ `chromium, once playwright is installed — ${INSTALL_CHROMIUM}`
90
+ ];
91
+ }
92
+ const path = located.chromium.executablePath();
93
+ return existsSync(path) ? unmet : [...unmet, `chromium is not installed at ${path} — ${INSTALL_CHROMIUM}`];
94
+ };
66
95
  var settle = async (page, ready, timeout) => {
67
96
  if (ready.scrollTo !== undefined) {
68
97
  try {
@@ -117,8 +146,12 @@ var walk = async ({
117
146
  }) => {
118
147
  if (urls.length === 0)
119
148
  throw new WalkError("no URL to walk");
120
- for (const probe of probes)
121
- await probe.needs?.(options[probe.id] ?? {});
149
+ const unmet = await unmetBeforeLaunch(probes, options, browser === undefined ? loadPlaywright : undefined);
150
+ if (unmet.length > 0) {
151
+ throw new WalkError(`the walk cannot start until each of these is fixed:
152
+ ${unmet.map((line) => ` - ${line}`).join(`
153
+ `)}`);
154
+ }
122
155
  const startedAt = new Date().toISOString();
123
156
  const own = browser ?? await launchBrowser(gpu);
124
157
  const memo = new Map;
@@ -183,5 +216,6 @@ export {
183
216
  VERSION_KEY,
184
217
  findingsIn,
185
218
  launchBrowser,
219
+ unmetBeforeLaunch,
186
220
  walk
187
221
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geonosis/walk",
3
- "version": "3.8.3",
3
+ "version": "3.9.0",
4
4
  "types": "./dist/index.d.ts",
5
5
  "description": "The customer walk as a gate: fifteen probes over a list of URLs, fourteen computed-DOM readings and axe’s accessibility rules, 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.8.3"
39
+ "@geonosis/base": "3.9.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@axe-core/playwright": "^4.14.0",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "scripts": {
77
77
  "build": "bun ../../tooling/build-step.ts bun ../../tooling/bundle.ts",
78
- "typecheck": "tsc --noEmit",
78
+ "typecheck": "bun check --no-script",
79
79
  "lint": "oxlint --report-unused-disable-directives-severity=error --config ../../.oxlintrc.json .",
80
80
  "test:unit": "vitest run --project unit --root ../.. --passWithNoTests \"$PWD\"",
81
81
  "test:bin": "vitest run --project bin --root ../.. --passWithNoTests \"$PWD\"",