#!/usr/bin/env node import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; import { createRequire } from "node:module"; import { pathToFileURL } from "node:url"; const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), ".."); const build = path.resolve(process.argv[2] ?? path.join(root, "freecad-source/build-web/configure/bin")); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url); const loader = await import(pathToFileURL(path.join(build, "FreeCADWebMaterialKernelProbe.js"))); const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMaterialKernelProbe.wasm")) }); const call = (name, type = "number") => kernel.ccall(name, type); const run = () => ({ run: call("fc_web_material_create_recompute"), document: call("fc_web_material_kernel_document", "string"), object: call("fc_web_material_kernel_object", "string"), propertyType: call("fc_web_material_kernel_property_type", "string"), uuid: call("fc_web_material_kernel_uuid", "string"), name: call("fc_web_material_kernel_name", "string"), objectCount: call("fc_web_material_kernel_object_count"), recompute: call("fc_web_material_kernel_recompute"), hasError: call("fc_web_material_kernel_has_error"), resourcesReleased: call("fc_web_material_kernel_resources_released"), code: call("fc_web_material_kernel_error_code", "string"), message: call("fc_web_material_kernel_error_message", "string"), }); const first = run(); const second = run(); const stable = JSON.stringify(first) === JSON.stringify(second); if (first.run !== 1 || second.run !== 1 || first.document !== "MaterialKernel" || first.object !== "MaterialFeature" || first.propertyType !== "Materials::PropertyMaterial" || first.uuid !== "material-web-fixture-v1" || first.name !== "Web Fixture Material" || first.objectCount !== 1 || first.recompute < 0 || first.hasError !== 0 || first.resourcesReleased !== 1 || !stable) throw new Error(JSON.stringify({ first, second, stable })); const report = { schema: "freecad-web-p6-material-kernel/v1", taskId: "FW-P6-MAT-C", module: "Material", action: "create/recompute", result: "pass", fixture: { module: "Material", objectType: "App::FeaturePython", propertyType: "Materials::PropertyMaterial", uuid: "material-web-fixture-v1", name: "Web Fixture Material", inputSha256: crypto.createHash("sha256").update(JSON.stringify({ module: "Material", objectType: "App::FeaturePython", propertyType: "Materials::PropertyMaterial", uuid: "material-web-fixture-v1", name: "Web Fixture Material" })).digest("hex") }, replay: { first, second, identicalResult: stable, resultSha256: crypto.createHash("sha256").update(JSON.stringify(first)).digest("hex") }, resultSummary: { document: first.document, object: first.object, objectCount: first.objectCount, objectType: "App::FeaturePython", propertyType: first.propertyType, materialUuid: first.uuid, materialName: first.name, recompute: first.recompute, hasError: first.hasError, resourcesReleased: first.resourcesReleased === 1 }, commands: [ "cmake --build freecad-source/build-web/configure --target FreeCADWebMaterialKernelProbe -j 8", "node tools/run_p6_material_kernel_smoke.mjs freecad-source/build-web/configure/bin", ], artifacts: { wasm: "freecad-source/build-web/configure/bin/FreeCADWebMaterialKernelProbe.wasm", workerLog: "docs/freecad-p6-material-c-kernel.log" }, boundaries: ["Only one App::FeaturePython with a Materials::PropertyMaterial fixture is covered; no GUI material editor or external library is used."], }; report.wasmSha256 = crypto.createHash("sha256").update(fs.readFileSync(path.join(build, "FreeCADWebMaterialKernelProbe.wasm"))).digest("hex"); fs.writeFileSync(path.join(root, "docs/p6/material-kernel.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-material-c-kernel.log"), `${JSON.stringify({ result: report.result, objectType: report.resultSummary.objectType, propertyType: report.resultSummary.propertyType, recompute: report.resultSummary.recompute, resourcesReleased: report.resultSummary.resourcesReleased, wasmSha256: report.wasmSha256 })}\n`); console.log(JSON.stringify({ result: report.result, objectType: report.resultSummary.objectType, propertyType: report.resultSummary.propertyType, resourcesReleased: report.resultSummary.resourcesReleased }));