Skip to content

refactor(client): constructor-injectable config, lazy settings, single close path - #54

Merged
Datata1 merged 1 commit into
mainfrom
refactor/03-client-config-lifecycle
Jul 12, 2026
Merged

refactor(client): constructor-injectable config, lazy settings, single close path#54
Datata1 merged 1 commit into
mainfrom
refactor/03-client-config-lifecycle

Conversation

@Datata1

Copy link
Copy Markdown
Owner

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.

…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.
@Datata1Datata1 self-assigned this Jul 12, 2026
@github-actions

Copy link
Copy Markdown

🛡️ Bandit Security Scan Results

✅ No security issues found by Bandit.

@github-actions

Copy link
Copy Markdown

Coverage

Pytest Coverage Report
FileStmtsMissBranchBrPartCoverMissing
__init__.py9000100%
client.py40060100%
config.py9000100%
exceptions.py9432382259%25->30, 40–42, 53->58, 54->55, 55, 73->74, 74, 85–87, 101–104, 106–107, 148–151, 158–160, 196->197, 197–199, 204->205, 205, 206->207, 207, 210->211, 211, 214, 215->216, 216, 217->218, 218–219, 222
http_client.py4966285%42->exit, 52->exit, 87–88, 90–91, 96–97
utils.py2716181531%12->13, 13–14, 27–33, 35–36, 41–44, 46
core
__init__.py4000100%
base.py47020100%
handler.py59318096%80–82
operations.py15000100%
resources
__init__.py0000100%
resources/metadata
__init__.py3000100%
operations.py6000100%
resources.py13000100%
schemas.py28000100%
resources/team
__init__.py5000100%
operations.py8000100%
resources.py11000100%
schemas.py27000100%
resources/team/domain
__init__.py0000100%
manager.py21000100%
operations.py12000100%
resources.py2650081%31, 33, 36, 39–40
schemas.py34000100%
resources/team/usage
__init__.py3000100%
manager.py4528292%99->102, 102, 162->165, 165
operations.py4000100%
schemas.py8515141372%69->70, 70, 84–85, 88, 96–99, 114–115, 118, 126–129
resources/workspace
__init__.py5000100%
operations.py12000100%
resources.py1624280%13->14, 14, 19->20, 20
schemas.py99146681%100–101, 103–109, 115–116, 118, 142, 161
resources/workspace/envVars
__init__.py3000100%
models.py30212486%34->36, 36–37, 39->exit
operations.py7000100%
schemas.py4000100%
resources/workspace/git
__init__.py3000100%
models.py20040100%
operations.py8000100%
schema.py4000100%
resources/workspace/landscape
__init__.py3000100%
models.py99736889%28->29, 29, 126->129, 132->135, 156->157, 157–158, 160->155, 163->164, 164, 168–170
operations.py11000100%
resources.py0000100%
schemas.py2972910489%122–123, 126, 131–132, 135–136, 139, 144–146, 149–150, 153, 260, 267–268, 343–345, 347–349, 351–352, 467–468, 475–476
resources/workspace/logs
__init__.py3000100%
models.py15586625435%41–42, 48, 50–52, 54, 57–58, 61, 64–65, 67–70, 72–73, 76–77, 79–80, 82–83, 85–87, 89–90, 92–96, 98–99, 101–103, 105–110, 123–124, 214–216, 225–227, 236–238, 248–257, 267–276, 286–295
operations.py5000100%
schemas.py19000100%
TOTAL148721924413280%

Test Execution Summary

TestsSkippedFailuresErrorsTime
2760 💤0 ❌0 🔥2.862s ⏱️

@Datata1
Datata1 merged commit 49e1b14 into mainJul 12, 2026
3 of 4 checks passed
Sign up for freeto 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

@Datata1