From 3d06f49f3ccc7503ee0eade82f93b34ef65e404c Mon Sep 17 00:00:00 2001 From: Ilia Denisov Date: Tue, 19 May 2026 10:13:25 +0200 Subject: [PATCH] fix(generator): drop incorrect distinctness assert in TestPlanetRandomName MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `RandomName` builds the suffix as two independent `rand.Intn(1000)` calls, so the two 4-digit halves collide on ~0.1% of runs. The sub-test asserted `g[2] != g[3]`, which flakes whenever the same value lands twice — once per ~1000 sub-runs per class, so across the seven `PlanetClass` rows the integration suite hit it on `#199 go-unit.yaml` against `feature/subscribe-events-heartbeat` (`"0074"` collision). Distinctness is not a property `RandomName` promises and is not load-bearing for callers: `game/internal/controller/generate_game.go` uses these names for planet labels and already tolerates duplicate names across planets, so collisions inside one name are no worse than collisions between names. Drop the assert; keep the format and class-prefix checks, which are the actual contract. Stress-tested with `-count=200`: 200 consecutive iterations × 7 classes = 1400 sub-runs without a single failure where the prior version's flake probability would have surfaced ~once on average. Co-Authored-By: Claude Opus 4.7 (1M context) --- game/internal/generator/planet_test.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/game/internal/generator/planet_test.go b/game/internal/generator/planet_test.go index 6995b38..3fad418 100644 --- a/game/internal/generator/planet_test.go +++ b/game/internal/generator/planet_test.go @@ -18,14 +18,21 @@ func TestPlanetRandomName(t *testing.T) { for _, pc := range []g.PlanetClass{g.PlanetClassHW, g.PlanetClassDW, g.PlanetClassGiant, g.PlanetClassBig, g.PlanetClassNormal, g.PlanetClassRich, g.PlanetClassAsterioid} { t.Run(string(pc), func(t *testing.T) { name := g.NewPlanet(pc, g.Coordinate{0, 0}, 0, 0).RandomName() - g := re.FindStringSubmatch(name) - assert.NotNilf(t, g, "cannot parse: %q", name) - if g == nil { + // `RandomName` formats `-<4-digit>-<4-digit>`, + // where each suffix is an independent `rand.Intn(1000)`. + // We assert the wire format and the class prefix; an + // earlier revision also asserted `g[2] != g[3]`, which + // flaked on the legitimate ~0.1% collision (a property + // the function does not — and need not — guarantee: + // `generate_game.go` already tolerates duplicate names + // across planets). + groups := re.FindStringSubmatch(name) + assert.NotNilf(t, groups, "cannot parse: %q", name) + if groups == nil { return } - assert.Equalf(t, 4, len(g), "regexp groups") - assert.Equal(t, string(pc), g[1]) - assert.NotEqual(t, g[2], g[3]) + assert.Equalf(t, 4, len(groups), "regexp groups") + assert.Equal(t, string(pc), groups[1]) }) } } -- 2.52.0