@metamesh/testkit 0.16.0 → 0.18.0

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/README.md +122 -88
  3. package/dist/assertions.d.ts +8 -15
  4. package/dist/assertions.d.ts.map +1 -1
  5. package/dist/assertions.js +24 -70
  6. package/dist/assertions.js.map +1 -1
  7. package/dist/content-assertions.d.ts +28 -0
  8. package/dist/content-assertions.d.ts.map +1 -0
  9. package/dist/content-assertions.js +75 -0
  10. package/dist/content-assertions.js.map +1 -0
  11. package/dist/content-matchers.d.ts +12 -0
  12. package/dist/content-matchers.d.ts.map +1 -0
  13. package/dist/content-matchers.js +22 -0
  14. package/dist/content-matchers.js.map +1 -0
  15. package/dist/docs/guides/package.md +122 -88
  16. package/dist/docs/manifest.json +175 -35
  17. package/dist/docs/reference/font-fixtures/LoadedFontFixtures.md +1 -1
  18. package/dist/docs/reference/font-fixtures/loadFontFixtureServices.md +1 -1
  19. package/dist/docs/reference/font-fixtures/loadFontFixtures.md +1 -1
  20. package/dist/docs/reference/fonts/FontTestFixture.md +1 -1
  21. package/dist/docs/reference/fonts/prepareFontTestServices.md +1 -1
  22. package/dist/docs/reference/index/BufferContent.md +13 -0
  23. package/dist/docs/reference/index/ContentMismatchError.md +12 -0
  24. package/dist/docs/reference/index/GeneratorModelTestInput.md +13 -0
  25. package/dist/docs/reference/index/GeneratorModelTestOptions.md +10 -0
  26. package/dist/docs/reference/index/GeneratorTestResult.md +18 -0
  27. package/dist/docs/reference/index/GeneratorTestRunner.md +9 -9
  28. package/dist/docs/reference/index/GeneratorTestRunnerOptions.md +2 -3
  29. package/dist/docs/reference/index/MeshContent.md +13 -0
  30. package/dist/docs/reference/index/MeshMeasurementExpectation.md +3 -3
  31. package/dist/docs/reference/index/MeshMeasurementTolerances.md +1 -1
  32. package/dist/docs/reference/index/RunModelOptions.md +13 -0
  33. package/dist/docs/reference/index/assertEqualBuffer.md +15 -0
  34. package/dist/docs/reference/index/assertEqualMesh.md +14 -0
  35. package/dist/docs/reference/index/{expectMeshMeasurements.md → assertMeshMeasurements.md} +3 -3
  36. package/dist/docs/reference/index/{expectValidDefaults.md → assertValidDefaults.md} +3 -3
  37. package/dist/docs/reference/index/assertValidDefinition.md +10 -0
  38. package/dist/docs/reference/index/assertValidParts.md +12 -0
  39. package/dist/docs/reference/index/{expectValidPresets.md → assertValidPresets.md} +3 -3
  40. package/dist/docs/reference/index/contentMatchers.md +12 -0
  41. package/dist/docs/reference/index/createGeneratorTestRunner.md +2 -4
  42. package/dist/docs/reference/index/getTestEngine.md +1 -1
  43. package/dist/docs/reference/index/runModel.md +13 -0
  44. package/dist/generator-execution.d.ts +6 -0
  45. package/dist/generator-execution.d.ts.map +1 -0
  46. package/dist/generator-execution.js +20 -0
  47. package/dist/generator-execution.js.map +1 -0
  48. package/dist/generator-test-runner.d.ts +32 -0
  49. package/dist/generator-test-runner.d.ts.map +1 -0
  50. package/dist/generator-test-runner.js +109 -0
  51. package/dist/generator-test-runner.js.map +1 -0
  52. package/dist/index.d.ts +10 -5
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +7 -4
  55. package/dist/index.js.map +1 -1
  56. package/dist/measurements.d.ts +4 -4
  57. package/dist/measurements.d.ts.map +1 -1
  58. package/dist/measurements.js +10 -9
  59. package/dist/measurements.js.map +1 -1
  60. package/dist/run-model.d.ts +21 -0
  61. package/dist/run-model.d.ts.map +1 -0
  62. package/dist/run-model.js +39 -0
  63. package/dist/run-model.js.map +1 -0
  64. package/dist/{engine.d.ts → test-engine.d.ts} +1 -1
  65. package/dist/test-engine.d.ts.map +1 -0
  66. package/dist/{engine.js → test-engine.js} +1 -1
  67. package/dist/test-engine.js.map +1 -0
  68. package/package.json +8 -5
  69. package/dist/docs/reference/index/GeneratorTestExecution.md +0 -19
  70. package/dist/docs/reference/index/expectSerializableDefinition.md +0 -10
  71. package/dist/docs/reference/index/expectValidParts.md +0 -19
  72. package/dist/engine.d.ts.map +0 -1
  73. package/dist/engine.js.map +0 -1
  74. package/dist/runner.d.ts +0 -36
  75. package/dist/runner.d.ts.map +0 -1
  76. package/dist/runner.js +0 -121
  77. package/dist/runner.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,196 @@
