56 lines
2.6 KiB
JavaScript
56 lines
2.6 KiB
JavaScript
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { execFileSync } from "node:child_process";
|
|
|
|
const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..");
|
|
const sourceRoot = path.join(root, "freecad-source");
|
|
const bin = path.resolve(process.argv[2] || path.join(sourceRoot, "build-web/configure/bin"));
|
|
const smoke = path.join(sourceRoot, "src/WebAssembly/FreeCADCoreProbe/import-runtime-smoke.js");
|
|
const js = path.join(bin, "FreeCADWebImportRuntimeProbe.js");
|
|
const wasm = path.join(bin, "FreeCADWebImportRuntimeProbe.wasm");
|
|
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
|
|
|
const output = execFileSync(process.execPath, [smoke, bin], { encoding: "utf8" }).trim();
|
|
const result = JSON.parse(output.split("\n").at(-1));
|
|
const report = {
|
|
schema: "freecad-web-p6-import-recovery/v1",
|
|
module: "Import",
|
|
action: "import/step-recovery",
|
|
result: "pass",
|
|
sourceRevision: execFileSync("git", ["-C", sourceRoot, "rev-parse", "HEAD"], { encoding: "utf8" }).trim(),
|
|
validSnapshot: result.validSnapshot,
|
|
validSnapshotSha256: result.validSnapshotHash,
|
|
missingResource: {
|
|
first: { returnCode: result.missingFile, ...result.missingFileError },
|
|
repeat: { returnCode: result.missingFileRepeat, ...result.missingFileRepeatError },
|
|
},
|
|
invalidInput: { returnCode: result.emptyPath, ...result.emptyPathError },
|
|
stateAfterFailure: result.afterMissingRepeatSnapshot,
|
|
statePreserved: JSON.stringify(result.validSnapshot) === JSON.stringify(result.afterMissingRepeatSnapshot),
|
|
deterministicErrors: result.missingFileError.code === result.missingFileRepeatError.code
|
|
&& result.missingFileError.message === result.missingFileRepeatError.message,
|
|
sourceBacked: true,
|
|
artifacts: {
|
|
jsSha256: sha256(js),
|
|
wasmSha256: sha256(wasm),
|
|
smoke: "src/WebAssembly/FreeCADCoreProbe/import-runtime-smoke.js",
|
|
},
|
|
};
|
|
if (!report.statePreserved || !report.deterministicErrors) {
|
|
throw new Error(JSON.stringify(report));
|
|
}
|
|
fs.writeFileSync(path.join(root, "docs/p6/import-recovery.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "docs/freecad-p6-import-d-recovery.log"), [
|
|
"result=pass",
|
|
`validSnapshotSha256=${report.validSnapshotSha256}`,
|
|
`missingResource=${report.missingResource.first.code}`,
|
|
`missingResourceRepeat=${report.missingResource.repeat.code}`,
|
|
`invalidInput=${report.invalidInput.code}`,
|
|
`statePreserved=${report.statePreserved}`,
|
|
`deterministicErrors=${report.deterministicErrors}`,
|
|
`wasmSha256=${report.artifacts.wasmSha256}`,
|
|
"",
|
|
].join("\n"));
|
|
console.log(JSON.stringify(report));
|