Skip to content

test-audit: fix RNG-reuse bug, trim an oversized test loop#758

Merged
stphung merged 1 commit into
mainfrom
claude/lucid-brahmagupta-e6wdh7
Jul 15, 2026
Merged

test-audit: fix RNG-reuse bug, trim an oversized test loop#758
stphung merged 1 commit into
mainfrom
claude/lucid-brahmagupta-e6wdh7

Conversation

@stphung

@stphung stphung commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • tests/game_tick_tests/game_loop_test.rs's simulate_tick()/simulate_ticks() helpers reseeded a fresh ChaCha8Rng on every call, so multi-tick test loops replayed the identical "random" roll every tick instead of a real sequence. Threaded one RNG through each affected loop instead (spawn/combat/regen/kill-tracking tests), and removed the now-unused simulate_tick() wrapper.
  • tests/combat_tests/combat_submodules_test.rs::test_consecutive_deaths_triggers_retreat looped 100 times for an event that actually resolves within ~20 ticks (one enemy attack interval of 2.0s at 0.1s/tick); trimmed the bound to 40 for a comfortable 2x margin.

Found via /test-audit. The three-agent audit also surfaced a larger set of redundant/duplicate test coverage across deep_tests/, game_tick_tests/, and achievement_tests/, plus a known-tracked ~40-instance brute-force RNG-search category — left untouched as those need human judgment on consolidation, not mechanical fixes.

Test plan

  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test (full suite, 0 failures)
  • QUEST_ACT2=1 cargo test flag_on
  • cargo run --release --bin simulator -- --check-progression
  • cargo run --release --bin voyage_simulator
  • cargo test x10 consecutive runs — 0 failures (flakiness check)

Generated by Claude Code

game_loop_test.rs's simulate_tick()/simulate_ticks() reseeded a fresh
ChaCha8Rng on every call, so multi-tick loops replayed the same "random"
roll every tick instead of a real sequence. Thread one RNG through each
loop instead.

combat_submodules_test.rs's test_consecutive_deaths_triggers_retreat
looped 100 times for an event that resolves within ~20 ticks (one enemy
attack interval); trimmed to 40 for a comfortable margin.

Found by /test-audit.
@stphung stphung marked this pull request as ready for review July 15, 2026 16:33
@stphung stphung enabled auto-merge (squash) July 15, 2026 16:33
@stphung stphung merged commit 364e869 into main Jul 15, 2026
9 checks passed
@stphung stphung deleted the claude/lucid-brahmagupta-e6wdh7 branch July 15, 2026 16:38
@stphung stphung mentioned this pull request Jul 15, 2026
1 task
stphung added a commit that referenced this pull request Jul 15, 2026
PR #758 fixed an RNG-reuse bug in game_loop_test.rs and trimmed an
oversized loop in combat_submodules_test.rs; remaining findings
(redundant test coverage across deep_tests/game_tick_tests/
achievement_tests, and two production-side unseeded-RNG call sites)
are flagged for human review, not auto-fixed.

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants