fix(battle-node): MsgEnvelope rejects reserved Body keys + complete ReceiveNodeResultCode

ToJson now throws ArgumentException when a Body key collides with a reserved
envelope field (uri/viewerId/uuid/bid/try/cat/pubSeq/playSeq); FromJson reuses
the same shared ReservedEnvelopeKeys HashSet. ReceiveNodeResultCode expanded
from 9 to 31 codes to mirror the full enums.md catalog. Two regression tests
added for the collision guard and PascalCase uri serialization.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-31 21:55:11 -04:00
parent 383044dd8f
commit 4cc8b3c01c
3 changed files with 79 additions and 5 deletions

View File

@@ -63,4 +63,42 @@ public class MsgEnvelopeTests
Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.PlayActions));
Assert.That(env.Cat, Is.EqualTo(EmitCategory.Battle));
}
[Test]
public void ToJson_BodyContainingReservedKey_Throws()
{
var env = new MsgEnvelope(
Uri: NetworkBattleUri.Loaded,
ViewerId: 1,
Uuid: "u",
Bid: null,
Try: 0,
Cat: EmitCategory.Battle,
PubSeq: null,
PlaySeq: null,
Body: new Dictionary<string, object?> { ["uri"] = "Injected" });
var ex = Assert.Throws<ArgumentException>(() => MsgEnvelope.ToJson(env));
Assert.That(ex!.Message, Does.Contain("uri"));
}
[Test]
public void ToJson_UriField_SerializesAsExactPascalCaseMemberName()
{
var env = new MsgEnvelope(
Uri: NetworkBattleUri.PlayActions,
ViewerId: 1,
Uuid: "u",
Bid: null,
Try: 0,
Cat: EmitCategory.Battle,
PubSeq: null,
PlaySeq: null,
Body: new Dictionary<string, object?>());
var json = MsgEnvelope.ToJson(env);
// Wire form must be PascalCase exactly — not "playActions", not "play_actions".
Assert.That(json, Does.Contain("\"uri\":\"PlayActions\""));
}
}