25 lines
3.4 KiB
JavaScript
25 lines
3.4 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 = 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") => kernel.ccall(name, type);
|
|
const run = () => ({ run: call("fc_web_material_source_inventory"), sourceEntry: call("fc_web_material_source_entry", "string"), registeredTypes: call("fc_web_material_registered_type_count"), pythonBindings: call("fc_web_material_python_binding_count"), code: call("fc_web_material_error_code", "string"), message: call("fc_web_material_error_message", "string") });
|
|
const first = run();
|
|
const second = run();
|
|
const stable = JSON.stringify(first) === JSON.stringify(second);
|
|
if (first.run !== 1 || second.run !== 1 || first.sourceEntry !== "src/Mod/Material/App/AppMaterial.cpp" || first.registeredTypes !== 27 || first.pythonBindings !== 12 || !stable) throw new Error(JSON.stringify({ first, second, stable }));
|
|
const report = { schema: "freecad-web-p6-material-action-02-kernel/v1", taskId: "FW-P6-MAT-ACT-02-C", module: "Material", action: "inspect/source-inventory", result: "pass", fixture: { module: "Material", action: "inspect/source-inventory", sourceEntry: first.sourceEntry, inputSha256: crypto.createHash("sha256").update(JSON.stringify({ module: "Material", action: "inspect/source-inventory", sourceEntry: first.sourceEntry })).digest("hex") }, replay: { first, second, identicalResult: stable, resultSha256: crypto.createHash("sha256").update(JSON.stringify(first)).digest("hex") }, resultSummary: { sourceEntry: first.sourceEntry, registeredTypeCount: first.registeredTypes, pythonBindingCount: first.pythonBindings, readOnly: true, resourcesReleased: true }, commands: ["cmake --build freecad-source/build-web/configure --target FreeCADWebMaterialRuntimeProbe -j 8", "node tools/run_p6_material_action02_kernel_smoke.mjs freecad-source/build-web/configure/bin"], artifacts: { wasm: "freecad-source/build-web/configure/bin/FreeCADWebMaterialRuntimeProbe.wasm", workerLog: "docs/freecad-p6-material-action-02-c-kernel.log" }, boundaries: ["Only Material App source inventory is covered; no document mutation or GUI module is initialized."] };
|
|
report.wasmSha256 = crypto.createHash("sha256").update(fs.readFileSync(path.join(build, "FreeCADWebMaterialRuntimeProbe.wasm"))).digest("hex");
|
|
fs.writeFileSync(path.join(root, "docs/p6/material-action-02-kernel.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "docs/freecad-p6-material-action-02-c-kernel.log"), `${JSON.stringify({ result: report.result, sourceEntry: first.sourceEntry, registeredTypes: first.registeredTypes, pythonBindings: first.pythonBindings, wasmSha256: report.wasmSha256 })}\n`);
|
|
console.log(JSON.stringify({ result: report.result, sourceEntry: first.sourceEntry, registeredTypes: first.registeredTypes, pythonBindings: first.pythonBindings }));
|