95 lines
9.3 KiB
JavaScript
95 lines
9.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.join(root, "docs/current/module-batch-manifest.json");
|
|
const batch = JSON.parse(fs.readFileSync(batchPath, "utf8"));
|
|
if (batch.status !== "ready" || batch.taskId !== "FW-P6-FPA-Y" || batch.selected?.module !== "Assembly" || batch.selected?.tier !== "tier-1-readonly" || batch.selected?.family !== "geometry-value" || !Array.isArray(batch.records) || batch.records.length !== 1) throw new Error("unexpected Assembly geometry-value module batch manifest");
|
|
const records = batch.records.map(([apiId, name, disposition, sourcePath, sourceLine]) => ({ apiId, name, family: batch.selected.family, sourcePath, sourceLine, disposition }));
|
|
const output = fs.mkdtempSync(path.join(os.tmpdir(), "freecad-assembly-generic-batch-"));
|
|
const hash = (value) => crypto.createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
const fileHash = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
|
|
|
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/assembly-python-family-facade.ts")], { cwd: root, stdio: "inherit" });
|
|
const worker = new Worker(path.join(root, "tools/assembly-python-family-facade-smoke-worker.mjs"), { workerData: { buildDirectory: build, facadePath: pathToFileURL(path.join(output, "assembly-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 facade = await import(pathToFileURL(path.join(output, "assembly-python-family-facade.js")));
|
|
const envelope = await import(pathToFileURL(path.join(output, "facade-envelope.js")));
|
|
const request = (requestId, rows = records) => facade.createAssemblyPythonFamilyRequest(requestId, rows, "tier-1-readonly");
|
|
const ready = await next();
|
|
worker.postMessage(request("assembly-generic-batch-success")); const success = await next();
|
|
worker.postMessage(request("assembly-generic-batch-repeat")); const repeat = await next();
|
|
worker.postMessage(request("assembly-generic-batch-cross", [{ ...records[0], apiId: "py:BIM:class:Binding" }])); const cross = await next();
|
|
worker.postMessage({ ...request("assembly-generic-batch-invalid"), payload: { ...request("assembly-generic-batch-invalid").payload, tier: "tier-unsupported" } }); const malformed = await next();
|
|
const cancelRequest = request("assembly-family-cancel-1"); worker.postMessage(cancelRequest); worker.postMessage(envelope.createCancel("assembly-generic-batch-cancel-control", cancelRequest.requestId)); const cancelled = await next();
|
|
worker.postMessage({ kind: "reset", requestId: "assembly-generic-batch-reset" }); const reset = await next();
|
|
await worker.terminate();
|
|
|
|
if (ready.kind !== "ready" || success.kind !== "result" || repeat.kind !== "result" || cross.kind !== "result" || malformed.kind !== "error" || cancelled.kind !== "error" || reset.requestId !== "assembly-generic-batch-reset") throw new Error(JSON.stringify({ ready, success, repeat, cross, malformed, cancelled, reset }));
|
|
const result = success.result;
|
|
if (result.schema !== "freecad-web-assembly/python-family/v1" || result.module !== "Assembly" || result.tier !== "tier-1-readonly" || result.count !== records.length || result.records.length !== records.length || result.resourcesReleased !== true) throw new Error("Assembly geometry-value batch result is incomplete");
|
|
const terminal = new Set(["exposed", "restricted", "nonportable", "not_implemented"]);
|
|
const sourceLineHash = (row) => {
|
|
const sourceFile = path.join(root, "freecad-source", row.sourceEntry);
|
|
if (!fs.existsSync(sourceFile)) throw new Error(`Assembly source entry is missing: ${row.sourceEntry}`);
|
|
const lines = fs.readFileSync(sourceFile, "utf8").split(/\r?\n/);
|
|
const sourceLine = lines[row.sourceLine - 1];
|
|
if (!sourceLine || !sourceLine.trim()) throw new Error(`Assembly source line is empty: ${row.sourceEntry}:${row.sourceLine}`);
|
|
return hash(sourceLine);
|
|
};
|
|
if (result.records.some((row, index) => !terminal.has(row.status) || row.native !== true || row.resourcesReleased !== true || row.sourceEntry !== records[index].sourcePath || row.sourceLine !== records[index].sourceLine || row.sourceVerified !== true || typeof row.sourceRevision !== "string")) throw new Error("Assembly generic-object batch record schema is incomplete");
|
|
for (const row of result.records) {
|
|
sourceLineHash(row);
|
|
if (row.status !== "exposed" || row.code !== "native_fixture" || row.replay !== "native-source-fixture") throw new Error(`Assembly geometry-value fixture mismatch for ${row.name}`);
|
|
}
|
|
if (JSON.stringify(result) !== JSON.stringify(repeat.result)) throw new Error("Assembly generic-object batch replay changed native result");
|
|
if (cross.result.records?.[0]?.status !== "not_implemented" || cross.result.records?.[0]?.code !== "unmatched_source_record") throw new Error("Assembly cross-module boundary failed");
|
|
if (malformed.error.code !== "invalid_request" || cancelled.error.code !== "cancelled") throw new Error("Assembly error/cancel boundary failed");
|
|
|
|
const dispositionCounts = Object.fromEntries([...terminal].map((status) => [status, result.records.filter((row) => row.status === status).length]));
|
|
const evidencePath = `docs/p6/assembly-geometry-value-module-batch-${batch.batchId}-runtime.json`;
|
|
const manifestPath = path.join(root, "docs/p6/python-api-manifest.json");
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
const byId = new Map(result.records.map((row) => [row.apiId, row]));
|
|
for (const row of manifest.records) {
|
|
const native = byId.get(row.id);
|
|
if (!native) continue;
|
|
row.status = native.status;
|
|
row.dispositionEvidence = [evidencePath];
|
|
row.dispositionReason = native.message;
|
|
}
|
|
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
const report = {
|
|
schema: "freecad-web-assembly-module-batch-runtime/v1",
|
|
taskId: "FW-P6-FPA-Y",
|
|
batchId: batch.batchId,
|
|
module: "Assembly",
|
|
tier: "tier-1-readonly",
|
|
family: "geometry-value",
|
|
status: "pass_with_boundaries",
|
|
sourceRevision: result.records[0]?.sourceRevision,
|
|
route: { command: "assembly.pythonFamily", native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/AssemblyRuntimeProbe.cpp:fc_web_dispatch_json", facade: "web/src/assembly-python-family-facade.ts", worker: "web/src/assembly.worker.ts" },
|
|
input: { cmd: "assembly.pythonFamily", 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, reset, traceSha256: hash({ ready, success, repeat, cross, malformed, cancelled, reset }) },
|
|
dispositionCounts,
|
|
records: result.records.map((row) => ({ apiId: row.apiId, name: row.name, family: row.family, status: row.status, code: row.code, message: row.message, sourceEntry: row.sourceEntry, sourceLine: row.sourceLine, sourceVerified: row.sourceVerified, sourceRevision: row.sourceRevision, sourceLineHash: sourceLineHash(row), parameterSchema: row.parameterSchema, returnSchema: row.returnSchema, result: row.result, evidenceSha256: hash(row) })),
|
|
resources: { resourcesReleased: result.resourcesReleased, documentMutation: false, documentGraphFixture: true },
|
|
artifacts: { wasm: { path: "web/public/kernel/FreeCADWebAssemblyProbe.wasm", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebAssemblyProbe.wasm")) }, loader: { path: "web/public/kernel/FreeCADWebAssemblyProbe.js", sha256: fileHash(path.join(root, "web/public/kernel/FreeCADWebAssemblyProbe.js")) } },
|
|
boundaries: ["Assembly document-graph object records are exposed only when the compiled FreeCAD fixture creates, links, recomputes and releases the selected object types.", "GUI-only view-provider behavior remains outside this object-contract batch and is handled by an explicit restricted boundary in its own family.", "All statuses, source lines and hashes derive 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-assembly-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: report.batchId, count: records.length, dispositionCounts, resultSha256: report.resultSha256 }));
|