feat: enforce trade deadline in /trade commands #121
No reviewers
Labels
No Label
ai-changes-requested
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
in-next-release
status/in-progress
status/pr-open
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-v2#121
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/trade-deadline-enforcement"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
is_past_trade_deadlineproperty to theCurrentmodel (offseason-aware, inclusive of deadline week)/trade initiate, Submit button, and_finalize_tradeagainst trades after the deadlineTests
Test plan
python -m pytest— all 981 passtrade_deadlinevalue🤖 Generated with Claude Code
All 981 tests pass. Trade deadline enforcement is correct — fails closed on missing API data, guards all three entry points (/trade initiate, Submit button, _finalize_trade), and the model-level property handles offseason edge cases cleanly. Approving.
AI Code Review
Files Reviewed
models/current.py(modified — addedis_past_trade_deadlineproperty)commands/transactions/trade.py(modified — deadline guard intrade_initiate)views/trade_embed.py(modified — deadline guards insubmit_buttonand_finalize_trade)tests/test_commands_trade_deadline.py(added)tests/test_models.py(modified — addedtest_is_past_trade_deadline)Findings
Correctness
is_past_trade_deadlinelogic is correct:week > trade_deadline(allowing trading on the deadline week itself), with an offseason bypass (week > 18→False). Matches the PR description exactly.trade_initiate,submit_button,_finalize_trade) implement the same fail-closed pattern correctly._finalize_trade, the oldnext_week = current.week + 1 if current else 1fallback is removed — the1fallback was a silent lie that would have applied trades to week 1 if the API was unavailable. The newreturnonnot currentis strictly safer.league_servicewas already imported inviews/trade_embed.py(already used by_finalize_trade), so no missing import.call_kwargs[0][0]) correctly matches the positional string arg passed tofollowup.send. ✓Security
Style & Conventions
"❌ ...") are consistent with other quick error messages intrade.py.test_trade_initiate_allowed_at_deadline_weektest correctly patchesclear_trade_builderand asserts it was called — this verifies the deadline check was passed, not just that no error was sent. Good approach.Suggestions
submit_buttonand_finalize_tradedeadline checks are not covered by the new tests — all 3 command-level tests targettrade_initiate. These paths follow the same pattern and are likely correct, but a race-condition scenario (deadline passes between initiation and submission) is exactly the kind of edge case worth covering.is_past_trade_deadlinereturnsFalseduring the offseason (week > 18), effectively re-opening trades. This is presumably intentional (off-season trading window), but it may be worth a comment in the property docstring clarifying why the offseason bypasses the deadline, so future readers don't mistake it for a bug.Verdict: COMMENT
Clean, correct implementation. The fail-closed approach and the three-layer guard (initiate → submit → finalize) are all sound. Minor gap: the view-level deadline checks in
submit_buttonand_finalize_tradehave no corresponding tests, but the logic is straightforward and the pattern is identical to the testedtrade_initiateguard. Mergeable as-is.Automated review by Claude PR Reviewer