fix(rank-battle): route ai-start through the queue-time MatchContext
Live-smoke bug 2026-06-02: queued Bloodcraft (deck #5), wire showed classId=2 (Swordcraft) for self_info on the /ai_unlimited_rank_battle/start response — client rendered the wrong leader. Two layers of the same bug: 1. MatchContextBuilder.BuildForRankBattleAsync hardcoded deckNo=1 instead of taking it from the do_matching request — verified against data_dumps/captures/traffic.ndjson L17 where deck_no=5 was on the wire. Signature changes to (viewerId, format, deckNo); DoMatchingInternal passes req.DeckNo. 2. AiStartInternal rebuilt MatchContext from scratch — but the /ai_*/start request body is BaseRequest only, no deck_no on the wire. The fix uses the MatchContext the bridge already stored at do_matching resolution time (in the Bot PendingBattle), so deck/cosmetic data is consistent end-to-end. New IBattleSessionStore.TryFindPendingForViewer(viewerId) finds the viewer's pending battle for lookup. The store entry persists across ai_start (idempotent reads are fine — the WS handler removes on connect). No-pending sentinel: ai_id=-1 surfaces the "no AI assigned" error in the client. Tests: 936 → 939 passing. - MatchContextBuilderTests.BuildForRankBattle_uses_the_caller_supplied_deck_number seeds deck #1 (class 1) and deck #5 (class 6) and asserts the deckNo argument picks the right one. - RankBattleControllerTests.AiStart_self_info_class_matches_queued_deck_number is the end-to-end regression: register Bot battle with deck #5, hit /ai_unlimited_rank_battle/start, assert self_info.classId == 6. - RankBattleControllerTests.AiStart_without_pending_battle_returns_neg1_sentinel locks the defensive ai_id=-1 path. - Existing AiStart_* tests bypass do_matching, so adapted to call a new RegisterBotBattleAsync helper that mirrors what InProcessPairUp does on AI-fallback resolution. SeedDeckAsync gains an optional classId so test cases can differentiate decks by class (was always picking Classes.First()). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,16 @@ public interface IBattleSessionStore
|
|||||||
/// <summary>Look up the pending battle. Returns null if not present.</summary>
|
/// <summary>Look up the pending battle. Returns null if not present.</summary>
|
||||||
PendingBattle? TryGetPending(string battleId);
|
PendingBattle? TryGetPending(string battleId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find a pending battle this viewer is a participant in (P1 or P2). Used by the
|
||||||
|
/// HTTP-side <c>/ai_<fmt>/start</c> endpoint to retrieve the deck/cosmetic
|
||||||
|
/// context the viewer registered at <c>do_matching</c> time — the <c>/start</c>
|
||||||
|
/// request body carries no <c>deck_no</c> of its own. Returns null if the viewer
|
||||||
|
/// has no pending battle (already consumed by WS connect, never registered, or
|
||||||
|
/// evicted by timeout).
|
||||||
|
/// </summary>
|
||||||
|
PendingBattle? TryFindPendingForViewer(long viewerId);
|
||||||
|
|
||||||
/// <summary>Mark a battle as no longer pending (e.g. on successful connect or explicit close).</summary>
|
/// <summary>Mark a battle as no longer pending (e.g. on successful connect or explicit close).</summary>
|
||||||
bool RemovePending(string battleId);
|
bool RemovePending(string battleId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,21 @@ public sealed class InMemoryBattleSessionStore : IBattleSessionStore
|
|||||||
public PendingBattle? TryGetPending(string battleId) =>
|
public PendingBattle? TryGetPending(string battleId) =>
|
||||||
_pending.TryGetValue(battleId, out var b) ? b : null;
|
_pending.TryGetValue(battleId, out var b) ? b : null;
|
||||||
|
|
||||||
|
public PendingBattle? TryFindPendingForViewer(long viewerId)
|
||||||
|
{
|
||||||
|
// Linear scan — _pending is bounded by concurrent in-flight matches (low
|
||||||
|
// double digits at most), so this stays cheap. Returns whichever match the
|
||||||
|
// dictionary's enumerator yields first; in practice a viewer has at most one
|
||||||
|
// pending battle since each /do_matching either pairs/falls-back the existing
|
||||||
|
// slot or parks without registering.
|
||||||
|
foreach (var b in _pending.Values)
|
||||||
|
{
|
||||||
|
if (b.P1.ViewerId == viewerId) return b;
|
||||||
|
if (b.P2 is not null && b.P2.ViewerId == viewerId) return b;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public bool RemovePending(string battleId) =>
|
public bool RemovePending(string battleId) =>
|
||||||
_pending.TryRemove(battleId, out _);
|
_pending.TryRemove(battleId, out _);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SVSim.BattleNode.Bridge;
|
using SVSim.BattleNode.Bridge;
|
||||||
|
using SVSim.BattleNode.Sessions;
|
||||||
using SVSim.Database.Enums;
|
using SVSim.Database.Enums;
|
||||||
using SVSim.EmulatedEntrypoint.Constants;
|
using SVSim.EmulatedEntrypoint.Constants;
|
||||||
using SVSim.EmulatedEntrypoint.Matching;
|
using SVSim.EmulatedEntrypoint.Matching;
|
||||||
@@ -24,6 +25,7 @@ public sealed class RankBattleController : ControllerBase
|
|||||||
{
|
{
|
||||||
private readonly IMatchingPairUpService _pairUp;
|
private readonly IMatchingPairUpService _pairUp;
|
||||||
private readonly IMatchingBridge _bridge;
|
private readonly IMatchingBridge _bridge;
|
||||||
|
private readonly IBattleSessionStore _sessionStore;
|
||||||
private readonly IMatchContextBuilder _ctxBuilder;
|
private readonly IMatchContextBuilder _ctxBuilder;
|
||||||
private readonly IBotRoster _botRoster;
|
private readonly IBotRoster _botRoster;
|
||||||
private readonly ILogger<RankBattleController> _log;
|
private readonly ILogger<RankBattleController> _log;
|
||||||
@@ -31,12 +33,14 @@ public sealed class RankBattleController : ControllerBase
|
|||||||
public RankBattleController(
|
public RankBattleController(
|
||||||
IMatchingPairUpService pairUp,
|
IMatchingPairUpService pairUp,
|
||||||
IMatchingBridge bridge,
|
IMatchingBridge bridge,
|
||||||
|
IBattleSessionStore sessionStore,
|
||||||
IMatchContextBuilder ctxBuilder,
|
IMatchContextBuilder ctxBuilder,
|
||||||
IBotRoster botRoster,
|
IBotRoster botRoster,
|
||||||
ILogger<RankBattleController> log)
|
ILogger<RankBattleController> log)
|
||||||
{
|
{
|
||||||
_pairUp = pairUp;
|
_pairUp = pairUp;
|
||||||
_bridge = bridge;
|
_bridge = bridge;
|
||||||
|
_sessionStore = sessionStore;
|
||||||
_ctxBuilder = ctxBuilder;
|
_ctxBuilder = ctxBuilder;
|
||||||
_botRoster = botRoster;
|
_botRoster = botRoster;
|
||||||
_log = log;
|
_log = log;
|
||||||
@@ -120,14 +124,14 @@ public sealed class RankBattleController : ControllerBase
|
|||||||
MatchContext ctx;
|
MatchContext ctx;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ctx = await _ctxBuilder.BuildForRankBattleAsync(vid, format);
|
ctx = await _ctxBuilder.BuildForRankBattleAsync(vid, format, req.DeckNo);
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ex)
|
catch (InvalidOperationException ex)
|
||||||
{
|
{
|
||||||
// Most likely cause: viewer has no deck for this format. Surface as 3001
|
// Most likely cause: viewer has no deck at that slot for this format. Surface
|
||||||
// RC_BATTLE_MATCHING_ILLEGAL — the client shows the standard matchmaking-error
|
// as 3001 RC_BATTLE_MATCHING_ILLEGAL — the client shows the standard
|
||||||
// dialog rather than retrying forever.
|
// matchmaking-error dialog rather than retrying forever.
|
||||||
_log.LogWarning(ex, "BuildForRankBattleAsync failed for viewer {Vid} format {Fmt}; returning 3001.", vid, format);
|
_log.LogWarning(ex, "BuildForRankBattleAsync failed for viewer {Vid} format {Fmt} deckNo {DeckNo}; returning 3001.", vid, format, req.DeckNo);
|
||||||
return Ok(new DoMatchingResponseDto { MatchingState = 3001, NodeServerUrl = "" });
|
return Ok(new DoMatchingResponseDto { MatchingState = 3001, NodeServerUrl = "" });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,18 +171,19 @@ public sealed class RankBattleController : ControllerBase
|
|||||||
{
|
{
|
||||||
if (!TryGetViewerId(out var vid)) return Unauthorized();
|
if (!TryGetViewerId(out var vid)) return Unauthorized();
|
||||||
|
|
||||||
MatchContext selfCtx;
|
// The /ai_<fmt>/start request body is BaseRequest only — it carries no deck_no.
|
||||||
try
|
// The deck the viewer queued with was captured in the PendingBattle's MatchContext
|
||||||
|
// at /do_matching resolution time (when InProcessPairUp called bridge.RegisterBattle).
|
||||||
|
// Reuse that context so SelfInfo's classId/charaId/sleeveId match what the user
|
||||||
|
// actually picked. Rebuilding from deck #1 was the 2026-06-02 wire-bug — surfaced
|
||||||
|
// as "queued Bloodcraft, saw Swordcraft leader."
|
||||||
|
var pending = _sessionStore.TryFindPendingForViewer(vid);
|
||||||
|
if (pending is null)
|
||||||
{
|
{
|
||||||
selfCtx = await _ctxBuilder.BuildForRankBattleAsync(vid, format);
|
_log.LogWarning("AiStart for viewer {Vid} format {Fmt} has no pending battle; returning ai_id=-1.", vid, format);
|
||||||
}
|
|
||||||
catch (InvalidOperationException ex)
|
|
||||||
{
|
|
||||||
// No deck → can't build a self profile. Surface as the "no AI assigned"
|
|
||||||
// sentinel; the client treats ai_id=-1 as a fallback/error condition.
|
|
||||||
_log.LogWarning(ex, "AiStart failed for viewer {Vid} format {Fmt}; returning ai_id=-1.", vid, format);
|
|
||||||
return Ok(new AiBattleStartResponseDto { AiId = -1 });
|
return Ok(new AiBattleStartResponseDto { AiId = -1 });
|
||||||
}
|
}
|
||||||
|
var selfCtx = pending.P1.Context;
|
||||||
|
|
||||||
var bot = await _botRoster.PickAsync(selfCtx, ct);
|
var bot = await _botRoster.PickAsync(selfCtx, ct);
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,10 @@ public interface IMatchContextBuilder
|
|||||||
Task<MatchContext> BuildForTwoPickAsync(long viewerId);
|
Task<MatchContext> BuildForTwoPickAsync(long viewerId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Build a context for a rank-battle viewer + format (rotation / unlimited). Pulls the
|
/// Build a context for a rank-battle viewer + format (rotation / unlimited) + the
|
||||||
/// viewer's deck #1 for that format + viewer cosmetics. Throws if the viewer has no
|
/// caller-selected deck number (from <c>do_matching</c>'s <c>deck_no</c>). Pulls the
|
||||||
/// deck registered for the format.
|
/// viewer's deck for that format/number + viewer cosmetics. Throws if the viewer has
|
||||||
|
/// no deck at that slot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
Task<MatchContext> BuildForRankBattleAsync(long viewerId, Format format, int deckNo);
|
||||||
/// Deck-selection persistence (which deck number is "current" for this format) is a
|
|
||||||
/// separate concern; deck #1 is a placeholder until that lands.
|
|
||||||
/// </remarks>
|
|
||||||
Task<MatchContext> BuildForRankBattleAsync(long viewerId, Format format);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,17 +70,17 @@ public class MatchContextBuilder : IMatchContextBuilder
|
|||||||
BattleType: 11);
|
BattleType: 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<MatchContext> BuildForRankBattleAsync(long viewerId, Format format)
|
public async Task<MatchContext> BuildForRankBattleAsync(long viewerId, Format format, int deckNo)
|
||||||
{
|
{
|
||||||
var viewer = await _viewers.LoadForMatchContextAsync(viewerId)
|
var viewer = await _viewers.LoadForMatchContextAsync(viewerId)
|
||||||
?? throw new InvalidOperationException($"viewer {viewerId} not found");
|
?? throw new InvalidOperationException($"viewer {viewerId} not found");
|
||||||
|
|
||||||
// Per spec, deck-selection persistence (which deck number is "current" for this
|
// IDeckRepository is the right path here — viewer-graph nav refs (DeckCard.Card)
|
||||||
// format) is a separate concern; #1 is a placeholder until that lands. IDeckRepository
|
// don't auto-load (see project_ef_nav_include_pitfall memory), which would
|
||||||
// is the right path here — viewer-graph nav refs (DeckCard.Card) don't auto-load
|
// silently ship card_id=0.
|
||||||
// (see project_ef_nav_include_pitfall memory), which would silently ship card_id=0.
|
var deck = await _decks.GetDeck(viewerId, format, deckNo)
|
||||||
var deck = await _decks.GetDeck(viewerId, format, deckNo: 1)
|
?? throw new InvalidOperationException(
|
||||||
?? throw new InvalidOperationException($"viewer {viewerId} has no deck for format {format}");
|
$"viewer {viewerId} has no deck #{deckNo} for format {format}");
|
||||||
|
|
||||||
var defaults = _config.Get<DefaultLoadoutConfig>();
|
var defaults = _config.Get<DefaultLoadoutConfig>();
|
||||||
var emblemId = viewer.Info.SelectedEmblem.Id != 0
|
var emblemId = viewer.Info.SelectedEmblem.Id != 0
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ public class BattleNodeFlowTests
|
|||||||
var bridge = factory.Services.GetRequiredService<IMatchingBridge>();
|
var bridge = factory.Services.GetRequiredService<IMatchingBridge>();
|
||||||
using var scope = factory.Services.CreateScope();
|
using var scope = factory.Services.CreateScope();
|
||||||
var builder = scope.ServiceProvider.GetRequiredService<SVSim.EmulatedEntrypoint.Services.IMatchContextBuilder>();
|
var builder = scope.ServiceProvider.GetRequiredService<SVSim.EmulatedEntrypoint.Services.IMatchContextBuilder>();
|
||||||
var ctx = await builder.BuildForRankBattleAsync(vid, SVSim.Database.Enums.Format.Rotation);
|
var ctx = await builder.BuildForRankBattleAsync(vid, SVSim.Database.Enums.Format.Rotation, deckNo: 1);
|
||||||
var pending = bridge.RegisterBattle(
|
var pending = bridge.RegisterBattle(
|
||||||
new SVSim.BattleNode.Bridge.BattlePlayer(vid, ctx),
|
new SVSim.BattleNode.Bridge.BattlePlayer(vid, ctx),
|
||||||
p2: null,
|
p2: null,
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ using System.Net.Http.Json;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using SVSim.BattleNode.Bridge;
|
||||||
|
using SVSim.BattleNode.Sessions;
|
||||||
using SVSim.Database.Enums;
|
using SVSim.Database.Enums;
|
||||||
|
using SVSim.EmulatedEntrypoint.Services;
|
||||||
using SVSim.UnitTests.Infrastructure;
|
using SVSim.UnitTests.Infrastructure;
|
||||||
|
|
||||||
namespace SVSim.UnitTests.Controllers;
|
namespace SVSim.UnitTests.Controllers;
|
||||||
@@ -44,6 +47,21 @@ public class RankBattleControllerTests
|
|||||||
steam_session_ticket = "",
|
steam_session_ticket = "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AiStart in the real client flow always follows a do_matching call that resolved
|
||||||
|
/// to 3011 (AI fallback) — that's when the PendingBattle is registered with the
|
||||||
|
/// viewer's queue-time MatchContext (deck/cosmetics). Tests bypass do_matching's
|
||||||
|
/// time-threshold to register a Bot PendingBattle directly via the bridge.
|
||||||
|
/// </summary>
|
||||||
|
private static async Task RegisterBotBattleAsync(SVSimTestFactory factory, long viewerId, Format format, int deckNo)
|
||||||
|
{
|
||||||
|
var bridge = factory.Services.GetRequiredService<IMatchingBridge>();
|
||||||
|
using var scope = factory.Services.CreateScope();
|
||||||
|
var builder = scope.ServiceProvider.GetRequiredService<IMatchContextBuilder>();
|
||||||
|
var ctx = await builder.BuildForRankBattleAsync(viewerId, format, deckNo);
|
||||||
|
bridge.RegisterBattle(new BattlePlayer(viewerId, ctx), p2: null, BattleType.Bot);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task DoMatching_rotation_first_poll_returns_3002_RETRY_with_empty_node_server_url()
|
public async Task DoMatching_rotation_first_poll_returns_3002_RETRY_with_empty_node_server_url()
|
||||||
{
|
{
|
||||||
@@ -102,6 +120,7 @@ public class RankBattleControllerTests
|
|||||||
var viewerId = await factory.SeedViewerAsync(displayName: "TestViewer");
|
var viewerId = await factory.SeedViewerAsync(displayName: "TestViewer");
|
||||||
await factory.SeedGlobalsAsync();
|
await factory.SeedGlobalsAsync();
|
||||||
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
||||||
|
await RegisterBotBattleAsync(factory, viewerId, Format.Rotation, deckNo: 1);
|
||||||
var client = factory.CreateAuthenticatedClient(viewerId);
|
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", EmptyAuthedBody);
|
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", EmptyAuthedBody);
|
||||||
@@ -140,6 +159,7 @@ public class RankBattleControllerTests
|
|||||||
var viewerId = await factory.SeedViewerAsync(displayName: "Alice");
|
var viewerId = await factory.SeedViewerAsync(displayName: "Alice");
|
||||||
await factory.SeedGlobalsAsync();
|
await factory.SeedGlobalsAsync();
|
||||||
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
||||||
|
await RegisterBotBattleAsync(factory, viewerId, Format.Rotation, deckNo: 1);
|
||||||
var client = factory.CreateAuthenticatedClient(viewerId);
|
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", EmptyAuthedBody);
|
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", EmptyAuthedBody);
|
||||||
@@ -156,6 +176,7 @@ public class RankBattleControllerTests
|
|||||||
var viewerId = await factory.SeedViewerAsync(displayName: "PlayerA");
|
var viewerId = await factory.SeedViewerAsync(displayName: "PlayerA");
|
||||||
await factory.SeedGlobalsAsync();
|
await factory.SeedGlobalsAsync();
|
||||||
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
||||||
|
await RegisterBotBattleAsync(factory, viewerId, Format.Rotation, deckNo: 1);
|
||||||
var client = factory.CreateAuthenticatedClient(viewerId);
|
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", EmptyAuthedBody);
|
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", EmptyAuthedBody);
|
||||||
@@ -167,6 +188,48 @@ public class RankBattleControllerTests
|
|||||||
Assert.That(oppoInfo.GetProperty("classId").GetInt32(), Is.InRange(1, 8));
|
Assert.That(oppoInfo.GetProperty("classId").GetInt32(), Is.InRange(1, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task AiStart_self_info_class_matches_queued_deck_number()
|
||||||
|
{
|
||||||
|
// Regression for the 2026-06-02 "queued Bloodcraft, saw Swordcraft leader" wire bug.
|
||||||
|
// The original impl rebuilt MatchContext from deck #1 inside AiStart; the fix routes
|
||||||
|
// it through the PendingBattle the bridge stored at do_matching time (which carries
|
||||||
|
// the queue-time deck_no). Seed two distinct-class decks and confirm /ai_*/start
|
||||||
|
// returns the right class for a viewer registered with deck #5.
|
||||||
|
await using var factory = new SVSimTestFactory();
|
||||||
|
var viewerId = await factory.SeedViewerAsync(displayName: "Ranker");
|
||||||
|
await factory.SeedGlobalsAsync();
|
||||||
|
await factory.SeedDeckAsync(viewerId, Format.Unlimited, number: 1, classId: 1);
|
||||||
|
await factory.SeedDeckAsync(viewerId, Format.Unlimited, number: 5, classId: 6);
|
||||||
|
await RegisterBotBattleAsync(factory, viewerId, Format.Unlimited, deckNo: 5);
|
||||||
|
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
|
var resp = await client.PostAsJsonAsync("/ai_unlimited_rank_battle/start", EmptyAuthedBody);
|
||||||
|
using var doc = JsonDocument.Parse(await resp.Content.ReadAsStringAsync());
|
||||||
|
var selfInfo = doc.RootElement.GetProperty("self_info");
|
||||||
|
|
||||||
|
Assert.That(selfInfo.GetProperty("classId").GetInt32(), Is.EqualTo(6),
|
||||||
|
"Self class must reflect the deck the viewer queued with (deck #5 = Bloodcraft, class 6).");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task AiStart_without_pending_battle_returns_neg1_sentinel()
|
||||||
|
{
|
||||||
|
// Defensive: clients always do_matching before ai_start, but if /ai_*/start is hit
|
||||||
|
// without a registered PendingBattle (server restart, expired match, ...), the spec
|
||||||
|
// sentinel ai_id=-1 surfaces the "no AI assigned" error in the client.
|
||||||
|
await using var factory = new SVSimTestFactory();
|
||||||
|
var viewerId = await factory.SeedViewerAsync();
|
||||||
|
await factory.SeedGlobalsAsync();
|
||||||
|
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
||||||
|
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
|
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", EmptyAuthedBody);
|
||||||
|
using var doc = JsonDocument.Parse(await resp.Content.ReadAsStringAsync());
|
||||||
|
|
||||||
|
Assert.That(doc.RootElement.GetProperty("ai_id").GetInt32(), Is.EqualTo(-1));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Finish_emits_stubbed_zeros_with_battle_result_echo()
|
public async Task Finish_emits_stubbed_zeros_with_battle_result_echo()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -369,13 +369,16 @@ internal sealed class SVSimTestFactory : WebApplicationFactory<Program>
|
|||||||
/// path. Picks the first seeded class/sleeve/leader-skin from the master tables; tests
|
/// path. Picks the first seeded class/sleeve/leader-skin from the master tables; tests
|
||||||
/// that need specific ids should hit the DB directly.
|
/// that need specific ids should hit the DB directly.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task SeedDeckAsync(long viewerId, Format format, int number, string name = "Test Deck")
|
public async Task SeedDeckAsync(long viewerId, Format format, int number, string name = "Test Deck", int? classId = null)
|
||||||
{
|
{
|
||||||
using var scope = Services.CreateScope();
|
using var scope = Services.CreateScope();
|
||||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||||
var repo = scope.ServiceProvider.GetRequiredService<IDeckRepository>();
|
var repo = scope.ServiceProvider.GetRequiredService<IDeckRepository>();
|
||||||
|
|
||||||
var cls = await db.Classes.FirstAsync();
|
var cls = classId is null
|
||||||
|
? await db.Classes.FirstAsync()
|
||||||
|
: await db.Classes.FindAsync(classId.Value)
|
||||||
|
?? throw new InvalidOperationException($"SeedDeckAsync: class {classId} not found");
|
||||||
var sleeve = await db.Sleeves.FirstAsync();
|
var sleeve = await db.Sleeves.FirstAsync();
|
||||||
var skin = await db.LeaderSkins.FirstAsync();
|
var skin = await db.LeaderSkins.FirstAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public class MatchContextBuilderTests
|
|||||||
using var scope = factory.Services.CreateScope();
|
using var scope = factory.Services.CreateScope();
|
||||||
var builder = scope.ServiceProvider.GetRequiredService<IMatchContextBuilder>();
|
var builder = scope.ServiceProvider.GetRequiredService<IMatchContextBuilder>();
|
||||||
|
|
||||||
var ctx = await builder.BuildForRankBattleAsync(viewerId, Format.Rotation);
|
var ctx = await builder.BuildForRankBattleAsync(viewerId, Format.Rotation, deckNo: 1);
|
||||||
|
|
||||||
Assert.That(ctx.UserName, Is.EqualTo("Ranker"));
|
Assert.That(ctx.UserName, Is.EqualTo("Ranker"));
|
||||||
Assert.That(ctx.BattleType, Is.EqualTo(11), "BattleType=11 matches the prod rank-battle wire value (same as TK2).");
|
Assert.That(ctx.BattleType, Is.EqualTo(11), "BattleType=11 matches the prod rank-battle wire value (same as TK2).");
|
||||||
@@ -148,10 +148,33 @@ public class MatchContextBuilderTests
|
|||||||
using var scope = factory.Services.CreateScope();
|
using var scope = factory.Services.CreateScope();
|
||||||
var builder = scope.ServiceProvider.GetRequiredService<IMatchContextBuilder>();
|
var builder = scope.ServiceProvider.GetRequiredService<IMatchContextBuilder>();
|
||||||
|
|
||||||
Assert.That(async () => await builder.BuildForRankBattleAsync(viewerId, Format.Rotation),
|
Assert.That(async () => await builder.BuildForRankBattleAsync(viewerId, Format.Rotation, deckNo: 1),
|
||||||
Throws.Exception);
|
Throws.Exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task BuildForRankBattle_uses_the_caller_supplied_deck_number()
|
||||||
|
{
|
||||||
|
// Regression for the 2026-06-02 "queued Bloodcraft, saw Swordcraft leader"
|
||||||
|
// wire bug — MatchContextBuilder.BuildForRankBattleAsync hardcoded deckNo=1.
|
||||||
|
// Seed two decks for different classes (1 and 6) and confirm the deckNo
|
||||||
|
// argument picks the right one.
|
||||||
|
await using var factory = new SVSimTestFactory();
|
||||||
|
var viewerId = await factory.SeedViewerAsync(displayName: "Ranker");
|
||||||
|
await factory.SeedGlobalsAsync();
|
||||||
|
await factory.SeedDeckAsync(viewerId, Format.Unlimited, number: 1, name: "Deck 1", classId: 1);
|
||||||
|
await factory.SeedDeckAsync(viewerId, Format.Unlimited, number: 5, name: "Deck 5", classId: 6);
|
||||||
|
|
||||||
|
using var scope = factory.Services.CreateScope();
|
||||||
|
var builder = scope.ServiceProvider.GetRequiredService<IMatchContextBuilder>();
|
||||||
|
|
||||||
|
var deck1Ctx = await builder.BuildForRankBattleAsync(viewerId, Format.Unlimited, deckNo: 1);
|
||||||
|
var deck5Ctx = await builder.BuildForRankBattleAsync(viewerId, Format.Unlimited, deckNo: 5);
|
||||||
|
|
||||||
|
Assert.That(deck1Ctx.ClassId, Is.EqualTo("1"), "deckNo=1 → class 1.");
|
||||||
|
Assert.That(deck5Ctx.ClassId, Is.EqualTo("6"), "deckNo=5 → class 6 (the wire-bug case).");
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task BuildForTwoPick_falls_back_to_default_loadout_when_unequipped()
|
public async Task BuildForTwoPick_falls_back_to_default_loadout_when_unequipped()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user