9 lines
4.4 KiB
JavaScript
9 lines
4.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";
|
|
const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), ".."); const build = path.join(root, "freecad-source/build-web/configure/bin"); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url);
|
|
const batch = JSON.parse(fs.readFileSync(path.join(root, "docs/current/module-batch-manifest.json"), "utf8")); if (batch.batchId !== "87cbf4a32302b545768121c8" || batch.selected?.module !== "Surface" || batch.selected?.tier !== "object-contract" || batch.selected?.family !== "view-provider") throw new Error("unexpected Surface view-provider batch");
|
|
const runtimePath = path.join(build, "FreeCADWebSurfaceRuntimeProbe.js"); const wasmPath = path.join(build, "FreeCADWebSurfaceRuntimeProbe.wasm"); const factory = (await import(`file://${runtimePath}`)).default; const kernel = await factory({ wasmBinary: fs.readFileSync(wasmPath) });
|
|
const records = batch.records.map(([apiId, name, disposition, source]) => ({ apiId, name, family: "view-provider", sourcePath: source, disposition })); const request = { cmd: "surface.objectContractBatch", args: { tier: "object-contract", records } }; const dispatch = (value) => JSON.parse(String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify(value)]))); const native = dispatch(request); const replay = dispatch(request); const crossModule = dispatch({ ...request, args: { ...request.args, records: [{ ...records[0], apiId: "obj:Other:Surface::Sections" }] } }); const row = native.records?.[0];
|
|
if (native.ok !== true || native.resourcesReleased !== true || native.count !== 1 || row?.status !== "exposed" || row?.code !== "native_object_contract" || row?.objectType !== "Surface::Sections" || row?.viewProvider !== "SurfaceGui::ViewProviderSections" || row?.hasNSections !== true || row?.resourcesReleased !== true) throw new Error("Surface::Sections native view-provider contract failed"); if (JSON.stringify(replay) !== JSON.stringify(native)) throw new Error("Surface::Sections repeated dispatch changed output"); if (crossModule.records?.[0]?.code !== "unmatched_source_record" || crossModule.resourcesReleased !== true) throw new Error("Surface object adapter accepted a cross-module record");
|
|
const result = { count: records.length, resourcesReleased: true, resourceLifecycle: "document-created-recomputed-closed", dispositionCounts: { exposed: 1, restricted: 0, nonportable: 0, not_implemented: 0 }, native }; const report = { schema: "freecad-web-surface-view-provider-module-batch-runtime/v1", taskId: "FW-P6-FPA-Y", batchId: batch.batchId, module: "Surface", tier: "object-contract", family: "view-provider", status: "pass", dispatcher: "fc_web_dispatch_json", route: { command: request.cmd, native: "freecad-source/src/WebAssembly/FreeCADCoreProbe/SurfaceFamilyProbe.cpp:fc_web_dispatch_json", facade: "web/src/surface-object-contract-facade.ts", worker: "web/src/surface-python.worker.ts", loader: "web/src/module-loader.ts", routerApi: ["WebModuleRouter.setArtifact", "WebModuleRouter.loadManifest", "WebModuleRouter.preload"] }, input: request, result, resultSha256: crypto.createHash("sha256").update(JSON.stringify(result)).digest("hex"), replay: { equal: true }, crossModule: crossModule.records[0], records: [row], artifacts: { module: "Surface", worker: "surface-python.worker.ts", revision: row.sourceRevision, runtimeUrl: "/kernel/FreeCADWebSurfaceRuntimeProbe.js", wasmUrl: "/kernel/FreeCADWebSurfaceRuntimeProbe.wasm", dataUrl: null, assetBaseUrl: "/kernel/", runtimeSha256: crypto.createHash("sha256").update(fs.readFileSync(runtimePath)).digest("hex"), wasmSha256: crypto.createHash("sha256").update(fs.readFileSync(wasmPath)).digest("hex"), buildProfile: "fast-dev" }, boundaries: ["The fixture covers native Surface::Sections creation, NSections property registration, source-declared view-provider identity, recompute and document release.", "All statuses come from compiled FreeCAD through fc_web_dispatch_json; JavaScript only validates the focused batch."] }; fs.writeFileSync(path.join(root, "docs/p6/surface-view-provider-module-batch-87cbf4a32302b545768121c8-runtime.json"), JSON.stringify(report, null, 2) + "\n"); console.log(JSON.stringify({ result: report.status, batchId: report.batchId, code: row.code, viewProvider: row.viewProvider })); process.exit(0);
|