95 lines
8.3 KiB
JavaScript
95 lines
8.3 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 { Worker } from "node:worker_threads";
|
|
import { execFileSync } from "node:child_process";
|
|
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 batchPath = path.resolve(process.env.PARTDESIGN_BATCH_MANIFEST || path.join(root, "docs/current/module-batch-manifest.json"));
|
|
const batch = JSON.parse(fs.readFileSync(batchPath, "utf8"));
|
|
const selectedTier = batch.selected?.tier;
|
|
const hash = (value) => crypto.createHash("sha256").update(typeof value === "string" ? value : JSON.stringify(value)).digest("hex");
|
|
const fileHash = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
|
if (batch.status !== "ready" || batch.selected?.module !== "PartDesign" || batch.selected?.tier !== "tier-1-readonly" || batch.selected?.family !== "generic-object" || batch.records.length < 2 || batch.records.length > 32) throw new Error("unexpected PartDesign module batch manifest");
|
|
|
|
const records = batch.records.map(([apiId, name, disposition, sourcePath]) => ({ apiId, name, family: batch.selected.family, sourcePath, disposition }));
|
|
const output = fs.mkdtempSync(path.join(os.tmpdir(), "freecad-partdesign-module-batch-"));
|
|
execFileSync(path.join(root, "web/node_modules/.bin/tsc"), ["--target", "ES2022", "--module", "ESNext", "--moduleResolution", "Bundler", "--strict", "--skipLibCheck", "--outDir", output, "--declaration", "false", "--noEmit", "false", path.join(root, "web/src/facade-envelope.ts"), path.join(root, "web/src/partdesign-python-family-facade.ts")], { cwd: root, stdio: "inherit" });
|
|
const facade = await import(pathToFileURL(path.join(output, "partdesign-python-family-facade.js")));
|
|
const envelope = await import(pathToFileURL(path.join(output, "facade-envelope.js")));
|
|
const request = (requestId, rows = records) => facade.createPartDesignPythonFamilyRequest(requestId, rows, "tier-1-readonly");
|
|
const worker = new Worker(path.join(root, "tools/partdesign-python-family-facade-smoke-worker.mjs"), { workerData: { buildDirectory: build, facadePath: pathToFileURL(path.join(output, "partdesign-python-family-facade.js")).href, envelopePath: pathToFileURL(path.join(output, "facade-envelope.js")).href } });
|
|
const next = () => new Promise((resolve, reject) => {
|
|
const onMessage = (value) => { worker.off("error", onError); resolve(value); };
|
|
const onError = (error) => { worker.off("message", onMessage); reject(error); };
|
|
worker.once("message", onMessage); worker.once("error", onError);
|
|
});
|
|
const ready = await next();
|
|
worker.postMessage(request("pd-object-batch-success"));
|
|
const success = await next();
|
|
worker.postMessage(request("pd-object-batch-repeat"));
|
|
const repeat = await next();
|
|
const crossRequest = request("pd-object-batch-cross", [{ ...records[0], apiId: "obj:BIM:class:Binding" }]);
|
|
worker.postMessage(crossRequest);
|
|
const cross = await next();
|
|
worker.postMessage({ ...request("pd-object-batch-invalid"), payload: { ...request("pd-object-batch-invalid").payload, tier: "tier-unsupported" } });
|
|
const malformed = await next();
|
|
const cancelRequest = request("pdn-python-cancel-1");
|
|
worker.postMessage(cancelRequest);
|
|
worker.postMessage(envelope.createCancel("pd-object-batch-cancel-control", cancelRequest.requestId));
|
|
const cancelled = await next();
|
|
await worker.terminate();
|
|
|
|
if (ready.kind !== "ready" || success.kind !== "result" || repeat.kind !== "result" || cross.kind !== "result" || malformed.kind !== "error" || cancelled.kind !== "error") throw new Error(JSON.stringify({ ready, success, repeat, cross, malformed, cancelled }));
|
|
const result = success.result;
|
|
const terminal = new Set(["exposed", "restricted", "nonportable", "not_implemented"]);
|
|
if (result.module !== "PartDesign" || result.tier !== selectedTier || result.count !== records.length || result.records.length !== records.length || result.resourcesReleased !== true) throw new Error("PartDesign batch result is incomplete");
|
|
if (result.records.some((row) => !terminal.has(row.status) || row.native !== true || row.resourcesReleased !== true || typeof row.sourceRevision !== "string" || typeof row.sourceEntry !== "string" || typeof row.parameterSchema !== "string" || typeof row.returnSchema !== "string")) throw new Error("PartDesign object batch record schema is incomplete");
|
|
if (JSON.stringify(result) !== JSON.stringify(repeat.result)) throw new Error("PartDesign object batch replay changed native result");
|
|
if (cross.result.records?.[0]?.code !== "unmatched_source_record") throw new Error("PartDesign object cross-module boundary failed");
|
|
if (malformed.error.code !== "invalid_request" || cancelled.error.code !== "cancelled") throw new Error("PartDesign object error/cancel boundary failed");
|
|
|
|
const matrixPath = path.join(root, "docs/p6/object-contract-matrix.json");
|
|
const matrix = JSON.parse(fs.readFileSync(matrixPath, "utf8"));
|
|
const byId = new Map(result.records.map((row) => [row.apiId, row]));
|
|
const evidencePath = `docs/p6/partdesign-module-batch-${batch.batchId}-runtime.json`;
|
|
for (const row of matrix.records) {
|
|
const native = byId.get(row.id);
|
|
if (!native) continue;
|
|
row.status = native.status;
|
|
row.dispositionEvidence = [evidencePath];
|
|
row.dispositionReason = native.message;
|
|
}
|
|
fs.writeFileSync(matrixPath, `${JSON.stringify(matrix, null, 2)}\n`);
|
|
const dispositionCounts = Object.fromEntries([...terminal].map((status) => [status, result.records.filter((row) => row.status === status).length]));
|
|
const report = {
|
|
schema: "freecad-web-partdesign-module-batch-runtime/v1",
|
|
taskId: "FW-P6-FPA-Y",
|
|
batchId: batch.batchId,
|
|
module: "PartDesign",
|
|
tier: "object-contract",
|
|
family: "generic-document-object",
|
|
status: "pass_with_boundaries",
|
|
sourceRevision: result.records[0]?.sourceRevision,
|
|
route: { command: "partdesign.pythonFamilyBatch", native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/PartDesignRuntimeProbe.cpp:fc_web_dispatch_json", facade: "web/src/partdesign-python-family-facade.ts", worker: "web/src/partdesign-python.worker.ts" },
|
|
input: { cmd: "partdesign.pythonFamilyBatch", args: { tier: "object-contract", records } },
|
|
inputSha256: hash(records),
|
|
result,
|
|
resultSha256: hash(result),
|
|
replay: { equal: true, resultSha256: hash(repeat.result) },
|
|
facadeWorker: { ready, success, repeat, crossModule: cross, malformed, cancelled, traceSha256: hash({ ready, success, repeat, cross, malformed, cancelled }) },
|
|
dispositionCounts,
|
|
records: result.records.map((row) => ({ apiId: row.apiId, name: row.name, status: row.status, code: row.code, message: row.message, result: row.result, sourceEntry: row.sourceEntry, sourceRevision: row.sourceRevision, evidenceSha256: hash(row) })),
|
|
resources: { resourcesReleased: true, documentMutation: false },
|
|
artifacts: { module: "PartDesign", worker: "partdesign.worker.ts", revision: result.records[0]?.sourceRevision, runtimeUrl: "/kernel/FreeCADWebPartDesignRuntimeProbe.js", wasmUrl: "/kernel/FreeCADWebPartDesignRuntimeProbe.wasm", dataUrl: null, assetBaseUrl: "/kernel/", buildProfile: "fast-dev", wasm: { path: "web/public/kernel/FreeCADWebPartDesignRuntimeProbe.wasm", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebPartDesignRuntimeProbe.wasm")) }, loader: { path: "web/public/kernel/FreeCADWebPartDesignRuntimeProbe.js", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebPartDesignRuntimeProbe.js")) } },
|
|
boundaries: ["Body and datum objects use native registration/create/recompute fixtures.", "Chamfer, Draft, DressUp and Fillet retain native_fixture_required until topology-specific PartDesign fixtures are available.", "All statuses, values and schemas come from compiled FreeCAD through fc_web_dispatch_json; JavaScript only transports and validates the batch envelope."]
|
|
};
|
|
fs.writeFileSync(path.join(root, evidencePath), `${JSON.stringify(report, null, 2)}\n`);
|
|
const logPath = `docs/freecad-p6-partdesign-module-batch-${batch.batchId}.log`;
|
|
fs.writeFileSync(path.join(root, logPath), `${JSON.stringify({ status: report.status, batchId: report.batchId, count: records.length, dispositionCounts, resultSha256: report.resultSha256 })}\n`);
|
|
console.log(JSON.stringify({ status: report.status, batchId: batch.batchId, count: records.length, dispositionCounts, resultSha256: report.resultSha256 }));
|