@se-studio/site-check 2.16.0 → 2.16.1

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.16.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 32ef4b1: Fix local `smoke-test-one` failing `llms.txt` / `markdown-index.txt` discovery checks with `discovery_invalid_content`. Those prerendered routes bake the app's `URL` (often `http://localhost:3000` from `.env.local`) while smoke validates against the app port. `smoke-test-one` now forces `URL=http://localhost:<port>` (over `process.env` and `.env.local`) for the build and server it starts. With `SMOKE_TEST_SKIP_BUILD=true` it now refuses to run when `.next` is missing or its prerendered discovery files were baked with a different origin, naming the expected and found origins and telling you to rerun without `SMOKE_TEST_SKIP_BUILD`. `smoke-test-deploy-check` (Vercel post-build) sets `SMOKE_TEST_PRESERVE_URL=true` and is unchanged. Customer `.env.example` files may note that local smoke overrides `URL` to the app port.
8
+
3
9
  ## 2.16.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -148,7 +148,8 @@ Add `smoke.cases.json`, `scripts/smoke-test-run.ts`, and optionally `scripts/smo
148
148
  | Variable | Purpose |
149
149
  |----------|---------|
150
150
  | `SMOKE_TEST_SERVER_SCRIPT=dev:dev` | Default dev server; use `start:dev` for prod-like `next start` (runs `pnpm build` first; not portless) |
151
- | `SMOKE_TEST_SKIP_BUILD=true` | Skip `pnpm build` when `SERVER_SCRIPT=start:dev` (use after Vercel `next build`) |
151
+ | `SMOKE_TEST_SKIP_BUILD=true` | Skip `pnpm build` when `SERVER_SCRIPT=start:dev` (use after Vercel `next build`). Fails if `.next` is missing or was baked with an origin other than `http://localhost:<port>`; rerun without it to rebuild |
152
+ | `SMOKE_TEST_PRESERVE_URL=true` | Keep `URL` from env/`.env.local` and skip the skip-build origin guard (set by `smoke-test-deploy-check`). By default local smoke overrides `URL` to `http://localhost:<port>` so prerendered `llms.txt` / `markdown-index.txt` match the validator |
152
153
  | `SMOKE_TEST_VERIFY_CACHE=true` | Run smoke twice; assert `x-nextjs-cache` on HTML (meaningful with `start:dev`, soft in `next dev`) |
153
154
  | `SMOKE_TEST_AUDIT_CACHE_LOGS=true` | Pipe server/build logs and scan for 2MB cache failures, `cache skip`, and `hard refresh` |
154
155
  | `SMOKE_TEST_CACHE_SKIP_SEVERITY=warn` | `warn` or `error` for cache-skip log lines (default `warn`) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/site-check",
3
- "version": "2.16.0",
3
+ "version": "2.16.1",
4
4
  "description": "Validate SE marketing sites (sitemap, llms.txt) and download markdown files preserving structure",
