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

22 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 build = path.resolve(process.argv[2] ?? path.join(root, "freecad-source/build-web/configure/bin"));
const docs = path.join(root, "docs/p6"); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url);
const loader = await import(pathToFileURL(path.join(build, "FreeCADWebPlotRuntimeProbe.js")));
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebPlotRuntimeProbe.wasm")), print: () => {}, printErr: () => {} });
const call = (name, type = "number") => kernel.ccall(name, type);
const run = () => ({ run: call("fc_web_plot_recovery"), error: call("fc_web_plot_recovery_error", "string"), before: call("fc_web_plot_recovery_series_before"), afterReject: call("fc_web_plot_recovery_series_after_reject"), afterValid: call("fc_web_plot_recovery_series_after_valid"), unchanged: call("fc_web_plot_recovery_unchanged"), repeatedStable: call("fc_web_plot_recovery_repeated_stable") });
const first = run(); const second = run();
const result = { first, second, deterministic: JSON.stringify(first) === JSON.stringify(second), pass: first.run === 1 && first.error === "plot series requires equally sized non-empty x and y values" && first.before === 1 && first.afterReject === 1 && first.afterValid === 2 && first.unchanged === 1 && first.repeatedStable === 1 };
const fixture = { module: "Plot", action: "python-api", invalid: { x: [0], y: [1, 2], expected: "ValueError" }, recovery: { x: [1, 2], y: [1, 4], expectedSeriesCount: 2 } };
const hash = value => crypto.createHash("sha256").update(value).digest("hex");
const report = { schema: "freecad-web-p6-plot-action-02-recovery/v1", taskId: "FW-P6-PLT-ACT-02-D", module: "Plot", action: "python-api", result: result.pass && result.deterministic ? "pass" : "fail", fixture: { ...fixture, inputSha256: hash(JSON.stringify(fixture)) }, details: result, resultSha256: hash(JSON.stringify(result)), recovery: { unchangedAfterReject: first.unchanged === 1, repeatedErrorStable: first.repeatedStable === 1, recoveredSeriesCount: first.afterValid }, commands: ["node tools/run_p6_plot_action02_recovery.mjs freecad-source/build-web/configure/bin"], boundaries: ["Invalid series length is rejected by the official Plot.py headless backend; no document state exists to mutate.", "Valid series can be added after rejection and produces deterministic data state."] };
fs.writeFileSync(path.join(docs, "plot-action-02-recovery.json"), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(path.join(root, "docs/freecad-p6-plot-action-02-d-recovery.log"), `${JSON.stringify({ result: report.result, deterministic: result.deterministic, unchangedAfterReject: first.unchanged === 1, repeatedErrorStable: first.repeatedStable === 1 })}\n`);
console.log(JSON.stringify({ result: report.result, deterministic: result.deterministic, unchangedAfterReject: first.unchanged === 1, repeatedErrorStable: first.repeatedStable === 1 }));
if (report.result !== "pass") process.exitCode = 1;