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

3 lines
3.8 KiB
JavaScript

import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; import { createRequire } from "node:module"; import { fileURLToPath, pathToFileURL } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const build = path.resolve(process.argv[2] ?? path.join(root, "freecad-source/build-web/configure/bin")); const docs = path.join(root, "docs/p6"); const runtime = JSON.parse(fs.readFileSync(path.join(docs, "partdesign-runtime.json"), "utf8")); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url); const loader = await import(pathToFileURL(path.join(build, "FreeCADWebPartDesignRuntimeProbe.js"))); const probe = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebPartDesignRuntimeProbe.wasm")) }); const call = (name, type = "number") => probe.ccall(name, type); const run = () => ({ run: call("fc_web_partdesign_save_reopen"), error: call("fc_web_partdesign_persistence_error", "string"), path: call("fc_web_partdesign_persistence_path", "string"), objectType: call("fc_web_partdesign_persistence_object_type", "string"), beforeVolume: call("fc_web_partdesign_persistence_before_volume"), afterVolume: call("fc_web_partdesign_persistence_after_volume"), size: call("fc_web_partdesign_persistence_size"), objectCount: call("fc_web_partdesign_persistence_object_count") }); const first = run(); const second = run(); const stable = (value) => ({ run: value.run, error: value.error, path: value.path, objectType: value.objectType, beforeVolume: value.beforeVolume, afterVolume: value.afterVolume, objectCount: value.objectCount }); const result = { first, second, deterministic: JSON.stringify(stable(first)) === JSON.stringify(stable(second)), roundTrip: first.run === 1 && first.error === "" && first.path === "/tmp/PartDesignWeb.FCStd" && first.objectType === "PartDesign::Feature" && first.size > 0 && first.objectCount === 2 && Math.abs(first.beforeVolume - first.afterVolume) < 1e-9 && Math.abs(first.afterVolume - 24) < 1e-9 }; if (!result.roundTrip || !result.deterministic) throw new Error(JSON.stringify(result)); const fixture = { module: "PartDesign", action: "save/reopen", path: "/tmp/PartDesignWeb.FCStd", objectType: "PartDesign::Feature", dimensions: [2, 3, 4] }; const wasmPath = path.join(build, "FreeCADWebPartDesignRuntimeProbe.wasm"); const report = { schema: "freecad-web-partdesign-action-04-kernel/v1", task_id: "FW-P6-PDN-ACT-04-C", module: "PartDesign", action: "save/reopen", status: "pass", source_revision: runtime.source_revision, input_sha256: crypto.createHash("sha256").update(JSON.stringify(fixture)).digest("hex"), result, result_sha256: crypto.createHash("sha256").update(JSON.stringify(result)).digest("hex"), commands: ["node tools/run_p6_partdesign_action04_kernel.mjs freecad-source/build-web/configure/bin"], artifacts: { runtime: "docs/p6/partdesign-runtime.json", wasm: { path: "freecad-source/build-web/configure/bin/FreeCADWebPartDesignRuntimeProbe.wasm", sha256: crypto.createHash("sha256").update(fs.readFileSync(wasmPath)).digest("hex") } }, boundaries: ["The native probe owns FCStd save/reopen and closes both documents before returning.", "The fixture is a PartDesign::Feature carrying a 2x3x4 native shape; AdditiveBox/BaseFeature persistence remains an explicit unsupported boundary in this Web slice."] }; fs.writeFileSync(path.join(docs, "partdesign-action-04-kernel.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-partdesign-action-04-c-kernel.log"), `${JSON.stringify({ status: report.status, roundTrip: result.roundTrip, deterministic: result.deterministic, resultSha256: report.result_sha256 })}\n`); console.log(JSON.stringify({ status: report.status, roundTrip: result.roundTrip, deterministic: result.deterministic, resultSha256: report.result_sha256 }));