63 lines
4.2 KiB
JavaScript
63 lines
4.2 KiB
JavaScript
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { createRequire } from "node:module";
|
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const build = path.resolve(process.argv[2] ?? path.join(root, "freecad-source/build-web/configure/bin"));
|
|
const docs = path.join(root, "docs/p6");
|
|
const runtime = JSON.parse(fs.readFileSync(path.join(docs, "partdesign-runtime.json"), "utf8"));
|
|
globalThis.__dirname = `${build}${path.sep}`;
|
|
globalThis.require = createRequire(import.meta.url);
|
|
const loader = await import(pathToFileURL(path.join(build, "FreeCADWebPartDesignRuntimeProbe.js")));
|
|
const probe = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebPartDesignRuntimeProbe.wasm")) });
|
|
const call = (name, type = "number", argTypes = [], values = []) => probe.ccall(name, type, argTypes, values);
|
|
const sourceEntry = "src/Mod/PartDesign/App/AppPartDesignPy.cpp";
|
|
const run = () => ({
|
|
run: call("fc_web_partdesign_python_api_validate", "number", ["string"], [sourceEntry]),
|
|
sourceEntry: call("fc_web_partdesign_python_api_source_entry", "string"),
|
|
summary: call("fc_web_partdesign_python_api_summary", "string"),
|
|
apiNames: call("fc_web_partdesign_python_api_names", "string"),
|
|
apiCount: call("fc_web_partdesign_python_api_count"),
|
|
generatedBindings: call("fc_web_partdesign_python_api_generated_bindings"),
|
|
resourcesReleased: call("fc_web_partdesign_python_api_resources_released"),
|
|
});
|
|
const first = run();
|
|
const second = run();
|
|
const invalid = call("fc_web_partdesign_python_api_validate", "number", ["string"], ["src/Mod/PartDesign/App/Missing.py"]);
|
|
const invalidError = call("fc_web_partdesign_error_code", "string");
|
|
const empty = call("fc_web_partdesign_python_api_validate", "number", ["string"], [""]);
|
|
const emptyError = call("fc_web_partdesign_error_code", "string");
|
|
const result = { first, second, invalid, invalidError, empty, emptyError };
|
|
if (first.run !== 1 || JSON.stringify(first) !== JSON.stringify(second) || first.apiCount !== 1 || first.apiNames !== "makeFilletArc" || first.generatedBindings !== 2 || first.resourcesReleased !== 1 || invalid !== 0 || invalidError !== "revision_mismatch" || empty !== 0 || emptyError !== "invalid_argument") throw new Error(JSON.stringify(result));
|
|
const fixture = { module: "PartDesign", action: "python-api", sourceEntry };
|
|
const wasmPath = path.join(build, "FreeCADWebPartDesignRuntimeProbe.wasm");
|
|
const report = {
|
|
schema: "freecad-web-partdesign-action-03-kernel/v1",
|
|
task_id: "FW-P6-PDN-ACT-03-C",
|
|
module: "PartDesign",
|
|
action: "python-api",
|
|
status: "pass",
|
|
source_revision: runtime.source_revision,
|
|
input_sha256: crypto.createHash("sha256").update(JSON.stringify(fixture)).digest("hex"),
|
|
result,
|
|
result_sha256: crypto.createHash("sha256").update(JSON.stringify(result)).digest("hex"),
|
|
commands: [
|
|
"EM_CONFIG=/absolute/freecad-source/build-web/emscripten-config.py env -u EM_FROZEN_CACHE ninja -C freecad-source/build-web/configure FreeCADWebPartDesignRuntimeProbe -j8",
|
|
"node tools/run_p6_partdesign_action03_kernel.mjs freecad-source/build-web/configure/bin",
|
|
],
|
|
artifacts: {
|
|
runtime: "docs/p6/partdesign-runtime.json",
|
|
wasm: { path: "freecad-source/build-web/configure/bin/FreeCADWebPartDesignRuntimeProbe.wasm", sha256: crypto.createHash("sha256").update(fs.readFileSync(wasmPath)).digest("hex") },
|
|
},
|
|
boundaries: [
|
|
"The native Python module is loaded by the real PartDesign WASM runtime; exports are read-only metadata and no document is created.",
|
|
"The API count covers makeFilletArc and the two generated Body/Feature bindings, not the full desktop Python ecosystem.",
|
|
"PySide, Pivy and GUI Python exports remain excluded."
|
|
],
|
|
};
|
|
fs.writeFileSync(path.join(docs, "partdesign-action-03-kernel.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "docs/freecad-p6-partdesign-action-03-c-kernel.log"), `${JSON.stringify({ status: report.status, apiCount: first.apiCount, apiNames: first.apiNames, resultSha256: report.result_sha256 })}\n`);
|
|
console.log(JSON.stringify({ status: report.status, apiCount: first.apiCount, apiNames: first.apiNames, resultSha256: report.result_sha256 }));
|