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

80 lines
7.0 KiB
JavaScript

#!/usr/bin/env node
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"));
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 === "MeshPart" && row.tier === "tier-1-readonly")
.map(({ id, name, family, evidence, disposition }) => ({ apiId: id, name, family, sourcePath: evidence?.path, disposition }));
if (records.length !== 8) throw new Error(`MeshPart tier-1 manifest expected 8 records, got ${records.length}`);
globalThis.__dirname = `${build}${path.sep}`;
globalThis.require = createRequire(import.meta.url);
const loader = await import(pathToFileURL(path.join(build, "FreeCADWebMeshPartRuntimeProbe.js")));
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMeshPartRuntimeProbe.wasm")) });
const invoke = (value) => JSON.parse(String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify(value)])));
const hash = (value) => crypto.createHash("sha256").update(Buffer.isBuffer(value) ? value : typeof value === "string" ? value : JSON.stringify(value)).digest("hex");
const request = { cmd: "meshpart.pythonFamilyBatch", args: { tier: "tier-1-readonly", records } };
const success = invoke(request);
const repeated = invoke(request);
const mismatch = invoke({ cmd: request.cmd, args: { tier: request.args.tier, records: [{ ...records[0], apiId: "py:BIM:class:MeshPartWorkbench" }] } });
const malformed = invoke({ cmd: request.cmd, args: { tier: "tier-2-pure", records } });
const unsupported = invoke({ cmd: "meshpart.unknown", args: {} });
if (success.ok !== true || success.schema !== "freecad-web-meshpart/python-family-batch/v1" || success.module !== "MeshPart" || success.tier !== "tier-1-readonly" || success.source !== "freecad-source" || success.count !== records.length || !Array.isArray(success.records) || success.records.length !== records.length || success.resourcesReleased !== true) throw new Error("MeshPart family dispatch did not return a complete result");
if (success.records.some((record) => record.status !== "restricted" || record.native !== true || record.resourcesReleased !== true || !record.sourceEntry || record.sourceRevision !== "2778e3f9c215da48bf0cfd562478d45d624aaa47" || !record.parameterSchema || !record.returnSchema || record.code !== "gui_dependency_unavailable" || record.pythonModule !== "MeshPart" || record.capability !== "FreeCADGui")) throw new Error("MeshPart native record metadata or terminal disposition is incomplete");
if (JSON.stringify(success) !== JSON.stringify(repeated)) throw new Error("MeshPart family replay changed the native result");
if (mismatch.ok !== true || mismatch.records?.[0]?.status !== "not_implemented" || mismatch.records?.[0]?.code !== "unmatched_source_record") throw new Error("MeshPart module-scoped mismatch was not rejected");
if (malformed.ok !== false || malformed.code !== "invalid_request") throw new Error("MeshPart invalid tier was not rejected");
if (unsupported.ok !== false || unsupported.code !== "unsupported_command") throw new Error("MeshPart unsupported command was not rejected");
const counts = success.records.reduce((out, record) => { out[record.status] = (out[record.status] || 0) + 1; return out; }, {});
const resultById = new Map(success.records.map((record) => [record.apiId, record]));
for (const row of manifest.records) {
if (row.module !== "MeshPart" || row.tier !== "tier-1-readonly") continue;
const native = resultById.get(row.id);
if (!native) throw new Error(`native result missing ${row.id}`);
row.disposition = native.status;
row.dispositionEvidence = ["docs/p6/meshpart-tier1-readonly-family.json"];
row.dispositionReason = "requires FreeCADGui GUI/resource capability; native MeshPart Python module is loaded but this GUI-only API is unavailable in the Web kernel";
}
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
const artifacts = {
js: { path: path.relative(root, path.join(build, "FreeCADWebMeshPartRuntimeProbe.js")), sha256: hash(fs.readFileSync(path.join(build, "FreeCADWebMeshPartRuntimeProbe.js"))) },
wasm: { path: path.relative(root, path.join(build, "FreeCADWebMeshPartRuntimeProbe.wasm")), sha256: hash(fs.readFileSync(path.join(build, "FreeCADWebMeshPartRuntimeProbe.wasm"))) },
};
const report = {
schema: "freecad-web-p6-meshpart-tier1-readonly-family-runtime/v1",
taskId: "FW-P6-FPA-F1-MESHPART",
module: "MeshPart",
tier: "tier-1-readonly",
status: "pass_with_restricted",
sourceRevision: "2778e3f9c215da48bf0cfd562478d45d624aaa47",
route: { worker: "web/src/meshpart.worker.ts", facade: "web/src/meshpart-python-family-facade.ts", command: request.cmd, native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/MeshPartRuntimeProbe.cpp:fc_web_dispatch_json" },
input: { count: records.length, requestSha256: hash(request) },
result: { count: success.count, resourcesReleased: success.resourcesReleased, dispositionCounts: counts, resultSha256: hash(success) },
replay: { equal: true, resultSha256: hash(repeated) },
mismatchRequest: { result: mismatch, resultSha256: hash(mismatch) },
malformedRequest: { result: malformed, resultSha256: hash(malformed) },
unsupportedRequest: { result: unsupported, resultSha256: hash(unsupported) },
records: success.records.map((record) => ({ apiId: record.apiId, name: record.name, family: record.family, status: record.status, code: record.code, message: record.message, sourceEntry: record.sourceEntry, sourceRevision: record.sourceRevision, parameterSchema: record.parameterSchema, returnSchema: record.returnSchema, pythonSymbolAvailable: record.pythonSymbolAvailable, evidenceSha256: hash(record) })),
artifacts,
resources: { resourcesReleased: success.resourcesReleased, documentMutation: false },
boundaries: [
"All eight selected records are sourced from MeshPart GUI Python scripts and are returned as restricted by compiled FreeCAD WebAssembly.",
"The MeshPart App Python extension is initialized and reflected natively; FreeCADGui-dependent classes and methods remain unavailable in the GUI-free worker.",
"Parameter and return schemas are derived from the source declarations; no JavaScript API result or cross-module name match is used.",
],
};
fs.writeFileSync(path.join(root, "docs/p6/meshpart-tier1-readonly-family.json"), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(path.join(root, "docs/freecad-p6-meshpart-tier1-readonly-family.log"), `${JSON.stringify({ status: report.status, count: records.length, dispositionCounts: counts, resultSha256: report.result.resultSha256, wasmSha256: artifacts.wasm.sha256 })}\n`);
console.log(JSON.stringify({ status: report.status, count: records.length, dispositionCounts: counts, resultSha256: report.result.resultSha256, wasmSha256: artifacts.wasm.sha256 }));