Skip to content

Extract bounty attempt helpers#363

Closed
TUPM96 wants to merge 1 commit into
ramimbo:mainfrom
TUPM96:codex/bounty-320-attempt-helpers
Closed

Extract bounty attempt helpers#363
TUPM96 wants to merge 1 commit into
ramimbo:mainfrom
TUPM96:codex/bounty-320-attempt-helpers

Conversation

@TUPM96
Copy link
Copy Markdown
Contributor

@TUPM96 TUPM96 commented May 26, 2026

Refs #320

Summary

  • Extract bounty-attempt status, serialization, warning, active-condition, and stale-expiration helpers from app/main.py into app/bounty_attempts.py.
  • Add focused helper tests for expired active attempts, warning generation, and stale attempt expiration.
  • Keep checks green by removing redundant ledger casts reported by mypy app and by sanitizing percent-decoded OAuth next paths covered by the existing OAuth regression test.

Complexity reduced

app/main.py no longer owns bounty-attempt serialization and query helper logic used by REST routes and MCP dispatch. Attempt behavior now lives in a small module with direct tests, leaving route handlers focused on auth, request parsing, and response status.

Tests

  • python -m pytest -q -> 337 passed
  • python -m pytest tests/test_bounty_attempt_helpers.py tests/test_bounty_attempts.py tests/test_api_mcp.py::test_mcp_list_bounty_attempts_reports_active_and_expired tests/test_ledger.py -q -> 36 passed
  • python -m ruff format --check app/main.py app/ledger/service.py app/bounty_attempts.py tests/test_bounty_attempt_helpers.py
  • python -m ruff check app/main.py app/ledger/service.py app/bounty_attempts.py tests/test_bounty_attempt_helpers.py
  • python -m mypy app

Copilot AI review requested due to automatic review settings May 26, 2026 01:59
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@TUPM96, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 11 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c36aba4b-ce46-47ef-ba03-e13b8bf565fe

📥 Commits

Reviewing files that changed from the base of the PR and between ac99d79 and 40f5696.

📒 Files selected for processing (4)
  • app/bounty_attempts.py
  • app/ledger/service.py
  • app/main.py
  • tests/test_bounty_attempt_helpers.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR extracts bounty-attempt helper logic from app/main.py into a dedicated module, adds focused unit tests for the new helpers, and includes a small hardening update to _safe_next_path plus minor typing cleanup in ledger service.

Changes:

  • Added app/bounty_attempts.py to host attempt serialization, status/warnings, and expiration helpers.
  • Updated app/main.py to use the extracted helpers and improved _safe_next_path validation by checking decoded input.
  • Added tests/test_bounty_attempt_helpers.py to cover expiration/status/warnings behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/test_bounty_attempt_helpers.py Adds tests validating attempt serialization/status and warnings/expiration flows.
app/main.py Switches to extracted bounty-attempt helpers and strengthens next path validation using decoding.
app/ledger/service.py Removes unnecessary typing casts around session.execute(...update...) results.
app/bounty_attempts.py New standalone module for attempt helper functions previously embedded in app/main.py.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/bounty_attempts.py
return value.astimezone(UTC)


def attempt_effective_status(attempt: BountyAttempt, now: datetime) -> str:
Comment thread app/main.py
Comment on lines 222 to 236
def _safe_next_path(next_path: str | None) -> str:
decoded_next_path = unquote(next_path) if next_path else ""
if (
not next_path
or not next_path.startswith("/")
or next_path.startswith("//")
or len(next_path) > 2048
or "\\" in next_path
or decoded_next_path.startswith("//")
or "\\" in decoded_next_path
or any(ord(char) < 32 or 127 <= ord(char) < 160 for char in next_path)
or any(ord(char) < 32 or 127 <= ord(char) < 160 for char in decoded_next_path)
):
return "/me"
return next_path
@TUPM96
Copy link
Copy Markdown
Contributor Author

TUPM96 commented May 26, 2026

Closing this duplicate because #362 is the focused, CI-green PR for the Bounty #320 bounty-attempt helper extraction. This branch also pulled in unrelated follow-up changes.

@TUPM96 TUPM96 closed this May 26, 2026
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