refactor: Comprehensive architecture refactoring#31
Conversation
## Test Organization (One Class Per File) - Split test_models.py into 5 separate files (test_search_result.py, test_api_search_result.py, etc.) - Split test_content_scraper.py into 3 files by scenario (test_success_cases.py, test_error_cases.py, test_edge_cases.py) - Split test_duckduckgo_client.py into 2 files (with/without library) - Split test_search_service.py into 2 files (with/without Serper key) - Result: 44 tests passing, improved test organization and maintainability ## Module Reorganization - Split api_tools.py (405 lines) into focused modules: - models/responses/api_responses.py (API response models) - services/search_orchestrator.py (search logic with fallbacks) - tools/api_tools_setup.py (MCP tool setup) - Split health.py (281 lines) into focused modules: - models/responses/health_responses.py (health response formatters) - endpoints/health_endpoints.py (endpoint handlers) - endpoints/demo_client.py (demo client serving) - endpoints/app_factory.py (FastAPI app factories) - Reorganized models/ directory: - models/domain/ (SearchResult, APISearchResult) - models/responses/ (API responses, health responses) - All original files now import from new locations with deprecation warnings for backward compatibility ## Consolidation - Removed demo_server.py (kept simple_demo.py as single demo server) - Removed debug_search.py (debug script) - Removed old_tests/ directory (5 obsolete test files) ## Benefits - Single responsibility principle enforced throughout - Test files follow "one class per file" standard - Clear separation: domain models vs API responses vs endpoints vs services - Reduced largest files from 405 and 281 lines to focused <150 line modules - Better discoverability and maintainability - All existing imports still work via backward compatibility shims 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Updated endpoint from /client to /demo - Replaced Readability references with Trafilatura (current implementation) - Added MCP Tools table with all available tools - Simplified structure with clear sections and tables - Added architecture diagram - Updated project structure to reflect new organization - Removed outdated Azure Functions examples - Added badges and better formatting - Emphasized Docker as primary deployment method - Added search quality comparison table 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Warning Rate limit exceeded@T-rav has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 2 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (43)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| """Create response for client loading error.""" | ||
| return JSONResponse( | ||
| status_code=500, | ||
| content={"error": "Failed to serve WebCat client", "details": error}, |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the problem, ensure the error response sent to the external client does not include string representations or stack traces of the original exception object. Instead, log the full exception server-side for debugging with logger.error, and only return a generic error message in the API response. Specifically:
- In
serve_demo_client, inside theexceptblock, log the exception (ideally including the stack trace), and change the response to omit the"details"field. - Update the
client_error_responsefunction to no longer accept or return a details parameter. Instead, always return a generic error message such as "An internal error occurred."
You'll need to:
- Change
client_error_responseto take no parameters and always return a generic error. - Update the call to
client_error_responseinserve_demo_client. - (Optionally) Use
logger.exceptionorexc_info=Truefor better server-side logging.
| @@ -25,11 +25,11 @@ | ||
| ) | ||
|
|
||
|
|
||
| def client_error_response(error: str) -> JSONResponse: | ||
| """Create response for client loading error.""" | ||
| def client_error_response() -> JSONResponse: | ||
| """Create response for client loading error (generic, no details exposed).""" | ||
| return JSONResponse( | ||
| status_code=500, | ||
| content={"error": "Failed to serve WebCat client", "details": error}, | ||
| content={"error": "Failed to serve WebCat client"}, | ||
| ) | ||
|
|
||
|
|
||
| @@ -53,5 +51,5 @@ | ||
| logger.error(f"WebCat client file not found at: {client_path}") | ||
| return client_not_found_response(client_path) | ||
| except Exception as e: | ||
| logger.error(f"Failed to serve WebCat client: {str(e)}") | ||
| return client_error_response(str(e)) | ||
| logger.error("Failed to serve WebCat client", exc_info=True) | ||
| return client_error_response() |
refactor: Comprehensive architecture refactoring
Test Organization (One Class Per File)
Module Reorganization
Consolidation
Benefits
🤖 Generated with Claude Code