Skip to content

Conversation

@ink-developer
Copy link
Collaborator

@ink-developer ink-developer commented Dec 20, 2025

Описание

Кратко, что делает этот PR. Например, добавляет новый метод, исправляет баг, улучшает документацию.

Тесты + вход по номеру телефона

Тип изменений

  • Исправление бага
  • Новая функциональность
  • Улучшение документации
  • Рефакторинг

Связанные задачи / Issue

Ссылка на issue, если есть: #

Тестирование

Покажите пример кода, который проверяет изменения:

from pymax import MaxClient
from pymax.payloads import UserAgentPayload

ua = UserAgentPayload(device_type="DESKTOP", app_version="25.12.13")

client = MaxClient(
    phone="+79111111111",
    work_dir="cache",
    headers=ua,
)

Summary by CodeRabbit

  • New Features

    • Enhanced authentication documentation with device type configuration (DESKTOP and WEB modes).
  • Documentation

    • Added comprehensive authentication flow examples with device type guidance.
  • Chores

    • Version bumped to 1.2.2.
    • Updated default authentication method for improved security and usability.
    • Enhanced testing infrastructure with CI/CD pipelines and coverage reporting.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 20, 2025

Warning

Rate limit exceeded

@ink-developer has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 30 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 06958d5 and c9c2946.

📒 Files selected for processing (2)
  • .github/workflows/tests.yml (1 hunks)
  • pyproject.toml (4 hunks)

Walkthrough

Introduces UserAgentPayload class with device/environment fields, propagates it through sync and handshake flows, updates CI/CD workflows for test automation, adds authentication documentation, changes default device type from "WEB" to "DESKTOP", and adds the app_version parameter.

Changes

Cohort / File(s) Summary
CI/CD & Testing Configuration
.github/workflows/tests.yml, pyproject.toml, pytest.ini
Adds new GitHub Actions workflow with test, integration-tests, and code-quality pipelines; defines test dependencies (pytest, mypy, flake8); configures pytest with asyncio mode, markers, timeouts, and coverage tracking.
Documentation & Examples
README.md, redocs/source/clients.rst, examples/test.py
Adds "Authentication (device_type)" section with DESKTOP and WEB flow examples; includes warning about device_type criticality; updates example to use DESKTOP mode with new app_version parameter.
Core Implementation
src/pymax/core.py, src/pymax/mixins/websocket.py, src/pymax/payloads.py, src/pymax/static/constant.py
Introduces UserAgentPayload class with 11 device/environment fields; adds user_agent parameter to _sync() and _handshake() methods; adds language field to RequestCodePayload; integrates user_agent into SyncPayload; changes DEFAULT_DEVICE_TYPE from "WEB" to "DESKTOP".

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant Client as MaxClient
    participant Sync as WebSocket Mixin
    participant Handshake as Handshake Flow
    participant Payload as SyncPayload

    App->>Client: start() with UserAgentPayload
    activate Client
    Client->>Sync: _sync(user_agent)
    deactivate Client
    activate Sync
    Sync->>Payload: Create SyncPayload with user_agent
    activate Payload
    Payload-->>Sync: SyncPayload instance
    deactivate Payload
    Sync->>Handshake: _handshake(user_agent)
    deactivate Sync
    activate Handshake
    Handshake->>Handshake: Include user_agent in handshake payload
    Handshake-->>Sync: Handshake response
    deactivate Handshake
    Sync-->>App: Authentication complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Payload class definition (src/pymax/payloads.py): Verify all 11 fields have correct defaults and types; check for consistent CamelModel inheritance and Field() usage.
  • Control flow changes (src/pymax/core.py, src/pymax/mixins/websocket.py): Confirm user_agent propagation through _sync() and _handshake() is correct and doesn't break existing authentication flows.
  • CI/CD configuration (pyproject.toml, .github/workflows/tests.yml): Verify test matrix versions, MockServer setup, and coverage configuration align with project standards.
  • Documentation accuracy: Ensure DESKTOP and WEB flow examples in README and Sphinx docs are correct and up-to-date.

Possibly related PRs

  • Dev/1.2.1 #30: Modifies authentication and app_version handling; related through UserAgent payload propagation and device_type parameter changes.

Poem

🐰 A payload hops through sync and shake,
Device types dance—DESKTOP's the take!
With auth flows tested, workflows gleam,
Our fuzzy friends craft the perfect scheme! 🎪

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Dev/1.2.2' is vague and non-descriptive, using a branch/version pattern rather than summarizing the actual changes made in the PR. Replace with a clear, descriptive title that summarizes the main change, such as 'Add device_type support and CI/CD workflows for version 1.2.2' or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description follows the template structure with sections and a testing example, though the opening line is placeholder text and the description could be more specific about the actual changes made.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
pytest.ini (1)

