refactor(client): constructor-injectable config, lazy settings, single close path#54
Merged
Merged
Conversation
…e close path Implements plans/refactor/03-client-config-lifecycle.md: - config.py no longer instantiates Settings() at import time; token is optional on the Settings model. 'import codesphere' now succeeds without any environment variables - CodesphereSDK(token=..., base_url=..., timeout=..., http_client=...) with resolution order: explicit argument > CS_* env (.env honored) > built-in default. A missing token raises AuthenticationError at construction (previously a raw pydantic ValidationError at import; the purpose-built exception was never raised) - Fix dead CS_BASE_URL: the transport no longer defaults its own base_url, so the configured value actually applies; two SDK instances with different tokens/URLs can now coexist in one process - APIHttpClient becomes a dumb transport: full config passed in, no settings access, dynamic get/post/... setattr loop removed, BaseModel re-dump removed (serialization owned solely by execute_operation) - One close path: __aexit__ delegates to close(exc_type, exc_val, exc_tb) on both SDK and transport - New tests/test_sdk_config.py: import-without-env (empty-env subprocess), token/base_url/timeout resolution order, two-client isolation via httpx.MockTransport; conftest fixtures no longer patch a settings singleton - config.py and http_client.py removed from the ty ratchet - README documents constructor configuration Behavior change (fix): startup failure moves from import time to CodesphereSDK() construction and is now AuthenticationError.
🛡️ Bandit Security Scan Results✅ No security issues found by Bandit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements plans/refactor/03-client-config-lifecycle.md:
with resolution order: explicit argument > CS_* env (.env honored) >
built-in default. A missing token raises AuthenticationError at construction (previously a raw pydantic ValidationError at import; the purpose-built exception was never raised)
Behavior change (fix): startup failure moves from import time to CodesphereSDK() construction and is now AuthenticationError.