Update to longwei 2.0.0 #13
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
longwei 2.0 is a major release with two categories of breaking changes that require updates across taibai.
Breaking change 1: APClient API
APClient.create() no longer accepts an external httpx client. It now manages its own HTTP client and is used as an async context manager:
Old: ap = await APClient.create(instance_url, http_client, access_token)
New: async with await APClient.create(instance=instance_url, access_token=access_token) as ap:
The static auth methods (create_app, validate_authorization_code) also drop the http_client parameter, and the code argument to validate_authorization_code is renamed to authorization_code.
The INSTANCE_TYPE_MASTODON constant moves from longwei.constants to the longwei top-level import.
Breaking change 2: HTTP library change
longwei 2.0 replaces httpx with httpx2 (pydantic's HTTP client). This means pytest-httpx (which targets httpx==0.28.*) no longer works for tests. The replacement is pytest-httpx2~=1.0, which wraps respx and provides an httpx2_mock fixture with a different route-builder API.
Findings
longwei 2.0.0 on PyPI declares dependency httpx2[http2]~=2.3 (pydantic's HTTP client) and imports from httpx2 import AsyncClient internally. This makes pytest-httpx incompatible — it targets httpx==0.28.* only.
Plan of attack
Commit 1 — dep bump: pyproject.toml: longwei~=1.5.0 → longwei~=2.0.0; regenerate uv.lock and pylock.toml.
Commit 2 — source migration: All 16 command files: remove import httpx, replace async with httpx.AsyncClient() block with async with await APClient.create(instance=..., access_token=...) as ap:. commands/init.py: drop http_client from create_app() and validate_authorization_code() (renamed code → authorization_code). commands/trending.py: fix INSTANCE_TYPE_MASTODON import path.
Commit 3 — test migration: pyproject.toml: swap pytest-httpx → pytest-httpx2~=1.0. All async-layer test files (~18): rename httpx_mock fixture to httpx2_mock, update add_instance_mock helper in conftest.py, convert httpx_mock.add_response(method=..., url=..., json=...) to httpx2_mock.get(...).respond(json=...) etc. tests/test_init.py: update APClient.create patch to return async context manager.
Commit 4 — release notes update.
Key files: pyproject.toml, src/taibai/commands/.py (all), tests/conftest.py, tests/test_.py (all async-layer).