Skip to content

refactor(#101): extract backfill-age routes to backfill_routes.py - #200

Merged
jphein merged 1 commit into
mainfrom
refactor/101-mainpy-split
May 30, 2026
Merged

refactor(#101): extract backfill-age routes to backfill_routes.py#200
jphein merged 1 commit into
mainfrom
refactor/101-mainpy-split

Conversation

@jphein

@jphein jphein commented May 30, 2026

Copy link
Copy Markdown
Collaborator

What

Extracts the AGE-backfill route cluster out of main.py into a new backfill_routes.py — the next clean slice for #101.

Symbol Was Now
POST /backfill-age main.py backfill_routes.py (APIRouter)
GET /backfill-age/status main.py backfill_routes.py (APIRouter)
_backfill_state / _backfill_lock main.py module state backfill_routes.py (private to these handlers — no other call site)
_backfill_unprocessed_breakdown main.py backfill_routes.py (re-exported by main for tests)

main.py: 3116 → 2907 lines (−209). New module is 270 lines.

How (same pattern as slice #3 / search_routes.py)

  • Handlers resolve main-owned symbols (_check_auth, _check_viz_auth, _mp) via lazy import main at request time, so the test suite's patches on those names stay effective and tests are unmodified.
  • BackfillAgeBody (from search_models) and record_db_error (from db_errors) are imported directly — neither imports main, so no circular import (search_routes.py imports search_models the same way).
  • _backfill_state / _backfill_lock move outright (grep confirmed no other main.py call site). They're shared by reference within the module and never rebound, so mutation semantics are identical.
  • main.py mounts via app.include_router(_backfill_router) and re-exports the pure _backfill_unprocessed_breakdown so tests/test_backfill_unprocessed.py keeps resolving main._backfill_unprocessed_breakdown unchanged.

Behavior

Pure refactor — no logic change. The only non-mechanical edit is lifting the function-local import logging in backfill_age_status's except clause to a module-level import.

Verification

  • Full suite: 603 passed, 1 skipped, 20 subtests — identical to the pre-change baseline.
  • Both routes confirmed registered on app; main._backfill_unprocessed_breakdown is backfill_routes._backfill_unprocessed_breakdown.
  • No orphaned imports left in main.py (BackfillAgeBody / Body were backfill-only and removed; record_db_error still used 5× elsewhere, kept).
  • ruff not available in this environment; relied on py_compile + the test suite.

Refactor only — not deployed to familiar (deploy is separate).

🤖 Generated with Claude Code

Move POST /backfill-age + GET /backfill-age/status out of main.py into a
new backfill_routes.py APIRouter, along with their shared run-state
(_backfill_state / _backfill_lock — private to these handlers, no other
call site) and the _backfill_unprocessed_breakdown query helper.

Follows the proven #101 slice-#3 (search_routes.py) pattern:
- handlers resolve main-owned symbols (_check_auth, _check_viz_auth, _mp)
  via lazy `import main` at request time, so test patches on those names
  stay effective and the suite is unmodified;
- BackfillAgeBody (search_models) and record_db_error (db_errors) are
  imported directly — neither imports main, so no circular import;
- main.py mounts via app.include_router and re-exports the pure
  _backfill_unprocessed_breakdown so tests/test_backfill_unprocessed.py
  keeps resolving main._backfill_unprocessed_breakdown unchanged.

Pure refactor, behavior identical. main.py 3116 -> 2907 lines (-209).
Full suite: 603 passed, 1 skipped, 20 subtests — same as baseline.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 30, 2026 06:49
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jphein
jphein merged commit 644d884 into main May 30, 2026
1 check failed
@jphein
jphein deleted the refactor/101-mainpy-split branch May 30, 2026 06:56
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