@se-studio/site-check 2.22.1 → 2.25.3

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,60 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.25.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d4ad977]
8
+ - @se-studio/contentful-rest-api@2.9.3
9
+ - @se-studio/core-data-types@2.2.1
10
+ - @se-studio/core-ui@1.48.7
11
+
12
+ ## 2.25.2
13
+
14
+ ### Patch Changes
15
+
16
+ - acd8820: site-check develop-published-gate: the sitemap-parity stage no longer fails on a valid but empty (or absent) `/sitemap-unindexed.xml`; `/sitemap.xml` must still list at least one URL, every listed path must still pass the slug guard, and a 5xx or non-sitemap body on the unindexed file still fails. Also fixes the `--compare-timeout-minutes` header text ("finite and > 0") and moves the end-to-end test setup inside its `try`.
17
+
18
+ core-ui: new `hasStaticAssetExtension(pathname)`, the pathname guard's static-asset list. The site proxy template's `applyCmsRedirects` uses it, so a CMS redirect whose From path contains a dot (`/blog/st.-louis/`) now applies; only static-asset extensions (`.pdf`, `.xml`, `.html`, ...) are skipped.
19
+ - Updated dependencies [acd8820]
20
+ - @se-studio/core-ui@1.48.6
21
+
22
+ ## 2.25.1
23
+
24
+ ### Patch Changes
25
+
26
+ - b65f49f: develop-published-gate: round the compare timeout to whole milliseconds (at least 1) and treat a non-finite `GATE_COMPARE_TIMEOUT_MINUTES` (Infinity, NaN) as unset, so `spawnSync` can no longer throw; an `Infinity` `--compare-timeout-minutes` is a usage error. Adds an end-to-end test of `main` with stubbed fetch, fixes the usage line (`--prod-url` is only needed with `--compare` or `--sitemap-roots`) and the docs and template timeout notes (job timeout above the compare limit). The release rule text in docs, the skills references and the promote-gate message now says a promote needs a green develop-published gate on the exact commit, and the prod compare is a manual run only when Nick asks for one.
27
+
28
+ ## 2.25.0
29
+
30
+ ### Minor Changes
31
+
32
+ - 55c2a3b: develop-published-gate: the develop-vs-production compare is now on demand only. It is off by default and runs only with `--compare` (alias `--prod-compare`). Without it the stage reports exactly `compare: not run (on-demand)` and counts as neither a pass nor a fail (recorded in `--json` as `ok: null, skipped: true`), and `--prod-url` is no longer required. `--compare-timeout-minutes` and `GATE_COMPARE_TIMEOUT_MINUTES` apply only when the compare runs. Every other stage (exact commit, noindex, draft canary, full smoke, content smoke, sitemap slug-guard parity) runs unchanged on every deployment; parity fetches the build's own sitemap and never depended on the compare. The workflow template gains a `workflow_dispatch` boolean input `compare` (default false) that passes `--compare` only for a manual run; the deployment.ready path never does. Manual compare runs are never skipped as already green, have their own concurrency group, and post the same status context with the description noting whether the compare ran. Note for gate consumers: a green `develop-published gate` no longer includes a prod compare unless `--compare` was passed.
33
+
34
+ ## 2.24.0
35
+
36
+ ### Minor Changes
37
+
38
+ - 57e556e: develop-published-gate: the spawned prod compare limit is configurable and defaults to 25 minutes again. `--compare-timeout-minutes <n>` sets it, `GATE_COMPARE_TIMEOUT_MINUTES` overrides the default when it is a positive number, and the flag wins. The published gate had hard-coded 10 minutes, which contradicted the 25 minutes in the docs and the earlier changelog and would have killed healthy compares (HSD takes about 20, Pedestal about 30). Also adds `--no-draft-canary` for sites with no draft-only page: the draft-canary stage passes with a `SKIPPED` detail instead of failing for lack of `--draft-canary`. With these, the vendored gate copies (HSD, Eagle, Pedestal, Headwater, Brightline, BLK) can be replaced by the `develop-published-gate` bin.
39
+
40
+ ## 2.23.1
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [53ee13b]
45
+ - @se-studio/core-ui@1.48.5
46
+
47
+ ## 2.23.0
48
+
49
+ ### Minor Changes
50
+
51
+ - 161a183: `develop-published-gate` adds a sitemap-parity stage: any path in the build's sitemap that fails core's impossible-slug guard (`pathnameHasImpossibleCmsSlug`, imported from `@se-studio/core-ui/impossible-cms-slug`) now FAILS the gate instead of passing silently. An unreadable build sitemap also fails. Adds `@se-studio/core-ui` as a dependency.
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [161a183]
56
+ - @se-studio/core-ui@1.48.4
57
+
3
58
  ## 2.22.1
4
59
 
5
60
  ### Patch Changes
