22 lines
3.4 KiB
JavaScript
22 lines
3.4 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_save_reopen"), path: call("fc_web_mesh_persistence_path", "string"), size: call("fc_web_mesh_persistence_size"), objectCount: call("fc_web_mesh_persistence_object_count"), objectType: call("fc_web_mesh_persistence_object_type", "string"), facets: call("fc_web_mesh_persistence_facets"), points: call("fc_web_mesh_persistence_points"), roundTrip: call("fc_web_mesh_persistence_round_trip"), code: call("fc_web_mesh_persistence_error_code", "string"), message: call("fc_web_mesh_persistence_error_message", "string") });
|
|
const first = run(); const second = run(); const stable = JSON.stringify({ ...first, path: "", size: 0 }) === JSON.stringify({ ...second, path: "", size: 0 });
|
|
const fixture = { module: "Mesh", action: "save/reopen", format: "FCStd", objectType: "Mesh::Feature", facets: 1, points: 3 };
|
|
if (first.run !== 1 || second.run !== 1 || first.size <= 0 || first.objectCount !== 1 || first.objectType !== "Mesh::Feature" || first.facets !== 1 || first.points !== 3 || first.roundTrip !== 1 || !stable) throw new Error(JSON.stringify({ first, second, stable }));
|
|
const report = { schema: "freecad-web-p6-mesh-action-05-kernel/v1", taskId: "FW-P6-MSH-ACT-05-C", module: "Mesh", action: "save/reopen", 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, path: "", size: 0 })).digest("hex") }, resultSummary: { format: "FCStd", path: first.path, size: first.size, objectCount: first.objectCount, objectType: first.objectType, facetCount: first.facets, pointCount: first.points, roundTrip: true, resourcesReleased: true }, commands: ["node tools/run_p6_mesh_action05_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-05-c-kernel.log" }, boundaries: ["Native FCStd round-trip covers one Mesh::Feature triangle and its Mesh property; cross-version migration remains out of scope."] };
|
|
fs.writeFileSync(path.join(docs, "mesh-action-05-kernel.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "docs/freecad-p6-mesh-action-05-c-kernel.log"), `${JSON.stringify({ result: report.result, format: "FCStd", size: first.size, objectCount: first.objectCount, facets: first.facets, points: first.points, roundTrip: true })}\n`);
|
|
console.log(JSON.stringify({ result: report.result, size: first.size, objectType: first.objectType, facets: first.facets, points: first.points }));
|