fix(battle-node): collision-safe battle-id registration + viewer eviction

RegisterPending → TryRegisterPending (TryAdd instead of indexer) so
battle-id collisions return false instead of silently evicting a live
battle. MatchingBridge retries with fresh IDs on collision (max 5).

Before registering, EvictStaleForViewer removes any stale pending
battle the viewer left behind, enforcing the one-pending-per-viewer
invariant that was previously comment-asserted.

Store tests switched to per-test local stores to fix a race under
the assembly-wide ParallelScope.All.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-04 22:13:20 -04:00
parent c6fb411861
commit 564b1d678f
5 changed files with 60 additions and 27 deletions

View File

@@ -2,8 +2,10 @@ namespace SVSim.BattleNode.Sessions;
public interface IBattleSessionStore
{
/// <summary>Register a battle minted by the matching bridge, awaiting a WS connect.</summary>
void RegisterPending(PendingBattle battle);
/// <summary>Register a battle minted by the matching bridge, awaiting a WS connect.
/// Returns false if a battle with the same id is already pending (caller should retry
/// with a fresh id).</summary>
bool TryRegisterPending(PendingBattle battle);
/// <summary>Look up the pending battle. Returns null if not present.</summary>
PendingBattle? TryGetPending(string battleId);