48 lines
6.4 KiB
JavaScript
48 lines
6.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 = "/home/mes123456/FreeCADWasmDev/working/FreeCAD";
|
|
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, "FreeCADWebShowRuntimeProbe.js")));
|
|
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebShowRuntimeProbe.wasm")), print: () => {}, printErr: () => {} });
|
|
const manifestPath = path.join(root, "docs/p6/python-api-manifest.json");
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
const records = manifest.records.filter((row) => row.module === "Show" && row.tier === "tier-1-readonly").map((row) => ({ apiId: row.id, name: row.name, family: row.family, sourcePath: row.evidence?.path, disposition: row.disposition }));
|
|
if (records.length !== 18) throw new Error(`expected 18 Show Tier-1 records, got ${records.length}`);
|
|
const request = { cmd: "show.pythonFamilyBatch", args: { tier: "tier-1-readonly", records } };
|
|
const invoke = (value) => JSON.parse(String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify(value)])));
|
|
const success = invoke(request);
|
|
const repeated = invoke(request);
|
|
const crossModule = invoke({ cmd: request.cmd, args: { tier: request.args.tier, records: [{ ...records[0], apiId: "py:BIM:class:Camera" }] } });
|
|
const malformed = invoke({ cmd: request.cmd, args: { tier: "tier-2-pure", records } });
|
|
if (success.ok !== true || success.module !== "Show" || success.tier !== "tier-1-readonly" || success.count !== records.length || success.resourcesReleased !== true || !Array.isArray(success.records) || success.records.length !== records.length) throw new Error("Show family dispatch did not return a complete result");
|
|
const terminal = new Set(["exposed", "restricted", "nonportable", "not_implemented"]);
|
|
if (success.records.some((record) => !terminal.has(record.status) || record.native !== true || record.resourcesReleased !== true || !record.sourceEntry || !record.sourceRevision)) throw new Error("Show family result contains a non-terminal or non-native record");
|
|
const dispositionCounts = Object.fromEntries([...terminal].map((status) => [status, success.records.filter((record) => record.status === status).length]));
|
|
if (dispositionCounts.exposed !== 15 || dispositionCounts.restricted !== 1 || dispositionCounts.nonportable !== 0 || dispositionCounts.not_implemented !== 2) throw new Error(`unexpected Show disposition counts: ${JSON.stringify(dispositionCounts)}`);
|
|
if (JSON.stringify(repeated) !== JSON.stringify(success)) throw new Error("Show family replay changed the native result");
|
|
if (crossModule.ok !== true || crossModule.records?.[0]?.status !== "not_implemented" || crossModule.records?.[0]?.code !== "unmatched_source_record") throw new Error("Show cross-module boundary failed");
|
|
if (malformed.ok !== false || malformed.code !== "invalid_request") throw new Error("Show invalid tier was not rejected");
|
|
const hash = (value) => crypto.createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
const fileHash = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
|
const byId = new Map(success.records.map((record) => [record.apiId, record]));
|
|
for (const row of manifest.records) {
|
|
if (row.module !== "Show" || row.tier !== "tier-1-readonly") continue;
|
|
const native = byId.get(row.id);
|
|
if (!native) throw new Error(`native result missing ${row.id}`);
|
|
row.disposition = native.status;
|
|
row.dispositionEvidence = ["docs/p6/show-tier1-readonly-family-runtime.json"];
|
|
row.dispositionReason = native.status === "restricted" ? native.message : native.status === "not_implemented" ? native.message : "native Show Python symbol/object method was resolved and replayed by the headless FreeCAD Web runtime";
|
|
}
|
|
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
const report = { schema: "freecad-web-p6-show-tier1-readonly-family-runtime/v1", taskId: "FW-P6-FPA-F1-SHOW", module: "Show", tier: "tier-1-readonly", status: "pass_with_boundaries", sourceRevision: success.records[0]?.sourceRevision, route: { worker: "web/src/show-python.worker.ts", facade: "web/src/show-python-family-facade.ts", command: request.cmd, native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/ShowRuntimeProbe.cpp:fc_web_dispatch_json" }, input: request, inputSha256: hash(request), result: success, resultSha256: hash(success), replay: { equal: true, resultSha256: hash(repeated) }, crossModuleBoundary: { result: crossModule, resultSha256: hash(crossModule) }, malformedRequest: { result: malformed, resultSha256: hash(malformed) }, dispositionCounts, records: success.records.map((record) => ({ apiId: record.apiId, name: record.name, family: record.family, status: record.status, code: record.code, parameterSchema: record.parameterSchema, returnSchema: record.returnSchema, replay: record.replay, sourceEntry: record.sourceEntry, sourceRevision: record.sourceRevision, evidenceSha256: hash(record) })), resources: { resourcesReleased: true, documentMutation: false }, artifacts: { wasm: { path: "web/public/kernel/FreeCADWebShowRuntimeProbe.wasm", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebShowRuntimeProbe.wasm")) }, loader: { path: "web/public/kernel/FreeCADWebShowRuntimeProbe.js", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebShowRuntimeProbe.js")) } }, boundaries: ["Show Workbench remains restricted because FreeCADGui is unavailable in the headless Web runtime.", "Camera and ClipPlane source modules fail native import in the embedded runtime and remain not_implemented; no source-only record is promoted.", "All statuses, schemas and hashes come from compiled FreeCAD through fc_web_dispatch_json; no JavaScript API result is substituted."] };
|
|
fs.writeFileSync(path.join(root, "docs/p6/show-tier1-readonly-family-runtime.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "docs/freecad-p6-show-tier1-readonly-family.log"), `${JSON.stringify({ status: report.status, count: records.length, dispositionCounts, resultSha256: report.resultSha256 })}\n`);
|
|
console.log(JSON.stringify({ status: report.status, count: records.length, dispositionCounts, resultSha256: report.resultSha256 }));
|