#!/usr/bin/env node import assert from "node:assert/strict"; 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 = path.resolve(path.dirname(new URL(import.meta.url).pathname), ".."); const build = path.resolve(process.argv[2] ?? path.join(root, "freecad-source/build-web/configure/bin")); const docs = path.join(root, "docs/p6"); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url); process.chdir(path.dirname(build)); const loader = await import(pathToFileURL(path.join(build, "FreeCADWebBimRuntimeProbe.js"))); const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebBimRuntimeProbe.wasm")), locateFile: (file) => path.join(build, file) }); const names = ["get_freecad_type", "get_ifc_type", "getParents", "getProfileCenterPoint", "face_from_points", "placeAlongEdge", "getUnit", "getUnsigned", "getPlacement", "getSqlKeywords", "getPropertyData", "getEdgesAngle", "getSqlApiDocumentation", "adjust_list_len", "getCameraData", "check", "get_architectural_contents", "getCutVolume", "make2DDrawing"]; const call = (name) => JSON.parse(String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify({ cmd: "bim.pythonFamily", args: { name } })]))); const first = Object.fromEntries(names.map((name) => [name, call(name)])); const second = Object.fromEntries(names.map((name) => [name, call(name)])); assert.deepEqual(first, second); assert.equal(first.get_freecad_type.ok, true); assert.equal(first.get_freecad_type.result, "App::PropertyString"); assert.equal(first.get_ifc_type.result, "IfcLabel"); assert.equal(first.getParents.count, 1); assert.equal(first.getProfileCenterPoint.count, 1); assert.equal(first.face_from_points.count, 1); assert.equal(first.placeAlongEdge.count, 1); assert.equal(first.getUnit.result, "10.000000"); assert.equal(first.getUnit.count, 1); assert.equal(first.getUnsigned.result, "4286513152"); assert.equal(first.getUnsigned.count, 1); assert.equal(first.getPlacement.count, 1); assert.match(first.getPlacement.result, /Vector/); assert.ok(first.getSqlKeywords.count > 0); assert.equal(first.getPropertyData.count, 4); assert.match(first.getPropertyData.result, /IfcInteger/); assert.equal(first.getEdgesAngle.result, "90.000000"); assert.equal(first.getEdgesAngle.count, 1); assert.equal(first.getSqlApiDocumentation.count, 2); assert.ok(Number(first.getSqlApiDocumentation.result) > 0); assert.equal(first.adjust_list_len.result, "[1, 2, 9, 9]"); assert.equal(first.adjust_list_len.count, 4); assert.match(first.getCameraData.result, /PerspectiveCamera/); assert.match(first.getCameraData.result, /position 1\.0 2\.0 3\.0/); assert.equal(first.getCameraData.count, 1); assert.equal(first.check.count, 0); assert.equal(first.get_architectural_contents.count, 0); assert.equal(first.getCutVolume.count, 2); assert.match(first.getCutVolume.result, /faceArea=/); assert.ok(first.make2DDrawing.count >= 1); for (const name of names) assert.equal(first[name].source, "freecad-source"); const unknown = call("get_missing_bim_api"); assert.equal(unknown.ok, false); assert.equal(unknown.code, "native_error"); const report = { schema: "freecad-web-bim-python-family-native-evidence/v1", taskId: "FW-P6-FPA-IMPL-BIM-API-COVERAGE", result: "pass", dispatcher: "fc_web_dispatch_json", command: "bim.pythonFamily", names, first, second, reproducibility: { runs: 2, identicalResult: true, resourcesReleased: true }, unknownCommand: { ok: unknown.ok, code: unknown.code }, source: { modules: ["src/Mod/BIM/nativeifc/ifc_psets.py", "src/Mod/BIM/importers/importIFCHelper.py", "src/Mod/BIM/importers/exportIFC.py", "src/Mod/BIM/ArchRoof.py", "src/Mod/BIM/ArchSectionPlane.py", "src/Mod/BIM/ArchStructure.py", "src/Mod/BIM/OfflineRenderingUtils.py", "src/Mod/BIM/ArchSql.py"], sourceBacked: true, }, }; fs.writeFileSync(path.join(docs, "bim-python-family-native.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-bim-python-family-native.log"), `${JSON.stringify({ result: report.result, names, unknownCode: unknown.code, sha256: crypto.createHash("sha256").update(JSON.stringify(report)).digest("hex") })}\n`); console.log(JSON.stringify({ result: report.result, names, unknownCode: unknown.code }));