Commit ffe80a7
authored
* refactor(geometry,processing,wasm): split four modules back under budget, and collapse three hand-written clones (#3199 follow-up)
#3210 raised four allowlist budgets to land the representation-item work.
AGENTS.md says prefer splitting to allowlisting, so this pays that back: every
budget goes DOWN, none up, each exactly its file's line count with no slack, and
no new file needs a row.
rust/geometry/src/mesh.rs 1543 -> 1012 tests to mesh_tests.rs
rust/processing/src/element.rs 966 -> 812 colour to element/element_color.rs
rust/wasm-bindings/src/zero_copy/mesh.rs 764 -> 754 three clones collapsed
rust/geometry/src/router/layers.rs 686 -> 637 tests to layers_tests.rs
The two test moves use the house `#[cfg(test)] #[path = "<name>_tests.rs"]`
pattern; layers.rs already used it for `layers_cycle_tests.rs`. Test-fn counts
are unchanged (24 and 4) and the moved blocks are byte-identical modulo the
licence header.
`element_color.rs` is a real seam: colour and material-name resolution for an
element's sub-meshes is a pure function of (geometry id, style map) with its own
bounded walk, and the mesh production it serves stays in element.rs.
MeshDataJs had THREE hand-written 21-field copies -- `get`, `takeMesh`, and
`MeshCollection`'s own `Clone` -- which that file's allowlist row names as a
cost in as many words. Deriving `Clone` reduces them to `.cloned()`, `mem::take`
and `.clone()`.
Be precise about what that buys, because the obvious claim is wrong: an
exhaustive struct literal that OMITS a field is a COMPILE error, so those
literals were never silently lossy. What they were is three places to edit for
one field. `Default` is what makes `takeMesh` a one-liner, and it also makes
`..Default::default()` legal, which WOULD be lossy. One literal remains, in
`new` (spelled `Self { .. }`, which is why grepping `MeshDataJs {` misses it),
and it must stay exhaustive.
`Default` is hand-written, not derived, because the derive DISAGREED with `new`:
it gives `false` for the texture repeat flags where `new` sets `true`, so a
`default()`-built mesh plus setters would clamp a texture that should tile.
`default_agrees_with_new_on_the_fields_new_does_not_take` pins that, and it has
teeth -- flipping one flag in the impl fails it with the intended message. It
runs natively in `cargo test --workspace`, which the wasm crate is part of.
The second `takeMesh` on one index now reports a default mesh rather than a
metadata-bearing husk. That is an observable change on a published package, so
it carries a patch changeset for `@ifc-lite/wasm` rather than riding in silently
-- the earlier draft claimed "no published API changes", which conflated the
type surface with the behaviour. The contract test anticipated the change ("a
switch to `mem::take` on the whole struct would change what a second call
reports, and this suite should be the thing that notices") and permitted both
answers; that permissive form is spent, so it pins the exact behaviour now. The
only in-repo caller, geometry.worker.ts, takes each index exactly once.
Gates, all run here: `cargo test --workspace` 172 binaries 0 failures; clippy
`--exclude ifc-lite-wasm --all-targets -D warnings` clean; `pnpm typecheck`;
`pnpm lint`; `pnpm test` 94/94; `check:api-surface` matches; docs regions clean;
`pnpm test:wasm-contract` 73 passed 0 failed WITH fixtures present, since it
exits 0 silently without them; module-size ratchet 5/5.
Ten things review caught across three rounds. Recording them because the pattern
in most is one thing: a check that could not observe the case it was trusted for.
Removing a `pub(crate) use` only `#[cfg(test)]` consumed left `cargo build`
green and broke the test build -- the trap AGENTS.md names.
Re-adding it failed clippy as unused in the non-test build.
Importing the constant from core in the test then SHADOWED the glob, making
the assertion compare it with itself. Now read back through element_color.rs;
mutation-proved a private copy there fails it.
The third clone site survived a draft that claimed the mechanism was gone.
"Removes every `MeshDataJs { .. }` literal" was false: `new` spells one
`Self { .. }`, invisible to that grep.
`#[derive(Default)]` silently disagreed with `new`.
The `takeMesh` behaviour change needed a changeset.
`element.rs`'s budget carried 4 lines of unearned slack.
Two stale pointers to `element.rs` for a constant that moved.
Two contract-test comments describing a divergence this change removes.
* docs(wasm): name the JS-visible property in the takeMesh contract
CodeRabbit on #3235, minor and correct. The doc said `express_id`, the Rust
field name. This text is generated into `packages/wasm/pkg/ifc-lite.d.ts`, whose
audience is JS callers, and they read `expressId` — so the declaration described
a property they cannot access.
Fixed in the source and regenerated via scripts/build-wasm.sh rather than editing
the generated output, which AGENTS.md forbids.
1 parent 180a896 commit ffe80a7
18 files changed
Lines changed: 958 additions & 846 deletions
File tree
- .changeset
- packages/wasm/pkg
- rust
- geometry/src
- router
- processing
- src
- element
- processor
- symbolic
- tests
- wasm-bindings/src/zero_copy
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
891 | 891 | | |
892 | 892 | | |
893 | 893 | | |
894 | | - | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
895 | 898 | | |
896 | 899 | | |
897 | 900 | | |
| |||
1015 | 1018 | | |
1016 | 1019 | | |
1017 | 1020 | | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
1018 | 1042 | | |
1019 | 1043 | | |
1020 | 1044 | | |
| |||
0 commit comments