@se-studio/site-check 2.15.1 → 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 +19 -0
- package/README.md +17 -1
- package/check-comments.mjs +196 -0
- package/docs/llms.md +6 -0
- package/package.json +7 -4
- package/scripts/smoke-env.mjs +73 -0
- package/smoke-test-deploy-check.mjs +2 -0
- package/smoke-test-one.mjs +16 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
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
|
+
|
|
9
|
+
## 2.16.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- e39fed8: Add the `check-comments` bin (lifted from HopSkipDrive's `scripts/check-comments.mjs`). It fails on stray comments in `src/**/*.ts(x)` (narration, banners, commented-out code, docs on non-exported symbols), skipping `src/generated/`. Default is a whole-tree scan; `--diff` checks only lines added since the merge base with `origin/develop` (or `$COMMENT_BASE`) and, in CI, fails with a `fetch-depth: 0` hint when the base is missing. Allowed: `biome-ignore`, `@ts-expect-error`, `@ts-ignore`, `se-exception:`, `why-external:`, licence headers, a comment with an http(s) link, `/// <reference`, and a `/**` doc block directly above an `export`. Customer sites opt in with `pnpm exec check-comments`; nothing runs it for them.
|
|
14
|
+
|
|
15
|
+
A `/*` inside a `//` line comment (for example `// rewrite /api/*`) no longer opens a block comment, so the code lines after it are not swallowed.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [850c4f7]
|
|
20
|
+
- @se-studio/contentful-rest-api@2.8.0
|
|
21
|
+
|
|
3
22
|
## 2.15.1
|
|
4
23
|
|
|
5
24
|
### Patch 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`) |
|
|
@@ -405,6 +406,21 @@ color: #111; /* se-exception: print stylesheet, no CMS colour */
|
|
|
405
406
|
|
|
406
407
|
The reason after `se-exception:` is required. A comment with no reason still fails.
|
|
407
408
|
|
|
409
|
+
## Comment lint (`check-comments`)
|
|
410
|
+
|
|
411
|
+
Fails when `src/**/*.ts(x)` holds a stray comment (narration, banners, commented-out code, docs on non-exported symbols or interface members). `src/generated/` is skipped. Not part of customer CI until a site opts in.
|
|
412
|
+
|
|
413
|
+
Run it from the **app root**:
|
|
414
|
+
|
|
415
|
+
```bash
|
|
416
|
+
pnpm exec check-comments # whole tree: every line of every file
|
|
417
|
+
pnpm exec check-comments --diff # only lines added since the merge base with origin/develop (or $COMMENT_BASE)
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
Allowed: `biome-ignore`, `@ts-expect-error`, `@ts-ignore`; `se-exception: <reason>`; `why-external: <system and constraint>`; licence headers (`@license`, `Copyright`, `SPDX-License`, `@generated`); a comment that carries an http(s) link; `/// <reference`; and a `/**` doc block directly above an `export`.
|
|
421
|
+
|
|
422
|
+
`--diff` needs the base ref. Locally a missing base prints a warning and skips; with `CI` set it fails, so check out with `fetch-depth: 0` (or `git fetch origin develop`).
|
|
423
|
+
|
|
408
424
|
## Exit codes
|
|
409
425
|
|
|
410
426
|
- `0` — Validation passed (sitemap.xml required; llms.txt and sitemap-unindexed.xml optional). If `--check-rewrites` was set, no unexpected rewrites. Every sitemap page returned 200 for its `.md` URL and files were saved (or in compare mode: all production sitemap pages exist on development and, if `--check-rewrites`, no unexpected rewrites).
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Guard: no stray comments in src/**\/*.ts(x). By default every line of every tracked
|
|
8
|
+
* (and untracked) file is checked, so the whole tree stays clean. `--diff` checks only
|
|
9
|
+
* lines added since the merge base with origin/develop (or $COMMENT_BASE).
|
|
10
|
+
*
|
|
11
|
+
* Allowed:
|
|
12
|
+
* - biome-ignore, @ts-expect-error, @ts-ignore (their reasons are checked elsewhere)
|
|
13
|
+
* - `se-exception: <reason>` and `why-external: <system and constraint>`
|
|
14
|
+
* - licence headers (@license, Copyright, SPDX)
|
|
15
|
+
* - a comment that carries an http(s) link to an issue or RFC
|
|
16
|
+
* - a /** doc block directly above an exported declaration
|
|
17
|
+
* Everything else (narration, banners, commented-out code, sermons) is removed or replaced
|
|
18
|
+
* by a better name, type or structure.
|
|
19
|
+
*
|
|
20
|
+
* Run from the app root: pnpm exec check-comments [--diff]
|
|
21
|
+
* `--diff` needs the base ref: in CI use `fetch-depth: 0`.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const SCOPE = /^src\/.*\.tsx?$/;
|
|
25
|
+
const SKIP = /^src\/generated\//;
|
|
26
|
+
const ALLOWED = [
|
|
27
|
+
/biome-ignore/,
|
|
28
|
+
/@ts-expect-error/,
|
|
29
|
+
/@ts-ignore/,
|
|
30
|
+
/se-exception:\s*\S/,
|
|
31
|
+
/why-external:\s*\S/,
|
|
32
|
+
/@license|Copyright|SPDX-License|@generated/,
|
|
33
|
+
/https?:\/\/\S+/,
|
|
34
|
+
/^\s*\/\/\/\s*<reference/,
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const stripStrings = (l) =>
|
|
38
|
+
l.replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*`/g, '""');
|
|
39
|
+
const stripJsxText = (l) => l.replace(/>[^<>{}]+</g, '><');
|
|
40
|
+
|
|
41
|
+
/** Which lines are comment lines, tracking block comments and template literals across lines. */
|
|
42
|
+
export function commentLines(lines) {
|
|
43
|
+
const flags = [];
|
|
44
|
+
let inBlock = false;
|
|
45
|
+
let inTemplate = false;
|
|
46
|
+
for (const line of lines) {
|
|
47
|
+
if (inBlock) {
|
|
48
|
+
flags.push(true);
|
|
49
|
+
if (line.includes('*/')) inBlock = false;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (inTemplate) {
|
|
53
|
+
flags.push(false);
|
|
54
|
+
if ((line.match(/(?<!\\)`/g) ?? []).length % 2 === 1) inTemplate = false;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const code = stripJsxText(stripStrings(line));
|
|
58
|
+
const lineStart = code.search(/(?:^|[\s;,{}()\]])\/\/\s/);
|
|
59
|
+
const rawOpen = code.indexOf('/*');
|
|
60
|
+
const open = lineStart !== -1 && lineStart < rawOpen ? -1 : rawOpen;
|
|
61
|
+
const comment =
|
|
62
|
+
/^\s*\/\//.test(code) ||
|
|
63
|
+
open !== -1 ||
|
|
64
|
+
lineStart !== -1 ||
|
|
65
|
+
/(?<=[;,{}()\]])\s*\/\/\s/.test(code);
|
|
66
|
+
if (open !== -1 && !code.includes('*/', open + 2)) inBlock = true;
|
|
67
|
+
if ((stripStrings(line).match(/(?<!\\)`/g) ?? []).length % 2 === 1) inTemplate = true;
|
|
68
|
+
flags.push(comment);
|
|
69
|
+
}
|
|
70
|
+
return flags;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Group consecutive added comment lines so a doc block is judged as a whole. */
|
|
74
|
+
export function findViolations(file, lines, added) {
|
|
75
|
+
const out = [];
|
|
76
|
+
const flags = commentLines(lines);
|
|
77
|
+
let i = 0;
|
|
78
|
+
while (i < lines.length) {
|
|
79
|
+
if (!added.has(i + 1) || !flags[i]) {
|
|
80
|
+
i++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
let end = i;
|
|
84
|
+
while (end + 1 < lines.length && added.has(end + 2) && flags[end + 1]) end++;
|
|
85
|
+
const block = lines.slice(i, end + 1);
|
|
86
|
+
const allowed = block.some((l) => ALLOWED.some((re) => re.test(l)));
|
|
87
|
+
const next = lines.slice(end + 1).find((l) => l.trim() !== '') ?? '';
|
|
88
|
+
const doc = /^\s*\/\*\*/.test(block[0]) && /^\s*export\s/.test(next);
|
|
89
|
+
if (!allowed && !doc) out.push(`${file}:${i + 1} ${block[0].trim().slice(0, 100)}`);
|
|
90
|
+
i = end + 1;
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const git = (...args) =>
|
|
96
|
+
execFileSync('git', args, { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
|
|
97
|
+
|
|
98
|
+
function addedLines(base, file) {
|
|
99
|
+
const added = new Set();
|
|
100
|
+
const diff = git('diff', '-U0', '--no-color', base, '--', file);
|
|
101
|
+
for (const m of diff.matchAll(/^@@ -\S+ \+(\d+)(?:,(\d+))? @@/gm)) {
|
|
102
|
+
const start = Number(m[1]);
|
|
103
|
+
const count = m[2] === undefined ? 1 : Number(m[2]);
|
|
104
|
+
for (let n = start; n < start + count; n++) added.add(n);
|
|
105
|
+
}
|
|
106
|
+
return added;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Every line of the file counts as added, so the whole file is checked. */
|
|
110
|
+
export function checkWholeFile(file, text) {
|
|
111
|
+
const lines = text.split('\n');
|
|
112
|
+
return findViolations(file, lines, new Set(lines.map((_, i) => i + 1)));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function inScope(file) {
|
|
116
|
+
return SCOPE.test(file) && !SKIP.test(file);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function wholeTreeViolations() {
|
|
120
|
+
const tracked = git('ls-files', 'src').split('\n').filter(Boolean);
|
|
121
|
+
const untracked = git('ls-files', '--others', '--exclude-standard').split('\n').filter(Boolean);
|
|
122
|
+
const violations = [];
|
|
123
|
+
for (const file of new Set([...tracked, ...untracked])) {
|
|
124
|
+
if (!inScope(file)) continue;
|
|
125
|
+
let text;
|
|
126
|
+
try {
|
|
127
|
+
text = readFileSync(file, 'utf8');
|
|
128
|
+
} catch {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
violations.push(...checkWholeFile(file, text));
|
|
132
|
+
}
|
|
133
|
+
return violations;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function diffViolations() {
|
|
137
|
+
const baseRef = process.env.COMMENT_BASE ?? 'origin/develop';
|
|
138
|
+
let base;
|
|
139
|
+
try {
|
|
140
|
+
base = git('merge-base', 'HEAD', baseRef).trim();
|
|
141
|
+
} catch {
|
|
142
|
+
const msg = `check-comments: cannot find ${baseRef}. Run git fetch origin develop (CI needs fetch-depth: 0).`;
|
|
143
|
+
if (process.env.CI) {
|
|
144
|
+
console.error(msg);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
console.warn(`${msg} Skipping.`);
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
const changed = git('diff', '--name-only', base).split('\n').filter(Boolean);
|
|
151
|
+
const untracked = git('ls-files', '--others', '--exclude-standard').split('\n').filter(Boolean);
|
|
152
|
+
const violations = [];
|
|
153
|
+
for (const file of new Set([...changed, ...untracked])) {
|
|
154
|
+
if (!inScope(file)) continue;
|
|
155
|
+
let text;
|
|
156
|
+
try {
|
|
157
|
+
text = readFileSync(file, 'utf8');
|
|
158
|
+
} catch {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const lines = text.split('\n');
|
|
162
|
+
const added = untracked.includes(file)
|
|
163
|
+
? new Set(lines.map((_, i) => i + 1))
|
|
164
|
+
: addedLines(base, file);
|
|
165
|
+
violations.push(...findViolations(file, lines, added));
|
|
166
|
+
}
|
|
167
|
+
return violations;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function main() {
|
|
171
|
+
const diffMode = process.argv.includes('--diff');
|
|
172
|
+
const violations = diffMode ? diffViolations() : wholeTreeViolations();
|
|
173
|
+
if (violations.length > 0) {
|
|
174
|
+
console.error('check-comments: comments are not allowed in src.\n');
|
|
175
|
+
for (const v of violations) console.error(` ${v}`);
|
|
176
|
+
console.error(
|
|
177
|
+
`\n${violations.length} comment(s). Delete it, or make the code say it (a name, a type, a smaller function). ` +
|
|
178
|
+
'Keep only: a link to an issue/RFC, `why-external: <system>` for a constraint we cannot reshape, ' +
|
|
179
|
+
'`se-exception: <reason>`, or a /** doc block above an export.',
|
|
180
|
+
);
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
console.log(`check-comments: ok (${diffMode ? 'diff' : 'whole tree'})`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function isDirectRun() {
|
|
187
|
+
const entry = process.argv[1];
|
|
188
|
+
if (!entry) return false;
|
|
189
|
+
try {
|
|
190
|
+
return realpathSync(entry) === realpathSync(fileURLToPath(import.meta.url));
|
|
191
|
+
} catch {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (isDirectRun()) main();
|
package/docs/llms.md
CHANGED
|
@@ -132,6 +132,12 @@ R1 (literal chrome colours) runs only when that file has an `r1` object: `chrome
|
|
|
132
132
|
|
|
133
133
|
Escape hatch on the same line: `// se-exception: <reason>` or `/* se-exception: <reason> */`. The reason is required.
|
|
134
134
|
|
|
135
|
+
### check-comments
|
|
136
|
+
|
|
137
|
+
Bin: `check-comments`. Run from the app root: `pnpm exec check-comments` (whole tree of `src/**/*.ts(x)`, skipping `src/generated/`) or `check-comments --diff` (lines added since the merge base with `origin/develop`, or `$COMMENT_BASE`). **Customer sites do not run this in CI until they opt in.**
|
|
138
|
+
|
|
139
|
+
Allowed: `biome-ignore`, `@ts-expect-error`, `@ts-ignore`, `se-exception: <reason>`, `why-external: <system and constraint>`, licence headers (`@license`, `Copyright`, `SPDX-License`, `@generated`), a comment with an http(s) link, `/// <reference`, and a `/**` doc block directly above an `export`. Everything else is a violation. A missing `--diff` base fails in CI (`fetch-depth: 0` needed) and is skipped locally.
|
|
140
|
+
|
|
135
141
|
### check-no-context-workarounds
|
|
136
142
|
|
|
137
143
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@se-studio/site-check",
|
|
3
|
-
"version": "2.
|
|
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",
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"markdown-accuracy-audit": "./markdown-accuracy-audit.mjs",
|
|
59
59
|
"check-no-context-workarounds": "./check-no-context-workarounds.mjs",
|
|
60
60
|
"check-publish-state": "./check-publish-state.mjs",
|
|
61
|
-
"check-cms-driven": "./check-cms-driven.mjs"
|
|
61
|
+
"check-cms-driven": "./check-cms-driven.mjs",
|
|
62
|
+
"check-comments": "./check-comments.mjs"
|
|
62
63
|
},
|
|
63
64
|
"files": [
|
|
64
65
|
"dist",
|
|
@@ -67,6 +68,7 @@
|
|
|
67
68
|
"templates",
|
|
68
69
|
"*.md",
|
|
69
70
|
"smoke-test-one.mjs",
|
|
71
|
+
"scripts/smoke-env.mjs",
|
|
70
72
|
"smoke-test-deploy-check.mjs",
|
|
71
73
|
"smoke-test-live.mjs",
|
|
72
74
|
"validate-build-routes.mjs",
|
|
@@ -76,6 +78,7 @@
|
|
|
76
78
|
"check-no-context-workarounds.mjs",
|
|
77
79
|
"check-publish-state.mjs",
|
|
78
80
|
"check-cms-driven.mjs",
|
|
81
|
+
"check-comments.mjs",
|
|
79
82
|
"cms-driven-baseline.mjs",
|
|
80
83
|
"screaming-frog"
|
|
81
84
|
],
|
|
@@ -95,7 +98,7 @@
|
|
|
95
98
|
"url": "https://github.com/Something-Else-Studio/se-core-product/issues"
|
|
96
99
|
},
|
|
97
100
|
"dependencies": {
|
|
98
|
-
"@se-studio/contentful-rest-api": "2.
|
|
101
|
+
"@se-studio/contentful-rest-api": "2.8.0",
|
|
99
102
|
"@se-studio/core-data-types": "2.0.5"
|
|
100
103
|
},
|
|
101
104
|
"devDependencies": {
|
|
@@ -109,6 +112,6 @@
|
|
|
109
112
|
"type-check": "tsc --noEmit",
|
|
110
113
|
"lint": "biome lint .",
|
|
111
114
|
"clean": "rm -rf dist .turbo *.tsbuildinfo",
|
|
112
|
-
"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/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs scripts/publish-state.test.mjs"
|
|
115
|
+
"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/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs scripts/publish-state.test.mjs"
|
|
113
116
|
}
|
|
114
117
|
}
|
|
@@ -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
|
};
|
package/smoke-test-one.mjs
CHANGED
|
@@ -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
|
|
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
|
|