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 fixture = path.join(root, "web/public/samples/freecad-sample.step"); 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-kernel/v1", module: "Import", action: "import/step", result: "pass", sourceRevision: execFileSync("git", ["-C", sourceRoot, "rev-parse", "HEAD"], { encoding: "utf8" }).trim(), input: { path: "web/public/samples/freecad-sample.step", sha256: sha256(fixture), bytes: fs.statSync(fixture).size, }, first: { returnCode: 1, handle: result.importHandle, summary: result.firstImport, activeBeforeRelease: result.activeAfterImport, release: result.release, activeAfterRelease: result.activeAfterRelease, }, repeat: { returnCode: 1, handle: result.repeatHandle, summary: result.repeatImport, release: result.repeatRelease, activeAfterRelease: result.activeAfterRepeatRelease, }, error: { returnCode: result.missingFile, ...result.missingFileError, }, deterministic: JSON.stringify(result.firstImport) === JSON.stringify(result.repeatImport), sourceBacked: true, artifacts: { jsSha256: sha256(js), wasmSha256: sha256(wasm), smoke: "src/WebAssembly/FreeCADCoreProbe/import-runtime-smoke.js", }, }; if (!report.deterministic || report.first.activeAfterRelease !== 0 || report.repeat.activeAfterRelease !== 0) { throw new Error(JSON.stringify(report)); } fs.writeFileSync(path.join(root, "docs/p6/import-kernel.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-import-c-kernel-smoke.log"), [ "result=pass", `fixtureSha256=${report.input.sha256}`, `wasmSha256=${report.artifacts.wasmSha256}`, `firstHandle=${report.first.handle}`, `repeatHandle=${report.repeat.handle}`, `objects=${report.first.summary.objects}`, `parts=${report.first.summary.parts}`, `solids=${report.first.summary.solids}`, `volume=${report.first.summary.volume}`, `errorCode=${report.error.code}`, "activeAfterRelease=0", "deterministic=true", "", ].join("\n")); console.log(JSON.stringify(report));