Files
FreeCADWasmDev/tools/run_p6_meshpart_runtime_smoke.mjs
wangdequan 9a7c4f0335 Save FreeCAD Web workspace sources and user validation evidence
IFC native binding remains incomplete; preserve accurate test results.
2026-09-15 22:01:58 +08:00

31 lines
4.1 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, "FreeCADWebMeshPartRuntimeProbe.js")));
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMeshPartRuntimeProbe.wasm")) });
const c = (name, type = "number", argTypes = [], args = []) => kernel.ccall(name, type, argTypes, args);
const initialize = (name) => ({ run: c("fc_web_meshpart_initialize", "number", ["string"], [name]), code: c("fc_web_meshpart_error_code", "string"), message: c("fc_web_meshpart_error_message", "string"), calls: c("fc_web_meshpart_initialization_calls"), runs: c("fc_web_meshpart_initialization_runs"), initialized: c("fc_web_meshpart_initialized") });
const first = initialize("MeshPart");
const repeated = initialize("MeshPart");
const type = { run: c("fc_web_meshpart_type_probe", "number", ["string"], ["MeshPart"]), code: c("fc_web_meshpart_error_code", "string") };
const create = { run: c("fc_web_meshpart_create_recompute"), facets: c("fc_web_meshpart_kernel_facets"), points: c("fc_web_meshpart_kernel_points"), resourcesReleased: c("fc_web_meshpart_kernel_resources_released"), code: c("fc_web_meshpart_kernel_error_code", "string"), message: c("fc_web_meshpart_kernel_error_message", "string") };
const missing = initialize("MeshPartMissing");
const gui = initialize("MeshPartGui");
const result = { first, repeated, type, create, missing, gui };
const stable = JSON.stringify(result);
if (first.run !== 1 || repeated.run !== 1 || first.runs !== 1 || repeated.runs !== 1 || type.run !== 1 || create.run !== 1 || create.facets <= 0 || create.points <= 0 || create.resourcesReleased !== 1 || missing.code !== "module_unavailable" || gui.code !== "gui_dependency_unavailable" || repeated.initialized !== 1) throw new Error(stable);
const report = { schema: "freecad-web-p6-meshpart-runtime/v1", taskId: "FW-P6-MSP-B", module: "MeshPart", result: "pass", resultSha256: crypto.createHash("sha256").update(stable).digest("hex"), responses: result, initialization: { calls: repeated.calls, runs: repeated.runs, idempotent: repeated.runs === 1 }, dependencies: { part: true, mesh: true, smesh: false, netgen: false, gui: false }, commands: ["EM_CACHE=/tmp/freecad-emscripten-cache cmake -S . -B build-web/configure -DFREECAD_WEB_ENABLE_MESHPART=ON", "EM_CACHE=/tmp/freecad-emscripten-cache cmake --build build-web/configure --target FreeCADWebMeshPartRuntimeProbe -j 8", "node tools/run_p6_meshpart_runtime_smoke.mjs freecad-source/build-web/configure/bin"], artifacts: { wasm: "freecad-source/build-web/configure/bin/FreeCADWebMeshPartRuntimeProbe.wasm", workerLog: "docs/freecad-p6-meshpart-b-runtime.log" }, boundaries: ["Runtime covers GUI-free MeshPart initialization and the standard OCC-backed shape-to-mesh action; SMESH/VTK, NETGEN, flatmesh, and MeshPartGui remain disabled."] };
report.wasmSha256 = crypto.createHash("sha256").update(fs.readFileSync(path.join(build, "FreeCADWebMeshPartRuntimeProbe.wasm"))).digest("hex");
fs.writeFileSync(path.join(docs, "meshpart-runtime.json"), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(path.join(root, "docs/freecad-p6-meshpart-b-runtime.log"), `${JSON.stringify({ result: report.result, initializationRuns: report.initialization.runs, typeProbe: report.responses.type.run, facets: create.facets, points: create.points, missingCode: report.responses.missing.code, guiCode: report.responses.gui.code, smesh: false, wasmSha256: report.wasmSha256 })}\n`);
console.log(JSON.stringify({ result: report.result, initializationRuns: report.initialization.runs, typeProbe: report.responses.type.run, facets: create.facets, points: create.points, smesh: false, wasmSha256: report.wasmSha256 }));