8 lines
3.3 KiB
JavaScript
8 lines
3.3 KiB
JavaScript
#!/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 docs = path.join(root, "docs/p6"); 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, "FreeCADWebMeshRuntimeProbe.js"))); const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMeshRuntimeProbe.wasm")) }); const call = (name, type = "number") => kernel.ccall(name, type); const run = () => ({ run: call("fc_web_mesh_import_export"), path: call("fc_web_mesh_io_path", "string"), exportBytes: call("fc_web_mesh_io_export_bytes"), importedFacets: call("fc_web_mesh_io_imported_facets"), importedPoints: call("fc_web_mesh_io_imported_points"), resourcesReleased: call("fc_web_mesh_io_resources_released"), code: call("fc_web_mesh_io_error_code", "string"), message: call("fc_web_mesh_io_error_message", "string") }); const fixture = { module: "Mesh", action: "import/export", format: "STL", sourceFacets: 1, sourcePoints: 3 }; const first = run(); const second = run(); const stable = JSON.stringify(first) === JSON.stringify(second); if (first.run !== 1 || second.run !== 1 || first.exportBytes <= 0 || first.importedFacets !== 1 || first.importedPoints !== 3 || first.resourcesReleased !== 1 || first.code !== "" || !stable) throw new Error(JSON.stringify({ first, second, stable })); const report = { schema: "freecad-web-p6-mesh-action-02-kernel/v1", taskId: "FW-P6-MSH-ACT-02-C", module: "Mesh", action: "import/export", result: "pass", fixture: { ...fixture, inputSha256: crypto.createHash("sha256").update(JSON.stringify(fixture)).digest("hex") }, replay: { first, second, identicalResult: stable, resultSha256: crypto.createHash("sha256").update(JSON.stringify(first)).digest("hex") }, resultSummary: { format: "STL", path: first.path, exportBytes: first.exportBytes, importedFacetCount: first.importedFacets, importedPointCount: first.importedPoints, resourcesReleased: true }, commands: ["EM_CACHE=/tmp/freecad-emscripten-cache cmake --build freecad-source/build-web/configure --target FreeCADWebMeshRuntimeProbe -j 8", "node tools/run_p6_mesh_action02_kernel_smoke.mjs freecad-source/build-web/configure/bin"], artifacts: { wasm: "freecad-source/build-web/configure/bin/FreeCADWebMeshRuntimeProbe.wasm", workerLog: "docs/freecad-p6-mesh-action-02-c-kernel.log" }, boundaries: ["The deterministic STL round-trip uses native MeshObject save/load; other mesh formats and GUI dialogs remain out of scope."] }; fs.writeFileSync(path.join(docs, "mesh-action-02-kernel.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-mesh-action-02-c-kernel.log"), `${JSON.stringify({ result: report.result, format: "STL", exportBytes: first.exportBytes, importedFacets: first.importedFacets, importedPoints: first.importedPoints, resourcesReleased: true })}\n`); console.log(JSON.stringify({ result: report.result, format: "STL", exportBytes: first.exportBytes, importedFacets: first.importedFacets, importedPoints: first.importedPoints }));
|