71 lines
3.5 KiB
JavaScript
71 lines
3.5 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_create_recompute"),
|
|
objectType: call("fc_web_mesh_kernel_object_type", "string"),
|
|
facets: call("fc_web_mesh_kernel_facets"),
|
|
points: call("fc_web_mesh_kernel_points"),
|
|
resourcesReleased: call("fc_web_mesh_kernel_resources_released"),
|
|
code: call("fc_web_mesh_kernel_error_code", "string"),
|
|
message: call("fc_web_mesh_kernel_error_message", "string"),
|
|
});
|
|
const fixture = {
|
|
module: "Mesh",
|
|
action: "create/recompute",
|
|
objectType: "Mesh::Feature",
|
|
facets: [{ points: [[0, 0, 0], [1, 0, 0], [0, 1, 0]] }],
|
|
};
|
|
const first = run();
|
|
const second = run();
|
|
const stable = JSON.stringify(first) === JSON.stringify(second);
|
|
if (first.run !== 1 || second.run !== 1 || first.objectType !== "Mesh::Feature" || first.facets !== 1 || first.points !== 3 || first.resourcesReleased !== 1 || first.code !== "" || !stable) {
|
|
throw new Error(JSON.stringify({ first, second, stable }));
|
|
}
|
|
const report = {
|
|
schema: "freecad-web-p6-mesh-kernel/v1",
|
|
taskId: "FW-P6-MSH-C",
|
|
module: "Mesh",
|
|
action: "create/recompute",
|
|
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: {
|
|
objectType: first.objectType,
|
|
objectCount: 1,
|
|
facetCount: first.facets,
|
|
pointCount: first.points,
|
|
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_kernel_smoke.mjs freecad-source/build-web/configure/bin",
|
|
],
|
|
artifacts: {
|
|
wasm: "freecad-source/build-web/configure/bin/FreeCADWebMeshRuntimeProbe.wasm",
|
|
workerLog: "docs/freecad-p6-mesh-c-kernel.log",
|
|
},
|
|
boundaries: ["Only one source-backed Mesh::Feature triangle fixture is covered; import/export, repair, transforms, and GUI commands remain out of scope."],
|
|
};
|
|
report.wasmSha256 = crypto.createHash("sha256").update(fs.readFileSync(path.join(build, "FreeCADWebMeshRuntimeProbe.wasm"))).digest("hex");
|
|
fs.writeFileSync(path.join(docs, "mesh-kernel.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "docs/freecad-p6-mesh-c-kernel.log"), `${JSON.stringify({ result: report.result, objectType: first.objectType, facets: first.facets, points: first.points, resourcesReleased: true, wasmSha256: report.wasmSha256 })}\n`);
|
|
console.log(JSON.stringify({ result: report.result, objectType: first.objectType, facets: first.facets, points: first.points, resourcesReleased: true }));
|