1
1
  # @metamesh/testkit
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2eea694: Consolidate model authoring, execution, and testing around fluent shapes and durable immutable
8
+ results. Upgrade all four packages together; these Preview API changes have no compatibility
9
+ aliases. Rebuild compiled Generators for module format 5 and Modeling runtime major 11. Older
10
+ module formats and incompatible runtime versions are rejected before execution.
11
+
12
+ ### Modeling imports and operations
13
+
14
+ | Previous API | 0.18 API |
15
+ | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
16
+ | `body.subtract([cutter])` for a single operand | `body.subtract(cutter)`; fluent `union`, `intersect`, and `subtract` accept one shape or a readonly array |
17
+ | `compose(shapes)` | `union(shapes)` |
18
+ | Free shape inspection, emptiness, component, and anchor queries | `shape.inspect()`, `shape.isEmpty()`, `shape.components()`, and `shape.anchor(name)` |
19
+ | Free Solid distance/segment queries and splitting functions | `solid.distance(other)`, `solid.castSegment(...)`, `solid.split(cutter)`, and `solid.splitByPlane(plane)` |
20
+ | `solid.toTriangleMesh()` | `solid.toMesh()` |
21
+ | Named `mesh` import from `/geometry`, or standalone triangle-mesh functions | `import * as mesh from "@metamesh/modeling/geometry/mesh"` |
22
+ | Standalone `immutableMesh(...)` | `mesh.immutable(...)` |
23
+ | `helicalThreadRidgeMesh`, `helicalThreadSolidMesh`, and `preflightHelicalThreadSolidMesh` | `mesh.threadRidge`, `mesh.threadSolid`, and `mesh.preflightThreadSolid` |
24
+ | `HelicalThreadRidgeMeshOptions`, `HelicalThreadSolidMeshOptions`, and `HelicalThreadSolidMeshPreflight` | `ThreadRidgeOptions`, `ThreadSolidOptions`, and `ThreadSolidPreflight`, exported from the mesh module |
25
+ | Mesh `connectedComponentCount` | `shellCount`; native inspection `componentCount` still counts material components |
26
+ | Inspection extrema on the inspection result | Immutable `inspection.bounds.min` and `inspection.bounds.max` |
27
+ | `starContour(outerRadius, points, innerRadius, limits)` | `starContour({ outerRadius, innerRadius, points, limits })` |
28
+
29
+ Free `union(shapes)` and `intersect(shapes)` remain for collections of peers and reject empty
30
+ collections. Fluent Boolean methods with an empty array return the receiver.
31
+
32
+ Use `section.extrude(options)` in fluent modeling, `extrude(profile, options)` for generic
33
+ `Section | CorrespondingProfile` inputs, and `mesh.extrude(contour, options)` for pure triangle
34
+ buffers. The same fluent/generic distinction applies to revolution and sweeping. Pure extrusion
35
+ uses `ExtrudeMeshOptions` and rejects `ends`; use Section extrusion for native end treatments.
36
+ Construction, transforms, and splitting remain deferred recipes; observations and `toMesh()`
37
+ require active model execution.
38
+
39
+ Point-loop and arbitrary Section lofts default to direct correspondence when the method is
40
+ omitted; known primitive landmarks remain preserved. Dimension inputs accept fluent vectors.
41
+ Tube sizing accepts complete inner/outer radius or diameter pairs. Both star factories require
42
+ an explicit inner radius and support degree rotation; use `innerRadius: outerRadius / 2` to retain
43
+ the contour helper's former default.
44
+
45
+ Rod and internal-cutter `bevelBottom`, `bevelTop`, and `bevelSize` become `bevel`. The shared
46
+ `Bevel` contract accepts a nonnegative size, `"auto"`, or a readonly `[bottom, top]` pair; zero
47
+ disables an end and omission preserves factory defaults. Complete-thread mesh builders use the
48
+ same contract, with thread termination under `ends`. Nuts replace bevel selection, `chamferSize`,
49
+ and `flushBuildPlateBottom` with independent `innerBevel` and `outerBevel`. For a flat outside
50
+ bottom that retains its inner opening bevel, use `outerBevel: [0, "auto"]`. Nut preflight exposes
51
+ resolved inner/outer pairs and checks face walls pairwise; each end's reservation and automatic
52
+ sizing are resolved independently, including internal-cutter axial extension.
53
+
54
+ Primitive contours and their points are immutable and can be explicit `computed` dependencies.
55
+ Copy the outer array and any points before editing. Geometry errors are available from the
56
+ Modeling root; operation option/result types are exported beside their owning operations.
57
+ Topology analysis with `includeTopology: true`, finalized parts, and local geometry resources
58
+ include required `shellCount` and `edgeCount`. Bounds construction options describe inputs only;
59
+ existing fluent bounds remain accepted.
60
+
61
+ ### Part placement and result ownership
62
+
63
+ Replace `part(id, { geometry, position, rotation })` with
64
+ `part(id, { geometry, transform })`. The optional transform accepts a fluent `transform3()` value,
65
+ a row-major 16-number matrix, or a computed reader; omission means identity. Pattern and
66
+ attachment matrices pass directly to `part()`. Only rigid placement is supported: scale, shear,
67
+ reflection, perspective, and non-finite values are rejected. Geometry-only and geometry-or-options
68
+ union inputs remain accepted without casts.
69
+
70
+ Use `PartDeclaration` for authored parts. Replace `ModelSnapshot` / `FinalizedModel` with
71
+ `ModelResult`, and `SnapshotPart` / `FinalizedPart` with `ModelPart`. `engine.run()`, `session.run()`,
72
+ and Testkit's `runModel()` return durable immutable results. Dispose sessions and runners to release their
73
+ caches; completed results remain valid and need no disposal. `model.part(id)` returns a required
74
+ semantic part or throws with available IDs; `model.parts` preserves output order.
75
+
76
+ Finalized buffers expose stable, iterable `ImmutableBuffer` values. Use `.copy()` for mutable
77
+ storage. A `ModelPart`'s top-level positions and indices are already in world space; apply its
78
+ immutable `transform` only to the reusable local buffers under `geometry`. Worker deliveries also
79
+ nest local resources under `geometry`. Host integrations use `ModelDeliveryEncoder`,
80
+ `PartDeliveryDecoder`, and `toWorldMeshes` for owned transfer and manufacturing output.
81
+ Replace `engine.export3mf(...)` with standalone `export3mf(parts, options)` from `/engine`, which
82
+ accepts completed meshes with explicit resource limits, independently of engine initialization.
83
+
84
+ Statistics rename `volumeMm3` → `signedVolume`, `finalizationMs` → `finalizeMs`, and
85
+ `generationMs` → `generateMs`; `buildMs` measures declarations.
86
+ `ModelResult.stats.byteCount` means bytes occupied by finalized world-space position and index buffers,
87
+ counting shared buffers once. Worker statistics preserve engine `generateMs`; host elapsed time
88
+ is `timings.totalMs`, with `paramsMs` for parameter work. Other host timing stages are optional:
89
+ an omitted stage is unmeasured.
90
+
91
+ Model parameter roots must be object maps. Captured parameters and computed results expose
92
+ deeply readonly `ImmutableValue<T>` views; supported mutable caller input is still accepted and
93
+ recaptured on every revision, including mutable children inside frozen objects. Deeply immutable
94
+ data retains identity reuse. Assertions and warnings accept bounded immutable nested `path`
95
+ metadata. Replace `validateModel` with `checkModel` and session/runner `.validate()` with `.check()`.
96
+ These check declarations and reached assertions without finalizing geometry; unexpected execution
97
+ failures still throw.
98
+
99
+ ### Generator SDK and Testkit
100
+
101
+ | Previous API | 0.18 API |
102
+ | -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
103
+ | Nested compiled Generator module | Flat format-5 model program; bind an existing program with `defineGeneratorModule({ definition, program })` |
104
+ | `isGeneratorModule(value)` | `parseGeneratorModule(value, definition)` |
105
+ | `executeGenerator({ ..., parsedParameters })` | `executeGenerator({ ..., parameters })`; current-definition validation always runs |
106
+ | Callback-scoped `withModel`, `ModelTestOptions`, or `runner.withModel` | `await runModel(programOrCallback, ...)` for one-off results; explicit sessions or Generator runners for repeated edits |
107
+ | Generator test `runner.execute(...)` | `runner.run(...)`, returning `GeneratorTestResult` |
108
+ | `expectSerializableDefinition` | `assertValidDefinition` |
109
+ | `expectValidDefaults`, `expectValidPresets`, and `expectValidParts` | `assertValidDefaults`, `assertValidPresets`, and `assertValidParts` |
110
+ | `expectMeshMeasurements` | `assertMeshMeasurements` |
111
+ | `canonicalizeParameters(definition, parameters)` from `/parameters` | `canonicalizeParameters(parameters)` from `/runtime` |
112
+ | `GeneratedPartsDecoder`, `parseGeneratedParts`, and `GeneratedPartsLimits` | `PartDeliveryDecoder`, `parseModelParts`, and `PartDeliveryLimits` |
113
+ | `GeneratedPart` and `GeneratedModel` | `ModelPartData` and `ModelData` |
114
+ | `GeneratedPartDelivery` and `GeneratedModelDelivery` | `PartDelivery` and `ModelDelivery` |
115
+
116
+ Testkit `runModel` accepts existing `ModelProgram` values and synchronous inline callbacks;
117
+ typed callbacks use `runModel<Parameters, Services>`. Its definition-bound Generator overload
118
+ validates inputs and prepares services. The SDK Modeling adapter adds definition-inferred
119
+ `GeneratorModel` and `parseGeneratorModel`. Ordinary model tests preserve definition-inferred
120
+ input types. Reusable Generator runners accept physical generation policy plus `cache` and
121
+ `verifyCache` for edit sequences; dispose the runner after use.
122
+
123
+ Generator execution and ordinary tests strictly require complete canonical parameter maps.
124
+ Use the parameter codec for strict input and `normalizeParameters` for forgiving recovery;
125
+ replace `prepareParameters`, `validateParameters`, and `PreparedParameters` with
126
+ `createParamCodec(definition).parse(...)` or `.safeParse(...)`. Schema adapters remain private.
127
+ Codec failures provide structured issues without a substitute parameter map. For deliberate
128
+ malformed-input assertion probes, replace `runner.validate(parameters, { normalize: false })`
129
+ with `runner.check(parameters, { validateInput: false })`.
130
+ Defaults are selected only by omission or `undefined` where supported; a `null` parameter map is
131
+ rejected. Parameterless model calls can omit the empty map. Definition and preset helpers catch
132
+ nested key typos and validate immediately while retaining literal inference.
133
+
134
+ `assertValidParts` checks the supplied world-space buffers, closed topology, and exact agreement
135
+ with local geometry under `transform`; it no longer hides corrupted output by reconstructing it.
136
+ Always await `assertValidParts(parts, engine)` (or omit the engine): failures reject, and supplying
137
+ an engine changes resource reuse only.
138
+ `assertValidDefinition` also checks the canonical JSON round trip. New `assertEqualBuffer` and
139
+ `assertEqualMesh` compare exact ordered contents without copying; equivalent shapes with different
140
+ triangulations can differ. `ContentMismatchError` identifies the first differing element or
141
+ length, while malformed input and reader failures retain their errors. Optional `contentMatchers`
142
+ support `expect.extend`, including negation, without a test-framework dependency.
143
+
144
+ ### CLI and package requirements
145
+
146
+ Rename the type-only CLI command `metamesh check` to `metamesh typecheck`; no alias is retained.
147
+ Node authoring APIs and Modeling/Testkit declaration-check methods retain their names. Generator
148
+ runs use `overrides` / `--overrides`, merged with defaults before strict parsing; standalone models
149
+ use `params` / `--params`. Supplying the other entry kind's input option is rejected.
150
+
151
+ Captured runs use format 2 with transform-only placement. The bundled capture renderer resolves
152
+ from the installed CLI package so published installations can render captures.
153
+ Public packages require Node.js 24 or newer, ESM imports, and TypeScript 6.0 or newer with strict
154
+ checking for TypeScript consumers.
155
+
156
+ ### Patch Changes
157
+
158
+ - Updated dependencies [2eea694]
159
+ - @metamesh/modeling@0.18.0
160
+ - @metamesh/generator-sdk@0.18.0
161
+
162
+ ## 0.17.0
163
+
164
+ ### Minor Changes
165
+
166
+ - Add `defineGeneratorModel(definition, callback)` through the optional
167
+ `@metamesh/generator-sdk/modeling` adapter. It infers controls, synchronous services, and diagnostic
168
+ parameter IDs while leaving the SDK root independent of the Modeling runtime.
169
+
170
+ Add `runner.withModel(parameters, callback)` and Testkit's `withModel(program, parameters, callback,
171
+ options?)` for scoped assertions. Both await synchronous or asynchronous callbacks and release
172
+ their snapshot in `finally`; the plain-model helper also releases its temporary session.
173
+ Generator validation failures throw the existing structured `GenerationError` diagnostics.
174
+
175
+ Migration tip: replace private definition-plus-`generate` wrappers with the SDK adapter, and use
176
+ scoped callbacks instead of repeated successful-result narrowing and snapshot disposal. Keep
177
+ `runner.execute` and direct engine sessions for tests that inspect invalid results, cache behavior,
178
+ or explicit snapshot ownership. Prepared services are required for plain models that declare them.
179
+
180
+ Scoped callbacks retain snapshot parts without eagerly copying their buffers. For cross-run
181
+ geometry comparisons, select manufacturing fields rather than transient geometry resource IDs.
182
+ Capture `positions` and `indices` once before dense traversal: each accessor read returns a copy.
183
+
184
+ ### Patch Changes
185
+
186
+ - Updated dependencies
187
+ - Updated dependencies
188
+ - Updated dependencies [d0cc194]
189
+ - Updated dependencies
190
+ - Updated dependencies
191
+ - @metamesh/modeling@0.17.0
192
+ - @metamesh/generator-sdk@0.17.0
193
+
3
194
  ## 0.16.0
4
195
 
5
196
  ### Minor Changes
package/README.md CHANGED
@@ -1,120 +1,154 @@
1
1
  # `@metamesh/testkit`
2
2
 
3
- Test MetaMesh models and Generators with the same generation engine used by their hosts. Check definitions,
4
- presets, mesh validity, and physical measurements with any test runner.
3
+ Test MetaMesh models and Generators with their production engine. Check definitions, presets,
4
+ geometry, and physical measurements with any test runner.
5
5
 
6
6
  > **Preview:** `0.x` minor releases may break compatibility. Patches remain compatible within the
7
7
  > same minor line.
8
8
 
9
9
  ## Installation
10
10
 
11
- Install the same exact SDK, Modeling, and Testkit release. Testkit is a development dependency:
11
+ Install matching SDK, Modeling, and Testkit releases. Testkit is a development dependency:
12
12
 
13
13
  ```bash
