Skip to content

[IIRR-39] Add archived puzzle seeds for low success rate filter testing#77

Merged
arielj merged 7 commits into
mainfrom
feature/seed-archived-puzzles
May 19, 2026
Merged

[IIRR-39] Add archived puzzle seeds for low success rate filter testing#77
arielj merged 7 commits into
mainfrom
feature/seed-archived-puzzles

Conversation

@JuanVqz
Copy link
Copy Markdown
Member

@JuanVqz JuanVqz commented May 18, 2026

https://ombulabs.atlassian.net/browse/IIRR-39

Summary

  • Adds 7 archived (already sent) puzzles to db/seeds.rb with deterministic success rates spanning the last 7 days
  • Seeds answers for all 10 users against each archived puzzle so correct_answer_percentage returns real data
  • Each archived puzzle has a fixed success_rate (20, 40, 50, 70, 80, 90, 100). The seed assigns is_correct via user_idx < rate / 10, so the resulting percentages are exact across runs
  • Adds 4 cloned puzzles (2 pending, 2 archived) with original_puzzle_id set, so the "Hide cloned puzzles" filter from IIRR-33: Filter out cloned archived puzzles #78 has data to filter. Clone questions are suffixed with (clone) to make them easy to spot during manual testing
  • Removes the prior block that seeded random answers against approved puzzles. In reality only archived puzzles can have answers, so seeding them on approved was wrong

Context

Follow-up to #76 (low success rate filter) and #78 (hide cloned puzzles filter). Both filters need archived puzzles with known success rates and a mix of cloned/uncloned originals to be exercised locally.

Also includes a small fix to DailyPuzzleJobTest#test_marks_the_selected_puzzle_as_archived_and_sets_sent_at: clears any other approved + sent_at: nil puzzles before invoking the job, so the test no longer depends on which eligible puzzle the job picks at random. This was a pre-existing flake exposed once #76 removed sent_at from the :one fixture.

Test plan

  • Run bin/rails db:seed:replant
  • Navigate to the Archived Puzzles section
  • Verify 9 archived puzzles appear (7 originals + 2 archived clones suffixed with (clone))
  • Click "Show low success rate only" and verify only the 7 puzzles with rate ≤ 80 remain (the reduce 90% and validates 100% puzzles disappear)
  • Click "Hide cloned puzzles" and verify the 4 parents that have clones are hidden from the archived table
  • Combine both filters and verify the intersection behaves correctly
  • Run bin/rails test and confirm all tests pass

@JuanVqz JuanVqz requested a review from arielj May 18, 2026 19:54
@JuanVqz JuanVqz marked this pull request as ready for review May 18, 2026 19:54
@JuanVqz JuanVqz changed the title Add archived puzzle seeds for low success rate filter testing [IIRR-39] Add archived puzzle seeds for low success rate filter testing May 18, 2026
Comment thread db/seeds.rb
Comment thread db/seeds.rb Outdated
3.times do
puzzle = Puzzle.all.sample
puzzle = Puzzle.approved.sample
next unless puzzle
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this realistically ever happen? like... if the seed depends on approved puzzles we should be sure we have approved puzzles at this point instead of this conditional

it's also weird to have answers for approved puzzles, in real life we can only have answers for archived puzzles, approved puzzles have not been sent yet, so maybe the seed was always wrong creating answers for puzzles with any state other than archived

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like maybe we should remove this block directly

JuanVqz added 4 commits May 19, 2026 09:57
Adds 7 archived puzzles: 5 with random low/mixed answer rates and 2
with 90% correct rate to support manual testing of the low success rate
filter without needing production data.
- Remove random answers for approved puzzles. Real users only answer
  puzzles after they've been sent (archived state).
- Add two cloned puzzles so the 'hide cloned puzzles' filter from #78
  has data to filter.
Mix two pending clones with two archived clones so the 'hide cloned'
filter can be exercised across both states.
The :one fixture is approved with no sent_at, so it's eligible for
DailyPuzzleJob. The job picks one approved+unsent puzzle at random,
which made this test flaky depending on which puzzle was picked.
Clear the eligible pool before creating the puzzle under test, mirroring
the pattern in 'does nothing when no approved unsent puzzles exist'.
@JuanVqz JuanVqz force-pushed the feature/seed-archived-puzzles branch from 0b513b6 to 36deac3 Compare May 19, 2026 16:00
JuanVqz added 3 commits May 19, 2026 10:46
- Replace high_success boolean with per-puzzle success_rate (20, 40, 50,
  70, 80 for low; 90, 100 for high). user_idx < rate/10 makes the seeded
  correct/incorrect distribution exact across runs.
- Append '(clone)' to cloned puzzle questions so they are easy to spot
  in the archived table during manual testing.
- Clones inherit their parent's success_rate via original_puzzle lookup.
Now that each archived puzzle carries an explicit success_rate, the
correct-answer distribution no longer needs to ride along inside the
user loop. Iterating per puzzle and picking the first N server users
per puzzle reads more directly: 'for each puzzle, mark rate/10 users
correct'. The user loop is now purely about creating users and linking
them to the server.
Both groups already had the same shape; archived just carried extra
fields (state, sent_at, success_rate). Folding them into one array
removes the duplicated find_or_create_by! loop and gives a single
place to add new puzzles. Entries without an explicit state fall back
to the column default (:pending), preserving existing behavior.
@JuanVqz JuanVqz requested a review from arielj May 19, 2026 16:58
@arielj
Copy link
Copy Markdown
Contributor

arielj commented May 19, 2026

looks good!

@arielj arielj merged commit ea64586 into main May 19, 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.

2 participants