refactor(battle-node): rename ScriptedLifecycle->ServerBattleFrames, ScriptedProfiles->BattleFrameDefaults
Pure rename. These hold the shared server-authored frame builders used by every battle mode's handshake/mulligan dispatch — the 'Scripted' name was a historical accident that hid the PvP/Bot crossover. No behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -34,7 +34,7 @@ namespace SVSim.UnitTests.BattleNode.Integration;
|
||||
/// <para><b>Coverage:</b> a two-client PvP session emits all ten server-authored URIs
|
||||
/// (<c>InitNetwork, Matched, BattleStart, Deal, Swap, Ready, TurnStart, TurnEnd, Judge,
|
||||
/// BattleFinish</c>). PvP authors the handshake/mulligan frames through the same shared
|
||||
/// <see cref="SVSim.BattleNode.Lifecycle.ScriptedLifecycle"/> builders, and the turn cycle
|
||||
/// <see cref="SVSim.BattleNode.Lifecycle.ServerBattleFrames"/> builders, and the turn cycle
|
||||
/// (<c>TurnStart/TurnEnd/Judge</c>) falls out of the real two-client handover. Forwarded frames
|
||||
/// (<c>PlayActions / TurnEndActions / ChatStamp / TurnEndFinal</c>) relay the
|
||||
/// client's own bytes verbatim, so their shape is the client's contract, not ours — out of scope
|
||||
|
||||
@@ -7,14 +7,14 @@ using SVSim.BattleNode.Protocol.Bodies;
|
||||
namespace SVSim.UnitTests.BattleNode.Lifecycle;
|
||||
|
||||
[TestFixture]
|
||||
public class ScriptedLifecycleTests
|
||||
public class ServerBattleFramesTests
|
||||
{
|
||||
[Test]
|
||||
public void BuildMatched_PutsOppoIdInSelfInfoEqualToTheRealOpponentVid()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(), ScriptedBotCtx(),
|
||||
var env = ServerBattleFrames.BuildMatched(FixtureCtx(), ScriptedBotCtx(),
|
||||
selfViewerId: 906243102, oppoViewerId: 847666884,
|
||||
battleId: "b", seed: ScriptedProfiles.BattleSeed);
|
||||
battleId: "b", seed: BattleFrameDefaults.BattleSeed);
|
||||
|
||||
Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.Matched));
|
||||
var body = (MatchedBody)env.Body;
|
||||
@@ -26,7 +26,7 @@ public class ScriptedLifecycleTests
|
||||
[Test]
|
||||
public void BuildMatched_ContainsThirtyCardSelfDeck()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(), ScriptedBotCtx(), 1, 2, "b", ScriptedProfiles.BattleSeed);
|
||||
var env = ServerBattleFrames.BuildMatched(FixtureCtx(), ScriptedBotCtx(), 1, 2, "b", BattleFrameDefaults.BattleSeed);
|
||||
var body = (MatchedBody)env.Body;
|
||||
Assert.That(body.SelfDeck.Count, Is.EqualTo(30));
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class ScriptedLifecycleTests
|
||||
public void BuildMatched_deck_idxs_pair_1to30_with_context_card_ids()
|
||||
{
|
||||
var draftedDeck = Enumerable.Range(1, 30).Select(i => 200_000_000L + i).ToList();
|
||||
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(draftedDeck), ScriptedBotCtx(), 1, 2, "b", ScriptedProfiles.BattleSeed);
|
||||
var env = ServerBattleFrames.BuildMatched(FixtureCtx(draftedDeck), ScriptedBotCtx(), 1, 2, "b", BattleFrameDefaults.BattleSeed);
|
||||
var body = (MatchedBody)env.Body;
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
@@ -56,7 +56,7 @@ public class ScriptedLifecycleTests
|
||||
EmblemId = "888", DegreeId = "777", FieldId = 42, IsOfficial = 1,
|
||||
};
|
||||
|
||||
var env = ScriptedLifecycle.BuildMatched(ctx, ScriptedBotCtx(), 1, 2, "b", ScriptedProfiles.BattleSeed);
|
||||
var env = ServerBattleFrames.BuildMatched(ctx, ScriptedBotCtx(), 1, 2, "b", BattleFrameDefaults.BattleSeed);
|
||||
var body = (MatchedBody)env.Body;
|
||||
|
||||
Assert.That(body.SelfInfo.CountryCode, Is.EqualTo("JPN"));
|
||||
@@ -71,7 +71,7 @@ public class ScriptedLifecycleTests
|
||||
[Test]
|
||||
public void BuildBattleStart_HasTurnStateZero_AndUsesContextBattleType()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 1, turnState: 0);
|
||||
var env = ServerBattleFrames.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 1, turnState: 0);
|
||||
var body = (BattleStartBody)env.Body;
|
||||
Assert.That(body.TurnState, Is.EqualTo(0));
|
||||
Assert.That(body.BattleType, Is.EqualTo(11));
|
||||
@@ -87,7 +87,7 @@ public class ScriptedLifecycleTests
|
||||
BattleType = 42,
|
||||
};
|
||||
|
||||
var env = ScriptedLifecycle.BuildBattleStart(ctx, ScriptedBotCtx(), selfViewerId: 1, turnState: 0);
|
||||
var env = ServerBattleFrames.BuildBattleStart(ctx, ScriptedBotCtx(), selfViewerId: 1, turnState: 0);
|
||||
var body = (BattleStartBody)env.Body;
|
||||
|
||||
Assert.That(body.SelfInfo.ClassId, Is.EqualTo("7"));
|
||||
@@ -99,7 +99,7 @@ public class ScriptedLifecycleTests
|
||||
[Test]
|
||||
public void BuildDeal_HasThreeSelfAndThreeOppoEntries()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildDeal();
|
||||
var env = ServerBattleFrames.BuildDeal();
|
||||
var body = (DealBody)env.Body;
|
||||
Assert.That(body.Self.Count, Is.EqualTo(3));
|
||||
Assert.That(body.Oppo.Count, Is.EqualTo(3));
|
||||
@@ -108,28 +108,28 @@ public class ScriptedLifecycleTests
|
||||
[Test]
|
||||
public void ComputeHandAfterSwap_NoSwap_ReturnsInitialHand()
|
||||
{
|
||||
var hand = ScriptedLifecycle.ComputeHandAfterSwap(Array.Empty<long>());
|
||||
var hand = ServerBattleFrames.ComputeHandAfterSwap(Array.Empty<long>());
|
||||
Assert.That(hand, Is.EqualTo(new long[] { 1, 2, 3 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComputeHandAfterSwap_SwapMiddleCard_ReplacesWithFreshDeckIdx()
|
||||
{
|
||||
var hand = ScriptedLifecycle.ComputeHandAfterSwap(new long[] { 2 });
|
||||
var hand = ServerBattleFrames.ComputeHandAfterSwap(new long[] { 2 });
|
||||
Assert.That(hand, Is.EqualTo(new long[] { 1, 4, 3 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComputeHandAfterSwap_SwapAll_ReplacesAllWithFreshDeckIdxs()
|
||||
{
|
||||
var hand = ScriptedLifecycle.ComputeHandAfterSwap(new long[] { 1, 2, 3 });
|
||||
var hand = ServerBattleFrames.ComputeHandAfterSwap(new long[] { 1, 2, 3 });
|
||||
Assert.That(hand, Is.EqualTo(new long[] { 4, 5, 6 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildSwapResponse_RendersGivenHandAsPositions()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildSwapResponse(new long[] { 1, 4, 3 });
|
||||
var env = ServerBattleFrames.BuildSwapResponse(new long[] { 1, 4, 3 });
|
||||
var body = (SwapResponseBody)env.Body;
|
||||
Assert.That(body.Self.Count, Is.EqualTo(3));
|
||||
Assert.That(body.Self[1].Idx, Is.EqualTo(4));
|
||||
@@ -138,7 +138,7 @@ public class ScriptedLifecycleTests
|
||||
[Test]
|
||||
public void BuildReady_IncludesIdxChangeSeedAndSpin_AndUsesGivenHand()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 });
|
||||
var env = ServerBattleFrames.BuildReady(new long[] { 1, 4, 3 });
|
||||
var body = (ReadyBody)env.Body;
|
||||
Assert.That(body.IdxChangeSeed, Is.EqualTo(771_335_280));
|
||||
Assert.That(body.Spin, Is.EqualTo(243));
|
||||
@@ -148,7 +148,7 @@ public class ScriptedLifecycleTests
|
||||
[Test]
|
||||
public void BuildReady_two_arg_sets_oppo_to_supplied_hand()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 }, new long[] { 1, 2, 6 });
|
||||
var env = ServerBattleFrames.BuildReady(new long[] { 1, 4, 3 }, new long[] { 1, 2, 6 });
|
||||
var body = (ReadyBody)env.Body;
|
||||
|
||||
Assert.That(body.Self.Select(p => p.Idx), Is.EqualTo(new[] { 1, 4, 3 }));
|
||||
@@ -159,7 +159,7 @@ public class ScriptedLifecycleTests
|
||||
[Test]
|
||||
public void BuildReady_one_arg_defaults_oppo_to_InitialHand()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 });
|
||||
var env = ServerBattleFrames.BuildReady(new long[] { 1, 4, 3 });
|
||||
var body = (ReadyBody)env.Body;
|
||||
|
||||
Assert.That(body.Oppo.Select(p => p.Idx), Is.EqualTo(new[] { 1, 2, 3 }),
|
||||
@@ -27,8 +27,8 @@ public class TypedBodyWireShapeTests
|
||||
// Matching.StartBattleLoad reads it back, and GetSelfDeck().Select(...) crashes
|
||||
// with "Value cannot be null. Parameter name: source". The prod wire format
|
||||
// emits envelope keys (uri first) before body keys; we must too.
|
||||
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(), ScriptedBotCtx(),
|
||||
selfViewerId: 1, oppoViewerId: 2, battleId: "b", seed: ScriptedProfiles.BattleSeed);
|
||||
var env = ServerBattleFrames.BuildMatched(FixtureCtx(), ScriptedBotCtx(),
|
||||
selfViewerId: 1, oppoViewerId: 2, battleId: "b", seed: BattleFrameDefaults.BattleSeed);
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
|
||||
var uriIdx = json.IndexOf("\"uri\":", StringComparison.Ordinal);
|
||||
@@ -45,9 +45,9 @@ public class TypedBodyWireShapeTests
|
||||
[Test]
|
||||
public void BuildMatched_SerializesAllWireKeysExpectedByTheClient()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(), ScriptedBotCtx(),
|
||||
var env = ServerBattleFrames.BuildMatched(FixtureCtx(), ScriptedBotCtx(),
|
||||
selfViewerId: 906243102, oppoViewerId: 847666884, battleId: "597830888107",
|
||||
seed: ScriptedProfiles.BattleSeed);
|
||||
seed: BattleFrameDefaults.BattleSeed);
|
||||
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
var node = JsonNode.Parse(json)!.AsObject();
|
||||
@@ -86,7 +86,7 @@ public class TypedBodyWireShapeTests
|
||||
[Test]
|
||||
public void BuildBattleStart_SerializesAllWireKeysAndPreservesBattlePointAsymmetry()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 906243102, turnState: 0);
|
||||
var env = ServerBattleFrames.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 906243102, turnState: 0);
|
||||
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
var node = JsonNode.Parse(json)!.AsObject();
|
||||
@@ -109,7 +109,7 @@ public class TypedBodyWireShapeTests
|
||||
[Test]
|
||||
public void BuildDeal_SerializesSelfAndOppoArraysWithPosIdxShape()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildDeal();
|
||||
var env = ServerBattleFrames.BuildDeal();
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
var node = JsonNode.Parse(json)!.AsObject();
|
||||
|
||||
@@ -125,7 +125,7 @@ public class TypedBodyWireShapeTests
|
||||
[Test]
|
||||
public void BuildSwapResponse_SerializesSelfWithoutOppo()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildSwapResponse(new long[] { 1, 4, 3 });
|
||||
var env = ServerBattleFrames.BuildSwapResponse(new long[] { 1, 4, 3 });
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
var node = JsonNode.Parse(json)!.AsObject();
|
||||
|
||||
@@ -137,7 +137,7 @@ public class TypedBodyWireShapeTests
|
||||
[Test]
|
||||
public void BuildReady_SerializesAllFieldsIncludingSeedAndSpin()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 });
|
||||
var env = ServerBattleFrames.BuildReady(new long[] { 1, 4, 3 });
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
var node = JsonNode.Parse(json)!.AsObject();
|
||||
|
||||
|
||||
@@ -412,7 +412,7 @@ public class BattleSessionDispatchTests
|
||||
private static (BattleSession, FakeRealParticipant, FakeParticipant) NewBotSession()
|
||||
{
|
||||
var a = new FakeRealParticipant(viewerId: 1001, PlayerACtx());
|
||||
var b = new FakeParticipant(viewerId: ScriptedLifecycle.FakeOpponentViewerId, NoOpBotContext());
|
||||
var b = new FakeParticipant(viewerId: ServerBattleFrames.FakeOpponentViewerId, NoOpBotContext());
|
||||
var s = new BattleSession("bid-bot-1", BattleType.Bot, a, b, NullLogger<BattleSession>.Instance);
|
||||
return (s, a, b);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,6 @@ public class NoOpBotParticipantTests
|
||||
public void ViewerId_is_FakeOpponent()
|
||||
{
|
||||
var p = new NoOpBotParticipant();
|
||||
Assert.That(p.ViewerId, Is.EqualTo(SVSim.BattleNode.Lifecycle.ScriptedLifecycle.FakeOpponentViewerId));
|
||||
Assert.That(p.ViewerId, Is.EqualTo(SVSim.BattleNode.Lifecycle.ServerBattleFrames.FakeOpponentViewerId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user