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

62 lines
4.7 KiB
JavaScript

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"));
const fixture = { module: "Robot", action: "save/reopen", format: "FCStd", path: "/tmp/RobotAction04.FCStd", objectType: "Robot::RobotObject", axis1: 15, axis2: -10 };
const inputSha256 = crypto.createHash("sha256").update(JSON.stringify(fixture)).digest("hex");
globalThis.__dirname = `${build}${path.sep}`;
globalThis.require = createRequire(import.meta.url);
const loader = await import(pathToFileURL(path.join(build, "FreeCADWebRobotRuntimeProbe.js")));
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebRobotRuntimeProbe.wasm")), print: () => {}, printErr: () => {} });
const c = (name, type = "number", argTypes = [], args = []) => kernel.ccall(name, type, argTypes, args);
const run = () => {
const configured = c("fc_web_robot_persistence_set_path", "number", ["string"], [fixture.path]);
const result = {
configured,
run: c("fc_web_robot_save_reopen"),
error: c("fc_web_robot_persistence_error", "string"),
path: c("fc_web_robot_persistence_path", "string"),
size: c("fc_web_robot_persistence_size"),
objectType: c("fc_web_robot_persistence_object_type", "string"),
objectCount: c("fc_web_robot_persistence_object_count"),
resourcesReleased: c("fc_web_robot_persistence_resources_released"),
beforeAxis1: c("fc_web_robot_persistence_before_axis1"),
afterAxis1: c("fc_web_robot_persistence_after_axis1"),
beforeAxis2: c("fc_web_robot_persistence_before_axis2"),
afterAxis2: c("fc_web_robot_persistence_after_axis2"),
};
return result;
};
const first = run();
const second = run();
const semantic = value => ({ run: value.run, error: value.error, path: value.path, objectType: value.objectType, objectCount: value.objectCount, resourcesReleased: value.resourcesReleased, beforeAxis1: value.beforeAxis1, afterAxis1: value.afterAxis1, beforeAxis2: value.beforeAxis2, afterAxis2: value.afterAxis2 });
const deterministic = JSON.stringify(semantic(first)) === JSON.stringify(semantic(second));
const roundTrip = first.configured === 1 && first.run === 1 && first.error === "" && first.path === fixture.path && first.size > 0 && first.objectType === fixture.objectType && first.objectCount === 1 && first.resourcesReleased === 1 && first.beforeAxis1 === fixture.axis1 && first.afterAxis1 === fixture.axis1 && first.beforeAxis2 === fixture.axis2 && first.afterAxis2 === fixture.axis2;
const report = {
schema: "freecad-web-p6-robot-action-04-kernel/v1",
taskId: "FW-P6-ROB-ACT-04-C",
module: "Robot",
action: "save/reopen",
result: roundTrip && deterministic ? "pass" : "fail",
fixture: { ...fixture, inputSha256 },
first,
second,
deterministic,
roundTrip,
source: { save: "src/Mod/Robot/App/RobotObject.cpp::RobotObject::Save", restore: "src/Mod/Robot/App/RobotObject.cpp::RobotObject::Restore", probe: "freecad-source/src/WebAssembly/FreeCADCoreProbe/RobotRuntimeProbeFixed.cpp", wasm: "freecad-source/build-web/configure/bin/FreeCADWebRobotRuntimeProbe.wasm", wasmSha256: crypto.createHash("sha256").update(fs.readFileSync(path.join(build, "FreeCADWebRobotRuntimeProbe.wasm"))).digest("hex") },
resultSha256: crypto.createHash("sha256").update(JSON.stringify({ first: semantic(first), second: semantic(second), deterministic, roundTrip })).digest("hex"),
commands: ["EM_CACHE=/tmp/freecad-p6-emcache ninja -C freecad-source/build-web/configure FreeCADWebRobotRuntimeProbe -j8", "node tools/run_p6_robot_action04_kernel.mjs freecad-source/build-web/configure/bin"],
artifacts: { wasm: "freecad-source/build-web/configure/bin/FreeCADWebRobotRuntimeProbe.wasm", log: "docs/freecad-p6-robot-action-04-c-kernel.log" },
boundaries: ["Native RobotObject::Save/Restore is exercised through App::Document FCStd serialization.", "Cross-version migration and arbitrary external paths remain out of scope."],
};
fs.mkdirSync(docs, { recursive: true });
fs.writeFileSync(path.join(docs, "robot-action-04-kernel.json"), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(path.join(root, "docs/freecad-p6-robot-action-04-c-kernel.log"), `${JSON.stringify({ result: report.result, roundTrip, deterministic, path: first.path, size: first.size, objectType: first.objectType, objectCount: first.objectCount })}\n`);
console.log(JSON.stringify({ result: report.result, roundTrip, deterministic, path: first.path, size: first.size, objectType: first.objectType }));
if (report.result !== "pass") process.exitCode = 1;