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

30 lines
3.5 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 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, "FreeCADWebMaterialPythonKernelProbe.js")));
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMaterialPythonKernelProbe.wasm")) });
const call = (name, type = "number") => kernel.ccall(name, type);
const run = () => {
const result = call("fc_web_material_python_api");
const uuid = call("fc_web_material_python_uuid", "string");
return { run: result, name: call("fc_web_material_python_name", "string"), uuidPresent: uuid.length > 0, uuidLength: uuid.length, resourcesReleased: call("fc_web_material_python_resources_released"), code: call("fc_web_material_python_error_code", "string"), message: call("fc_web_material_python_error_message", "string") };
};
const first = run();
const second = run();
const semantic = (value) => ({ ...value, uuidLength: undefined });
const stable = JSON.stringify(semantic(first)) === JSON.stringify(semantic(second));
if (first.run !== 1 || second.run !== 1 || first.name !== "Web Python Fixture" || !first.uuidPresent || first.resourcesReleased !== 1 || !stable) throw new Error(JSON.stringify({ first, second, stable }));
const report = { schema: "freecad-web-p6-material-action-03-kernel/v1", taskId: "FW-P6-MAT-ACT-03-C", module: "Material", action: "python-api", result: "pass", fixture: { module: "Material", api: ["Material", "Name", "UUID"], name: "Web Python Fixture", inputSha256: crypto.createHash("sha256").update(JSON.stringify({ module: "Material", api: ["Material", "Name", "UUID"], name: "Web Python Fixture" })).digest("hex") }, replay: { first, second, identicalSemanticResult: stable, resultSha256: crypto.createHash("sha256").update(JSON.stringify(semantic(first))).digest("hex") }, resultSummary: { pythonModule: "Materials", type: "Material", name: first.name, uuidPresent: true, resourcesReleased: true }, commands: ["cmake --build freecad-source/build-web/configure --target FreeCADWebMaterialPythonKernelProbe -j 8", "node tools/run_p6_material_action03_kernel_smoke.mjs freecad-source/build-web/configure/bin"], artifacts: { wasm: "freecad-source/build-web/configure/bin/FreeCADWebMaterialPythonKernelProbe.wasm", workerLog: "docs/freecad-p6-material-action-03-c-kernel.log" }, boundaries: ["UUID is generated by the native Material constructor and is reported only as presence/length; semantic replay compares stable name/API fields."] };
report.wasmSha256 = crypto.createHash("sha256").update(fs.readFileSync(path.join(build, "FreeCADWebMaterialPythonKernelProbe.wasm"))).digest("hex");
fs.writeFileSync(path.join(root, "docs/p6/material-action-03-kernel.json"), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(path.join(root, "docs/freecad-p6-material-action-03-c-kernel.log"), `${JSON.stringify({ result: report.result, name: first.name, uuidPresent: first.uuidPresent, resourcesReleased: true, wasmSha256: report.wasmSha256 })}\n`);
console.log(JSON.stringify({ result: report.result, name: first.name, uuidPresent: first.uuidPresent, resourcesReleased: true }));