test: add validation and reachability tests for /scan-url#19
Conversation
|
hi @ionfwsrijan Please verify the tests - i have checked them locally also(all 4 passing) . Let me know if any changes required. Thanks! |
There was a problem hiding this comment.
Pull request overview
This PR adds a new backend test module to cover the /scan-url FastAPI endpoint’s URL validation and GitHub reachability handling, aiming to prevent regressions in error handling without performing real network calls.
Changes:
- Added tests for invalid GitHub URL format (422) and repository reachability failures (404 → 422, timeout → 422).
- Added a “success” test that mocks download/unzip/scan steps to exercise the happy-path route logic.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| mock_client = mock_async_client.return_value.__aenter__.return_value | ||
| mock_client.head.side_effect = httpx.TimeoutException("timeout") |
| mock_client = mock_async_client.return_value.__aenter__.return_value | ||
| mock_response = AsyncMock() | ||
| mock_response.status_code = 200 | ||
| mock_client.head.return_value = mock_response |
|
@lakshay122007 Great work! The code looks clean to me. |
|
@lakshay122007 Can you address copilot suggestions? They look valid to me |
|
yes - i am just verifying them just a moment |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…hay122007/PatchPilot into test/12-scan-url-validation
|
Done @ionfwsrijan |
|
@lakshay122007 Thanks for you valuable contribution |
|
@lakshay122007 You may raise new issues if you find some or just hit me up on dc ill give you a couple of feature suggestions |
|
@lakshay122007 Join our dc server! https://discord.gg/fRwjghKPJ |
|
@lakshay122007 I've posted a couple of new feature ideas and also mentors are there to help! |
Linked issue
Closes #12
What this PR does
This PR adds comprehensive test coverage for the
/scan-urlendpoint to prevent regressions in URL validation and error handling. It introduces isolated tests using mockedhttpxand file system operations to simulate various network states and user inputs without executing real network calls.Type of change
ML tier (if applicable)
Changes
Backend
backend/tests/test_scan_url.pywith tests covering invalid URL formats, 404 Not Found responses, andhttpx.TimeoutException.download_to_path,unzip_to_dir, and_scan_repo_dirto test the route logic cleanly without triggering actual file downloads or background CLI tools.Testing
How did you test this?
I ran the new test file locally using

pytest backend/tests/test_scan_url.py. All four test cases passed successfully. I verified that no actual network requests or file system modifications occurred during the test execution due to the mocks.Checklist
console.erroror unhandled Python exceptions introducedrequirements.txt/package.jsonupdated if new dependencies added.pkl,.pt, etc.) are gitignored, not committedAnything reviewers should focus on
Reviewers can check the mocking strategy in
test_scan_url_success.download_to_path(as anAsyncMock),unzip_to_dir, and_scan_repo_dirare all fully patched so that the CI pipeline can run this test rapidly without requiring the Semgrep/OSV/Gitleaks binaries to be installed in the [environment.](url)