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"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const outputPath = path.join(root, "tests/golden/WBV2-P7-003/atomic-chromium-receipt-index.json"); const relative = (file) => path.relative(root, file).replaceAll(path.sep, "/"); const absolute = (file) => path.join(root, file); const readJson = (file) => JSON.parse(fs.readFileSync(absolute(file), "utf8")); const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(absolute(file))).digest("hex"); const sources = [ { family: "ASSET_CATALOG", capabilityId: "CAP-ASSET-CATALOG-MUTATION", sourceTask: "C3-003", report: "tests/golden/corrective/C3-003/receipt-report.json", secondReport: "tests/golden/corrective/C3-003/receipt-report.second.json", manifest: "tests/golden/corrective/C3-003/manifest.json", proof: { desktopPositive: "positive.desktop", wasmMutation: "positive.wasm", saveReopenExact: "persistence" }, }, { family: "MODIFIER", capabilityId: "CAP-MODIFIER-STATE-MUTATION", sourceTask: "C4-001", report: "tests/golden/corrective/C4-001/receipt-report.json", secondReport: "tests/golden/corrective/C4-001/receipt-report.second.json", manifest: "tests/golden/corrective/C4-001/manifest.json", proof: { desktopPositive: "positive.desktop", wasmMutation: "positive.wasm", saveReopenExact: "persistence.reopened" }, }, { family: "MESH", capabilityId: "CAP-MESH-POSITIVE-EDIT", sourceTask: "C4-002", report: "tests/golden/corrective/C4-002/receipt-report.json", secondReport: "tests/golden/corrective/C4-002/receipt-report.second.json", manifest: "tests/golden/corrective/C4-002/manifest.json", proof: { desktopPositive: "positive.desktop", wasmMutation: "positive.wasm", saveReopenExact: "persistence.reopened" }, }, ]; const behaviors = ["desktopPositive", "wasmMutation", "saveReopenExact"]; const get = (value, selector) => selector.split(".").reduce((current, key) => current?.[key], value); const entries = []; for (const source of sources) { const report = readJson(source.report); const manifest = readJson(source.manifest); assert.equal(manifest.status, "done", `${source.sourceTask} manifest is not done`); assert.equal(report.browser, "chromium", `${source.sourceTask} is not Chromium evidence`); assert.equal(report.queueMutation, false, `${source.sourceTask} mutated the queue`); assert.equal(report.parity, true, `${source.sourceTask} did not prove parity`); assert.equal(sha256(source.secondReport), sha256(source.report), `${source.sourceTask} report is not deterministic`); const bound = Object.values(manifest.artifacts ?? {}).find((artifact) => artifact.path === source.report); assert.ok(bound, `${source.sourceTask} report is not manifest-bound`); assert.equal(bound.sha256, sha256(source.report), `${source.sourceTask} report hash drift`); for (const behavior of behaviors) { const proofPath = source.proof[behavior]; const proof = get(report, proofPath); assert.ok(proof, `${source.sourceTask} missing ${behavior} proof`); entries.push({ id: `WBV2-P7-003-${source.family}-${behavior.toUpperCase()}`, family: source.family, capabilityId: source.capabilityId, behavior, browser: "chromium", status: "EXACT_REUSED_FROM_CORRECTIVE_CHROMIUM", manifestBound: true, queueMutation: false, source: { task: source.sourceTask, manifest: source.manifest, manifestSha256: sha256(source.manifest), report: source.report, reportSha256: sha256(source.report), secondReport: source.secondReport, secondReportSha256: sha256(source.secondReport), proofPath, }, proof, }); } } const report = { schemaVersion: 1, task: "WBV2-P7-003", operation: "ATOMIC_CHROMIUM_RECEIPT_INDEX", browser: "chromium", queueMutation: false, policy: { sourceReportsReadOnly: true, exactReuseOnly: true, featureParityClaims: 0, canonicalOrder: behaviors, }, summary: { total: entries.length, manifestBound: entries.filter((entry) => entry.manifestBound).length, families: [...new Set(entries.map((entry) => entry.family))] }, entries, }; fs.mkdirSync(path.dirname(outputPath), { recursive: true }); fs.writeFileSync(outputPath, `${JSON.stringify(report, null, 2)}\n`, "utf8"); process.stdout.write(`atomic-chromium-receipts-ok task=${report.task} receipts=${report.summary.total} families=${report.summary.families.length} queueMutation=false output=${relative(outputPath)}\n`);