Assembly export and viewer: evidence log (issue 54)
This log records what ran, where it ran and what it printed for arena assembly export-meshes,
assembly/export.py and the assembly pose view in web/. The usage and the manifest schema are in
docs/assembly-viewer.md.
What was built
src/tolerance_arena/assembly/export.py:export_pose(assembly, q, delta, output_dir)places each part withpose.placements, measures the requirement pair withmeasure.measure, and hands the placed solids tomeshes.export_mesheswith aposeblock of"kind": "assembly".src/tolerance_arena/assembly/cli.py: theexport-meshessubcommand with--sidecaror--family,--q,--delta-mm,--output, repeatable--param NAME=VALUE,--tessellation-mmand--json.src/tolerance_arena/meshes.py: two changes to the shared writer, described under "Defects found in code that was already merged".web/:parseManifest.tsreads the assembly pose block;lib/poseDirectory.tsmaps?pose=NAMEtodata/NAME;scene/assemblePose.tsbuilds the scene from the loaded pieces with one label per part and the gap marker;panels/AssemblyPanels.tsxshows the parts, the joint coordinate and the measured gap;scene/partTokens.tsandlib/formatNumber.tsare small helpers.- Sample data under
web/public/data/:family-hinged-flap-post/(familyhinged-flap-post, q 45 deg, delta -1.2 mm) andstep-hinge/(the STEP sidecarfixtures/assembly/hinge.assembly.yaml, q 85 deg, delta -0.5 mm). The pin sampleweb/public/data/pose/is untouched. - Tests:
tests/assembly/test_assembly_export.py(59, no kernel),tests/test_meshes_empty_file.py(15, no kernel) andtests/assembly/test_assembly_export_native.py(16, markernative), with the GLB readertests/assembly/assembly_glb.py. On the web sideassembly-manifest.test.ts(53),assemble-pose.test.ts(21),pose-directory.test.ts(21),assembly-viewer.test.tsx(12) andformat-number.test.ts(4): 111 new tests next to the 45 pin tests, which are unchanged. scripts/mutation_check.py: the AX01 to AX36 mutants, andnode_modulesadded to the names the tree copy skips (the copy of a clone with an installedweb/node_moduleswas otherwise large).
Baseline: commit 10afd38 on main of the scratch clone. The code is in commit 31e002f (Python)
and commit 4dc8cca (web), in that order; this log and the documents are the third commit. git diff --name-only -- web/tests tests
printed nothing, so no existing test file was edited.
Test first
Python:
.venv/bin/python -m pytest -q -p no:cacheprovider tests/assembly/test_assembly_export.py tests/assembly/test_assembly_export_native.pybeforeexport.pyexisted:E ImportError: cannot import name 'export' from 'tolerance_arena.assembly'and2 errors in 5.70s.tests/test_meshes_empty_file.pybefore the no-vertex guard:10 failed, 1 passed in 1.89s, each failureFailed: DID NOT RAISE MeshExportError. After the guard:15 passed.- The native test
test_a_solid_read_from_a_step_file_exports_a_meshbefore the parent fix:1 failed, 1 passed, 14 deselected in 4.77s.
Web:
npx --no-install vitest run tests/assembly-manifest.test.tsbefore the parser change:Tests 47 failed | 1 passed (48). After it:Tests 64 passed (64)over two files.- The files
pose-directory.test.ts,assemble-pose.test.ts,assembly-viewer.test.tsxandformat-number.test.tswere written before their sources, but I did not run them before the sources existed, so there is no failing run to quote for them. The mutation sweep below is the evidence that each of their guards is bound by a test.
Defects found in code that was already merged
- A glTF file with no mesh.
build123d0.13.0export_gltfskips a root shape that has a parent and still writes a valid container. A solid read from a STEP file is a child of aCompound, soarena assembly export-meshes --sidecar ...first wrote a 240 byte file for the pin. The debug print of the solid's attributes held'_NodeMixin__parent': 'Compound', and a rebuilt copy of the same solid exported at 21316 bytes.meshes.export_meshesnow re-wraps a shape that has a parent (Shape.cast(placed.wrapped), the caller's solid keeps its parent) and reads each written file back: a file with noPOSITIONaccessor that holds a vertex isMeshExportError("export_failed", "<name>: the glTF file holds no mesh"). The unit tests of that check are intests/test_meshes_empty_file.py, the real case istest_a_solid_read_from_a_step_file_exports_a_mesh. AX10 and AX11 kill the two changes. - The issue 49 viewer converted each mesh twice.
meshes.pyexports a piece from a copy atC * L * C^-1, so the node in the file already holdsC * L_cadin metres. The viewer then applied the manifest matrix again throughplacePiece. The sample pin pose has the pin and the obstacle standing up (height 8 mm along CAD +Z); the viewer drew them lying on their side (docs/assembly-log/export-viewer-pin-before-fix.png).placeExportedPieceputs the piece under a group with the identity, and the manifest matrix is used only for CAD-frame numbers the manifest holds, the witness points.export-viewer-pin-after-fix.pngshows the pins upright from the same manifest and files.placePieceand its tests are unchanged, so the pin tests stay as they were, and the visible pin sample changes with this fix. A test reads the committed GLB, runsassemblePoseand compares the box of the post, the flap and the pin with the CAD box converted once (web/tests/assemble-pose.test.ts).
The pose in the files
tests/assembly/test_assembly_export_native.py reads every exported GLB with its own reader
(assembly_glb.py, no code shared with the exporter) and checks, for a family pose and for the STEP
sidecar pose:
- the manifest on disk equals the manifest the function returned; one
cad_to_viewmatrix at the top and the same matrix in each piece; eachsha256equals the hash of the file; - the mesh box, converted back with
meshes.view_to_cad, equals the bounding box of the placed solid within the tessellation tolerance (0.01 mm) plus the float32 rounding of a vertex; - the flap mesh is turned by the joint coordinate and the post mesh carries the deviation, against closed-form corner positions;
- the witness points lie on the written meshes (the distance from each point to its part's
triangles is within the tolerance) and the distance between them equals
distance_mm; - the same pose exported twice writes byte-identical files.
A GLB vertex is a 32-bit float in metres, so a coordinate read from a mesh agrees with the CAD value
to about 1e-4 mm. The tests use GLB_PRECISION_MM = 1e-4 for that and nothing wider.
The committed samples are reproducible
Both sample directories were regenerated into an empty scratch folder with:
arena assembly export-meshes --family hinged-flap-post --q 45 --delta-mm=-1.2 --output <dir>/family-hinged-flap-post
arena assembly export-meshes --sidecar fixtures/assembly/hinge.assembly.yaml --q 85 --delta-mm=-0.5 --output <dir>/step-hinge
Output lines of the first: measured_gap_mm: 0.9063058585, requirement: minimum_gap minimum_clearance flap post minimum=1.5 mm, flap.glb sha256=13da293cb20725f703007dbbd3a23e44c3ecd528bad9708ed2acc6129bac16bc,
post.glb sha256=96337c94264db51047d91f2748540adb66450b4f3b7e54883318e31a9252a817, and
The gap is measured at this pose only: no verdict was computed and no other pose was measured.
Of the second: measured_gap_mm: 0.6141590572, pin.glb sha256=918c67802d08a08f85c978e368f4ae28400ce9798dc5ea345edbe0c8c589e245,
block.glb sha256=988441649193b6db72d3e1ce21f243c231bd1470cdf43d973a6549c067493395. Both commands
exited 0. cmp printed identical for all six files against web/public/data/.
Two checks of the numbers by hand:
- The family gap at q 45 deg and delta -1.2 mm is 0.9063 mm in
docs/assembly-families.md(reference and kernel); the exported value is 0.9063058585 mm. - The STEP sidecar witness points are
(2.6146722824297406, 32.885840942752374, 10)and(2.6146722824297424, 33.5, 10)mm, so the gap is 33.5 - 32.885840942752374 = 0.614159057247626 mm up to the 1.8e-15 mm difference in x. The manifest holds 0.6141590572476261.
Mutants
Python, scripts/mutation_check.py, first and only run of the AX set:
.venv/bin/python scripts/mutation_check.py --workdir runs/mut_54/w1 --only '^AX[0-9]+$' --python "$PWD/.venv/bin/python"
control before: PASS (112 passed) scope=tests/assembly/test_assembly_export.py tests/assembly/test_assembly_export_native.py tests/test_meshes.py tests/test_meshes_empty_file.py
control after: PASS (112 passed)
mutants: 36 KILLED=36 SURVIVED=0 CAPPED=0 INVALID=0 BROKEN=0
RESULT: every mutant killed, controls clean
| Ids | Guard |
|---|---|
| AX01, AX02 | _check_parts: a part id with two dots, a part that is not a CAD shape |
| AX03, AX06, AX07 | the pose block: witnesses are null on overlap, the witnesses keep their order, the unit follows the joint type |
| AX04, AX05, AX08, AX09 | export_pose: the gap is measured at the exported pose, parts are placed, the tolerance reaches the writer, the parts are checked before the query |
| AX10 to AX17 | meshes.py: the no-vertex check (AX10, AX12 to AX17) and the re-wrap of a shape that has a parent (AX11) |
| AX18 to AX21 | the required source, --q, --delta-mm and --output |
| AX22, AX23 | the plain-decimal pattern for pose numbers (nan, inf, 4_5) |
| AX24 to AX26 | --param with a sidecar, repeated, and with no name or value |
| AX27 to AX30 | the refusal tuple: AssemblyError, NativeQueryError, MeshExportError, OSError |
| AX31 to AX34 | the overlap note, the planted-parameter note, the scope statement, the tessellation option |
| AX35, AX36 | the dispatch to _export and the JSON form |
Each result line names the test that killed the mutant; for example AX11 KILLED ... :: tests/assembly/test_assembly_export_native.py::test_a_step_sidecar_pose_exports_and_passes_the_manifest_checks[30.0--0.5].
No mutant is listed as equivalent. Three places have no mutant on purpose: the float(q) and
float(delta) casts in export_pose (a JSON reader cannot tell 45 from 45.0), the
isinstance(index, int) test in _holds_a_vertex (a non-integer index raises TypeError at the
comparison, which the same except clause turns into the same answer) and the constant
_GLB_FIRST_CHUNK_OFFSET (every GLB test passes through it, but I ran no mutant on it).
The harness runs pytest, so it cannot mutate TypeScript. The web guards were checked with a
sweep script kept outside the repository: it copies web/ to a scratch folder with node_modules
linked, applies one edit that must match exactly once, runs vitest run --bail 1, restores the
original bytes and compares hashes. The control before and after each batch passed.
control before: PASS 152 passed
... (47 edits)
control after: PASS 152 passed
mutants: 47 killed=43 other=4
T01 SURVIVED a reversed range is accepted 152 passed
T09 SURVIVED a negative distance is accepted 152 passed
T14 SURVIVED an overlap flag that is text is accepted 152 passed
T23 SURVIVED a requirement part with no piece is accepted 152 passed
The four survivors were redundant paths in the tests, not in the code: a reversed range is also
refused by the range check on q, a negative distance is also refused by the witness span check,
a text overlap flag with a gap is also refused by the distance check, and a requirement part is
always a joint part in the demo manifest. Tests were added for each (the field named in the error,
a distance of -1e-7 hidden inside the tolerance, a text and a zero overlap flag, and a requirement
part that no joint names) and the four were run again on the same copy method:
control before: PASS 156 passed
T01 KILLED ... T09 KILLED ... T14 KILLED ... T23 KILLED
control after: PASS 156 passed
mutants: 4 killed=4 other=0
All 47 edits:
| Id | File | What the edit does | Result |
|---|---|---|---|
| T01 | web/src/manifest/parseManifest.ts | a reversed range is accepted | survived the first run; a test was added; killed on the rerun |
| T02 | web/src/manifest/parseManifest.ts | a value below its range is accepted | killed |
| T03 | web/src/manifest/parseManifest.ts | a value above its range is accepted | killed |
| T04 | web/src/manifest/parseManifest.ts | the lower end of a range is refused | killed |
| T05 | web/src/manifest/parseManifest.ts | the upper end of a range is refused | killed |
| T06 | web/src/manifest/parseManifest.ts | a joint in the wrong unit is accepted | killed |
| T07 | web/src/manifest/parseManifest.ts | a minimum of zero is accepted | killed |
| T08 | web/src/manifest/parseManifest.ts | one part named twice in the requirement is accepted | killed |
| T09 | web/src/manifest/parseManifest.ts | a negative distance is accepted | survived the first run; a test was added; killed on the rerun |
| T10 | web/src/manifest/parseManifest.ts | an overlap with a distance is accepted | killed |
| T11 | web/src/manifest/parseManifest.ts | an overlap with witness points is accepted | killed |
| T12 | web/src/manifest/parseManifest.ts | witness points that do not span the distance are accepted | killed |
| T13 | web/src/manifest/parseManifest.ts | the witness tolerance is a thousand times wider | killed |
| T14 | web/src/manifest/parseManifest.ts | an overlap flag that is text is accepted | survived the first run; a test was added; killed on the rerun |
| T15 | web/src/manifest/parseManifest.ts | an unknown requirement type is accepted | killed |
| T16 | web/src/manifest/parseManifest.ts | an empty id is accepted | killed |
| T17 | web/src/manifest/parseManifest.ts | a number that is not finite is accepted | killed |
| T18 | web/src/manifest/parseManifest.ts | a moving part with no piece is accepted | killed |
| T19 | web/src/manifest/parseManifest.ts | a fixed part with no piece is accepted | killed |
| T20 | web/src/manifest/parseManifest.ts | a deviation part with no piece is accepted | killed |
| T21 | web/src/manifest/parseManifest.ts | an assembly pose needs a pin and an obstacle | killed |
| T22 | web/src/manifest/parseManifest.ts | an assembly pose needs no piece | killed |
| T23 | web/src/manifest/parseManifest.ts | a requirement part with no piece is accepted | survived the first run; a test was added; killed on the rerun |
| T24 | web/src/lib/poseDirectory.ts | a pose name that leaves the data folder is accepted | killed |
| T25 | web/src/lib/poseDirectory.ts | a pose name may start with a dot or a dash | killed |
| T26 | web/src/lib/poseDirectory.ts | a pose name may have 65 characters | killed |
| T27 | web/src/lib/poseDirectory.ts | a pose name of 64 characters is refused | killed |
| T28 | web/src/lib/poseDirectory.ts | no pose parameter reads data/null | killed |
| T29 | web/src/lib/poseDirectory.ts | the default directory moves | killed |
| T30 | web/src/lib/formatNumber.ts | the display shows twelve digits | killed |
| T31 | web/src/lib/formatNumber.ts | the display shows six digits | killed |
| T32 | web/src/scene/assemblePose.ts | a label sits inside its part | killed |
| T33 | web/src/scene/assemblePose.ts | a zero-length gap draws a marker with a NaN direction | killed |
| T34 | web/src/scene/assemblePose.ts | the gap ends are swapped | killed |
| T35 | web/src/scene/assemblePose.ts | a piece with no object is skipped | killed |
| T36 | web/src/scene/assemblePose.ts | a piece keeps its loaded material | killed |
| T37 | web/src/scene/assemblePose.ts | a label is not in the scene | killed |
| T38 | web/src/scene/assemblePose.ts | the gap marker is not in the scene | killed |
| T39 | web/src/scene/assemblePose.ts | the gap marker has no thickness | killed |
| T40 | web/src/scene/assemblePose.ts | the gap marker is as large as the parts | killed |
| T41 | web/src/scene/partTokens.ts | the fifth part has no colour | killed |
| T42 | web/src/scene/partTokens.ts | an assembly uses the pin colours by name | killed |
| T43 | web/src/panels/AssemblyPanels.tsx | the requirement position is zero based | killed |
| T44 | web/src/panels/AssemblyPanels.tsx | the first requirement part has no role | killed |
| T45 | web/src/panels/AssemblyPanels.tsx | an overlap is not said on screen | killed |
| T46 | web/src/panels/AssemblyPanels.tsx | the fixed part has no role | killed |
| T47 | web/src/scene/placePiece.ts | the exported piece is converted a second time | killed |
Screenshots
The viewer was built (npm run build), served from web/dist on 127.0.0.1 and rendered in headless
Chrome with software WebGL (--use-angle=swiftshader --enable-unsafe-swiftshader), 1280 by 1300
pixels (1280 by 900 for the two pin shots). The dark shots use a second browser session with the colour scheme set to dark.
| File | Shows |
|---|---|
export-viewer-family-light.png, export-viewer-family-dark.png | ?pose=family-hinged-flap-post: the flap and post labels, the gap marker between the flap corner and the post, the three panels with q 45 deg, delta -1.2 mm and 0.9063058585 mm |
export-viewer-step-light.png, export-viewer-step-dark.png | ?pose=step-hinge: the pin and block labels, the gap marker at the top, the sidecar source with its SHA-256, 0.6141590572 mm |
export-viewer-pin-before-fix.png, export-viewer-pin-after-fix.png | the pin sample before and after placeExportedPiece |
The page prints the numbers of the manifest and no verdict. The gap marker is a small bar because the gaps are 0.9 and 0.6 mm and the parts are 41.5 mm and 12 mm across.
Gates
Run one after the other in the clone with export PYTHONDONTWRITEBYTECODE=1, on commit 10afd38
plus the working tree of this change, before the documents and screenshots of this change were
added (HEAD=10afd384d3187a25d64db3504b44c0f1509e8b49 was the first line the run printed):
OK check-fast: 2723 tests passed, no native query issued
OK check-geometry: 350 native tests passed
OK check-agents: 437 tests passed; all 3510 collected tests belong to a gate
OK check-web: 156 tests passed, typecheck and build clean
Each of the four exited 0. After the documents and screenshots were added, bash scripts/check-fast.sh
ran again on the tree that is committed and printed OK check-fast: 2723 tests passed, no native query issued (exit 0, 2723 passed, 400 deselected in 137.77s). ruff check . printed All checks passed!, ruff format --check .
printed 220 files already formatted and .venv/bin/mypy printed
Success: no issues found in 54 source files.
Count: 3510 collected = 2723 fast + 350 native + 437 agents. The floors rise from 2649 to 2723
(check-fast.sh) and from 334 to 350 (check-geometry.sh); check-agents.sh stays at 437. The 74
new fast tests are 59 plus 15, the 16 new native tests are the ones named above, and no agents
test was added. The web count is 45 pin tests plus 111 new tests.
The machine ran with a load average between 8 and 14 on 12 cores during these runs. The native gate
took 384.32 s (350 passed, 2773 deselected, 5 warnings in 384.32s (0:06:24)).
Not done
- The viewer shows one pose per export. It has no joint slider and no sweep.
- Only
minimum_clearancerequirements are read. - The viewer draws no verdict. The requirement minimum sits beside the gap and the page never says whether the gap meets it.
- The TypeScript mutation sweep is a scratch script, not a gate. The harness in
scripts/stays Python only.