@se-studio/site-check 2.19.1 → 2.20.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 (66) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +7 -0
  3. package/dist/smoke-test/cms-page-checks.d.ts.map +1 -1
  4. package/dist/smoke-test/cms-page-checks.js +1 -0
  5. package/dist/smoke-test/cms-page-checks.js.map +1 -1
  6. package/dist/smoke-test/config.d.ts.map +1 -1
  7. package/dist/smoke-test/config.js +106 -0
  8. package/dist/smoke-test/config.js.map +1 -1
  9. package/dist/smoke-test/content-assert.d.ts +14 -1
  10. package/dist/smoke-test/content-assert.d.ts.map +1 -1
  11. package/dist/smoke-test/content-assert.js +29 -5
  12. package/dist/smoke-test/content-assert.js.map +1 -1
  13. package/dist/smoke-test/dead-links.d.ts +58 -0
  14. package/dist/smoke-test/dead-links.d.ts.map +1 -0
  15. package/dist/smoke-test/dead-links.js +180 -0
  16. package/dist/smoke-test/dead-links.js.map +1 -0
  17. package/dist/smoke-test/environment.d.ts +19 -0
  18. package/dist/smoke-test/environment.d.ts.map +1 -0
  19. package/dist/smoke-test/environment.js +55 -0
  20. package/dist/smoke-test/environment.js.map +1 -0
  21. package/dist/smoke-test/index.d.ts +7 -2
  22. package/dist/smoke-test/index.d.ts.map +1 -1
  23. package/dist/smoke-test/index.js +4 -1
  24. package/dist/smoke-test/index.js.map +1 -1
  25. package/dist/smoke-test/runner.d.ts.map +1 -1
  26. package/dist/smoke-test/runner.js +90 -18
  27. package/dist/smoke-test/runner.js.map +1 -1
  28. package/dist/smoke-test/smoke-coverage/classify.d.ts +10 -0
  29. package/dist/smoke-test/smoke-coverage/classify.d.ts.map +1 -0
  30. package/dist/smoke-test/smoke-coverage/classify.js +90 -0
  31. package/dist/smoke-test/smoke-coverage/classify.js.map +1 -0
  32. package/dist/smoke-test/smoke-coverage/evaluate.d.ts +29 -0
  33. package/dist/smoke-test/smoke-coverage/evaluate.d.ts.map +1 -0
  34. package/dist/smoke-test/smoke-coverage/evaluate.js +270 -0
  35. package/dist/smoke-test/smoke-coverage/evaluate.js.map +1 -0
  36. package/dist/smoke-test/smoke-coverage/index.d.ts +8 -0
  37. package/dist/smoke-test/smoke-coverage/index.d.ts.map +1 -0
  38. package/dist/smoke-test/smoke-coverage/index.js +7 -0
  39. package/dist/smoke-test/smoke-coverage/index.js.map +1 -0
  40. package/dist/smoke-test/smoke-coverage/model.d.ts +20 -0
  41. package/dist/smoke-test/smoke-coverage/model.d.ts.map +1 -0
  42. package/dist/smoke-test/smoke-coverage/model.js +114 -0
  43. package/dist/smoke-test/smoke-coverage/model.js.map +1 -0
  44. package/dist/smoke-test/smoke-coverage/run.d.ts +19 -0
  45. package/dist/smoke-test/smoke-coverage/run.d.ts.map +1 -0
  46. package/dist/smoke-test/smoke-coverage/run.js +123 -0
  47. package/dist/smoke-test/smoke-coverage/run.js.map +1 -0
  48. package/dist/smoke-test/smoke-coverage/sitemap.d.ts +34 -0
  49. package/dist/smoke-test/smoke-coverage/sitemap.d.ts.map +1 -0
  50. package/dist/smoke-test/smoke-coverage/sitemap.js +148 -0
  51. package/dist/smoke-test/smoke-coverage/sitemap.js.map +1 -0
  52. package/dist/smoke-test/smoke-coverage/types.d.ts +74 -0
  53. package/dist/smoke-test/smoke-coverage/types.d.ts.map +1 -0
  54. package/dist/smoke-test/smoke-coverage/types.js +13 -0
  55. package/dist/smoke-test/smoke-coverage/types.js.map +1 -0
  56. package/dist/smoke-test/static.d.ts.map +1 -1
  57. package/dist/smoke-test/static.js +69 -6
  58. package/dist/smoke-test/static.js.map +1 -1
  59. package/dist/smoke-test/types.d.ts +23 -6
  60. package/dist/smoke-test/types.d.ts.map +1 -1
  61. package/dist/smoke-test/types.js.map +1 -1
  62. package/docs/llms.md +1 -0
  63. package/docs/smoke-assertions.md +72 -0
  64. package/docs/smoke-coverage.md +92 -0
  65. package/package.json +4 -2
  66. package/smoke-coverage-dry-run.mjs +61 -0
