Add auto-resume session from GARTH_HOME or GARTH_TOKEN env vars (#172)#175
Add auto-resume session from GARTH_HOME or GARTH_TOKEN env vars (#172)#175
Conversation
- Add _auto_resume() method to Client class that checks env vars on init - Support GARTH_HOME (directory path) or GARTH_TOKEN (base64 token string) - Raise GarthException if both env vars are set simultaneously - Add __str__ method to GarthException for proper exception message display - Update client test fixture to clear env vars for clean test isolation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Warning Rate limit exceeded@matin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 31 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (7)
WalkthroughThis pull request implements auto-resumption of Garth sessions using environment variables. When a Client is initialized, it automatically loads session data from GARTH_HOME (directory) or GARTH_TOKEN (token string). If both variables are set, an exception is raised. A Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #175 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 66 66
Lines 3044 3118 +74
=========================================
+ Hits 3044 3118 +74
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
When a client was loaded from GARTH_HOME and the OAuth2 token is refreshed, automatically dump the updated tokens back to GARTH_HOME to keep the persisted session current. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/garth/http.py (1)
95-108: Implementation looks correct.The mutual exclusion logic and conditional loading are well-implemented. The truthiness checks handle edge cases like empty strings correctly.
Consider adding a return type hint for consistency with other methods:
- def _auto_resume(self): + def _auto_resume(self) -> None:
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/garth/exc.pysrc/garth/http.pytests/conftest.pytests/test_http.py
🧰 Additional context used
📓 Path-based instructions (2)
tests/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
tests/**/*.py: Use pytest with VCR cassettes for HTTP recording/playback in tests
Mirror test directory structure to match source code structure
Files:
tests/conftest.pytests/test_http.py
tests/**
⚙️ CodeRabbit configuration file
tests/**: - test functions shouldn't have a return type hint
- it's ok to use
assertinstead ofpytest.assume()
Files:
tests/conftest.pytests/test_http.py
🧠 Learnings (1)
📚 Learning: 2026-01-09T22:41:07.978Z
Learnt from: CR
Repo: matin/garth PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-09T22:41:07.978Z
Learning: Expose main client instance as `garth.client` and provide `connectapi()` method for direct API calls returning JSON
Applied to files:
tests/test_http.py
🧬 Code graph analysis (2)
tests/test_http.py (3)
src/garth/exc.py (2)
GarthException(7-13)GarthHTTPError(17-21)tests/conftest.py (4)
authed_client(68-78)client(21-25)oauth1_token(40-41)oauth2_token(58-64)src/garth/http.py (1)
Client(19-261)
src/garth/http.py (1)
src/garth/exc.py (2)
GarthException(7-13)GarthHTTPError(17-21)
🔇 Additional comments (6)
src/garth/exc.py (1)
12-13: LGTM!The
__str__method correctly returns the message, ensuring consistent string representation forGarthExceptioninstances. This aligns well with the existingGarthHTTPError.__str__pattern and enables proper display when the exception is raised (e.g., in the auto-resume conflict scenario).src/garth/http.py (1)
43-43: LGTM!The
_auto_resume()call is correctly placed afterconfigure(), ensuring the client is properly initialized before attempting to load tokens from environment variables.tests/test_http.py (3)
32-43: LGTM!The test correctly verifies that a new
Clientauto-resumes fromGARTH_HOME. Good use ofmonkeypatchto isolate the environment andtempfile.TemporaryDirectoryfor cleanup.
45-54: LGTM!The test correctly verifies that a new
Clientauto-resumes fromGARTH_TOKEN. The setup mirrorstest_auto_resume_garth_homeappropriately.
57-62: LGTM!The test correctly verifies that
GarthExceptionis raised with the expected message when both environment variables are set. Good use ofpytest.raiseswithmatchfor precise error validation.tests/conftest.py (1)
20-25: LGTM!The fixture correctly clears environment variables before creating the
Client, preventing auto-resume from interfering with tests that don't explicitly test that behavior. Theraising=Falseparameter properly handles cases where the variables aren't set.
- Update README with auto-resume in features list - Add environment variable examples to README - Add comprehensive auto-resume section in getting-started docs - Document GARTH_HOME, GARTH_TOKEN, and auto-persist behavior Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- OAuth1Token: mask oauth_token_secret as '***' - OAuth2Token: mask access_token and refresh_token as '***' - Use @DataClass(repr=False) with custom __repr__ methods Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add oauth2_only parameter to Client.dump() - Use oauth2_only=True in refresh_oauth2() to avoid unnecessary oauth1 file write - Add test to verify oauth1 file is not modified on refresh Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Clear _garth_home in authed_client fixture to prevent tests from auto-persisting tokens back to the user's actual GARTH_HOME directory. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Client()is initializedGARTH_HOMEenv var pointing to directory with saved tokensGARTH_TOKENenv var with base64-encoded token stringGarthExceptionif both env vars are set simultaneously__str__method toGarthExceptionfor proper message display in exceptionsTest plan
test_auto_resume_garth_home- Verify loading from directory pathtest_auto_resume_garth_token- Verify loading from base64 tokentest_auto_resume_both_set_raises- Verify error when both env vars setCloses #172
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.