- build:release reads the immutable root projection from the root Release assets (MARQDO_DATA_RELEASE) or the production origin, verifies it against MARQDO_DATA_ROOT_SHA, and deploys the same pointer/snapshot under /data/; - production pipeline runs prepare-example + build:release; the manual trigger supplies the accepted root commit and release base, failing closed without them; - verify-dist enforces /data consistency in release builds and absence in safe builds; verify-deploy probes the pointer, snapshot, both product offers and the MQDH download entry; - pin the site example and evidence to the accepted CLI v3.0.0-rc.7 and document the MQDH beta install path in the quick start; - drop the temporary screenshot helper and keep only durable baseline facts in docs/BASELINE.md; progress lives in the repository issues.
94 lines
6.3 KiB
JavaScript
94 lines
6.3 KiB
JavaScript
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
import { join, posix } from 'node:path';
|
|
import { gzipSync } from 'node:zlib';
|
|
import { createHash } from 'node:crypto';
|
|
import assert from 'node:assert/strict';
|
|
|
|
const dist = 'dist';
|
|
// Site information architecture: the wiki replaces the former /docs/ body, so
|
|
// /docs/ is a static migration page that must still resolve.
|
|
const routes = ['', 'download/', 'start/', 'ecosystem/', 'research/', 'releases/', 'feedback/', 'about/', 'privacy/', 'docs/'];
|
|
const paths = ['', 'en/'].flatMap(locale => routes.map(route => locale + route + 'index.html')).concat('404.html');
|
|
const documents = new Map(paths.map(path => [path, readFileSync(join(dist, path), 'utf8')]));
|
|
const ids = new Map([...documents].map(([path, html]) =>
|
|
[path, new Set([...html.matchAll(/\sid="([^"]+)"/g)].map(match => match[1]))]));
|
|
const production = process.env.MARQDO_RELEASE_BUILD === '1';
|
|
|
|
for (const [path, html] of documents) {
|
|
assert.equal([...html.matchAll(/<h1[\s>]/g)].length, 1, `Expected one h1 in ${path}`);
|
|
assert.match(html, /© 2026 CFLMY/);
|
|
assert.match(html, /豫ICP备2025120352号-6/);
|
|
assert.match(html, /mailto:pingan@cflmy\.com/);
|
|
// The wiki is the single documentation entry; no page may link a removed
|
|
// in-site documentation body.
|
|
assert.doesNotMatch(html, /href="\/(?:en\/)?docs\/#[^"]*"/, `Stale in-site docs anchor in ${path}`);
|
|
if (!production) assert.match(html, /name="robots" content="noindex"/);
|
|
assert.doesNotMatch(html, /<script(?:\s[^>]*?)?>\s*[^<\s]/, `Inline script in ${path}`);
|
|
assert.doesNotMatch(html, /(?:https?:\/\/(?:localhost|127\.0\.0\.1)|fixture_kind|MARQDO_WOODPECKER_DISPATCH_TOKEN|BEGIN (?:OPENSSH |RSA |EC )?PRIVATE KEY)/);
|
|
for (const [, ref] of html.matchAll(/\s(?:href|src)="(\/[^/"][^"]*|\/|#[^"]+)"/g)) {
|
|
const [link, anchor] = ref.split('#');
|
|
const dest = link ? decodeURIComponent(link.slice(1)) : path;
|
|
const file = link && (!dest || dest.endsWith('/')) ? posix.join(dest, 'index.html') : dest;
|
|
assert.ok(existsSync(join(dist, file)) && statSync(join(dist, file)).isFile(), `Missing ${ref}, referenced by ${path}`);
|
|
if (anchor && ids.has(file)) assert.ok(ids.get(file).has(decodeURIComponent(anchor)), `Missing anchor ${ref}, referenced by ${path}`);
|
|
}
|
|
}
|
|
|
|
for (const file of ['assets/logo.svg', 'assets/hero-particles.svg', 'assets/cflmy.jpg', 'assets/social.png', 'assets/geometry.mq.md', 'robots.txt', 'sitemap.xml']) {
|
|
assert.ok(existsSync(join(dist, file)), `Missing ${file}`);
|
|
}
|
|
// The documentation search index was removed with the in-site docs body.
|
|
assert.ok(!existsSync(join(dist, 'pagefind')), 'Pagefind output must not be shipped');
|
|
|
|
// The footer keeps the two-column project/author contract on every page.
|
|
for (const path of ['index.html', 'en/download/index.html', 'privacy/index.html']) {
|
|
const html = documents.get(path);
|
|
assert.match(html, /class="footer-columns"/, `Missing footer columns in ${path}`);
|
|
assert.match(html, /class="author-avatar"/, `Missing author avatar in ${path}`);
|
|
assert.match(html, /class="footer-rule"/, `Missing footer rule in ${path}`);
|
|
}
|
|
|
|
// The demo keeps its three panes, four view modes and evidence entry.
|
|
const home = documents.get('index.html');
|
|
assert.match(home, /data-pane="source"/);
|
|
assert.match(home, /data-pane="reading"/);
|
|
assert.match(home, /data-pane="compute"/);
|
|
assert.equal([...home.matchAll(/<button[^>]*data-mode="(?:compare|source|reading|compute)"/g)].length, 4, 'Expected four demo view buttons');
|
|
assert.match(home, /查看 CLI 命令与实测依据/);
|
|
|
|
const homeScripts = [...home.matchAll(/<script[^>]* src="(\/[^"]+)"/g)].map(hit => hit[1]);
|
|
const compressed = homeScripts.reduce((size, file) => size + gzipSync(readFileSync(dist + file)).length, 0);
|
|
assert.ok(compressed <= 150 * 1024, `Home JS exceeds 150 KiB: ${compressed}`);
|
|
const particleChunks = readdirSync(join(dist, '_astro')).filter(name => /^hero-particles\.[\w-]+\.js$/.test(name));
|
|
assert.equal(particleChunks.length, 1, 'Expected one lazy hero particle chunk');
|
|
assert.ok(!home.includes(particleChunks[0]), 'The particle chunk must not appear in initial homepage HTML');
|
|
const particleBytes = gzipSync(readFileSync(join(dist, '_astro', particleChunks[0]))).length;
|
|
assert.ok(particleBytes < 180 * 1024, `Lazy particle bundle exceeds 180 KiB: ${particleBytes}`);
|
|
const posterBytes = gzipSync(readFileSync(join(dist, 'assets/hero-particles.svg'))).length;
|
|
assert.ok(posterBytes < 25 * 1024, `Hero poster exceeds 25 KiB: ${posterBytes}`);
|
|
assert.ok(!readdirSync(dist).some(name => name.startsWith('.')), 'Unexpected output root entries');
|
|
// The release build ships the exact verified projection under /data/; the safe
|
|
// build must never contain synthetic or stale release data.
|
|
const dataRoot = join(dist, 'data');
|
|
// `build:release` runs the site build first and then adds the verified
|
|
// projection bytes; the pointer env is present for that second verification.
|
|
const dataRequired = production && process.env.MARQDO_DATA_READY === '1';
|
|
if (dataRequired) {
|
|
const pointerBytes = readFileSync(join(dataRoot, 'current.json'));
|
|
const pointer = JSON.parse(pointerBytes.toString('utf8'));
|
|
assert.equal(pointer.schema_version, 1, 'Invalid release pointer schema');
|
|
assert.ok(Number.isInteger(pointer.revision) && pointer.revision >= 0, 'Invalid release pointer revision');
|
|
assert.equal(pointer.snapshot, `/data/snapshots/${pointer.sha256}.json`, 'Invalid release pointer snapshot');
|
|
const snapshotBytes = readFileSync(join(dist, 'data', 'snapshots', `${pointer.sha256}.json`));
|
|
assert.equal(createHash('sha256').update(snapshotBytes).digest('hex'), pointer.sha256,
|
|
'Release snapshot digest does not match the pointer');
|
|
const snapshot = JSON.parse(snapshotBytes.toString('utf8'));
|
|
assert.equal(snapshot.snapshot_revision, pointer.revision, 'Snapshot revision does not match the pointer');
|
|
assert.ok(Array.isArray(snapshot.offers) && snapshot.offers.length > 0, 'Release snapshot has no offers');
|
|
assert.ok(Array.isArray(snapshot.recommendations) && snapshot.recommendations.length > 0,
|
|
'Release snapshot has no recommendations');
|
|
} else if (!production) {
|
|
assert.ok(!existsSync(dataRoot), 'Safe build must not ship release data');
|
|
}
|
|
console.log(`Verified ${paths.length} HTML pages, local references and anchors; initial homepage JS ${compressed} bytes gzip, lazy particles ${particleBytes} bytes gzip, poster ${posterBytes} bytes gzip.`);
|