99 lines
4.6 KiB
JavaScript
99 lines
4.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
|
|
// Verifies a production deployment produced by
|
|
// `edgeone makers deploy --json`. The deployment URL carries a one-time
|
|
// `eo_token`/`eo_time` pair: the first request answers 302 and sets cookies,
|
|
// later requests use the cookie. Every probe therefore performs its own
|
|
// handshake, and the token query is kept for the 404 probe.
|
|
|
|
const file = process.argv[2] ?? 'deploy-result.json';
|
|
const lines = readFileSync(file, 'utf8').trim().split('\n').filter(line => line.startsWith('{'));
|
|
assert.ok(lines.length > 0, `${file}: no JSON deployment result`);
|
|
const result = JSON.parse(lines[lines.length - 1]);
|
|
|
|
assert.equal(result.status, 'success', `Deployment did not succeed: ${JSON.stringify(result)}`);
|
|
assert.ok(result.deploymentId, 'Deployment result is missing deploymentId');
|
|
assert.ok(result.projectId, 'Deployment result is missing projectId');
|
|
assert.match(result.url ?? '', /^https:\/\//, 'Deployment result is missing an https url');
|
|
|
|
const timeout = 30_000;
|
|
|
|
function probeURL(pathname) {
|
|
const url = new URL(result.url);
|
|
url.pathname = pathname;
|
|
return url;
|
|
}
|
|
|
|
async function probe(pathname) {
|
|
const entry = probeURL(pathname);
|
|
let response = await fetch(entry, { redirect: 'manual', signal: AbortSignal.timeout(timeout) });
|
|
if (response.status >= 300 && response.status < 400) {
|
|
const location = response.headers.get('location');
|
|
assert.ok(location, `${pathname}: redirect without location`);
|
|
const cookie = response.headers.getSetCookie().map(value => value.split(';')[0]).join('; ');
|
|
assert.ok(cookie, `${pathname}: access token redirect without cookie`);
|
|
response = await fetch(new URL(location, entry), {
|
|
redirect: 'manual',
|
|
headers: { cookie },
|
|
signal: AbortSignal.timeout(timeout),
|
|
});
|
|
}
|
|
return { status: response.status, body: await response.text() };
|
|
}
|
|
|
|
const home = await probe('/');
|
|
assert.equal(home.status, 200, `Home returned HTTP ${home.status}`);
|
|
for (const marker of ['Marqdo', '\u00a9 2026 CFLMY', '\u8c6bICP\u59072025120352\u53f7-6']) {
|
|
assert.ok(home.body.includes(marker), `Home is missing marker: ${marker}`);
|
|
}
|
|
|
|
const english = await probe('/en/');
|
|
assert.equal(english.status, 200, `English home returned HTTP ${english.status}`);
|
|
assert.ok(english.body.includes('Marqdo'), 'English home is missing the site title');
|
|
|
|
const missing = await probe('/__verify_absent__');
|
|
assert.equal(missing.status, 404, `Absent path returned HTTP ${missing.status}`);
|
|
|
|
// Production deployments must serve the exact root projection and a download
|
|
// center derived from it; a site without /data is a safe preview build.
|
|
let releaseEvidence = { checked: ['home', 'english-home', 'not-found'] };
|
|
if (process.env.MARQDO_EXPECT_RELEASE === '1') {
|
|
const pointerResponse = await probe('/data/current.json');
|
|
assert.equal(pointerResponse.status, 200, `Release pointer returned HTTP ${pointerResponse.status}`);
|
|
const pointer = JSON.parse(pointerResponse.body);
|
|
assert.equal(pointer.schema_version, 1, 'Invalid release pointer schema');
|
|
assert.match(pointer.snapshot, /^\/data\/snapshots\/[a-f0-9]{64}\.json$/, 'Invalid release pointer snapshot');
|
|
const snapshotResponse = await probe(pointer.snapshot);
|
|
assert.equal(snapshotResponse.status, 200, `Release snapshot returned HTTP ${snapshotResponse.status}`);
|
|
const snapshot = JSON.parse(snapshotResponse.body);
|
|
assert.ok(Array.isArray(snapshot.offers) && snapshot.offers.some(offer => offer.product === 'mqdh'),
|
|
'Release snapshot has no MQDH offer');
|
|
assert.ok(Array.isArray(snapshot.offers) && snapshot.offers.some(offer => offer.product === 'marqdo'),
|
|
'Release snapshot has no Marqdo offer');
|
|
const download = await probe('/download/');
|
|
assert.equal(download.status, 200, `Download center returned HTTP ${download.status}`);
|
|
const assets = new Map(snapshot.releases.flatMap(release => release.assets.map(asset => [asset.asset_id, asset])));
|
|
const recommended = new Set(snapshot.recommendations.map(item => item.offer_id));
|
|
for (const offer of snapshot.offers.filter(item => recommended.has(item.offer_id))) {
|
|
for (const id of offer.primary_asset_ids) {
|
|
assert.ok(download.body.includes(`href="${assets.get(id).download_url}"`),
|
|
`Download center is missing the primary download for ${offer.product}: ${id}`);
|
|
}
|
|
}
|
|
releaseEvidence = {
|
|
revision: pointer.revision,
|
|
snapshot_sha256: pointer.sha256,
|
|
offers: snapshot.offers.map(offer => offer.offer_id),
|
|
checked: ['home', 'english-home', 'not-found', 'release-pointer', 'release-snapshot', 'download-center'],
|
|
};
|
|
}
|
|
|
|
console.log(JSON.stringify({
|
|
status: 'verified',
|
|
projectId: result.projectId,
|
|
deploymentId: result.deploymentId,
|
|
url: result.url,
|
|
...releaseEvidence,
|
|
}));
|