Send structured banned payload for localized client handling#1086
Send structured banned payload for localized client handling#1086ZainKazmiii wants to merge 11 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughReplaces human-readable ban notices with a structured "banned" payload: BanError.to_payload() returns UTC ISO-8601 expires_at and reason; LobbyConnection sends that payload and aborts with a fixed message. Tests and protocol annotation updated. ChangesBan message to structured payload migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@server/exceptions.py`:
- Around line 5-7: Add one additional blank line between the top import
statement (from datetime import timezone) and the class declaration (class
ClientError) so there are two blank lines separating imports and top-level class
definitions to satisfy flake8 E302/isort formatting rules.
In `@tests/integration_tests/test_login.py`:
- Around line 1-2: The import order in the test module is incorrect for isort:
move the datetime import before time so that "from datetime import datetime,
timezone" appears above "from time import time"; update the top-of-file imports
accordingly (keeping the same imported symbols: time, datetime, timezone) to
satisfy isort --check --diff.
In `@tests/integration_tests/test_server.py`:
- Line 724: The test title string "title": "ÇÒÖL GÃMÊ" contains
confusable/ambiguous Unicode characters flagged by Ruff; replace that value with
a clear non-ASCII but unambiguous title (for example "ÇÖL GÁMÉ" or another
equivalent) so the test intent remains but RUF001 is avoided, i.e., update the
literal where "title": "ÇÒÖL GÃMÊ" appears in
tests/integration_tests/test_server.py to the chosen unambiguous non-ASCII
string.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 51ea1e81-1dac-4b40-a3b2-b2b8a704f097
📒 Files selected for processing (5)
server/exceptions.pyserver/lobbyconnection.pytests/integration_tests/test_login.pytests/integration_tests/test_server.pytests/unit_tests/test_lobbyconnection.py
Signed-off-by: Zain Kazmi <kazmiza@shernet.sheridancollege.ca>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
server/protocol/qdatastream.py (1)
74-74: ⚖️ Poor tradeoffClarify immutability contract between
pack_messageandpack_block.
- A search shows
QDataStreamProtocol.pack_block(...)is only called at line 95 inQDataStreamProtocol.pack_message; there are no other call sites that would requirepack_blockto acceptbytearray.- If the intended contract is “convert mutable buffer to immutable bytes before calling
pack_block”, addbytes(msg)at line 95 and narrowpack_blockback tobytes; otherwise, update the description to match the current “acceptbytes | bytearrayand return packedbytes” approach.🤖 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 `@server/protocol/qdatastream.py` at line 74, The signature of QDataStreamProtocol.pack_block currently accepts bytes | bytearray but is only called from QDataStreamProtocol.pack_message; change the contract to require immutable bytes by converting the mutable buffer at the call site: in pack_message call pack_block with bytes(msg) (i.e., ensure msg is converted to bytes before invoking pack_block) and update pack_block's type annotation to accept only bytes, removing bytearray from its parameter type.
🤖 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.
Nitpick comments:
In `@server/protocol/qdatastream.py`:
- Line 74: The signature of QDataStreamProtocol.pack_block currently accepts
bytes | bytearray but is only called from QDataStreamProtocol.pack_message;
change the contract to require immutable bytes by converting the mutable buffer
at the call site: in pack_message call pack_block with bytes(msg) (i.e., ensure
msg is converted to bytes before invoking pack_block) and update pack_block's
type annotation to accept only bytes, removing bytearray from its parameter
type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 066a843e-fb42-49ea-a65c-6347d464a999
⛔ Files ignored due to path filters (1)
Pipfile.lockis excluded by!**/*.lock
📒 Files selected for processing (1)
server/protocol/qdatastream.py
aa10c6e to
7db962f
Compare
|
Quick note on the latest CodeRabbit qdatastream nitpick: I intentionally kept Current head |
Signed-off-by: ZainKazmiii <111486944+ZainKazmiii@users.noreply.github.com>
|
Addressed in 7e722a6. I clarified the pack_block contract in qdatastream.py: it intentionally accepts �ytes | bytearray because pack_message builds a mutable �ytearray buffer and passes it through. I kept behavior unchanged here because forcing �ytes(msg) previously correlated with the qstream regression we just fixed. |
Signed-off-by: ZainKazmiii <111486944+ZainKazmiii@users.noreply.github.com>
|
Follow-up on the qdatastream immutability discussion: this is now addressed in head commit
This keeps the contract explicit and aligns with the CodeRabbit note. Current PR checks are green on this head. |
|
@coderabbitai review Current head (41d82aa) now calls pack_block(bytes(msg)) and keeps pack_block(block: bytes), so the immutability nitpick should be resolved on latest commit. |
|
✅ Actions performedReview triggered.
|
Fixes #640
Summary
bannedpayloadexpires_atplusreasonso clients can localize presentationValidation
python -m py_compile server/exceptions.py server/lobbyconnection.py tests/integration_tests/test_login.py tests/integration_tests/test_server.py tests/unit_tests/test_lobbyconnection.pypython -m pytest tests/unit_tests/test_lobbyconnection.py -k abort_connection_if_banned -q(blocked in this runner:No module named pytest)Test updates
noticetext to the structuredbannedpayload formatSummary by CodeRabbit
Bug Fixes
Tests