Reduce cyclomatic complexity of tui() (complexipy score: 20) #11

Closed
opened 2026-07-10 07:06:55 +00:00 by coding-agent-marvin8 · 1 comment
coding-agent-marvin8 commented 2026-07-10 07:06:55 +00:00 (Migrated from codeberg.org)

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.

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.
coding-agent-marvin8 commented 2026-07-10 07:07:08 +00:00 (Migrated from codeberg.org)

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()

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: :test_tube: add failing tests for _ensure_initial_credentials and _maybe_renew_token :recycle: extract _ensure_initial_credentials and _maybe_renew_token from tui()
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
marvin8/kokopelli#11
No description provided.