import assert from "node:assert/strict"; import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; import { execFileSync } from "node:child_process"; import { fileURLToPath } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const reportPath = path.join(root, "tests/golden/M14-01A/chromium-freeze-report.json"); const manifestPath = path.join(root, "tests/golden/M14-01A/manifest.json"); const digest = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex"); const fileDigest = (file) => digest(fs.readFileSync(file)); const relative = (file) => path.relative(root, file).replaceAll(path.sep, "/"); const chromeCommand = process.env.CHROME_PATH ?? "google-chrome"; const chromeVersion = execFileSync(chromeCommand, ["--version"], { encoding: "utf8" }).trim(); const versionMatch = chromeVersion.match(/^(Google Chrome|Chromium) (\d+\.\d+\.\d+\.\d+)$/u); assert.ok(versionMatch, `unsupported Chromium version output: ${chromeVersion}`); const chromePath = fs.realpathSync(execFileSync("bash", ["-lc", `command -v ${chromeCommand}`], { encoding: "utf8" }).trim()); const enginePath = path.join(root, "web/app/public/engine-manifest.json"); const engine = JSON.parse(fs.readFileSync(enginePath, "utf8")); const variants = Object.fromEntries(engine.variants.map((variant) => [variant.id, Object.fromEntries(Object.entries(variant.resources).map(([kind, resource]) => { const file = path.join(root, "web/app/public", resource.url.replace(/^\//u, "")); assert.equal(fileDigest(file), resource.sha256, `${variant.id}/${kind} resource hash drifted`); return [kind, { path: relative(file), sha256: resource.sha256 }]; }))])); const rcPath = path.join(root, "release/RC_MANIFEST.json"); const rc = JSON.parse(fs.readFileSync(rcPath, "utf8")); const archiveEntries = Object.fromEntries(["binaryArchive", "sourceArchive"].map((name) => { const file = path.join(root, rc.artifacts[name].path); assert.equal(fileDigest(file), rc.artifacts[name].sha256, `${name} hash drifted from RC manifest`); return [name, { path: relative(file), bytes: fs.statSync(file).size, sha256: fileDigest(file) }]; })); const sumsPath = path.join(root, "release/SHA256SUMS.txt"); const sums = fs.readFileSync(sumsPath, "utf8").trim().split(/\r?\n/u); assert.deepEqual(sums, [ `${archiveEntries.binaryArchive.sha256} ${path.basename(archiveEntries.binaryArchive.path)}`, `${archiveEntries.sourceArchive.sha256} ${path.basename(archiveEntries.sourceArchive.path)}`, ]); const report = { schemaVersion: 1, task: "M14-01A", operation: "CHROMIUM_ENGINE_ARCHIVE_FREEZE", browser: { family: versionMatch[1], version: versionMatch[2], command: chromeCommand, executablePath: chromePath, executableSha256: fileDigest(chromePath), versionOutput: chromeVersion }, engine: { releaseId: engine.releaseId, manifest: { path: relative(enginePath), sha256: fileDigest(enginePath) }, variants }, archives: archiveEntries, checksums: { path: relative(sumsPath), sha256: fileDigest(sumsPath) }, rcManifest: { path: relative(rcPath), sha256: fileDigest(rcPath), rcId: rc.rcId, gitCommit: rc.gitCommit }, execution: "DISABLED", nextTask: "M14-01B", }; if (process.env.UPDATE_M14_01A_REPORT === "1") { fs.mkdirSync(path.dirname(reportPath), { recursive: true }); fs.writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`); } assert.deepEqual(JSON.parse(fs.readFileSync(reportPath, "utf8")), report); const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); assert.deepEqual({ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { schemaVersion: 1, task: "M14-01A", parentTask: "M13-05H", nextTask: "M14-01B" }); for (const artifact of Object.values(manifest.artifacts)) assert.equal(fileDigest(path.join(root, artifact.path)), artifact.sha256, artifact.path); process.stdout.write(`chromium-freeze-ok browser=${versionMatch[2]} engine=${engine.releaseId} variants=${engine.variants.length} archives=2 checksums=1 execution=DISABLED next=${manifest.nextTask}\n`);