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:
@@ -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\""));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user