@@ -0,0 +1,72 @@
1
+ # Smoke assertions: 404 content, environments, dead links, bypass
2
+
3
+ Four opt-in additions to `smoke.cases.json` and the smoke runners. A file that uses none of them behaves exactly as before.
4
+
5
+ ## 1. Vercel protection bypass
6
+
7
+ `smoke-test-live`, `smoke-test-preview` and `runPreviewStaticSmokeTest` / `runLiveSmokeTest` already send `x-vercel-protection-bypass` (token from `VERCEL_PROTECTION_BYPASS_TOKEN`, aliases `VERCEL_AUTOMATION_BYPASS_SECRET` and `VERCEL_BYPASS_TOKEN`). New:
8
+
9
+ - `runStaticSmokeTest(file, { baseUrl, protectionBypass: true })` sends the header on every request to a remote `baseUrl`. It is opt-in because `baseUrl` can be any host; with no token set it throws rather than running unprotected.
10
+ - A customer runner that does its own fetching (for example a locale smoke script) can reuse the exported helpers from `@se-studio/site-check/smoke-test`:
11
+
12
+ ```ts
13
+ import { createProtectedFetch, requireProtectionBypass } from '@se-studio/site-check/smoke-test';
14
+
15
+ const fetchFn = createProtectedFetch(requireProtectionBypass(), fetch); // use fetchFn instead of fetch
16
+ ```
17
+
18
+ The header is sent to every URL the wrapped fetch requests, including `imagesMustLoad` image URLs and redirect targets the platform follows for you. Do not wrap a fetch that also requests third-party hosts. The dead-link check follows redirects itself (up to 5 hops) and stops at the first hop that leaves the link's origin, so the header never goes to another host. Links are filtered against the origin of the configured page URL, and relative links resolve against the page's final URL only when a redirect stayed on that origin.
19
+
20
+ `site-check <baseUrl> --vercel-bypass` (the audit CLI) already supports the header. `smoke-test-one` and `revalidation-matrix-test` run against a local server and need none. The production SEO audit targets the public production site.
21
+
22
+ ## 2. Content assertions on an expected 404
23
+
24
+ `contentAssert` is skipped on non-2xx responses. Set `allowNon2xx` on a block, together with the case's `expectHtmlStatus`, to run it when the response status equals `expectHtmlStatus`:
25
+
26
+ ```json
27
+ {
28
+ "category": "not-found",
29
+ "label": "404 page",
30
+ "path": "/definitely-missing/",
31
+ "expectMarkdown": false,
32
+ "expectHtmlStatus": 404,
33
+ "contentAssert": { "allowNon2xx": true, "mustInclude": ["href=\"/\""] }
34
+ }
35
+ ```
36
+
37
+ If the status is not the expected one the case fails with `html_non_2xx` and the assertions are not run. CMS chrome checks stay 2xx-only.
38
+
39
+ ## 3. Environment-aware assertions
40
+
41
+ A `contentAssert` block may carry `environments` (`local`, `preview`, `production`). `contentAssert` may also be an array of blocks, so shared and environment-specific checks sit side by side:
42
+
43
+ ```json
44
+ "contentAssert": [
45
+ { "mustInclude": ["<h1"] },
46
+ { "environments": ["production"], "mustInclude": ["meta-externalagent"] }
47
+ ]
48
+ ```
49
+
50
+ An invalid `SMOKE_TEST_ENVIRONMENT` fails the run only when a case uses `environments`. A scoped block runs only when the run's environment is listed. When the environment is unknown the block is skipped (the report notes the skip), so a production-only pin can never fail a preview.
51
+
52
+ The environment is, in order: `environment` option on the load/run functions, `SMOKE_TEST_ENVIRONMENT` (`local|preview|production`, anything else throws), then inferred: a localhost URL is `local`; a host equal to `PRODUCTION_SITE_URL` is `production`; `runPreviewStaticSmokeTest` / `runLiveSmokeTest` fall back to `preview`; otherwise unknown. A preview or deployment URL is never read as production. To run the production pins from CI against the live site, set `SMOKE_TEST_ENVIRONMENT=production` (or `PRODUCTION_SITE_URL`). An explicit `production` is trusted: if you set it job-wide and the same job also smokes a preview, the production pins run against the preview and fail. Set it only on the step that targets production. As a guard, a `production` environment combined with a `*.vercel.app` base URL adds a warning to the run (not an error). `environments` must be a non-empty array.
53
+
54
+ ## 4. Dead internal links (`deadLinks`)
55
+
56
+ Opt-in top-level block. For each smoke page that returns 2xx (not `not-found`, `probe` or `discovery` cases), same-origin `<a href>` links are collected. Unique targets are requested with HEAD (GET if HEAD is not conclusive; a HEAD 404/410 is final), under caps. A target that is also a smoke case reuses that case's status.
57
+
58
+ ```json
59
+ "deadLinks": { "mode": "warn", "maxLinksPerPage": 50, "maxTotal": 200, "concurrency": 4, "timeoutMs": 10000, "ignorePrefixes": ["/_next/"] }
60
+ ```
61
+
62
+ | Key | Default | Meaning |
63
+ |---|---|---|
64
+ | `enabled` | `true` when the block is present | `false` switches the check off without removing the block |
65
+ | `mode` | `warn` | `warn` only lists dead links in Warnings (default, for a staged rollout); `error` fails each source page with `dead_internal_link`. Adopt with `warn`, then switch a repo to `error` once its warnings are clean |
66
+ | `maxLinksPerPage` | 50 | unique links taken from one page, in document order |
67
+ | `maxTotal` | 200 | unique links requested in the whole run; the rest are reported as not checked |
68
+ | `concurrency` | 4 | simultaneous requests |
69
+ | `timeoutMs` | 10000 | per request |
70
+ | `ignorePrefixes` | `["/_next/"]` | path prefixes never checked |
71
+
72
+ A case can opt out with `"skipDeadLinks": true`. Dead links are listed with every source page ("linked from"). Same-origin redirects are followed; a redirect to another origin counts as alive and is not followed; status 400+ or no response is dead. Fragments, `mailto:`, `tel:`, `javascript:` and other origins are ignored. Relative links resolve against `<base href>` when the page has one. Link extraction is regex-based: it reads quoted `href` on `<a>` tags in the served HTML, so it also sees anchors inside comments, scripts and `<noscript>`, and misses unquoted hrefs. Only server-rendered `<a href>` is seen; links added by client-side JavaScript are not. With `SMOKE_TEST_VERIFY_CACHE` (two passes) the check runs on pass 1 only, so pass 1 takes longer and the timing-only cache fallback (used when `x-nextjs-cache` is absent) is easier to pass. Run it against a local or preview deployment: it adds requests, so keep the caps modest on production.
@@ -0,0 +1,92 @@
1
+ # Smoke coverage (`coverage` block in `smoke.cases.json`)
2
+
3
+ Smoke routes are curated by hand, so coverage drifts: a new article type, person type or privacy page gets no case and nobody notices. The optional `coverage` block compares the cases with the site's Contentful model and sitemap, and fails (or samples) when a routable type has no case.
4
+
5
+ **Opt-in.** A `smoke.cases.json` without a `coverage` block behaves exactly as before: no sitemap request, no Contentful request, no extra cases.
6
+
7
+ ## How it works
8
+
9
+ 1. **Model (read-only).** GETs `content_types` and the slugs of `pageVariant`, `articleType`, `personType` and `customType` entries, plus entry counts for the other routable types. Uses `CONTENTFUL_SPACE_ID`, `CONTENTFUL_ENVIRONMENT` (or `CONTENTFUL_ENVIRONMENT_NAME`, default `master`), `CONTENTFUL_ACCESS_TOKEN` (or `CONTENTFUL_PREVIEW_ACCESS_TOKEN` when `cmsIntegrity.preview` is true) and optionally `CONTENTFUL_DEFAULT_LOCALE` (picks the slug locale on management reads). If there is no delivery token, `CONTENTFUL_MANAGEMENT_TOKEN` is used for GETs only. Nothing is written.
10
+ 2. **Sitemap.** Reads `<baseUrl>/sitemap.xml` (or `coverage.sitemapUrl`), following sitemap indexes on the same host. Only the path is kept, so a sitemap that lists production URLs works against a dev server or preview. At most 20 sitemaps and 20,000 paths are read, and exceeding either counts as an incomplete read (see below). Requests time out after 15 s. If any sitemap (or child sitemap) cannot be read, or is `.xml.gz`, the run reports one coverage failure (a warning in `warn` mode) rather than treating the missing routes as not routable. A `coverage.sitemapUrl` on another host is fetched without the Vercel bypass header.
11
+ 3. **Classify.** Each sitemap path and each curated case is mapped to an item using the model and `cmsIntegrity.routing` (`articleTypesBasePath`, `tagsBasePath`, `peopleBasePath`). Without `cmsIntegrity.routing` the check assumes `/articles`, `/tags`, `/people` and says so.
12
+ 4. **Compare.** A routable item with no case is flagged, naming the content type.
13
+
14
+ ### Items
15
+
16
+ | Item | Needs a case when | Satisfied by |
17
+ |---|---|---|
18
+ | `home` | model has `page` | category `home`, or path `/` |
19
+ | `privacy` | model has `page` | category `privacy`, or a plain page whose last path segment contains `privacy` (article, person and tag routes are never read as privacy) |
20
+ | `page` | model has `page` | any other page path |
21
+ | `pageVariant` | model has published `pageVariant` entries | a path equal to a variant slug |
22
+ | `articleTypeIndex:<slug>` | an `articleType` entry has a sitemap route | its index path |
23
+ | `article:<slug>` | the sitemap has an article under that type | a path under the type |
24
+ | `articlesIndex` | the sitemap has the articles base path | `<articleTypesBasePath>/` |
25
+ | `person`, `person:<slug>` | published `person` entries and a sitemap route | a path under the people base path or person type |
26
+ | `peopleIndex`, `personType:<slug>` | the sitemap has the index | a case at that path (category `person-index` is recommended; the category itself is not checked) |
27
+ | `tag`, `tagsIndex` | published `tag` entries and a sitemap route | a path under, or at, the tags base path |
28
+ | `customType:<slug>` | a `customType` entry has a sitemap route | its path |
29
+
30
+ Matching is by path, not by category; only `home` and `privacy` cases are also recognised by category. `prefix:*` wildcards also match the bare family item, so `article:*` covers `article`. An article type is recognised both under `articleTypesBasePath` and at the site root (`/<slug>/`), so a normal page with the same slug as an article type is read as that type's index.
31
+
32
+ Only `home`, `privacy` and `page` are required without sitemap evidence. Every other item is required only when the model has entries for it and the sitemap has a route, so a site that turns tag or people pages off is not flagged. Such items are listed as `not routable on this site`.
33
+
34
+ ## Config
35
+
36
+ ```json
37
+ {
38
+ "coverage": {
39
+ "mode": "warn",
40
+ "require": ["home", "privacy", "article:*", "articleTypeIndex:*"],
41
+ "sitemapUrl": "https://www.example.com/sitemap.xml",
42
+ "samplesPerItem": 1,
43
+ "maxSamples": 25,
44
+ "seed": "smoke"
45
+ }
46
+ }
47
+ ```
48
+
49
+ | Key | Default | Meaning |
50
+ |---|---|---|
51
+ | `mode` | `warn` | `warn` (default): reported, never fails (use while migrating). `enforce`: a missing item fails the run. `sample`: a missing item is filled by a sitemap sample that runs as a case; it fails only when the sitemap has nothing to sample or `maxSamples` is reached (core items `home`, `privacy`, `page` are sampled first). |
52
+ | `require` | all derived items | Allowlist. Only these items are checked. `prefix:*` matches a family, for example `article:*`. |
53
+ | `exempt` | none | Schema field only; fleet policy is that no site uses it (all sites are held to the same coverage). `reason` is required and validated. An exemption that matches nothing is reported as stale. |
54
+ | `sitemapUrl` | `<baseUrl>/sitemap.xml` | Override when the sitemap lives elsewhere. |
55
+ | `samplesPerItem` | `1` | Routes sampled per uncovered item in `sample` mode. `enforce` and `warn` suggest the first pick. |
56
+ | `maxSamples` | `25` | Cap on sampled routes per run. Items past the cap are reported as `sample_cap` failures. |
57
+ | `seed` | `smoke` | Changes which routes the sampler picks. Same seed and sitemap give the same routes. |
58
+
59
+ Sampling is deterministic: candidates are ordered by a hash of `seed`, item and path, so the pick does not depend on sitemap order. Only entries in `cases` count as curated coverage; cases added by discovery are not seen. Slugs are compared after percent-decoding, except `%2F`, `%3F`, `%23` and `%25`, which stay encoded, and escape sequences that are not valid UTF-8, which are left as written. Sampled URLs are re-encoded without touching existing `%XX` escapes, so nothing is encoded twice. Sampled cases are labelled `[coverage sample] <item>` and use `expectMarkdown: false` (HTML status and CMS chrome checks only). To keep a route permanently, copy it into `cases`.
60
+
61
+ If the model or sitemap cannot be read, the run reports one coverage failure (a warning in `warn` mode) instead of crashing. Item `privacy` matches a plain page whose last path segment contains `privacy`, including `/privacy.html`.
62
+
63
+ ## Categories
64
+
65
+ `SmokeTestCategory` gains `privacy` and `person-index`.
66
+
67
+ - `privacy` is a CMS page category: nav, footer, h1, title, description and og:image checks apply.
68
+ - `person-index` is accepted for people and person-type indexes. It is **not** added to the CMS chrome checks, so sites that already use it see no new failures (Headwater and Pedestal use it in their `smoke.cases.json`; no checked customer repo uses `privacy` yet). Add it to `CMS_PAGE_CATEGORIES` later if wanted.
69
+
70
+ ## Dry run
71
+
72
+ Read-only; runs no page cases and writes nothing. Works on a `smoke.cases.json` that has no `coverage` block yet:
73
+
74
+ ```bash
75
+ CONTENTFUL_SPACE_ID=<space> CONTENTFUL_ENVIRONMENT=master CONTENTFUL_ACCESS_TOKEN=<cda-token> \
76
+ node node_modules/@se-studio/site-check/smoke-coverage-dry-run.mjs \
77
+ --cases smoke.cases.json --base-url https://www.example.com [--mode warn]
78
+ ```
79
+
80
+ Exit code 1 means the check would fail.
81
+
82
+ ## Migration note for customer repos
83
+
84
+ Nothing changes until a repo adds a `coverage` block, so upgrading `@se-studio/site-check` is safe on its own. The default mode is `warn`. Adoption is staged per repo: **`warn` first, then `enforce`**. Each repo gets its own PR.
85
+
86
+ 1. Bump `@se-studio/site-check` to the release that contains this feature. The `cmsIntegrity.routing` block should already match the app's URL rules; coverage depends on it.
87
+ 2. Run the dry run above. Review what it flags.
88
+ 3. Add `"coverage": { "mode": "warn" }` (or leave `mode` out, since `warn` is the default). Make sure the CI/local env has the Contentful variables `cmsIntegrity` already needs. Do not add `exempt` entries: the fleet rule is that every site is held to the same coverage, so a gap is fixed with a case, not exempted.
89
+ 4. Add the cases the report suggests (use the `privacy` category for the privacy page, `person-index` for people indexes). Sampled cases are HTML-only (`expectMarkdown: false`).
90
+ 5. When the `warn` report is clean, set `"mode": "enforce"`. `enforce` is never the default; a repo opts in.
91
+
92
+ Repos with a custom live script or a vendored `smoke-test-one.mjs` (Pedestal, Highlander) only pick this up if their script calls `runStaticSmokeTest` / `runPreviewStaticSmokeTest` from `@se-studio/site-check/smoke-test`. Check that before enabling.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/site-check",
3
- "version": "2.19.1",
3
+ "version": "2.20.0",
4
4
  "description": "Validate SE marketing sites (sitemap, llms.txt) and download markdown files preserving structure",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,6 +57,7 @@
