72 lines
4.2 KiB
JavaScript
72 lines
4.2 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 { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const source = path.join(root, "freecad-source");
|
|
const build = path.resolve(process.argv[2] ?? path.join(source, "build-web/assembly-configure/bin"));
|
|
const manifest = JSON.parse(fs.readFileSync(path.join(root, "docs/p6/python-api-manifest.json"), "utf8"));
|
|
const records = manifest.records
|
|
.filter((row) => row.module === "Assembly" && row.tier === "tier-1-readonly")
|
|
.map((row) => ({ apiId: row.id, name: row.name, family: row.family }));
|
|
const loaderPath = path.join(build, "FreeCADWebAssemblyProbe.js");
|
|
globalThis.__dirname = `${build}${path.sep}`;
|
|
globalThis.require = createRequire(import.meta.url);
|
|
const loader = await import(pathToFileURL(loaderPath));
|
|
const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebAssemblyProbe.wasm")) });
|
|
const dispatch = (request) => JSON.parse(String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify(request)])));
|
|
const request = { cmd: "assembly.pythonFamily", args: { tier: "tier-1-readonly", records } };
|
|
const first = dispatch(request);
|
|
const second = dispatch(request);
|
|
const invalid = dispatch({ cmd: "assembly.pythonFamily", args: {} });
|
|
const unsupported = dispatch({ cmd: "assembly.unknown", args: { records } });
|
|
const stable = (value) => crypto.createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
const counts = first.records.reduce((acc, item) => { acc[item.status] = (acc[item.status] ?? 0) + 1; return acc; }, {});
|
|
const recordEvidence = first.records.map((item) => ({
|
|
apiId: item.apiId,
|
|
name: item.name,
|
|
family: item.family,
|
|
disposition: item.status,
|
|
evidenceSha256: stable({ command: "assembly.pythonFamily", record: item }),
|
|
}));
|
|
const result = first.ok === true
|
|
&& first.module === "Assembly"
|
|
&& first.tier === "tier-1-readonly"
|
|
&& first.count === 120
|
|
&& first.records.length === 120
|
|
&& counts.restricted === 66
|
|
&& counts.not_implemented === 54
|
|
&& first.resourcesReleased === true
|
|
&& first.records.every((item) => item.native === true && (item.status === "restricted" || item.status === "not_implemented"))
|
|
&& stable(first) === stable(second)
|
|
&& invalid.ok === false
|
|
&& invalid.code === "invalid_request"
|
|
&& unsupported.ok === false
|
|
&& unsupported.code === "unsupported_command";
|
|
const report = {
|
|
schema: "freecad-web-p6-assembly-tier1-readonly-native/v1",
|
|
taskId: "FW-P6-FPA-F1-ASSEMBLY",
|
|
result: result ? "pass_with_boundaries" : "fail",
|
|
sourceRevision: (await import("node:child_process")).execFileSync("git", ["-C", source, "rev-parse", "HEAD"], { encoding: "utf8" }).trim(),
|
|
dispatcher: "fc_web_dispatch_json",
|
|
command: "assembly.pythonFamily",
|
|
coverage: { manifestRecords: records.length, returnedRecords: first.records.length, statusCounts: counts, uniqueIds: new Set(records.map((item) => item.apiId)).size },
|
|
records: recordEvidence,
|
|
response: { firstSha256: stable(first), secondSha256: stable(second), resourcesReleased: first.resourcesReleased },
|
|
errors: { invalid, unsupported },
|
|
artifacts: { wasm: "web/public/kernel/FreeCADWebAssemblyProbe.wasm", loader: "web/public/kernel/FreeCADWebAssemblyProbe.js" },
|
|
boundaries: [
|
|
"Assembly view-resource APIs are restricted because AssemblyGui is unavailable in the GUI-free Web kernel.",
|
|
"Generic-object and geometry-value methods remain not_implemented until method-level readonly parameter/return evidence is available.",
|
|
"No JavaScript result is used as a substitute for native FreeCAD execution.",
|
|
],
|
|
};
|
|
const docs = path.join(root, "docs/p6");
|
|
fs.writeFileSync(path.join(docs, "assembly-tier1-readonly-native.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "docs/freecad-p6-assembly-f1-readonly.log"), `${JSON.stringify({ result: report.result, coverage: report.coverage, firstSha256: report.response.firstSha256 })}\n`);
|
|
console.log(JSON.stringify({ result: report.result, coverage: report.coverage, invalidCode: invalid.code, unsupportedCode: unsupported.code }));
|
|
if (!result) process.exitCode = 1;
|