Add unit test suite for main.py (0% -> 95% coverage) - #4
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
The repo had no tests — the single
main.pymodule (the entire codebase) sat at 0% coverage. This PR adds apytestsuite that bringsmain.pyto 95% statement coverage (96 tests), targeting the previously-untested application logic.Coverage went
0% -> 95%; the only remaining uncovered lines are a handful of defensiveexceptbranches in the WS relay and the__main__/uvicorn bootstrap.What's added
pytest.ini—asyncio_mode = auto,testpaths = tests.requirements-dev.txt— pinspytest,pytest-asyncio,pytest-covon top ofrequirements.txt.tests/conftest.py— an autousereset_statefixture that clears the module-level globals (LINKS,SESSIONS,AUTH,stats,connections,error_logs,hourly_traffic) around every test so the in-memory state is deterministic, plusclient/auth_clientTestClientfixtures.Test breakdown
test_helpers.py— pure helpers:hash_password,generate_uuid(seeded + random),generate_vless_link,uptime,parse_size_to_bytes,get_host,format_link_uuid.test_sessions.py—create_session/is_valid_session(incl. expiry purge) /destroy_session/require_auth.test_links_logic.py—ensure_default_link(idempotency),check_quota(unknown/inactive/unlimited/at-limit/over-limit),add_usage.test_vless_header.py—parse_vless_headerfor IPv4 / domain / IPv6, addon skipping, payload extraction, and the too-small / unknown-address-typeValueErrorpaths.test_api.py— endpoint behavior viaTestClient:/,/health, login/logout/me, change-password (auth + validation),/stats, full/api/linksCRUD (create/list/toggle/delete, 404s, label truncation), page routes (login/dashboard redirects,/test-ws), and the proxy success + 502 error branches (withhttp_clientmonkeypatched — no real network).test_relay.py—ws_to_tcp/tcp_to_wswith fake WebSocket/reader/writer: byte relaying, usage accounting, the\x00\x00first-frame prefix, and quota-exceeded1008closes.test_websocket_tunnel.py— end-to-end/ws/{uuid}against a threaded local TCP echo server (accept -> parse header ->open_connection-> relay), plus the disabled-link immediate-close path.Run
pip install -r requirements-dev.txt pytest --cov=main --cov-report=term-missing # 96 passed ... main.py 371 17 95%No production code in
main.pywas modified.Link to Devin session: https://app.devin.ai/sessions/47ddcdd850fa4f3d9b4e067b37e4e907
Requested by: @hmilan1366