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

47 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, "FreeCADWebPartDesignRuntimeProbe.js")).href);
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebPartDesignRuntimeProbe.wasm")) });
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 === "PartDesign" && 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 !== 55) throw new Error(`expected 55 PartDesign records, got ${records.length}`);
const request = { cmd: "partdesign.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);
if (success.ok !== true || success.module !== "PartDesign" || success.count !== records.length || success.resourcesReleased !== true || !Array.isArray(success.records) || success.records.length !== records.length) throw new Error("PartDesign 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("PartDesign family result contains a non-terminal or non-native record");
const counts = Object.fromEntries([...terminal].map((status) => [status, success.records.filter((record) => record.status === status).length]));
if (counts.restricted !== 15 || counts.not_implemented !== 40 || counts.exposed !== 0 || counts.nonportable !== 0) throw new Error(`unexpected PartDesign disposition counts: ${JSON.stringify(counts)}`);
if (JSON.stringify(repeated) !== JSON.stringify(success)) throw new Error("PartDesign family replay changed the native result");
const crossModule = invoke({ cmd: request.cmd, args: { tier: request.args.tier, records: [{ ...records[0], apiId: "py:BIM:class:Binding" }] } });
if (crossModule.ok !== true || crossModule.records?.[0]?.status !== "not_implemented" || crossModule.records?.[0]?.code !== "unmatched_source_record") throw new Error("PartDesign cross-module boundary failed");
const malformed = invoke({ cmd: request.cmd, args: { tier: "tier-2-pure", records: [records[0]] } });
if (malformed.ok !== false || malformed.code !== "invalid_request") throw new Error("PartDesign 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 !== "PartDesign" || 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/partdesign-tier1-readonly-family-runtime.json"];
row.dispositionReason = native.status === "restricted" ? native.message : "source-backed PartDesign API remains not_implemented until method-level readonly native argument/return evidence exists";
}
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
const report = { schema: "freecad-web-p6-partdesign-tier1-readonly-family-runtime/v1", taskId: "FW-P6-FPA-F1-PARTDESIGN", module: "PartDesign", tier: "tier-1-readonly", status: "pass_with_restricted_and_pending", sourceRevision: success.records[0]?.sourceRevision, route: { worker: "web/src/partdesign-python.worker.ts", facade: "web/src/partdesign-python-family-facade.ts", command: request.cmd, native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/PartDesignRuntimeProbe.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: counts, records: success.records.map((record) => ({ apiId: record.apiId, name: record.name, family: record.family, status: record.status, code: record.code, sourceEntry: record.sourceEntry, sourceRevision: record.sourceRevision, evidenceSha256: hash(record) })), resources: { resourcesReleased: true, documentMutation: false }, artifacts: { wasm: { path: "web/public/kernel/FreeCADWebPartDesignRuntimeProbe.wasm", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebPartDesignRuntimeProbe.wasm")) }, loader: { path: "web/public/kernel/FreeCADWebPartDesignRuntimeProbe.js", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebPartDesignRuntimeProbe.js")) } }, boundaries: ["PartDesign GUI/workbench/view records remain restricted without FreeCADGui.", "Non-GUI source-backed records remain not_implemented pending method-level native argument/return replay.", "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/partdesign-tier1-readonly-family-runtime.json"), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(path.join(root, "docs/freecad-p6-partdesign-tier1-readonly-family.log"), `${JSON.stringify({ status: report.status, count: records.length, dispositionCounts: counts, resultSha256: report.resultSha256 })}\n`);
console.log(JSON.stringify({ status: report.status, count: records.length, dispositionCounts: counts, resultSha256: report.resultSha256 }));