test_deepwiki_repo_info.py provides comprehensive unit tests for the repo_info tool with DeepWiki integration and URL parsing.
- test_deepwiki_success: Successful DeepWiki MCP SSE connection and content retrieval
- test_deepwiki_timeout: Handles timeout after 60s gracefully
- test_deepwiki_empty_response: Handles empty/None responses from DeepWiki
- test_deepwiki_connection_error: Handles connection errors with proper fallback
Tests the coerce_github_url_or_none() and _coerce_owner_repo_ref() functions:
GitHub URL Formats (Accepted):
owner/repo→https://github.com/owner/repohttps://github.com/owner/repohttp://github.com/owner/repogithub.com/owner/repo→https://github.com/owner/repohttps://github.com/owner/repo.git→https://github.com/owner/repohttps://github.com/owner/repo/tree/main→https://github.com/owner/repo#main
Non-GitHub URLs (Rejected):
- GitLab URLs →
None - BitBucket URLs →
None - Random URLs →
None - Empty strings →
None
Edge Cases:
- Extracts owner, repo, and ref from various formats
- Handles special characters in repo names (hyphens, underscores, dots)
- FTP URLs with github.com are extracted via regex
Tests the full tool_repo_summary() pipeline:
- test_repo_info_deepwiki_success: DeepWiki succeeds, returns
source="deepwiki" - test_repo_info_deepwiki_failure_fallback_to_repocards: DeepWiki fails, falls back to repocards
- test_repo_info_deepwiki_exception_fallback: DeepWiki exception triggers repocards fallback
- test_repo_info_both_fail_error_response: Both fail, returns
source="error"with message - test_repo_info_truncation: Content over 20K chars is truncated
- test_repo_info_with_various_github_formats: All valid GitHub URL formats work
- test_gitlab_url_detection: GitLab URLs properly rejected
- test_other_urls_detection: Non-GitHub/GitLab URLs properly rejected
- test_empty_url: Empty URL strings handled gracefully
- test_url_with_special_characters: Repo names with special chars work
- test_deepwiki_timeout_duration: Confirms timeout is enforced (~60s)
- test_real_github_repo: Real API call (set
INTEGRATION_TESTS=1to run)
# Run all tests
pytest tests/test_deepwiki_repo_info.py -v
# Run specific test
pytest tests/test_deepwiki_repo_info.py::test_deepwiki_success -v
# Run with integration tests
INTEGRATION_TESTS=1 pytest tests/test_deepwiki_repo_info.py -v
# Run only URL coercion tests
pytest tests/test_deepwiki_repo_info.py::TestURLCoercion -v
# Run with detailed output
pytest tests/test_deepwiki_repo_info.py -vv --tb=short✅ 27 tests passed
⏭️ 1 test skipped (integration test)
⏱️ ~61 seconds execution time
pytest- Testing frameworkpytest-asyncio- Async test support- Mock modules for
retrieverandapi(handled in test setup)
The tests use:
- Unit test doubles (mocks/patches) to avoid external dependencies
- AsyncMock for testing async functions
- Fixtures for reusable test data
- Parametrized tests (via loops) for URL format variations
- ✅ DeepWiki First: Tries DeepWiki MCP before repocards
- ✅ Graceful Fallback: Falls back to repocards on any DeepWiki error
- ✅ GitLab Rejection: GitLab URLs are properly rejected (not supported)
- ✅ URL Normalization: Various GitHub URL formats are normalized
- ✅ Timeout Handling: 60s timeout prevents hanging
- ✅ Error Reporting: Both sources failing returns error message
- Tests use mocked modules to avoid importing the full RAG pipeline
- Integration test requires network access and GitHub API
- Timeout test takes ~60s due to actual timeout simulation