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

34 lines
4.1 KiB
JavaScript

#!/usr/bin/env node
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import os from "node:os";
import { createRequire } from "node:module";
import { pathToFileURL } from "node:url";
const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..");
const batch = JSON.parse(fs.readFileSync(path.join(root, "docs/current/module-batch-manifest.json"), "utf8"));
const build = path.join(root, "freecad-source/build-web/configure/bin");
const staged = fs.mkdtempSync(path.join(os.tmpdir(), "freecad-measure-batch-"));
for (const name of fs.readdirSync(build).filter(name => name.startsWith("FreeCADWebMeasureKernelProbe."))) fs.copyFileSync(path.join(build, name), path.join(staged, name));
const record = batch.records[0];
if (!record || batch.selected?.module !== "Measure" || batch.selected?.tier !== "object-contract" || batch.selected?.family !== "data-property") throw new Error("unexpected Measure batch manifest");
const input = { id: record[0], name: record[1] };
globalThis.__dirname = `${staged}${path.sep}`;
globalThis.require = createRequire(import.meta.url);
const loader = await import(pathToFileURL(path.join(staged, "FreeCADWebMeasureKernelProbe.js")));
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMeasureKernelProbe.wasm")) });
const request = { cmd: "measure.objectFamily", args: { records: [input] } };
const dispatch = () => JSON.parse(String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify(request)])));
const first = dispatch();
const second = dispatch();
if (first.ok !== true || first.count !== 1 || first.resourcesReleased !== true || first.records?.[0]?.status !== "passed_boundary") throw new Error(`Measure Measurement boundary failed: ${JSON.stringify(first)}`);
if (JSON.stringify(first) !== JSON.stringify(second)) throw new Error("Measure Measurement replay changed native result");
const hash = value => crypto.createHash("sha256").update(typeof value === "string" ? value : JSON.stringify(value)).digest("hex");
const report = { schema: "freecad-web-measure-object-contract-module-batch-runtime/v1", taskId: "FW-P6-FPA-Y", batchId: batch.batchId, module: "Measure", tier: "object-contract", family: "data-property", status: "pass_with_boundaries", dispatcher: "fc_web_dispatch_json", route: { command: "measure.objectFamily", native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/MeasureKernelProbe.cpp:fc_web_dispatch_json", facade: "web/src/measure-object-family-facade.ts", worker: "web/src/measure.worker.ts", loader: "web/src/module-loader.ts" }, artifacts: { module: "Measure", worker: "measure.worker.ts", revision: hash(fs.readFileSync(path.join(build, "FreeCADWebMeasureKernelProbe.wasm"))).slice(0, 16), runtimeUrl: "/kernel/FreeCADWebMeasureKernelProbe.js", wasmUrl: "/kernel/FreeCADWebMeasureKernelProbe.wasm", dataUrl: null, assetBaseUrl: "/kernel/", runtimeSha256: hash(fs.readFileSync(path.join(build, "FreeCADWebMeasureKernelProbe.js"))), wasmSha256: hash(fs.readFileSync(path.join(build, "FreeCADWebMeasureKernelProbe.wasm"))), buildProfile: "fast-dev" }, input: request, inputSha256: hash(request), result: first, resultSha256: hash(first), replay: { equal: true, resultSha256: hash(second) }, dispositionCounts: { passed: 0, passedBoundary: 1, blocked: 0 }, records: first.records, resources: { resourcesReleased: true }, boundaries: ["Measure::Measurement is registered natively but is not an App::DocumentObject; this object-contract record is explicitly passed_boundary.", "All values and status come from compiled FreeCAD through measure.objectFamily and fc_web_dispatch_json."] };
const evidence = path.join(root, `docs/p6/measure-data-property-module-batch-${batch.batchId}-runtime.json`);
fs.writeFileSync(evidence, JSON.stringify(report, null, 2) + "\n");
fs.writeFileSync(path.join(root, `docs/freecad-p6-measure-data-property-module-batch-${batch.batchId}.log`), JSON.stringify({ status: report.status, batchId: batch.batchId, resultSha256: report.resultSha256 }) + "\n");
console.log(JSON.stringify({ status: report.status, batchId: batch.batchId, resultSha256: report.resultSha256 }));
process.exit(0);