sectorsync 2026.713.0

Fast-by-default facade for the SectorSync spatial replication middleware
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
//! Coherent Station-local product state.

use sectorsync_core::{
    command::{CommandQueueLimits, CommandQueues},
    component::{ComponentDescriptor, ComponentStore, ComponentStoreError},
    entity::{EntityRecord, EntityTags},
    handoff::HandoffTransfer,
    ids::{EntityHandle, EntityId, OwnerEpoch, PolicyId, StationId, Tick},
    spatial::{Bounds, GridSpec, Position3},
    spatial_index::{CellIndex, CellIndexUpdate, CellIndexUpdateScratch},
    station::{Station, StationConfig, StationError},
};

/// Capacity and topology configuration for [`StationRuntime`].
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct StationRuntimeConfig {
    /// Station authority and tick metadata.
    pub station: StationConfig,
    /// Station-local spatial grid.
    pub grid: GridSpec,
    /// Expected live entity records.
    pub entity_capacity: usize,
    /// Expected occupied spatial cells.
    pub occupied_cell_capacity: usize,
    /// Expected recycled-handle count retained for despawn churn.
    pub free_handle_capacity: usize,
    /// Optional bounded Station-local command queues.
    pub command_queue_limits: Option<CommandQueueLimits>,
}

impl StationRuntimeConfig {
    /// Creates configuration without preallocated entity or cell storage.
    pub const fn new(station: StationConfig, grid: GridSpec) -> Self {
        Self {
            station,
            grid,
            entity_capacity: 0,
            occupied_cell_capacity: 0,
            free_handle_capacity: 0,
            command_queue_limits: None,
        }
    }

    /// Preallocates the expected live entity and occupied-cell counts.
    #[must_use]
    pub const fn with_capacity(
        mut self,
        entity_capacity: usize,
        occupied_cell_capacity: usize,
    ) -> Self {
        self.entity_capacity = entity_capacity;
        self.occupied_cell_capacity = occupied_cell_capacity;
        self
    }

    /// Preallocates recycled handles for expected despawn churn.
    #[must_use]
    pub const fn with_free_handle_capacity(mut self, capacity: usize) -> Self {
        self.free_handle_capacity = capacity;
        self
    }

    /// Adds bounded Station-local command queues to the product state.
    #[must_use]
    pub const fn with_command_queues(mut self, limits: CommandQueueLimits) -> Self {
        self.command_queue_limits = Some(limits);
        self
    }
}

/// One authoritative entity spawn request.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SpawnEntity {
    /// Stable entity id.
    pub id: EntityId,
    /// Initial world position.
    pub position: Position3,
    /// Spatial bounds.
    pub bounds: Bounds,
    /// Compiled synchronization policy id.
    pub policy_id: PolicyId,
}

/// One read-only ghost upsert request.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GhostEntity {
    /// Stable entity id.
    pub id: EntityId,
    /// Latest replicated position.
    pub position: Position3,
    /// Spatial bounds.
    pub bounds: Bounds,
    /// Compiled synchronization policy id.
    pub policy_id: PolicyId,
    /// Authoritative Station.
    pub owner_station: StationId,
    /// Authoritative owner epoch.
    pub owner_epoch: OwnerEpoch,
    /// Tick after which the ghost may be discarded.
    pub expires_at: Tick,
}

/// Result of inserting or refreshing Station-local spatial state.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct StationEntityUpdateReport {
    /// Station-local entity handle.
    pub handle: EntityHandle,
    /// Spatial membership outcome.
    pub index_update: CellIndexUpdate,
}

impl SpawnEntity {
    /// Creates an authoritative spawn request.
    pub const fn new(
        id: EntityId,
        position: Position3,
        bounds: Bounds,
        policy_id: PolicyId,
    ) -> Self {
        Self {
            id,
            position,
            bounds,
            policy_id,
        }
    }
}

/// Result of moving one authoritative entity.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct StationMoveReport {
    /// Spatial membership update performed after the authoritative move.
    pub index_update: CellIndexUpdate,
}

/// Result of removing one Station-local entity and its middleware state.
#[derive(Clone, Debug, PartialEq)]
pub struct DespawnReport {
    /// Removed entity record.
    pub entity: EntityRecord,
    /// Whether the entity had spatial membership to remove.
    pub index_removed: bool,
    /// Component blobs removed with the entity.
    pub components_removed: usize,
}