5
5
  "repository": {
6
6
  "type": "git",
@@ -68,6 +68,7 @@
68
68
  "templates",
69
69
  "*.md",
70
70
  "smoke-test-one.mjs",
71
+ "scripts/smoke-env.mjs",
71
72
  "smoke-test-deploy-check.mjs",
72
73
  "smoke-test-live.mjs",
73
74
  "validate-build-routes.mjs",
@@ -0,0 +1,73 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ const BAKED_PAYLOADS = ['llms.txt.body', 'markdown-index.txt.body'];
5
+
6
+ export function smokeBaseUrl(port) {
7
+ return `http://localhost:${port}`;
8
+ }
9
+
10
+ /** Set by smoke-test-deploy-check: the build used the real deployment URL, so keep it. */
11
+ export function shouldPreserveUrl(env) {
12
+ return (env.SMOKE_TEST_PRESERVE_URL ?? '').toLowerCase() === 'true';
13
+ }
14
+
15
+ /** `URL` is forced to the smoke port so prerendered discovery files match the validator's origin. */
16
+ export function applySmokeEnv(processEnv, envLocal, port) {
17
+ const merged = { ...processEnv, ...envLocal, PORT: String(port) };
18
+ if (shouldPreserveUrl(merged)) return merged;
19
+ return { ...merged, URL: smokeBaseUrl(port) };
20
+ }
21
+
22
+ function originsIn(text) {
23
+ const origins = new Set();
24
+ for (const match of text.matchAll(/https?:\/\/[^\s/"'<>)\]]+/g)) {
25
+ origins.add(match[0].toLowerCase());
26
+ }
27
+ return origins;
28
+ }
29
+
30
+ /**
31
+ * Check that an existing `.next` build baked the expected origin into its
32
+ * prerendered discovery payloads. Never returns ok when detection fails.
33
+ * @returns {{ ok: boolean, found: string[], message?: string }}
34
+ */
35
+ export function checkExistingBuildOrigin(appDir, expectedOrigin) {
36
+ const nextDir = path.join(appDir, '.next');
37
+ const rerun = 'Rerun without SMOKE_TEST_SKIP_BUILD so the app rebuilds with the smoke-port URL.';
38
+ if (!fs.existsSync(nextDir)) {
39
+ return {
40
+ ok: false,
41
+ found: [],
42
+ message: `SMOKE_TEST_SKIP_BUILD is set but ${nextDir} does not exist. ${rerun}`,
43
+ };
44
+ }
45
+
46
+ const found = new Set();
47
+ let payloads = 0;
48
+ for (const name of BAKED_PAYLOADS) {
49
+ const file = path.join(nextDir, 'server', 'app', name);
50
+ if (!fs.existsSync(file)) continue;
51
+ payloads += 1;
52
+ for (const origin of originsIn(fs.readFileSync(file, 'utf8'))) found.add(origin);
53
+ }
54
+
55
+ const list = [...found];
56
+ if (payloads === 0 || list.length === 0) {
57
+ return {
58
+ ok: false,
59
+ found: list,
60
+ message: `Cannot detect the origin baked into the existing build (no prerendered llms.txt / markdown-index.txt origins under ${nextDir}/server/app). Expected ${expectedOrigin}. ${rerun}`,
61
+ };
62
+ }
63
+
64
+ const wrongLocal = list.filter((o) => /^https?:\/\/(localhost|127\.0\.0\.1)(:|$)/.test(o) && o !== expectedOrigin);
65
+ if (!found.has(expectedOrigin) || wrongLocal.length > 0) {
66
+ return {
67
+ ok: false,
68
+ found: list,
69
+ message: `Existing build was produced with a different origin. Expected ${expectedOrigin}; found ${list.join(', ')}. ${rerun}`,
70
+ };
71
+ }
72
+ return { ok: true, found: list };
73
+ }
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * Env (set automatically; override if needed):
8
8
  * SMOKE_TEST_SKIP_BUILD=true
9
+ * SMOKE_TEST_PRESERVE_URL=true — build used the real deployment URL; do not override URL or guard origin
9
10
  * SMOKE_TEST_USE_RUNNING_SERVER=false
10
11
  * SMOKE_TEST_SERVER_SCRIPT=start:dev
11
12
  * SMOKE_TEST_IGNORE=true — skip entirely (emergency bypass on Vercel)
@@ -50,6 +51,7 @@ const smokeTestOnePath = path.join(packageDir, 'smoke-test-one.mjs');
50
51
  const env = {
51
52
  ...process.env,
52
53
  SMOKE_TEST_SKIP_BUILD: 'true',
54
+ SMOKE_TEST_PRESERVE_URL: 'true',
53
55
  SMOKE_TEST_USE_RUNNING_SERVER: 'false',
54
56
  SMOKE_TEST_SERVER_SCRIPT: 'start:dev',
55
57
  };
@@ -12,7 +12,9 @@
12
12
  * SMOKE_TEST_CACHE_SKIP_SEVERITY=warn — cache-skip log severity: warn | error (default warn)
13
13
  * SMOKE_TEST_READY_PATH=/ — path polled until server responds
14
14
  * SMOKE_TEST_USE_RUNNING_SERVER=true — reuse server already on port (default true)
15
- * SMOKE_TEST_SKIP_BUILD=true — skip pnpm build when SERVER_SCRIPT is start:dev (post-build deploy check)
15
+ * SMOKE_TEST_SKIP_BUILD=true — skip pnpm build when SERVER_SCRIPT is start:dev (post-build deploy check); fails unless the existing .next baked URL=http://localhost:<port>
16
+ * SMOKE_TEST_PRESERVE_URL=true — keep .env.local/process URL and skip the origin guard (set by smoke-test-deploy-check)
17
+ * (URL is otherwise always overridden to http://localhost:<port> for local smoke)
16
18
  * SMOKE_TEST_VALIDATE_ROUTES=false — skip route-build-policy.json check after build (default on when file exists)
17
19
  * SMOKE_TEST_VALIDATE_ANALYTICS_CONTEXT=false — skip dual AnalyticsProvider chunk scan (default on when .next/static/chunks exists)
18
20
  * SMOKE_TEST_SKIP_INTEGRITY=true — HTTP smoke only (set by smoke-test-one when cmsIntegrity runs in parallel)
@@ -24,6 +26,11 @@ import fs from 'node:fs';
24
26
  import net from 'node:net';
25
27
  import path from 'node:path';
26
28
  import { fileURLToPath } from 'node:url';
29
+ import {
30
+ applySmokeEnv,
31
+ checkExistingBuildOrigin,
32
+ shouldPreserveUrl,
33
+ } from './scripts/smoke-env.mjs';
27
34
 
28
35
  const packageDir = path.dirname(fileURLToPath(import.meta.url));
29
36
 
@@ -66,7 +73,7 @@ function parseEnvFile(filePath) {
66
73
 
67
74
  function loadEnv() {
68
75
  const envLocal = parseEnvFile(path.join(appDir, '.env.local'));
69
- return { ...process.env, ...envLocal, PORT: port };
76
+ return applySmokeEnv(process.env, envLocal, port);
70
77
  }
71
78
 
72
79
  function sleep(ms) {
@@ -333,6 +340,13 @@ if (isProductionStart && !skipBuild) {
333
340
 
334
341
  // Post-build deploy-check: build already ran; still scan existing .next chunks.
335
342
  if (isProductionStart && skipBuild) {
343
+ const originCheck = shouldPreserveUrl(env)
344
+ ? { ok: true }
345
+ : checkExistingBuildOrigin(appDir, baseUrl);
346
+ if (!originCheck.ok) {
347
+ console.error(originCheck.message);
348
+ process.exit(1);
349
+ }
336
350
  await runAnalyticsContextBundleCheck(appDir, env);
337
351
  }
338
352