feat(battle-node): thread MatchContext through bridge to BattleSession
IMatchingBridge.RegisterPendingBattle now takes a MatchContext; PendingBattle carries it; BattleSession stores it. ArenaTwoPickBattleController builds ctx from IMatchContextBuilder. ScriptedLifecycle still uses ScriptedProfiles for the player half — Tasks 5/6 migrate the lifecycle. Existing tests updated: MatchingBridgeTests, BattleNodeFlowTests, InMemoryBattleSessionStoreTests, BattleSessionDispatchTests, BattleSession PumpTests, ArenaTwoPickBattleControllerTests (which now seeds a TK2 run + adds a no-active-run 400 case). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Controllers;
|
||||
@@ -12,6 +15,8 @@ public class ArenaTwoPickBattleControllerTests
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
await SeedCompleteTwoPickRunAsync(factory, viewerId);
|
||||
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
var req = new {
|
||||
deck_no = 1L, need_init = 1, log = 1, excluded_field_id_list = new long[] { }, use_stage_select = 1, is_default_skin = 0,
|
||||
@@ -28,12 +33,50 @@ public class ArenaTwoPickBattleControllerTests
|
||||
var battleId = root.GetProperty("battle_id").GetString();
|
||||
Assert.That(battleId, Is.Not.Null.And.Not.Empty);
|
||||
var nodeUrl = root.GetProperty("node_server_url").GetString();
|
||||
// Matches prod wire format: host:port/socket.io/, no scheme prefix.
|
||||
Assert.That(nodeUrl, Does.Contain("/socket.io/"));
|
||||
Assert.That(nodeUrl, Does.Not.StartWith("ws://"));
|
||||
Assert.That(nodeUrl, Does.Not.StartWith("http://"));
|
||||
// Required when matching_state ∈ {3004,3007,3011} per
|
||||
// DoMatchingBase.SettingCardMasterId; client throws KeyNotFoundException without it.
|
||||
Assert.That(root.GetProperty("card_master_id").GetInt32(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DoMatching_NoActiveRun_Returns400WithErrorCode()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
var req = new {
|
||||
deck_no = 1L, need_init = 1, log = 1, excluded_field_id_list = new long[] { }, use_stage_select = 1, is_default_skin = 0,
|
||||
viewer_id = "0", steam_id = 0, steam_session_ticket = "",
|
||||
};
|
||||
var resp = await client.PostAsync("/arena_two_pick_battle/do_matching", JsonContent.Create(req));
|
||||
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
using var doc = JsonDocument.Parse(body);
|
||||
Assert.That(doc.RootElement.GetProperty("error_code").GetString(),
|
||||
Is.EqualTo("arena_two_pick_no_active_run"));
|
||||
}
|
||||
|
||||
private static async Task SeedCompleteTwoPickRunAsync(SVSimTestFactory factory, long viewerId)
|
||||
{
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
var deck = Enumerable.Range(1, 30).Select(i => 100_011_000L + i).ToList();
|
||||
db.ViewerArenaTwoPickRuns.Add(new ViewerArenaTwoPickRun
|
||||
{
|
||||
ViewerId = viewerId,
|
||||
EntryId = 1,
|
||||
ClassId = 1,
|
||||
LeaderSkinId = 1,
|
||||
SelectedCardIdsJson = JsonSerializer.Serialize(deck),
|
||||
IsSelectCompleted = true,
|
||||
MaxBattleCount = 5,
|
||||
CandidateClassIdsJson = "[1,2,3]",
|
||||
PendingPickSetsJson = "[]",
|
||||
ResultListJson = "[]",
|
||||
NextCandidateId = 1,
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user