Skip to content

fix(cli): warn when auth validation falls back to API#1209

Merged
inimaz merged 1 commit into
mlco2:masterfrom
puneetdixit200:fix/1208-auth-validation-warning
May 27, 2026
Merged

fix(cli): warn when auth validation falls back to API#1209
inimaz merged 1 commit into
mlco2:masterfrom
puneetdixit200:fix/1208-auth-validation-warning

Conversation

@puneetdixit200
Copy link
Copy Markdown
Contributor

Description

Log a warning when local CLI access-token validation is skipped because the auth server cannot be reached. This preserves the existing offline/flaky-network fallback while making it explicit that token freshness was not proven locally and the API will make the final authorization decision.

Related Issue

Fixes #1208

Motivation and Context

The existing fallback is useful for availability, but silent success makes the path look like a completed local validation. A warning keeps the behavior unchanged while surfacing the caveat from the issue.

How Has This Been Tested?

Red before implementation:

uv run --group dev python -m pytest -q tests/cli/test_cli_auth.py::TestAuthMethods::test_validate_access_token_network_error_returns_true

Green after implementation:

uv run --group dev python -m pytest -q tests/cli/test_cli_auth.py::TestAuthMethods::test_validate_access_token_network_error_returns_true
uv run --group dev python -m pytest -q tests/cli/test_cli_auth.py tests/cli/test_cli.py tests/cli/test_cli_main.py
uv run --group dev black --check codecarbon/cli/auth.py tests/cli/test_cli_auth.py
uv run --group dev ruff check codecarbon/cli/auth.py tests/cli/test_cli_auth.py
git diff HEAD^ --check

Screenshots (if appropriate):

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

AI Usage Disclosure

OpenAI GPT-5 generated the small code/test change and PR text under explicit human-directed issue-fix constraints. I reviewed the touched auth path, preserved existing fallback behavior, and verified the change with the commands listed above.

  • 🟥 AI-vibecoded: You cannot explain the logic. Car analogy : the car drive by itself, you are outside it and just tell it where to go.
  • 🟠 AI-generated: Car analogy : the car drive by itself, you are inside and give instructions.
  • ⭐ AI-assisted. Car analogy : you drive the car, AI help you find your way.
  • ♻️ No AI used. Car analogy : you drive the car.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/how-to/contributing.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@puneetdixit200 puneetdixit200 requested a review from a team as a code owner May 20, 2026 23:19
Log a warning when local CLI access-token validation is skipped because the auth server cannot be reached, while preserving the existing availability fallback.

Fixes mlco2#1208
@puneetdixit200 puneetdixit200 force-pushed the fix/1208-auth-validation-warning branch from 31eb66b to 65e5f05 Compare May 26, 2026 18:43
@puneetdixit200
Copy link
Copy Markdown
Contributor Author

Rebased this branch onto the current master head.

Local verification after the rebase:

UV_CACHE_DIR=/private/tmp/codecarbon-1209-uv-cache uv run python -m pytest tests/cli/test_cli_auth.py
# 17 passed, 1 warning

git diff --check upstream/master...HEAD
# passed

GitHub currently reports no check rows for this branch yet.

Copy link
Copy Markdown
Collaborator

@inimaz inimaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition thanks @puneetdixit200 !

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.93%. Comparing base (5a7cee8) to head (65e5f05).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1209   +/-   ##
=======================================
  Coverage   88.92%   88.93%           
=======================================
  Files          45       45           
  Lines        4306     4309    +3     
=======================================
+ Hits         3829     3832    +3     
  Misses        477      477           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@inimaz inimaz merged commit d215e21 into mlco2:master May 27, 2026
13 checks passed
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.

CLI auth falls back to API on auth-server network errors

2 participants