Skip to content

refactor(provider): collapse transport to a single deep complete()#23

Merged
AccursedGalaxy merged 1 commit into
mainfrom
refactor/provider-complete-transport
May 21, 2026
Merged

refactor(provider): collapse transport to a single deep complete()#23
AccursedGalaxy merged 1 commit into
mainfrom
refactor/provider-complete-transport

Conversation

@AccursedGalaxy
Copy link
Copy Markdown
Owner

Summary

Replaces the misnamed provider.get_commit_message with a deep complete(system, user, model, max_tokens, temperature) transport shared by both commands, and folds the error-taxonomy work into the same seam. Outcome of an architecture-review grilling session on candidates #21 and #22 — which turned out to be the same seam, so they land together.

What changed

  • provider.pycomplete() owns the Anthropic client, key injection, and response unwrapping, and collapses the entire anthropic exception hierarchy into a single ProviderError carrying an ErrorKind (auth / rate_limit / connection / status). An anthropic.APIError catch-all ensures the SDK's error surface never leaks past the seam.
  • commands/suggest.py — commit-prompt assembly extracted to a pure, private _build_user_content helper (single caller → kept private, not a module). Catches one ProviderError; wording lives in a per-command SUGGEST_WORDING map.
  • commands/test.py — calls complete() directly instead of smuggling a joke through a commit-message-named function. Its own TEST_WORDING map.
  • Both wording maps sit behind an import-time exhaustiveness assertion (assert set(MAP) == set(ErrorKind)).
  • Neither command imports anthropic anymore — it's confined to provider.py.

Why

get_commit_message was ~90% transport with 9 lines of commit-specific assembly bolted on; the test command proved the name lied by passing a joke as the "diff". The four-branch except anthropic.* ladder was also duplicated verbatim across both commands. One deep transport gives locality (error mapping in one place, mirroring the existing KeyStoreError precedent) and leverage (callers shed the anthropic import).

Testing

  • TDD red-green-refactor. 97 tests pass, black/isort clean, no lines > 100 cols.
  • Old get_commit_message tests deleted (superseded by complete interface tests); new tests assert each anthropic error maps to the correct ErrorKind, and _build_user_content is now unit-tested with zero mocks.

Closes #21
Closes #22

🤖 Generated with Claude Code

…ning API

- Replace `get_commit_message` with `complete(system, user, model, max_tokens, temperature)` that owns the Anthropic client and collapses SDK exceptions into single `ProviderError` carrying `ErrorKind` (auth / rate-limit / connection / status)
- Move four-branch `except anthropic.*` ladder into `complete()`; commands no longer import `anthropic` (APIError catch-all keeps the SDK surface from leaking past the seam)
- Extract pure `_build_user_content()` helper in `suggest.py` for unit testing without mocks
- Each command keeps its own `*_WORDING` dict per `ErrorKind` behind import-time exhaustiveness assertions
- `test` calls `complete()` directly for generic completions, not the commit-message function
- Update tests to mock `complete()` and `ProviderError` instead of anthropic exceptions

Closes #21, closes #22.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Warning

Rate limit exceeded

@AccursedGalaxy has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 20 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1866c95c-ed30-4543-881a-a71889532c28

📥 Commits

Reviewing files that changed from the base of the PR and between e1d4dc9 and cc8052b.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • noidea/commands/suggest.py
  • noidea/commands/test.py
  • noidea/provider.py
  • tests/test_cli.py
  • tests/test_provider.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/provider-complete-transport

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AccursedGalaxy AccursedGalaxy merged commit 287fcb8 into main May 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant