@geonosis/walk 2.13.0 → 3.0.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 (45) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/bin/geonosis-walk.mjs +1 -1
  3. package/dist/browser.d.ts +124 -0
  4. package/dist/browser.js +242 -0
  5. package/dist/config.d.ts +16 -0
  6. package/dist/config.js +100 -0
  7. package/dist/index.d.ts +7 -153
  8. package/dist/index.js +5 -13
  9. package/dist/options.d.ts +19 -0
  10. package/dist/options.js +64 -0
  11. package/dist/probes/buy-box-above-fold.d.ts +14 -0
  12. package/dist/probes/buy-box-above-fold.js +54 -0
  13. package/dist/probes/empty-section.d.ts +16 -0
  14. package/dist/probes/empty-section.js +29 -0
  15. package/dist/probes/error-page-status.d.ts +20 -0
  16. package/dist/probes/error-page-status.js +37 -0
  17. package/dist/probes/fabricated-claim.d.ts +14 -0
  18. package/dist/probes/fabricated-claim.js +29 -0
  19. package/dist/probes/fake-session.d.ts +14 -0
  20. package/dist/probes/fake-session.js +45 -0
  21. package/dist/probes/index.d.ts +9 -0
  22. package/dist/probes/index.js +42 -0
  23. package/dist/probes/light-on-light.d.ts +15 -0
  24. package/dist/probes/light-on-light.js +26 -0
  25. package/dist/probes/link-integrity.d.ts +14 -0
  26. package/dist/probes/link-integrity.js +69 -0
  27. package/dist/probes/money-format.d.ts +14 -0
  28. package/dist/probes/money-format.js +33 -0
  29. package/dist/probes/ops-leakage.d.ts +13 -0
  30. package/dist/probes/ops-leakage.js +29 -0
  31. package/dist/probes/orphan-url.d.ts +13 -0
  32. package/dist/probes/orphan-url.js +54 -0
  33. package/dist/probes/placeholder-asset.d.ts +14 -0
  34. package/dist/probes/placeholder-asset.js +40 -0
  35. package/dist/probes/stub-only-entity.d.ts +14 -0
  36. package/dist/probes/stub-only-entity.js +30 -0
  37. package/dist/probes/thin-page.d.ts +14 -0
  38. package/dist/probes/thin-page.js +30 -0
  39. package/dist/types.d.ts +104 -0
  40. package/dist/types.js +10 -0
  41. package/dist/walk-cli.js +41 -47
  42. package/dist/walk.d.ts +23 -0
  43. package/dist/walk.js +93 -0
  44. package/package.json +5 -4
  45. package/dist/chunk-VCGYSFL5.js +0 -956
