feat(chats,auth,provider-connections): close P3 of #11 + extract dispatchWrite#20
Conversation
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
…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.
036bf2e to
58576bf
Compare
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
GET /api/v1/provider_connectionsprovider-connections listGET /api/v1/chatschats list [--page](upstream fixed 20/page)GET /api/v1/chats/:idchats show <id> [--page](messages 50/page)POST /api/v1/chatschats create --title --message --model [--apply]PATCH /api/v1/chats/:idchats update <id> --title [--apply]DELETE /api/v1/chats/:idchats delete <id> [--apply]POST /api/v1/chats/:chat_id/messageschats messages create --chat-id --content --model [--apply]POST /api/v1/chats/:chat_id/messages/retrychats messages retry --chat-id [--apply]PATCH /api/v1/auth/enable_aiauth enable-ai [--apply]Refactor —
dispatchWritePulled the repeated
if !apply { printDryRun(method, path, body); return }; printX(path, ...)pattern into a singledispatchWrite(apply, method, path, body)helper next toprintDryRuninreference_cmds.go. Migrated:The investment / financial / users / family-export
print*DryRunvariants 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.Failrather than silently no-oping.TDD notes
buildChatCreateBody,buildChatUpdateBody,buildMessageCreateBody,validateMessageRetryOptscovering required + optional fields and whitespace-only titles (matches upstreamvalidates :title, presence: true).chats listmust NOT expose--per-page(upstream uses a fixed page size).TestDispatchWrite_DryRun_POST/_DryRun_DELETE_OmitsNilBodycapture stdout viaos.Pipeand parse the JSON envelope to lock in the dry-run shape.Find-based registration tests across chats / auth / provider-connections — cobra'sFindsilently returns the nearest matching ancestor when a leaf is missing, so the tests now compare resolved cmdName()to the expected leaf.go test ./...green across the suite.Refs #11.