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

70 lines
6.3 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 = "/home/mes123456/FreeCADWasmDev/working/FreeCAD";
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, "FreeCADWebPlotRuntimeProbe.js")).href);
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebPlotRuntimeProbe.wasm")), print: () => {}, printErr: () => {} });
const manifestPath = path.join(root, "docs/p6/python-api-manifest.json");
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
const records = manifest.records.filter((row) => row.module === "Plot" && row.tier === "tier-1-readonly").map((row) => ({ apiId: row.id, name: row.name, family: row.family, sourcePath: row.evidence?.path, disposition: row.disposition }));
if (records.length !== 7) throw new Error(`expected 7 Plot records, got ${records.length}`);
const request = { cmd: "plot.pythonFamilyBatch", args: { tier: "tier-1-readonly", records } };
const invoke = (value) => JSON.parse(String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify(value)])));
const success = invoke(request);
const repeated = invoke(request);
const crossModule = invoke({ cmd: request.cmd, args: { tier: request.args.tier, records: [{ ...records[0], apiId: "py:BIM:class:Binding" }] } });
const malformed = invoke({ cmd: request.cmd, args: { tier: "tier-2-pure", records: [records[0]] } });
if (success.ok !== true || success.module !== "Plot" || success.count !== records.length || success.resourcesReleased !== true || !Array.isArray(success.records) || success.records.length !== records.length) throw new Error("Plot family dispatch did not return a complete result");
const terminal = new Set(["exposed", "restricted", "nonportable", "not_implemented"]);
if (success.records.some((record) => !terminal.has(record.status) || record.native !== true || record.resourcesReleased !== true || !record.sourceEntry || !record.sourceRevision)) throw new Error("Plot family result contains a non-terminal or non-native record");
const dispositionCounts = Object.fromEntries([...terminal].map((status) => [status, success.records.filter((record) => record.status === status).length]));
if (dispositionCounts.exposed !== 5 || dispositionCounts.restricted !== 2 || dispositionCounts.nonportable !== 0 || dispositionCounts.not_implemented !== 0) throw new Error(`unexpected Plot disposition counts: ${JSON.stringify(dispositionCounts)}`);
if (JSON.stringify(repeated) !== JSON.stringify(success)) throw new Error("Plot family replay changed the native result");
if (crossModule.records?.[0]?.status !== "not_implemented" || crossModule.records?.[0]?.code !== "unmatched_source_record") throw new Error("Plot cross-module boundary failed");
if (malformed.ok !== false || malformed.code !== "invalid_request") throw new Error("Plot invalid tier was not rejected");
const hash = (value) => crypto.createHash("sha256").update(JSON.stringify(value)).digest("hex");
const fileHash = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
const byId = new Map(success.records.map((record) => [record.apiId, record]));
for (const row of manifest.records) {
if (row.module !== "Plot" || row.tier !== "tier-1-readonly") continue;
const native = byId.get(row.id);
if (!native) throw new Error(`native result missing ${row.id}`);
row.disposition = native.status;
row.dispositionEvidence = ["docs/p6/plot-tier1-readonly-family-runtime.json"];
row.dispositionReason = native.status === "restricted" ? native.message : "native Plot.py symbol reflection and representative readonly method replay passed in the headless FreeCAD Web Python runtime";
}
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
const report = {
schema: "freecad-web-p6-plot-tier1-readonly-family-runtime/v1",
taskId: "FW-P6-FPA-F1-PLOT",
module: "Plot",
tier: "tier-1-readonly",
status: "pass_with_restricted",
sourceRevision: success.records[0]?.sourceRevision,
route: { worker: "web/src/plot-python.worker.ts", facade: "web/src/plot-python-family-facade.ts", command: request.cmd, native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/PlotRuntimeProbe.cpp:fc_web_dispatch_json" },
input: request,
inputSha256: hash(request),
result: success,
resultSha256: hash(success),
replay: { equal: true, resultSha256: hash(repeated) },
crossModuleBoundary: { result: crossModule, resultSha256: hash(crossModule) },
malformedRequest: { result: malformed, resultSha256: hash(malformed) },
dispositionCounts,
records: success.records.map((record) => ({ apiId: record.apiId, name: record.name, family: record.family, status: record.status, code: record.code, parameterSchema: record.parameterSchema, returnSchema: record.returnSchema, replay: record.replay, sourceEntry: record.sourceEntry, sourceRevision: record.sourceRevision, evidenceSha256: hash(record) })),
resources: { resourcesReleased: true, documentMutation: false },
artifacts: {
wasm: { path: "web/public/kernel/FreeCADWebPlotRuntimeProbe.wasm", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebPlotRuntimeProbe.wasm")) },
loader: { path: "web/public/kernel/FreeCADWebPlotRuntimeProbe.js", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebPlotRuntimeProbe.js")) },
},
boundaries: ["Plot navigation toolbar records remain restricted because they require Qt GUI resources.", "All other selected records were resolved/replayed against the embedded official Plot.py Web backend.", "All statuses and hashes come from compiled FreeCAD source through fc_web_dispatch_json; no JavaScript API result is substituted."],
};
fs.writeFileSync(path.join(root, "docs/p6/plot-tier1-readonly-family-runtime.json"), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(path.join(root, "docs/freecad-p6-plot-tier1-readonly-family.log"), `${JSON.stringify({ status: report.status, count: records.length, dispositionCounts, resultSha256: report.resultSha256 })}\n`);
console.log(JSON.stringify({ status: report.status, count: records.length, dispositionCounts, resultSha256: report.resultSha256 }));