Files
FreeCADWasmDev/tools/run_p6_partdesign_action02_kernel.mjs
wangdequan 9a7c4f0335 Save FreeCAD Web workspace sources and user validation evidence
IFC native binding remains incomplete; preserve accurate test results.
2026-09-15 22:01:58 +08:00

69 lines
4.3 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 fixture = { sourceEntry: "src/Mod/PartDesign/App/AppPartDesign.cpp", includeGui: false, readOnly: true };
const inputSha256 = crypto.createHash("sha256").update(JSON.stringify(fixture)).digest("hex");
const run = () => ({
run: call("fc_web_partdesign_source_inventory_validate", "number", ["string"], [fixture.sourceEntry]),
sourceEntry: call("fc_web_partdesign_inspect_source_entry", "string"),
summary: call("fc_web_partdesign_inspect_summary", "string"),
sourceFiles: call("fc_web_partdesign_inspect_source_files", "string"),
registeredTypes: call("fc_web_partdesign_inspect_registered_types"),
formatCount: call("fc_web_partdesign_inspect_format_count"),
pythonBindings: call("fc_web_partdesign_inspect_python_bindings"),
resourcesReleased: call("fc_web_partdesign_inspect_resources_released"),
});
const first = run();
const second = run();
const invalid = call("fc_web_partdesign_source_inventory_validate", "number", ["string"], ["src/Mod/PartDesign/App/Missing.cpp"]);
const invalidError = call("fc_web_partdesign_error_code", "string");
const empty = call("fc_web_partdesign_source_inventory_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.registeredTypes !== 8 || first.formatCount !== 0 || first.pythonBindings !== 2 || first.resourcesReleased !== 1 || invalid !== 0 || invalidError !== "revision_mismatch" || empty !== 0 || emptyError !== "invalid_argument") {
throw new Error(JSON.stringify(result));
}
const wasmPath = path.join(build, "FreeCADWebPartDesignRuntimeProbe.wasm");
const report = {
schema: "freecad-web-partdesign-action-02-kernel/v1",
task_id: "FW-P6-PDN-ACT-02-C",
module: "PartDesign",
action: "inspect/source-inventory",
status: "pass",
source_revision: runtime.source_revision,
input_sha256: inputSha256,
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_action02_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 PartDesign runtime probe performs the source-inventory type queries; no document is created or mutated.",
"The result covers the eight deterministic representative types, zero declared file formats and two generated binding units.",
"Facade, Worker, Chrome and persistence evidence remain later child cards."
]
};
fs.writeFileSync(path.join(docs, "partdesign-action-02-kernel.json"), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(path.join(root, "docs/freecad-p6-partdesign-action-02-c-kernel.log"), `${JSON.stringify({ status: report.status, result: report.result, inputSha256, resultSha256: report.result_sha256 })}\n`);
console.log(JSON.stringify({ status: report.status, registeredTypes: first.registeredTypes, resultSha256: report.result_sha256 }));