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.join(sourceRoot, "build-web/configure/bin"); const smoke = path.join(sourceRoot, "src/WebAssembly/FreeCADCoreProbe/import-runtime-smoke.js"); const fixture = path.join(root, "web/public/samples/freecad-sample.step"); const sha256 = (value) => crypto.createHash("sha256").update(value).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-action-01-kernel/v1", taskId: "FW-P6-IMP-ACT-01-C", module: "Import", action: "create/recompute", result: "pass", sourceRevision: execFileSync("git", ["-C", sourceRoot, "rev-parse", "HEAD"], { encoding: "utf8" }).trim(), input: { path: "web/public/samples/freecad-sample.step", sha256: sha256(fs.readFileSync(fixture)), bytes: fs.statSync(fixture).size }, request: { requestId: "import-create-kernel-1", nativeCommand: "fc_web_import_step" }, success: { returnCode: result.importHandle, handle: result.importHandle, objectCount: result.firstImport.objects, partCount: result.firstImport.parts, solidCount: result.firstImport.solids, volume: result.firstImport.volume, objectType: result.firstImport.objectType, recomputeHasError: 0, release: result.release, activeAfterClose: result.activeAfterRelease, }, repeat: { summary: result.repeatImport, deterministic: JSON.stringify(result.firstImport) === JSON.stringify(result.repeatImport), release: result.repeatRelease, activeAfterClose: result.activeAfterRepeatRelease }, expectedError: { returnCode: result.missingFile, ...result.missingFileError }, inputSha256: sha256(JSON.stringify({ path: "web/public/samples/freecad-sample.step", sha256: sha256(fs.readFileSync(fixture)) })), wasmSha256: sha256(fs.readFileSync(path.join(bin, "FreeCADWebImportRuntimeProbe.wasm"))), sourceBacked: true, }; if (report.success.objectCount !== 32 || report.success.partCount !== 5 || report.success.solidCount !== 5 || report.success.activeAfterClose !== 0 || !report.repeat.deterministic || report.expectedError.code !== "file_not_found") throw new Error(JSON.stringify(report)); fs.writeFileSync(path.join(root, "docs/p6/import-action-01-kernel.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-import-action-01-c-kernel.log"), `result=pass\nrequestId=${report.request.requestId}\nobjects=${report.success.objectCount}\nparts=${report.success.partCount}\nsolids=${report.success.solidCount}\nvolume=${report.success.volume}\nactiveAfterClose=${report.success.activeAfterClose}\nexpectedError=${report.expectedError.code}\ndeterministic=${report.repeat.deterministic}\nwasmSha256=${report.wasmSha256}\n`); console.log(JSON.stringify({ result: report.result, objects: report.success.objectCount, deterministic: report.repeat.deterministic }));