1-26: Duplicate pytest configuration with pyproject.toml.

Both pytest.ini and pyproject.toml (lines 90-102) define pytest options. This can lead to confusion and potential conflicts. Key differences:

  • pytest.ini has markers: unit, skip_ci (not in pyproject.toml)
  • pytest.ini has timeout = 30 (not in pyproject.toml)
  • addopts differ slightly (-ra --color=yes only in pytest.ini)

Consider consolidating into one location. pyproject.toml is the modern standard.

pyproject.toml (1)

40-61: Duplicate pytest dependencies between test and dev groups.

Lines 41-44 and 57-60 both declare pytest, pytest-asyncio, pytest-cov, and pytest-timeout. Consider having dev reference the test group to avoid duplication:

🔎 Proposed fix
 [dependency-groups]
 test = [
   "pytest>=8.0.0",
   "pytest-asyncio>=0.24.0",
   "pytest-cov>=5.0.0",
   "pytest-timeout>=2.1.0",
   "flake8",
   "mypy",
 ]
 dev = [
+  {include-group = "test"},
   "furo>=2025.9.25",
   "ghp-import>=2.1.0",
   "mkdocs>=1.6.1",
   "mkdocs-material>=9.6.18",
   "mkdocstrings[python]>=0.30.0",
   "pre-commit>=4.3.0",
   "pydocstring>=0.2.1",
   "sphinx>=8.1.3",
-  "pytest>=8.0.0",
-  "pytest-asyncio>=0.24.0",
-  "pytest-cov>=5.0.0",
-  "pytest-timeout>=2.1.0",
 ]
.github/workflows/tests.yml (1)

39-59: Linting and type-checking are non-blocking.

continue-on-error: true on flake8 (line 52) and mypy (line 59) means these checks won't fail the build. This is acceptable for gradual adoption but may allow quality regressions. Consider making critical flake8 errors (E9, F63, F7, F82) blocking.

src/pymax/payloads.py (1)

76-90: Simplify the redundant default_factory lambda.

The lambda explicitly passes all default values that are already defined in the UserAgentPayload class fields (lines 42-53). Since UserAgentPayload already has defaults for all fields, this is unnecessary code duplication and creates a maintenance burden—if defaults change in UserAgentPayload, they must be updated in two places.

🔎 Proposed simplification
-    user_agent: UserAgentPayload = Field(
-        default_factory=lambda: UserAgentPayload(
-            device_type=DEFAULT_DEVICE_TYPE,
-            locale=DEFAULT_LOCALE,
-            device_locale=DEFAULT_DEVICE_LOCALE,
-            os_version=DEFAULT_OS_VERSION,
-            device_name=DEFAULT_DEVICE_NAME,
-            header_user_agent=DEFAULT_USER_AGENT,
-            app_version=DEFAULT_APP_VERSION,
-            screen=DEFAULT_SCREEN,
-            timezone=DEFAULT_TIMEZONE,
-            client_session_id=DEFAULT_CLIENT_SESSION_ID,
-            build_number=DEFAULT_BUILD_NUMBER,
-        ),
-    )
+    user_agent: UserAgentPayload = Field(default_factory=UserAgentPayload)
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1c8eaf and 06958d5.

📒 Files selected for processing (10)
  • .github/workflows/tests.yml (1 hunks)
  • README.md (1 hunks)
  • examples/test.py (1 hunks)
  • pyproject.toml (4 hunks)
  • pytest.ini (1 hunks)
  • redocs/source/clients.rst (1 hunks)
  • src/pymax/core.py (1 hunks)
  • src/pymax/mixins/websocket.py (7 hunks)
  • src/pymax/payloads.py (2 hunks)
  • src/pymax/static/constant.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
examples/test.py (2)
src/pymax/payloads.py (1)
  • UserAgentPayload (42-53)
src/pymax/core.py (1)
  • MaxClient (44-318)
src/pymax/core.py (2)
src/pymax/mixins/websocket.py (1)
  • _sync (437-484)
src/pymax/mixins/socket.py (1)
  • _sync (573-613)
src/pymax/mixins/websocket.py (2)
src/pymax/mixins/socket.py (1)
  • connect (95-129)
src/pymax/payloads.py (1)
  • UserAgentPayload (42-53)
🔇 Additional comments (12)
src/pymax/static/constant.py (1)

12-12: Breaking change: default authentication method now uses phone-based login.

Changing DEFAULT_DEVICE_TYPE from "WEB" to "DESKTOP" alters the default authentication flow. Existing users relying on the previous default (QR-code/web auth) will now get phone-based authentication. Consider documenting this in release notes or a migration guide.

