refactor(battle-node): switch MsgEnvelope.Body to IMsgBody, migrate all sites

This commit is contained in:
gamer147
2026-06-01 10:40:09 -04:00
parent 118be92dc5
commit 5ee270eb16
11 changed files with 183 additions and 231 deletions

View File

@@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using NUnit.Framework;
using SVSim.BattleNode.Protocol;
using SVSim.BattleNode.Protocol.Bodies;
using SVSim.BattleNode.Sessions;
namespace SVSim.UnitTests.BattleNode.Sessions;
@@ -17,7 +18,7 @@ public class BattleSessionDispatchTests
private static MsgEnvelope NewEnvelope(NetworkBattleUri uri) =>
new(uri, ViewerId: 1, Uuid: "u", Bid: null, Try: 0, Cat: EmitCategory.Battle,
PubSeq: null, PlaySeq: null, Body: new Dictionary<string, object?>());
PubSeq: null, PlaySeq: null, Body: new RawBody(new Dictionary<string, object?>()));
[Test]
public void InitNetwork_PushesAckOnly_TransitionsToAwaitingInitBattle()
@@ -58,18 +59,22 @@ public class BattleSessionDispatchTests
s.ComputeResponses(NewEnvelope(NetworkBattleUri.InitNetwork));
s.ComputeResponses(NewEnvelope(NetworkBattleUri.InitBattle));
s.ComputeResponses(NewEnvelope(NetworkBattleUri.Loaded));
var swapEnv = NewEnvelope(NetworkBattleUri.Swap);
// Simulate the client's Swap{idxList:[2]}: the dict shape produced by MsgEnvelope.FromJson
// (a List<object?> of boxed long values).
swapEnv.Body["idxList"] = new List<object?> { 2L };
// (a List<object?> of boxed long values), wrapped in a RawBody as the inbound type.
var swapEnv = new MsgEnvelope(
NetworkBattleUri.Swap, ViewerId: 1, Uuid: "u", Bid: null, Try: 0,
Cat: EmitCategory.Battle, PubSeq: null, PlaySeq: null,
Body: new RawBody(new Dictionary<string, object?>
{
["idxList"] = new List<object?> { 2L },
}));
var responses = s.ComputeResponses(swapEnv);
var swapBody = responses[0].Envelope.Body;
var self = (List<object?>)swapBody["self"]!;
Assert.That(((Dictionary<string, object?>)self[0]!)["idx"], Is.EqualTo(1));
Assert.That(((Dictionary<string, object?>)self[1]!)["idx"], Is.EqualTo(4)); // swapped — fresh deck idx
Assert.That(((Dictionary<string, object?>)self[2]!)["idx"], Is.EqualTo(3));
var swapBody = (SwapResponseBody)responses[0].Envelope.Body;
Assert.That(swapBody.Self[0].Idx, Is.EqualTo(1));
Assert.That(swapBody.Self[1].Idx, Is.EqualTo(4)); // swapped — fresh deck idx
Assert.That(swapBody.Self[2].Idx, Is.EqualTo(3));
}
[Test]