@@ -0,0 +1,54 @@
1
+ // src/probes/orphan-url.ts
2
+ import { collect } from "../browser.js";
3
+ import { stringOption, stringsOption } from "../options.js";
4
+ var MEMO = "orphan-url:linked";
5
+ var linkedIn = (memo) => {
6
+ const seen = memo.get(MEMO);
7
+ if (seen instanceof Set)
8
+ return seen;
9
+ const fresh = new Set;
10
+ memo.set(MEMO, fresh);
11
+ return fresh;
12
+ };
13
+ var bare = (url) => {
14
+ try {
15
+ const parsed = new URL(url);
16
+ return `${parsed.origin}${parsed.pathname.replace(/\/index\.html?$/, "/")}`;
17
+ } catch {
18
+ return url;
19
+ }
20
+ };
21
+ var orphanUrl = {
22
+ class: "content-integrity",
23
+ finish: ({ memo, options, urls }) => {
24
+ if (urls.length < 2)
25
+ return [];
26
+ const linked = linkedIn(memo);
27
+ const entry = stringsOption(options, "entry", []).map(bare);
28
+ return urls.filter((url) => !linked.has(bare(url)) && !entry.includes(bare(url))).map((url) => ({
29
+ class: "content-integrity",
30
+ evidence: `no page in this walk links to ${bare(url)} — it is reachable only by being handed the URL`,
31
+ severity: "major",
32
+ url
33
+ }));
34
+ },
35
+ id: "orphan-url",
36
+ run: async (page, { memo, options, url }) => {
37
+ const linked = linkedIn(memo);
38
+ const here = bare(url);
39
+ for (const hit of await collect(page, {
40
+ kind: "links",
41
+ selector: stringOption("orphan-url", options, "selector", 'a,[role="link"]')
42
+ })) {
43
+ if (hit.resolved === "")
44
+ continue;
45
+ const target = bare(hit.resolved);
46
+ if (target !== here)
47
+ linked.add(target);
48
+ }
49
+ return [];
50
+ }
51
+ };
52
+ export {
53
+ orphanUrl
54
+ };
@@ -0,0 +1,14 @@
1
+ import type { Probe } from '../types.js';
2
+ /**
3
+ * One mark in many slots, and marks whose own name says they are stand-ins.
4
+ *
5
+ * A Medusa storefront shipped ONE green-square SVG for thirteen content-icon keys and one stacked-shippers
6
+ * photo for four of six category tiles. A screenshot showed thirteen shapes; the DOM showed one
7
+ * repeated, which is what `new Set(signatures).size` is for. A signature is the resolved `src` of
8
+ * an image or the geometry of an SVG's own shapes, so two files that draw the same thing under
9
+ * different names still read as different marks, and one file under two names reads as one.
10
+ *
11
+ * `signatures` is the second half: patterns matched against the signature AND the element's
12
+ * alt/aria-label/title, because the audit's own placeholder said "placeholder" in its label.
13
+ */
14
+ export declare const placeholderAsset: Probe;
@@ -0,0 +1,40 @@
1
+ // src/probes/placeholder-asset.ts
2
+ import { collect } from "../browser.js";
3
+ import { assertPatterns, numberOption, patternFlags, stringOption, stringsOption } from "../options.js";
4
+ var placeholderAsset = {
5
+ class: "placeholder-asset",
6
+ id: "placeholder-asset",
7
+ run: async (page, { options, url }) => {
8
+ const maxRepeats = numberOption(options, "maxRepeats", 2);
9
+ const signatures = stringsOption(options, "signatures", []);
10
+ const flags = patternFlags("placeholder-asset", options);
11
+ assertPatterns("placeholder-asset", signatures, flags);
12
+ const hits = await collect(page, {
13
+ assetSelector: stringOption("placeholder-asset", options, "assets", "img,svg"),
14
+ kind: "assets",
15
+ scope: stringOption("placeholder-asset", options, "scope", "body")
16
+ });
17
+ const named = hits.filter((hit) => signatures.some((pattern) => new RegExp(pattern, flags).test(`${hit.signature} ${hit.label}`))).map((hit) => ({
18
+ class: "placeholder-asset",
19
+ evidence: `asset matches a placeholder signature: ${hit.signature.slice(0, 120)}`,
20
+ selector: hit.selector,
21
+ severity: "major",
22
+ url
23
+ }));
24
+ const bySignature = new Map;
25
+ for (const hit of hits) {
26
+ bySignature.set(hit.signature, [...bySignature.get(hit.signature) ?? [], hit.selector]);
27
+ }
28
+ const repeated = [...bySignature.entries()].filter(([, selectors]) => selectors.length > maxRepeats).map(([signature, selectors]) => ({
29
+ class: "placeholder-asset",
30
+ evidence: `the same asset in ${selectors.length} slots, more than the ${maxRepeats} allowed — ${signature.slice(0, 120)}`,
31
+ selector: selectors[0],
32
+ severity: "major",
33
+ url
34
+ }));
35
+ return [...named, ...repeated];
36
+ }
37
+ };
38
+ export {
39
+ placeholderAsset
40
+ };
@@ -0,0 +1,14 @@
1
+ import type { Probe } from '../types.js';
2
+ /**
3
+ * A page that offers to sell something the backend does not have.
4
+ *
5
+ * A Medusa storefront rendered full product pages with an Add to cart for three handles that were
6
+ * in no live store: a buyer could configure `standard-mailer-box` and never place an order for it.
7
+ * The page cannot know this on its own, so the authoritative set is required (D-031) — it comes
8
+ * from the store's own API, the seed, or wherever the repo's truth actually lives.
9
+ *
10
+ * The affordance matters as much as the id: a retired handle that renders an explainer and no way
11
+ * to buy is the FIX (a redirect stub), not the bug, and a probe that could not tell them apart
12
+ * would fire on every correct retirement.
13
+ */
14
+ export declare const stubOnlyEntity: Probe;
@@ -0,0 +1,30 @@
1
+ // src/probes/stub-only-entity.ts
2
+ import { collect } from "../browser.js";
3
+ import { requireStrings, stringOption } from "../options.js";
4
+ var stubOnlyEntity = {
5
+ class: "stub-only-entity",
6
+ id: "stub-only-entity",
7
+ needs: (options) => {
8
+ requireStrings("stub-only-entity", options, "known");
9
+ },
10
+ run: async (page, { options, url }) => {
11
+ const known = new Set(requireStrings("stub-only-entity", options, "known"));
12
+ const attribute = stringOption("stub-only-entity", options, "attribute", "data-entity-id");
13
+ const hits = await collect(page, {
14
+ affordance: stringOption("stub-only-entity", options, "affordance", ""),
15
+ attribute,
16
+ kind: "entities",
17
+ selector: stringOption("stub-only-entity", options, "selector", `[${attribute}]`)
18
+ });
19
+ return hits.filter((hit) => hit.id !== "" && hit.affordance && !known.has(hit.id)).map((hit) => ({
20
+ class: "stub-only-entity",
21
+ evidence: `"${hit.id}" can be bought here and is in no authoritative set of ${known.size} entities`,
22
+ selector: hit.selector,
23
+ severity: "blocking",
24
+ url
25
+ }));
26
+ }
27
+ };
28
+ export {
29
+ stubOnlyEntity
30
+ };
@@ -0,0 +1,14 @@
1
+ import type { Probe } from '../types.js';
2
+ /**
3
+ * A page that renders correctly and says almost nothing.
4
+ *
5
+ * The page is not broken: it has a heading, a layout, a 200. It has three sentences where a reader
6
+ * came for an answer, and every gate in the stack reads it as fine — a screenshot looks like a
7
+ * page, a link check passes, a status check passes. Only counting the words a reader is actually
8
+ * shown says otherwise.
9
+ *
10
+ * `minWords` is REQUIRED (D-031), because how much a page owes a reader is a property of what the
11
+ * page is for — a checkout step owes almost nothing, a guide owes a lot — and a floor the kit
12
+ * picked would be somebody else's idea of thin applied to every repo that never chose one.
13
+ */
14
+ export declare const thinPage: Probe;
@@ -0,0 +1,30 @@
1
+ // src/probes/thin-page.ts
2
+ import { collect } from "../browser.js";
3
+ import { requireNumber, stringOption } from "../options.js";
4
+ var thinPage = {
5
+ class: "content-integrity",
6
+ id: "thin-page",
7
+ needs: (options) => {
8
+ requireNumber("thin-page", options, "minWords");
9
+ },
10
+ run: async (page, { options, url }) => {
11
+ const minWords = requireNumber("thin-page", options, "minWords");
12
+ const scope = stringOption("thin-page", options, "scope", "body");
13
+ const hits = await collect(page, {
14
+ headingSelector: stringOption("thin-page", options, "headingSelector", "h1,h2,h3,h4,h5,h6"),
15
+ kind: "prose",
16
+ mediaSelector: stringOption("thin-page", options, "mediaSelector", "img,svg,video,iframe,canvas"),
17
+ selector: scope
18
+ });
19
+ return hits.filter((hit) => hit.words < minWords).map((hit) => ({
20
+ class: "content-integrity",
21
+ evidence: `${scope} renders ${hit.words} word(s), ${hit.headingWords} of them headings — the floor is ${minWords}`,
22
+ ...hit.selector === "" ? {} : { selector: hit.selector },
23
+ severity: "major",
24
+ url
25
+ }));
26
+ }
27
+ };
28
+ export {
29
+ thinPage
30
+ };
@@ -0,0 +1,104 @@
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
+ */
17
+ 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
+ /** `blocking` breaks trust or the buy path; `major` confuses the buyer; `minor` is polish. */
19
+ 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
+ */
25
+ export type Finding = {
26
+ class: DefectClass;
27
+ evidence: string;
28
+ selector?: string;
29
+ severity: Severity;
30
+ url: string;
31
+ };
32
+ export type Viewport = {
33
+ height: number;
34
+ width: number;
35
+ };
36
+ 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
+ */
41
+ memo: Map<string, unknown>;
42
+ /** This probe's own block of the `options` map, already narrowed by id. */
43
+ 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
+ */
49
+ status: number;
50
+ url: string;
51
+ viewport: Viewport;
52
+ };
53
+ export type Probe = {
54
+ class: DefectClass;
55
+ 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
+ */
64
+ needs?: (options: Record<string, unknown>) => void;
65
+ 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
+ */
72
+ finish?: (context: FinishContext) => Finding[];
73
+ };
74
+ /** What a probe knows once the walk is over: its own memo, its options, and where it went. */
75
+ export type FinishContext = {
76
+ memo: Map<string, unknown>;
77
+ options: Record<string, unknown>;
78
+ urls: string[];
79
+ };
80
+ export type PageReport = {
81
+ findings: Finding[];
82
+ url: string;
83
+ };
84
+ 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
+ */
90
+ counts: Partial<Record<DefectClass, number>>;
91
+ finishedAt: string;
92
+ pages: PageReport[];
93
+ probes: string[];
94
+ startedAt: string;
95
+ viewport: Viewport;
96
+ };
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
+ */
102
+ export declare class WalkError extends Error {
103
+ constructor(message: string);
104
+ }
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ // src/types.ts
2
+ class WalkError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "WalkError";
6
+ }
7
+ }
8
+ export {
9
+ WalkError
10
+ };
package/dist/walk-cli.js CHANGED
@@ -1,40 +1,36 @@
1
- import {
2
- PROBES,
3
- WalkError,
4
- configPath,
5
- configShape,
6
- findingsIn,
7
- loadWalkConfig,
8
- parseViewport,
9
- probeById,
10
- walk
11
- } from "./chunk-VCGYSFL5.js";
12
-
13
1
  // src/walk-cli.ts
