Skip to content

Stop the stocked-floor re-seed test assuming a fourth room - #399

Merged
calebl merged 1 commit into
mainfrom
fm/ta-flaky-loader-538
Dec 3, 2026
Merged

calebl merged 1 commit into
mainfrom
fm/ta-flaky-loader-538

Conversation

@calebl

@calebl calebl commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

What failed

On #398, CI attempt 1 failed with this error, and the PR did not touch the test:

WorldSeed::LoaderTest#test_re-seeding_a_laid-out_floor_leaves_its_supplies_and_its_safe_room:
NoMethodError: undefined method 'update!' for nil
    test/lib/world_seed/loader_test.rb:543

Cause

The cause is in the test, not in the app. The test lays out "The Stocked Floor" with Location::Interior.lay_out! and then uses rooms.fourth. lay_out! takes its roll from Roll.generator(story: story.id, sequence: place.id, kind: Roll::INTERIOR). That is a deliberate choice: the interior's header says "KEYED ON THE PLACE'S ID". The Ruby layout also does not read the floor's rooms: 4; it rolls storeys and rooms per storey (ROOMS_PER_STOREY, at least 2). So the room count depends on which ids the rows get:

  • In a fresh test database the ids are always (story 1, place 2). That pair lays out 12 rooms, so the test passed every time locally.
  • In CI, a non-transactional test that ran earlier in the same worker (several set use_transactional_tests = false) moves the sequence. The floor then gets a different place id.
  • Across 800 synthetic (story, place) id pairs (story 1–20, place story+1 to story+40), 119 laid out 2 or 3 rooms, about 15%. For every one of those, rooms.fourth is nil.

Reproduction: before and after

A throwaway subclass of LoaderTest (not committed) set the locations row of sqlite_sequence to SHIFT before each test. It then ran only this test for shifts 0–39:

  • Before: 6 of 40 shifts failed (2, 7, 17, 18, 20, 39), with the same NoMethodError as CI.
  • After: 0 of 40 failed. The range includes shifts 13 and 33, whose ids lay the floor out as only 2 rooms.

Fix

The test now puts the safe room and the two draughts in the first and last non-entry rooms, which exist in any layout. Before, it used rooms.second and rooms.fourth. The entry room is still never stocked, as the world file says. Every assertion is the same as before: the safe room keeps sanctuary, each draught keeps its id, room and supply, the floor's counts are cleared, and the landing's own draught is left alone. A comment on the test explains why it must not assume a room count.

This change touches only the test: no app code, model-facing text, world file or engine.

Checks

Run with OPENROUTER_API_KEY and TYPESAFE_API_KEY unset:

  • bin/rails test: 5507 runs, 0 failures, 0 errors, 0 skips
  • bundle exec rubocop: no offenses
  • bin/rails zeitwerk:check: all good
  • bin/brakeman --no-pager: 0 warnings

"re-seeding a laid-out floor leaves its supplies and its safe room" put
its safe room and a draught in rooms.fourth. Location::Interior.lay_out!
rolls from the story's and the place's ids and does not read the floor's
`rooms: 4`, so some id pairs lay the floor out as two or three rooms and
rooms.fourth is nil. Locally the ids are always the same, so it passed
every time. In CI an earlier non-transactional test in the same worker
moves the ids, which is how it failed once.

The safe room and the draughts now go in the first and last non-entry
rooms, which every layout has. The assertions are unchanged.
@calebl
calebl merged commit 6335f50 into main Dec 3, 2026
4 checks passed
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.

1 participant