Skip to content

feat(chats,auth,provider-connections): close P3 of #11 + extract dispatchWrite#20

Merged
dgilperez merged 1 commit into
mainfrom
feat/cli-chats-auth-provider
May 23, 2026
Merged

feat(chats,auth,provider-connections): close P3 of #11 + extract dispatchWrite#20
dgilperez merged 1 commit into
mainfrom
feat/cli-chats-auth-provider

Conversation

@dgilperez
Copy link
Copy Markdown
Collaborator

Closes the remaining read+chat surface flagged in #11 (P3), plus a small refactor that retires the dry-run-or-execute boilerplate across the codebase.

New commands

Endpoint Command
GET /api/v1/provider_connections provider-connections list
GET /api/v1/chats chats list [--page] (upstream fixed 20/page)
GET /api/v1/chats/:id chats show <id> [--page] (messages 50/page)
POST /api/v1/chats chats create --title --message --model [--apply]
PATCH /api/v1/chats/:id chats update <id> --title [--apply]
DELETE /api/v1/chats/:id chats delete <id> [--apply]
POST /api/v1/chats/:chat_id/messages chats messages create --chat-id --content --model [--apply]
POST /api/v1/chats/:chat_id/messages/retry chats messages retry --chat-id [--apply]
PATCH /api/v1/auth/enable_ai auth enable-ai [--apply]

Refactor — dispatchWrite

Pulled the repeated if !apply { printDryRun(method, path, body); return }; printX(path, ...) pattern into a single dispatchWrite(apply, method, path, body) helper next to printDryRun in reference_cmds.go. Migrated:

  • All 5 chats write sites
  • The 1 auth write site
  • The 3 existing tags create/update/delete sites

The investment / financial / users / family-export print*DryRun variants are intentionally left alone — they wrap their own per-context print helpers and consolidating them across contexts is a separate cleanup.

Unsupported HTTP methods now fail loudly via output.Fail rather than silently no-oping.

TDD notes

  • Tests-first for every new command (shape, registration, flag set).
  • Per-builder unit tests for buildChatCreateBody, buildChatUpdateBody, buildMessageCreateBody, validateMessageRetryOpts covering required + optional fields and whitespace-only titles (matches upstream validates :title, presence: true).
  • Explicit guard: chats list must NOT expose --per-page (upstream uses a fixed page size).
  • TestDispatchWrite_DryRun_POST / _DryRun_DELETE_OmitsNilBody capture stdout via os.Pipe and parse the JSON envelope to lock in the dry-run shape.
  • Tightened Find-based registration tests across chats / auth / provider-connections — cobra's Find silently returns the nearest matching ancestor when a leaf is missing, so the tests now compare resolved cmd Name() to the expected leaf.

go test ./... green across the suite.

Refs #11.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

Warning

Review limit reached

@dgilperez, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 47 minutes and 13 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, 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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8a9faa52-d77f-4c4e-b4de-165ad628d06b

📥 Commits

Reviewing files that changed from the base of the PR and between 90ee7c0 and 58576bf.

📒 Files selected for processing (11)
  • README.md
  • cmd/sure-cli/root/auth_cmd.go
  • cmd/sure-cli/root/auth_cmd_test.go
  • cmd/sure-cli/root/chats_cmd.go
  • cmd/sure-cli/root/chats_cmd_test.go
  • cmd/sure-cli/root/dispatch_write_test.go
  • cmd/sure-cli/root/provider_connections_cmd.go
  • cmd/sure-cli/root/provider_connections_cmd_test.go
  • cmd/sure-cli/root/reference_cmds.go
  • cmd/sure-cli/root/root.go
  • docs/ROADMAP.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cli-chats-auth-provider

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.

@superagent-security superagent-security Bot added contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis. labels May 23, 2026
…dispatchWrite

Adds the remaining `/api/v1/*` surface flagged in #11 (P3):

- `provider-connections list` — read-only aggregator status
  (`GET /api/v1/provider_connections`).
- `chats` subtree (requires AI enabled on the account):
  - `list` (paged at upstream's fixed 20/page; `--page` only).
  - `show <id> [--page]` (messages paged at 50/page upstream).
  - `create --title --message --model [--apply]` (POST).
  - `update <id> --title [--apply]` (PATCH).
  - `delete <id> [--apply]` (DELETE).
  - `messages create --chat-id --content --model [--apply]` (POST).
  - `messages retry --chat-id [--apply]` (POST collection action).
- `auth enable-ai [--apply]` — PATCH `/api/v1/auth/enable_ai`
  (correct verb per routes.rb:491).

Refactor (behavior-preserving):

Extracts `dispatchWrite(apply, method, path, body)` next to the
`printDryRun`/`printPost`/`printPatch`/`printDelete` helpers in
reference_cmds.go. It replaces the 4-line dry-run-or-execute pattern
across chats (5 sites), auth (1 site), and the existing tags
create/update/delete (3 sites). Unsupported HTTP methods fail loudly
via `output.Fail` rather than silently no-oping.

Other helpers like `printInvestmentDryRun`, `printFinancialDryRun`,
etc. are intentionally left alone — they wrap different print helpers
(scoped per output context) and consolidating them is out of scope.

TDD:

- Tests written first for each new command's shape, registration, and
  flag set.
- Per-builder unit tests for `buildChatCreateBody`,
  `buildChatUpdateBody`, `buildMessageCreateBody`,
  `validateMessageRetryOpts` covering required fields, optional
  fields, whitespace-only titles (matching upstream
  `validates :title, presence: true`), and `--per-page` absence on
  `chats list` (upstream has no per_page param).
- `TestDispatchWrite_DryRun_POST` and `_DryRun_DELETE_OmitsNilBody`
  capture stdout via `os.Pipe` and parse the JSON envelope to verify
  the dry-run shape end-to-end.
- Tightened `Find`-based registration tests across chats, auth,
  provider-connections — cobra's `Find` silently returns the parent
  when a leaf is missing, so tests now assert the resolved cmd's
  `Name()` matches the expected leaf.

Closes the read coverage half of #11.

Refs #11.
@dgilperez dgilperez force-pushed the feat/cli-chats-auth-provider branch from 036bf2e to 58576bf Compare May 23, 2026 19:41
@dgilperez dgilperez merged commit f1ef2cf into main May 23, 2026
5 checks passed
@dgilperez dgilperez deleted the feat/cli-chats-auth-provider branch May 23, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant