import assert from "node:assert/strict"; import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { execFileSync } from "node:child_process"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const generator = path.join(root, "tools/web/generate-blender-gap-audit.mjs"); const auditPath = path.join(root, "tests/golden/M15-02B/blender-gap-audit.json"); const reportPath = path.join(root, "tests/golden/M15-02B/gap-audit-check-report.json"); const manifestPath = path.join(root, "tests/golden/M15-02B/manifest.json"); const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex"); const fileSha256 = (file) => sha256(fs.readFileSync(file)); const relative = (file) => path.relative(root, file).replaceAll(path.sep, "/"); const audit = JSON.parse(fs.readFileSync(auditPath, "utf8")); assert.equal(audit.schemaVersion, 1); assert.equal(audit.task, "M15-02B"); assert.equal(audit.operation, "BLENDER_PARITY_GAP_AUDIT"); assert.equal(audit.interpretation.inventoryBaseline, "SUMMARY_ONLY"); assert.equal(fileSha256(path.join(root, audit.source.path)), audit.source.sha256); const categories = ["unmapped", "duplicateIds", "summaryOnly", "proxyOnly", "routeOnly"]; const sortedUnique = (values, label) => { assert.deepEqual(values, [...values].sort((a, b) => a < b ? -1 : a > b ? 1 : 0), `${label} are not sorted`); assert.equal(new Set(values).size, values.length, `${label} are not unique`); }; for (const category of categories) { assert.ok(Array.isArray(audit.gaps[category])); sortedUnique(audit.gaps[category], category); } assert.equal(audit.summary.inventoried, audit.summary.unmapped + audit.summary.summaryOnly + audit.summary.proxyOnly + audit.summary.routeOnly); assert.equal(audit.summary.duplicate, audit.gaps.duplicateIds.length); assert.equal(audit.summary.gapCount, categories.reduce((sum, category) => sum + audit.gaps[category].length, 0)); assert.ok(audit.summary.inventoried >= 6900); assert.equal(audit.summary.unmapped, 0); assert.equal(audit.summary.duplicate, 0); assert.equal(audit.summary.proxyOnly, 0); assert.equal(audit.summary.routeOnly, 0); assert.equal(audit.summary.summaryOnly, audit.summary.inventoried); const temporary = path.join(root, ".tmp-m15-02b-audit.json"); try { execFileSync(process.execPath, [generator, temporary], { cwd: root, stdio: "pipe" }); assert.deepEqual(fs.readFileSync(temporary), fs.readFileSync(auditPath), "gap audit is not deterministic"); } finally { fs.rmSync(temporary, { force: true }); } const report = { schemaVersion: 1, task: "M15-02B", operation: "BLENDER_PARITY_GAP_AUDIT_CHECK", summary: audit.summary, auditSha256: fileSha256(auditPath), nextTask: audit.nextTask }; if (process.env.UPDATE_M15_02B_MANIFEST === "1") { fs.mkdirSync(path.dirname(reportPath), { recursive: true }); fs.writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`); const artifactPaths = { parentManifest: path.join(root, "tests/golden/M15-02A/manifest.json"), generator, checker: path.join(root, "tools/web/check-blender-gap-audit.mjs"), audit: auditPath, report: reportPath, package: path.join(root, "web/package.json") }; const artifacts = Object.fromEntries(Object.entries(artifactPaths).map(([name, file]) => [name, { path: relative(file), sha256: fileSha256(file) }])); fs.writeFileSync(manifestPath, `${JSON.stringify({ schemaVersion: 1, task: "M15-02B", parentTask: "M15-02A", enablingTask: false, parityStateChange: false, runtime: "BLENDER_5_2_PARITY", operation: "BLENDER_PARITY_GAP_AUDIT", artifacts, nextTask: "M15-02C" }, null, 2)}\n`); } const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); assert.deepEqual({ task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { task: "M15-02B", parentTask: "M15-02A", nextTask: "M15-02C" }); for (const artifact of Object.values(manifest.artifacts)) assert.equal(fileSha256(path.join(root, artifact.path)), artifact.sha256, artifact.path); process.stdout.write(`blender-gap-audit-ok inventoried=${audit.summary.inventoried} gaps=${audit.summary.gapCount} summaryOnly=${audit.summary.summaryOnly} next=${manifest.nextTask}\n`);