From 49ba10bca6faa5d25e92a7088e4c41f729a257bc Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sun, 20 Sep 2026 21:07:49 -0600 Subject: [PATCH] Pin the event roll in the foundering-voyage test The test patched randint and random but not rollEvent's random.choice, so a run that drew only harmless events never foundered - red about one run in forty, including on main at b68b09a. Every leg now presents the leak, whose first choice always damages. Thirty consecutive runs green. Closes #200 Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01KaGDnS44p4wsoDADXhyh9M --- tests/location/test_docks.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/location/test_docks.py b/tests/location/test_docks.py index 1d5710f..903f8a0 100644 --- a/tests/location/test_docks.py +++ b/tests/location/test_docks.py @@ -1504,10 +1504,17 @@ def test_a_voyage_that_founders_ends_early(): docksInstance.userInterface.showDialogue = MagicMock() startingDay = docksInstance.timeService.day - # call - every damage roll at its worst - with patch("src.business.adventures.random.randint", return_value=99): - with patch("src.business.adventures.random.random", return_value=0.0): - docksInstance.takeTheHelm() + # call - every leg presents the leak, whose first choice always damages, + # and every damage roll is at its worst. rollEvent draws from the role's + # pool with random.choice, which the two patches below never covered: + # a run that drew driftwood, calm water or good grounds every leg took + # no damage and never foundered, and the test failed about one run in + # forty (#200). + leak = next(event for event in adventures.EVENTS if event["id"] == "leak") + with patch("src.business.adventures.rollEvent", return_value=leak): + with patch("src.business.adventures.random.randint", return_value=99): + with patch("src.business.adventures.random.random", return_value=0.0): + docksInstance.takeTheHelm() # check - she came home early with nothing, but she came home assert docksInstance.timeService.day < startingDay + plan["legs"]