Skip to content

refactor(state): split tests.rs monolith into per-concern files#486

Merged
intendednull merged 1 commit into
claude/friendly-maxwell-0olkefrom
auto-fix/issue-263-state-tests-split
Apr 29, 2026
Merged

refactor(state): split tests.rs monolith into per-concern files#486
intendednull merged 1 commit into
claude/friendly-maxwell-0olkefrom
auto-fix/issue-263-state-tests-split

Conversation

@intendednull
Copy link
Copy Markdown
Owner

what

crates/state/src/tests.rs was 4714 LOC, 117 #[test] fns, one file. Issue #263 say split by concern. Did that.

buckets

file tests LOC
tests/dag.rs 17 708
tests/materialize.rs 54 1916
tests/permissions.rs 31 1087
tests/stress.rs 7 387
tests/sync.rs 2 247
tests/voting.rs 6 457

Sum 117. Pre-split file 4714 LOC monolith → 6 files biggest 1916 LOC. Below materialize.rs source (1625 LOC), within reach.

sixth bucket

Issue suggest five buckets. Stress tests no clean fit (large-DAG scale, performance bounds, perf-sensitive). CLAUDE.md guidance per dispatch says add sixth bucket rather than force. Named stress.rs, theme obvious.

wiring

#[path = "tests/<file>.rs"] mod tests_<bucket>; in crates/state/src/lib.rs, matching crates/client/src/lib.rs:49-55 pattern issue called out. Removed tests.rs.

helpers

Each bucket has its own copy of genesis_kind, test_dag, do_emit plus the original 5-line use block. #![allow(unused_imports, dead_code)] at top of each file so subset-using buckets compile clean. Tradeoff: 30 LOC of duplicated boilerplate per file vs introducing a tests/common.rs helper module gated by another #[path]. Issue scope = mechanical split, no new abstraction. Picked duplication.

verify

  • cargo test -p willow-state227 passed (matches pre-split: 227 → 227, zero drift)
  • cargo fmt --check → clean
  • cargo clippy --workspace --all-targets -- -D warnings → clean
  • cargo check --target wasm32-unknown-unknown -p willow-state → clean

Sub-PR base = master batch branch, not main → CI workflows scoped branches: [main] not fire. Local gate green = merge gate.

Refs #263

https://claude.ai/code/session_01FHLLfYeh9P9FP7Y47wu9We


Generated by Claude Code

tests.rs grew to 4714 LOC, 117 #[test] fns, single file. Adding new
test = scroll monolith. Split by concern matching #[path] pattern from
crates/client/src/lib.rs:49-55:

  tests/dag.rs          — 17 tests (insert, equivocation, topo sort, ManagedDag, pending buffer)
  tests/materialize.rs  — 54 tests (channels, messages, profiles, mute, pin, ephemeral, idempotency)
  tests/permissions.rs  — 31 tests (grant/revoke, check_permission, kick, member edits, set_permission round-trip)
  tests/stress.rs       — 7 tests (1000 events, 100 authors, sort perf, governance scale)
  tests/sync.rs         — 2 tests (joining peer + grant batches)
  tests/voting.rs       — 6 tests (proposal/vote ordering, multi-admin kick majority)

All 117 tests preserved verbatim — only relocated. Test count before/after:
227 -> 227 (cargo test -p willow-state).

Sixth bucket (stress.rs) added since the issue's five suggested buckets
don't cleanly absorb the scale tests; CLAUDE.md guidance says add a
sixth file rather than force-fit. Common helpers (genesis_kind, test_dag,
do_emit) duplicated per-file with #![allow(unused_imports, dead_code)]
so each bucket compiles standalone — every bucket only references a
subset, but factoring them into a shared helper module would have
required a load-bearing #[path]-glued helpers.rs that the issue's
mechanical-split scope didn't ask for.

Refs #263

https://claude.ai/code/session_01FHLLfYeh9P9FP7Y47wu9We
@intendednull intendednull merged commit eaf0b20 into claude/friendly-maxwell-0olke Apr 29, 2026
intendednull added a commit that referenced this pull request Apr 29, 2026
tests.rs grew to 4714 LOC, 117 #[test] fns, single file. Adding new
test = scroll monolith. Split by concern matching #[path] pattern from
crates/client/src/lib.rs:49-55:

  tests/dag.rs          — 17 tests (insert, equivocation, topo sort, ManagedDag, pending buffer)
  tests/materialize.rs  — 54 tests (channels, messages, profiles, mute, pin, ephemeral, idempotency)
  tests/permissions.rs  — 31 tests (grant/revoke, check_permission, kick, member edits, set_permission round-trip)
  tests/stress.rs       — 7 tests (1000 events, 100 authors, sort perf, governance scale)
  tests/sync.rs         — 2 tests (joining peer + grant batches)
  tests/voting.rs       — 6 tests (proposal/vote ordering, multi-admin kick majority)

All 117 tests preserved verbatim — only relocated. Test count before/after:
227 -> 227 (cargo test -p willow-state).

Sixth bucket (stress.rs) added since the issue's five suggested buckets
don't cleanly absorb the scale tests; CLAUDE.md guidance says add a
sixth file rather than force-fit. Common helpers (genesis_kind, test_dag,
do_emit) duplicated per-file with #![allow(unused_imports, dead_code)]
so each bucket compiles standalone — every bucket only references a
subset, but factoring them into a shared helper module would have
required a load-bearing #[path]-glued helpers.rs that the issue's
mechanical-split scope didn't ask for.

Refs #263

https://claude.ai/code/session_01FHLLfYeh9P9FP7Y47wu9We

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants