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 reportPath = path.join(root, "tests/golden/M12-07J/io-format-recovery-report.json"); const manifestPath = path.join(root, "tests/golden/M12-07J/manifest.json"); const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8")); const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex"); const report = readJson(reportPath); const manifest = readJson(manifestPath); assert.deepEqual({ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { schemaVersion: 1, task: "M12-07J", parentTask: "M12-07I", nextTask: "M13-01A" }); assert.deepEqual({ schemaVersion: report.schemaVersion, task: report.task, operation: report.operation, nextTask: report.nextTask }, { schemaVersion: 1, task: "M12-07J", operation: "IO_FORMAT_THREE_WAY_RECOVERY", nextTask: "M13-01A" }); assert.deepEqual(report.assertions, { formats: ["OBJ", "STL", "PLY"], cancellationUnpublished: true, oomUnpublished: true, restartHashStable: true, smallRecoveryStable: true }); for (const format of ["OBJ", "STL", "PLY"]) { const value = report.formats[format]; assert.equal(value.cancel.status, "CANCELLED"); assert.equal(value.cancel.errorCode, "IO_FORMAT_OPERATION_CANCELLED"); assert.equal(value.cancel.publishedResults, 0); assert.equal(value.oom.status, "BLOCKED"); assert.equal(value.oom.errorCode, "IO_FORMAT_OOM"); assert.equal(value.oom.publishedResults, 0); assert.equal(value.first.status, "COMMITTED"); assert.equal(value.second.status, "COMMITTED"); assert.equal(value.small.status, "COMMITTED"); assert.equal(value.recovered.status, "RECOVERED"); assert.equal(value.recovered.errorCode, "IO_FORMAT_WORKER_RESTARTED"); assert.equal(value.hashes.first, value.hashes.second); assert.equal(value.hashes.first, value.hashes.small); assert.equal(value.first.outputSha256, value.recovered.outputSha256); } for (const artifact of Object.values(manifest.artifacts)) assert.equal(sha256(fs.readFileSync(path.join(root, artifact.path))), artifact.sha256, `artifact hash mismatch ${artifact.path}`); process.stdout.write(`io-format-recovery-ok formats=OBJ,STL,PLY cancelled=3 oom=3 restart=3 smallRecovery=3 deterministic=true next=${manifest.nextTask}\n`);