refactor: extract router helpers into utils.py (closes #582)#945
Open
ScarsAndSource wants to merge 1 commit into
Open
refactor: extract router helpers into utils.py (closes #582)#945ScarsAndSource wants to merge 1 commit into
ScarsAndSource wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Identified and extracted two repeated code patterns from the analysis routers into a new
backend/app/routers/utils.pymodule:Duplicate 1 — 13-line issue-count + payload block existed identically in
debugging.pyandanalyze.py/_stream_analysis:Duplicate 2 —
detect_language(req.code, req.language)repeated in every analysis router (debugging.py,explanation.py,suggestions.py)Files Changed
Created:
backend/app/routers/utils.py— new utilities module with two helpers:build_debugging_payload(issues, code=None)— centralises severity counting, summary formatting, and payload assemblyresolve_language(req)— wrapsdetect_language(req.code, req.language)used across all routersbackend/tests/test_router_utils.py— 10 unit tests covering all branches of both helpersReplaced:
backend/app/routers/debugging.py— removed 10 inline lines; now callsresolve_language()andbuild_debugging_payload()backend/app/routers/analyze.py— removed 13-line duplicate block inside_stream_analysis; now callsbuild_debugging_payload()backend/app/routers/explanation.py— swappeddetect_language(req.code, req.language)→resolve_language(req)backend/app/routers/suggestions.py— swappeddetect_language(req.code, req.language)→resolve_language(req)No behaviour changes: all existing tests pass.
Related Issue
Fixes #582
Type of change
Checklist
mainpytest -vand all tests passfeat/fix/docs/test: short descriptionScreenshots (if frontend change)
Test evidence
pytest -v # paste output