/// Retained-capacity observation for [`StationRuntime`].
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct StationRuntimeCapacities {
    /// Station entity slots.
    pub station_entities: usize,
    /// Station entity-id lookup entries.
    pub station_id_index: usize,
    /// Station recycled handles.
    pub station_free_handles: usize,
    /// Spatial entity membership entries.
    pub indexed_entities: usize,
    /// Spatial occupied-cell entries.
    pub occupied_cells: usize,
    /// Reusable multi-cell update coordinates.
    pub index_update_cells: usize,
    /// Dense plus sparse component column slots.
    pub component_columns: usize,
    /// Ready command queue slots, or zero when queues are disabled.
    pub command_ready: usize,
    /// Barrier command queue slots, or zero when queues are disabled.
    pub command_barrier: usize,
}

/// Capacity change produced by explicit retained-storage reclamation.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct StationRuntimeReclaimReport {
    /// Capacities before reclamation.
    pub before: StationRuntimeCapacities,
    /// Capacities after reclamation.
    pub after: StationRuntimeCapacities,
}

/// Product-path Station operation error.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum StationRuntimeError {
    /// Authority or entity-state failure.
    Station(StationError),
    /// Component schema, codec, or payload failure.
    Component(ComponentStoreError),
}

impl core::fmt::Display for StationRuntimeError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Station(error) => write!(f, "{error}"),
            Self::Component(error) => write!(f, "{error}"),
        }
    }
}

impl std::error::Error for StationRuntimeError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Station(error) => Some(error),
            Self::Component(error) => Some(error),
        }
    }
}

impl From<StationError> for StationRuntimeError {
    fn from(error: StationError) -> Self {
        Self::Station(error)
    }
}

impl From<ComponentStoreError> for StationRuntimeError {
    fn from(error: ComponentStoreError) -> Self {
        Self::Component(error)
    }
}

/// Coherent owner of `SectorSync`'s normal Station-local middleware state.
#[derive(Clone, Debug)]
pub struct StationRuntime {
    station: Station,
    index: CellIndex,
    components: ComponentStore,
    commands: Option<CommandQueues>,
    index_update_scratch: CellIndexUpdateScratch,
}

impl StationRuntime {
    /// Creates empty Station-local state with explicit topology and capacities.
    pub fn new(config: StationRuntimeConfig) -> Self {
        let mut station = Station::with_capacity(config.station, config.entity_capacity);
        station.reserve_free_handles(config.free_handle_capacity);
        Self {
            station,
            index: CellIndex::with_capacity(
                config.grid,
                config.entity_capacity,
                config.occupied_cell_capacity,
            ),
            components: ComponentStore::default(),
            commands: config.command_queue_limits.map(CommandQueues::new),
            index_update_scratch: CellIndexUpdateScratch::default(),
        }
    }

    /// Returns Station authority and entity state.
    pub const fn station(&self) -> &Station {
        &self.station
    }

    /// Returns the Station-local spatial index.
    pub const fn index(&self) -> &CellIndex {
        &self.index
    }

    /// Returns the Station-local component store.
    pub const fn components(&self) -> &ComponentStore {
        &self.components
    }

    /// Returns configured Station-local command queues, if enabled.
    pub const fn command_queues(&self) -> Option<&CommandQueues> {
        self.commands.as_ref()
    }

    /// Returns mutable configured command queues, if enabled.
    pub const fn command_queues_mut(&mut self) -> Option<&mut CommandQueues> {
        self.commands.as_mut()
    }

    /// Returns current retained-capacity observations.
    pub fn retained_capacities(&self) -> StationRuntimeCapacities {
        StationRuntimeCapacities {
            station_entities: self.station.entity_capacity(),
            station_id_index: self.station.id_index_capacity(),
            station_free_handles: self.station.free_list_capacity(),
            indexed_entities: self.index.entity_capacity(),
            occupied_cells: self.index.occupied_cell_capacity(),
            index_update_cells: self.index_update_scratch.retained_cell_capacity(),
            component_columns: self.components.column_slots_capacity(),
            command_ready: self
                .commands
                .as_ref()
                .map_or(0, CommandQueues::total_ready_retained_capacity),
            command_barrier: self
                .commands
                .as_ref()
                .map_or(0, CommandQueues::barrier_buffer_retained_capacity),
        }
    }

