115 lines
8.1 KiB
JavaScript
115 lines
8.1 KiB
JavaScript
#!/usr/bin/env node
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { execFileSync } from "node:child_process";
|
|
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"));
|
|
const docs = path.join(root, "docs/p6");
|
|
const manifestPath = path.join(docs, "python-api-manifest.json");
|
|
const out = fs.mkdtempSync(path.join(os.tmpdir(), "freecad-p6-templatepymod-tier2-"));
|
|
execFileSync(path.join(root, "web/node_modules/.bin/tsc"), [
|
|
"--target", "ES2022", "--module", "ESNext", "--moduleResolution", "Bundler", "--strict", "--skipLibCheck",
|
|
"--outDir", out, "--declaration", "false", "--noEmit", "false",
|
|
"web/src/facade-envelope.ts", "web/src/templatepymod-python-family-facade.ts",
|
|
], { cwd: root, stdio: "inherit" });
|
|
|
|
const hash = (value) => crypto.createHash("sha256").update(typeof value === "string" ? value : JSON.stringify(value)).digest("hex");
|
|
const fileHash = (file) => hash(fs.readFileSync(file));
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
const rows = manifest.records.filter((row) => row.module === "TemplatePyMod" && row.tier === "tier-2-pure");
|
|
if (rows.length !== 81) throw new Error(`expected 81 TemplatePyMod tier-2-pure records, got ${rows.length}`);
|
|
const records = rows.map((row) => ({
|
|
apiId: row.id,
|
|
name: row.name,
|
|
family: row.family,
|
|
kind: row.kind,
|
|
sourcePath: row.evidence?.path,
|
|
disposition: row.disposition,
|
|
}));
|
|
if (records.some((record) => typeof record.sourcePath !== "string" || !record.sourcePath.startsWith("src/Mod/TemplatePyMod/"))) {
|
|
throw new Error("TemplatePyMod Tier-2 source evidence is incomplete");
|
|
}
|
|
|
|
globalThis.__dirname = `${build}${path.sep}`;
|
|
globalThis.require = createRequire(import.meta.url);
|
|
const facade = await import(pathToFileURL(path.join(out, "templatepymod-python-family-facade.js")));
|
|
const envelope = await import(pathToFileURL(path.join(out, "facade-envelope.js")));
|
|
const loader = await import(pathToFileURL(path.join(build, "FreeCADWebTemplatePyModRuntimeProbe.js")));
|
|
const kernel = await loader.default({
|
|
wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebTemplatePyModRuntimeProbe.wasm")),
|
|
print: () => {},
|
|
printErr: () => {},
|
|
});
|
|
const queue = new envelope.FacadeSerialQueue();
|
|
const dispatch = (request, source = kernel) => facade.dispatchTemplatePyModPythonFamily(queue, request, source);
|
|
const tier = "tier-2-pure";
|
|
const successRequest = facade.createTemplatePyModPythonFamilyRequest("templatepymod-tier2-success", records, tier);
|
|
const success = await dispatch(successRequest);
|
|
const repeated = await dispatch(facade.createTemplatePyModPythonFamilyRequest("templatepymod-tier2-replay", records, tier));
|
|
const cross = await dispatch(facade.createTemplatePyModPythonFamilyRequest("templatepymod-tier2-cross", [{ ...records[0], apiId: "py:BIM:class:Camera" }], tier));
|
|
const malformed = await dispatch({ ...successRequest, requestId: "templatepymod-tier2-invalid-tier", payload: { ...successRequest.payload, tier: "tier-3-stateful" } });
|
|
const cancelRequest = facade.createTemplatePyModPythonFamilyRequest("templatepymod-tier2-cancel", records, tier);
|
|
const cancelledPromise = dispatch(cancelRequest, new Promise((resolve) => setTimeout(() => resolve(kernel), 25)));
|
|
queue.cancel(envelope.createCancel("templatepymod-tier2-cancel-control", cancelRequest.requestId));
|
|
const cancelled = await cancelledPromise;
|
|
|
|
if (success.kind !== "result") throw new Error(`TemplatePyMod Tier-2 family dispatch failed: ${JSON.stringify(success)}`);
|
|
const result = success.result;
|
|
const terminal = new Set(["exposed", "restricted", "nonportable", "not_implemented"]);
|
|
if (result.module !== "TemplatePyMod" || result.tier !== tier || result.count !== rows.length || result.records.length !== rows.length || result.resourcesReleased !== true) throw new Error("TemplatePyMod Tier-2 result is incomplete");
|
|
if (result.records.some((record) => !terminal.has(record.status) || record.native !== true || record.resourcesReleased !== true || !record.sourceEntry || !record.sourceRevision || typeof record.parameterSchema !== "string" || typeof record.returnSchema !== "string")) throw new Error("TemplatePyMod Tier-2 record is not terminal/schema-complete");
|
|
if (JSON.stringify(result) !== JSON.stringify(repeated.result)) throw new Error("TemplatePyMod Tier-2 replay changed the native result");
|
|
if (cross.kind !== "result" || cross.result.records?.[0]?.status !== "not_implemented" || cross.result.records?.[0]?.code !== "unmatched_source_record") throw new Error("TemplatePyMod Tier-2 cross-module boundary failed");
|
|
if (malformed.kind !== "error" || malformed.error.code !== "invalid_request") throw new Error("TemplatePyMod Tier-2 invalid tier was not rejected");
|
|
if (cancelled.kind !== "error" || cancelled.error.code !== "cancelled") throw new Error("TemplatePyMod Tier-2 cancellation was not reported");
|
|
|
|
const dispositionCounts = Object.fromEntries([...terminal].map((status) => [status, result.records.filter((record) => record.status === status).length]));
|
|
const byId = new Map(result.records.map((record) => [record.apiId, record]));
|
|
for (const row of manifest.records) {
|
|
if (row.module !== "TemplatePyMod" || row.tier !== tier) 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/templatepymod-tier2-pure-family-runtime.json"];
|
|
row.dispositionReason = native.message;
|
|
}
|
|
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
|
|
const report = {
|
|
schema: "freecad-web-p6-templatepymod-tier2-pure-family-runtime/v1",
|
|
taskId: "FW-P6-FPA-F2-TEMPLATEPYMOD",
|
|
module: "TemplatePyMod",
|
|
tier,
|
|
status: "pass_with_boundaries",
|
|
sourceRevision: result.records[0]?.sourceRevision,
|
|
route: { worker: "web/src/templatepymod-python.worker.ts", facade: "web/src/templatepymod-python-family-facade.ts", command: facade.TEMPLATEPYMOD_PYTHON_FAMILY_COMMAND, native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/TemplatePyModRuntimeProbe.cpp:fc_web_dispatch_json" },
|
|
input: successRequest,
|
|
inputSha256: hash(successRequest),
|
|
result,
|
|
resultSha256: hash(result),
|
|
replay: { equal: true, resultSha256: hash(repeated.result) },
|
|
crossModuleBoundary: { result: cross, resultSha256: hash(cross) },
|
|
malformedRequest: { result: malformed, resultSha256: hash(malformed) },
|
|
cancellation: { result: cancelled, resultSha256: hash(cancelled) },
|
|
dispositionCounts,
|
|
records: result.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: path.relative(root, path.join(build, "FreeCADWebTemplatePyModRuntimeProbe.wasm")), sha256: fileHash(path.join(build, "FreeCADWebTemplatePyModRuntimeProbe.wasm")) },
|
|
loader: { path: path.relative(root, path.join(build, "FreeCADWebTemplatePyModRuntimeProbe.js")), sha256: fileHash(path.join(build, "FreeCADWebTemplatePyModRuntimeProbe.js")) },
|
|
},
|
|
boundaries: [
|
|
"TemplatePyMod GUI/Qt and command/view-resource records remain restricted in the headless Web runtime.",
|
|
"Method records remain not_implemented until typed argument/return replay fixtures are available.",
|
|
"All statuses, schemas and hashes derive from compiled FreeCAD through fc_web_dispatch_json; no JavaScript API result is substituted.",
|
|
],
|
|
};
|
|
fs.writeFileSync(path.join(docs, "templatepymod-tier2-pure-family-runtime.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "docs/freecad-p6-templatepymod-f2-tier2.log"), `${JSON.stringify({ status: report.status, count: rows.length, dispositionCounts, resultSha256: report.resultSha256 })}\n`);
|
|
console.log(JSON.stringify({ status: report.status, count: rows.length, dispositionCounts, resultSha256: report.resultSha256 }));
|