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

4 lines
4.0 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, "FreeCADWebMaterialKernelProbe.js"))); const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMaterialKernelProbe.wasm")) }); const c = (name, type = "number") => kernel.ccall(name, type); const run = () => ({ run: c("fc_web_material_save_reopen"), path: c("fc_web_material_persistence_path", "string"), size: c("fc_web_material_persistence_size"), objectCount: c("fc_web_material_persistence_object_count"), objectType: c("fc_web_material_persistence_object_type", "string"), propertyType: c("fc_web_material_persistence_property_type", "string"), uuid: c("fc_web_material_persistence_uuid", "string"), name: c("fc_web_material_persistence_name", "string"), code: c("fc_web_material_kernel_error_code", "string"), message: c("fc_web_material_kernel_error_message", "string") }); const first = run(); const second = run(); const semantic = (value) => ({ ...value, size: undefined }); const stable = JSON.stringify(semantic(first)) === JSON.stringify(semantic(second)); if (first.run !== 1 || second.run !== 1 || first.objectCount !== 1 || first.objectType !== "App::DocumentObjectGroup" || first.propertyType !== "App::Document::Comment+App::DocumentObject::Label" || first.uuid !== "material-web-fixture-v1" || first.name !== "Web Fixture Material" || !stable) throw new Error(JSON.stringify({ first, second, stable })); const report = { schema: "freecad-web-p6-material-action-04-kernel/v1", taskId: "FW-P6-MAT-ACT-04-C", module: "Material", action: "save/reopen", result: "pass", fixture: { module: "Material", objectType: first.objectType, propertyType: first.propertyType, uuid: first.uuid, name: first.name, inputSha256: crypto.createHash("sha256").update(JSON.stringify({ module: "Material", objectType: first.objectType, propertyType: first.propertyType, uuid: first.uuid, name: first.name })).digest("hex") }, replay: { first, second, identicalSemanticResult: stable, resultSha256: crypto.createHash("sha256").update(JSON.stringify(semantic(first))).digest("hex") }, resultSummary: { format: ".fcstd", path: first.path, objectCount: first.objectCount, objectType: first.objectType, propertyType: first.propertyType, uuid: first.uuid, name: first.name, roundTrip: true, resourcesReleased: true, materialPropertyRestore: false }, commands: ["cmake --build freecad-source/build-web/configure --target FreeCADWebMaterialKernelProbe -j 8", "node tools/run_p6_material_action04_kernel_smoke.mjs freecad-source/build-web/configure/bin"], artifacts: { wasm: "freecad-source/build-web/configure/bin/FreeCADWebMaterialKernelProbe.wasm", workerLog: "docs/freecad-p6-material-action-04-c-kernel.log" }, boundaries: ["FCStd round-trip persists Material UUID/name metadata through Document Comment and Label; Materials::PropertyMaterial restore is excluded because the GUI-free bundle has no material library mapping."] }; report.wasmSha256 = crypto.createHash("sha256").update(fs.readFileSync(path.join(build, "FreeCADWebMaterialKernelProbe.wasm"))).digest("hex"); fs.writeFileSync(path.join(root, "docs/p6/material-action-04-kernel.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-material-action-04-c-kernel.log"), `${JSON.stringify({ result: report.result, path: first.path, objectType: first.objectType, propertyType: first.propertyType, roundTrip: true, wasmSha256: report.wasmSha256 })}\n`); console.log(JSON.stringify({ result: report.result, path: first.path, objectType: first.objectType, propertyType: first.propertyType }));