    /// Releases unused retained storage without changing live middleware state.
    pub fn reclaim_retained_capacity(&mut self) -> StationRuntimeReclaimReport {
        let before = self.retained_capacities();
        self.station.reclaim_retained_capacity();
        self.index.reclaim_retained_capacity();
        self.index_update_scratch.reclaim_retained_capacity();
        self.components.reclaim_retained_capacity();
        if let Some(commands) = &mut self.commands {
            commands.reclaim_retained_capacity();
        }
        StationRuntimeReclaimReport {
            before,
            after: self.retained_capacities(),
        }
    }

    /// Advances the Station tick on the caller thread.
    pub fn advance_tick(&mut self) {
        self.station.advance_tick();
    }

    /// Spawns an authoritative entity and inserts its spatial membership.
    pub fn spawn_owned(&mut self, spawn: SpawnEntity) -> Result<EntityHandle, StationError> {
        let handle =
            self.station
                .spawn_owned(spawn.id, spawn.position, spawn.bounds, spawn.policy_id)?;
        let update = self.upsert_index(handle, spawn.position, spawn.bounds);
        debug_assert_eq!(update, CellIndexUpdate::Inserted);
        Ok(handle)
    }

    /// Inserts or refreshes a read-only ghost and its spatial membership.
    pub fn upsert_ghost(&mut self, ghost: GhostEntity) -> StationEntityUpdateReport {
        let handle = self.station.upsert_ghost(
            ghost.id,
            ghost.position,
            ghost.bounds,
            ghost.policy_id,
            ghost.owner_station,
            ghost.owner_epoch,
            ghost.expires_at,
        );
        let index_update = self.upsert_index(handle, ghost.position, ghost.bounds);
        StationEntityUpdateReport {
            handle,
            index_update,
        }
    }

    /// Moves an authoritative entity and updates spatial membership.
    pub fn move_owned(
        &mut self,
        handle: EntityHandle,
        position: Position3,
    ) -> Result<StationMoveReport, StationError> {
        self.station.move_owned(handle, position)?;
        let record = self
            .station
            .get(handle)
            .expect("successful move retains the authoritative entity");
        let (position, bounds) = (record.position, record.bounds);
        let index_update = self.upsert_index(handle, position, bounds);
        Ok(StationMoveReport { index_update })
    }

    /// Removes an entity, its spatial membership, and all component blobs.
    pub fn despawn(&mut self, handle: EntityHandle) -> Result<DespawnReport, StationError> {
        let entity = self.station.remove(handle)?;
        let index_removed = self.index.remove(handle);
        let components_removed = self.components.clear_entity(handle);
        Ok(DespawnReport {
            entity,
            index_removed,
            components_removed,
        })
    }

    /// Replaces authoritative tags through the Station authority guard.
    pub fn set_tags(&mut self, handle: EntityHandle, tags: EntityTags) -> Result<(), StationError> {
        self.station.set_tags(handle, tags)
    }

    /// Copies an opaque component value into retained storage after checking authority.
    pub fn set_component_blob(
        &mut self,
        descriptor: &ComponentDescriptor,
        handle: EntityHandle,
        version: u64,
        bytes: &[u8],
    ) -> Result<(), StationRuntimeError> {
        self.ensure_owned(handle)?;
        self.components
            .set_blob_from_slice(descriptor, handle, version, bytes)?;
        Ok(())
    }

    /// Prepares an outgoing two-phase handoff without changing ownership.
    pub fn prepare_outgoing_handoff(
        &self,
        entity_id: EntityId,
        target_station: StationId,
        target_owner_epoch: OwnerEpoch,
        source_ghost_expires_at: Tick,
    ) -> Result<HandoffTransfer, StationError> {
        self.station.prepare_outgoing_handoff(
            entity_id,
            target_station,
            target_owner_epoch,
            source_ghost_expires_at,
        )
    }

    /// Prewarms a target ghost and synchronizes its spatial membership.
    pub fn prewarm_handoff_ghost(
        &mut self,
        transfer: &HandoffTransfer,
    ) -> Result<StationEntityUpdateReport, StationError> {
        let handle = self.station.prewarm_handoff_ghost(transfer)?;
        let record = self
            .station
            .get(handle)
            .expect("successful handoff prewarm retains the ghost");
        let (position, bounds) = (record.position, record.bounds);
        let index_update = self.upsert_index(handle, position, bounds);
        Ok(StationEntityUpdateReport {
            handle,
            index_update,
        })
    }

