Repository navigation
tests: Add comprehensive test suite for Telegram handlers - #718
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe PR adds shared Telegram test fakes and broad async coverage for admin, client, base, and error handlers. It also improves test database isolation across SQLite, PostgreSQL, and MySQL and removes stale local SQLite artifacts before migrations. ChangesTelegram fixtures and local database cleanup
Bulk admin action flows
Admin menu and user handlers
Client, base, and error handlers
Cross-database test isolation
Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1
✨ Finishing Touches
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. I’m a rabbit with fixtures in tow, Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/telegram/handlers/test_error_handler.py (1)
16-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the cleanup and alert contracts, not only that calls occurred.
The message-path test does not verify old messages are deleted or state is cleared; the callback-path test would pass without
show_alert=Trueor the required...truncation suffix.Proposed assertions
async def test_handle_exception_value_error_message_path(monkeypatch, fake_state, fake_message): state = fake_state + state._state = "busy" state._data = {"messages_to_delete": [1, 2]} ... await error_handler.handle_exception(event, state) msg.answer.assert_awaited_once() + msg.bot.delete_messages.assert_awaited_once_with(msg.chat.id, [1, 2]) + assert await state.get_state() is None + assert await state.get_value("messages_to_delete") == [msg.message_id + 1] ... callback.answer.assert_awaited_once() sent_text = callback.answer.await_args.args[0] assert len(sent_text) == 200 + assert sent_text.endswith("...") + assert callback.answer.await_args.kwargs == {"show_alert": True}Also applies to: 33-37
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/telegram/handlers/test_error_handler.py` around lines 16 - 18, Strengthen the error-handler tests around handle_exception in both message and callback paths: assert that prior messages are deleted, state is cleared, and the user notification uses show_alert=True with the required “...” truncation suffix. Verify the exact cleanup and alert arguments rather than only checking that answer was awaited.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/api/__init__.py`:
- Around line 105-112: Update the database cleanup block in the test setup to
run only for SQLite URLs, parse the configured database path from DATABASE_URL,
and remove that exact database file plus its -shm and -wal sidecars. Stop
checking or deleting hardcoded CWD paths such as test.db, while preserving the
existing best-effort cleanup behavior.
---
Nitpick comments:
In `@tests/telegram/handlers/test_error_handler.py`:
- Around line 16-18: Strengthen the error-handler tests around handle_exception
in both message and callback paths: assert that prior messages are deleted,
state is cleared, and the user notification uses show_alert=True with the
required “...” truncation suffix. Verify the exact cleanup and alert arguments
rather than only checking that answer was awaited.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3d75c352-6714-4b6b-86e7-d4c2e7178ed5
📒 Files selected for processing (10)
tests/api/__init__.pytests/telegram/conftest.pytests/telegram/handlers/admin/test_bulk_actions.pytests/telegram/handlers/admin/test_confirm_action.pytests/telegram/handlers/admin/test_main_menu.pytests/telegram/handlers/admin/test_user.pytests/telegram/handlers/client/test_show_info.pytests/telegram/handlers/test_base.pytests/telegram/handlers/test_error_handler.pytests/test_record_usages.py
Take dev's tests/api/__init__.py and tests/test_record_usages.py, which both conflicted. This branch's two test-infra edits there (deleting the configured SQLite test file, and truncating tables on PostgreSQL and MySQL) are left out on purpose: the Telegram tests need neither, and they can return as their own PR. This PR now only adds the Telegram handler tests.
Current ruff flags the lambda that returns an empty dict; use dict, which does the same.
…ain bba95f274 Checked with git ls-remote on 2026-10-11 02:55 UTC. Panel dev moved from d94e157 to 83fe90e with 22 commits; main is still v5.4.1. - PasarGuard#879 (2d0ca81, loopback Xray client inbounds) is ported by design: the fork took the open pull request on 2026-09-25 as 2e7fc45 with migration bfd88026565b, the same listener rewrite. - PasarGuard#934 (a5b28f3) moves from the port queue to a dated waiver until 2026-11-09: the fork refuses to delete a core that nodes still use (W3-013, fix/node-health) instead of restarting those nodes. - PasarGuard#993 (Hysteria2 FinalMask without a udp mask) is queued until 2026-10-18: the fork has the same FinalMask | dict field and the same non-null-safe udpHop reads, so a udpHop-only host can fail the whole subscription. - PasarGuard#984, PasarGuard#985, PasarGuard#986, PasarGuard#989, PasarGuard#944, PasarGuard#864, PasarGuard#948, PasarGuard#951, PasarGuard#778, PasarGuard#774, PasarGuard#787, PasarGuard#994, PasarGuard#865, PasarGuard#875, PasarGuard#718, PasarGuard#967, PasarGuard#772, PasarGuard#662, PasarGuard#995 and PasarGuard#913 are queued as security: no until 2026-10-25, each with its reason; PasarGuard#913's node-removal half is already in the fork through sync_remove_users. - The branch commits that upstream squash-merged (the three dashboard branches, telegram/tests, fix/core-editor-api-section-followup, fix/hwid-count-test-cleanup, fix/hysteria-finalmask-quic-only) follow their squash, by patch-id or by an equal tree. Scripts main moved to bba95f274 (PasarGuard#35, PasarGuard#36, PasarGuard#37 after PasarGuard#34). The three squashes are queued security: no until 2026-10-25, and their pre-squash branch commits are waived as superseded (equal trees). Against live upstream the panel gate now fails only on the 17 port-queue commits classified security: yes, and the forks gate only on node f72ac0ef (security: yes). No upstream commit is undecided.
…#718) * test: add comprehensive test suite for Telegram handlers * fix * fix 2 * fix 3 * Delete the configured SQLite database path, not CWD test.db * Delete the configured SQLite database path, not CWD test.db * update telegram tests * test(telegram): satisfy ruff PIE807 in the handler test fixture Current ruff flags the lambda that returns an empty dict; use dict, which does the same. --------- Co-authored-by: T3ST3ST3R0N <[email protected]> (cherry picked from commit 65695ac)
…e in the PasarGuard#718 suite The fork checks username uniqueness globally with get_existing_usernames (b794f21) instead of the admin-scoped get_validated_user lookup, so the three PasarGuard#718 cases that reach that check stub it too; their asserted outcomes are unchanged.
…asarGuard#938 hunk 65695ac moves to Ported by design: its cherry-pick -x 357040fda is unchanged and ea4c2512f stubs the fork's global username check in three cases. 41eee93 stays in the port queue: 15 of its 16 hunks are on main, the jwt.decode hunk must not be taken as it is (0e964a528 fails on it), and the Ported by design check finds no fork commit whose lines are all still on main.
…asarGuard#718 Telegram user tests
Summary
Type of change
Checklist
I tested the change locally or explained why it cannot be tested.
I added or updated tests for behavior changes.
I did not include secrets, tokens, private keys, or unrelated changes.
I updated documentation, translations, or examples if needed.
I checked database migrations when models or schema changed.
Summary by CodeRabbit