14
14
  pnpm add @metamesh/generator-sdk @metamesh/modeling
15
15
  pnpm add -D @metamesh/testkit
16
16
  ```
17
17
 
18
- ## Execute models in tests
18
+ The package publishes ES modules only. Use Node.js 24 or newer. TypeScript consumers need
19
+ TypeScript 6.0 or newer, `strict` checking, and `NodeNext` or `Bundler` module resolution.
19
20
 
20
- Given a Generator module exporting its `definition` and default runtime, such as the
21
- [SDK example](https://github.com/JasonKoolman/metamesh/blob/main/packages/generator-sdk/README.md#define-controls):
21
+ Testkit has no test-framework, compiler, renderer, or browser dependency. For source checking,
22
+ captured runs, or images, use [CLI](https://github.com/JasonKoolman/metamesh/blob/main/packages/cli/README.md).
22
23
 
23
- ```ts
24
- import { getDefaultParameters } from "@metamesh/generator-sdk/parameters";
25
- import { createGeneratorTestRunner, expectValidParts } from "@metamesh/testkit";
26
-
27
- import runtime, { definition } from "./generator.js";
28
-
29
- const runner = createGeneratorTestRunner(definition, runtime);
30
- try {
31
- const result = await runner.execute(getDefaultParameters(definition));
32
- if (result.type !== "generated") throw new Error("Expected valid Generator output.");
33
- try {
34
- await expectValidParts(result.model.parts);
35
- } finally {
36
- result.model.dispose();
37
- }
38
- } finally {
39
- runner.dispose();
40
- }
41
- ```
42
-
43
- `execute` normalizes values, prepares services, and runs a persistent session. Schema and assertion
44
- errors return `invalid`; unexpected execution or malformed-output errors reject. Dispose returned
45
- snapshots separately from the runner; captured snapshots remain valid after runner disposal.
46
-
47
- Use `runner.validate(parameters, { normalize: false })` to probe deliberately invalid typed values
48
- without finalizing parts. It checks declarations and reached assertions; observing geometry can
49
- still initialize the engine. Creating a runner alone loads no engine or assets. Pass `options.engine`
50
- to reuse a test-owned engine and `options.limits` to lower host ceilings.
51
-
52
- ## Assertions
53
-
54
- Helpers throw on failure without depending on your test framework:
55
-
56
- | Helper | Checks |
57
- | ------------------------------ | ------------------------------------------------------------------ |
58
- | `expectSerializableDefinition` | Strict parsing and a canonical JSON round trip |
59
- | `expectValidDefaults` | Strict parameter decoding and agreement with definition defaults |
60
- | `expectValidPresets` | Serializable preset metadata; use the runner for domain assertions |
61
- | `expectValidParts` | Strict part metadata, closed topology, and native reconstruction |
62
- | `expectMeshMeasurements` | Bounds, area, signed volume, and connected-component count |
63
-
64
- `expectValidParts(parts, engine)` is synchronous and uses that engine's limits. Without an engine,
65
- it returns a promise using the shared test engine and default limits. It also accepts finalized
66
- parts, stripping measurement facts before strict validation; other unknown fields reject.
67
- Snapshot inputs retain shared local mesh buffers and rigid placements in the returned parts.
24
+ ## Test a model
68
25
 
69
- Compare physical measurements with explicit tolerances. For a 30 × 20 × 4 mm box mesh:
26
+ Build a plate, check its volume and shell count, then verify native reconstruction:
70
27
 
71
28
  ```ts
