refactor(services): ResolvedProjectCredentials dataclass over (stack_url, token) tuple (#516 NB-1)#519
Merged
Conversation
…rl, token) tuple (#516 NB-1) The single-project services (token / stream / snapshot) each carried a byte-identical `_resolve_project(alias) -> tuple[str, str]` returning (stack_url, token) -- a bare heterogeneous 2-tuple whose positional order a caller has to remember. CONTRIBUTING.md ("Return values -- name them with dataclasses, not tuples") forbids this for new code; PR #516 review flagged the new snapshot_service instance (NB-1), and fixing the trio together keeps them consistent rather than diverging from the two grandfathered siblings. - New `ResolvedProjectCredentials` frozen dataclass + shared `resolve_project_credentials(config_store, alias)` helper in services/base.py (the existing home for cross-service free functions like default_client_factory), which also removes the previously-triplicated lookup body. - All three `_resolve_project` helpers delegate to it; call sites now read `creds.stack_url` / `creds.token` instead of positional unpacking. - The "not registered" ConfigError message is preserved verbatim (not switched to the richer ConfigStore.project_not_found_error) so behavior is identical. - Drops the now-unused ConfigError import from token_service. make check clean (4648 passed, 8 skipped); no behavior change.
padak
force-pushed
the
refactor/resolve-project-credentials-dataclass
branch
from
July 22, 2026 09:41
5458d8a to
f5de1f9
Compare
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.
Addresses NB-1 from the #516 review.
Why
The three single-project services —
token,stream,snapshot— each carried a byte-identical helper:That bare
(stack_url, token)2-tuple is exactly the heterogeneous positional return CONTRIBUTING.md forbids for new code ("Return values — name them with dataclasses, not tuples"). The #516 review flagged the newly-addedsnapshot_serviceinstance (NB-1) and noted that fixing it in isolation would diverge from the two grandfathered siblings — so the trio is fixed together here.What
ResolvedProjectCredentialsfrozen dataclass + sharedresolve_project_credentials(config_store, alias)helper inservices/base.py(the existing home for cross-service free functions likedefault_client_factory/sanitize_unexpected_error). This also collapses the previously-triplicated lookup body into one place._resolve_projecthelpers now delegate to the shared function and return the dataclass; call sites readcreds.stack_url/creds.tokeninstead of positional unpacking.token_serviceConfigErrorimport is dropped (now unused there).Behavior preserved
kbagent project list."ConfigErrormessage is kept verbatim — I deliberately did not switch to the richerConfigStore.project_not_found_error(issue config.json disappears repeatedly (v0.66.0, macOS) — recurring 'Project not found' #477), to keep behavior identical. That swap could be a separate follow-up if desired.Scope
Only the three
_resolve_projectcredential helpers. The other pre-existingtuple[str, str]returns in the codebase (http_forwarder_service.resolve_endpoint,project_service.resolve_pinned_alias) are unrelated and stay grandfathered per CONTRIBUTING.md.Verification
make checkclean — 4648 passed, 8 skipped (identical count to the #516 baseline, confirming no tests added/removed and no regressions).ruff+tyclean on all four files. No new tests were needed: the change is a pure return-type refactor with no behavior change, and the existing service/CLI suites (token, stream, snapshot — 98 tests across them) already exercise every converted call site and the unchanged error path.