Files
FreeCADWasmDev/tools/run_p6_robot_facade.mjs
wangdequan 9a7c4f0335 Save FreeCAD Web workspace sources and user validation evidence
IFC native binding remains incomplete; preserve accurate test results.
2026-09-15 22:01:58 +08:00

2 lines
3.2 KiB
JavaScript

import assert from"node:assert/strict";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)),".."),build=path.resolve(process.argv[2]??path.join(root,"freecad-source/build-web/configure/bin")),out=fs.mkdtempSync(path.join(os.tmpdir(),"robot-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/robot-create-facade.ts"],{cwd:root,stdio:"inherit"});const f=await import(pathToFileURL(path.join(out,"robot-create-facade.js"))),e=await import(pathToFileURL(path.join(out,"facade-envelope.js"))),w=new Worker(path.join(root,"tools/robot-create-facade-smoke-worker.mjs"),{workerData:{buildDirectory:build,facadePath:pathToFileURL(path.join(out,"robot-create-facade.js")).href,envelopePath:pathToFileURL(path.join(out,"facade-envelope.js")).href}}),recv=()=>new Promise((r,j)=>{const h=v=>{w.off("error",j);r(v)};w.once("message",h);w.once("error",j)}),ready=await recv(),sr=f.createRobotCreateRequest("robot-create-success");w.postMessage(sr);const success=await recv();w.postMessage(f.createRobotCreateRequest("robot-create-error",{...f.ROBOT_CREATE_FIXTURE,axis1:9}));const expected=await recv();w.postMessage(sr);const dup=await recv();const cancel=f.createRobotCreateRequest("robot-create-cancel"),cancelledP=new Promise((r,j)=>{const h=v=>{if(v.requestId===cancel.requestId){w.off("error",j);r(v)}};w.on("message",h);w.once("error",j)});w.postMessage(cancel);w.postMessage(e.createCancel("robot-create-cancel-control",cancel.requestId,"robot-create"));const cancelled=await cancelledP;w.postMessage(f.createRobotCreateRequest("robot-create-after"));const after=await recv();await w.terminate();assert.equal(ready.kind,"ready");assert.equal(success.kind,"result");assert.equal(success.result.objectType,"Robot::RobotObject");assert.equal(expected.error.code,"invalid_fixture");assert.equal(dup.error.code,"duplicate_request");assert.equal(cancelled.error.code,"cancelled");assert.equal(after.kind,"result");assert.equal(after.result.objectType,success.result.objectType);const trace={ready,success,expected,dup,cancelled,after},report={schema:"freecad-web-p6-robot-facade/v1",taskId:"FW-P6-ROB-E",module:"Robot",action:f.ROBOT_CREATE_COMMAND,result:"pass",typedSchema:f.ROBOT_CREATE_SCHEMA,trace,traceSha256:crypto.createHash("sha256").update(JSON.stringify(trace)).digest("hex"),sequencing:{requestCount:6,responseCount:6,maxActive:1,cancelAccepted:true},artifacts:{kernel:"docs/p6/robot-kernel.json",recovery:"docs/p6/robot-recovery.json",worker:"web/src/robot-create.worker.ts"}};fs.writeFileSync(path.join(root,"docs/p6/robot-facade.json"),JSON.stringify(report,null,2)+"\n");fs.writeFileSync(path.join(root,"docs/freecad-p6-robot-e-facade.log"),JSON.stringify({result:"pass",requests:6,cancel:cancelled.error.code})+"\n");console.log(JSON.stringify({result:"pass",requests:6,cancel:cancelled.error.code}));