72
- import { expectMeshMeasurements } from "@metamesh/testkit";
29
+ import { box } from "@metamesh/modeling";
30
+ import { assertMeshMeasurements, assertValidParts, runModel } from "@metamesh/testkit";
73
31
 
74
- expectMeshMeasurements(
75
- mesh,
76
- { signedVolume: 30 * 20 * 4, connectedComponentCount: 1 },
32
+ const model = await runModel<{ width: number }>(
33
+ ({ params, part }) => part("plate", box({ size: [params.width, 20, 4] })),
34
+ { width: 30 }
35
+ );
36
+
37
+ assertMeshMeasurements(
38
+ model.part("plate"),
39
+ { signedVolume: 2400, shellCount: 1 },
77
40
  { signedVolume: 0.05 }
78
41
  );
42
+ await assertValidParts(model.parts);
79
43
  ```
80
44
 
81
- Bounds use mm, area mm², and volume mm³. Tolerances are absolute and default to zero; component
82
- counts are exact. Measurements check closed oriented topology without a native engine. Matching
83
- measurements alone do not establish geometric equivalence or exclude self-intersections; use
84
- `expectValidParts` for native reconstruction.
85
-
86
- ## Font fixtures
87
-
88
- Supply `prepareServices` in runner options for models with fonts. It receives the definition and
89
- current parameters, and can return services synchronously or asynchronously. Missing fixtures or
90
- service failures reject before generation. A different services object starts a fresh session;
91
- return the same immutable object when capabilities are unchanged to retain computation caches.
45
+ Helpers report failures without registering global assertions. `runModel` returns durable,
46
+ immutable parts, measurements, diagnostics, and dependencies; the result needs no cleanup.
47
+ Use `model.part(id)` for a required semantic part or `model.parts` for iteration and export.
48
+
49
+ Always await `assertValidParts(parts, engine)`: it resolves to the same parts or rejects on failure.
50
+ A supplied engine is reused; omission lazily initializes the shared test engine.
51
+ It checks the supplied world-space buffers for closed topology, then requires their positions and
52
+ indices to exactly match local geometry reconstructed with the declared rigid transform.
53
+ A valid local mesh cannot conceal corrupted or inconsistent world-space output.
54
+
55
+ Pass an existing Modeling program directly: `await runModel(program, parameters)` uses the same
56
+ program and parameter types as `engine.run`. A synchronous generation callback is also accepted;
57
+ without parameters, no type argument or wrapper is needed:
58
+ `await runModel(({ part }) => part("cube", box({ size: 2 })))`.
59
+ Parameters retain the program or callback's declared type; use
60
+ `GenerateCallback<Parameters, Services>` for a reusable callback or supply
61
+ `runModel<Parameters, Services>` inline. Options stay in the third argument; use `undefined` for
62
+ omitted parameters when supplying an engine, limits, or prepared services.
92
63
 
93
- `prepareFontTestServices` from `/fonts` checks immutable font revisions and prepares services from
94
- checked-in bytes. Install Modeling's optional `fontkit` peer, plus `woff2-encoder` for WOFF2 fixtures.
95
- Tests need no font downloads or browser cache; retain the fixtures' licenses.
64
+ ## Assertions
96
65
 
97
- For local JSON fixture descriptors, `loadFontFixtureServices` from
98
- `@metamesh/testkit/font-fixtures` returns the runner's `prepareServices` adapter. Descriptor paths
99
- resolve beside the JSON file, and every file's SHA-256 must match its declared selection revision.
100
- `loadFontFixtures` additionally returns the verified selections. These loaders are Node-only;
101
- use `/fonts` when the host already supplies the bytes.
66
+ | Helper | Checks |
67
+ | ------------------------ | -------------------------------------------------------------- |
68
+ | `assertValidDefinition` | Strict parsing and a canonical JSON round trip. |
69
+ | `assertValidDefaults` | Strict decoding and agreement with definition defaults. |
70
+ | `assertValidPresets` | Complete, normalized preset metadata. |
71
+ | `assertValidParts` | Part metadata, closed topology, and native reconstruction. |
72
+ | `assertMeshMeasurements` | Bounds, surface area, signed volume, and surface shell count. |
73
+ | `assertEqualBuffer` | Exact ordered numeric buffer contents without copying storage. |
74
+ | `assertEqualMesh` | Exact positions and indices, independently of mesh metadata. |
75
+
76
+ `assertValidDefinition` requires strict SDK parsing and a canonical JSON round trip; it does not
77
+ execute the Generator. Check model assertions and domain constraints through the Generator runner.
78
+
79
+ Measurement tolerances are absolute: millimetres for bounds, mm² for area, and mm³ for volume.
80
+ They default to zero; shell counts are exact. Matching measurements do not prove geometric
81
+ equivalence or rule out self-intersections. Use native reconstruction checks alongside them.
82
+
83
+ Use `assertEqualBuffer(actual, expected)` or `assertEqualMesh(actual, expected)` directly without a
84
+ test framework. They read `length` and `at(index)` without copying storage and throw
85
+ `ContentMismatchError` with the first differing index or length. Malformed representations throw
86
+ `TypeError`; reader failures propagate. Numeric equality uses `Object.is`: `NaN` equals `NaN` and
87
+ signed zero differs. Mesh comparisons ignore metadata and require identical position and index
88
+ contents. Geometrically equivalent meshes with different triangulation or ordering can fail.
89
+
90
+ Register the thin optional adapters with your runner's `expect.extend(contentMatchers)` to use
91
+ `toEqualBuffer` and `toEqualMesh`, including `.not`. Only `ContentMismatchError` becomes a failed
92
+ matcher result; invalid inputs and unexpected errors still throw. Follow your runner's
93
+ [matcher extension guidance](https://vitest.dev/guide/extending-matchers) for TypeScript declarations.
94
+
95
+ ## Test Generators and repeated edits
96
+
97
+ For a module exporting its definition and default runtime, pass
98
+ `runModel({ definition, runtime }, parameters)`. Omit parameters or pass `undefined` to use defaults;
99
+ all other supplied Generator inputs have the definition's inferred types and must form a complete
100
+ canonical map. Use `runner.run(record)` to test unknown keys, missing fields, or wrong value types.
101
+ For one changed value, spread
102
+ `getDefaultParameters(definition)` and then apply the override; the runner does not merge defaults. The overload strictly parses inputs and prepares
103
+ services. Use SDK `normalizeParameters` explicitly when recovering saved values. Plain model
104
+ parameters pass through directly.
105
+
106
+ Generator integration tests should import the actual entry point instead of repeating its input
107
+ resolution and builder wiring. Use a direct callback for isolated construction or mesh reconstruction.
108
+ For a deliberate schema bypass, `runModel(runtime, parameters, { services })` executes
109
+ the Generator's model behavior without claiming those values pass its parameter schema.
110
+ See the [SDK example](https://github.com/JasonKoolman/metamesh/blob/main/packages/generator-sdk/README.md#define-controls).
111
+
112
+ Use `createGeneratorTestRunner(definition, runtime)` for repeated parameter cases or cache tests.
113
+ Its `run` method returns a generated result or structured validation failure. `check` probes
114
+ declarations and reached assertions without finalizing parts; geometry observations can still
115
+ require the engine. Dispose the runner in `finally`; returned results remain usable.
116
+ Use `check(parameters, { validateInput: false })` only to probe model assertions with deliberately
117
+ invalid typed values, bypassing the parameter schema.
118
+
119
+ For models using `computed`, include repeated-edit tests with `{ verifyCache: true }` on the runner.
120
+ Change geometry inputs and placement inputs independently. Verification reruns cached calculations
121
+ and rejects changed results without tracked dependencies, including accidentally captured destructured
122
+ parameters. Read parameters inside the computation or list changing outer values in its dependency
123
+ array. Verification is a bounded development probe; unsupported captures or large results can
124
+ require comparison with `{ cache: false }` on a separate runner. It cannot prove arbitrary JavaScript.
125
+ Keep prepared service identity stable for unchanged assets; replacing services creates a new session
126
+ and prevents testing cache reuse. Isolated `runModel` calls do not verify repeated-edit correctness.
127
+
128
+ For plain models, use `engine.createSession(program, options)` for repeated edits or cache tests
129
+ and dispose the session in `finally`. Session results remain usable after later runs and disposal.
130
+ Both `runModel` and Generator runners can reuse a test-owned engine and lower its resource ceilings.
131
+ They accept the same physical `resolution`, `meshValidation`, and `meshTopologyMode` policy.
132
+
133
+ ## Fonts and entry points
134
+
135
+ | Import | Responsibility |
136
+ | --------------------------------- | ------------------------------------------------------------------------------ |
137
+ | `@metamesh/testkit` | Model execution, Generator runners, assertions, and optional content matchers. |
138
+ | `@metamesh/testkit/fonts` | Prepared font services from supplied fixture bytes. |
139
+ | `@metamesh/testkit/font-fixtures` | Node-only JSON fixture loading with SHA-256 verification. |
140
+
141
+ Font-dependent Generators receive a `prepareServices` callback before generation. Tests use
142
+ checked-in bytes without CDN access; retain their licenses. Font preparation needs Modeling's
143
+ optional `fontkit` peer, plus `woff2-encoder` for WOFF2 fixtures.
102
144
 
103
145
  ## Documentation
104
146
 
105
- Resolve `@metamesh/testkit/docs/manifest.json` for this installed version's Markdown
106
- reference and testing guidance. Testkit has no compiler, bundler, renderer, or browser dependencies.
107
- It shares the Modeling engine and Generator SDK contracts rather than duplicating runtime rules.
108
-
109
- For source checking, captured runs, documentation lookup, and images, install
110
- [`@metamesh/cli`](https://github.com/JasonKoolman/metamesh/blob/main/packages/cli/README.md).
111
- Its executable is `metamesh`; reusable Node authoring functions live in `@metamesh/cli/authoring`.
112
-
113
- - [Generator SDK](https://github.com/JasonKoolman/metamesh/blob/main/packages/generator-sdk/README.md) — definitions, parameter values, and module authoring.
114
- - [Modeling](https://github.com/JasonKoolman/metamesh/blob/main/packages/modeling/README.md) — geometry, sessions, and snapshots.
115
- - [API source](https://github.com/JasonKoolman/metamesh/blob/main/packages/testkit/src/index.ts) — runner and assertion exports; [font helpers](https://github.com/JasonKoolman/metamesh/blob/main/packages/testkit/src/fonts.ts) live in `/fonts`.
116
-
117
- For package development, see [Contributing](https://github.com/JasonKoolman/metamesh/blob/main/CONTRIBUTING.md).
147
+ Resolve `@metamesh/testkit/docs/manifest.json` for exact-version Markdown guidance and annotated
148
+ API references. With CLI installed, read `pnpm exec metamesh docs show testkit/guide/testing`.
149
+ See [Modeling](https://github.com/JasonKoolman/metamesh/blob/main/packages/modeling/README.md)
150
+ for geometry and [Contributing](https://github.com/JasonKoolman/metamesh/blob/main/CONTRIBUTING.md)
151
+ for package development.
118
152
 
119
153
  ## License
120
154
 
@@ -1,20 +1,13 @@
1
1
  import type { GeneratorDefinition, GeneratorParams, GeneratorPreset } from "@metamesh/generator-sdk";
2
- import { type GeneratedPart } from "@metamesh/generator-sdk/runtime";
3
- import { type FinalizedPart } from "@metamesh/modeling";
4
- import type { ModelEngine } from "@metamesh/modeling/engine";
5
- /** Throws unless a definition already has the canonical package-serializable representation. */
6
- export declare function expectSerializableDefinition(definition: GeneratorDefinition): void;
2
+ import type { ModelEngine, ModelPart } from "@metamesh/modeling/engine";
3
+ /** Strictly parses a definition and requires its JSON round trip to retain the canonical package representation. */
4
+ export declare function assertValidDefinition(definition: GeneratorDefinition): void;
7
5
  /** Throws unless defaults strictly decode and equal the defaults derived from the definition. */
8
- export declare function expectValidDefaults<const D extends GeneratorDefinition>(definition: D, defaults: GeneratorParams<D>): void;
6
+ export declare function assertValidDefaults<const D extends GeneratorDefinition>(definition: D, defaults: GeneratorParams<D>): void;
9
7
  /** Checks preset metadata. Validate domain assertions through the generation test runner. */
10
- export declare function expectValidPresets<const D extends GeneratorDefinition>(definition: D, presets: readonly GeneratorPreset<D>[]): void;
11
- /**
12
- * Checks finalized parts without measurement facts, retaining shared snapshot resources and placement.
13
- * Runs mesh reconstruction/finalization synchronously using the supplied engine.
8
+ export declare function assertValidPresets<const D extends GeneratorDefinition>(definition: D, presets: readonly GeneratorPreset<D>[]): void;
9
+ /** Validates supplied world meshes and their exact agreement with reconstructed local geometry and placement.
10
+ * Resolves to the same parts or rejects on failure. A supplied engine is reused; otherwise the shared engine initializes lazily.
14
11
  */
15
- export declare function expectValidParts(value: readonly FinalizedPart[], engine: ModelEngine): readonly GeneratedPart[];
16
- /** Strictly checks unknown wire data and reconstructs its meshes using the supplied engine. */
17
- export declare function expectValidParts(value: unknown, engine: ModelEngine): readonly GeneratedPart[];
18
- /** Initializes the shared test engine lazily, then applies the same wire and mesh checks. */
19
- export declare function expectValidParts(value: unknown): Promise<readonly GeneratedPart[]>;
12
+ export declare function assertValidParts(parts: readonly ModelPart[], engine?: ModelEngine): Promise<readonly ModelPart[]>;
20
13
  //# sourceMappingURL=assertions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EACf,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAC1F,OAAO,EAAY,KAAK,aAAa,EAAqB,MAAM,oBAAoB,CAAC;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AA4B7D,gGAAgG;AAChG,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,mBAAmB,GAAG,IAAI,CAUlF;AAED,iGAAiG;AACjG,wBAAgB,mBAAmB,CAAC,KAAK,CAAC,CAAC,SAAS,mBAAmB,EACrE,UAAU,EAAE,CAAC,EACb,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,GAC3B,IAAI,CAQN;AAED,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAAC,KAAK,CAAC,CAAC,SAAS,mBAAmB,EACpE,UAAU,EAAE,CAAC,EACb,OAAO,EAAE,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,GACrC,IAAI,CAEN;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,aAAa,EAAE,EAC/B,MAAM,EAAE,WAAW,GAClB,SAAS,aAAa,EAAE,CAAC;AAE5B,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,aAAa,EAAE,CAAC;AAEhG,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EACf,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAOjC,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AA2BxE,oHAAoH;AACpH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,mBAAmB,GAAG,IAAI,CAU3E;AACD,iGAAiG;AACjG,wBAAgB,mBAAmB,CAAC,KAAK,CAAC,CAAC,SAAS,mBAAmB,EACrE,UAAU,EAAE,CAAC,EACb,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,GAC3B,IAAI,CAQN;AACD,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAAC,KAAK,CAAC,CAAC,SAAS,mBAAmB,EACpE,UAAU,EAAE,CAAC,EACb,OAAO,EAAE,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,GACrC,IAAI,CAEN;AACD;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CA6B/B"}
@@ -1,8 +1,9 @@
1
1
  import { parseGeneratorDefinition, validateGeneratorPresets, } from "@metamesh/generator-sdk/packages";
2
2
  import { createParamCodec, getDefaultParameters } from "@metamesh/generator-sdk/parameters";
3
- import { parseGeneratedParts } from "@metamesh/generator-sdk/runtime";
4
3
  import { generate } from "@metamesh/modeling";
5
- import { getTestEngine } from "./engine.js";
4
+ import * as mesh from "@metamesh/modeling/geometry/mesh";
5
+ import { assertEqualMesh } from "./content-assertions.js";
6
+ import { getTestEngine } from "./test-engine.js";
6
7
  function stringify(value, label) {
7
8
  try {
8
9
  const serialized = JSON.stringify(value);
@@ -26,8 +27,8 @@ function sortJson(value) {
26
27
  function stableStringify(value, label) {
27
28
  return stringify(sortJson(value), label);
28
29
  }
29
- /** Throws unless a definition already has the canonical package-serializable representation. */
30
- export function expectSerializableDefinition(definition) {
30
+ /** Strictly parses a definition and requires its JSON round trip to retain the canonical package representation. */
31
+ export function assertValidDefinition(definition) {
31
32
  parseGeneratorDefinition(definition);
32
33
  const decoded = JSON.parse(stringify(definition, "Generator definition"));
33
34
  const parsed = parseGeneratorDefinition(decoded);
@@ -37,7 +38,7 @@ export function expectSerializableDefinition(definition) {
37
38
  }
38
39
  }
39
40
  /** Throws unless defaults strictly decode and equal the defaults derived from the definition. */
40
- export function expectValidDefaults(definition, defaults) {
41
+ export function assertValidDefaults(definition, defaults) {
41
42
  const parsed = createParamCodec(definition).parse(defaults);
42
43
  if (stableStringify(parsed, "Generator defaults") !==
43
44
  stableStringify(getDefaultParameters(definition), "Derived Generator defaults")) {
@@ -45,74 +46,27 @@ export function expectValidDefaults(definition, defaults) {
45
46
  }
46
47
  }
47
48
  /** Checks preset metadata. Validate domain assertions through the generation test runner. */
48
- export function expectValidPresets(definition, presets) {
49
+ export function assertValidPresets(definition, presets) {
49
50
  validateGeneratorPresets(definition, presets);
50
51
  }
51
- export function expectValidParts(value, engine) {
52
- if (engine === undefined)
53
- return getTestEngine().then((host) => expectValidParts(value, host));
54
- const meshes = new WeakMap();
55
- const wireValue = Array.isArray(value)
56
- ? value.map((part, index) => {
57
- if (typeof part !== "object" || part === null || !Object.hasOwn(part, "measurements"))
58
- return part;
59
- const prototype = Object.getPrototypeOf(part);
60
- if (prototype !== null && prototype !== Object.prototype)
61
- return part;
62
- const descriptors = Object.getOwnPropertyDescriptors(part);
63
- if (Object.keys(descriptors).some((key) => ![
64
- "id",
65
- "positions",
66
- "indices",
67
- "color",
68
- "measurements",
69
- "geometry",
70
- "position",
71
- "rotation",
72
- ].includes(key)))
73
- return part;
74
- const resource = descriptors["geometry"];
75
- if (resource !== undefined && !("value" in resource))
76
- return part;
77
- const geometry = resource?.value;
78
- const source = typeof geometry === "object" && geometry !== null
79
- ? geometry
80
- : part;
81
- // Snapshot getters return copies. Read each local resource once to retain shared storage.
82
- let mesh = meshes.get(source);
83
- if (mesh === undefined) {
84
- mesh = { positions: source.positions, indices: source.indices };
85
- meshes.set(source, mesh);
86
- }
87
- descriptors["positions"] = { value: mesh.positions, enumerable: true };
88
- descriptors["indices"] = { value: mesh.indices, enumerable: true };
89
- if (source === part) {
90
- delete descriptors["position"];
91
- delete descriptors["rotation"];
92
- }
93
- delete descriptors["measurements"];
94
- delete descriptors["geometry"];
95
- return Object.defineProperties({
96
- geometryId: `assertion-${index}`,
97
- geometryRevision: 0,
98
- position: [0, 0, 0],
99
- rotation: [0, 0, 0],
100
- }, descriptors);
101
- })
102
- : value;
103
- const parts = parseGeneratedParts(wireValue, engine.limits);
104
- const session = engine.createSession(generate(({ part }) => parts.map((mesh) => part(mesh.id, {
105
- geometry: mesh,
106
- position: mesh.position,
107
- rotation: mesh.rotation,
108
- ...(mesh.color === undefined ? {} : { color: mesh.color }),
109
- }))));
110
- try {
111
- session.run({}).dispose();
112
- }
113
- finally {
114
- session.dispose();
52
+ /** Validates supplied world meshes and their exact agreement with reconstructed local geometry and placement.
53
+ * Resolves to the same parts or rejects on failure. A supplied engine is reused; otherwise the shared engine initializes lazily.
54
+ */
55
+ export async function assertValidParts(parts, engine) {
56
+ const host = engine ?? (await getTestEngine());
57
+ for (const part of parts) {
58
+ const unknown = Reflect.ownKeys(part).find((key) => typeof key !== "string" ||
59
+ !["id", "positions", "indices", "color", "measurements", "geometry", "transform"].includes(key));
60
+ if (unknown !== undefined)
61
+ throw new TypeError('Model part contains unknown field "' + String(unknown) + '".');
62
+ mesh.validate(part, { requireClosed: true });
115
63
  }
64
+ const reconstructed = host.run(generate(({ part }) => parts.map((value) => part(value.id, {
65
+ geometry: value.geometry,
66
+ transform: value.transform,
67
+ ...(value.color === undefined ? {} : { color: value.color }),
68
+ }))), undefined, { meshTopologyMode: "original" });
69
+ parts.forEach((part, index) => assertEqualMesh(part, reconstructed.parts[index]));
116
70
  return parts;
117
71
  }
118
72
  //# sourceMappingURL=assertions.js.map