refactor(server): extract the enrichment route handlers into routers/enrichment.py (R3) - #868
Conversation
…enrichment.py (R3) The 14 /api/enrichment/* routes — status, kick/cancel, per-song state, the Match-Review queue (accept/reject/pick/search/rematch/refresh/states), and the AcoustID fingerprint identify endpoints — plus the route-exclusive candidate sanitizer move to lib/routers/enrichment.py. Bodies verbatim except @app->@router and the seam reads (meta_db->appstate.meta_db, CONFIG_DIR->appstate.config_dir). The enrichment engine (transport, matcher, worker, upload caps) already lives in lib/enrichment.py from the earlier subsystem move and is reached as enrichment.X. No new seams. server.py: 2,925 -> 2,638 (-287). Verified: pyflakes clean; route set identical (143); full pytest 2396 passed (the enrichment route + Match-Review + identify cases, which fake the network on the enrichment module). eslint 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe enrichment API surface was moved from ChangesEnrichment router extraction
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
lib/routers/enrichment.py (1)
86-86: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRuff B008 here is a false positive for FastAPI.
Body(...)(andQuery/Depends) in parameter defaults is the intended FastAPI idiom, so don't rewrite these handlers (also flagged at Lines 114, 163, 210). To silence it repo-wide across all routers, add the FastAPI factories to Bugbear's immutable-call allowlist in your Ruff config, e.g.:[tool.ruff.lint.flake8-bugbear] extend-immutable-calls = ["fastapi.Body", "fastapi.Query", "fastapi.Depends", "fastapi.File", "fastapi.Form"]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/routers/enrichment.py` at line 86, Add the FastAPI dependency factories Body, Query, Depends, File, and Form to Ruff’s flake8-bugbear extend-immutable-calls configuration, preserving the existing handler signatures such as api_enrichment_rematch and the other router handlers.Source: Linters/SAST tools
server.py (1)
1807-1830: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTrailing blank-line artifact from the deleted handler block. ~24 consecutive blank lines remain where the inline
/api/enrichment/*handlers used to live. Collapse to the normal 2-blank-line spacing before the next top-level statement to keep the diff clean (and avoid an E303-style lint if Ruff runs overserver.py).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server.py` around lines 1807 - 1830, Remove the excessive consecutive blank lines left by the deleted inline enrichment handlers in server.py, restoring standard two-blank-line spacing before the next top-level statement. Do not alter the surrounding handler or statement logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/routers/enrichment.py`:
- Line 86: Add the FastAPI dependency factories Body, Query, Depends, File, and
Form to Ruff’s flake8-bugbear extend-immutable-calls configuration, preserving
the existing handler signatures such as api_enrichment_rematch and the other
router handlers.
In `@server.py`:
- Around line 1807-1830: Remove the excessive consecutive blank lines left by
the deleted inline enrichment handlers in server.py, restoring standard
two-blank-line spacing before the next top-level statement. Do not alter the
surrounding handler or statement logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3c94e406-61be-4836-8775-6ef6a0daed42
📒 Files selected for processing (4)
CHANGELOG.mddocs/size-exemptions.mdlib/routers/enrichment.pyserver.py
The 14
/api/enrichment/*routes — status, kick/cancel, per-song state, the Match-Review queue (accept/reject/pick/search/rematch/refresh/states), and the AcoustID fingerprint identify endpoints — plus the route-exclusive candidate sanitizer →lib/routers/enrichment.py.Bodies verbatim except
@app→@routerand the seam reads (meta_db→appstate.meta_db,CONFIG_DIR→appstate.config_dir). The enrichment engine (transport, matcher, worker, upload caps) already lives inlib/enrichment.pyfrom the earlier subsystem move and is reached asenrichment.X. No new seams.server.py: 2,925 → 2,638 (−287).Verification
pyflakesclean; route set identical (143).pytest2396 passed (the enrichment route + Match-Review + identify cases, which fake the network on theenrichmentmodule).npm run lint0; Codex 0 findings.🤖 Generated with Claude Code
Summary by CodeRabbit