Skip to content

fix(fraud): exclude system whodunnit from reviewer credit, allow month-scoped payout runs - #1231

Draft
NeonGamerBot-QK wants to merge 1 commit into
hackclub:mainfrom
NeonGamerBot-QK:fix/fraud-payout-user-0-and-month-run
Draft

fix(fraud): exclude system whodunnit from reviewer credit, allow month-scoped payout runs#1231
NeonGamerBot-QK wants to merge 1 commit into
hackclub:mainfrom
NeonGamerBot-QK:fix/fraud-payout-user-0-and-month-run

Conversation

@NeonGamerBot-QK

Copy link
Copy Markdown
Member

what's this do?

Two changes to the fraud squad payout system:

  1. Fixes a bug where the admin fraud payouts leaderboard showed a "User #0" row. Shop::AutoApprovable stamps its PaperTrail whodunnit with a class-name string ("Shop::AutoApprovable") for unattended system approvals, not a user id. FraudPayoutRun.reviewer_from_version was blindly doing whodunnit.to_i on it, and "Shop::AutoApprovable".to_i == 0 in Ruby, so those auto-approved orders got silently attributed to a fake "reviewer #0" and rendered as "User #0" in the admin UI. FraudPayoutRun.reviewer_versions now only considers versions with a purely numeric whodunnit, matching the same guard ShopOrder.leaderboard already uses for this exact problem.
  2. Lets admins trigger a payout run scoped to a specific calendar month, instead of only "everything since the last run." Added a month picker next to the existing "Trigger Manual Run" button on /admin/fraud_payouts. Fraud::CalculatePayoutsJob#perform now takes optional period_start/period_end; already-paid orders stay excluded regardless (via payout_eligible_orders), so re-running an old month can't double-pay.

show it works

Added test coverage for both changes:

  • test/jobs/fraud/calculate_payouts_job_test.rb: a new test asserts explicit period bounds only pick up orders created inside that window and ignore everything else.
  • test/controllers/admin/fraud_payouts_controller_test.rb: new tests assert trigger with a valid month param enqueues the job with the correct start/end, and that an unparseable month enqueues nothing and shows an alert.

I wrote these against the existing test conventions in both files, but I was not able to run the suite myself — my local environment has no Docker daemon running and the gems aren't installed on the host, so bin/rails test isn't runnable from where I am. Please run before merging:

docker compose run --service-ports web bin/rails test test/jobs/fraud/calculate_payouts_job_test.rb test/controllers/admin/fraud_payouts_controller_test.rb

ai?

Yes — this PR (investigation, diagnosis, code, and tests) was written with Claude Code (Sonnet 5), with me directing/reviewing each step and reading the actual diffs before asking for the PR. I have not run the test suite myself (see above) and would appreciate a careful review + a CI/local test run before merge.

…h-scoped payout runs

Shop::AutoApprovable stamps ShopOrder PaperTrail versions with a class-name
whodunnit ("Shop::AutoApprovable") for system approvals, which
FraudPayoutRun.reviewer_from_version blindly coerced via .to_i into a fake
reviewer id of 0, showing up as "User #0" on the admin fraud payouts
leaderboard. reviewer_versions now only considers numeric whodunnit values,
matching the guard ShopOrder.leaderboard already used for the same problem.

Also lets admins trigger a fraud payout run scoped to a specific calendar
month (instead of only "everything since the last run"), via a month picker
on the admin fraud payouts page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Signed-off-by: Neon <neon@saahild.com>
@NeonGamerBot-QK
NeonGamerBot-QK marked this pull request as draft September 4, 2026 01:49
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