Files
FreeCADWasmDev/tools/run_p6_show_recovery.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.2 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")); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url); const loader = await import(pathToFileURL(path.join(build, "FreeCADWebShowRuntimeProbe.js"))); const probe = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebShowRuntimeProbe.wasm")), print: () => {}, printErr: () => {} }); const c = (name, type = "number", argTypes = [], args = []) => probe.ccall(name, type, argTypes, args); const entry = "src/Mod/Show/__init__.py"; const valid = () => ({ valid: c("fc_web_show_source_inventory_validate", "number", ["string"], [entry]), api: c("fc_web_show_python_api_validate", "number", ["string"], [entry]), count: c("fc_web_show_python_api_count"), available: c("fc_web_show_module_available"), released: c("fc_web_show_resources_released"), error: c("fc_web_show_last_error", "string") }); const before = valid(); const invalid = { valid: c("fc_web_show_source_inventory_validate", "number", ["string"], ["src/Mod/Show/Missing.py"]), error: c("fc_web_show_last_error", "string") }; const repeated = { valid: c("fc_web_show_source_inventory_validate", "number", ["string"], ["src/Mod/Show/Missing.py"]), error: c("fc_web_show_last_error", "string") }; const after = valid(); const stable = value => ({ valid: value.valid, api: value.api, count: value.count, available: value.available, released: value.released }); const beforeHash = crypto.createHash("sha256").update(JSON.stringify(stable(before))).digest("hex"); const afterHash = crypto.createHash("sha256").update(JSON.stringify(stable(after))).digest("hex"); const report = { schema: "freecad-web-p6-show-recovery/v1", taskId: "FW-P6-SHW-D", module: "Show", action: "inspect/source-inventory", result: before.valid === 1 && before.api === 1 && invalid.valid === 0 && invalid.error === "revision_mismatch" && repeated.valid === 0 && repeated.error === invalid.error && after.valid === 1 && beforeHash === afterHash ? "pass" : "fail", before, invalid, repeated, after, recovery: { beforeHash, afterHash, unchangedAfterReject: beforeHash === afterHash, repeatedErrorStable: invalid.error === repeated.error }, artifacts: { kernel: "docs/p6/show-kernel.json", workerLog: "docs/freecad-p6-show-d-recovery.log" }, boundaries: ["Unknown source entry is rejected before mutation; the real Show runtime remains usable afterward."] }; fs.writeFileSync(path.join(docs, "show-recovery.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-show-d-recovery.log"), `${JSON.stringify({ result: report.result, invalidError: invalid.error, unchangedAfterReject: report.recovery.unchangedAfterReject })}\n`); console.log(JSON.stringify({ result: report.result, invalidError: invalid.error, unchangedAfterReject: report.recovery.unchangedAfterReject })); if (report.result !== "pass") process.exitCode = 1;