geospec 0.1.0-beta.9 → 0.4.1-next.331
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -9
- package/agent/doctrine.md +2 -1
- package/agent/geospec-authoring/SKILL.md +3 -3
- package/agent/geospec-authoring/api-index.md +20 -92
- package/agent/geospec-authoring/api-types.md +85 -480
- package/agent/geospec-authoring/public-api-functions.md +21 -1
- package/agent/geospec-authoring/public-api-index.md +215 -319
- package/agent/geospec-authoring/public-api-types-2.md +480 -352
- package/agent/geospec-authoring/public-api-types-3.md +79 -215
- package/agent/geospec-authoring/public-api-types.md +334 -849
- package/agent/resources.js +12 -13
- package/agent/skills.json +2 -3
- package/dist/assertion-client/client.d.mts +14 -15
- package/dist/assertion-client/client.mjs +1 -1
- package/dist/cli/check.mjs +2 -0
- package/dist/cli/cli.d.mts +5 -5
- package/dist/cli/cli.mjs +20 -3
- package/dist/cli/node-host.d.mts +5 -4
- package/dist/cli/node-host.mjs +1 -1
- package/dist/cli/wire-value.mjs +1 -1
- package/dist/config/define-config.d.mts +2 -3
- package/dist/config/node/index.mjs +1 -1
- package/dist/config/node/load.d.mts +2 -3
- package/dist/config/node/load.mjs +1 -1
- package/dist/config/read-geospec-config.d.mts +10 -6
- package/dist/config/read-geospec-config.mjs +1 -1
- package/dist/config/types.d.mts +6 -7
- package/dist/create-geospec.d.mts +7 -6
- package/dist/engine/client.d.mts +15 -15
- package/dist/engine/client.mjs +1 -1
- package/dist/engine/matchers.d.mts +10 -11
- package/dist/engine/pmi.types.d.mts +11 -12
- package/dist/engine/protocol.d.mts +7 -8
- package/dist/engine/protocol.mjs +1 -1
- package/dist/geometry-unit.d.mts +2 -3
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/mesh/index.d.mts +2 -2
- package/dist/mesh/types.d.mts +8 -505
- package/dist/model/errors.d.mts +2 -3
- package/dist/model/load-model.d.mts +3 -4
- package/dist/model/mesh-evidence-matchers.d.mts +2 -3
- package/dist/model/native-model-loader.d.mts +14 -17
- package/dist/model/native-model-loader.mjs +1 -1
- package/dist/model/node/command-exporter.d.mts +3 -4
- package/dist/model/node/command-exporter.mjs +1 -1
- package/dist/model/node/index.mjs +1 -1
- package/dist/model/region-scope.d.mts +3 -6
- package/dist/model/region-scope.mjs +1 -1
- package/dist/model/subject.d.mts +2 -5
- package/dist/model/subject.mjs +1 -1
- package/dist/model/types.d.mts +19 -20
- package/dist/runner/collector.d.mts +7 -8
- package/dist/runner/collector.mjs +3 -1
- package/dist/runner/discovery.d.mts +10 -11
- package/dist/runner/discovery.mjs +5 -1
- package/dist/runner/filter.d.mts +6 -7
- package/dist/runner/filter.mjs +3 -1
- package/dist/runner/index.d.mts +3 -1
- package/dist/runner/index.mjs +1 -1
- package/dist/runner/native/native-pool-grants.d.mts +2 -3
- package/dist/runner/native/native-serial-runner.d.mts +4 -7
- package/dist/runner/native/native-serial-runner.mjs +1 -1
- package/dist/runner/node/engine.d.mts +5 -6
- package/dist/runner/node/index.mjs +1 -1
- package/dist/runner/node/node-vm-filesystem.d.mts +4 -5
- package/dist/runner/node/node-vm-filesystem.mjs +1 -1
- package/dist/runner/node/pool-runner.d.mts +15 -6
- package/dist/runner/node/pool-runner.mjs +1 -1
- package/dist/runner/node/pool-worker-entry.d.mts +9 -6
- package/dist/runner/node/pool-worker-entry.mjs +1 -1
- package/dist/runner/pool/events.mjs +1 -1
- package/dist/runner/pool/pool-messages.d.mts +8 -9
- package/dist/runner/pool/pool.d.mts +4 -6
- package/dist/runner/pool/pool.mjs +1 -1
- package/dist/runner/pool/shard-timings.d.mts +3 -4
- package/dist/runner/pool/worker-host.d.mts +6 -5
- package/dist/runner/pool/worker-host.mjs +1 -1
- package/dist/runner/run-geospec-module.d.mts +2 -3
- package/dist/runner/run-geospec-module.mjs +2 -2
- package/dist/runner/timeout-codes.d.mts +6 -8
- package/dist/runner/types.d.mts +56 -53
- package/dist/runner/worker/no-matching-tests-issue.d.mts +3 -4
- package/dist/runner/worker/runner-types.d.mts +17 -16
- package/dist/runner/worker/serial-runner.mjs +1 -1
- package/dist/selector/types.d.mts +22 -23
- package/dist/step/types.d.mts +4 -119
- package/dist/support/filesystem-errors.mjs +1 -0
- package/dist/support/hash.mjs +1 -0
- package/dist/support/path.mjs +1 -0
- package/dist/support/sha256.mjs +1 -0
- package/dist/support/types.d.mts +38 -0
- package/dist/vitest/adapter.d.mts +5 -6
- package/dist/vitest/adapter.mjs +1 -1
- package/dist/vitest/index.d.mts +0 -1
- package/dist/vitest/index.mjs +1 -1
- package/dist/vitest/node/index.d.mts +2 -0
- package/dist/vitest/node/index.mjs +1 -0
- package/dist/vitest/node/setup-project.d.mts +60 -0
- package/dist/vitest/node/setup-project.mjs +1 -0
- package/dist/vm/plain-module-vm.d.mts +13 -0
- package/dist/vm/plain-module-vm.mjs +8 -0
- package/dist/vm/types.d.mts +142 -0
- package/package.json +17 -9
- package/agent/geospec-authoring/api-types-2.md +0 -85
|
@@ -1 +1 @@
|
|
|
1
|
-
import{geoSpecAuthoredWorkUnitLimitProblem as e,resolveGeoSpecMaximumWorkUnitLimit as t}from"../engine/client.mjs";import{bindRawSubjectResidency as n}from"./subject.mjs";import{GeoSpecModelLoadError as r}from"./errors.mjs";import{assertRootedPath as i,isNotFoundError as a,joinRelativePath as o,sha256Bytes as s}from"@taucad/runtime/kernel";const c={canonicalProfile:`geospec-jcs-v1`,protocolVersion:3,registryVersion:5},l=new TextEncoder,u=new TextDecoder(`utf-8`,{fatal:!0}),d=new Set([`glb`,`step`,`stp`]),f=new WeakMap,p=16777216,m=e=>e instanceof Error&&`code`in e&&e.code===`limit-exceeded`&&`capacity`in e&&typeof e.capacity==`object`&&e.capacity!==null&&`unit`in e.capacity&&e.capacity.unit===`retained subjects`,h=(e,t)=>Object.assign(RangeError(e),{code:`limit-exceeded`,capacity:{code:`GEOSPEC_RESOURCE_LIMIT`,limitClass:`admission`,unit:`bytes`,...t,source:`host`}}),g=e=>{let t=f.get(e);if(t!==void 0)return t;let n=x(e.processRequest(y({...c,method:`initialize`,requestId:`configuration`})),`initialize response`),r=b(n.result,`initialize result`);if(n.requestId!==`configuration`||r.protocolVersion!==3||r.registryVersion!==5||r.canonicalProfile!==`geospec-jcs-v1`)throw TypeError(`Native GeoSpec residency requires a compatible initialize profile.`);let i=b(r.configuration,`initialize configuration`),a=b(i.binaryAdmissionLimits,`binary admission limits`),o=[a.maxSubjectBytes,a.maxTotalBinaryBytes].map(e=>{if(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0)throw TypeError(`Native GeoSpec residency requires safe positive binary admission limits.`);return e}),s={inputs:new Map,resident:new Map,binaryLimit:Math.max(...o),binaryBytes:0,descriptorBytes:0};return f.set(e,s),s},_=e=>new r(e),v=e=>({code:e.code,severity:`error`,message:e.message,suggestion:e.suggestion,...e.details===void 0?{}:{details:e.details}}),y=e=>l.encode(JSON.stringify(e)),b=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`Native GeoSpec returned a non-object ${t}.`);return e},x=(e,t)=>b(JSON.parse(u.decode(e)),t),S=/^(?:\/|[A-Za-z][A-Za-z0-9+.-]*:)/u,C=(e,t)=>e===void 0||S.test(t)?t:o(e,t),w=e=>{try{return i(e),!0}catch{return!1}},T=(e,t)=>`code`in e?{}:`source`in e?{...typeof e.source==`string`?{source:C(t,e.source)}:{},...e.resources===void 0?{}:{resources:e.resources.map(e=>typeof e.source==`string`?{...e,source:C(t,e.source)}:e)}}:{file:C(t,e.file)},E=(e,t)=>`${e.replace(/[/\\]+$/u,``)}/${t}`,D=e=>{let{path:t,projectPath:n,rootDir:r}=e;return v({code:`GEOSPEC_MODEL_SOURCE_NOT_FOUND`,message:`loadModel found no file '${t}'${r===void 0?``:` (rootDir '${r}')`} in the project root${n===void 0?``:` ${n}, looking for ${E(n,t)}`}.`,suggestion:`loadModel({ file }) resolves against the project root, the same root as every tool's targetFile: name the model by its path from that root, or pass rootDir with the project-relative folder it is in, as in loadModel({ file: 'main.ts', rootDir: 'parts/gear' }).`,details:{path:t,...r===void 0?{}:{rootDir:r},...n===void 0?{}:{projectRoot:n}}})},O=async(e,t,n={})=>{if(e instanceof Uint8Array)return Uint8Array.from(e);if(e instanceof ArrayBuffer)return Uint8Array.from(new Uint8Array(e));if(typeof Blob<`u`&&e instanceof Blob)return new Uint8Array(await e.arrayBuffer());if(t!==void 0)try{return await t(e)}catch(t){let{projectPath:r,rootDir:i}=n,a=typeof e==`string`&&r!==void 0&&!S.test(e);throw _([v({code:`GEOSPEC_NATIVE_SOURCE_READ_FAILED`,message:`The host source reader could not read ${typeof e==`string`?e:`this source`}${a?` at ${E(r,e)} in the project root ${r}${i===void 0?``:` (rootDir '${i}')`}`:``}: ${t instanceof Error?t.message:String(t)}`,suggestion:`Check that the source exists at its path from the project root, or pass rootDir with the project-relative folder it is in, and that it is readable, then retry the load.`,...typeof e==`string`?{details:{source:e,...i===void 0?{}:{rootDir:i},...a?{projectRoot:r}:{}}}:{}})])}throw _([v({code:`GEOSPEC_NATIVE_SOURCE_READER_UNAVAILABLE`,message:`The native model loader cannot read this source form without a host source reader.`,suggestion:`Pass in-memory bytes or configure readSource on createGeoSpecNativeModelLoader().`})])},k=(e,t)=>{let n=t.slice(t.lastIndexOf(`/`)+1),r=n.lastIndexOf(`.`),i=r<=0?``:n.slice(r+1).toLowerCase();return e.extensions.some(e=>e===`*`||i!==``&&e.replace(/^\./u,``).toLowerCase()===i)},A=({exporter:e,file:t,capability:n,reason:r,details:i={}})=>_([v({code:`GEOSPEC_EXPORTER_UNSUPPORTED`,message:`Exporter '${e.id}' cannot export '${t}': ${r}`,suggestion:`Keep the claim and report it as unsupported by this exporter, or configure an exporter that declares the capability.`,details:{exporter:e.id,file:t,capability:n,...i}})]),j=(e,t,n)=>_([v({code:`GEOSPEC_EXPORTER_INVALID_ARTIFACT`,message:`Exporter '${e.id}' returned an artifact GeoSpec cannot admit for '${t}': ${n}`,suggestion:`Fix the exporter so it returns non-empty bytes in the requested format.`,details:{exporter:e.id,file:t}})]),M=/^(?:sha256:)?([0-9a-f]{64})$/u,N=(e,t)=>{if(t===void 0||t.length===0)return;let n={};for(let{path:e,sha256:r}of t){let t=M.exec(r)?.[1];n[e]=t===void 0?r:`sha256:${t}`}return{entry:e,files:n}},P=(e,t)=>{let n=e.format??t??`glb`;if(!d.has(n))throw _([v({code:`GEOSPEC_NATIVE_MODEL_FORMAT_UNSUPPORTED`,message:`The native model host does not admit '${n}' models.`,suggestion:`Use 'step', 'stp', or 'glb' for native model assertions.`,details:{format:n}})]);return n},F=e=>{if(e===null||typeof e==`boolean`||typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`)return Number.isFinite(e)?JSON.stringify(e):void 0;if(Array.isArray(e)){let t=e.map(e=>F(e));return t.includes(void 0)?void 0:`[${t.join(`,`)}]`}if(typeof e==`object`&&Object.getPrototypeOf(e)===Object.prototype){let t=Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:1).map(([e,t])=>[e,F(t)]);return t.some(([,e])=>e===void 0)?void 0:`{${t.map(([e,t])=>`${JSON.stringify(e)}:${t}`).join(`,`)}}`}},I=e=>Array.isArray(e)&&e.length===3&&e.every(e=>typeof e==`number`&&Number.isFinite(e)),L=e=>{if(e===void 0)return;let t=typeof e==`object`&&e?e:{},{min:n,max:r}=t;return I(n)&&I(r)&&Object.keys(t).every(e=>e===`min`||e===`max`)&&n.every((e,t)=>e<r[t])?void 0:_([v({code:`GEOSPEC_MODEL_OPTION_INVALID`,message:`loadModel region must be { min: [x, y, z], max: [x, y, z] } in millimetres with every min axis below its max axis.`,suggestion:`Pass finite millimetre corners of the box to check, for example { min: [0, 0, 0], max: [40, 40, 60] }.`,details:{option:`region`,region:structuredClone(e)}})])},R=({min:e,max:t})=>({min:[e[0],e[1],e[2]],max:[t[0],t[1],t[2]]}),z=(e,t)=>{let n=N(e.entry,t);if(n===void 0)return!1;let{files:r}=n;return Object.entries(r).every(([t,n])=>n===`missing`||e.files[t]===n)&&Object.entries(e.files).every(([e,t])=>t===`missing`?r[e]===void 0||r[e]===`missing`:r[e]===t)},B=i=>{let o=0,l=t(i.maximumWorkUnitLimit),u=new Map,d=new Map,S=0,C=new Set,E=new Map,M=new Set,I=e=>(o+=1,`geospec-native-model:${e}:${o}`),B=e=>{let t=i.exporters??[],n=t.find(t=>k(t,e.file));if(n!==void 0)return n;throw _([v({code:`GEOSPEC_EXPORTER_MISSING`,message:t.length===0?`No exporter is configured, so GeoSpec cannot export '${e.file}'.`:`No configured exporter claims '${e.file}', so GeoSpec cannot export it.`,suggestion:`Give the host an exporter whose extensions include this file's, or load STEP or GLB bytes directly.`,details:{file:e.file,exporters:t.map(({id:e})=>e)}})])},V=e=>{i.engine.releaseSubject(y({...c,method:`releaseSubject`,requestId:I(`release`),subjectHandle:e}))},H=(e,t)=>{let n=f.get(i.engine),r=n?.inputs.get(e);if(n!==void 0&&r!==void 0&&(r.cleanupPending?.(),delete r.cleanupPending,r.owners.has(t))){if(r.owners.size>1){r.owners.delete(t);return}r.handle!==void 0&&(V(r.handle),delete r.handle),r.owners.delete(t),n.resident.delete(e),n.inputs.delete(e),n.binaryBytes-=r.resources.reduce((e,t)=>e+t.byteLength,r.primary.byteLength),n.descriptorBytes-=r.request.byteLength}},U=e=>{for(let[t,n]of e.inputs)n.cleanupPending!==void 0&&(n.cleanupPending(),delete n.cleanupPending,delete n.handle,e.resident.delete(t))},W=()=>[...i.carried??[]].filter(([e])=>!u.has(e)),G=(e,t)=>{let n=e.format===`stp`?`step`:e.format,r=g(i.engine);U(r);let a=y({...c,method:`ingestSubject`,requestId:I(`ingest`),format:n,frame:{coordinateSystem:`z-up`,sourceUnit:n===`step`?`auto`:e.sourceUnit??`m`,outputUnit:`mm`},ingestOptions:e.ingestOptions??{},...e.diagnostics===void 0||e.diagnostics.length===0?{}:{diagnostics:e.diagnostics},primaryByteLength:e.primary.byteLength,resources:e.resources.map(({name:e,bytes:t})=>({name:e,byteLength:t.byteLength}))}),o=e.resources.reduce((e,{bytes:t})=>e+t.byteLength,e.primary.byteLength);if(!Number.isSafeInteger(o)||o>r.binaryLimit)throw h(`GeoSpec retained admission input exceeds its byte limit.`,{name:`maxTotalBinaryBytes`,limit:r.binaryLimit,required:o});if(a.byteLength>p)throw h(`GeoSpec retained admission input exceeds its byte limit.`,{name:`descriptorBytes`,limit:p,required:a.byteLength});let s=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),l={...x(a,`admission request`),requestId:``},f=[...r.inputs.values()].find(t=>{let n={...x(t.request,`retained request`),requestId:``};return JSON.stringify(n)===JSON.stringify(l)&&s(t.primary,e.primary)&&t.resources.length===e.resources.length&&t.resources.every((t,n)=>s(t,e.resources[n].bytes))});if(f===void 0&&o>r.binaryLimit-r.binaryBytes)throw h(`GeoSpec live admission snapshots exceed their retained input byte limit.`,{name:`maxTotalBinaryBytes`,limit:r.binaryLimit,required:r.binaryBytes+o});if(f===void 0&&a.byteLength>p-r.descriptorBytes)throw h(`GeoSpec live admission snapshots exceed their retained input byte limit.`,{name:`descriptorBytes`,limit:p,required:r.descriptorBytes+a.byteLength});let _=f??{request:Uint8Array.from(a),primary:Uint8Array.from(e.primary),resources:e.resources.map(({bytes:e})=>Uint8Array.from(e)),owners:new Set},v=()=>i.engine.ingestSubject(a,e.primary,e.resources.map(({bytes:e})=>e)),S;try{S=v()}catch(e){let t=W();if(!m(e))throw e;let n=!1;for(let[e,a]of t){let t=r.inputs.get(e);if(t===void 0)V(a),n=!0;else{let r=t.owners.size===1&&t.handle!==void 0;H(e,i.carried),n||=r}i.carried?.delete(e)}if(!n){let t=r.resident.entries().next().value;if(t===void 0)throw e;V(t[1].handle),delete t[1].handle,r.resident.delete(t[0])}S=v()}let C=x(S,`admission response`),w=b(C.result,`admission result`),{subjectHash:T}=b(w.subject,`admitted subject`);if(typeof T!=`string`||!/^[0-9a-f]{64}$/u.test(T))throw TypeError(`Native GeoSpec admission did not return a valid subjectHash.`);let E=x(i.engine.subjectHandle(y({...c,method:`subjectHandle`,requestId:I(`handle`),subjectHash:T})),`subject-handle response`),D=b(E.result,`subject-handle result`).subjectHandle;if(D===void 0)throw TypeError(`Native GeoSpec did not return a subject handle.`);let O=r.inputs.get(T),k=O??_;O===void 0&&(r.inputs.set(T,k),r.binaryBytes+=o,r.descriptorBytes+=k.request.byteLength);for(let e of t)k.owners.add(e),d.set(e,T);return k.handle=D,r.resident.delete(T),r.resident.set(T,k),u.set(T,k),{subjectHash:T}},K=e=>{let t=u.get(e);if(t===void 0)throw TypeError(`This subject is not admitted by the active GeoSpec host.`);let n=g(i.engine);if(U(n),t.handle===void 0){let r=()=>i.engine.ingestSubject(t.request,t.primary,t.resources),a;try{a=r()}catch(e){let t=n.resident.entries().next().value;if(!m(e)||t===void 0)throw e;V(t[1].handle),delete t[1].handle,n.resident.delete(t[0]),a=r()}let o=()=>{let t=b(x(i.engine.subjectHandle(y({...c,method:`subjectHandle`,requestId:I(`restore-handle`),subjectHash:e})),`restored handle`).result,`restored handle result`),n=b(t.subjectHandle,`restored subject handle`);if(n.subjectHash!==e)throw TypeError(`Native GeoSpec restored handle changed its subject identity.`);return n};try{if(b(b(x(a,`restored admission`).result,`restored result`).subject,`restored subject`).subjectHash!==e)throw TypeError(`Native GeoSpec restored admission changed its subject identity.`);t.handle=o()}catch(e){throw t.cleanupPending=()=>{try{V(o())}catch(t){throw AggregateError([e,t],`Native GeoSpec restored admission failed and cleanup remains pending.`,{cause:e})}},t.cleanupPending(),delete t.cleanupPending,e}}n.resident.delete(e),n.resident.set(e,t)},q=async e=>{if(i.readSource===void 0)return!1;try{return await i.readSource(e),!1}catch(e){return a(e)}},J=async(e,t)=>!(`code`in e)&&await q(e.file)?_([D({path:e.file,projectPath:i.projectPath,rootDir:e.rootDir})]):t,Y=async(e,t)=>{let n=P(e,i.format),r={projectPath:i.projectPath,rootDir:e.rootDir},a=await O(e.source,i.readSource,r),o=await Promise.all((e.resources??[]).map(async({name:e,source:t})=>({name:e,bytes:await O(t,i.readSource,r),...typeof t==`string`?{sourcePath:t}:{}}))),c=await Promise.all([{name:e.path??e.name??`primary`,bytes:a,...typeof e.source==`string`?{sourcePath:e.source}:{}},...o].map(async({name:e,bytes:t,sourcePath:n})=>({name:e,sha256:await s(t),byteLength:t.byteLength,...n===void 0?{}:{sourcePath:n}})));return{...G({format:n,primary:a,resources:o,...e.ingestOptions===void 0?{}:{ingestOptions:e.ingestOptions},...e.sourceUnit===void 0?{}:{sourceUnit:e.sourceUnit}},t),load:{loadId:``,status:`complete`,format:n,parameters:e.parameters??{},ingestOptions:e.ingestOptions??{},...typeof e.source==`string`?{sourcePath:e.source}:{},...e.rootDir===void 0?{}:{rootDir:e.rootDir},...e.workUnitLimit===void 0?{}:{workUnitLimit:e.workUnitLimit},artifacts:c}}},X=async(e,t)=>{let{exporter:n,options:a,format:o}=e,{capabilities:c}=n;if(!c.formats.includes(o))throw A({exporter:n,file:a.file,capability:`formats`,reason:`it does not produce ${o.toUpperCase()}.`,details:{format:o,formats:[...c.formats]}});let l=`code`in a?a.code:void 0;if(l!==void 0&&c.inlineSources!==!0)throw A({exporter:n,file:a.file,capability:`inlineSources`,reason:`it does not accept inline sources.`});let u=a.parameters===void 0||Object.keys(a.parameters).length===0?void 0:a.parameters;if(u!==void 0&&c.parameters!==!0)throw A({exporter:n,file:a.file,capability:`parameters`,reason:`it does not accept parameters.`,details:{parameters:Object.keys(u)}});let d=a.region===void 0?void 0:R(a.region);if(d!==void 0&&c.region!==!0)throw A({exporter:n,file:a.file,capability:`region`,reason:`it does not crop to a region.`,details:{region:d}});let f=a.projectPath??i.projectPath,p=a.meshLinearTolerance===void 0&&a.meshAngularToleranceDegrees===void 0?void 0:{...a.meshLinearTolerance===void 0?{}:{linearTolerance:a.meshLinearTolerance},...a.meshAngularToleranceDegrees===void 0?{}:{angularToleranceDegrees:a.meshAngularToleranceDegrees}},m={file:a.file,format:o,...f===void 0?{}:{projectPath:f},...u===void 0?{}:{parameters:structuredClone(u)},...p===void 0?{}:{mesh:p},...d===void 0?{}:{region:R(d)},...l===void 0?{}:{inline:{...l}}},h;M.add(n);try{h=await n.export(m)}catch(e){throw await J(a,e instanceof r?e:_([v({code:`GEOSPEC_EXPORTER_FAILED`,message:`Exporter '${n.id}' failed to export '${a.file}': ${e instanceof Error?e.message:String(e)}`,suggestion:`Fix the model or the exporter, then rerun.`,details:{exporter:n.id,file:a.file,format:o}})]))}if(!(h.bytes instanceof Uint8Array)||h.bytes.byteLength===0)throw j(n,a.file,`its bytes are empty.`);if(h.format!==o)throw j(n,a.file,`it is ${String(h.format)}, not the requested ${o}.`);let g=(h.resources??[]).map(({name:e,bytes:t})=>({name:e,bytes:t})),y=await Promise.all([{name:`model.${o}`,bytes:h.bytes},...g].map(async({name:e,bytes:t})=>({name:e,sha256:await s(t),byteLength:t.byteLength}))),b=N(a.file,h.consumedSources),x=b!==void 0&&/^sha256:[0-9a-f]{64}$/u.test(b.files[b.entry]??``)&&Object.values(b.files).every(e=>e===`missing`||/^sha256:[0-9a-f]{64}$/u.test(e)),S=G({format:o,primary:h.bytes,resources:g,sourceUnit:h.sourceUnit??`mm`,...h.diagnostics===void 0?{}:{diagnostics:h.diagnostics},...a.ingestOptions===void 0?{}:{ingestOptions:a.ingestOptions}},t),C={exporter:n.id,...p===void 0?{}:{mesh:p},...d===void 0?{}:{region:{min:[...d.min],max:[...d.max]}},...h.exportOptions===void 0?{}:{options:structuredClone(h.exportOptions)}};return{...S,load:{loadId:``,status:x?`complete`:`unavailable`,format:o,parameters:a.parameters??{},exportOptions:C,ingestOptions:a.ingestOptions??{},...b===void 0?{}:{sourceRevision:b},...`rootDir`in a&&a.rootDir!==void 0?{rootDir:a.rootDir}:{},...a.workUnitLimit===void 0?{}:{workUnitLimit:a.workUnitLimit},...d===void 0?{}:{region:d},artifacts:y}}},Z=async(e,t)=>{for(let t of[`sourceUnit`,`unit`,`scale`,`coordinateSystem`])if(t in e)throw _([v({code:`GEOSPEC_NATIVE_RUNTIME_FRAME_OVERRIDE`,message:`Exported model loading rejects '${t}': the exporter owns the frame.`,suggestion:`Remove the frame override and let GeoSpec request canonical Z-up millimetre evidence.`,details:{key:t}})]);let n=P(e,i.format),r=n===`stp`?`step`:n;return X({exporter:B(e),options:e,format:r},t)},Q=(e,t)=>{let n=f.get(i.engine)?.inputs.get(e);return n===void 0||n.owners.size===0?!1:(n.owners.add(t),d.set(t,e),u.set(e,n),!0)},$=async(e,t,n)=>{let r=n.status===`complete`?n.sourceRevision:void 0;if(r===void 0||e.revision===void 0)return!1;let a=t.projectPath??i.projectPath;try{return z(r,await e.revision({file:t.file,...a===void 0?{}:{projectPath:a}}))}catch{return!1}},ee=async(e,t)=>{let n=i.exporters?.find(t=>k(t,e.file)),r=`code`in e,a=r&&Object.values(e.code).every(e=>typeof e==`string`)?e.code:void 0,o=n===void 0||r&&a===void 0||[`sourceUnit`,`unit`,`scale`,`coordinateSystem`].some(t=>t in e)?void 0:F({file:e.file,code:a,projectPath:e.projectPath??i.projectPath,format:e.format??i.format??`glb`,meshLinearTolerance:e.meshLinearTolerance,meshAngularToleranceDegrees:e.meshAngularToleranceDegrees,parameters:e.parameters,ingestOptions:e.ingestOptions,region:e.region});if(n===void 0||o===void 0)return Z(e,new Set([t]));let s=E.get(n);s===void 0&&(s=new Map,E.set(n,s));let c=s.get(o);if(c!==void 0){c.owners?.add(t);let r=await c.pending;if((c.owners!==void 0||await $(n,e,r.load))&&Q(r.subjectHash,t)){let{workUnitLimit:t,rootDir:n,...i}=r.load;return{subjectHash:r.subjectHash,load:{...i,...`rootDir`in e&&e.rootDir!==void 0?{rootDir:e.rootDir}:{},...e.workUnitLimit===void 0?{}:{workUnitLimit:e.workUnitLimit},reused:!0}}}}let l=new Set([t]),u=Z(e,l),d={pending:u,...a===void 0?{}:{owners:l}};return s.set(o,d),u.then(void 0,()=>{s.delete(o)}),u};return Object.assign(t=>{let r={},a=I(`load`),o=`rootDir`in t?t.rootDir:void 0,s={...t,...`code`in t?{code:Object.fromEntries(Object.entries(t.code))}:{},...t.parameters===void 0?{}:{parameters:structuredClone(t.parameters)},...t.ingestOptions===void 0?{}:{ingestOptions:structuredClone(t.ingestOptions)},...`region`in t&&t.region!==void 0?{region:structuredClone(t.region)}:{},...typeof o==`string`&&w(o)?T(t,o):{}},c=t.format??i.format??`glb`,f=[`stepStreaming`,...`code`in t?[`rootDir`]:[],...t.mesh===!1&&(c===`step`||c===`stp`)?[]:[`mesh`],...`source`in t?[`meshLinearTolerance`,`meshAngularToleranceDegrees`,`region`,...c===`step`||c===`stp`?[`sourceUnit`]:[]]:[],...c===`step`||c===`stp`?[`region`]:[]].find(e=>e in t&&(e!==`region`&&e!==`rootDir`||t[e]!==void 0));if(f!==void 0)return Promise.reject(_([v({code:`GEOSPEC_MODEL_OPTION_UNSUPPORTED`,message:`This GeoSpec host cannot honor model option '${f}'.`,suggestion:`Remove this option or configure a host that supports its declared behavior.`,details:{option:f}})]));let p=e(t.workUnitLimit,`loadModel workUnitLimit`,l);if(p!==void 0)return Promise.reject(_([v({code:`GEOSPEC_MODEL_OPTION_INVALID`,message:p,suggestion:`Pass a positive integer workUnitLimit within the stated bound, or omit it for the engine default.`,details:{option:`workUnitLimit`}})]));let m=`source`in t?void 0:L(t.region);if(m!==void 0)return Promise.reject(m);if(o!==void 0&&!(typeof o==`string`&&w(o)))return Promise.reject(_([v({code:`GEOSPEC_MODEL_OPTION_INVALID`,message:`loadModel rootDir must be a project-relative folder in canonical form, such as 'parts/gear': no leading or trailing '/', and no '.' or '..' segments.`,suggestion:`Pass the folder the model is in, from the project root, as in rootDir: 'parts/gear', or name the file by its path from the project root.`,details:{option:`rootDir`,...typeof o==`string`?{rootDir:o}:{}}})]));let h=`source`in t?Y(s,new Set([r])):ee(s,r),g=(async()=>{let e=await h,t={...e,...e.load===void 0?{}:{load:{...e.load,loadId:a}}},i=S,o=!1;return n(t,{ensureResident(){if(i!==S||!d.has(r))throw TypeError(`This subject is not admitted by the active GeoSpec host.`);K(e.subjectHash)},dispose(){if(!(o||!d.has(r))){o=!0;try{H(e.subjectHash,r),d.delete(r),[...d.values()].includes(e.subjectHash)||u.delete(e.subjectHash)}finally{o=!1}}}}),t})();return C.add(g),g},{async releaseAll(){do{let e=[...C];await Promise.allSettled(e);for(let t of e)C.delete(t)}while(C.size>0);let e=[],{carried:t}=i;if(S+=1,E.clear(),t!==void 0){for(let[n,r]of W())try{f.get(i.engine)?.inputs.has(n)?H(n,t):V(r),t.delete(n)}catch(t){e.push(t)}for(let[e,n]of u)n.handle===void 0?(n.owners.delete(t),t.delete(e)):(n.owners.add(t),t.set(e,n.handle))}for(let[t,n]of[...d].reverse())try{H(n,t),d.delete(t),[...d.values()].includes(n)||u.delete(n)}catch(t){e.push(t)}for(let t of M)try{await t.close?.()}catch(t){e.push(t)}if(M.clear(),e.length>0)throw AggregateError(e,`Native GeoSpec model cleanup failed.`)}})};export{B as createGeoSpecNativeModelLoader};
|
|
1
|
+
import{geoSpecAuthoredWorkUnitLimitProblem as e,resolveGeoSpecMaximumWorkUnitLimit as t}from"../engine/client.mjs";import{bindRawSubjectResidency as n}from"./subject.mjs";import{GeoSpecModelLoadError as r}from"./errors.mjs";import{assertRootedPath as i,joinRelativePath as a}from"../support/path.mjs";import{sha256Bytes as o}from"../support/hash.mjs";import{isNotFoundError as s}from"../support/filesystem-errors.mjs";const c={canonicalProfile:`geospec-jcs-v1`,protocolVersion:3,registryVersion:5},l=new TextEncoder,u=new TextDecoder(`utf-8`,{fatal:!0}),d=/* @__PURE__ */ new Set([`glb`,`step`,`stp`]),f=/* @__PURE__ */ new WeakMap,p=16777216,m=e=>e instanceof Error&&`code`in e&&e.code===`limit-exceeded`&&`capacity`in e&&typeof e.capacity==`object`&&e.capacity!==null&&`unit`in e.capacity&&e.capacity.unit===`retained subjects`,h=(e,t)=>Object.assign(RangeError(e),{code:`limit-exceeded`,capacity:{code:`GEOSPEC_RESOURCE_LIMIT`,limitClass:`admission`,unit:`bytes`,...t,source:`host`}}),g=e=>{let t=f.get(e);if(t!==void 0)return t;let n=x(e.processRequest(y({...c,method:`initialize`,requestId:`configuration`})),`initialize response`),r=b(n.result,`initialize result`);if(n.requestId!==`configuration`||r.protocolVersion!==3||r.registryVersion!==5||r.canonicalProfile!==`geospec-jcs-v1`)throw TypeError(`Native GeoSpec residency requires a compatible initialize profile.`);let i=b(r.configuration,`initialize configuration`),a=b(i.binaryAdmissionLimits,`binary admission limits`),o=[a.maxSubjectBytes,a.maxTotalBinaryBytes].map(e=>{if(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0)throw TypeError(`Native GeoSpec residency requires safe positive binary admission limits.`);return e}),s={inputs:/* @__PURE__ */ new Map,resident:/* @__PURE__ */ new Map,binaryLimit:Math.max(...o),binaryBytes:0,descriptorBytes:0};return f.set(e,s),s},_=e=>new r(e),v=e=>({code:e.code,severity:`error`,message:e.message,suggestion:e.suggestion,...e.details===void 0?{}:{details:e.details}}),y=e=>l.encode(JSON.stringify(e)),b=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`Native GeoSpec returned a non-object ${t}.`);return e},x=(e,t)=>b(JSON.parse(u.decode(e)),t),S=/^(?:\/|[A-Za-z][A-Za-z0-9+.-]*:)/u,C=(e,t)=>e===void 0||S.test(t)?t:a(e,t),w=e=>{try{return i(e),!0}catch{return!1}},T=(e,t)=>`code`in e?{}:`source`in e?{...typeof e.source==`string`?{source:C(t,e.source)}:{},...e.resources===void 0?{}:{resources:e.resources.map(e=>typeof e.source==`string`?{...e,source:C(t,e.source)}:e)}}:{file:C(t,e.file)},E=(e,t)=>`${e.replace(/[/\\]+$/u,``)}/${t}`,D=e=>{let{path:t,projectPath:n,rootDir:r}=e;return v({code:`GEOSPEC_MODEL_SOURCE_NOT_FOUND`,message:`loadModel found no file '${t}'${r===void 0?``:` (rootDir '${r}')`} in the project root${n===void 0?``:` ${n}, looking for ${E(n,t)}`}.`,suggestion:`loadModel({ file }) resolves against the project root, the same root as every tool's targetFile: name the model by its path from that root, or pass rootDir with the project-relative folder it is in, as in loadModel({ file: 'main.ts', rootDir: 'parts/gear' }).`,details:{path:t,...r===void 0?{}:{rootDir:r},...n===void 0?{}:{projectRoot:n}}})},O=async(e,t,n={})=>{if(e instanceof Uint8Array)return Uint8Array.from(e);if(e instanceof ArrayBuffer)return Uint8Array.from(new Uint8Array(e));if(typeof Blob<`u`&&e instanceof Blob)return new Uint8Array(await e.arrayBuffer());if(t!==void 0)try{return await t(e)}catch(t){let{projectPath:r,rootDir:i}=n,a=typeof e==`string`&&r!==void 0&&!S.test(e);throw _([v({code:`GEOSPEC_NATIVE_SOURCE_READ_FAILED`,message:`The host source reader could not read ${typeof e==`string`?e:`this source`}${a?` at ${E(r,e)} in the project root ${r}${i===void 0?``:` (rootDir '${i}')`}`:``}: ${t instanceof Error?t.message:String(t)}`,suggestion:`Check that the source exists at its path from the project root, or pass rootDir with the project-relative folder it is in, and that it is readable, then retry the load.`,...typeof e==`string`?{details:{source:e,...i===void 0?{}:{rootDir:i},...a?{projectRoot:r}:{}}}:{}})])}throw _([v({code:`GEOSPEC_NATIVE_SOURCE_READER_UNAVAILABLE`,message:`The native model loader cannot read this source form without a host source reader.`,suggestion:`Pass in-memory bytes or configure readSource on createGeoSpecNativeModelLoader().`})])},k=(e,t)=>{let n=t.slice(t.lastIndexOf(`/`)+1),r=n.lastIndexOf(`.`),i=r<=0?``:n.slice(r+1).toLowerCase();return e.extensions.some(e=>e===`*`||i!==``&&e.replace(/^\./u,``).toLowerCase()===i)},A=({exporter:e,file:t,capability:n,reason:r,details:i={}})=>_([v({code:`GEOSPEC_EXPORTER_UNSUPPORTED`,message:`Exporter '${e.id}' cannot export '${t}': ${r}`,suggestion:`Keep the claim and report it as unsupported by this exporter, or configure an exporter that declares the capability.`,details:{exporter:e.id,file:t,capability:n,...i}})]),j=(e,t,n)=>_([v({code:`GEOSPEC_EXPORTER_INVALID_ARTIFACT`,message:`Exporter '${e.id}' returned an artifact GeoSpec cannot admit for '${t}': ${n}`,suggestion:`Fix the exporter so it returns non-empty bytes in the requested format.`,details:{exporter:e.id,file:t}})]),M=/^(?:sha256:)?([0-9a-f]{64})$/u,N=(e,t)=>{if(t===void 0||t.length===0)return;let n={};for(let{path:e,sha256:r}of t){let t=M.exec(r)?.[1];n[e]=t===void 0?r:`sha256:${t}`}return{entry:e,files:n}},P=(e,t)=>{let n=e.format??t??`glb`;if(!d.has(n))throw _([v({code:`GEOSPEC_NATIVE_MODEL_FORMAT_UNSUPPORTED`,message:`The native model host does not admit '${n}' models.`,suggestion:`Use 'step', 'stp', or 'glb' for native model assertions.`,details:{format:n}})]);return n},F=e=>{if(e===null||typeof e==`boolean`||typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`)return Number.isFinite(e)?JSON.stringify(e):void 0;if(Array.isArray(e)){let t=e.map(e=>F(e));return t.includes(void 0)?void 0:`[${t.join(`,`)}]`}if(typeof e==`object`&&Object.getPrototypeOf(e)===Object.prototype){let t=Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:1).map(([e,t])=>[e,F(t)]);return t.some(([,e])=>e===void 0)?void 0:`{${t.map(([e,t])=>`${JSON.stringify(e)}:${t}`).join(`,`)}}`}},I=e=>Array.isArray(e)&&e.length===3&&e.every(e=>typeof e==`number`&&Number.isFinite(e)),L=e=>{if(e===void 0)return;let t=typeof e==`object`&&e?e:{},{min:n,max:r}=t;return I(n)&&I(r)&&Object.keys(t).every(e=>e===`min`||e===`max`)&&n.every((e,t)=>e<r[t])?void 0:_([v({code:`GEOSPEC_MODEL_OPTION_INVALID`,message:`loadModel region must be { min: [x, y, z], max: [x, y, z] } in millimetres with every min axis below its max axis.`,suggestion:`Pass finite millimetre corners of the box to check, for example { min: [0, 0, 0], max: [40, 40, 60] }.`,details:{option:`region`,region:structuredClone(e)}})])},R=({min:e,max:t})=>({min:[e[0],e[1],e[2]],max:[t[0],t[1],t[2]]}),z=(e,t)=>{let n=N(e.entry,t);if(n===void 0)return!1;let{files:r}=n;return Object.entries(r).every(([t,n])=>n===`missing`||e.files[t]===n)&&Object.entries(e.files).every(([e,t])=>t===`missing`?r[e]===void 0||r[e]===`missing`:r[e]===t)},B=i=>{let a=0,l=t(i.maximumWorkUnitLimit),u=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Map,S=0,C=/* @__PURE__ */ new Set,E=/* @__PURE__ */ new Map,M=/* @__PURE__ */ new Set,I=e=>(a+=1,`geospec-native-model:${e}:${a}`),B=e=>{let t=i.exporters??[],n=t.find(t=>k(t,e.file));if(n!==void 0)return n;throw _([v({code:`GEOSPEC_EXPORTER_MISSING`,message:t.length===0?`No exporter is configured, so GeoSpec cannot export '${e.file}'.`:`No configured exporter claims '${e.file}', so GeoSpec cannot export it.`,suggestion:`Give the host an exporter whose extensions include this file's, or load STEP or GLB bytes directly.`,details:{file:e.file,exporters:t.map(({id:e})=>e)}})])},V=e=>{i.engine.releaseSubject(y({...c,method:`releaseSubject`,requestId:I(`release`),subjectHandle:e}))},H=(e,t)=>{let n=f.get(i.engine),r=n?.inputs.get(e);n!==void 0&&r!==void 0&&(r.cleanupPending?.(),delete r.cleanupPending,r.owners.has(t)&&(r.owners.size>1?r.owners.delete(t):(r.handle!==void 0&&(V(r.handle),delete r.handle),r.owners.delete(t),n.resident.delete(e),n.inputs.delete(e),n.binaryBytes-=r.resources.reduce((e,t)=>e+t.byteLength,r.primary.byteLength),n.descriptorBytes-=r.request.byteLength)))},U=e=>{for(let[t,n]of e.inputs)n.cleanupPending!==void 0&&(n.cleanupPending(),delete n.cleanupPending,delete n.handle,e.resident.delete(t))},W=()=>[...i.carried??[]].filter(([e])=>!u.has(e)),G=(e,t)=>{let n=e.format===`stp`?`step`:e.format,r=g(i.engine);U(r);let a=y({...c,method:`ingestSubject`,requestId:I(`ingest`),format:n,frame:{coordinateSystem:`z-up`,sourceUnit:n===`step`?`auto`:e.sourceUnit??`m`,outputUnit:`mm`},ingestOptions:e.ingestOptions??{},...e.diagnostics===void 0||e.diagnostics.length===0?{}:{diagnostics:e.diagnostics},primaryByteLength:e.primary.byteLength,resources:e.resources.map(({name:e,bytes:t})=>({name:e,byteLength:t.byteLength}))}),o=e.resources.reduce((e,{bytes:t})=>e+t.byteLength,e.primary.byteLength);if(!Number.isSafeInteger(o)||o>r.binaryLimit)throw h(`GeoSpec retained admission input exceeds its byte limit.`,{name:`maxTotalBinaryBytes`,limit:r.binaryLimit,required:o});if(a.byteLength>p)throw h(`GeoSpec retained admission input exceeds its byte limit.`,{name:`descriptorBytes`,limit:p,required:a.byteLength});let s=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),l={...x(a,`admission request`),requestId:``},f=[...r.inputs.values()].find(t=>{let n={...x(t.request,`retained request`),requestId:``};return JSON.stringify(n)===JSON.stringify(l)&&s(t.primary,e.primary)&&t.resources.length===e.resources.length&&t.resources.every((t,n)=>s(t,e.resources[n].bytes))});if(f===void 0&&o>r.binaryLimit-r.binaryBytes)throw h(`GeoSpec live admission snapshots exceed their retained input byte limit.`,{name:`maxTotalBinaryBytes`,limit:r.binaryLimit,required:r.binaryBytes+o});if(f===void 0&&a.byteLength>p-r.descriptorBytes)throw h(`GeoSpec live admission snapshots exceed their retained input byte limit.`,{name:`descriptorBytes`,limit:p,required:r.descriptorBytes+a.byteLength});let _=f??{request:Uint8Array.from(a),primary:Uint8Array.from(e.primary),resources:e.resources.map(({bytes:e})=>Uint8Array.from(e)),owners:/* @__PURE__ */ new Set},v=()=>i.engine.ingestSubject(a,e.primary,e.resources.map(({bytes:e})=>e)),S;try{S=v()}catch(e){let t=W();if(!m(e))throw e;let n=!1;for(let[e,a]of t){let t=r.inputs.get(e);if(t===void 0)V(a),n=!0;else{let r=t.owners.size===1&&t.handle!==void 0;H(e,i.carried),n||=r}i.carried?.delete(e)}if(!n){let t=r.resident.entries().next().value;if(t===void 0)throw e;V(t[1].handle),delete t[1].handle,r.resident.delete(t[0])}S=v()}let C=x(S,`admission response`),w=b(C.result,`admission result`),{subjectHash:T}=b(w.subject,`admitted subject`);if(typeof T!=`string`||!/^[0-9a-f]{64}$/u.test(T))throw TypeError(`Native GeoSpec admission did not return a valid subjectHash.`);let E=x(i.engine.subjectHandle(y({...c,method:`subjectHandle`,requestId:I(`handle`),subjectHash:T})),`subject-handle response`),D=b(E.result,`subject-handle result`).subjectHandle;if(D===void 0)throw TypeError(`Native GeoSpec did not return a subject handle.`);let O=r.inputs.get(T),k=O??_;O===void 0&&(r.inputs.set(T,k),r.binaryBytes+=o,r.descriptorBytes+=k.request.byteLength);for(let e of t)k.owners.add(e),d.set(e,T);return k.handle=D,r.resident.delete(T),r.resident.set(T,k),u.set(T,k),{subjectHash:T}},K=e=>{let t=u.get(e);if(t===void 0)throw TypeError(`This subject is not admitted by the active GeoSpec host.`);let n=g(i.engine);if(U(n),t.handle===void 0){let r=()=>i.engine.ingestSubject(t.request,t.primary,t.resources),a;try{a=r()}catch(e){let t=n.resident.entries().next().value;if(!m(e)||t===void 0)throw e;V(t[1].handle),delete t[1].handle,n.resident.delete(t[0]),a=r()}let o=()=>{let t=b(x(i.engine.subjectHandle(y({...c,method:`subjectHandle`,requestId:I(`restore-handle`),subjectHash:e})),`restored handle`).result,`restored handle result`),n=b(t.subjectHandle,`restored subject handle`);if(n.subjectHash!==e)throw TypeError(`Native GeoSpec restored handle changed its subject identity.`);return n};try{if(b(b(x(a,`restored admission`).result,`restored result`).subject,`restored subject`).subjectHash!==e)throw TypeError(`Native GeoSpec restored admission changed its subject identity.`);t.handle=o()}catch(e){throw t.cleanupPending=()=>{try{V(o())}catch(t){throw AggregateError([e,t],`Native GeoSpec restored admission failed and cleanup remains pending.`,{cause:e})}},t.cleanupPending(),delete t.cleanupPending,e}}n.resident.delete(e),n.resident.set(e,t)},q=async e=>{if(i.readSource===void 0)return!1;try{return await i.readSource(e),!1}catch(e){return s(e)}},J=async(e,t)=>!(`code`in e)&&await q(e.file)?_([D({path:e.file,projectPath:i.projectPath,rootDir:e.rootDir})]):t,Y=async(e,t)=>{let n=P(e,i.format),r={projectPath:i.projectPath,rootDir:e.rootDir},a=await O(e.source,i.readSource,r),s=await Promise.all((e.resources??[]).map(async({name:e,source:t})=>({name:e,bytes:await O(t,i.readSource,r),...typeof t==`string`?{sourcePath:t}:{}}))),c=await Promise.all([{name:e.path??e.name??`primary`,bytes:a,...typeof e.source==`string`?{sourcePath:e.source}:{}},...s].map(async({name:e,bytes:t,sourcePath:n})=>({name:e,sha256:await o(t),byteLength:t.byteLength,...n===void 0?{}:{sourcePath:n}})));return{...G({format:n,primary:a,resources:s,...e.ingestOptions===void 0?{}:{ingestOptions:e.ingestOptions},...e.sourceUnit===void 0?{}:{sourceUnit:e.sourceUnit}},t),load:{loadId:``,status:`complete`,format:n,parameters:e.parameters??{},ingestOptions:e.ingestOptions??{},...typeof e.source==`string`?{sourcePath:e.source}:{},...e.rootDir===void 0?{}:{rootDir:e.rootDir},...e.workUnitLimit===void 0?{}:{workUnitLimit:e.workUnitLimit},artifacts:c}}},X=async(e,t)=>{let{exporter:n,options:a,format:s}=e,{capabilities:c}=n;if(!c.formats.includes(s))throw A({exporter:n,file:a.file,capability:`formats`,reason:`it does not produce ${s.toUpperCase()}.`,details:{format:s,formats:[...c.formats]}});let l=`code`in a?a.code:void 0;if(l!==void 0&&c.inlineSources!==!0)throw A({exporter:n,file:a.file,capability:`inlineSources`,reason:`it does not accept inline sources.`});let u=a.parameters===void 0||Object.keys(a.parameters).length===0?void 0:a.parameters;if(u!==void 0&&c.parameters!==!0)throw A({exporter:n,file:a.file,capability:`parameters`,reason:`it does not accept parameters.`,details:{parameters:Object.keys(u)}});let d=a.region===void 0?void 0:R(a.region);if(d!==void 0&&c.region!==!0)throw A({exporter:n,file:a.file,capability:`region`,reason:`it does not crop to a region.`,details:{region:d}});let f=a.projectPath??i.projectPath,p=a.meshLinearTolerance===void 0&&a.meshAngularToleranceDegrees===void 0?void 0:{...a.meshLinearTolerance===void 0?{}:{linearTolerance:a.meshLinearTolerance},...a.meshAngularToleranceDegrees===void 0?{}:{angularToleranceDegrees:a.meshAngularToleranceDegrees}},m={file:a.file,format:s,...f===void 0?{}:{projectPath:f},...u===void 0?{}:{parameters:structuredClone(u)},...p===void 0?{}:{mesh:p},...d===void 0?{}:{region:R(d)},...l===void 0?{}:{inline:{...l}}},h;M.add(n);try{h=await n.export(m)}catch(e){throw await J(a,e instanceof r?e:_([v({code:`GEOSPEC_EXPORTER_FAILED`,message:`Exporter '${n.id}' failed to export '${a.file}': ${e instanceof Error?e.message:String(e)}`,suggestion:`Fix the model or the exporter, then rerun.`,details:{exporter:n.id,file:a.file,format:s}})]))}if(!(h.bytes instanceof Uint8Array)||h.bytes.byteLength===0)throw j(n,a.file,`its bytes are empty.`);if(h.format!==s)throw j(n,a.file,`it is ${String(h.format)}, not the requested ${s}.`);let g=(h.resources??[]).map(({name:e,bytes:t})=>({name:e,bytes:t})),y=await Promise.all([{name:`model.${s}`,bytes:h.bytes},...g].map(async({name:e,bytes:t})=>({name:e,sha256:await o(t),byteLength:t.byteLength}))),b=N(a.file,h.consumedSources),x=b!==void 0&&/^sha256:[0-9a-f]{64}$/u.test(b.files[b.entry]??``)&&Object.values(b.files).every(e=>e===`missing`||/^sha256:[0-9a-f]{64}$/u.test(e)),S=G({format:s,primary:h.bytes,resources:g,sourceUnit:h.sourceUnit??`mm`,...h.diagnostics===void 0?{}:{diagnostics:h.diagnostics},...a.ingestOptions===void 0?{}:{ingestOptions:a.ingestOptions}},t),C={exporter:n.id,...p===void 0?{}:{mesh:p},...d===void 0?{}:{region:{min:[...d.min],max:[...d.max]}},...h.exportOptions===void 0?{}:{options:structuredClone(h.exportOptions)}};return{...S,load:{loadId:``,status:x?`complete`:`unavailable`,format:s,parameters:a.parameters??{},exportOptions:C,ingestOptions:a.ingestOptions??{},...b===void 0?{}:{sourceRevision:b},...`rootDir`in a&&a.rootDir!==void 0?{rootDir:a.rootDir}:{},...a.workUnitLimit===void 0?{}:{workUnitLimit:a.workUnitLimit},...d===void 0?{}:{region:d},artifacts:y}}},Z=async(e,t)=>{for(let t of[`sourceUnit`,`unit`,`scale`,`coordinateSystem`])if(t in e)throw _([v({code:`GEOSPEC_NATIVE_RUNTIME_FRAME_OVERRIDE`,message:`Exported model loading rejects '${t}': the exporter owns the frame.`,suggestion:`Remove the frame override and let GeoSpec request canonical Z-up millimetre evidence.`,details:{key:t}})]);let n=P(e,i.format),r=n===`stp`?`step`:n;return X({exporter:B(e),options:e,format:r},t)},Q=(e,t)=>{let n=f.get(i.engine)?.inputs.get(e);return n===void 0||n.owners.size===0?!1:(n.owners.add(t),d.set(t,e),u.set(e,n),!0)},$=async(e,t,n)=>{let r=n.status===`complete`?n.sourceRevision:void 0;if(r===void 0||e.revision===void 0)return!1;let a=t.projectPath??i.projectPath;try{return z(r,await e.revision({file:t.file,...a===void 0?{}:{projectPath:a}}))}catch{return!1}},ee=async(e,t)=>{let n=i.exporters?.find(t=>k(t,e.file)),r=`code`in e,a=r&&Object.values(e.code).every(e=>typeof e==`string`)?e.code:void 0,o=n===void 0||r&&a===void 0||[`sourceUnit`,`unit`,`scale`,`coordinateSystem`].some(t=>t in e)?void 0:F({file:e.file,code:a,projectPath:e.projectPath??i.projectPath,format:e.format??i.format??`glb`,meshLinearTolerance:e.meshLinearTolerance,meshAngularToleranceDegrees:e.meshAngularToleranceDegrees,parameters:e.parameters,ingestOptions:e.ingestOptions,region:e.region});if(n===void 0||o===void 0)return Z(e,/* @__PURE__ */ new Set([t]));let s=E.get(n);s===void 0&&(s=/* @__PURE__ */ new Map,E.set(n,s));let c=s.get(o);if(c!==void 0){c.owners?.add(t);let r=await c.pending;if((c.owners!==void 0||await $(n,e,r.load))&&Q(r.subjectHash,t)){let{workUnitLimit:t,rootDir:n,...i}=r.load;return{subjectHash:r.subjectHash,load:{...i,...`rootDir`in e&&e.rootDir!==void 0?{rootDir:e.rootDir}:{},...e.workUnitLimit===void 0?{}:{workUnitLimit:e.workUnitLimit},reused:!0}}}}let l=/* @__PURE__ */ new Set([t]),u=Z(e,l),d={pending:u,...a===void 0?{}:{owners:l}};return s.set(o,d),u.then(void 0,()=>{s.delete(o)}),u};return Object.assign(t=>{let r={},a=I(`load`),o=`rootDir`in t?t.rootDir:void 0,s={...t,...`code`in t?{code:Object.fromEntries(Object.entries(t.code))}:{},...t.parameters===void 0?{}:{parameters:structuredClone(t.parameters)},...t.ingestOptions===void 0?{}:{ingestOptions:structuredClone(t.ingestOptions)},...`region`in t&&t.region!==void 0?{region:structuredClone(t.region)}:{},...typeof o==`string`&&w(o)?T(t,o):{}},c=t.format??i.format??`glb`,f=[`stepStreaming`,...`code`in t?[`rootDir`]:[],...t.mesh===!1&&(c===`step`||c===`stp`)?[]:[`mesh`],...`source`in t?[`meshLinearTolerance`,`meshAngularToleranceDegrees`,`region`,...c===`step`||c===`stp`?[`sourceUnit`]:[]]:[],...c===`step`||c===`stp`?[`region`]:[]].find(e=>e in t&&(e!==`region`&&e!==`rootDir`||t[e]!==void 0));if(f!==void 0)return Promise.reject(_([v({code:`GEOSPEC_MODEL_OPTION_UNSUPPORTED`,message:`This GeoSpec host cannot honor model option '${f}'.`,suggestion:`Remove this option or configure a host that supports its declared behavior.`,details:{option:f}})]));let p=e(t.workUnitLimit,`loadModel workUnitLimit`,l);if(p!==void 0)return Promise.reject(_([v({code:`GEOSPEC_MODEL_OPTION_INVALID`,message:p,suggestion:`Pass a positive integer workUnitLimit within the stated bound, or omit it for the engine default.`,details:{option:`workUnitLimit`}})]));let m=`source`in t?void 0:L(t.region);if(m!==void 0)return Promise.reject(m);if(o!==void 0&&!(typeof o==`string`&&w(o)))return Promise.reject(_([v({code:`GEOSPEC_MODEL_OPTION_INVALID`,message:`loadModel rootDir must be a project-relative folder in canonical form, such as 'parts/gear': no leading or trailing '/', and no '.' or '..' segments.`,suggestion:`Pass the folder the model is in, from the project root, as in rootDir: 'parts/gear', or name the file by its path from the project root.`,details:{option:`rootDir`,...typeof o==`string`?{rootDir:o}:{}}})]));let h=`source`in t?Y(s,/* @__PURE__ */ new Set([r])):ee(s,r),g=(async()=>{let e=await h,t={...e,...e.load===void 0?{}:{load:{...e.load,loadId:a}}},i=S,o=!1;return n(t,{ensureResident(){if(i!==S||!d.has(r))throw TypeError(`This subject is not admitted by the active GeoSpec host.`);K(e.subjectHash)},dispose(){if(!o&&d.has(r)){o=!0;try{H(e.subjectHash,r),d.delete(r),[...d.values()].includes(e.subjectHash)||u.delete(e.subjectHash)}finally{o=!1}}}}),t})();return C.add(g),g},{async releaseAll(){do{let e=[...C];await Promise.allSettled(e);for(let t of e)C.delete(t)}while(C.size>0);let e=[],{carried:t}=i;if(S+=1,E.clear(),t!==void 0){for(let[n,r]of W())try{f.get(i.engine)?.inputs.has(n)?H(n,t):V(r),t.delete(n)}catch(t){e.push(t)}for(let[e,n]of u)n.handle===void 0?(n.owners.delete(t),t.delete(e)):(n.owners.add(t),t.set(e,n.handle))}for(let[t,n]of[...d].reverse())try{H(n,t),d.delete(t),[...d.values()].includes(n)||u.delete(n)}catch(t){e.push(t)}for(let t of M)try{await t.close?.()}catch(t){e.push(t)}if(M.clear(),e.length>0)throw AggregateError(e,`Native GeoSpec model cleanup failed.`)}})};export{B as createGeoSpecNativeModelLoader};
|
|
@@ -5,7 +5,7 @@ import { GeoSpecExporterCapabilities, GeoSpecModelExporter } from "../types.mjs"
|
|
|
5
5
|
*
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
|
-
type CommandExporterOptions = {
|
|
8
|
+
export type CommandExporterOptions = {
|
|
9
9
|
readonly id: string;
|
|
10
10
|
/** File extensions without the dot, or `'*'`. */
|
|
11
11
|
readonly extensions: readonly string[];
|
|
@@ -28,6 +28,5 @@ type CommandExporterOptions = {
|
|
|
28
28
|
* @throws TypeError when the options are incomplete or declare `inlineSources`.
|
|
29
29
|
* @public
|
|
30
30
|
*/
|
|
31
|
-
declare const commandExporter: (options: CommandExporterOptions) => GeoSpecModelExporter;
|
|
32
|
-
//#endregion
|
|
33
|
-
export { CommandExporterOptions, commandExporter };
|
|
31
|
+
export declare const commandExporter: (options: CommandExporterOptions) => GeoSpecModelExporter;
|
|
32
|
+
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{GeoSpecModelLoadError as e}from"../errors.mjs";import{z as t}from"zod";import{
|
|
1
|
+
import{GeoSpecModelLoadError as e}from"../errors.mjs";import{z as t}from"zod";import{isAbsolute as n,join as r,relative as i,resolve as a,sep as o}from"node:path";import{mkdtemp as s,readFile as c,rm as l}from"node:fs/promises";import{tmpdir as u}from"node:os";import{spawn as d}from"node:child_process";import f from"node:process";const p=t.object({protocol:t.literal(1),error:t.object({code:t.string().min(1),message:t.string(),suggestion:t.string().optional()})}),m=t.object({protocol:t.literal(1),format:t.enum([`glb`,`step`]),sourceUnit:t.string().optional(),primary:t.string().min(1),resources:t.array(t.object({name:t.string().min(1),path:t.string().min(1)})).optional(),consumedSources:t.array(t.object({path:t.string().min(1),sha256:t.string().min(1)}))}),h=({id:t,file:n,reason:r,details:i={}})=>new e([{code:`GEOSPEC_EXPORTER_FAILED`,severity:`error`,message:`Exporter '${t}' failed to export '${n}': ${r}`,suggestion:`Run the exporter command by hand with the same arguments and fix what it reports.`,details:{exporter:t,file:n,...i}}]),g=(e,t)=>{let r=a(e,t),s=i(e,r);return s===``||s===`..`||s.startsWith(`..${o}`)||n(s)?void 0:r},_=async e=>{let t=await c(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)},v=(e,t,n)=>[`--file`,e.file,`--format`,e.format,`--project`,t,`--out`,n,...e.parameters===void 0?[]:[`--parameters-json`,JSON.stringify(e.parameters)],...e.mesh?.linearTolerance===void 0?[]:[`--mesh-linear-tolerance`,String(e.mesh.linearTolerance)],...e.mesh?.angularToleranceDegrees===void 0?[]:[`--mesh-angular-tolerance-degrees`,String(e.mesh.angularToleranceDegrees)],...e.region===void 0?[]:[`--region-min`,e.region.min.join(`,`),`--region-max`,e.region.max.join(`,`)]],y=e=>{let t=new TextDecoder;return e.map(e=>t.decode(e,{stream:!0})).join(``)+t.decode()},b=async(e,t,n)=>new Promise((r,i)=>{let a=d(e,t,{cwd:n.cwd,env:n.env,stdio:[`ignore`,`pipe`,`pipe`],...n.signal===void 0?{}:{signal:n.signal}}),o=[],s=[];a.stdout.on(`data`,e=>o.push(e)),a.stderr.on(`data`,e=>s.push(e));let c,l;a.once(`error`,e=>{a.pid===void 0?i(e):(c=e,l=setTimeout(()=>a.kill(`SIGKILL`),2e3))}),a.once(`close`,e=>{clearTimeout(l),c===void 0?r({exitCode:e??void 0,stdout:y(o),stderr:y(s)}):i(c)})}),x=t=>{let[n,...i]=t.command;if(t.id===``||t.extensions.length===0||n===void 0||n===``)throw TypeError(`commandExporter needs an id, at least one extension and a command.`);if(t.capabilities.formats.length===0)throw TypeError(`commandExporter '${t.id}' must declare at least one format.`);if(t.exportTimeout!==void 0&&!(Number.isInteger(t.exportTimeout)&&t.exportTimeout>0&&t.exportTimeout<=2147483647))throw TypeError(`commandExporter '${t.id}' exportTimeout must be whole milliseconds from 1 to 2147483647.`);if(t.capabilities.inlineSources===!0)throw TypeError(`commandExporter '${t.id}' cannot accept inline sources: protocol 1 passes files only.`);let{id:a,exportTimeout:o}=t;return{id:a,extensions:[...t.extensions],capabilities:{...t.capabilities,formats:[...t.capabilities.formats]},async export(c){let d=c.projectPath??t.cwd??f.cwd(),y=await s(r(u(),`geospec-export-`));try{let r=o===void 0?void 0:AbortSignal.timeout(o),s=[c.signal,r].filter(e=>e!==void 0),l;try{l=await b(n,[...i,...v(c,d,y)],{cwd:t.cwd??d,env:{...f.env,...t.env},signal:s.length>1?AbortSignal.any(s):s[0]})}catch(e){throw r?.aborted===!0&&c.signal?.aborted!==!0?h({id:a,file:c.file,reason:`it ran longer than ${String(o)} ms.`,details:{exportTimeout:o}}):h({id:a,file:c.file,reason:`the command could not run (${e instanceof Error?e.message:String(e)}).`})}let u=l.stderr.slice(-2e3),x;try{x=JSON.parse(l.stdout)}catch{throw h({id:a,file:c.file,reason:`it printed no protocol 1 JSON document (exit ${String(l.exitCode)}).`,details:{exitCode:l.exitCode,stderr:u}})}let S=p.safeParse(x);if(S.success){let{code:t,message:n,suggestion:r}=S.data.error;throw new e([{code:t,severity:`error`,message:n,...r===void 0?{}:{suggestion:r},details:{exporter:a,file:c.file}}])}let C=m.safeParse(x);if(l.exitCode!==0||!C.success)throw h({id:a,file:c.file,reason:l.exitCode===0?`its JSON document is not a protocol 1 response.`:`it exited ${String(l.exitCode)} without a protocol 1 error.`,details:{exitCode:l.exitCode,stderr:u}});let w=C.data,T=g(y,w.primary),E=(w.resources??[]).flatMap(({name:e,path:t})=>{let n=g(y,t);return n===void 0?[]:[{name:e,path:n}]});if(T===void 0||E.length!==(w.resources??[]).length)throw h({id:a,file:c.file,reason:`it named an artifact outside its output directory.`});let[D,O]=await Promise.all([_(T),Promise.all(E.map(async({name:e,path:t})=>({name:e,bytes:await _(t)})))]);return{bytes:D,format:w.format,...w.sourceUnit===void 0?{}:{sourceUnit:w.sourceUnit},...O.length===0?{}:{resources:O},consumedSources:w.consumedSources}}finally{await l(y,{recursive:!0,force:!0})}}}};export{x as commandExporter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{commandExporter}from"./command-exporter.mjs";
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import "../mesh/types.mjs";
|
|
2
|
-
import "./types.mjs";
|
|
3
1
|
import { GeoSpecAssertion } from "../runner/types.mjs";
|
|
4
2
|
//#region src/model/region-scope.d.ts
|
|
5
3
|
/**
|
|
@@ -12,12 +10,11 @@ import { GeoSpecAssertion } from "../runner/types.mjs";
|
|
|
12
10
|
*
|
|
13
11
|
* @public
|
|
14
12
|
*/
|
|
15
|
-
declare const geoSpecRegionScopedKinds: ReadonlySet<GeoSpecAssertion['kind']>;
|
|
13
|
+
export declare const geoSpecRegionScopedKinds: ReadonlySet<GeoSpecAssertion['kind']>;
|
|
16
14
|
/**
|
|
17
15
|
* Diagnostic code of a whole-model claim made on a region-cropped subject.
|
|
18
16
|
*
|
|
19
17
|
* @public
|
|
20
18
|
*/
|
|
21
|
-
declare const geoSpecRegionWholeModelClaimCode = "GEOSPEC_REGION_WHOLE_MODEL_CLAIM";
|
|
22
|
-
//#endregion
|
|
23
|
-
export { geoSpecRegionScopedKinds, geoSpecRegionWholeModelClaimCode };
|
|
19
|
+
export declare const geoSpecRegionWholeModelClaimCode = "GEOSPEC_REGION_WHOLE_MODEL_CLAIM";
|
|
20
|
+
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e
|
|
1
|
+
const e=/* @__PURE__ */ new Set([`boundingBox`,`volume`,`surfaceArea`,`mass`,`centerOfMass`]),t=`GEOSPEC_REGION_WHOLE_MODEL_CLAIM`,n=(n,r)=>n===void 0||e.has(r)?void 0:{code:t,severity:`error`,message:`A '${r}' claim is about the whole model, and this subject is cropped to the region min [${n.min.join(`, `)}] max [${n.max.join(`, `)}] mm, so the claim cannot be decided on it.`,suggestion:`Keep the claim and make it on a whole-model load (loadModel without region). If the whole model exceeds a host limit, report the claim as not decided at this capacity. A region load answers only bounding box, volume, surface area, mass and center of mass of that region.`,details:{kind:r,region:{min:[...n.min],max:[...n.max]},regionScopedKinds:[...e]}};export{e as geoSpecRegionScopedKinds,t as geoSpecRegionWholeModelClaimCode,n as regionScopeRefusal};
|
package/dist/model/subject.d.mts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import "./native-model-loader.mjs";
|
|
2
|
-
import "../engine/client.mjs";
|
|
3
|
-
import "../assertion-client/client.mjs";
|
|
4
1
|
//#region src/model/subject.d.ts
|
|
5
2
|
declare const subjectBrand: unique symbol;
|
|
6
3
|
/** A model admitted by one live GeoSpec host scope. Load it through `geospec/model`. @public */
|
|
7
|
-
type GeoSpecSubject = {
|
|
4
|
+
export type GeoSpecSubject = {
|
|
8
5
|
readonly [subjectBrand]: true;
|
|
9
6
|
};
|
|
10
7
|
//#endregion
|
|
11
|
-
export {
|
|
8
|
+
export {};
|
package/dist/model/subject.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e
|
|
1
|
+
const e=/* @__PURE__ */ new WeakMap,t=/* @__PURE__ */ new WeakMap,n=(n,r)=>{e.set(n,r),t.set(r.ensureResident,r)},r=t=>e.get(t)?.ensureResident,i=/* @__PURE__ */ new WeakMap,a=e=>{let n=Object.freeze({});return i.set(n,{client:e.client,engine:e.engine,identity:e.identity,isLive:e.isLive,...e.load===void 0?{}:{load:e.load},...e.ensureResident===void 0?{}:{ensureResident:e.ensureResident},...e.ensureResident===void 0||!t.has(e.ensureResident)?{}:{lease:t.get(e.ensureResident)}}),n},o=(e,t)=>{let n=typeof e==`object`&&e?i.get(e):void 0;if(n===void 0||!n.isLive()||t!==void 0&&n.engine!==t)throw Object.assign(/* @__PURE__ */ TypeError(`This subject is not admitted by the active GeoSpec host. Reload it within its live scope.`),{code:`GEOSPEC_SUBJECT_INVALID`});return n.ensureResident?.(),n};export{a as bindGeoSpecSubject,n as bindRawSubjectResidency,r as rawSubjectResidency,o as resolveGeoSpecSubject};
|
package/dist/model/types.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GeoSpecUnit } from "../geometry-unit.mjs";
|
|
2
|
-
import { StepSource, StepStreamingMode } from "../step/types.mjs";
|
|
3
2
|
import { GeometryDiagnostic, MeshFileFormat } from "../mesh/types.mjs";
|
|
4
3
|
import { GeoSpecSubject } from "./subject.mjs";
|
|
4
|
+
import { StepSource, StepStreamingMode } from "../step/types.mjs";
|
|
5
5
|
import { GeoSpecNativeModelEngine, GeoSpecNativeSourceReader } from "./native-model-loader.mjs";
|
|
6
6
|
//#region src/model/types.d.ts
|
|
7
7
|
/**
|
|
@@ -9,7 +9,7 @@ import { GeoSpecNativeModelEngine, GeoSpecNativeSourceReader } from "./native-mo
|
|
|
9
9
|
*
|
|
10
10
|
* @public
|
|
11
11
|
*/
|
|
12
|
-
type MeshBufferSource = {
|
|
12
|
+
export type MeshBufferSource = {
|
|
13
13
|
format: 'mesh-buffer';
|
|
14
14
|
positions: Float32Array<ArrayBuffer> | number[];
|
|
15
15
|
indices?: Uint32Array<ArrayBuffer> | Uint16Array<ArrayBuffer> | number[];
|
|
@@ -20,26 +20,26 @@ type MeshBufferSource = {
|
|
|
20
20
|
*
|
|
21
21
|
* @public
|
|
22
22
|
*/
|
|
23
|
-
type MeshSource = Uint8Array<ArrayBuffer> | ArrayBuffer | Blob | File | URL | string | MeshBufferSource;
|
|
23
|
+
export type MeshSource = Uint8Array<ArrayBuffer> | ArrayBuffer | Blob | File | URL | string | MeshBufferSource;
|
|
24
24
|
/**
|
|
25
25
|
* Geometry formats accepted by {@link import('./load-model.js').loadModel}.
|
|
26
26
|
*
|
|
27
27
|
* @public
|
|
28
28
|
*/
|
|
29
|
-
type GeoSpecModelFormat = MeshFileFormat | 'step' | 'stp';
|
|
29
|
+
export type GeoSpecModelFormat = MeshFileFormat | 'step' | 'stp';
|
|
30
30
|
/**
|
|
31
31
|
* Formats a {@link GeoSpecModelExporter} may produce from a source-kind file.
|
|
32
32
|
*
|
|
33
33
|
* @public
|
|
34
34
|
*/
|
|
35
|
-
type GeoSpecExportFormat = Extract<GeoSpecModelFormat, 'glb' | 'step'>;
|
|
35
|
+
export type GeoSpecExportFormat = Extract<GeoSpecModelFormat, 'glb' | 'step'>;
|
|
36
36
|
/**
|
|
37
37
|
* What a {@link GeoSpecModelExporter} declares it can do. The loader refuses a load the exporter
|
|
38
38
|
* cannot serve with `GEOSPEC_EXPORTER_UNSUPPORTED` before it calls `export`.
|
|
39
39
|
*
|
|
40
40
|
* @public
|
|
41
41
|
*/
|
|
42
|
-
type GeoSpecExporterCapabilities = {
|
|
42
|
+
export type GeoSpecExporterCapabilities = {
|
|
43
43
|
/** The formats `export` produces; at least one. A GLB-only exporter refuses STEP loads up front. */
|
|
44
44
|
readonly formats: readonly GeoSpecExportFormat[];
|
|
45
45
|
/** Accepts `parameters`. Without it, a load that passes parameters refuses. */
|
|
@@ -55,7 +55,7 @@ type GeoSpecExporterCapabilities = {
|
|
|
55
55
|
*
|
|
56
56
|
* @public
|
|
57
57
|
*/
|
|
58
|
-
type GeoSpecModelExportRequest = {
|
|
58
|
+
export type GeoSpecModelExportRequest = {
|
|
59
59
|
/** Entry file, as a path from the project root. */
|
|
60
60
|
readonly file: string;
|
|
61
61
|
/** Absolute project root the exporter resolves `file` and its imports against, when the host has one. */
|
|
@@ -79,7 +79,7 @@ type GeoSpecModelExportRequest = {
|
|
|
79
79
|
*
|
|
80
80
|
* @public
|
|
81
81
|
*/
|
|
82
|
-
type GeoSpecModelArtifact = {
|
|
82
|
+
export type GeoSpecModelArtifact = {
|
|
83
83
|
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
84
84
|
readonly format: GeoSpecExportFormat;
|
|
85
85
|
/** Unit of raw GLB coordinates; defaults to `'mm'`. STEP carries its own unit. */
|
|
@@ -105,7 +105,7 @@ type GeoSpecModelArtifact = {
|
|
|
105
105
|
*
|
|
106
106
|
* @public
|
|
107
107
|
*/
|
|
108
|
-
type GeoSpecConsumedSources = ReadonlyArray<{
|
|
108
|
+
export type GeoSpecConsumedSources = ReadonlyArray<{
|
|
109
109
|
readonly path: string;
|
|
110
110
|
readonly sha256: string;
|
|
111
111
|
}>;
|
|
@@ -116,7 +116,7 @@ type GeoSpecConsumedSources = ReadonlyArray<{
|
|
|
116
116
|
*
|
|
117
117
|
* @public
|
|
118
118
|
*/
|
|
119
|
-
type GeoSpecModelExporter = {
|
|
119
|
+
export type GeoSpecModelExporter = {
|
|
120
120
|
readonly id: string;
|
|
121
121
|
readonly extensions: readonly string[];
|
|
122
122
|
readonly capabilities: GeoSpecExporterCapabilities;
|
|
@@ -138,7 +138,7 @@ type GeoSpecModelExporter = {
|
|
|
138
138
|
*
|
|
139
139
|
* @public
|
|
140
140
|
*/
|
|
141
|
-
type GeoSpecLoadRegion = {
|
|
141
|
+
export type GeoSpecLoadRegion = {
|
|
142
142
|
readonly min: readonly [number, number, number];
|
|
143
143
|
readonly max: readonly [number, number, number];
|
|
144
144
|
};
|
|
@@ -147,7 +147,7 @@ type GeoSpecLoadRegion = {
|
|
|
147
147
|
*
|
|
148
148
|
* @public
|
|
149
149
|
*/
|
|
150
|
-
type LoadModelSourceOptions = {
|
|
150
|
+
export type LoadModelSourceOptions = {
|
|
151
151
|
/** Geometry bytes, path, browser file/blob, or in-memory mesh buffer. */
|
|
152
152
|
source: MeshSource | StepSource;
|
|
153
153
|
/** Named external resources consumed alongside the direct geometry bytes. */
|
|
@@ -190,7 +190,7 @@ type LoadModelSourceOptions = {
|
|
|
190
190
|
*
|
|
191
191
|
* @public
|
|
192
192
|
*/
|
|
193
|
-
type LoadModelCodeOptions<Code extends Record<string, string> = Record<string, string>> = {
|
|
193
|
+
export type LoadModelCodeOptions<Code extends Record<string, string> = Record<string, string>> = {
|
|
194
194
|
/** Source files keyed by project-relative path. */
|
|
195
195
|
code: Code;
|
|
196
196
|
/** Entry path to render from {@link code}. */
|
|
@@ -231,7 +231,7 @@ type LoadModelCodeOptions<Code extends Record<string, string> = Record<string, s
|
|
|
231
231
|
*
|
|
232
232
|
* @public
|
|
233
233
|
*/
|
|
234
|
-
type LoadModelFileOptions = {
|
|
234
|
+
export type LoadModelFileOptions = {
|
|
235
235
|
/**
|
|
236
236
|
* Model file to render, as a path from the project root: the same root every tool's `targetFile` resolves
|
|
237
237
|
* against, which the result names as `projectRoot` where the host reports it, as `tau mcp` does.
|
|
@@ -277,16 +277,16 @@ type LoadModelFileOptions = {
|
|
|
277
277
|
*
|
|
278
278
|
* @public
|
|
279
279
|
*/
|
|
280
|
-
type LoadModelOptions<Code extends Record<string, string> = Record<string, string>> = LoadModelSourceOptions | LoadModelCodeOptions<Code> | LoadModelFileOptions;
|
|
280
|
+
export type LoadModelOptions<Code extends Record<string, string> = Record<string, string>> = LoadModelSourceOptions | LoadModelCodeOptions<Code> | LoadModelFileOptions;
|
|
281
281
|
/**
|
|
282
282
|
* Function shape used by GeoSpec runners to provide model loading inside VM
|
|
283
283
|
* executed test files.
|
|
284
284
|
*
|
|
285
285
|
* @public
|
|
286
286
|
*/
|
|
287
|
-
type GeoSpecModelLoader = <Code extends Record<string, string> = Record<string, string>>(options: LoadModelOptions<Code>) => Promise<GeoSpecSubject>;
|
|
287
|
+
export type GeoSpecModelLoader = <Code extends Record<string, string> = Record<string, string>>(options: LoadModelOptions<Code>) => Promise<GeoSpecSubject>;
|
|
288
288
|
/** A configured loader whose admissions can be released with its owner. @public */
|
|
289
|
-
type ManagedGeoSpecModelLoader = GeoSpecModelLoader & {
|
|
289
|
+
export type ManagedGeoSpecModelLoader = GeoSpecModelLoader & {
|
|
290
290
|
dispose(): Promise<void>;
|
|
291
291
|
};
|
|
292
292
|
/**
|
|
@@ -294,7 +294,7 @@ type ManagedGeoSpecModelLoader = GeoSpecModelLoader & {
|
|
|
294
294
|
*
|
|
295
295
|
* @public
|
|
296
296
|
*/
|
|
297
|
-
type CreateModelLoaderOptions = {
|
|
297
|
+
export type CreateModelLoaderOptions = {
|
|
298
298
|
/** Initialized compiled engine supplied by the host, never selected by an authored spec. */
|
|
299
299
|
engine: GeoSpecNativeModelEngine;
|
|
300
300
|
/** Rooted host reader for direct filesystem or URL sources. */
|
|
@@ -314,5 +314,4 @@ type CreateModelLoaderOptions = {
|
|
|
314
314
|
/** Angular tolerance in degrees used while meshing exact BRep evidence. */
|
|
315
315
|
meshAngularToleranceDegrees?: number;
|
|
316
316
|
};
|
|
317
|
-
//#endregion
|
|
318
|
-
export { CreateModelLoaderOptions, GeoSpecConsumedSources, GeoSpecExportFormat, GeoSpecExporterCapabilities, GeoSpecLoadRegion, GeoSpecModelArtifact, GeoSpecModelExportRequest, GeoSpecModelExporter, GeoSpecModelFormat, GeoSpecModelLoader, LoadModelCodeOptions, LoadModelFileOptions, LoadModelOptions, LoadModelSourceOptions, ManagedGeoSpecModelLoader, MeshBufferSource, MeshSource };
|
|
317
|
+
//#endregion
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GeometryDiagnostic } from "../mesh/types.mjs";
|
|
2
2
|
import { GeoSpecExpectOptions, GeoSpecMatcher, GeoSpecTestCase, GeoSpecTestEvent } from "./types.mjs";
|
|
3
3
|
import { GeoSpecAssertionClientOptions } from "../assertion-client/client.mjs";
|
|
4
|
-
import "../assertion-client/index.mjs";
|
|
5
4
|
import { GeoSpecTestNamePattern } from "./filter.mjs";
|
|
6
5
|
//#region src/runner/collector.d.ts
|
|
7
6
|
type GeoSpecTestFunction = () => unknown | PromiseLike<unknown>;
|
|
@@ -11,7 +10,7 @@ type GeoSpecTestFunction = () => unknown | PromiseLike<unknown>;
|
|
|
11
10
|
*
|
|
12
11
|
* @public
|
|
13
12
|
*/
|
|
14
|
-
type GeoSpecCollector = {
|
|
13
|
+
export type GeoSpecCollector = {
|
|
15
14
|
tests: GeoSpecTestCase[];
|
|
16
15
|
describe(name: string, function_: GeoSpecTestFunction): void;
|
|
17
16
|
describeSkip(name: string, _function?: GeoSpecTestFunction): void;
|
|
@@ -21,7 +20,7 @@ type GeoSpecCollector = {
|
|
|
21
20
|
waitForCompletion(testTimeout?: number, testNamePattern?: GeoSpecTestNamePattern): Promise<void>;
|
|
22
21
|
};
|
|
23
22
|
/** Per-module collector configuration; native subject/engine lifetime stays with the host. @public */
|
|
24
|
-
type GeoSpecCollectorOptions = {
|
|
23
|
+
export type GeoSpecCollectorOptions = {
|
|
25
24
|
nativeAssertions: GeoSpecAssertionClientOptions;
|
|
26
25
|
/** Observes each selected test as it starts and settles, for host progress reporting. */
|
|
27
26
|
onTestEvent?: (event: GeoSpecTestEvent) => void;
|
|
@@ -34,7 +33,7 @@ type GeoSpecCollectorOptions = {
|
|
|
34
33
|
*
|
|
35
34
|
* @public
|
|
36
35
|
*/
|
|
37
|
-
declare class GeoSpecAssertionError extends Error {
|
|
36
|
+
export declare class GeoSpecAssertionError extends Error {
|
|
38
37
|
readonly diagnostics: readonly GeometryDiagnostic[];
|
|
39
38
|
constructor(diagnostics: readonly GeometryDiagnostic[]);
|
|
40
39
|
}
|
|
@@ -45,18 +44,18 @@ declare class GeoSpecAssertionError extends Error {
|
|
|
45
44
|
* @returns A fresh collector whose matchers evaluate through the native engine.
|
|
46
45
|
* @public
|
|
47
46
|
*/
|
|
48
|
-
declare function createCollector(options: GeoSpecCollectorOptions): GeoSpecCollector;
|
|
47
|
+
export declare function createCollector(options: GeoSpecCollectorOptions): GeoSpecCollector;
|
|
49
48
|
/**
|
|
50
49
|
* Clear runner globals after a module finishes.
|
|
51
50
|
*/
|
|
52
51
|
/** @public */
|
|
53
|
-
declare const clearCollectorGlobals: () => void;
|
|
52
|
+
export declare const clearCollectorGlobals: () => void;
|
|
54
53
|
/**
|
|
55
54
|
* Install a collector into the current JavaScript global scope.
|
|
56
55
|
*
|
|
57
56
|
* @param collector - Collector for the active run.
|
|
58
57
|
*/
|
|
59
58
|
/** @public */
|
|
60
|
-
declare const installCollector: (collector: GeoSpecCollector) => void;
|
|
59
|
+
export declare const installCollector: (collector: GeoSpecCollector) => void;
|
|
61
60
|
//#endregion
|
|
62
|
-
export {
|
|
61
|
+
export {};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import{assertGeoSpecAuthoredWorkUnitLimit as e}from"../engine/client.mjs";import{resolveGeoSpecSubject as t}from"../model/subject.mjs";import{GeoSpecAssertionError as n,createGeoSpecAssertionClient as r,createGeoSpecMatcherMethods as i}from"../assertion-client/client.mjs";import{diagnosticForTransport as a,geometryDiagnosticSchema as o}from"../model/errors.mjs";import{matchesGeoSpecTestName as s}from"./filter.mjs";import{geoSpecTimeoutCode as c}from"./timeout-codes.mjs";import{regionScopeRefusal as l}from"../model/region-scope.mjs";const u=`__GEOSPEC_COLLECTOR__`,d=globalThis,f=e=>typeof e==`object`&&!!e&&`then`in e&&typeof e.then==`function`;var p=class extends Error{diagnostics;constructor(e){super(e.map(e=>e.message).join(`
|
|
2
|
-
`)||`GeoSpec assertion failed.`),this.name=`GeoSpecAssertionError`,this.diagnostics=Object.freeze([...e])}},m=class extends Error{testTimeout;constructor(e){super(`GeoSpec test timed out after ${e}ms.`),this.name=`GeoSpecTestTimeoutError`,this.testTimeout=e}};const h=e=>typeof e==`object`&&!!e&&Reflect.get(e,`code`)===`limit-exceeded`,g=e=>{let{message:t,name:n}=e,r=typeof t==`string`?t:`GeoSpec ran out of room for this claim.`;return{code:`TEST_FAILED`,severity:`error`,message:r,details:{name:typeof n==`string`?n:`Error`,message:r}}},_=e=>{let{capacity:t,message:n}=e,{code:r,...i}=typeof t==`object`&&t?{...t}:{};return a({code:typeof r==`string`?r:`GEOSPEC_RESOURCE_LIMIT`,severity:`error`,message:typeof n==`string`?n:`GeoSpec refused to admit this load.`,...Object.keys(i).length===0?{}:{details:i}})},v=e=>{if(e instanceof p)return[...e.diagnostics];if(h(e))return[_(e)];if(e instanceof m)return[{code:c.test,severity:`error`,message:`${e.message} The test still ran to completion before the run moved on; this is a wall-clock timeout, not a geometry verdict.`,suggestion:`Keep the assertion and the model as designed. Raise testTimeout (CLI --test-timeout) so the requirement can finish; if this host cannot give it the time, report it as not decided at this capacity.`,details:{testTimeout:e.testTimeout}}];if(typeof e==`object`&&e&&Reflect.get(e,`name`)===`GeoSpecModelLoadError`){let t=Reflect.get(e,`diagnostics`);if(Array.isArray(t)&&t.length>0)try{return t.map(e=>a(y(e)))}catch{}}let t=typeof e==`object`&&e&&typeof Reflect.get(e,`message`)==`string`?String(Reflect.get(e,`message`)):String(e),{details:n}=a({code:`TEST_FAILED`,severity:`error`,message:t,details:e});return t.includes(`model.volume is not a function`)?[{code:`GEOSPEC_SUBJECT_API_MISUSE`,severity:`error`,message:`GeoSpec GeometrySubject does not expose model.volume().`,suggestion:`Use expectGeo(model).toHaveVolume({ value, tolerance }) instead of reading model.volume().`,details:n}]:/Cannot read properties of undefined \(reading 'bounds'\)/u.test(t)?[{code:`GEOSPEC_SUBJECT_API_MISUSE`,severity:`error`,message:`GeoSpec GeometrySubject does not expose model.boundingBox.bounds.`,suggestion:`Use expectGeo(model).toHaveBoundingBox({ min, max, size, center, tolerance }) instead of reading model.boundingBox.`,details:n}]:[{code:`TEST_FAILED`,severity:`error`,message:t,details:n}]},y=e=>o.parse(e),b=(e,t)=>{if(e.passed=t.length===0,e.diagnostics=t,t.length>0)throw new p(t);return e},x=async(e,t)=>{if(t===void 0)return e;let n;try{return await Promise.race([e,new Promise((e,r)=>{n=setTimeout(()=>{r(new m(t))},t)})])}finally{
|
|
2
|
+
`)||`GeoSpec assertion failed.`),this.name=`GeoSpecAssertionError`,this.diagnostics=Object.freeze([...e])}},m=class extends Error{testTimeout;constructor(e){super(`GeoSpec test timed out after ${e}ms.`),this.name=`GeoSpecTestTimeoutError`,this.testTimeout=e}};const h=e=>typeof e==`object`&&!!e&&Reflect.get(e,`code`)===`limit-exceeded`,g=e=>{let{message:t,name:n}=e,r=typeof t==`string`?t:`GeoSpec ran out of room for this claim.`;return{code:`TEST_FAILED`,severity:`error`,message:r,details:{name:typeof n==`string`?n:`Error`,message:r}}},_=e=>{let{capacity:t,message:n}=e,{code:r,...i}=typeof t==`object`&&t?{...t}:{};return a({code:typeof r==`string`?r:`GEOSPEC_RESOURCE_LIMIT`,severity:`error`,message:typeof n==`string`?n:`GeoSpec refused to admit this load.`,...Object.keys(i).length===0?{}:{details:i}})},v=e=>{if(e instanceof p)return[...e.diagnostics];if(h(e))return[_(e)];if(e instanceof m)return[{code:c.test,severity:`error`,message:`${e.message} The test still ran to completion before the run moved on; this is a wall-clock timeout, not a geometry verdict.`,suggestion:`Keep the assertion and the model as designed. Raise testTimeout (CLI --test-timeout) so the requirement can finish; if this host cannot give it the time, report it as not decided at this capacity.`,details:{testTimeout:e.testTimeout}}];if(typeof e==`object`&&e&&Reflect.get(e,`name`)===`GeoSpecModelLoadError`){let t=Reflect.get(e,`diagnostics`);if(Array.isArray(t)&&t.length>0)try{return t.map(e=>a(y(e)))}catch{}}let t=typeof e==`object`&&e&&typeof Reflect.get(e,`message`)==`string`?String(Reflect.get(e,`message`)):String(e),{details:n}=a({code:`TEST_FAILED`,severity:`error`,message:t,details:e});return t.includes(`model.volume is not a function`)?[{code:`GEOSPEC_SUBJECT_API_MISUSE`,severity:`error`,message:`GeoSpec GeometrySubject does not expose model.volume().`,suggestion:`Use expectGeo(model).toHaveVolume({ value, tolerance }) instead of reading model.volume().`,details:n}]:/Cannot read properties of undefined \(reading 'bounds'\)/u.test(t)?[{code:`GEOSPEC_SUBJECT_API_MISUSE`,severity:`error`,message:`GeoSpec GeometrySubject does not expose model.boundingBox.bounds.`,suggestion:`Use expectGeo(model).toHaveBoundingBox({ min, max, size, center, tolerance }) instead of reading model.boundingBox.`,details:n}]:[{code:`TEST_FAILED`,severity:`error`,message:t,details:n}]},y=e=>o.parse(e),b=(e,t)=>{if(e.passed=t.length===0,e.diagnostics=t,t.length>0)throw new p(t);return e},x=async(e,t)=>{if(t===void 0)return e;let n;try{return await Promise.race([e,new Promise((e,r)=>{n=setTimeout(()=>{r(new m(t))},t)})])}finally{
|
|
3
|
+
/* v8 ignore next -- The Promise executor runs synchronously, so the handle is always assigned. */
|
|
4
|
+
n!==void 0&&clearTimeout(n)}},S=(e,t)=>{for(let n of e)n.status===`rejected`&&t(n.reason)},C=()=>{let e=d[u];if(!w(e))throw Error(`GeoSpec collector is not active. Run the module through runGeoSpecModule().`);return e},w=e=>typeof e==`object`&&!!e&&`describe`in e&&`it`in e&&`expectGeo`in e&&`tests`in e,T=e=>typeof e==`object`&&!!e&&`suite`in e&&`name`in e&&`assertions`in e;function E(o){let c=r(o.nativeAssertions),u=[],d=[],m=[],_=[],C=/* @__PURE__ */ new WeakSet,w,E=!1,D=(e,t)=>{try{o.onTestEvent?.({type:e,test:t})}catch{}},O=(e,t)=>{m.push((async()=>{try{await e}catch(e){t.onError(e)}finally{t.onFinally()}})())},k=e=>{d.push({ordinal:d.length,suite:[...u],name:e,assertions:[],status:`skipped`,diagnostics:[]})},A=(e,r)=>{if(!T(w))throw Error(`expectGeo() must be called inside it().`);let i={kind:e.kind,subject:null,expected:e.expected};w.assertions.push(i);let s=performance.now();try{let s=t(e.subject,o.nativeAssertions.engine);i.subject=s.identity,s.load!==void 0&&(i.loadId=s.load.loadId);let u=s.load?.region;u!==void 0&&(i.region={min:[...u.min],max:[...u.max]});let d=l(u,e.kind);if(d!==void 0)return b(i,[d]);let f=r?.workUnitLimit??s.load?.workUnitLimit,p=c.expectGeo(s.identity,f===void 0?void 0:{workUnitLimit:f}),m=(e.polarity===`negative`?p.not:p)[e.matcher],h;try{h=m(...e.arguments)}catch(e){if(!(e instanceof n))throw e;h=e.report}if(i.report=h,h.status===`passed`)return b(i,[]);let g=h.diagnostics.map(e=>a(y(e)));return b(i,g.length>0?g:[{code:`GEOSPEC_NATIVE_ASSERTION_FAILED`,severity:`error`,message:`Native claim '${h.claimId}' ended with status '${h.status}'.`,details:{claimId:h.claimId,status:h.status}}])}catch(e){if(e instanceof p&&i.report!==void 0&&C.add(e),h(e))return b(i,[g(e)]);throw i.passed=!1,i.diagnostics??=v(e),e}finally{i.durationMs=performance.now()-s}};return{describe(e,t){u.push(e);try{let n=t();if(f(n)){let t=[...u];O(n,{onError(n){d.push({ordinal:d.length,suite:t,name:e,assertions:[],status:h(n)?`inconclusive`:`failed`,diagnostics:v(n)})},onFinally(){u.pop()}});return}}catch(t){d.push({ordinal:d.length,suite:[...u],name:e,assertions:[],status:h(t)?`inconclusive`:`failed`,diagnostics:v(t)})}u.pop()},describeSkip(e){k(e)},it(e,t){let n={ordinal:d.length,suite:[...u],name:e,assertions:[],status:`not-run`,diagnostics:[]};d.push(n),_.push({test:n,function_:t})},itSkip(e){k(e)},expectGeo(t,n){e(n?.workUnitLimit,`expectGeo workUnitLimit`,o.nativeAssertions.maximumWorkUnitLimit);let r=e=>A(e,n);return Object.assign(i({invoke:r,polarity:`positive`,subject:t}),{not:i({invoke:r,polarity:`negative`,subject:t})})},async waitForCompletion(e,t){if(E)return;E=!0;let n=Promise.allSettled(m);try{await x(n,e)}catch(e){throw await n,e}for(let n of _){if(!s(n.test,t))continue;let r=w;w=n.test,n.test.status=`passed`,D(`test-start`,n.test);let i=performance.now(),a=[],o=e=>{a.some(t=>Object.is(t,e))||a.push(e)};try{let t;try{t=Promise.resolve(n.function_()),await x(t,e)}catch(e){o(e)}if(t!==void 0&&S(await Promise.allSettled([t]),o),a.length>0||n.test.assertions.some(e=>e.passed===!1)){n.test.status=`failed`;for(let e of a)n.test.diagnostics.push(...v(e));let{assertions:e}=n.test;if(!(a.some(e=>!h(e)&&(!(e instanceof p)||!C.has(e)))||e.some(e=>e.passed===!1&&(e.report===void 0||e.report.status===`invalid`||e.report.status===`engine-error`)))){let t=e.map(e=>e.report?.status);n.test.status=t.includes(`failed`)?`failed`:a.some(e=>h(e))||t.some(e=>e!==void 0&&e!==`passed`&&e!==`unsupported`)?`inconclusive`:t.includes(`unsupported`)?`unsupported`:`failed`}}}finally{w=r,n.test.durationMs=performance.now()-i,D(`test-complete`,n.test)}}},tests:d}}const D=()=>{Reflect.deleteProperty(d,u)},O=e=>{d[u]=e};export{p as GeoSpecAssertionError,D as clearCollectorGlobals,u as collectorGlobalKey,E as createCollector,C as getCollector,O as installCollector};
|
|
@@ -4,26 +4,26 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
declare const defaultGeoSpecInclude: readonly ["**/*.geospec.{ts,js}"];
|
|
7
|
+
export declare const defaultGeoSpecInclude: readonly ["**/*.geospec.{ts,js}"];
|
|
8
8
|
/**
|
|
9
9
|
* Directories skipped by recursive GeoSpec discovery unless callers provide
|
|
10
10
|
* their own ignored-directory list.
|
|
11
11
|
*
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
|
-
declare const defaultGeoSpecIgnoredDirectories: readonly [".git", "node_modules", "dist", "coverage", ".tau/cache", ".tau/artifacts", ".tau/transcripts"];
|
|
14
|
+
export declare const defaultGeoSpecIgnoredDirectories: readonly [".git", "node_modules", "dist", "coverage", ".tau/cache", ".tau/artifacts", ".tau/transcripts"];
|
|
15
15
|
/**
|
|
16
16
|
* File kind returned by a GeoSpec discovery filesystem.
|
|
17
17
|
*
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
|
-
type GeoSpecDiscoveryFileKind = 'file' | 'directory';
|
|
20
|
+
export type GeoSpecDiscoveryFileKind = 'file' | 'directory';
|
|
21
21
|
/**
|
|
22
22
|
* Minimal stat object required for recursive GeoSpec test discovery.
|
|
23
23
|
*
|
|
24
24
|
* @public
|
|
25
25
|
*/
|
|
26
|
-
type GeoSpecDiscoveryFileStat = {
|
|
26
|
+
export type GeoSpecDiscoveryFileStat = {
|
|
27
27
|
kind: GeoSpecDiscoveryFileKind;
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
@@ -34,7 +34,7 @@ type GeoSpecDiscoveryFileStat = {
|
|
|
34
34
|
*
|
|
35
35
|
* @public
|
|
36
36
|
*/
|
|
37
|
-
type GeoSpecDiscoveryFileSystem = {
|
|
37
|
+
export type GeoSpecDiscoveryFileSystem = {
|
|
38
38
|
readdir(path: string): Promise<readonly string[]>;
|
|
39
39
|
stat(path: string): Promise<GeoSpecDiscoveryFileStat>;
|
|
40
40
|
};
|
|
@@ -49,7 +49,7 @@ type GeoSpecDiscoveryFileSystem = {
|
|
|
49
49
|
*
|
|
50
50
|
* @public
|
|
51
51
|
*/
|
|
52
|
-
type DiscoverGeoSpecFilesOptions = {
|
|
52
|
+
export type DiscoverGeoSpecFilesOptions = {
|
|
53
53
|
filesystem: GeoSpecDiscoveryFileSystem;
|
|
54
54
|
projectPath: string;
|
|
55
55
|
files?: readonly string[];
|
|
@@ -66,7 +66,7 @@ type DiscoverGeoSpecFilesOptions = {
|
|
|
66
66
|
*
|
|
67
67
|
* @public
|
|
68
68
|
*/
|
|
69
|
-
type GeoSpecDiscoveryResult = {
|
|
69
|
+
export type GeoSpecDiscoveryResult = {
|
|
70
70
|
files: string[];
|
|
71
71
|
unmatchedRoots: string[];
|
|
72
72
|
};
|
|
@@ -77,7 +77,7 @@ type GeoSpecDiscoveryResult = {
|
|
|
77
77
|
* @returns True when the path ends with `.geospec.ts` or `.geospec.js`.
|
|
78
78
|
* @public
|
|
79
79
|
*/
|
|
80
|
-
declare const isGeoSpecTestFile: (path: string) => boolean;
|
|
80
|
+
export declare const isGeoSpecTestFile: (path: string) => boolean;
|
|
81
81
|
/**
|
|
82
82
|
* Discover GeoSpec test files from exact files or directory roots.
|
|
83
83
|
*
|
|
@@ -88,6 +88,5 @@ declare const isGeoSpecTestFile: (path: string) => boolean;
|
|
|
88
88
|
* @returns Sorted, de-duplicated project-relative GeoSpec files plus unmatched roots.
|
|
89
89
|
* @public
|
|
90
90
|
*/
|
|
91
|
-
declare const discoverGeoSpecFiles: (options: DiscoverGeoSpecFilesOptions) => Promise<GeoSpecDiscoveryResult>;
|
|
92
|
-
//#endregion
|
|
93
|
-
export { DiscoverGeoSpecFilesOptions, GeoSpecDiscoveryFileKind, GeoSpecDiscoveryFileStat, GeoSpecDiscoveryFileSystem, GeoSpecDiscoveryResult, defaultGeoSpecIgnoredDirectories, defaultGeoSpecInclude, discoverGeoSpecFiles, isGeoSpecTestFile };
|
|
91
|
+
export declare const discoverGeoSpecFiles: (options: DiscoverGeoSpecFilesOptions) => Promise<GeoSpecDiscoveryResult>;
|
|
92
|
+
//#endregion
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
import{assertRootedPath as e}from"
|
|
1
|
+
import{assertRootedPath as e}from"../support/path.mjs";const t=[`**/*.geospec.{ts,js}`],n=[`.git`,`node_modules`,`dist`,`coverage`,`.tau/cache`,`.tau/artifacts`,`.tau/transcripts`],r=/\.geospec\.(?:ts|js)$/u,i=e=>e.replaceAll(`\\`,`/`).replaceAll(/\/+/gu,`/`).replace(/^\.\//u,``),a=e=>{let t=i(e);return!t||t===`.`?``:t===`/`?t:t.replace(/\/$/u,``)},o=(t,n)=>{let r=e(t);return r===``?n:n===``?r:`${n.replace(/\/$/u,``)}/${r}`},s=(e,t)=>{let n=i(e).replace(/\/$/u,``);if(t===``)return n;let r=t.endsWith(`/`)?t:`${t}/`;return n===t?``:n.startsWith(r)?n.slice(r.length):n},c=e=>e.replaceAll(/[|\\{}()[\]^$+?.]/gu,String.raw`\$&`),l=e=>{let t=i(e),n=`^`;for(let e=0;e<t.length;){
|
|
2
|
+
/* v8 ignore start -- The loop bound already guarantees an in-range character. */
|
|
3
|
+
let r=t[e];if(r===void 0)break;
|
|
4
|
+
/* v8 ignore stop */
|
|
5
|
+
let i=t[e+1];if(r===`*`&&i===`*`)t[e+2]===`/`?(n+=String.raw`(?:.*\/)?`,e+=3):(n+=`.*`,e+=2);else if(r===`*`)n+=`[^/]*`,e+=1;else if(r===`?`)n+=`[^/]`,e+=1;else{if(r===`{`){let r=t.indexOf(`}`,e+1);if(r!==-1){let i=t.slice(e+1,r).split(`,`).map(e=>c(e));n+=`(?:${i.join(`|`)})`,e=r+1;continue}}n+=r===`/`?String.raw`\/`:c(r),e+=1}}return RegExp(`${n}$`,`u`)},u=(e,t)=>l(t).test(i(e)),d=(e,t)=>t.some(t=>u(e,t)),f=(e,t)=>{let n=i(e).replace(/\/$/u,``),r=n.split(`/`).at(-1)??n;return t.has(n)||t.has(r)},p=e=>{if(typeof e!=`object`||!e)return!1;let t=`code`in e?e.code:void 0,n=`name`in e?e.name:void 0,r=e instanceof Error?e.message:``;return t===`ENOENT`||t===`ENOTDIR`||n===`NotFoundError`||r.startsWith(`ENOENT:`)||r.startsWith(`ENOTDIR:`)},m=e=>r.test(i(e)),h=async e=>{let t=await e.filesystem.readdir(e.directoryPath),n=[];for(let r of t){let t=e.directoryPath===``?r:`${e.directoryPath}/${r}`,i=s(t,e.projectPath);(await e.filesystem.stat(t)).kind===`directory`?f(i,e.ignoredDirectories)||n.push(t):m(i)&&e.selectedFiles.add(i)}n.sort((e,t)=>e.localeCompare(t));for(let t of n)await h({...e,directoryPath:t})},g=async e=>{let t=/* @__PURE__ */ new Set,n=o(e.root,e.projectPath),r;try{r=await e.filesystem.stat(n)}catch(e){if(p(e))return[];throw e}if(r.kind===`file`){let r=s(n,e.projectPath);return m(r)&&t.add(r),[...t]}let i=s(n,e.projectPath);return i&&f(i,e.ignoredDirectories)?[]:(await h({filesystem:e.filesystem,directoryPath:n,projectPath:e.projectPath,ignoredDirectories:e.ignoredDirectories,selectedFiles:t}),[...t])},_=async e=>{let r=a(e.projectPath),o=e.include&&e.include.length>0?e.include:t,s=e.exclude??[],c=new Set(e.ignoredDirectories??n),l=e.files&&e.files.length>0?e.files:[``],u=/* @__PURE__ */ new Set,f=[];for(let t of l){let n=await g({filesystem:e.filesystem,projectPath:r,root:t,ignoredDirectories:c});if(n.length===0)f.push(i(t)||`.`);else for(let e of n)u.add(e)}return{files:[...u].filter(e=>d(e,o)&&!d(e,s)).sort((e,t)=>e.localeCompare(t)),unmatchedRoots:f}};export{n as defaultGeoSpecIgnoredDirectories,t as defaultGeoSpecInclude,_ as discoverGeoSpecFiles,m as isGeoSpecTestFile};
|
package/dist/runner/filter.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { VmIssue } from "../vm/types.mjs";
|
|
1
2
|
import { GeoSpecTestCase } from "./types.mjs";
|
|
2
|
-
import { VmIssue } from "@taucad/esbuild/vm";
|
|
3
3
|
//#region src/runner/filter.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Compiled Vitest-style test-name pattern used by a GeoSpec run.
|
|
6
6
|
*
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
|
-
type GeoSpecTestNamePattern = RegExp;
|
|
9
|
+
export type GeoSpecTestNamePattern = RegExp;
|
|
10
10
|
/**
|
|
11
11
|
* Compile a Vitest-style test-name pattern once for a GeoSpec run.
|
|
12
12
|
*
|
|
@@ -18,7 +18,7 @@ type GeoSpecTestNamePattern = RegExp;
|
|
|
18
18
|
*
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
21
|
-
declare const compileGeoSpecTestNamePattern: (testNamePattern: string | RegExp | undefined) => {
|
|
21
|
+
export declare const compileGeoSpecTestNamePattern: (testNamePattern: string | RegExp | undefined) => {
|
|
22
22
|
success: true;
|
|
23
23
|
pattern?: GeoSpecTestNamePattern;
|
|
24
24
|
} | {
|
|
@@ -35,7 +35,7 @@ declare const compileGeoSpecTestNamePattern: (testNamePattern: string | RegExp |
|
|
|
35
35
|
* @param testNamePattern - optional compiled regex.
|
|
36
36
|
* @returns whether the test should be included.
|
|
37
37
|
*/
|
|
38
|
-
declare const matchesGeoSpecTestName: (test: Pick<GeoSpecTestCase, "suite" | "name">, testNamePattern: GeoSpecTestNamePattern | undefined) => boolean;
|
|
38
|
+
export declare const matchesGeoSpecTestName: (test: Pick<GeoSpecTestCase, "suite" | "name">, testNamePattern: GeoSpecTestNamePattern | undefined) => boolean;
|
|
39
39
|
/**
|
|
40
40
|
* Filter collected GeoSpec tests by compiled test-name pattern.
|
|
41
41
|
*
|
|
@@ -45,6 +45,5 @@ declare const matchesGeoSpecTestName: (test: Pick<GeoSpecTestCase, "suite" | "na
|
|
|
45
45
|
* @param testNamePattern - optional compiled regex.
|
|
46
46
|
* @returns tests that match the filter.
|
|
47
47
|
*/
|
|
48
|
-
declare const filterGeoSpecTests: (tests: readonly GeoSpecTestCase[], testNamePattern: GeoSpecTestNamePattern | undefined) => GeoSpecTestCase[];
|
|
49
|
-
//#endregion
|
|
50
|
-
export { GeoSpecTestNamePattern, compileGeoSpecTestNamePattern, filterGeoSpecTests, matchesGeoSpecTestName };
|
|
48
|
+
export declare const filterGeoSpecTests: (tests: readonly GeoSpecTestCase[], testNamePattern: GeoSpecTestNamePattern | undefined) => GeoSpecTestCase[];
|
|
49
|
+
//#endregion
|
package/dist/runner/filter.mjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
const e=e=>[...e.suite,e.name].join(` > `),t=e=>{if(e===void 0||typeof e==`string`&&e.trim()===``)return{success:!0};if(e instanceof RegExp)return{success:!0,pattern:e};try{return{success:!0,pattern:new RegExp(e,`u`)}}catch(t){return{success:!1,issue:{code:`INVALID_GEOSPEC_TEST_NAME_PATTERN`,message:`testNamePattern is not a valid JavaScript regular expression.`,severity:`error`,type:`runtime`,details:{testNamePattern:e,
|
|
1
|
+
const e=e=>[...e.suite,e.name].join(` > `),t=e=>{if(e===void 0||typeof e==`string`&&e.trim()===``)return{success:!0};if(e instanceof RegExp)return{success:!0,pattern:e};try{return{success:!0,pattern:new RegExp(e,`u`)}}catch(t){return{success:!1,issue:{code:`INVALID_GEOSPEC_TEST_NAME_PATTERN`,message:`testNamePattern is not a valid JavaScript regular expression.`,severity:`error`,type:`runtime`,details:{testNamePattern:e,
|
|
2
|
+
/* v8 ignore next -- The RegExp constructor only ever throws a SyntaxError. */
|
|
3
|
+
reason:t instanceof Error?t.message:String(t)}}}}},n=(t,n)=>!n||(n.lastIndex=0,n.test(e(t))),r=(e,t)=>e.filter(e=>n(e,t));export{t as compileGeoSpecTestNamePattern,r as filterGeoSpecTests,n as matchesGeoSpecTestName};
|
package/dist/runner/index.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { BuiltinModule, BundleResult, CreateModuleVm, GeoSpecModuleVmModule, ModuleVm, ModuleVmOptions, VmExecuteResult, VmFileSystem, VmIssue } from "../vm/types.mjs";
|
|
1
2
|
import { GeoSpecAssemblyOccurrenceExpectation, GeoSpecAssemblyOccurrencesExpectation, GeoSpecAssertion, GeoSpecAxisExpectation, GeoSpecBoundingBoxExpectation, GeoSpecCenterOfMassExpectation, GeoSpecChamferFeatureExpectation, GeoSpecCircularHoleExpectation, GeoSpecCircularHolePatternExpectation, GeoSpecComponentInterferenceAllowance, GeoSpecComponentInterferenceExpectation, GeoSpecComponentInterferencePairExpectation, GeoSpecConnectedComponentsExpectation, GeoSpecCylindricalFaceExpectation, GeoSpecFilletFeatureExpectation, GeoSpecGeometrySelector, GeoSpecMassExpectation, GeoSpecMatcher, GeoSpecMeshIntegrityExpectation, GeoSpecMinimumWallThicknessExpectation, GeoSpecModuleBundleCache, GeoSpecNumericExpectation, GeoSpecPlanarFaceExpectation, GeoSpecPointExpectation, GeoSpecProductStructureExpectation, GeoSpecRunFailure, GeoSpecRunResult, GeoSpecRunSuccess, GeoSpecSpatialRelationshipExpectation, GeoSpecSpatialRelationshipsExpectation, GeoSpecStepUnitsExpectation, GeoSpecSurfaceAreaExpectation, GeoSpecTestCase, GeoSpecTestEvent, GeoSpecTestStatus, GeoSpecTopologyCountsExpectation, GeoSpecValidBrepExpectation, GeoSpecVolumeExpectation, RunGeoSpecModuleOptions } from "./types.mjs";
|
|
2
3
|
import { DiscoverGeoSpecFilesOptions, GeoSpecDiscoveryFileKind, GeoSpecDiscoveryFileStat, GeoSpecDiscoveryFileSystem, GeoSpecDiscoveryResult, defaultGeoSpecIgnoredDirectories, defaultGeoSpecInclude, discoverGeoSpecFiles, isGeoSpecTestFile } from "./discovery.mjs";
|
|
3
4
|
import { GeoSpecTestNamePattern, compileGeoSpecTestNamePattern, filterGeoSpecTests, matchesGeoSpecTestName } from "./filter.mjs";
|
|
4
5
|
import { GeoSpecAssertionError, GeoSpecCollector, GeoSpecCollectorOptions, clearCollectorGlobals, createCollector, installCollector } from "./collector.mjs";
|
|
5
6
|
import { runGeoSpecModule } from "./run-geospec-module.mjs";
|
|
6
7
|
import { GeoSpecTimeoutCode, geoSpecTimeoutCode, isGeoSpecTimeoutCode } from "./timeout-codes.mjs";
|
|
7
|
-
|
|
8
|
+
import { createPlainModuleVm } from "../vm/plain-module-vm.mjs";
|
|
9
|
+
export { type BuiltinModule, type BundleResult, type CreateModuleVm, type DiscoverGeoSpecFilesOptions, type GeoSpecAssemblyOccurrenceExpectation, type GeoSpecAssemblyOccurrencesExpectation, type GeoSpecAssertion, GeoSpecAssertionError, type GeoSpecAxisExpectation, type GeoSpecBoundingBoxExpectation, type GeoSpecCenterOfMassExpectation, type GeoSpecChamferFeatureExpectation, type GeoSpecCircularHoleExpectation, type GeoSpecCircularHolePatternExpectation, type GeoSpecCollector, type GeoSpecCollectorOptions, type GeoSpecComponentInterferenceAllowance, type GeoSpecComponentInterferenceExpectation, type GeoSpecComponentInterferencePairExpectation, type GeoSpecConnectedComponentsExpectation, type GeoSpecCylindricalFaceExpectation, type GeoSpecDiscoveryFileKind, type GeoSpecDiscoveryFileStat, type GeoSpecDiscoveryFileSystem, type GeoSpecDiscoveryResult, type GeoSpecFilletFeatureExpectation, type GeoSpecGeometrySelector, type GeoSpecMassExpectation, type GeoSpecMatcher, type GeoSpecMeshIntegrityExpectation, type GeoSpecMinimumWallThicknessExpectation, type GeoSpecModuleBundleCache, type GeoSpecModuleVmModule, type GeoSpecNumericExpectation, type GeoSpecPlanarFaceExpectation, type GeoSpecPointExpectation, type GeoSpecProductStructureExpectation, type GeoSpecRunFailure, type GeoSpecRunResult, type GeoSpecRunSuccess, type GeoSpecSpatialRelationshipExpectation, type GeoSpecSpatialRelationshipsExpectation, type GeoSpecStepUnitsExpectation, type GeoSpecSurfaceAreaExpectation, type GeoSpecTestCase, type GeoSpecTestEvent, type GeoSpecTestNamePattern, type GeoSpecTestStatus, type GeoSpecTimeoutCode, type GeoSpecTopologyCountsExpectation, type GeoSpecValidBrepExpectation, type GeoSpecVolumeExpectation, type ModuleVm, type ModuleVmOptions, type RunGeoSpecModuleOptions, type VmExecuteResult, type VmFileSystem, type VmIssue, clearCollectorGlobals, compileGeoSpecTestNamePattern, createCollector, createPlainModuleVm, defaultGeoSpecIgnoredDirectories, defaultGeoSpecInclude, discoverGeoSpecFiles, filterGeoSpecTests, geoSpecTimeoutCode, installCollector, isGeoSpecTestFile, isGeoSpecTimeoutCode, matchesGeoSpecTestName, runGeoSpecModule };
|