feat(battle-node): add ScriptedBotParticipant wrapping v1.2 burst
PushAsync(TurnEnd|TurnEndFinal) fires FrameEmitted three times: OpponentTurnStart + OpponentTurnEnd + OpponentJudge. Behaviour-identical to the v1.2 case arm in BattleSession.ComputeResponses; just repackaged as a participant. Other URIs are swallowed. Used by Phase 1 to preserve v1.2 behaviour under the new abstraction; replaces the case-arm logic in BattleSession in Task 7.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using NUnit.Framework;
|
||||
using SVSim.BattleNode.Bridge;
|
||||
using SVSim.BattleNode.Protocol;
|
||||
using SVSim.BattleNode.Protocol.Bodies;
|
||||
using SVSim.BattleNode.Sessions;
|
||||
using SVSim.BattleNode.Sessions.Participants;
|
||||
|
||||
namespace SVSim.UnitTests.BattleNode.Sessions.Participants;
|
||||
|
||||
[TestFixture]
|
||||
public class ScriptedBotParticipantTests
|
||||
{
|
||||
[Test]
|
||||
public async Task PushAsync_TurnEnd_fires_three_FrameEmitted_in_order()
|
||||
{
|
||||
var p = new ScriptedBotParticipant();
|
||||
var emitted = new List<NetworkBattleUri>();
|
||||
p.FrameEmitted += (env, _) => { emitted.Add(env.Uri); return Task.CompletedTask; };
|
||||
|
||||
await p.PushAsync(NewEnvelope(NetworkBattleUri.TurnEnd), noStock: false, CancellationToken.None);
|
||||
|
||||
Assert.That(emitted, Is.EqualTo(new[]
|
||||
{
|
||||
NetworkBattleUri.TurnStart,
|
||||
NetworkBattleUri.TurnEnd,
|
||||
NetworkBattleUri.Judge,
|
||||
}));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PushAsync_TurnEndFinal_fires_three_FrameEmitted_in_order()
|
||||
{
|
||||
// Same burst as TurnEnd — TurnEndFinal is the game-ending variant but the
|
||||
// bot's response shape is unchanged for v1.2 behaviour preservation.
|
||||
var p = new ScriptedBotParticipant();
|
||||
var emitted = new List<NetworkBattleUri>();
|
||||
p.FrameEmitted += (env, _) => { emitted.Add(env.Uri); return Task.CompletedTask; };
|
||||
|
||||
await p.PushAsync(NewEnvelope(NetworkBattleUri.TurnEndFinal), noStock: false, CancellationToken.None);
|
||||
|
||||
Assert.That(emitted, Is.EqualTo(new[]
|
||||
{
|
||||
NetworkBattleUri.TurnStart,
|
||||
NetworkBattleUri.TurnEnd,
|
||||
NetworkBattleUri.Judge,
|
||||
}));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PushAsync_other_uris_do_not_fire()
|
||||
{
|
||||
var p = new ScriptedBotParticipant();
|
||||
var fired = 0;
|
||||
p.FrameEmitted += (_, _) => { fired++; return Task.CompletedTask; };
|
||||
|
||||
foreach (var uri in new[]
|
||||
{
|
||||
NetworkBattleUri.Matched, NetworkBattleUri.BattleStart, NetworkBattleUri.Deal,
|
||||
NetworkBattleUri.Swap, NetworkBattleUri.Ready, NetworkBattleUri.PlayActions,
|
||||
NetworkBattleUri.TurnStart, NetworkBattleUri.TurnEndActions, NetworkBattleUri.Echo,
|
||||
NetworkBattleUri.Judge, NetworkBattleUri.BattleFinish,
|
||||
})
|
||||
{
|
||||
await p.PushAsync(NewEnvelope(uri), noStock: false, CancellationToken.None);
|
||||
}
|
||||
|
||||
Assert.That(fired, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RunAsync_returns_immediately()
|
||||
{
|
||||
var p = new ScriptedBotParticipant();
|
||||
await p.RunAsync(CancellationToken.None);
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
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 ResultCodeOnlyBody());
|
||||
}
|
||||
Reference in New Issue
Block a user