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 with pose.placements, measures the requirement pair with measure.measure, and hands the placed solids to meshes.export_meshes with a pose block of "kind": "assembly".
  • src/tolerance_arena/assembly/cli.py: the export-meshes subcommand with --sidecar or --family, --q, --delta-mm, --output, repeatable --param NAME=VALUE, --tessellation-mm and --json.
  • src/tolerance_arena/meshes.py: two changes to the shared writer, described under "Defects found in code that was already merged".
  • web/: parseManifest.ts reads the assembly pose block; lib/poseDirectory.ts maps ?pose=NAME to data/NAME; scene/assemblePose.ts builds the scene from the loaded pieces with one label per part and the gap marker; panels/AssemblyPanels.tsx shows the parts, the joint coordinate and the measured gap; scene/partTokens.ts and lib/formatNumber.ts are small helpers.
  • Sample data under web/public/data/: family-hinged-flap-post/ (family hinged-flap-post, q 45 deg, delta -1.2 mm) and step-hinge/ (the STEP sidecar fixtures/assembly/hinge.assembly.yaml, q 85 deg, delta -0.5 mm). The pin sample web/public/data/pose/ is untouched.
  • Tests: tests/assembly/test_assembly_export.py (59, no kernel), tests/test_meshes_empty_file.py (15, no kernel) and tests/assembly/test_assembly_export_native.py (16, marker native), with the GLB reader tests/assembly/assembly_glb.py. On the web side assembly-manifest.test.ts (53), assemble-pose.test.ts (21), pose-directory.test.ts (21), assembly-viewer.test.tsx (12) and format-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, and node_modules added to the names the tree copy skips (the copy of a clone with an installed web/node_modules was 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.py before export.py existed: E ImportError: cannot import name 'export' from 'tolerance_arena.assembly' and 2 errors in 5.70s.
  • tests/test_meshes_empty_file.py before the no-vertex guard: 10 failed, 1 passed in 1.89s, each failure Failed: DID NOT RAISE MeshExportError. After the guard: 15 passed.
  • The native test test_a_solid_read_from_a_step_file_exports_a_mesh before the parent fix: 1 failed, 1 passed, 14 deselected in 4.77s.

Web:

  • npx --no-install vitest run tests/assembly-manifest.test.ts before 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.tsx and format-number.test.ts were 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

  1. A glTF file with no mesh. build123d 0.13.0 export_gltf skips a root shape that has a parent and still writes a valid container. A solid read from a STEP file is a child of a Compound, so arena 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_meshes now 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 no POSITION accessor that holds a vertex is MeshExportError("export_failed", "<name>: the glTF file holds no mesh"). The unit tests of that check are in tests/test_meshes_empty_file.py, the real case is test_a_solid_read_from_a_step_file_exports_a_mesh. AX10 and AX11 kill the two changes.
  2. The issue 49 viewer converted each mesh twice. meshes.py exports a piece from a copy at C * L * C^-1, so the node in the file already holds C * L_cad in metres. The viewer then applied the manifest matrix again through placePiece. 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). placeExportedPiece puts 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.png shows the pins upright from the same manifest and files. placePiece and 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, runs assemblePose and 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_view matrix at the top and the same matrix in each piece; each sha256 equals 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
IdsGuard
AX01, AX02_check_parts: a part id with two dots, a part that is not a CAD shape
AX03, AX06, AX07the pose block: witnesses are null on overlap, the witnesses keep their order, the unit follows the joint type
AX04, AX05, AX08, AX09export_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 AX17meshes.py: the no-vertex check (AX10, AX12 to AX17) and the re-wrap of a shape that has a parent (AX11)
AX18 to AX21the required source, --q, --delta-mm and --output
AX22, AX23the 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 AX30the refusal tuple: AssemblyError, NativeQueryError, MeshExportError, OSError
AX31 to AX34the overlap note, the planted-parameter note, the scope statement, the tessellation option
AX35, AX36the 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:

