⚠️ Refactor bin/arcane_swarm/main.rs: extract BackendRuntime trait + impls (A-1)#42
Open
⚠️ Refactor bin/arcane_swarm/main.rs: extract BackendRuntime trait + impls (A-1)#42
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #38
Extracts
BackendRuntimetrait +SpacetimeRuntime/ArcaneRuntimeimpls frommain.rsintoruntime.rs, introducesSharedHandlesto reduce Arc cloning, and further extracts the control-mode orchestration intocontrol_mode.rs.Changes
BackendRuntimetrait +SpacetimeRuntime+ArcaneRuntime+SharedHandlesstruct + 8 unit testsrun_control_mode,handle_control_connection, andspawn_driver_samplerfrommain.rs+ 2 unit testshandles_sharedfield toControlSpawnKitforSharedHandleswiring; suppressed dead_code onPlayerLoopSharedSharedHandles
Introduced
SharedHandlesstruct grouping allArc-wrapped fields plus copy fields. Eachspawn_playernow performs oneSharedHandles::clone()instead of 6+ individualArc::clone()calls.Tests
10 new unit tests across
runtime.rs(8) andcontrol_mode.rs(2):spacetimedb_name_is_correct/arcane_name_is_correctspacetimedb_spawn_player_completes_when_stop_flag_set(tokio async test)spacetimedb_spawn_read_returns_none/arcane_spawn_read_returns_nonespacetimedb_snapshot_cache_counters_returns_zero/arcane_snapshot_cache_counters_returns_cache_stateshared_handles_clone_produces_pointer_equal_arcsspawn_driver_sampler_does_not_crashhandle_control_connection_rejects_empty_commandAcceptance Checklist
main.rsis < 350 lines (201 lines)BackendRuntimetrait + impls live inruntime.rscargo build+cargo testpass (12 tests, 0 warnings)cargo fmt --all -- --checkcleanRelated
architecture:swarm-main-too-large