4 lines
6.4 KiB
JavaScript
4 lines
6.4 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{createRequire}from"node:module";import{pathToFileURL}from"node:url";
|
|
const root="/home/mes123456/FreeCADWasmDev/working/FreeCAD",build=path.resolve(process.argv[2]??path.join(root,"freecad-source/build-web/configure/bin")),docs=path.join(root,"docs/p6"),out=fs.mkdtempSync(path.join(os.tmpdir(),"freecad-p6-pd-tier2-"));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/partdesign-python-family-facade.ts"],{cwd:root,stdio:"inherit"});const hash=v=>crypto.createHash("sha256").update(typeof v==="string"?v:JSON.stringify(v)).digest("hex"),mp=path.join(docs,"python-api-manifest.json"),manifest=JSON.parse(fs.readFileSync(mp,"utf8")),rows=manifest.records.filter(r=>r.module==="PartDesign"&&r.tier==="tier-2-pure");if(rows.length!==135)throw new Error(`expected 135 PartDesign records, got ${rows.length}`);const records=rows.map(r=>({apiId:r.id,name:r.name,family:r.family,sourcePath:r.evidence?.path,disposition:r.disposition}));globalThis.__dirname=`${build}${path.sep}`;globalThis.require=createRequire(import.meta.url);process.chdir(path.dirname(build));const facade=await import(pathToFileURL(path.join(out,"partdesign-python-family-facade.js"))),env=await import(pathToFileURL(path.join(out,"facade-envelope.js"))),loader=await import(pathToFileURL(path.join(build,"FreeCADWebPartDesignRuntimeProbe.js"))),kernel=await loader.default({wasmBinary:fs.readFileSync(path.join(build,"FreeCADWebPartDesignRuntimeProbe.wasm")),locateFile:f=>path.join(build,f),print:()=>{},printErr:()=>{}}),q=new env.FacadeSerialQueue(),dispatch=(r,k=kernel)=>facade.dispatchPartDesignPythonFamily(q,r,k);const request=facade.createPartDesignPythonFamilyRequest("pd-tier2-success",records,"tier-2-pure"),success=await dispatch(request),repeated=await dispatch(facade.createPartDesignPythonFamilyRequest("pd-tier2-replay",records,"tier-2-pure")),cross=await dispatch(facade.createPartDesignPythonFamilyRequest("pd-tier2-cross",[{...records[0],apiId:"py:BIM:class:Binding"}],"tier-2-pure")),malformed=await dispatch({...request,requestId:"pd-tier2-invalid-tier",payload:{...request.payload,tier:"tier-unsupported"}}),cancelRequest=facade.createPartDesignPythonFamilyRequest("pd-tier2-cancel",records,"tier-2-pure"),cancelledPromise=dispatch(cancelRequest,new Promise(resolve=>setTimeout(()=>resolve(kernel),25)));q.cancel(env.createCancel("pd-tier2-cancel-control",cancelRequest.requestId));const cancelled=await cancelledPromise;if(success.kind!=="result")throw new Error(`PartDesign dispatch failed: ${JSON.stringify(success)}`);const result=success.result;if(result.module!=="PartDesign"||result.tier!=="tier-2-pure"||result.count!==rows.length||result.records.length!==rows.length||result.resourcesReleased!==true)throw new Error("PartDesign result incomplete");if(result.records.some(r=>r.native!==true||r.resourcesReleased!==true||!r.sourceEntry||!r.sourceRevision||typeof r.parameterSchema!=="string"||typeof r.returnSchema!=="string"))throw new Error("PartDesign metadata incomplete");if(JSON.stringify(result)!==JSON.stringify(repeated.result))throw new Error("PartDesign replay changed");if(cross.kind!=="result"||cross.result.records?.[0]?.code!=="unmatched_source_record")throw new Error("PartDesign cross-module boundary failed");if(malformed.kind!=="error"||!["invalid_request","invalid_fixture"].includes(malformed.error.code))throw new Error("PartDesign invalid tier was not rejected");if(cancelled.kind!=="error"||cancelled.error.code!=="cancelled")throw new Error("PartDesign cancellation was not reported");const counts=Object.fromEntries(["exposed","restricted","nonportable","not_implemented"].map(s=>[s,result.records.filter(r=>r.status===s).length])),byId=new Map(result.records.map(r=>[r.apiId,r]));for(const row of manifest.records)if(row.module==="PartDesign"&&row.tier==="tier-2-pure"){const n=byId.get(row.id);row.disposition=n.status;row.dispositionEvidence=["docs/p6/partdesign-tier2-pure-family-runtime.json"];row.dispositionReason=n.message;}fs.writeFileSync(mp,`${JSON.stringify(manifest,null,2)}\n`);const report={schema:"freecad-web-p6-partdesign-tier2-pure-family-runtime/v1",taskId:"FW-P6-FPA-F2-PARTDESIGN",module:"PartDesign",tier:"tier-2-pure",status:"pass_with_boundaries",sourceRevision:result.records[0]?.sourceRevision,route:{worker:"web/src/partdesign-python.worker.ts",facade:"web/src/partdesign-python-family-facade.ts",command:facade.PARTDESIGN_PYTHON_FAMILY_COMMAND,native:"freecad-source/src/WebAssembly/FreeCADCoreProbe/PartDesignRuntimeProbe.cpp:fc_web_dispatch_json"},input:request,inputSha256:hash(request),result,resultSha256:hash(result),replay:{equal:true,resultSha256:hash(repeated.result)},crossModuleBoundary:{result:cross,resultSha256:hash(cross)},malformedRequest:{result:malformed,resultSha256:hash(malformed)},cancellation:{result:cancelled,resultSha256:hash(cancelled)},dispositionCounts:counts,records:result.records.map(r=>({apiId:r.apiId,name:r.name,family:r.family,status:r.status,code:r.code,parameterSchema:r.parameterSchema,returnSchema:r.returnSchema,sourceEntry:r.sourceEntry,sourceRevision:r.sourceRevision,evidenceSha256:hash(r)})),resources:{resourcesReleased:true,documentMutation:false},artifacts:{wasm:{path:path.relative(root,path.join(build,"FreeCADWebPartDesignRuntimeProbe.wasm")),sha256:hash(fs.readFileSync(path.join(build,"FreeCADWebPartDesignRuntimeProbe.wasm")))},loader:{path:path.relative(root,path.join(build,"FreeCADWebPartDesignRuntimeProbe.js")),sha256:hash(fs.readFileSync(path.join(build,"FreeCADWebPartDesignRuntimeProbe.js")))}},boundaries:["PartDesign methods without typed fixtures remain not_implemented.","All statuses and schemas derive from compiled FreeCAD through fc_web_dispatch_json."]};fs.writeFileSync(path.join(docs,"partdesign-tier2-pure-family-runtime.json"),`${JSON.stringify(report,null,2)}\n`);fs.writeFileSync(path.join(root,"docs/freecad-p6-partdesign-f2-tier2.log"),`${JSON.stringify({status:report.status,count:rows.length,dispositionCounts:counts,resultSha256:report.resultSha256})}\n`);console.log(JSON.stringify({status:report.status,count:rows.length,dispositionCounts:counts,resultSha256:report.resultSha256}));
|