IdFileWhat the edit doesResult
T01web/src/manifest/parseManifest.tsa reversed range is acceptedsurvived the first run; a test was added; killed on the rerun
T02web/src/manifest/parseManifest.tsa value below its range is acceptedkilled
T03web/src/manifest/parseManifest.tsa value above its range is acceptedkilled
T04web/src/manifest/parseManifest.tsthe lower end of a range is refusedkilled
T05web/src/manifest/parseManifest.tsthe upper end of a range is refusedkilled
T06web/src/manifest/parseManifest.tsa joint in the wrong unit is acceptedkilled
T07web/src/manifest/parseManifest.tsa minimum of zero is acceptedkilled
T08web/src/manifest/parseManifest.tsone part named twice in the requirement is acceptedkilled
T09web/src/manifest/parseManifest.tsa negative distance is acceptedsurvived the first run; a test was added; killed on the rerun
T10web/src/manifest/parseManifest.tsan overlap with a distance is acceptedkilled
T11web/src/manifest/parseManifest.tsan overlap with witness points is acceptedkilled
T12web/src/manifest/parseManifest.tswitness points that do not span the distance are acceptedkilled
T13web/src/manifest/parseManifest.tsthe witness tolerance is a thousand times widerkilled
T14web/src/manifest/parseManifest.tsan overlap flag that is text is acceptedsurvived the first run; a test was added; killed on the rerun
T15web/src/manifest/parseManifest.tsan unknown requirement type is acceptedkilled
T16web/src/manifest/parseManifest.tsan empty id is acceptedkilled
T17web/src/manifest/parseManifest.tsa number that is not finite is acceptedkilled
T18web/src/manifest/parseManifest.tsa moving part with no piece is acceptedkilled
T19web/src/manifest/parseManifest.tsa fixed part with no piece is acceptedkilled
T20web/src/manifest/parseManifest.tsa deviation part with no piece is acceptedkilled
T21web/src/manifest/parseManifest.tsan assembly pose needs a pin and an obstaclekilled
T22web/src/manifest/parseManifest.tsan assembly pose needs no piecekilled
T23web/src/manifest/parseManifest.tsa requirement part with no piece is acceptedsurvived the first run; a test was added; killed on the rerun
T24web/src/lib/poseDirectory.tsa pose name that leaves the data folder is acceptedkilled
T25web/src/lib/poseDirectory.tsa pose name may start with a dot or a dashkilled
T26web/src/lib/poseDirectory.tsa pose name may have 65 characterskilled
T27web/src/lib/poseDirectory.tsa pose name of 64 characters is refusedkilled
T28web/src/lib/poseDirectory.tsno pose parameter reads data/nullkilled
T29web/src/lib/poseDirectory.tsthe default directory moveskilled
T30web/src/lib/formatNumber.tsthe display shows twelve digitskilled
T31web/src/lib/formatNumber.tsthe display shows six digitskilled
T32web/src/scene/assemblePose.tsa label sits inside its partkilled
T33web/src/scene/assemblePose.tsa zero-length gap draws a marker with a NaN directionkilled
T34web/src/scene/assemblePose.tsthe gap ends are swappedkilled
T35web/src/scene/assemblePose.tsa piece with no object is skippedkilled
T36web/src/scene/assemblePose.tsa piece keeps its loaded materialkilled
T37web/src/scene/assemblePose.tsa label is not in the scenekilled
T38web/src/scene/assemblePose.tsthe gap marker is not in the scenekilled
T39web/src/scene/assemblePose.tsthe gap marker has no thicknesskilled
T40web/src/scene/assemblePose.tsthe gap marker is as large as the partskilled
T41web/src/scene/partTokens.tsthe fifth part has no colourkilled
T42web/src/scene/partTokens.tsan assembly uses the pin colours by namekilled
T43web/src/panels/AssemblyPanels.tsxthe requirement position is zero basedkilled
T44web/src/panels/AssemblyPanels.tsxthe first requirement part has no rolekilled
T45web/src/panels/AssemblyPanels.tsxan overlap is not said on screenkilled
T46web/src/panels/AssemblyPanels.tsxthe fixed part has no rolekilled
T47web/src/scene/placePiece.tsthe exported piece is converted a second timekilled

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.

FileShows
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.pngthe 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_clearance requirements 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.