4 lines
3.8 KiB
JavaScript
4 lines
3.8 KiB
JavaScript
#!/usr/bin/env node
|
|
import assert from "node:assert/strict"; import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; import { createRequire } from "node:module"; import { pathToFileURL } from "node:url";
|
|
const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), ".."); const facadePath = process.argv[2]; const facade = await import(pathToFileURL(path.resolve(facadePath))); const envelope = await import(pathToFileURL(path.join(path.dirname(path.resolve(facadePath)), "facade-envelope.js"))); const build = path.resolve(process.argv[3] ?? path.join(root, "freecad-source/build-web/configure/bin")); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url); const loader = await import(pathToFileURL(path.join(build, "FreeCADWebMeshPartRuntimeProbe.js"))); const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMeshPartRuntimeProbe.wasm")) }); const queue = new envelope.FacadeSerialQueue(); let active = 0; let maxActive = 0; async function dispatch(request, source = kernel) { return queue.dispatch(request, async (payload, signal) => { active += 1; maxActive = Math.max(maxActive, active); try { return await facade.handleMspInspect(payload, signal, source); } finally { active -= 1; } }); } const success = await dispatch(facade.createMspInspectRequest("msp-act02-success")); const expectedError = await dispatch(facade.createMspInspectRequest("msp-act02-error", { ...facade.MSP_INSPECT_FIXTURE, sourceEntry: "src/Mod/MeshPart/App/Unexpected.cpp" })); const duplicate = await dispatch(facade.createMspInspectRequest("msp-act02-success")); const delayed = new Promise((resolve) => setTimeout(() => resolve(kernel), 0)); const cancelRequest = facade.createMspInspectRequest("msp-act02-cancel"); const cancelPromise = dispatch(cancelRequest, delayed); const cancelAccepted = queue.cancel(envelope.createCancel("msp-act02-cancel-message", cancelRequest.requestId, "meshpart-source-inventory")); const cancelled = await cancelPromise; const afterCancel = await dispatch(facade.createMspInspectRequest("msp-act02-after-cancel")); assert.equal(success.kind, "result"); assert.equal(success.result.pythonMethodCount, 10); assert.equal(expectedError.error.code, "revision_mismatch"); assert.equal(duplicate.error.code, "duplicate_request"); assert.equal(cancelAccepted, true); assert.equal(cancelled.error.code, "cancelled"); assert.deepEqual(afterCancel.result, success.result); assert.equal(maxActive, 1); const responses = { success, expectedError, duplicate, cancelled, afterCancel }; const report = { schema: "freecad-web-p6-meshpart-action-02-facade/v1", taskId: "FW-P6-MSP-ACT-02-E", module: "MeshPart", action: facade.MSP_INSPECT_COMMAND, result: "pass", envelopeSchema: "freecad-web-facade/v1", typedSchema: facade.MSP_INSPECT_SCHEMA, fixture: { ...facade.MSP_INSPECT_FIXTURE, inputSha256: crypto.createHash("sha256").update(JSON.stringify(facade.MSP_INSPECT_FIXTURE)).digest("hex") }, responses, sequencing: { maxActive, requestCount: 5, responseCount: 5, cancelAccepted }, schemaChecks: { noNativePointers: !JSON.stringify(responses).match(/pointer|native/i) }, artifacts: { kernel: "docs/p6/meshpart-action-02-kernel.json", recovery: "docs/p6/meshpart-action-02-recovery.json", workerLog: "docs/freecad-p6-meshpart-action-02-e-facade.log" }, commands: ["npx tsc ... src/facade-envelope.ts src/meshpart-inspect-facade.ts", "node tools/run_p6_meshpart_action02_facade_smoke.mjs"] }; fs.writeFileSync(path.join(root, "docs/p6/meshpart-action-02-facade.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-meshpart-action-02-e-facade.log"), `${JSON.stringify({ result: report.result, maxActive, requests: 5, cancelAccepted })}\n`); console.log(JSON.stringify({ result: report.result, maxActive, requests: 5, cancelAccepted }));
|