feat(matching): per-mode policy + AI-fallback branch in InProcessPairUp

InProcessPairUp now consults ModePolicyRegistry per call and reads the
fallback threshold from MatchingConfig via IServiceScopeFactory (singleton
service consuming a scoped IGameConfigService). New behavior for
PvpFirstThenAiFallback modes: when the calling viewer IS the slot's
waiter and Now - WaitingSince >= threshold, the waiter unparks and the
bridge resolves a Bot match. PvpOnly modes (TK2) keep parking forever
(modulo a 5-minute stale-waiter eviction backstop).

TimeProvider is injected so tests can drive time forward with
FakeTimeProvider — 7 new tests cover the four key transitions
(stay-parked / pair-pvp / fall-back / stale-evict) plus per-mode
isolation. Fixture uses [FixtureLifeCycle(InstancePerTestCase)] because
the assembly is Parallelizable(ParallelScope.All).

Program.cs registers ModePolicyRegistry with three rows: TK2 PvpOnly,
rotation/unlimited rank PvpFirstThenAiFallback.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-02 01:09:42 -04:00
parent 3866c93065
commit b65cf81977
5 changed files with 281 additions and 30 deletions

View File

@@ -128,9 +128,15 @@ public class Program
// in appsettings*.json — see appsettings.Development.json for SoloDefaultsToScripted.
builder.Configuration.GetSection("BattleNode").Bind(opt);
});
// In-process FCFS pair-up for TK2 PvP /do_matching. Singleton: per-mode state is
// process-wide. Proper queue API is a separate spec; this is enough to actually
// pair two viewers polling the same mode end-to-end.
// In-process FCFS pair-up for TK2 PvP /do_matching, plus rank-battle's AI-fallback
// branch. Singleton: per-mode state is process-wide. Proper queue API is a separate
// spec; this is enough to actually pair two viewers polling the same mode end-to-end.
builder.Services.AddSingleton(new ModePolicyRegistry(new[]
{
new ModePolicy("arena_two_pick_battle", PolicyKind.PvpOnly),
new ModePolicy("rotation_rank_battle", PolicyKind.PvpFirstThenAiFallback),
new ModePolicy("unlimited_rank_battle", PolicyKind.PvpFirstThenAiFallback),
}));
builder.Services.AddSingleton<IMatchingPairUpService, InProcessPairUp>();
builder.Services.AddTransient<ShadowverseTranslationMiddleware>();