[DX-974] Fix commands params validation, --help documentation and json logging#181
[DX-974] Fix commands params validation, --help documentation and json logging#181
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughUpdated CLI help texts and examples across commands (channels, queues, rooms, integrations, auth), adjusted examples for channels annotations, added argument validation in base command parse, made openUrl optionally emit JSON, adjusted ChatClient logging behavior, extended channel metrics display, and added/updated unit tests for validation and JSON logging. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
| FLAGS | ||
| -v, --verbose Output verbose logs | ||
| --cipher=<value> Decryption key for encrypted messages (AES-128) | ||
| --direction=<option> [default: backwards] Direction of message retrieval (default: backwards) |
There was a problem hiding this comment.
No need to show default twice in help methods
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/utils/open-url.ts (1)
14-43:⚠️ Potential issue | 🟡 MinorOnly
src/commands/status.tsneeds updating for consistent JSON output.The
isJsonOutputparameter implementation insrc/utils/open-url.tsis correct. However,src/commands/status.tssupports the--jsonflag and should pass it toopenUrl()at line 90:await openUrl("https://status.ably.com", this, this.shouldOutputJson(flags));Without this change, users running
status --json --openwill receive colored text mixed with JSON output, breaking parsers.src/commands/support/contact.tsdoes not support--jsonand does not require updating.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/open-url.ts` around lines 14 - 43, The status command currently calls openUrl(...) without forwarding the JSON output flag, causing mixed colored text in JSON mode; update the call to openUrl in the status command to pass this.shouldOutputJson(flags) as the third argument so it becomes openUrl(..., this, this.shouldOutputJson(flags)) and ensure the import/use of openUrl and shouldOutputJson(flags) are correctly referenced (openUrl function and the command's shouldOutputJson method).
🧹 Nitpick comments (2)
src/commands/channels/annotations/delete.ts (1)
26-31: Consider updating the type argument description to match new examples.The
typeargument description still referencesreactions:flag.v1, reactions:multiple.v1, but the new examples usereceipts:flag.v1,categories:distinct.v1,reactions:unique.v1, andrating:multiple.v1. Consider updating the description to reflect the broader set of annotation types.📝 Suggested update
type: Args.string({ description: - "The annotation type (e.g., reactions:flag.v1, reactions:multiple.v1)", + "The annotation type (e.g., receipts:flag.v1, reactions:unique.v1, rating:multiple.v1)", required: true, }),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/channels/annotations/delete.ts` around lines 26 - 31, Update the description text for the Args.string argument named "type" in delete.ts to reflect the new example annotation types; replace the old examples ("reactions:flag.v1, reactions:multiple.v1") with the current examples such as "receipts:flag.v1, categories:distinct.v1, reactions:unique.v1, rating:multiple.v1" so the description accurately represents the broader set of supported annotation types.src/commands/channels/annotations/publish.ts (1)
26-31: Consider updating the type argument description to match new examples.Similar to
delete.ts, thetypeargument description still referencesreactions:flag.v1, reactions:multiple.v1, but the examples now usemetrics:total.v1,receipts:flag.v1,categories:distinct.v1,reactions:unique.v1, andrating:multiple.v1.📝 Suggested update
type: Args.string({ description: - "The annotation type (e.g., reactions:flag.v1, reactions:multiple.v1)", + "The annotation type (e.g., metrics:total.v1, receipts:flag.v1, rating:multiple.v1)", required: true, }),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/channels/annotations/publish.ts` around lines 26 - 31, Update the description of the `type` argument inside the Args.string(...) call in publish.ts to reflect the current examples instead of the old reactions examples; specifically replace the example list with the new annotation types used elsewhere (e.g., metrics:total.v1, receipts:flag.v1, categories:distinct.v1, reactions:unique.v1, rating:multiple.v1) so the `type` Arg description matches delete.ts and the rest of the codebase.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/channels/list.ts`:
- Around line 16-25: The ChannelMetrics interface declares objectPublishers and
objectSubscribers while the test mock in list.test.ts and the OccupancyMetrics
type (used in channels/occupancy/get.ts) do not — confirm whether the Ably
channel enumeration API actually returns these fields; if it does not, remove
objectPublishers and objectSubscribers from ChannelMetrics and any related
checks, and ensure OccupancyMetrics and test mocks in list.test.ts reflect the
same shape; if it does return them, add those fields to OccupancyMetrics and
update the mock data in list.test.ts (and any other affected tests) so
interfaces and tests match the real API.
---
Outside diff comments:
In `@src/utils/open-url.ts`:
- Around line 14-43: The status command currently calls openUrl(...) without
forwarding the JSON output flag, causing mixed colored text in JSON mode; update
the call to openUrl in the status command to pass this.shouldOutputJson(flags)
as the third argument so it becomes openUrl(..., this,
this.shouldOutputJson(flags)) and ensure the import/use of openUrl and
shouldOutputJson(flags) are correctly referenced (openUrl function and the
command's shouldOutputJson method).
---
Nitpick comments:
In `@src/commands/channels/annotations/delete.ts`:
- Around line 26-31: Update the description text for the Args.string argument
named "type" in delete.ts to reflect the new example annotation types; replace
the old examples ("reactions:flag.v1, reactions:multiple.v1") with the current
examples such as "receipts:flag.v1, categories:distinct.v1, reactions:unique.v1,
rating:multiple.v1" so the description accurately represents the broader set of
supported annotation types.
In `@src/commands/channels/annotations/publish.ts`:
- Around line 26-31: Update the description of the `type` argument inside the
Args.string(...) call in publish.ts to reflect the current examples instead of
the old reactions examples; specifically replace the example list with the new
annotation types used elsewhere (e.g., metrics:total.v1, receipts:flag.v1,
categories:distinct.v1, reactions:unique.v1, rating:multiple.v1) so the `type`
Arg description matches delete.ts and the rest of the codebase.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fcf6833d-8de8-4c2c-977b-ddad643091b4
📒 Files selected for processing (12)
README.mdsrc/commands/channels/annotations/delete.tssrc/commands/channels/annotations/index.tssrc/commands/channels/annotations/publish.tssrc/commands/channels/annotations/subscribe.tssrc/commands/channels/history.tssrc/commands/channels/inspect.tssrc/commands/channels/list.tssrc/commands/channels/subscribe.tssrc/commands/queues/create.tssrc/commands/rooms/messages/history.tssrc/utils/open-url.ts
| EXAMPLES | ||
| $ ably queues create --name "my-queue" | ||
|
|
||
| $ ably queues create --name "my-queue" --ttl 3600 --max-length 100000 |
There was a problem hiding this comment.
We are showing max values for both ttl and max-length, so updated to
ably queues create --name "my-queue" --ttl 300 --max-length 5000
There was a problem hiding this comment.
Pull request overview
This PR addresses DX-974 by aligning CLI --help/README documentation (examples and flag descriptions) with current command behavior, and additionally adjusts how URL-opening output is emitted in JSON mode.
Changes:
- Updates multiple command flag descriptions/examples to improve
--helpaccuracy (channels history/subscribe, rooms messages history, queues create, annotations commands). - Enhances
channels listoutput to show additional occupancy metrics when present. - Introduces JSON-mode handling for
openUrl()and wires it intochannels inspect.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/open-url.ts | Adds optional JSON output path when printing “Visit/Opening …” messages. |
| src/commands/rooms/messages/history.ts | Tweaks --order flag help text for clarity. |
| src/commands/queues/create.ts | Updates examples and revises --max-length/--ttl help text to mention maxima. |
| src/commands/channels/subscribe.ts | Clarifies cipher key encoding and delta compression help text. |
| src/commands/channels/list.ts | Adds optional display of additional occupancy metrics (object/presence subscribers/publishers). |
| src/commands/channels/inspect.ts | Passes JSON-mode indicator into openUrl(). |
| src/commands/channels/history.ts | Fixes examples and refines direction flag description. |
| src/commands/channels/annotations/subscribe.ts | Refreshes examples to match current annotation types/usage. |
| src/commands/channels/annotations/publish.ts | Refreshes examples to match current annotation types/usage. |
| src/commands/channels/annotations/index.ts | Updates topic-level examples for annotations. |
| src/commands/channels/annotations/delete.ts | Refreshes delete examples to match current annotation types/usage. |
| README.md | Regenerates/updates rendered help sections to match command example/flag text changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| '$ ably channels annotations delete my-channel "01234567890:0" "reactions:multiple.v1" --name thumbsup', | ||
| '$ ably channels annotations delete my-channel "01234567890:0" "reactions:flag.v1" --json', | ||
| '$ ably channels annotations delete my-channel "01234567890:0" "reactions:flag.v1" --pretty-json', | ||
| '$ ably channels annotations delete my-channel "01234567890:0" "receipts:flag.v1"', |
There was a problem hiding this comment.
--name isn't required for reactions:flag.v1 and reactions:total.v1
4313865 to
9c2e8a7
Compare
9c2e8a7 to
be142e9
Compare
397827f to
c30ec2f
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/channels/history.ts`:
- Around line 89-108: The progress/JSON "fetching" emission is happening before
buildHistoryParams(flags) which can throw, so move the block that calls
shouldOutputJson(), logJsonEvent(...) and the human log(formatProgress(...)) to
after the call to buildHistoryParams(flags); specifically, keep
buildHistoryParams(flags) where it is but relocate the entire "Show fetching
status" block (the calls to shouldOutputJson, logJsonEvent, log, formatProgress,
formatResource, and use of flags/channelName) to immediately after
buildHistoryParams returns so we only emit the fetching status when
historyParams was successfully constructed.
- Around line 50-53: The --direction flag currently omits the default from the
help text; update the Flags.string call for the direction flag (the property
named direction) so its description includes the default, e.g. change
description to "Direction of message retrieval (default: backwards)" or
"Direction of log retrieval (default: backwards)" while keeping options
["backwards","forwards"] so the help output matches the repo docs.
In `@src/commands/channels/publish.ts`:
- Line 56: The help text for the --delay option claims "max 25 msgs/sec" but
there is no enforcement; either remove the "max 25 msgs/sec" wording from the
description string for the --delay option or add a validator that enforces delay
>= 40ms (or equivalent rate limit) where the option is parsed/validated (look
for the --delay description string and the option/variable name delay in the
publish command implementation) and provide a clear error message when the user
supplies a value that would exceed 25 msgs/sec.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2a87f9bf-62f2-4d4f-b19d-c78d51d1b000
📒 Files selected for processing (26)
AGENTS.mdREADME.mdsrc/base-command.tssrc/chat-base-command.tssrc/commands/auth/issue-ably-token.tssrc/commands/auth/issue-jwt-token.tssrc/commands/channels/annotations/delete.tssrc/commands/channels/annotations/index.tssrc/commands/channels/annotations/publish.tssrc/commands/channels/annotations/subscribe.tssrc/commands/channels/history.tssrc/commands/channels/inspect.tssrc/commands/channels/list.tssrc/commands/channels/publish.tssrc/commands/channels/subscribe.tssrc/commands/integrations/create.tssrc/commands/queues/create.tssrc/commands/rooms/list.tssrc/commands/rooms/messages/history.tssrc/commands/rooms/messages/send.tssrc/commands/rooms/occupancy/get.tssrc/utils/open-url.tstest/unit/commands/channels/history.test.tstest/unit/commands/channels/publish.test.tstest/unit/commands/rooms/messages/history.test.tstest/unit/commands/rooms/messages/send.test.ts
✅ Files skipped from review due to trivial changes (12)
- src/commands/auth/issue-ably-token.ts
- src/commands/rooms/messages/history.ts
- src/commands/channels/annotations/subscribe.ts
- src/commands/integrations/create.ts
- src/commands/channels/annotations/index.ts
- AGENTS.md
- src/commands/auth/issue-jwt-token.ts
- src/commands/channels/annotations/publish.ts
- src/commands/queues/create.ts
- src/commands/channels/subscribe.ts
- src/commands/channels/annotations/delete.ts
- README.md
🚧 Files skipped from review as they are similar to previous changes (2)
- src/commands/channels/inspect.ts
- src/utils/open-url.ts
c30ec2f to
f9813f0
Compare
97826be to
5ca537b
Compare
5ca537b to
f5542f2
Compare
f5542f2 to
74c7fac
Compare
|
the help text cleanup, JSON output fixes, Chat SDK log suppression, and queue max validation all look good. Can you remove the empty name validation (validateChannelName, validateRoomName, validateSpaceName) and all the calls to them? oclif already catches missing args since they're required: true. The empty string edge case is too niche to justify touching 50+ files, and if we ever want it, it should live in arg parsing, not manual calls in every run() method. |
makes sense, will update accordingly 👍 |
74c7fac to
cab6161
Compare
b326422 to
4e10e3e
Compare
4e10e3e to
40a687c
Compare
40a687c to
f9a5cfd
Compare
f9a5cfd to
06c979f
Compare
|
Updated the code, removed |
| await openUrl(url, this); | ||
| const isJson = this.shouldOutputJson(flags); | ||
| if (isJson) { | ||
| this.logJsonResult({ message: `Opening ${url} in your browser` }, flags); |
There was a problem hiding this comment.
how would this work for agents using the cli in --json mode?
There was a problem hiding this comment.
It shows
> bin/run.js channels inspect demo --pretty-json
{
"type": "result",
"command": "channels:inspect",
"success": true,
"message": "Opening https://ably.com/accounts/DIBHRw/apps/Sh_lKw/channels/demo in your browser"
}
| description: "Length of encryption key in bits (default: 256)", | ||
| description: "Length of encryption key in bits", | ||
| }), | ||
| "cipher-mode": Flags.string({ |
There was a problem hiding this comment.
appreciate you've not changed this bit directly but since this PR is in this area...
we seem to have quite a few flags here that don't take any options at all? From a quick look, some of them don't even have an option e.g. cipher-mode is apparently always "cbc", and the algorithm is always "aes" when looking at what Ably supports? (worth double checking this)
Can you do an audit here and see what flags we actually need, the ones that stay should have options where applicable
There was a problem hiding this comment.
I had cross validated this with respect to doc, will check and put links here
| async run(): Promise<void> { | ||
| const { flags } = await this.parse(RulesCreateCommand); | ||
| if (!flags.name?.trim()) { | ||
| this.fail("Rule name cannot be empty", flags, "parse"); |
There was a problem hiding this comment.
same as previous comment... i don't think we need empty string validation
| async run(): Promise<void> { | ||
| const { flags } = await this.parse(AppsCreateCommand); | ||
| if (!flags.name?.trim()) { | ||
| this.fail("App name cannot be empty", flags, "parse"); |
There was a problem hiding this comment.
same as previous comment... i don't think we need empty string validation...
there are a few instances of this in the PR, can you check them all please
There was a problem hiding this comment.
Sorry, forgot to mention, intentionally kept for rules, queues and keys
There was a problem hiding this comment.
Only for queues create, rules create etc
There was a problem hiding this comment.
But if you want, I can remove it, but check is not repetitive as such
There was a problem hiding this comment.
we should have 1 way of doing things, we either add this empty string validation to all flags or none.
I don't think it adds any value tbh... required flags are already validated by oclif, and the "system" would throw an error if necessary if someone passed an empty string
There was a problem hiding this comment.
Problem is empty strings aren't validated by oclif, so the issue, but will remove it
- Fixed compile issues in presence get and presence subscribe
06c979f to
fea0de7
Compare
--helpdoc for most of the commands- Added emptychannelName,roomName,spaceNamevalidations etcjsonpretty print for some of theably-clicommandsSummary by CodeRabbit
Documentation
New Examples
User-facing Changes
Validation