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, "FreeCADWebOpenSCADRuntimeProbe.js")).href); const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebOpenSCADRuntimeProbe.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 === "OpenSCAD" && 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 !== 68) throw new Error(`expected 68 OpenSCAD records, got ${records.length}`); const request = { cmd: "openscad.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 !== "OpenSCAD" || success.count !== records.length || success.resourcesReleased !== true || !Array.isArray(success.records) || success.records.length !== records.length) { throw new Error("OpenSCAD 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("OpenSCAD family result contains a non-terminal or non-native record"); } if (JSON.stringify(repeated) !== JSON.stringify(success)) throw new Error("OpenSCAD 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("OpenSCAD 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("OpenSCAD 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 !== "OpenSCAD" || 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/openscad-tier1-readonly-family-runtime.json"]; row.dispositionReason = native.status === "restricted" ? native.message : native.status === "not_implemented" ? "source declaration is present but method-level readonly native argument/return evidence is pending" : native.message; } fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`); const counts = Object.fromEntries([...terminal].map((status) => [status, success.records.filter((record) => record.status === status).length])); const report = { schema: "freecad-web-p6-openscad-tier1-readonly-family-runtime/v1", taskId: "FW-P6-FPA-F1-OPENSCAD", module: "OpenSCAD", tier: "tier-1-readonly", status: "pass_with_restricted_and_pending", sourceRevision: success.records[0]?.sourceRevision, route: { worker: "web/src/openscad.worker.ts", facade: "web/src/openscad-python-family-facade.ts", command: request.cmd, native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/OpenSCADRuntimeProbe.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/FreeCADWebOpenSCADRuntimeProbe.wasm", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebOpenSCADRuntimeProbe.wasm")) }, loader: { path: "web/public/kernel/FreeCADWebOpenSCADRuntimeProbe.js", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebOpenSCADRuntimeProbe.js")) }, }, boundaries: [ "OpenSCADCommands, InitGui and view-resource records remain restricted because the GUI/tool surface is unavailable in the GUI-free Web kernel.", "Source-backed non-GUI records remain not_implemented until method-level native argument/return replay is added.", "All statuses and hashes are derived from compiled FreeCAD source through the single fc_web_dispatch_json ABI; no JavaScript API result is substituted.", ], }; fs.writeFileSync(path.join(root, "docs/p6/openscad-tier1-readonly-family-runtime.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-openscad-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 }));