@se-studio/site-check 2.8.7 → 2.8.8

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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.8.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @se-studio/contentful-rest-api@1.14.6
9
+
3
10
  ## 2.8.7
4
11
 
5
12
  ### Patch Changes
@@ -0,0 +1,432 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Production markdown accuracy audit collector.
5
+ *
6
+ * Fetches HTML + .md for smoke-test URLs across client sites, records metrics,
7
+ * and writes full artifact files for LLM review (no content truncation).
8
+ *
9
+ * Usage (from monorepo root):
10
+ * node packages/site-check/markdown-accuracy-audit.mjs
11
+ * node packages/site-check/markdown-accuracy-audit.mjs --site se2026 --path /about/ --dry-run
12
+ *
13
+ * Options:
14
+ * --site <key> Run one site (se2026, om1, brightline, …)
15
+ * --path <path> Single smoke path (e.g. /about/)
16
+ * --dry-run Collect one case only; print artifact paths to stdout
17
+ * --delay-ms <n> Pause between URL pairs (default 500)
18
+ * --artifacts-dir <dir> Artifact root (default: docs/reports/.markdown-audit-artifacts)
19
+ * --source-root <path> Client repos root (default: ~/source or SE_SOURCE_ROOT)
20
+ * -h, --help Show help
21
+ */
22
+
23
+ import fs from 'node:fs';
24
+ import path from 'node:path';
25
+ import { fileURLToPath } from 'node:url';
26
+
27
+ import { htmlUrlToMarkdownUrl } from './dist/production-audit/index.js';
28
+ import { expandHome, joinBaseUrl, SITE_DEFINITIONS } from './develop-sites-timing.mjs';
29
+
30
+ const USER_AGENT = 'SEMarkdownAccuracyAudit/1.0';
31
+ const DEFAULT_DELAY_MS = 500;
32
+ const FETCH_TIMEOUT_MS = 45_000;
33
+
34
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
35
+ const MONOREPO_ROOT = path.resolve(__dirname, '../..');
36
+ const DEFAULT_ARTIFACTS_DIR = path.join(MONOREPO_ROOT, 'docs/reports/.markdown-audit-artifacts');
37
+
38
+ /**
39
+ * @typedef {object} MarkdownSmokeCase
40
+ * @property {string} category
41
+ * @property {string} label
42
+ * @property {string} path
43
+ */
44
+
45
+ /**
46
+ * @typedef {object} FetchMetrics
47
+ * @property {number} status
48
+ * @property {number} size
49
+ * @property {number} responseMs
50
+ * @property {string | null} nextjsCache
51
+ * @property {string | null} vercelCache
52
+ * @property {string | null} error
53
+ */
54
+
55
+ /**
56
+ * @typedef {object} CollectorCliOptions
57
+ * @property {string | undefined} siteKey
58
+ * @property {string | undefined} casePath
59
+ * @property {boolean} dryRun
60
+ * @property {number} delayMs
61
+ * @property {string} artifactsDir
62
+ * @property {string} sourceRoot
63
+ */
64
+
65
+ /**
66
+ * Remove only script and style blocks from HTML. Does not strip tags or truncate.
67
+ *
68
+ * @param {string} html
69
+ * @returns {string}
70
+ */
71
+ export function stripScriptAndStyle(html) {
72
+ return html
73
+ .replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, '')
74
+ .replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, '');
75
+ }
76
+
77
+ /**
78
+ * @param {string} routePath
79
+ * @returns {string}
80
+ */
81
+ export function pathToArtifactSlug(routePath) {
82
+ const normalized = routePath.replace(/\/+$/, '') || '/';
83
+ if (normalized === '/') return 'home';
84
+ const segments = normalized.split('/').filter(Boolean);
85
+ const last = segments.at(-1) ?? 'page';
86
+ const parent = segments.length > 1 ? segments.at(-2) : undefined;
87
+ if (parent && segments.length >= 2) {
88
+ return `${parent}--${last}`;
89
+ }
90
+ return last;
91
+ }
92
+
93
+ /**
94
+ * @param {string} smokePath
95
+ * @returns {MarkdownSmokeCase[]}
96
+ */
97
+ export function loadMarkdownSmokeCases(smokePath) {
98
+ const raw = JSON.parse(fs.readFileSync(smokePath, 'utf8'));
99
+ return raw.cases
100
+ .filter((entry) => entry.expectMarkdown !== false && entry.expectHtmlStatus !== 404)
101
+ .map((entry) => ({
102
+ category: entry.category ?? 'unknown',
103
+ label: entry.label ?? entry.path,
104
+ path: entry.path,
105
+ }));
106
+ }
107
+
108
+ /**
109
+ * @param {CollectorCliOptions} options
110
+ */
111
+ export function resolveMarkdownAuditSites(options) {
112
+ const sourceRoot = expandHome(options.sourceRoot);
113
+ let sites = SITE_DEFINITIONS;
114
+
115
+ if (options.siteKey) {
116
+ sites = sites.filter((site) => site.key === options.siteKey);
117
+ if (sites.length === 0) {
118
+ throw new Error(
119
+ `Unknown site key "${options.siteKey}". Valid keys: ${SITE_DEFINITIONS.map((s) => s.key).join(', ')}`,
120
+ );
121
+ }
122
+ }
123
+
124
+ return sites.map((site) => {
125
+ const repoPath = path.join(sourceRoot, site.repoDir);
126
+ const smokePath = path.join(repoPath, 'smoke.cases.json');
127
+ if (!fs.existsSync(smokePath)) {
128
+ throw new Error(`Missing smoke.cases.json for ${site.label}: ${smokePath}`);
129
+ }
130
+ let cases = loadMarkdownSmokeCases(smokePath);
131
+ if (options.casePath) {
132
+ cases = cases.filter((entry) => entry.path === options.casePath);
133
+ if (cases.length === 0) {
134
+ throw new Error(
135
+ `No markdown smoke case with path "${options.casePath}" for ${site.label} (${smokePath})`,
136
+ );
137
+ }
138
+ }
139
+ return {
140
+ ...site,
141
+ repoPath,
142
+ smokePath,
143
+ cases,
144
+ };
145
+ });
146
+ }
147
+
148
+ /**
149
+ * @param {string | null} value
150
+ * @returns {string | null}
151
+ */
152
+ export function normalizeCacheHeader(value) {
153
+ if (!value) return null;
154
+ const normalized = value.toUpperCase();
155
+ if (normalized === 'HIT' || normalized === 'MISS' || normalized === 'STALE') {
156
+ return normalized;
157
+ }
158
+ return value;
159
+ }
160
+
161
+ /**
162
+ * @param {string} url
163
+ * @param {typeof fetch} [fetchFn]
164
+ * @returns {Promise<{ body: string; metrics: FetchMetrics }>}
165
+ */
166
+ export async function fetchPage(url, fetchFn = fetch) {
167
+ const started = performance.now();
168
+ const controller = new AbortController();
169
+ const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
170
+
171
+ try {
172
+ const response = await fetchFn(url, {
173
+ method: 'GET',
174
+ redirect: 'follow',
175
+ cache: 'default',
176
+ headers: { 'User-Agent': USER_AGENT },
177
+ signal: controller.signal,
178
+ });
179
+ const body = await response.text();
180
+ const responseMs = Math.round(performance.now() - started);
181
+ const bytes = new TextEncoder().encode(body).length;
182
+
183
+ return {
184
+ body,
185
+ metrics: {
186
+ status: response.status,
187
+ size: bytes,
188
+ responseMs,
189
+ nextjsCache: normalizeCacheHeader(response.headers.get('x-nextjs-cache')),
190
+ vercelCache: normalizeCacheHeader(response.headers.get('x-vercel-cache')),
191
+ error: null,
192
+ },
193
+ };
194
+ } catch (error) {
195
+ const responseMs = Math.round(performance.now() - started);
196
+ return {
197
+ body: '',
198
+ metrics: {
199
+ status: 0,
200
+ size: 0,
201
+ responseMs,
202
+ nextjsCache: null,
203
+ vercelCache: null,
204
+ error: error instanceof Error ? error.message : String(error),
205
+ },
206
+ };
207
+ } finally {
208
+ clearTimeout(timer);
209
+ }
210
+ }
211
+
212
+ /**
213
+ * @param {object} input
214
+ * @param {string} input.siteKey
215
+ * @param {string} input.siteLabel
216
+ * @param {string} input.productionBase
217
+ * @param {MarkdownSmokeCase} input.testCase
218
+ * @param {string} input.artifactsDir
219
+ * @param {typeof fetch} [input.fetchFn]
220
+ * @returns {Promise<{ artifactDir: string; meta: Record<string, unknown> }>}
221
+ */
222
+ export async function collectCaseArtifacts(input) {
223
+ const pageUrl = joinBaseUrl(input.productionBase, input.testCase.path);
224
+ const markdownUrl = htmlUrlToMarkdownUrl(pageUrl);
225
+ const artifactDir = path.join(
226
+ input.artifactsDir,
227
+ input.siteKey,
228
+ pathToArtifactSlug(input.testCase.path),
229
+ );
230
+
231
+ const htmlResult = await fetchPage(pageUrl, input.fetchFn);
232
+ const mdResult = await fetchPage(markdownUrl, input.fetchFn);
233
+
234
+ const htmlForArtifact =
235
+ htmlResult.body.length > 0 ? stripScriptAndStyle(htmlResult.body) : htmlResult.body;
236
+
237
+ fs.mkdirSync(artifactDir, { recursive: true });
238
+
239
+ const meta = {
240
+ url: pageUrl,
241
+ markdownUrl,
242
+ site: input.siteKey,
243
+ siteLabel: input.siteLabel,
244
+ category: input.testCase.category,
245
+ label: input.testCase.label,
246
+ path: input.testCase.path,
247
+ collectedAt: new Date().toISOString(),
248
+ metrics: {
249
+ htmlStatus: htmlResult.metrics.status,
250
+ mdStatus: mdResult.metrics.status,
251
+ htmlSize: htmlResult.metrics.size,
252
+ mdSize: mdResult.metrics.size,
253
+ htmlMs: htmlResult.metrics.responseMs,
254
+ mdMs: mdResult.metrics.responseMs,
255
+ htmlNextCache: htmlResult.metrics.nextjsCache,
256
+ mdNextCache: mdResult.metrics.nextjsCache,
257
+ htmlVercelCache: htmlResult.metrics.vercelCache,
258
+ mdVercelCache: mdResult.metrics.vercelCache,
259
+ htmlError: htmlResult.metrics.error,
260
+ mdError: mdResult.metrics.error,
261
+ },
262
+ files: {
263
+ html: 'page.html',
264
+ markdown: 'page.md',
265
+ },
266
+ };
267
+
268
+ fs.writeFileSync(path.join(artifactDir, 'meta.json'), `${JSON.stringify(meta, null, 2)}\n`);
269
+ fs.writeFileSync(path.join(artifactDir, 'page.html'), htmlForArtifact);
270
+ fs.writeFileSync(path.join(artifactDir, 'page.md'), mdResult.body);
271
+
272
+ return { artifactDir, meta };
273
+ }
274
+
275
+ /**
276
+ * @param {number} bytes
277
+ * @returns {string}
278
+ */
279
+ export function formatBytes(bytes) {
280
+ if (bytes < 1024) return `${bytes} B`;
281
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
282
+ return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
283
+ }
284
+
285
+ /**
286
+ * @param {Record<string, unknown>} meta
287
+ * @returns {string}
288
+ */
289
+ export function formatCacheStatus(meta) {
290
+ const metrics = /** @type {Record<string, string | null>} */ (meta.metrics);
291
+ const html =
292
+ (metrics.htmlNextCache ?? metrics.htmlVercelCache)
293
+ ? `html:${metrics.htmlNextCache ?? metrics.htmlVercelCache ?? '-'}`
294
+ : 'html:-';
295
+ const md =
296
+ (metrics.mdNextCache ?? metrics.mdVercelCache)
297
+ ? `md:${metrics.mdNextCache ?? metrics.mdVercelCache ?? '-'}`
298
+ : 'md:-';
299
+ return `${html} ${md}`;
300
+ }
301
+
302
+ /**
303
+ * @param {string[]} argv
304
+ * @returns {CollectorCliOptions}
305
+ */
306
+ export function parseCollectorCliArgs(argv) {
307
+ /** @type {CollectorCliOptions} */
308
+ const options = {
309
+ siteKey: undefined,
310
+ casePath: undefined,
311
+ dryRun: false,
312
+ delayMs: DEFAULT_DELAY_MS,
313
+ artifactsDir: DEFAULT_ARTIFACTS_DIR,
314
+ sourceRoot: process.env.SE_SOURCE_ROOT ?? path.join(expandHome('~/source')),
315
+ };
316
+
317
+ const args = argv.slice(2).filter((arg) => arg !== '--');
318
+ for (let i = 0; i < args.length; i++) {
319
+ const arg = args[i];
320
+ if (arg === '--site') {
321
+ options.siteKey = args[++i];
322
+ } else if (arg === '--path') {
323
+ options.casePath = args[++i];
324
+ } else if (arg === '--dry-run') {
325
+ options.dryRun = true;
326
+ } else if (arg === '--delay-ms') {
327
+ options.delayMs = Number.parseInt(args[++i] ?? '', 10);
328
+ } else if (arg === '--artifacts-dir') {
329
+ options.artifactsDir = path.resolve(args[++i] ?? options.artifactsDir);
330
+ } else if (arg === '--source-root') {
331
+ options.sourceRoot = args[++i] ?? options.sourceRoot;
332
+ } else if (arg === '--help' || arg === '-h') {
333
+ printHelp();
334
+ process.exit(0);
335
+ } else {
336
+ throw new Error(`Unknown argument: ${arg}`);
337
+ }
338
+ }
339
+
340
+ if (!Number.isFinite(options.delayMs) || options.delayMs < 0) {
341
+ throw new Error('--delay-ms must be a non-negative integer');
342
+ }
343
+
344
+ if (options.dryRun && !options.casePath) {
345
+ throw new Error('--dry-run requires --path');
346
+ }
347
+
348
+ return options;
349
+ }
350
+
351
+ function printHelp() {
352
+ console.log(`Usage: markdown-accuracy-audit [options]
353
+
354
+ Collect production HTML + markdown artifacts for LLM accuracy review.
355
+
356
+ Options:
357
+ --site <key> se2026 | om1 | brightline | brightlifekids | pedestal | headwater | pointme
358
+ --path <path> Single smoke path (e.g. /about/)
359
+ --dry-run Collect one case (--path required); print artifact paths
360
+ --delay-ms <n> Pause between URL pairs (default ${DEFAULT_DELAY_MS})
361
+ --artifacts-dir <dir> Artifact root (default: docs/reports/.markdown-audit-artifacts)
362
+ --source-root <path> Client repos root (default: ~/source or SE_SOURCE_ROOT)
363
+ -h, --help Show this help
364
+ `);
365
+ }
366
+
367
+ function sleep(ms) {
368
+ return new Promise((resolve) => setTimeout(resolve, ms));
369
+ }
370
+
371
+ /**
372
+ * @param {CollectorCliOptions} options
373
+ */
374
+ export async function runMarkdownAccuracyCollector(options) {
375
+ const sites = resolveMarkdownAuditSites(options);
376
+ const collected = [];
377
+
378
+ for (const site of sites) {
379
+ if (site.cases.length === 0) {
380
+ console.warn(`Skipping ${site.label}: no markdown smoke cases`);
381
+ continue;
382
+ }
383
+
384
+ for (const testCase of site.cases) {
385
+ console.log(`Collecting ${site.label} ${testCase.path} …`);
386
+ const result = await collectCaseArtifacts({
387
+ siteKey: site.key,
388
+ siteLabel: site.label,
389
+ productionBase: site.production,
390
+ testCase,
391
+ artifactsDir: options.artifactsDir,
392
+ });
393
+ collected.push(result);
394
+
395
+ if (options.dryRun) {
396
+ console.log('');
397
+ console.log('Dry run complete.');
398
+ console.log(`Artifact dir: ${result.artifactDir}`);
399
+ console.log(`HTML URL: ${result.meta.url}`);
400
+ console.log(`Markdown URL: ${result.meta.markdownUrl}`);
401
+ console.log(
402
+ `Metrics: HTML ${formatBytes(/** @type {number} */ (result.meta.metrics.htmlSize))} / ${result.meta.metrics.htmlMs}ms, MD ${formatBytes(/** @type {number} */ (result.meta.metrics.mdSize))} / ${result.meta.metrics.mdMs}ms, cache ${formatCacheStatus(result.meta)}`,
403
+ );
404
+ return collected;
405
+ }
406
+
407
+ if (options.delayMs > 0) {
408
+ await sleep(options.delayMs);
409
+ }
410
+ }
411
+ }
412
+
413
+ console.log('');
414
+ console.log(`Collected ${collected.length} artifact(s) in ${options.artifactsDir}`);
415
+ return collected;
416
+ }
417
+
418
+ async function main() {
419
+ try {
420
+ const options = parseCollectorCliArgs(process.argv);
421
+ await runMarkdownAccuracyCollector(options);
422
+ } catch (error) {
423
+ console.error(error instanceof Error ? error.message : String(error));
424
+ process.exit(1);
425
+ }
426
+ }
427
+
428
+ const isMain =
429
+ process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
430
+ if (isMain) {
431
+ main();
432
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/site-check",
3
- "version": "2.8.7",
3
+ "version": "2.8.8",
4
4
  "description": "Validate SE marketing sites (sitemap, llms.txt) and download markdown files preserving structure",
5
5
  "repository": {
6
6
  "type": "git",
@@ -48,7 +48,8 @@
48
48
  "smoke-test-live": "./smoke-test-live.mjs",
49
49
  "validate-build-routes": "./validate-build-routes.mjs",
50
50
  "revalidation-matrix-test": "./revalidation-matrix-test.mjs",
51
- "develop-sites-timing": "./develop-sites-timing.mjs"
51
+ "develop-sites-timing": "./develop-sites-timing.mjs",
52
+ "markdown-accuracy-audit": "./markdown-accuracy-audit.mjs"
52
53
  },
53
54
  "files": [
54
55
  "dist",
@@ -61,7 +62,8 @@
61
62
  "smoke-test-live.mjs",
62
63
  "validate-build-routes.mjs",
63
64
  "revalidation-matrix-test.mjs",
64
- "develop-sites-timing.mjs"
65
+ "develop-sites-timing.mjs",
66
+ "markdown-accuracy-audit.mjs"
65
67
  ],
66
68
  "keywords": [
67
69
  "sitemap",
@@ -79,7 +81,7 @@
79
81
  "url": "https://github.com/Something-Else-Studio/se-core-product/issues"
80
82
  },
81
83
  "dependencies": {
82
- "@se-studio/contentful-rest-api": "1.14.5",
84
+ "@se-studio/contentful-rest-api": "1.14.6",
83
85
  "@se-studio/core-data-types": "1.6.1"
84
86
  },
85
87
  "devDependencies": {
@@ -93,6 +95,6 @@
93
95
  "type-check": "tsc --noEmit",
94
96
  "lint": "biome lint .",
95
97
  "clean": "rm -rf dist .turbo *.tsbuildinfo",
96
- "test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/production-audit.test.mjs scripts/smoke-test.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs"
98
+ "test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/production-audit.test.mjs scripts/smoke-test.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs"
97
99
  }
98
100
  }