fix(tests): isolate cloud-sync HOME so dev ~/.gradata/key doesn't leak (closes #216)#217
Conversation
closes #216) CloudClient.enabled falls through to _resolved_credential() which reads ~/.gradata/key. The TestCloudClient test fixtures didn't isolate HOME, so on any dev machine that had actually run 'gradata cloud enable', the real keyfile leaked into the test and two 'should-be-disabled' tests failed: - TestCloudClient::test_client_disabled_by_default - TestCloudClient::test_client_disabled_without_token Add an autouse fixture on TestCloudClient that: 1. Points HOME at a per-test tmp dir 2. Drops GRADATA_API_KEY from the env 3. Redirects the module-level KEYFILE_DIR/KEYFILE_PATH in gradata.cloud._credentials (those are captured at import time via Path.home(), so /home/olive alone isn't enough) Tests that rely on enabled=True still pass because they pass an explicit token on CloudConfig, which short-circuits the keyfile lookup.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
🧰 Additional context used📓 Path-based instructions (1)Gradata/tests/**/*.py📄 CodeRabbit inference engine (Gradata/AGENTS.md)
Files:
🔇 Additional comments (2)
📝 Walkthrough
WalkthroughThe PR adds credential isolation to the test module by importing ChangesCredential isolation fixture
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
Suggested labels
🚥 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 docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 OpenGrep (1.21.0)OpenGrep fatal error (exit code 2): �[32m✔�[39m �[1mOpengrep OSS�[0m �[1m Loading rules from local config...�[0m Comment |
Summary
Closes #216.
CloudClient.enabledfalls through to_resolved_credential(), which reads~/.gradata/key. TheTestCloudClientfixtures didn't isolateHOME, so on any dev machine that had rungradata cloud enable, the real keyfile leaked into the test and two 'should-be-disabled' assertions failed:TestCloudClient::test_client_disabled_by_defaultTestCloudClient::test_client_disabled_without_tokenThis PR adds an autouse fixture on
TestCloudClientthat:HOMEat a per-test tmp dirGRADATA_API_KEYfrom the envKEYFILE_DIR/KEYFILE_PATHingradata.cloud._credentials(those are captured at import time viaPath.home(), soHOMEalone isn't sufficient)Test plan
pytest tests/test_cloud_sync.pyon a dev box with a populated~/.gradata/key→ 21 passed (was 19 passed / 2 failed).enabled=Truestill pass because they set an explicitCloudConfig.token, which short-circuits the keyfile lookup before_resolved_credential()is consulted.~/.gradata/key, so it already passed; behavior unchanged there.Layering check
No layering impact — test-only change. No new imports into
src/gradata/.Risk
None. Test-isolation fix only. No production code touched.