@geonosis/walk 2.12.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 +8 -0
  2. package/bin/geonosis-walk.mjs +7 -192
  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
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.12.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\"",