Skip to content

⚠️ Refactor bin/arcane_swarm/main.rs: extract BackendRuntime trait + impls (A-1)#42

Open
martinjms wants to merge 2 commits intomainfrom
refactor/extract-backend-runtime-38
Open

⚠️ Refactor bin/arcane_swarm/main.rs: extract BackendRuntime trait + impls (A-1)#42
martinjms wants to merge 2 commits intomainfrom
refactor/extract-backend-runtime-38

Conversation

@martinjms
Copy link
Copy Markdown
Collaborator

@martinjms martinjms commented May 2, 2026

Summary

Closes #38

Extracts BackendRuntime trait + SpacetimeRuntime/ArcaneRuntime impls from main.rs into runtime.rs, introduces SharedHandles to reduce Arc cloning, and further extracts the control-mode orchestration into control_mode.rs.

Changes

  • runtime.rsBackendRuntime trait + SpacetimeRuntime + ArcaneRuntime + SharedHandles struct + 8 unit tests
  • control_mode.rs (new) — Extracted run_control_mode, handle_control_connection, and spawn_driver_sampler from main.rs + 2 unit tests
  • main.rs — Slimmed from 713→201 lines (was 602 after previous extraction)
  • spawn_context.rs — Added handles_shared field to ControlSpawnKit for SharedHandles wiring; suppressed dead_code on PlayerLoopShared

SharedHandles

Introduced SharedHandles struct grouping all Arc-wrapped fields plus copy fields. Each spawn_player now performs one SharedHandles::clone() instead of 6+ individual Arc::clone() calls.

Tests

10 new unit tests across runtime.rs (8) and control_mode.rs (2):

  • spacetimedb_name_is_correct / arcane_name_is_correct
  • spacetimedb_spawn_player_completes_when_stop_flag_set (tokio async test)
  • spacetimedb_spawn_read_returns_none / arcane_spawn_read_returns_none
  • spacetimedb_snapshot_cache_counters_returns_zero / arcane_snapshot_cache_counters_returns_cache_state
  • shared_handles_clone_produces_pointer_equal_arcs
  • spawn_driver_sampler_does_not_crash
  • handle_control_connection_rejects_empty_command

Acceptance Checklist

  • main.rs is < 350 lines (201 lines)
  • BackendRuntime trait + impls live in runtime.rs
  • At least 4 unit tests cover the runtime module (10 tests)
  • cargo build + cargo test pass (12 tests, 0 warnings)
  • cargo fmt --all -- --check clean

Related

martinjms added 2 commits May 2, 2026 19:04
… runtime module

Move BackendRuntime trait, SpacetimeRuntime, and ArcaneRuntime from
713-line main.rs into a dedicated runtime.rs module (main.rs → ~600 lines).

Introduce SharedHandles struct to reduce repeated Arc clones inside
spawn_player from 6 individual calls to 1 struct clone per spawn.

Add 8 unit tests covering both backends: name correctness, spawn_read
returns None, snapshot_cache counters, spawn_player lifecycle
completion, and SharedHandles pointer equality.

Update spawn_context.rs ControlSpawnKit to carry both &PlayerLoopShared
(for spawn_read) and &SharedHandles (for spawn_player).

Closes #38
…to 201 lines

- Extract run_control_mode + handle_control_connection into control_mode.rs
- Extract spawn_driver_sampler helper function
- Add control_mode module-level unit tests (2 new tests)
- Fix SharedHandles wiring in ControlSpawnKit
- Suppress dead_code warning on PlayerLoopShared fields
- main.rs: 201 lines (was 602) — under the 350-line acceptance target
- All 12 tests pass, cargo fmt clean, zero warnings
@martinjms martinjms changed the title ⚠️ refactor: extract BackendRuntime trait + impls into runtime module (A-1) ⚠️ Refactor bin/arcane_swarm/main.rs: extract BackendRuntime trait + impls (A-1) May 2, 2026
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.

⚠️ Refactor bin/arcane_swarm/main.rs: extract BackendRuntime trait + impls (A-1)

1 participant