57
57
  "smoke-test-one": "./smoke-test-one.mjs",
58
58
  "smoke-test-deploy-check": "./smoke-test-deploy-check.mjs",
59
59
  "smoke-test-live": "./smoke-test-live.mjs",
60
+ "smoke-coverage-dry-run": "./smoke-coverage-dry-run.mjs",
60
61
  "validate-build-routes": "./validate-build-routes.mjs",
61
62
  "revalidation-matrix-test": "./revalidation-matrix-test.mjs",
62
63
  "develop-sites-timing": "./develop-sites-timing.mjs",
@@ -78,6 +79,7 @@
78
79
  "scripts/smoke-env.mjs",
79
80
  "smoke-test-deploy-check.mjs",
80
81
  "smoke-test-live.mjs",
82
+ "smoke-coverage-dry-run.mjs",
81
83
  "validate-build-routes.mjs",
82
84
  "revalidation-matrix-test.mjs",
83
85
  "develop-sites-timing.mjs",
@@ -120,6 +122,6 @@
120
122
  "type-check": "tsc --noEmit",
121
123
  "lint": "biome lint .",
122
124
  "clean": "rm -rf dist .turbo *.tsbuildinfo",
123
- "test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/screaming-frog-config.test.mjs scripts/production-audit.test.mjs scripts/discovery.test.mjs scripts/smoke-test.test.mjs scripts/analytics-context-bundle.test.mjs scripts/check-no-context-workarounds.test.mjs scripts/check-cms-driven.test.mjs scripts/check-comments.test.mjs scripts/check-class-gaps.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs scripts/publish-state.test.mjs scripts/site-type-audit.test.mjs"
125
+ "test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/screaming-frog-config.test.mjs scripts/production-audit.test.mjs scripts/discovery.test.mjs scripts/smoke-test.test.mjs scripts/smoke-coverage.test.mjs scripts/smoke-followups.test.mjs scripts/analytics-context-bundle.test.mjs scripts/check-no-context-workarounds.test.mjs scripts/check-cms-driven.test.mjs scripts/check-comments.test.mjs scripts/check-class-gaps.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs scripts/publish-state.test.mjs scripts/site-type-audit.test.mjs"
124
126
  }
