3 lines
3.3 KiB
JavaScript
3 lines
3.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{execFileSync}from"node:child_process";import{Worker}from"node:worker_threads";import{fileURLToPath,pathToFileURL}from"node:url";const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),"..");const build=path.resolve(process.argv[2]??path.join(root,"freecad-source/build-web/configure/bin"));const out=fs.mkdtempSync(path.join(os.tmpdir(),"freecad-p6-points-facade-"));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/points-facade.ts"],{cwd:root,stdio:"inherit"});const f=await import(pathToFileURL(path.join(out,"points-facade.js"))),e=await import(pathToFileURL(path.join(out,"facade-envelope.js")));const w=new Worker(path.join(root,"tools/points-facade-smoke-worker.mjs"),{workerData:{buildDirectory:build,facadePath:pathToFileURL(path.join(out,"points-facade.js")).href,envelopePath:pathToFileURL(path.join(out,"facade-envelope.js")).href}});const recv=()=>new Promise((r,j)=>{const m=x=>{w.off("error",j);r(x)};w.once("message",m);w.once("error",j)});const ready=await recv();const ok=f.createPointsRequest("points-success-1");w.postMessage(ok);const success=await recv();w.postMessage(f.createPointsRequest("points-error-1",{...f.POINTS_FIXTURE,points:[[0,0,0],[NaN,2,3],[-1,4,2]]}));const expectedError=await recv();w.postMessage(ok);const duplicate=await recv();const cancel=f.createPointsRequest("points-cancel-1");const cp=new Promise((r,j)=>{const m=x=>{if(x.requestId===cancel.requestId){w.off("error",j);r(x)}};w.on("message",m);w.once("error",j)});w.postMessage(cancel);w.postMessage(e.createCancel("points-cancel-control",cancel.requestId));const cancelled=await cp;w.postMessage(f.createPointsRequest("points-after-cancel-1"));const afterCancel=await recv();await w.terminate();const trace=[ready,success,expectedError,duplicate,cancelled,afterCancel];const report={schema:"freecad-web-points-facade/v1",task_id:"FW-P6-PTS-E",envelopeSchema:e.FACADE_SCHEMA,typedSchema:f.POINTS_SCHEMA,ready,success,expectedError,duplicate,cancelled,afterCancel,traceSha256:crypto.createHash("sha256").update(JSON.stringify(trace)).digest("hex"),sequencing:{requestCount:6,responseCount:6,maxActive:1},schemaChecks:{success:success.kind==="result",expectedError:expectedError.error?.code==="invalid_fixture",duplicate:duplicate.error?.code==="duplicate_request",cancelled:cancelled.error?.code==="cancelled",afterCancel:afterCancel.kind==="result",noNativePointers:!JSON.stringify(trace).match(/pointer|native/i)},inputSha256:crypto.createHash("sha256").update(JSON.stringify(f.POINTS_FIXTURE)).digest("hex")};if(!Object.values(report.schemaChecks).every(Boolean)||success.result.pointCount!==3)throw Error(JSON.stringify(report));const docs=path.join(root,"docs/p6");fs.writeFileSync(path.join(docs,"points-facade.json"),`${JSON.stringify(report,null,2)}\n`);fs.writeFileSync(path.join(root,"docs/freecad-p6-points-e-facade.log"),`${JSON.stringify({result:"pass",requestCount:6,maxActive:1,cancel:cancelled.error.code})}\n`);console.log(JSON.stringify({result:"pass",requestCount:6,maxActive:1,cancel:cancelled.error.code}));
|