fix(auth): stop --help and tests hanging on client-login network call - #485
Merged
Conversation
…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>
This was referenced May 30, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Проблема
Регрессия из #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 независимых барьера)
auth.py— потолокLOGIN_RESOLVE_TIMEOUT_SECONDS = 8на best-effort резолвер + отключены ретраи. Никогда не висит.cli.py—--help/--version/-hпропускают резолвер (allow_login_resolve=False): команда не исполняется → логин не нужен.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_disallowed—allow_login_resolve=Falseподавляет миграцию.test_registered_mapped_groups_show_docs_urlтеперь идёт 0.02с (был ~30с / бесконечно).🤖 Generated with Claude Code