package/README.md CHANGED
@@ -259,7 +259,7 @@ Optional per-case HTML checks for release verification (key blocks must render,
259
259
 
260
260
  ### develop-published gate (`develop-published-gate`)
261
261
 
262
- Promote gate against a persistent published-content build of develop: exact commit, noindex, draft canary, full smoke, content smoke and a prod compare, in one command. Workflow templates are in `templates/develop-published/`. See [docs/develop-published.md](./docs/develop-published.md).
262
+ Promote gate against a persistent published-content build of develop: exact commit, noindex, draft canary, full smoke, content smoke and sitemap slug-guard parity in one command; the prod compare runs only on demand (`--compare`). Workflow templates are in `templates/develop-published/`. See [docs/develop-published.md](./docs/develop-published.md).
263
263
 
264
264
  ### Publish-state check (CDA vs CPA)
265
265
 
@@ -3,19 +3,30 @@
3
3
  /**
4
4
  * develop-published promote gate.
5
5
  *
6
- * Runs the full smoke, the content smoke (cases with `contentAssert` only) and the prod
7
- * compare against the `develop-published` deployment of the exact commit being promoted.
6
+ * Runs the full smoke, the content smoke (cases with `contentAssert` only), the sitemap slug-guard parity
7
+ * and the draft canary against the `develop-published` deployment of the exact commit being promoted.
8
+ * The develop-vs-production compare (sitemap pages exist, page text) is ON DEMAND ONLY: it runs just when
9
+ * `--compare` (alias `--prod-compare`) is given. Without it that stage reports `compare: not run (on-demand)`
10
+ * and counts as neither a pass nor a fail.
8
11
  * Run it from the app root (where smoke.cases.json and vercel.json live).
9
12
  *
10
13
  * Usage:
11
- * develop-published-gate --url <deploymentUrl> --prod-url <productionUrl> [options]
14
+ * develop-published-gate --url <deploymentUrl> --host-prefix <prefix> [options]
15
+ * (--prod-url <productionUrl> is needed only with --compare or --sitemap-roots)
12
16
  *
13
17
  * Options:
14
18
  * --url <url> develop-published deployment URL (or DEPLOYMENT_URL)
15
- * --prod-url <url> production site for the compare (or PRODUCTION_SITE_URL)
19
+ * --compare, --prod-compare run the develop-vs-production compare (off by default, on demand only)
20
+ * --prod-url <url> production site for the compare (or PRODUCTION_SITE_URL). Required with
21
+ * --compare (or --sitemap-roots); not needed otherwise
16
22
  * --expect-sha <sha> commit being promoted (default: git HEAD)
17
23
  * --deployment-sha <sha> commit the deployment was built from (the Vercel dispatch payload sha)
18
24
  * --draft-canary <path> path that exists only as a draft; must 404 on the deployment (repeatable)
25
+ * --no-draft-canary skip the canary stage (site has no draft-only page). Without it, giving no
26
+ * --draft-canary fails the gate. Ignored when a --draft-canary is also given
27
+ * --compare-timeout-minutes <n> kill the spawned prod compare after n minutes (default 25, or the
28
+ * GATE_COMPARE_TIMEOUT_MINUTES env when it is finite and > 0; the flag wins).
29
+ * Only used when --compare is given
19
30
  * --sitemap-roots <list> sitemap roots this app owns, comma-separated paths or absolute URLs on the production
20
31
  * site (e.g. /marketing/sitemap.xml); repeatable. The prod compare walks only these
21
32
  * roots (an index is followed one level). Default: the full production sitemap
@@ -30,6 +41,7 @@
30
41
  * --json <file> write the result summary as JSON
31
42
  *
32
43
  * Env: VERCEL_PROTECTION_BYPASS_TOKEN (deployment protection bypass; never printed).
44
+ * GATE_COMPARE_TIMEOUT_MINUTES (compare kill limit in minutes, default 25; ignored unless finite and > 0).
33
45
  * Exit 0 only when every stage passes, 1 when a stage fails, 2 on a usage or runtime error.
34
46
  * See docs/develop-published.md.
35
47
  */
@@ -38,6 +50,7 @@ import fs from 'node:fs';
38
50
  import os from 'node:os';
39
51
  import path from 'node:path';
40
52
  import { fileURLToPath } from 'node:url';
53
+ import { pathnameHasImpossibleCmsSlug } from '@se-studio/core-ui/impossible-cms-slug';
41
54
 
42
55
  const here = path.dirname(fileURLToPath(import.meta.url));
43
56
  const SMOKE_LIVE = path.join(here, 'smoke-test-live.mjs');
@@ -61,7 +74,14 @@ export function parseArgs(argv) {
61
74
  else if (a === '--expect-sha') o.expectSha = next();
62
75
  else if (a === '--deployment-sha') o.deploymentSha = next();
63
76
  else if (a === '--draft-canary') o.canaries.push(next());
64
- else if (a === '--sitemap-roots') {
77
+ else if (a === '--no-draft-canary') o.noCanary = true;
78
+ else if (a === '--compare' || a === '--prod-compare') o.compare = true;
79
+ else if (a === '--compare-timeout-minutes') {
80
+ const minutes = Number(next());
81
+ if (!Number.isFinite(minutes) || minutes <= 0)
82
+ throw new Error('--compare-timeout-minutes needs a positive number of minutes');
83
+ o.compareTimeoutMinutes = minutes;
84
+ } else if (a === '--sitemap-roots') {
65
85
  const roots = splitRoots(next());
66
86
  if (roots.length === 0) throw new Error('--sitemap-roots needs at least one root');
67
87
  o.sitemapRoots.push(...roots);
@@ -163,8 +183,21 @@ function bypassHeaders(url) {
163
183
  /** Per-request limit for every prod-compare / sitemap fetch (headers and body), so a stall cannot hang the run. */
164
184
  export const FETCH_TIMEOUT_MS = 30_000;
165
185
 
166
- /** Whole-process limit for the spawned site-check compare, so a stall inside it cannot hang the run either. */
167
- export const COMPARE_TIMEOUT_MS = 10 * 60_000;
186
+ /** Default whole-process limit for the spawned site-check compare (a healthy HSD compare takes ~20 minutes). */
187
+ export const DEFAULT_COMPARE_TIMEOUT_MINUTES = 25;
188
+ export const COMPARE_TIMEOUT_MS = DEFAULT_COMPARE_TIMEOUT_MINUTES * 60_000;
189
+
190
+ /**
191
+ * Whole-process limit for the spawned site-check compare, so a stall inside it cannot hang the run either.
192
+ * `--compare-timeout-minutes` wins, then a finite positive GATE_COMPARE_TIMEOUT_MINUTES (junk, zero, negative and
193
+ * Infinity count as unset), else the 25-minute default. The result is a whole number of milliseconds, at least 1.
194
+ */
195
+ export function resolveCompareTimeoutMs(flagMinutes, env = process.env) {
196
+ const toMs = (minutes) => Math.max(1, Math.round(minutes * 60_000));
197
+ if (flagMinutes !== undefined) return toMs(flagMinutes);
198
+ const fromEnv = Number(env.GATE_COMPARE_TIMEOUT_MINUTES);
199
+ return toMs(Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : DEFAULT_COMPARE_TIMEOUT_MINUTES);
200
+ }
168
201
 
169
202
  /** fetch() with a hard per-request timeout. The abort surfaces as a TimeoutError, which withRetry treats as transient. */
170
203
  export function fetchWithTimeout(url, init = {}, timeoutMs = FETCH_TIMEOUT_MS) {
@@ -277,10 +310,15 @@ export function isNonPageUrl(url) {
277
310
  * Production page URLs listed under the given sitemap roots only. A root that is a sitemap index is
278
311
  * followed one level (its child sitemaps are fetched and must answer 2xx; a nested index is an error);
279
312
  * a root that is a urlset contributes its own URLs. A root that does not answer 2xx, or lists nothing,
280
- * throws: the compare never passes on an empty or unreadable root.
313
+ * throws: the compare never passes on an empty or unreadable root. `allowEmpty` (optional roots only, such as
314
+ * the build's `/sitemap-unindexed.xml`) lets a valid sitemap with zero URLs pass; a non-sitemap body still throws.
281
315
  * `fetchText(url)` resolves {status, text}.
282
316
  */
283
- export async function collectRootPageUrls(rootUrls, fetchText) {
317
+ export async function collectRootPageUrls(
318
+ rootUrls,
319
+ fetchText,
320
+ { rebaseChildren = false, allowEmpty = false } = {},
321
+ ) {
284
322
  const pages = [];
285
323
  for (const root of rootUrls) {
286
324
  const origin = new URL(root).origin;
@@ -293,9 +331,11 @@ export async function collectRootPageUrls(rootUrls, fetchText) {
293
331
  if (!isIndex) {
294
332
  rootPages.push(...locs);
295
333
  } else {
296
- for (const child of locs) {
297
- if (new URL(child).origin !== origin)
298
- throw new Error(`child sitemap ${child} of ${root} is not on ${origin}`);
334
+ for (const loc of locs) {
335
+ const childUrl = new URL(loc);
336
+ if (childUrl.origin !== origin && !rebaseChildren)
337
+ throw new Error(`child sitemap ${loc} of ${root} is not on ${origin}`);
338
+ const child = rebaseChildren ? `${origin}${childUrl.pathname}${childUrl.search}` : loc;
299
339
  const c = await fetchText(child);
300
340
  if (c.status < 200 || c.status >= 300)
301
341
  throw new Error(`child sitemap ${child} of ${root} returned HTTP ${c.status}`);
@@ -304,7 +344,11 @@ export async function collectRootPageUrls(rootUrls, fetchText) {
304
344
  rootPages.push(...extractLocs(c.text));
305
345
  }
306
346
  }
307
- if (rootPages.length === 0) throw new Error(`sitemap root ${root} lists no URLs`);
347
+ if (rootPages.length === 0) {
348
+ const isSitemap = isIndex || /<urlset[\s>]/.test(res.text);
349
+ if (!allowEmpty) throw new Error(`sitemap root ${root} lists no URLs`);
350
+ if (!isSitemap) throw new Error(`sitemap root ${root} is not a sitemap`);
351
+ }
308
352
  pages.push(...rootPages);
309
353
  }
310
354
  return [...new Set(pages)];
@@ -372,6 +416,88 @@ export async function compareSitemapRoots({
372
416
  };
373
417
  }
374
418
 
419
+ /**
420
+ * Sitemap paths the core guard would 404. The guard is core's `pathnameHasImpossibleCmsSlug` (not a copy), so
421
+ * the sitemap and the routes cannot drift: a URL the sitemap advertises must never be one the app refuses.
422
+ * Returns the offending pathnames (decoded as listed), de-duplicated, in sitemap order.
423
+ */
424
+ export function findImpossibleSitemapPaths(urls, isImpossible = pathnameHasImpossibleCmsSlug) {
425
+ const bad = [];
426
+ for (const u of urls) {
427
+ let pathname;
428
+ try {
429
+ pathname = new URL(u).pathname;
430
+ } catch {
431
+ bad.push(u);
432
+ continue;
433
+ }
434
+ if (isImpossible(pathname)) bad.push(pathname);
435
+ }
436
+ return [...new Set(bad)];
437
+ }
438
+
439
+ /**
440
+ * Sitemap-parity stage: every page the deployment's own sitemap lists must pass the core slug guard. Roots are
441
+ * the build's sitemap roots (default `/sitemap.xml`, which must list at least one URL, plus `/sitemap-unindexed.xml` when the build serves it: absent or valid-but-empty passes, a 5xx or a non-sitemap body fails). Index children are fetched from the build origin even when the build's sitemap lists them on the production domain.
442
+ * A sitemap that cannot be read FAILS (never a silent pass). `fetchText(url)` resolves {status, text}.
443
+ */
444
+ export async function checkSitemapSlugParity({
445
+ rootUrls,
446
+ fetchText,
447
+ optionalRootUrls = [],
448
+ isImpossible = pathnameHasImpossibleCmsSlug,
449
+ }) {
450
+ let urls;
451
+ try {
452
+ const rebase = { rebaseChildren: true };
453
+ urls = await collectRootPageUrls(rootUrls, fetchText, rebase);
454
+ for (const root of optionalRootUrls) {
455
+ const probe = await fetchText(root);
456
+ if (probe.status >= 500)
457
+ throw new Error(`optional sitemap ${root} returned HTTP ${probe.status}`);
458
+ if (probe.status >= 200 && probe.status < 300)
459
+ urls = [
460
+ ...new Set([
461
+ ...urls,
462
+ ...(await collectRootPageUrls([root], fetchText, { ...rebase, allowEmpty: true })),
463
+ ]),
464
+ ];
465
+ }
466
+ } catch (err) {
467
+ return {
468
+ ok: false,
469
+ offenders: [],
470
+ detail: `could not read the build sitemap: ${err instanceof Error ? err.message : String(err)}`,
471
+ };
472
+ }
473
+ const offenders = findImpossibleSitemapPaths(urls, isImpossible);
474
+ if (offenders.length > 0) {
475
+ const shown = offenders.slice(0, 10).join(', ');
476
+ return {
477
+ ok: false,
478
+ offenders,
479
+ detail: `${offenders.length} sitemap path(s) fail the core impossible-slug guard and would 404: ${shown}${offenders.length > 10 ? ', …' : ''}`,
480
+ };
481
+ }
482
+ return {
483
+ ok: true,
484
+ offenders: [],
485
+ detail: `${urls.length} sitemap URL(s) all pass the core slug guard`,
486
+ };
487
+ }
488
+
489
+ /** Build sitemap roots: the configured roots rebased onto the deployment origin, else the default index. */
490
+ export function buildSitemapRoots(roots, prodUrl, devUrl) {
491
+ const dev = new URL(devUrl).origin;
492
+ if (roots.length === 0)
493
+ return { rootUrls: [`${dev}/sitemap.xml`], optionalRootUrls: [`${dev}/sitemap-unindexed.xml`] };
494
+ const rebased = resolveSitemapRoots(roots, prodUrl).map((r) => {
495
+ const u = new URL(r);
496
+ return `${dev}${u.pathname}${u.search}`;
497
+ });
498
+ return { rootUrls: rebased, optionalRootUrls: [] };
499
+ }
500
+
375
501
  /** ": <reason>" when the roots compare itself failed (unreadable root), else "". Only the roots path prints this marker. */
376
502
  function sitemapRootsError(out) {
377
503
  const m = out.match(/^Sitemap roots failed: (.+)$/m);
@@ -514,10 +640,38 @@ async function headStatus(url) {
514
640
  throw new Error(`Too many redirects from ${url}`);
515
641
  }
516
642
 
643
+ /** Detail (and console line) of the prod-compare stage when the compare was not asked for. */
644
+ export const COMPARE_NOT_RUN = 'compare: not run (on-demand)';
645
+
646
+ /** The prod-compare stage when `--compare` was not given: neither a pass nor a fail (`ok: null`, `skipped: true`). */
647
+ export function compareNotRunStage() {
648
+ return { name: 'prod compare', ok: null, skipped: true, detail: COMPARE_NOT_RUN };
649
+ }
650
+
651
+ /** The gate passes when every stage that ran passed. A skipped stage counts as neither a pass nor a fail. */
652
+ export function gateOk(stages) {
653
+ return stages.filter((x) => !x.skipped).every((x) => x.ok);
654
+ }
655
+
656
+ /** The draft-canary stage when no --draft-canary path was given: a failure, unless --no-draft-canary opts out. */
657
+ export function noCanaryStage(noCanary) {
658
+ return noCanary
659
+ ? {
660
+ ok: true,
661
+ detail:
662
+ 'SKIPPED (--no-draft-canary): this site has no draft-only page, published-only is not proven by a canary',
663
+ }
664
+ : { ok: false, detail: 'no --draft-canary given, published-only is unproven' };
665
+ }
666
+
517
667
  export async function main(argv) {
518
668
  const o = parseArgs(argv);
519
669
  if (!o.url) throw new Error('--url (or DEPLOYMENT_URL) is required');
520
- if (!o.prodUrl) throw new Error('--prod-url (or PRODUCTION_SITE_URL) is required');
670
+ // The production URL is only used by the compare (and to resolve --sitemap-roots paths).
671
+ if (!o.prodUrl && (o.compare || o.sitemapRoots.length > 0))
672
+ throw new Error(
673
+ '--prod-url (or PRODUCTION_SITE_URL) is required with --compare or --sitemap-roots',
674
+ );
521
675
  if (!o.hostPrefix)
522
676
  throw new Error(
523
677
  '--host-prefix is required (the bypass token is only sent to a matching *.vercel.app host)',
@@ -534,6 +688,8 @@ export async function main(argv) {
534
688
  stages.push({ name, ok, detail });
535
689
  console.log(`${ok ? 'PASS' : 'FAIL'} ${name}: ${detail}`);
536
690
  };
691
+ let sitemapWarnings = [];
692
+ let pages = [];
537
693
 
538
694
  // 0. exact commit
539
695
  const commit = checkExactCommit(o.deploymentSha, expect);
@@ -558,8 +714,10 @@ export async function main(argv) {
558
714
  `HTTP ${r.status} (404 means the draft is not served)`,
559
715
  );
560
716
  }
561
- if (o.canaries.length === 0)
562
- add('draft canary', false, 'no --draft-canary given, published-only is unproven');
717
+ if (o.canaries.length === 0) {
718
+ const stage = noCanaryStage(o.noCanary);
719
+ add('draft canary', stage.ok, stage.detail);
720
+ }
563
721
 
564
722
  // 2. full smoke
565
723
  const smoke = run(process.execPath, [SMOKE_LIVE, '--url', o.url, o.cases], {
@@ -610,70 +768,97 @@ export async function main(argv) {
610
768
  // 4a. prod compare: every production sitemap page that is live on production exists on the deployment.
611
769
  // Pages that 404 on production itself are dead sitemap entries: a warning, not a gate failure.
612
770
  // With --sitemap-roots only the roots this app owns are walked; without it the full production index is.
613
- const cmp =
614
- o.sitemapRoots.length > 0
615
- ? await compareSitemapRoots({
616
- rootUrls: resolveSitemapRoots(o.sitemapRoots, o.prodUrl),
617
- devUrl: o.url,
618
- fetchText: async (u) => {
619
- const r = await get(u);
620
- return { status: r.status, text: r.text };
621
- },
622
- headStatus,
623
- })
624
- : await runCompareWithRetry(() =>
625
- run(
626
- process.execPath,
627
- [
628
- SITE_CHECK,
629
- o.prodUrl,
630
- '--check-against',
631
- o.url,
632
- ...(process.env.VERCEL_PROTECTION_BYPASS_TOKEN ? ['--vercel-bypass'] : []),
633
- ],
634
- {},
635
- COMPARE_TIMEOUT_MS,
636
- ),
637
- );
638
- const sitemap = await judgeSitemapCompare(cmp, async (devUrl) => {
639
- const u = new URL(devUrl);
640
- return (await get(`${o.prodUrl}${u.pathname}${u.search}`)).status;
771
+ // Off unless --compare: then the stage is reported as not run, neither a pass nor a fail.
772
+ if (o.compare) {
773
+ const cmp =
774
+ o.sitemapRoots.length > 0
775
+ ? await compareSitemapRoots({
776
+ rootUrls: resolveSitemapRoots(o.sitemapRoots, o.prodUrl),
777
+ devUrl: o.url,
778
+ fetchText: async (u) => {
779
+ const r = await get(u);
780
+ return { status: r.status, text: r.text };
781
+ },
782
+ headStatus,
783
+ })
784
+ : await runCompareWithRetry(() =>
785
+ run(
786
+ process.execPath,
787
+ [
788
+ SITE_CHECK,
789
+ o.prodUrl,
790
+ '--check-against',
791
+ o.url,
792
+ ...(process.env.VERCEL_PROTECTION_BYPASS_TOKEN ? ['--vercel-bypass'] : []),
793
+ ],
794
+ {},
795
+ resolveCompareTimeoutMs(o.compareTimeoutMinutes),
796
+ ),
797
+ );
798
+ const sitemap = await judgeSitemapCompare(cmp, async (devUrl) => {
799
+ const u = new URL(devUrl);
800
+ return (await get(`${o.prodUrl}${u.pathname}${u.search}`)).status;
801
+ });
802
+ sitemapWarnings = sitemap.warnings;
803
+ for (const w of sitemap.warnings)
804
+ console.log(`WARN prod sitemap lists dead URL: ${w} (404/410 on production too)`);
805
+ add('prod compare: sitemap pages exist', sitemap.ok, sitemap.detail);
806
+ } else {
807
+ stages.push(compareNotRunStage());
808
+ console.log(COMPARE_NOT_RUN);
809
+ }
810
+
811
+ // 4a'. sitemap parity: no path the build's sitemap lists may fail the core impossible-slug guard. A hard
812
+ // failure (not a warning): such a path would 404 for crawlers and users while the sitemap advertises it.
813
+ const parity = await checkSitemapSlugParity({
814
+ ...buildSitemapRoots(o.sitemapRoots, o.prodUrl, o.url),
815
+ fetchText: async (u) => {
816
+ const r = await get(u);
817
+ return { status: r.status, text: r.text };
818
+ },
641
819
  });
642
- for (const w of sitemap.warnings)
643
- console.log(`WARN prod sitemap lists dead URL: ${w} (404/410 on production too)`);
644
- add('prod compare: sitemap pages exist', sitemap.ok, sitemap.detail);
645
-
646
- // 4b. prod compare: text of representative pages (release rule 3)
647
- const paths = asserting
648
- .map((x) => x.path)
649
- .filter((p, i, a) => a.indexOf(p) === i)
650
- .slice(0, o.pages);
651
- const pages = [];
652
- for (const p of paths) {
653
- const [prod, dev] = await Promise.all([get(`${o.prodUrl}${p}`), get(`${o.url}${p}`)]);
654
- const sim =
655
- prod.status === 200 && dev.status === 200
656
- ? similarity(visibleLines(prod.text), visibleLines(dev.text))
657
- : 0;
658
- pages.push({ path: p, prod: prod.status, dev: dev.status, similarity: Number(sim.toFixed(3)) });
820
+ add('sitemap slug guard parity', parity.ok, parity.detail);
821
+
822
+ // 4b. prod compare: text of representative pages (release rule 3). Part of the compare: only with --compare.
823
+ if (o.compare) {
824
+ const paths = asserting
825
+ .map((x) => x.path)
826
+ .filter((p, i, a) => a.indexOf(p) === i)
827
+ .slice(0, o.pages);
828
+ pages = [];
829
+ for (const p of paths) {
830
+ const [prod, dev] = await Promise.all([get(`${o.prodUrl}${p}`), get(`${o.url}${p}`)]);
831
+ const sim =
832
+ prod.status === 200 && dev.status === 200
833
+ ? similarity(visibleLines(prod.text), visibleLines(dev.text))
834
+ : 0;
835
+ pages.push({
836
+ path: p,
837
+ prod: prod.status,
838
+ dev: dev.status,
839
+ similarity: Number(sim.toFixed(3)),
840
+ });
841
+ }
842
+ const bad = pages.filter((x) => x.similarity < o.minSimilarity);
843
+ add(
844
+ 'prod compare: page text',
845
+ pages.length >= 3 && bad.length === 0,
846
+ `${pages.length} pages, min similarity ${Math.min(...pages.map((x) => x.similarity))} (threshold ${o.minSimilarity})`,
847
+ );
848
+ for (const p of pages)
849
+ console.log(` ${p.path} prod ${p.prod} dev ${p.dev} similarity ${p.similarity}`);
659
850
  }
660
- const bad = pages.filter((x) => x.similarity < o.minSimilarity);
661
- add(
662
- 'prod compare: page text',
663
- pages.length >= 3 && bad.length === 0,
664
- `${pages.length} pages, min similarity ${Math.min(...pages.map((x) => x.similarity))} (threshold ${o.minSimilarity})`,
665
- );
666
- for (const p of pages)
667
- console.log(` ${p.path} prod ${p.prod} dev ${p.dev} similarity ${p.similarity}`);
668
851
 
669
- const ok = stages.every((x) => x.ok);
852
+ const ok = gateOk(stages);
670
853
  const result = {
671
854
  ok,
672
855
  url: o.url,
673
856
  expectSha: expect,
674
857
  deploymentSha: o.deploymentSha ?? null,
675
858
  stages,
676
- warnings: sitemap.warnings.map((u) => `prod sitemap lists dead URL: ${u}`),
859
+ compare: !!o.compare,
860
+ warnings: sitemapWarnings.map((u) => `prod sitemap lists dead URL: ${u}`),
861
+ sitemapSlugOffenders: parity.offenders,
677
862
  pages,
678
863
  smoke: s,
679
864
  contentSmoke: c,
@@ -16,18 +16,26 @@ One persistent Vercel preview build of a site's integration branch that reads **
16
16
  2. Merge them. The first push creates `develop-published` at develop's head. The branch only ever fast-forwards: the job uses a plain push and fails, pushing nothing, if it cannot. Never edit the branch or force-push it.
17
17
  3. In the Vercel project, add a **branch-scoped Preview** env var for git branch `develop-published` that switches the site to published content. Find the flag in the app (for example `DRAFT_ONLY=false`; read the app's server config). The CDA token usually already exists as a Preview var. Vercel only accepts a branch-scoped var once the branch exists, so this comes after step 2. Never touch Production env vars.
18
18
  4. **Trigger the build.** Vercel's Git integration does not build a second branch that points at a commit it already built (verified twice on the pilot site, with a new develop-published pushed by the Action and a probe branch pushed by a person, both at a SHA develop had already built: no deployment either time). So the first build, and every refresh, needs an explicit trigger: a Vercel **deploy hook** for ref `develop-published`, or the deployments API with `gitSource {ref: develop-published, sha}`. The update workflow template has a commented trigger step for the deploy-hook route. Until a trigger is set up, the template alone creates no deployment. (Pilot: API call from the worker; a deploy hook is the proposal for automation.)
19
- **One gate run per commit:** the push and the deploy hook usually produce two READY deployments of the same SHA, and each sends its own `vercel.deployment.ready` event, so the gate would run twice. The template's `concurrency` group is keyed on the commit (and the Vercel project): the newer run cancels the older, and a cancelled run posts no status. Every compare and sitemap fetch has a 30s timeout that counts as a transient failure (3 tries); the spawned `site-check` compare is killed after 25 minutes (a healthy compare of a large sitemap takes about 20) and is not retried. The gate job has `timeout-minutes: 35` so a hung run cannot hold a runner for hours (a timed-out job counts as cancelled and posts no status). **Already green, skipped:** the first step of a Vercel-triggered run reads the commit statuses on the promoted SHA and, if the newest `develop-published gate` status (the `GATE_CONTEXT` job env; where one repo gates several apps, give each app's workflow copy its own context) is `success`, skips every later step and posts no new status, so a third deploy of the same SHA cannot re-run the gate. A `failure`, `error`, `pending` or missing status, or an API error, runs the gate; a manual `workflow_dispatch` always runs it.
19
+ **One gate run per commit:** the push and the deploy hook usually produce two READY deployments of the same SHA, and each sends its own `vercel.deployment.ready` event, so the gate would run twice. The template's `concurrency` group is keyed on the commit (and the Vercel project): the newer run cancels the older, and a cancelled run posts no status. Every compare and sitemap fetch has a 30s timeout that counts as a transient failure (3 tries). On a manual compare run, the spawned `site-check` compare is killed after 25 minutes by default (a healthy compare of a large sitemap takes about 20; `--compare-timeout-minutes` or `GATE_COMPARE_TIMEOUT_MINUTES` change it) and is not retried. The gate job has `timeout-minutes: 35`, above that 25 minute default, so a hung run cannot hold a runner for hours; raise it above any longer compare limit (60 for a 45 minute compare). A timed-out job counts as cancelled and posts no status. **Already green, skipped:** the first step of a Vercel-triggered run reads the commit statuses on the promoted SHA and, if the newest `develop-published gate` status (the `GATE_CONTEXT` job env; where one repo gates several apps, give each app's workflow copy its own context) is `success`, skips every later step and posts no new status, so a third deploy of the same SHA cannot re-run the gate. A `failure`, `error`, `pending` or missing status, or an API error, runs the gate; a manual `workflow_dispatch` always runs it.
20
20
  5. Revalidation: content changes reach the build through the site's Contentful webhook, not rebuilds. The existing webhooks target production and the develop branch alias, so they do not reach develop-published. A webhook for the `develop-published` branch alias (same topics and filter as the production one) is a Contentful write: it needs an owner's go.
21
21
 
22
22
  ## The gate
23
23
 
24
+ **The develop-vs-production compare is on demand only.** The gate runs the exact-commit, noindex, draft-canary, full smoke, content smoke and sitemap slug-guard parity stages on every `vercel.deployment.ready` event. The compare against production (sitemap pages exist, and page text) does not run unless `--compare` (alias `--prod-compare`) is passed. Without it the stage prints exactly `compare: not run (on-demand)`, is recorded in `--json` as `{name: "prod compare", ok: null, skipped: true}`, and counts as neither a pass nor a fail (a skipped stage never fails the gate and never rescues a failed one). `--prod-url` is then not needed (it is still required with `--compare`, and with `--sitemap-roots`, which resolves its paths against production). A green default gate therefore does **not** include a prod compare; ask for one when you want it (below).
25
+
24
26
  ```bash
25
27
  develop-published-gate --url https://<project>-git-develop-published-<team>.vercel.app \
26
28
  --prod-url https://www.example.com --host-prefix <project>- \
27
- --deployment-sha <built sha> --expect-sha <promoted sha> --draft-canary /a-draft-only-path/
29
+ --deployment-sha <built sha> --expect-sha <promoted sha> --draft-canary /a-draft-only-path/ [--compare]
28
30
  ```
29
31
 
30
- Stages (exit 0 only if all pass): exact commit (built from the promoted SHA, or from an ancestor when every file changed since is in `vercel.json`'s `ignoreCommand` pathspec); noindex; draft canary 404s; full smoke; content smoke (cases with `contentAssert`); prod compare (every production sitemap page that is live (200) on production exists on the build; a page that is 404/410 on production too is a "prod sitemap lists dead URL" warning, not a failure; transient fetch errors are retried 3 times with backoff; and the visible text of up to 5 representative pages matches, similarity >= 0.9). `--sitemap-roots <paths>` (comma-separated or repeated, default none) limits the sitemap compare to the sitemap roots this app owns, e.g. `--sitemap-roots /marketing/sitemap.xml` when the production domain is shared with other apps; without it the full production sitemap index (`/sitemap.xml` and `/sitemap-unindexed.xml`) is compared. An index root is followed one level; an unreadable, nested-index or empty root fails the stage. `--json` writes the result. `--host-prefix` is required. The bypass token goes only to the deployment host, which must be `<host-prefix>*.vercel.app`, the gate's own requests follow redirects by hand so a redirect off that host never carries it, and in compare mode `site-check` sends the bypass to the deployment only, never to production. (`site-check` itself still follows redirects automatically, so a deployment that redirects a sitemap path to another host would carry the header there; the Vercel deployment hosts do not.) Noindex is read from `robots.txt` (disallow all) or the home page (`x-robots-tag` or meta robots).
32
+ **Running the compare on demand.** In the workflow template, `workflow_dispatch` has a boolean input `compare` (default false). The gate step passes `--compare` only when the run is a manual one with `compare` ticked (`COMPARE_FLAG` env); the `repository_dispatch` deployment.ready path never does. A manual run is never skipped by skip-if-green. It posts the same `develop-published gate` status context as the normal gate, with the description saying whether the compare ran (`... (prod compare not run, on-demand)` or `... and prod compare (manual) ...`), so the promote PR keeps reading one context. A manual compare that fails posts `failure`, and being newest it re-opens the gate; one that passes posts `success`. A manual compare run has its own concurrency group (`...-compare`), so a later deployment.ready event for the same SHA cannot cancel it. The job `timeout-minutes: 35` is the same for both kinds of run and stays above the compare's default 25 minute limit; a site that raises `--compare-timeout-minutes` (Pedestal and Headwater use 45) must raise the job timeout above it too (60).
33
+
34
+ **Sitemap parity does not depend on the compare.** The slug-guard parity stage fetches the build's own sitemap (`<deployment>/sitemap.xml`, plus `/sitemap-unindexed.xml` when served, or the `--sitemap-roots` rebased onto the deployment) with its own requests; it never reads the compare's output or the production sitemap, so it runs unchanged with the compare off.
35
+
36
+ Options for sites that differ from the default: `--no-draft-canary` skips the draft-canary stage (recorded as a passing, clearly labelled `SKIPPED` stage) for a site with no draft-only page; it is ignored when a `--draft-canary` is also given, and giving neither still fails the gate. `--compare-timeout-minutes <n>` (or the `GATE_COMPARE_TIMEOUT_MINUTES` env, used only when it is a finite positive number, so junk, zero, negative and `Infinity` count as unset; the flag wins and an `Infinity` flag is a usage error; the value is rounded to whole milliseconds) sets how long the spawned prod compare may run before it is killed; both apply only when `--compare` is given. The default is 25 minutes, which suits compares of up to about 20 minutes; give a slower site more (Pedestal, whose cold compare takes about 30 minutes, uses 45) and raise the job `timeout-minutes` above it.
37
+
38
+ Stages (exit 0 only if every stage that ran passes): exact commit (built from the promoted SHA, or from an ancestor when every file changed since is in `vercel.json`'s `ignoreCommand` pathspec); noindex; draft canary 404s; full smoke; content smoke (cases with `contentAssert`); prod compare, **only with `--compare`** (every production sitemap page that is live (200) on production exists on the build; a page that is 404/410 on production too is a "prod sitemap lists dead URL" warning, not a failure; transient fetch errors are retried 3 times with backoff; and the visible text of up to 5 representative pages matches, similarity >= 0.9). `--sitemap-roots <paths>` (comma-separated or repeated, default none) limits the sitemap compare to the sitemap roots this app owns, e.g. `--sitemap-roots /marketing/sitemap.xml` when the production domain is shared with other apps; without it the full production sitemap index (`/sitemap.xml` and `/sitemap-unindexed.xml`) is compared. An index root is followed one level; an unreadable, nested-index or empty root fails the stage. `--json` writes the result. `--host-prefix` is required. The bypass token goes only to the deployment host, which must be `<host-prefix>*.vercel.app`, the gate's own requests follow redirects by hand so a redirect off that host never carries it, and in compare mode `site-check` sends the bypass to the deployment only, never to production. (`site-check` itself still follows redirects automatically, so a deployment that redirects a sitemap path to another host would carry the header there; the Vercel deployment hosts do not.) **Sitemap slug guard parity** (a hard failure, not a warning): every path in the build's own sitemap (the `--sitemap-roots` rebased onto the deployment, else `/sitemap.xml` plus `/sitemap-unindexed.xml` when served) must pass core's `pathnameHasImpossibleCmsSlug` from `@se-studio/core-ui/impossible-cms-slug`, so the sitemap never advertises a path the app would 404; an unreadable build sitemap also fails. Noindex is read from `robots.txt` (disallow all) or the home page (`x-robots-tag` or meta robots).
31
39
 
32
40
  The workflow template runs this when Vercel reports a `develop-published` deployment ready and posts commit status `develop-published gate` on the promoted SHA, which a develop -> main promote PR shows (its head is develop's head).
33
41
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/site-check",
3
- "version": "2.22.1",
3
+ "version": "2.25.3",
4
4
  "description": "Validate SE marketing sites (sitemap, llms.txt) and download markdown files preserving structure",
5
5
  "repository": {
6
6
  "type": "git",
@@ -110,8 +110,9 @@
110
110
  "url": "https://github.com/Something-Else-Studio/se-core-product/issues"
111
111
  },
112
112
  "dependencies": {
113
- "@se-studio/contentful-rest-api": "2.9.2",
114
- "@se-studio/core-data-types": "2.2.0"
113
+ "@se-studio/contentful-rest-api": "2.9.3",
114
+ "@se-studio/core-data-types": "2.2.1",
115
+ "@se-studio/core-ui": "1.48.7"
115
116
  },
116
117
  "devDependencies": {
117
118
  "@biomejs/biome": "^2.6.8",
@@ -2,7 +2,9 @@
2
2
  # project name), __PROD_URL__ and __DRAFT_CANARY__ (a draft-only path), and check the integration branch.
3
3
  # If one repo gates several apps, copy the file per app and give each copy its own GATE_CONTEXT (e.g.
4
4
  # `develop-published gate (<project>)`) and workflow name; the skip-if-green check reads that context.
5
- # Promote gate: full smoke, content smoke and prod compare against the develop-published build.
5
+ # Promote gate: full smoke, content smoke, sitemap slug-guard parity and the draft canary against the
6
+ # develop-published build. The develop-vs-production compare is ON DEMAND ONLY: it never runs on a Vercel
7
+ # deployment.ready event, only on a manual run with the `compare` input ticked.
6
8
  # Runs when Vercel finishes a develop-published deployment, and on demand. Posts a commit status
7
9
  # `develop-published gate` on the exact commit, so a develop -> main promote PR (whose head is
8
10
  # develop's head) shows it.
@@ -26,6 +28,11 @@ on:
26
28
  description: Commit being promoted (default = deployment_sha)
27
29
  required: false
28
30
  type: string
31
+ compare:
32
+ description: Also run the full develop-vs-production compare (slow, on demand only)
33
+ required: false
34
+ type: boolean
35
+ default: false
29
36
 
30
37
  permissions:
31
38
  contents: read
@@ -33,9 +40,11 @@ permissions:
33
40
 
34
41
  # One gate run per commit. A develop-published SHA is normally built twice (the branch push and the deploy
35
42
  # hook), and each READY deployment sends its own vercel.deployment.ready event; the newer run cancels the
36
- # older one. Events the job would skip anyway get a unique group so they can never cancel a real run.
43
+ # older one. Events the job would skip anyway get a unique group so they can never cancel a real run. A
44
+ # manual compare run has its own group (suffix -compare), so a later deployment.ready event for the same
45
+ # SHA can never cancel a ~20 minute compare, and the compare never cancels the normal gate run.
37
46
  concurrency:
38
- group: develop-published-gate-${{ github.event_name == 'workflow_dispatch' && (inputs.promote_sha || inputs.deployment_sha) || (github.event.client_payload.project.name == '__PROJECT_NAME__' && github.event.client_payload.git.ref == 'develop-published' && github.event.client_payload.environment == 'preview' && github.event.client_payload.git.sha) || github.run_id }}
47
+ group: develop-published-gate-${{ github.event_name == 'workflow_dispatch' && format('{0}{1}', inputs.promote_sha || inputs.deployment_sha, inputs.compare == true && '-compare' || '') || (github.event.client_payload.project.name == '__PROJECT_NAME__' && github.event.client_payload.git.ref == 'develop-published' && github.event.client_payload.environment == 'preview' && github.event.client_payload.git.sha) || github.run_id }}
39
48
  cancel-in-progress: true
40
49
 
41
50
  jobs:
@@ -49,18 +58,24 @@ jobs:
49
58
  github.event.client_payload.environment == 'preview'
50
59
  )
51
60
  runs-on: ubuntu-latest
52
- # A healthy prod compare of a large sitemap takes about 20 minutes; this only stops a hung run. A
53
- # timed-out job counts as cancelled, so it posts no status (the promote PR shows none, not green).
61
+ # A healthy prod compare of a large sitemap takes about 20 minutes (only on a manual run with compare
62
+ # on; the default gate takes a few minutes); this only stops a hung run. Kept at 35 for both so it stays
63
+ # above the compare's default 25 minute kill limit. If you give the compare a longer limit with
64
+ # --compare-timeout-minutes (for example 45), raise this above it (60). A timed-out job counts as
65
+ # cancelled, so it posts no status (the promote PR shows none, not green).
54
66
  timeout-minutes: 35
55
67
  env:
56
68
  GATE_CONTEXT: develop-published gate
57
69
  DEPLOYMENT_URL: ${{ github.event_name == 'workflow_dispatch' && inputs.deployment_url || github.event.client_payload.url }}
58
70
  DEPLOYMENT_SHA: ${{ github.event_name == 'workflow_dispatch' && inputs.deployment_sha || github.event.client_payload.git.sha }}
59
71
  PROMOTE_SHA: ${{ github.event_name == 'workflow_dispatch' && (inputs.promote_sha || inputs.deployment_sha) || github.event.client_payload.git.sha }}
72
+ # `--compare` only for a manual run that ticked `compare`. The deployment.ready path never gets it.
73
+ COMPARE_FLAG: ${{ github.event_name == 'workflow_dispatch' && inputs.compare == true && '--compare' || '' }}
60
74
  steps:
61
75
  # A third deploy of a SHA that already passed must not run the gate again. Only a `success` status
62
76
  # skips: failure, error, pending or no status runs the gate, and so does an API error. The newest
63
- # status for the context wins, so a later failure re-opens the gate. Manual runs always run.
77
+ # status for the context wins, so a later failure re-opens the gate. Manual runs always run, so a
78
+ # manual compare is never skipped because the default gate is already green.
64
79
  - name: Skip when this commit already has a green gate status
65
80
  id: already
66
81
  if: github.event_name == 'repository_dispatch'
@@ -102,12 +117,13 @@ jobs:
102
117
  --deployment-sha "$DEPLOYMENT_SHA" \
103
118
  --expect-sha "$PROMOTE_SHA" \
104
119
  --draft-canary "__DRAFT_CANARY__" \
120
+ $COMPARE_FLAG \
105
121
  --json gate-result.json
106
122
  - name: Gate summary
107
123
  if: always() && steps.already.outputs.skip != 'true'
108
124
  run: |
109
125
  if [ -f gate-result.json ]; then
110
- node -e 'const r=require("./gate-result.json");console.log("## develop-published gate: "+(r.ok?"PASS":"FAIL")+"\n");for(const s of r.stages)console.log("- "+(s.ok?"PASS":"FAIL")+" "+s.name+": "+s.detail)' >> "$GITHUB_STEP_SUMMARY"
126
+ node -e 'const r=require("./gate-result.json");console.log("## develop-published gate: "+(r.ok?"PASS":"FAIL")+"\n");for(const s of r.stages)console.log("- "+(s.skipped?"SKIP":s.ok?"PASS":"FAIL")+" "+s.name+": "+s.detail)' >> "$GITHUB_STEP_SUMMARY"
111
127
  fi
112
128
  - uses: actions/upload-artifact@v7
113
129
  if: always() && steps.already.outputs.skip != 'true'
@@ -120,10 +136,14 @@ jobs:
120
136
  env:
121
137
  GH_TOKEN: ${{ github.token }}
122
138
  STATE: ${{ job.status == 'success' && 'success' || 'failure' }}
139
+ # Same context for both kinds of run (the promote PR and the skip-if-green check read one context).
140
+ # The description says whether the compare ran. A manual compare that fails posts `failure`, and
141
+ # that newest status re-opens the gate; one that passes posts `success` with the compare noted.
142
+ DESCRIPTION: ${{ env.COMPARE_FLAG != '' && 'Smoke, content smoke, slug parity and prod compare (manual) on the develop-published build' || 'Smoke, content smoke and slug parity on the develop-published build (prod compare not run, on-demand)' }}
123
143
  run: |
124
144
  # On the promoted commit (the promote PR head). Same SHA as the build unless Vercel skipped it.
125
145
  gh api "repos/${GITHUB_REPOSITORY}/statuses/${PROMOTE_SHA}" \
126
146
  -f state="$STATE" \
127
147
  -f context="$GATE_CONTEXT" \
128
- -f description="Smoke, content smoke and prod compare on the develop-published build" \
148
+ -f description="$DESCRIPTION" \
129
149
  -f target_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"