Reduce cyclomatic complexity of tui() (complexipy score: 20) #11
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?
complexipy reports tui() with a complexity score of 20 (threshold is 15). The function handles credential migration, initial auth, token renewal, and app startup — too much in one place.
Two helpers extracted from tui():
_ensure_initial_credentials(configure, client_id, client_secret) -> CredentialsDict
Handles: .envrc migration, reading credentials, OAuth initial auth flow. Calls sys.exit(1) if client credentials are absent or if get_access_token() raises.
_maybe_renew_token(creds) -> CredentialsDict
Handles: token expiry check and opportunistic renewal via renew_access_token(). On failure prints warning and returns original creds unchanged.
tui() is left with: call _ensure_initial_credentials, check access_token present, call _maybe_renew_token, build headers, run app. Score drops to ~4.
Branch: feat/issue-11-reduce-tui-complexity
Commits:
🧪 add failing tests for _ensure_initial_credentials and _maybe_renew_token
♻️ extract _ensure_initial_credentials and _maybe_renew_token from tui()