    /// Commits an incoming owner handoff and synchronizes spatial membership.
    pub fn commit_incoming_handoff(
        &mut self,
        transfer: HandoffTransfer,
    ) -> Result<StationEntityUpdateReport, StationError> {
        let position = transfer.entity.position;
        let bounds = transfer.entity.bounds;
        let handle = self.station.commit_incoming_handoff(transfer)?;
        let index_update = self.upsert_index(handle, position, bounds);
        Ok(StationEntityUpdateReport {
            handle,
            index_update,
        })
    }

    /// Commits the source side of an owner handoff, retaining spatial ghost visibility.
    pub fn commit_outgoing_handoff(
        &mut self,
        transfer: &HandoffTransfer,
    ) -> Result<EntityHandle, StationError> {
        self.station.commit_outgoing_handoff(transfer)
    }

    /// Returns mutable low-level state for a custom integration.
    ///
    /// The caller must restore Station, spatial-index, component, and queue
    /// invariants before invoking another product-path operation.
    pub fn low_level_parts_mut(
        &mut self,
    ) -> (
        &mut Station,
        &mut CellIndex,
        &mut ComponentStore,
        Option<&mut CommandQueues>,
    ) {
        (
            &mut self.station,
            &mut self.index,
            &mut self.components,
            self.commands.as_mut(),
        )
    }

    fn upsert_index(
        &mut self,
        handle: EntityHandle,
        position: Position3,
        bounds: Bounds,
    ) -> CellIndexUpdate {
        self.index
            .upsert_with_scratch(handle, position, bounds, &mut self.index_update_scratch)
            .update
    }

    fn ensure_owned(&self, handle: EntityHandle) -> Result<(), StationError> {
        let record = self
            .station
            .get(handle)
            .ok_or(StationError::MissingEntityHandle(handle))?;
        if record.is_owned() {
            Ok(())
        } else {
            Err(StationError::NotOwner(record.id))
        }
    }

    /// Consumes the facade and returns its low-level state without conversion.
    pub fn into_parts(self) -> (Station, CellIndex, ComponentStore, Option<CommandQueues>) {
        (self.station, self.index, self.components, self.commands)
    }
}

#[cfg(test)]
mod tests {
    use sectorsync_core::{
        component::{ComponentMigrationMode, ComponentSyncMode},
        ids::{ComponentId, InstanceId, NodeId, StationId, Tick},
    };

    use super::*;

    fn config() -> StationRuntimeConfig {
        StationRuntimeConfig::new(
            StationConfig {
                station_id: StationId::new(1),
                node_id: NodeId::new(2),
                instance_id: InstanceId::new(3),
                tick_rate_hz: 20,
            },
            GridSpec::new(16.0).expect("valid grid"),
        )
        .with_capacity(8, 8)
    }

    fn config_for_station(station_id: u32) -> StationRuntimeConfig {
        StationRuntimeConfig::new(
            StationConfig {
                station_id: StationId::new(station_id),
                node_id: NodeId::new(2),
                instance_id: InstanceId::new(3),
                tick_rate_hz: 20,
            },
            GridSpec::new(16.0).expect("valid grid"),
        )
        .with_capacity(8, 8)
    }

    fn descriptor() -> ComponentDescriptor {
        ComponentDescriptor::sparse_blob(
            ComponentId::new(1),
            "health",
            ComponentSyncMode::Delta,
            ComponentMigrationMode::Copy,
            4,
        )
    }

    #[test]
    fn product_path_keeps_station_and_index_coherent() {
        let mut runtime = StationRuntime::new(config());
        let start = Position3::new(1.0, 2.0, 3.0);
        let handle = runtime
            .spawn_owned(SpawnEntity::new(
                EntityId::new(10),
                start,
                Bounds::Point,
                PolicyId::new(1),
            ))
            .expect("spawn should succeed");

        assert_eq!(
            runtime.station().get(handle).expect("entity").position,
            start
        );
        assert_eq!(runtime.index().query_sphere(start, 1.0), vec![handle]);

        let moved = Position3::new(33.0, 2.0, 3.0);
        let report = runtime
            .move_owned(handle, moved)
            .expect("move should succeed");
        assert_eq!(report.index_update, CellIndexUpdate::Relocated);
        assert!(runtime.index().query_sphere(start, 1.0).is_empty());
        assert_eq!(runtime.index().query_sphere(moved, 1.0), vec![handle]);

        let report = runtime.despawn(handle).expect("despawn should succeed");
        assert!(report.index_removed);
        assert_eq!(report.components_removed, 0);
        assert!(runtime.station().is_empty());
        assert!(runtime.index().query_sphere(moved, 1.0).is_empty());
    }

