Skip to content

fix(auth): stop --help and tests hanging on client-login network call - #485

Merged
axisrow merged 2 commits into
mainfrom
fix/login-resolve-network-hang
May 30, 2026
Merged

fix(auth): stop --help and tests hanging on client-login network call#485
axisrow merged 2 commits into
mainfrom
fix/login-resolve-network-hang

Conversation

@axisrow

@axisrow axisrow commented May 30, 2026

Copy link
Copy Markdown
Owner

Проблема

Регрессия из #480: get_credentials() при активном OAuth-профиле с email-логином (и невыставленным login_migration_checked) делал сетевой clients.get для резолва bare Client-Login на каждый вызов CLI — включая <group> --help. У этого запроса не было таймаута (ни в vendored-клиенте, ни в tapi2), поэтому медленная сеть или Yandex SmartCaptcha-гейт могли подвесить CLI бесконечно.

Под CliRunner это вешало и весь unit-набор: прогон вставал на test_registered_mapped_groups_show_docs_url (~30 вызовов --help).

Что сделано (3 независимых барьера)

  1. auth.py — потолок LOGIN_RESOLVE_TIMEOUT_SECONDS = 8 на best-effort резолвер + отключены ретраи. Никогда не висит.
  2. cli.py--help/--version/-h пропускают резолвер (allow_login_resolve=False): команда не исполняется → логин не нужен.
  3. tests/conftest.py — autouse-фикстура нейтрализует сетевой резолвер для всего unit-набора; модульный сбор test-creds его больше не триггерит.

Тесты

  • test_group_help_does_not_resolve_client_login_over_network--help-проход делает 0 вызовов резолвера.
  • test_get_credentials_skips_login_resolve_when_disallowedallow_login_resolve=False подавляет миграцию.
  • Ранее зависавший test_registered_mapped_groups_show_docs_url теперь идёт 0.02с (был ~30с / бесконечно).
  • Полный unit-набор: 2064 passed, 47 skipped за 82с.

🤖 Generated with Claude Code

…twork call

A regression from #480 made get_credentials() resolve the bare Client-Login
via a network clients.get on every CLI invocation when an OAuth profile with
an email login lacked the login_migration_checked flag — including plain
`<group> --help`. That call had no timeout (neither the vendored client nor
tapi2 set one), so a slow link or a Yandex SmartCaptcha gateway could hang the
CLI indefinitely. Under CliRunner this also hung the unit suite (it stalled on
test_registered_mapped_groups_show_docs_url, which fires ~30 `--help` calls).

Three independent guards:
- auth.py: cap the best-effort resolver with LOGIN_RESOLVE_TIMEOUT_SECONDS=8
  and disable retries, so it can never wait forever.
- cli.py: skip the resolver entirely on --help/--version/-h passes
  (allow_login_resolve=False) — no command runs, so no login is needed.
- tests/conftest.py: autouse fixture neutralizes the network resolver for the
  whole unit suite; the module-level test-credential probe no longer triggers it.

Adds regression tests asserting a --help pass makes zero resolver calls and
that allow_login_resolve=False suppresses the migration.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mypy (CI quality gate) flagged the `timeout=` passed to clients().post() in
_resolve_client_login_via_api as an unexpected keyword: the hand-maintained
.pyi stub's get/post signatures omitted it even though the runtime forwards
**kwargs straight to requests. Add `timeout: float = None` to both so the
hot-path timeout type-checks. Stub-only; no runtime change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@axisrow
axisrow merged commit 676af44 into main May 30, 2026
6 checks passed
@axisrow
axisrow deleted the fix/login-resolve-network-hang branch May 30, 2026 14:25
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.

1 participant