#!/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 = 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")); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url); const loader = await import(pathToFileURL(path.join(build, "FreeCADWebMaterialRuntimeProbe.js"))); const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMaterialRuntimeProbe.wasm")) }); const call = (name, type = "number", argTypes = [], args = []) => kernel.ccall(name, type, argTypes, args); const initialize = (name) => ({ run: call("fc_web_material_initialize", "number", ["string"], [name]), code: call("fc_web_material_error_code", "string"), message: call("fc_web_material_error_message", "string"), calls: call("fc_web_material_initialization_calls"), runs: call("fc_web_material_initialization_runs"), initialized: call("fc_web_material_initialized"), }); const first = initialize("Materials"); const repeated = initialize("Materials"); const type = { run: call("fc_web_material_type_probe", "number", ["string"], ["Materials::Material"]), type: call("fc_web_material_last_type", "string"), code: call("fc_web_material_error_code", "string"), }; const propertyType = { run: call("fc_web_material_type_probe", "number", ["string"], ["Materials::PropertyMaterial"]), type: call("fc_web_material_last_type", "string"), code: call("fc_web_material_error_code", "string"), }; const missing = initialize("MaterialsMissing"); const gui = initialize("MatGui"); const result = { first, repeated, type, propertyType, missing, gui }; const stable = JSON.stringify(result); if (first.run !== 1 || repeated.run !== 1 || first.runs !== 1 || repeated.runs !== 1 || type.run !== 1 || type.type !== "Materials::Material" || propertyType.run !== 1 || propertyType.type !== "Materials::PropertyMaterial" || missing.code !== "module_unavailable" || gui.code !== "gui_dependency_unavailable") throw new Error(`Material runtime contract failed: ${stable}`); const wasmPath = path.join(build, "FreeCADWebMaterialRuntimeProbe.wasm"); const report = { schema: "freecad-web-p6-material-runtime/v1", taskId: "FW-P6-MAT-B", module: "Material", result: "pass", resultSha256: crypto.createHash("sha256").update(stable).digest("hex"), responses: result, initialization: { calls: repeated.calls, runs: repeated.runs, idempotent: repeated.runs === 1 }, types: { material: type.type, propertyMaterial: propertyType.type, guiExcluded: true }, dependencies: { freecadApp: true, yamlCpp: true, qtConcurrent: false, gui: false, externalMaterial: false }, commands: [ "cmake -S freecad-source -B freecad-source/build-web/configure -DBUILD_MATERIAL=ON", "cmake --build freecad-source/build-web/configure --target FreeCADWebMaterialRuntimeProbe -j 8", "node tools/run_p6_material_runtime_smoke.mjs freecad-source/build-web/configure/bin", ], artifacts: { wasm: "freecad-source/build-web/configure/bin/FreeCADWebMaterialRuntimeProbe.wasm", workerLog: "docs/freecad-p6-material-b-runtime.log" }, boundaries: [ "Runtime probe verifies Materials module registration, two representative App types, idempotent initialization, and GUI-free error boundaries only.", "BUILD_MATERIAL_EXTERNAL is disabled; Material GUI and external manager runtime are not claimed.", ], }; report.wasmSha256 = crypto.createHash("sha256").update(fs.readFileSync(wasmPath)).digest("hex"); fs.writeFileSync(path.join(root, "docs/p6/material-runtime.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-material-b-runtime.log"), `${JSON.stringify({ result: report.result, initializationRuns: report.initialization.runs, types: report.types, missingCode: report.responses.missing.code, guiCode: report.responses.gui.code, wasmSha256: report.wasmSha256 })}\n`); console.log(JSON.stringify({ result: report.result, initializationRuns: report.initialization.runs, materialType: report.types.material, wasmSha256: report.wasmSha256 }));