    #[test]
    fn failed_station_operations_do_not_mutate_the_index() {
        let mut runtime = StationRuntime::new(config());
        let missing = EntityHandle::new(99, 0);
        let error = runtime
            .move_owned(missing, Position3::new(1.0, 0.0, 0.0))
            .expect_err("missing move should fail");
        assert_eq!(error, StationError::MissingEntityHandle(missing));
        assert_eq!(runtime.index().entity_count(), 0);

        let error = runtime
            .despawn(missing)
            .expect_err("missing despawn should fail");
        assert_eq!(error, StationError::MissingEntityHandle(missing));
        assert_eq!(runtime.index().entity_count(), 0);
    }

    #[test]
    fn component_writes_require_authority_and_despawn_clears_storage() {
        let mut runtime = StationRuntime::new(config());
        let position = Position3::new(1.0, 0.0, 1.0);
        let owned = runtime
            .spawn_owned(SpawnEntity::new(
                EntityId::new(1),
                position,
                Bounds::Point,
                PolicyId::new(1),
            ))
            .expect("owned");
        runtime
            .set_component_blob(&descriptor(), owned, 1, &[1, 2, 3, 4])
            .expect("owned component write");

        let ghost = runtime.upsert_ghost(GhostEntity {
            id: EntityId::new(2),
            position,
            bounds: Bounds::Point,
            policy_id: PolicyId::new(1),
            owner_station: StationId::new(9),
            owner_epoch: OwnerEpoch::new(1),
            expires_at: Tick::new(10),
        });
        let error = runtime
            .set_component_blob(&descriptor(), ghost.handle, 1, &[1, 2, 3, 4])
            .expect_err("ghost component write must fail");
        assert_eq!(
            error,
            StationRuntimeError::Station(StationError::NotOwner(EntityId::new(2)))
        );

        let report = runtime.despawn(owned).expect("despawn");
        assert_eq!(report.components_removed, 1);
        assert!(
            runtime
                .components()
                .get_blob(ComponentId::new(1), owned)
                .is_none()
        );
    }

    #[test]
    fn handoff_keeps_source_and_target_spatial_membership() {
        let mut source = StationRuntime::new(config_for_station(1));
        let mut target = StationRuntime::new(config_for_station(2));
        let position = Position3::new(20.0, 0.0, 20.0);
        source
            .spawn_owned(SpawnEntity::new(
                EntityId::new(7),
                position,
                Bounds::Point,
                PolicyId::new(1),
            ))
            .expect("source owner");
        let transfer = source
            .prepare_outgoing_handoff(
                EntityId::new(7),
                StationId::new(2),
                OwnerEpoch::new(1),
                Tick::new(10),
            )
            .expect("prepare");

        target
            .prewarm_handoff_ghost(&transfer)
            .expect("target prewarm");
        let target_owner = target
            .commit_incoming_handoff(transfer.clone())
            .expect("target commit");
        let source_ghost = source
            .commit_outgoing_handoff(&transfer)
            .expect("source commit");

        assert!(
            target
                .station()
                .get(target_owner.handle)
                .expect("target")
                .is_owned()
        );
        assert!(
            !source
                .station()
                .get(source_ghost)
                .expect("source")
                .is_owned()
        );
        assert_eq!(
            target.index().query_sphere(position, 1.0),
            vec![target_owner.handle]
        );
        assert_eq!(
            source.index().query_sphere(position, 1.0),
            vec![source_ghost]
        );
    }

    #[test]
    fn optional_commands_and_reclaim_are_explicit() {
        let config =
            config()
                .with_free_handle_capacity(32)
                .with_command_queues(CommandQueueLimits {
                    high: 4,
                    normal: 8,
                    low: 4,
                });
        let mut runtime = StationRuntime::new(config);
        assert!(runtime.command_queues().is_some());
        let before = runtime.retained_capacities();
        assert!(before.station_entities >= 8);
        assert!(before.station_free_handles >= 32);

        let report = runtime.reclaim_retained_capacity();

        assert_eq!(report.before, before);
        assert!(report.after.station_entities <= report.before.station_entities);
        assert!(report.after.station_free_handles <= report.before.station_free_handles);
        assert!(runtime.command_queues_mut().is_some());
    }
}