Files
FreeCADWasmDev/tools/run_p6_partdesign_geometry_family_native.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

39 lines
2.8 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, fileURLToPath } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const docs = path.join(root, "docs", "p6");
const build = path.resolve(process.argv[2] ?? path.join(root, "freecad-source", "build-web", "configure", "bin"));
const inventoryPath = path.join(docs, "partdesign-geometry-family-kernel.json");
const inventory = JSON.parse(fs.readFileSync(inventoryPath, "utf8"));
globalThis.__dirname = `${build}${path.sep}`;
globalThis.require = createRequire(import.meta.url);
const loader = await import(pathToFileURL(path.join(build, "FreeCADWebPartDesignRuntimeProbe.js")));
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebPartDesignRuntimeProbe.wasm")) });
const request = { cmd: "partdesign.geometryFamily", args: { records: inventory.records.map((record) => ({ name: record.name })) } };
const raw = String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify(request)]));
const result = JSON.parse(raw);
if (result.ok !== true || result.cmd !== request.cmd || result.module !== "PartDesign" || result.source !== "freecad-source" || result.count !== request.args.records.length || result.resourcesReleased !== true || !Array.isArray(result.records) || result.records.length !== request.args.records.length) {
throw new Error(`PartDesign geometry dispatcher contract failed: ${raw}`);
}
const counts = Object.fromEntries(["passed", "blocked"].map((status) => [status, result.records.filter((record) => record.status === status).length]));
const report = {
schema: "freecad-web-p6-partdesign-geometry-family-native/v1",
taskId: "FW-P6-FPA-IMPL-PARTDESIGN-GEOMETRY-FAMILY",
result: counts.blocked === 0 ? "pass" : "pass_with_blocked_records",
command: request.cmd,
build: path.relative(root, build),
inventorySha256: crypto.createHash("sha256").update(fs.readFileSync(inventoryPath)).digest("hex"),
coverage: { inventoryRecords: request.args.records.length, nativeRecords: result.records.length, counts, resourcesReleased: result.resourcesReleased },
records: result.records,
source: "freecad-source",
boundaries: ["Every result is returned by FreeCADWebPartDesignProbe through fc_web_dispatch_json.", "A blocked record retains the native first error and is not promoted by this smoke."]
};
fs.writeFileSync(path.join(docs, "partdesign-geometry-family-native.json"), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(path.join(root, "docs", "freecad-p6-partdesign-geometry-family-native.log"), `${JSON.stringify({ result: report.result, counts, inventorySha256: report.inventorySha256 })}\n`);
console.log(JSON.stringify({ result: report.result, counts, records: result.records.length }));