125
127
  }
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Read-only coverage dry run. Reads the Contentful model (GET only) and the site's sitemap, compares
5
+ * them with a smoke.cases.json, and prints what the coverage check would flag. It never runs page
6
+ * smoke cases and never writes anything.
7
+ *
8
+ * Usage: smoke-coverage-dry-run --cases <smoke.cases.json> --base-url <https://site> [--mode warn|sample|enforce]
9
+ * Env: CONTENTFUL_SPACE_ID, CONTENTFUL_ENVIRONMENT, and CONTENTFUL_ACCESS_TOKEN (or, read-only,
10
+ * CONTENTFUL_MANAGEMENT_TOKEN). Exit code is 1 when the check would fail.
11
+ */
12
+
13
+ import { dirname, join, resolve } from 'node:path';
14
+ import { fileURLToPath } from 'node:url';
15
+
16
+ const packageDir = dirname(fileURLToPath(import.meta.url));
17
+
18
+ function arg(name) {
19
+ const index = process.argv.indexOf(`--${name}`);
20
+ return index === -1 ? undefined : process.argv[index + 1];
21
+ }
22
+
23
+ const casesPath = arg('cases');
24
+ const baseUrl = arg('base-url');
25
+ if (!casesPath || !baseUrl) {
26
+ console.error(
27
+ 'Usage: smoke-coverage-dry-run --cases <smoke.cases.json> --base-url <https://site> [--mode warn|sample|enforce]',
28
+ );
29
+ process.exit(2);
30
+ }
31
+
32
+ const { prepareCoverage, formatCoverageReport } = await import(
33
+ join(packageDir, 'dist/smoke-test/smoke-coverage/index.js')
34
+ );
35
+ const { loadSmokeConfigFile } = await import(join(packageDir, 'dist/smoke-test/config.js'));
36
+ const { SMOKE_COVERAGE_MODES } = await import(
37
+ join(packageDir, 'dist/smoke-test/smoke-coverage/types.js')
38
+ );
39
+ const { joinSmokeBaseUrl } = await import(join(packageDir, 'dist/smoke-test/static.js'));
40
+
41
+ const mode = arg('mode');
42
+ if (mode && !SMOKE_COVERAGE_MODES.includes(mode)) {
43
+ console.error(`--mode must be one of ${SMOKE_COVERAGE_MODES.join(', ')}`);
44
+ process.exit(2);
45
+ }
46
+
47
+ const raw = loadSmokeConfigFile(resolve(casesPath));
48
+ // The dry run applies the check to files that have no coverage block yet.
49
+ raw.coverage = { ...(raw.coverage ?? {}), ...(mode ? { mode } : {}) };
50
+
51
+ const cases = (raw.cases ?? []).map((entry) => ({
52
+ category: entry.category,
53
+ label: entry.label,
54
+ pageUrl: joinSmokeBaseUrl(baseUrl, entry.path),
55
+ expectMarkdown: entry.expectMarkdown,
56
+ }));
57
+
58
+ const prepared = await prepareCoverage(raw, cases, { baseUrl, env: process.env });
59
+ console.log(`Coverage dry run: ${raw.siteName} (${baseUrl}), ${cases.length} curated cases`);
60
+ console.log(formatCoverageReport(prepared.report).join('\n'));
61
+ process.exit(prepared.report.failureCount > 0 ? 1 : 0);