14
- import { mkdirSync, writeFileSync } from "fs";
15
- import { dirname, resolve } from "path";
2
+ import { mkdirSync, writeFileSync } from "node:fs";
3
+ import { dirname, resolve } from "node:path";
4
+ import { parseArgs } from "node:util";
5
+ import { configPath, configShape, loadWalkConfig, parseViewport } from "./config.js";
6
+ import { PROBES, probeById } from "./probes/index.js";
7
+ import { WalkError } from "./types.js";
8
+ import { findingsIn, walk } from "./walk.js";
16
9
  var parse = (argv) => {
17
- const out = { probes: [], urls: [] };
18
- for (let at = 0; at < argv.length; at += 1) {
19
- const arg = argv[at];
20
- if (arg === void 0) continue;
21
- const takes = (name) => {
22
- const value = argv[at + 1];
23
- if (value === void 0) throw new WalkError(`${name} needs a value`);
24
- at += 1;
25
- return value;
10
+ try {
11
+ const { positionals, values } = parseArgs({
12
+ allowPositionals: true,
13
+ args: argv,
14
+ options: {
15
+ config: { type: "string" },
16
+ probe: { multiple: true, type: "string" },
17
+ report: { type: "string" },
18
+ viewport: { type: "string" }
19
+ },
20
+ strict: true
21
+ });
22
+ return {
23
+ ...values.config === undefined ? {} : { config: values.config },
24
+ probes: values.probe ?? [],
25
+ ...values.report === undefined ? {} : { report: values.report },
26
+ urls: positionals,
27
+ ...values.viewport === undefined ? {} : { viewport: values.viewport }
26
28
  };
27
- if (arg === "--config") out.config = takes("--config");
28
- else if (arg === "--report") out.report = takes("--report");
29
- else if (arg === "--viewport") out.viewport = takes("--viewport");
30
- else if (arg === "--probe") out.probes.push(takes("--probe"));
31
- else if (arg.startsWith("-"))
32
- throw new WalkError(`unknown option ${arg} \u2014 run geonosis-walk --help`);
33
- else out.urls.push(arg);
29
+ } catch (error) {
30
+ throw new WalkError(`${error instanceof Error ? error.message : String(error)} — run geonosis-walk --help`);
34
31
  }
35
- return out;
36
32
  };
37
- var USAGE = `geonosis-walk [url\u2026] [--config <geonosis.json>] [--probe <id>] [--viewport <WxH>] [--report <path>]
33
+ var USAGE = `geonosis-walk [url…] [--config <geonosis.json>] [--probe <id>] [--viewport <WxH>] [--report <path>]
38
34
 
39
35
  Walks the URLs this repo declares and runs the accessibility, correctness and dead-end probes
40
36
  against each. URLs and probes named on the command line replace the configured ones.
@@ -45,22 +41,23 @@ against each. URLs and probes named on the command line replace the configured o
45
41
  --report <path> where the JSON report is written (default: the config's)
46
42
  --help, -h this text
47
43
 
48
- Exit codes: 0 the walk ran and found nothing \xB7 1 the walk ran and found something \xB7 2 the walk did
49
- not run. The report is written for 0 and 1, and never for 2 \u2014 a tool that reported an empty result
44
+ Exit codes: 0 the walk ran and found nothing · 1 the walk ran and found something · 2 the walk did
45
+ not run. The report is written for 0 and 1, and never for 2 — a tool that reported an empty result
50
46
  for a browser it could not launch would pass hardest exactly when it is broken.`;
51
- var line = (finding) => `${finding.severity} ${finding.class} ${finding.url}${finding.selector === void 0 ? "" : ` ${finding.selector}`}
47
+ var line = (finding) => `${finding.severity} ${finding.class} ${finding.url}${finding.selector === undefined ? "" : ` ${finding.selector}`}
52
48
  ${finding.evidence}`;
53
49
  var denominator = (report) => {
54
50
  const ran = new Set(report.probes);
55
51
  const silent = PROBES.filter((probe) => !ran.has(probe.id)).map((probe) => probe.id);
56
- return `${ran.size} of ${PROBES.length} probe(s) ran${silent.length === 0 ? "" : ` \u2014 never looked for: ${silent.join(", ")}`}`;
52
+ return `${ran.size} of ${PROBES.length} probe(s) ran${silent.length === 0 ? "" : ` — never looked for: ${silent.join(", ")}`}`;
57
53
  };
58
54
  var summarise = (report) => [
59
55
  ...report.pages.flatMap((page) => page.findings.map(line)),
60
56
  "",
61
57
  ...Object.entries(report.counts).map(([name, count]) => `${count} ${name}`),
62
58
  `${report.pages.length} page(s), ${findingsIn(report)} finding(s), ${denominator(report)}`
63
- ].join("\n");
59
+ ].join(`
60
+ `);
64
61
  var main = async () => {
65
62
  const args = process.argv.slice(2);
66
63
  if (args.includes("--help") || args.includes("-h")) {
@@ -88,7 +85,7 @@ var main = async () => {
88
85
  options: config.options,
89
86
  probes,
90
87
  urls: argv.urls.length > 0 ? argv.urls : config.urls,
91
- viewport: argv.viewport === void 0 ? config.viewport : parseViewport(argv.viewport)
88
+ viewport: argv.viewport === undefined ? config.viewport : parseViewport(argv.viewport)
92
89
  });
93
90
  const at = resolve(cwd, argv.report ?? config.report);
94
91
  mkdirSync(dirname(at), { recursive: true });
@@ -99,13 +96,10 @@ ${at}
99
96
  `);
100
97
  return findingsIn(report) > 0 ? 1 : 0;
101
98
  };
102
- main().then(
103
- (code) => {
104
- process.exitCode = code;
105
- },
106
- (error) => {
107
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}
99
+ main().then((code) => {
100
+ process.exitCode = code;
101
+ }, (error) => {
102
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}
108
103
  `);
109
- process.exitCode = 2;
110
- }
111
- );
104
+ process.exitCode = 2;
105
+ });
package/dist/walk.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import type { Browser } from 'playwright';
2
+ import type { Probe, Viewport, WalkReport } from './types.js';
3
+ export type WalkInput = {
4
+ /** An already-open browser, for a walker driving a flow. Absent means launch one and close it. */
5
+ browser?: Browser;
6
+ /** Each probe's options, keyed by probe id. */
7
+ options?: Record<string, Record<string, unknown>>;
8
+ probes: Probe[];
9
+ urls: string[];
10
+ viewport: Viewport;
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>;
23
+ export declare const findingsIn: (report: WalkReport) => number;
package/dist/walk.js ADDED
@@ -0,0 +1,93 @@
1
+ // src/walk.ts
2
+ import { WalkError } from "./types.js";
3
+ var launch = async () => {
4
+ let chromium;
5
+ try {
6
+ ({ chromium } = await import("playwright"));
7
+ } catch (error) {
8
+ throw new WalkError(`playwright is a peer dependency of @geonosis/walk and is not installed: ${error.message}`);
9
+ }
10
+ try {
11
+ return await chromium.launch({ headless: true });
12
+ } catch (error) {
13
+ throw new WalkError(`chromium would not launch — \`npx playwright install chromium\`: ${error.message}`);
14
+ }
15
+ };
16
+ var walk = async ({
17
+ browser,
18
+ options = {},
19
+ probes,
20
+ urls,
21
+ viewport
22
+ }) => {
23
+ if (urls.length === 0)
24
+ throw new WalkError("no URL to walk");
25
+ for (const probe of probes)
26
+ probe.needs?.(options[probe.id] ?? {});
27
+ const startedAt = new Date().toISOString();
28
+ const own = browser ?? await launch();
29
+ const memo = new Map;
30
+ const pages = [];
31
+ try {
32
+ for (const url of urls) {
33
+ const context = await own.newContext({ viewport });
34
+ try {
35
+ const page = await context.newPage();
36
+ const response = await page.goto(url).catch((error) => {
37
+ throw new WalkError(`${url} could not be opened: ${error.message}`);
38
+ });
39
+ 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 = [];
45
+ for (const probe of probes) {
46
+ findings.push(...await probe.run(page, {
47
+ memo,
48
+ options: options[probe.id] ?? {},
49
+ status: response.status(),
50
+ url,
51
+ viewport
52
+ }));
53
+ }
54
+ pages.push({ findings, url });
55
+ } finally {
56
+ await context.close();
57
+ }
58
+ }
59
+ } finally {
60
+ if (browser === undefined)
61
+ await own.close();
62
+ }
63
+ for (const probe of probes) {
64
+ for (const finding of probe.finish?.({ memo, options: options[probe.id] ?? {}, urls }) ?? []) {
65
+ const page = pages.find((one) => one.url === finding.url);
66
+ if (page === undefined)
67
+ pages.push({ findings: [finding], url: finding.url });
68
+ else
69
+ page.findings.push(finding);
70
+ }
71
+ }
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
+ };
88
+ };
89
+ var findingsIn = (report) => report.pages.reduce((total, page) => total + page.findings.length, 0);
90
+ export {
91
+ findingsIn,
92
+ walk
93
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geonosis/walk",
3
- "version": "2.13.0",
3
+ "version": "3.0.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": [
@@ -44,16 +44,17 @@
44
44
  }
45
45
  },
46
46
  "devDependencies": {
47
- "playwright": "1.60.0"
47
+ "playwright": "1.63.0"
48
48
  },
49
49
  "engines": {
50
- "node": ">=22"
50
+ "node": ">=22",
51
+ "bun": "^1.4.2"
51
52
  },
52
53
  "publishConfig": {
53
54
  "access": "public"
54
55
  },
55
56
  "scripts": {
56
- "build": "tsx ../../tooling/build-step.ts tsup",
57
+ "build": "bun ../../tooling/build-step.ts bun ../../tooling/bundle.ts",
57
58
  "typecheck": "tsc --noEmit",
58
59
  "lint": "oxlint --config ../../.oxlintrc.json .",
59
60
  "test:unit": "vitest run --project unit --root ../.. --passWithNoTests \"$PWD\"",