Skip to content

feat: add auth login subcommand#1893

Open
aseembits93 wants to merge 5 commits intomainfrom
cf-auth-login-subcommand
Open

feat: add auth login subcommand#1893
aseembits93 wants to merge 5 commits intomainfrom
cf-auth-login-subcommand

Conversation

@aseembits93
Copy link
Contributor

Summary

  • Adds codeflash auth login CLI subcommand for standalone OAuth authentication
  • Prints the auth URL for the user to open, runs the full PKCE flow, and saves the API key
  • Skips OAuth if an existing API key is detected

Test plan

  • Unit tests for all auth_login() code paths (existing key, OSError, OAuth failure, success, Windows RC creation)
  • Argument parsing tests for auth login and bare auth
  • uv run prek passes on all changed files

🤖 Generated with Claude Code

Adds `codeflash auth login` CLI subcommand that performs the full OAuth
PKCE flow, prints the authentication URL, and saves the API key.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aseembits93 aseembits93 requested a review from HeshamHM28 March 24, 2026 20:44
@claude
Copy link
Contributor

claude bot commented Mar 24, 2026

Claude finished @aseembits93's task in 4m 9s —— View job


PR Review Summary

  • Triage PR scope — SMALL (53 lines production code)
  • Run lint/typecheck — prek passes, mypy clean
  • Resolve stale threads — none found
  • Code review
  • Duplicate detection
  • Fix failing tests and push

Prek Checks

All checks pass (ruff check, ruff format, mypy).

Code Review

Bug: Two tests were failingtest_successful_oauth_saves_key and test_windows_creates_rc_file_if_missing both patched codeflash.cli_cmds.cmd_auth.get_shell_rc_path, but get_shell_rc_path is never imported in cmd_auth.py (it lives inside save_api_key_to_rc in shell_utils.py). This caused AttributeError at test setup, and test_windows_creates_rc_file_if_missing also asserted mock_rc_path.touch.assert_called_once() — behavior that only exists inside save_api_key_to_rc, not in auth_login() itself.

Fixed and pushed (commit 2857e847): removed the phantom patches, dropped the untestable .touch() assertion, and renamed test_windows_creates_rc_file_if_missingtest_windows_oauth_saves_key to reflect what it actually tests. All 7 tests now pass.

Minor observation (cmd_auth.py): auth_login uses click.echo for error/success messages while using console.print (Rich) for status messages. Mixed output libraries in the same function is inconsistent, but not a blocking issue.

save_api_key_to_rc failure path (cmd_auth.py:35-36): when save_api_key_to_rc returns a Failure, the error is echoed but the function still prints "Signed in successfully!" and sets CODEFLASH_API_KEY. The API key is usable in-process but won't persist across sessions. This could silently mislead users. Worth either early-returning or adjusting the success message to note that persistence failed.

Duplicate Detection

No duplicates detected. auth_login and auth_status are new entry points with no equivalent elsewhere.

Test Coverage

7 tests added covering all major code paths in auth_login and argument parsing. auth_status has no dedicated tests — low risk given its simplicity, but worth noting.


Last updated: 2026-03-25
| Branch

@codeflash-ai
Copy link
Contributor

codeflash-ai bot commented Mar 24, 2026

⚡️ Codeflash found optimizations for this PR

📄 1,583% (15.83x) speedup for auth_login in codeflash/cli_cmds/cmd_auth.py

⏱️ Runtime : 19.0 milliseconds 1.13 milliseconds (best of 13 runs)

A new Optimization Review has been created.

🔗 Review here

Static Badge

codeflash-ai bot and others added 4 commits March 24, 2026 22:04
The optimization removed redundant operations that duplicated logic already inside `save_api_key_to_rc`. Previously, `auth_login` called `get_shell_rc_path()` (which performs `Path.home()` filesystem operations) and conditionally invoked `shell_rc_path.touch()` on Windows, then passed the result to `save_api_key_to_rc`. The optimized version calls `save_api_key_to_rc(api_key)` directly, because that function already internally calls `get_shell_rc_path()` and safely handles file creation via context managers. Line profiler shows `get_shell_rc_path()` dropped from ~1 ms to negligible per-call overhead, and `shell_rc_path.touch()` overhead was eliminated entirely. Runtime improved from 19 ms to 1.13 ms (1582% speedup) with no regressions across all test scenarios.
…gin-mn55wrey

⚡️ Speed up function `auth_login` by 1,583%
Co-authored-by: Aseem Saxena <undefined@users.noreply.github.com>
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