From d240cd5d940fb2515a30d0a2858a756b7d5faf92 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 5 Apr 2026 20:35:48 +0000 Subject: [PATCH] Fix flaky Champions Stage stochastic test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The makeTeams(8) helper creates only a 70-pt Elo spread (1800→1730). With the Champions Stage bracket math this gives team-0 a ~19.6% win rate — right at the 0.2 threshold, causing the test to fail ~63% of the time in CI despite 1000 iterations. Use 100-pt steps (1800→1100) instead, giving team-0 a ~40% win rate and raising the assertion threshold to 0.25 for a clear safety margin. https://claude.ai/code/session_019w21Nkf5TvTZHH6oVHaQXR --- .../__tests__/cs-major-simulator.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/services/simulations/__tests__/cs-major-simulator.test.ts b/app/services/simulations/__tests__/cs-major-simulator.test.ts index 78861b6..f57efad 100644 --- a/app/services/simulations/__tests__/cs-major-simulator.test.ts +++ b/app/services/simulations/__tests__/cs-major-simulator.test.ts @@ -217,14 +217,21 @@ describe("simulateChampionsStage", () => { }); it("top Elo team wins more often than last (stochastic)", () => { - const teams = makeTeams(8); - // team-0 has highest Elo, team-7 has lowest + // Use a clear Elo spread so team-0 has a decisive advantage. + // makeTeams(8) only gives a 70-pt gap (1800→1730) which puts the + // true win rate right at the 0.2 threshold — extremely flaky. + // 100-pt steps (1800→1100) give team-0 a ~40% win rate, well clear of 0.25. + const teams = Array.from({ length: 8 }, (_, i) => ({ + id: `team-${i}`, + elo: 1800 - i * 100, + rank: i + 1, + })); let wins = 0; for (let i = 0; i < 1000; i++) { const result = simulateChampionsStage(teams); if (result.placements.get("team-0") === 1) wins++; } - // Should win significantly more than 12.5% of the time (1/8 random) - expect(wins / 1000).toBeGreaterThan(0.2); + // Should win well above 12.5% (1/8 random baseline) + expect(wins / 1000).toBeGreaterThan(0.25); }); });