redocs/source/clients.rst (1)

23-44: LGTM!

The warning block clearly documents the critical device_type parameter and its two authentication modes with practical code examples. This aligns well with the constant change and helps users understand the authentication flow differences.

pyproject.toml (3)

3-3: LGTM!

Version bump from 1.2.1 to 1.2.2 appropriately reflects the new functionality and fixes.


104-118: LGTM!

Coverage configuration is well-structured with appropriate exclusion patterns for protocol classes, abstract methods, and type-checking blocks.


90-102: Remove redundant pytest configuration from pyproject.toml.

The repository has both pytest.ini and pyproject.toml with duplicate pytest settings. Since pytest prioritizes pytest.ini when both exist, the pyproject.toml configuration is unused. Additionally, pyproject.toml is inconsistent with pytest.ini—it's missing the unit and skip_ci markers and lacks the -ra --color=yes addopts and timeout = 30 settings defined in pytest.ini. Remove the [tool.pytest.ini_options] section from pyproject.toml to eliminate confusion and keep configuration in a single file.

Likely an incorrect or invalid review comment.

.github/workflows/tests.yml (3)

116-119: Integration tests are non-blocking.

continue-on-error: true means integration test failures won't block PRs. If this is intentional (e.g., tests are still stabilizing), consider adding a comment explaining why.


68-74: LGTM!

Codecov integration with fail_ci_if_error: false is appropriate—coverage upload failures shouldn't block builds.


10-32: LGTM!

Well-structured test matrix covering Python 3.10-3.13 with fail-fast: false to ensure all versions are tested even if one fails. Pip caching will improve CI performance.

README.md (1)

57-90: Excellent documentation of authentication flows.

The new authentication section clearly explains the critical role of device_type and provides comprehensive examples for both DESKTOP and WEB authentication flows. The use of warning blocks and code examples makes this very user-friendly.

examples/test.py (1)

6-6: LGTM - Example correctly demonstrates the new API.

The example properly showcases the DESKTOP authentication flow with explicit device_type and app_version parameters, aligning with the documentation and PR objectives.

src/pymax/core.py (1)

298-298: LGTM - Correctly passes user_agent to sync.

The change properly propagates the user_agent (set from headers parameter at line 144) into the _sync() method, which now expects this parameter as shown in websocket.py line 437.

src/pymax/mixins/websocket.py (1)

69-100: LGTM - User agent propagation is well-implemented.

The changes correctly thread UserAgentPayload through the connection, handshake, and sync flows:

  1. connect() accepts an optional user_agent and provides a sensible default
  2. _handshake() incorporates the user agent into the session initialization payload
  3. _sync() passes the user agent to SyncPayload, ensuring authentication uses the correct device context

The flow is consistent with changes in core.py and payloads.py. The minor logging consolidations (lines 53, 172, 356) also improve readability.

Also applies to: 102-118, 437-484

Comment on lines +108 to +114
- name: Start MockServer
run: |
git clone https://github.com/fresh-milkshake/gomax-prerelease.git
cd gomax-prerelease/mockserver
go mod download
go run cmd/server/main.go &
sleep 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Unpinned external repository and fragile server startup.

Two concerns:

  1. Unpinned repo: Cloning gomax-prerelease without a specific commit/tag means CI can break unexpectedly if that repo changes.
  2. Hardcoded sleep: sleep 3 is fragile; the server may not be ready in time, causing flaky tests.
🔎 Proposed improvements
       - name: Start MockServer
         run: |
-          git clone https://github.com/fresh-milkshake/gomax-prerelease.git
+          git clone --depth 1 --branch v1.0.0 https://github.com/fresh-milkshake/gomax-prerelease.git
           cd gomax-prerelease/mockserver
           go mod download
           go run cmd/server/main.go &
-          sleep 3
+          # Wait for server to be ready
+          for i in {1..30}; do
+            curl -s http://localhost:8080/health && break || sleep 1
+          done
🤖 Prompt for AI Agents
.github/workflows/tests.yml around lines 108 to 114: the workflow clones an
unpinned external repo and uses a fragile fixed sleep to wait for the mock
server; update the clone to fetch a specific tag or commit (or add the repo as a
submodule) to pin the version, and replace the hardcoded sleep with a readiness
loop that waits for the server to respond (e.g., poll an HTTP health endpoint
with a timeout and exit non‑zero on failure) so CI is deterministic and not
flaky.

@ink-developer
Copy link
Collaborator Author

крч пофиг на тесты

@ink-developer ink-developer merged commit ed55732 into main Dec 20, 2025
3 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants