Skip to content

[DX-1097] Fixed capability flag inconsistency for keys create/update#322

Merged
sacOO7 merged 1 commit intomainfrom
fix/auth-keys-capabilities
Apr 16, 2026
Merged

[DX-1097] Fixed capability flag inconsistency for keys create/update#322
sacOO7 merged 1 commit intomainfrom
fix/auth-keys-capabilities

Conversation

@sacOO7
Copy link
Copy Markdown
Contributor

@sacOO7 sacOO7 commented Apr 15, 2026

  • Fixes https://ably.atlassian.net/browse/DX-1097
  • Earlier keys create supported json capability and keys update supported comma-separated capability individually.
  • Now both commands support bothjson and comma-separated capability support

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cli-web-cli Ready Ready Preview, Comment Apr 16, 2026 9:58am

Request Review

@claude-code-ably-assistant
Copy link
Copy Markdown

Walkthrough

This PR fixes a capability format inconsistency between keys create and keys update: previously create only accepted JSON capabilities while update only accepted comma-separated. Both commands now accept either format (JSON object for per-channel granularity, or a comma-separated list that maps to {"*": [...]} globally). The PR also extracts two shared utility functions — parseCapabilities and resolveCurrentKeyName — to deduplicate logic spread across several key commands.

Changes

Area Files Summary
Commands src/commands/auth/keys/create.ts Switched from raw JSON.parse to parseCapabilities; updated flag description and examples
Commands src/commands/auth/keys/update.ts Replaced inline comma-split logic with parseCapabilities; updated flag description and added JSON example
Commands src/commands/auth/keys/current.ts, get.ts, list.ts Replaced duplicated key-name resolution inline expressions with resolveCurrentKeyName
Commands src/commands/auth/keys/index.ts Minor example improvement: added --name flag to update example
Utils src/utils/key-parsing.ts Added parseCapabilities() and resolveCurrentKeyName() utility functions
Tests test/unit/commands/auth/keys/create.test.ts Updated invalid-capabilities test fixture to use {invalid-json so it triggers the JSON path (consistent with the new format detection)

Review Notes

  • Behavioral change: keys create --capabilities "publish,subscribe" now works (previously would fail with a JSON parse error). Existing JSON usage is unchanged.
  • Error message change: The error for an invalid capabilities value has changed from "Invalid capabilities JSON format…" to "Invalid capabilities format…". Low impact but worth noting for any scripts or tests that assert on that string.
  • Comma-separated always maps to {"*": [...]} (all channels): This is intentional and matches prior update behaviour, but reviewers should confirm this is the correct semantics for both commands.
  • resolveCurrentKeyName edge case: The previous get.ts logic used keyId.split(".")[1] ?? keyId for the suffix when the key ID already contained a dot — the new resolveCurrentKeyName returns the full keyId as-is if it includes a dot, which is simpler and consistent with the other commands. Worth a sanity check that the old edge-case path was never reachable/needed.
  • Test coverage gap: There are no new unit tests for the update command's JSON capability path, or for the new parseCapabilities utility in isolation. A quick key-parsing.test.ts covering both branches (JSON and comma-separated, plus the error path) would improve confidence.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes how API key capabilities are provided across auth keys create and auth keys update, so both commands accept either a JSON capability object (per-channel) or a comma-separated capability list (applied to *).

Changes:

  • Added shared parsing helpers in src/utils/key-parsing.ts (parseCapabilities, resolveCurrentKeyName).
  • Updated auth keys create and auth keys update to use unified capability parsing and updated help/examples accordingly.
  • Refactored key “current key name” formatting in key listing/get/current commands to use the shared resolver.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/unit/commands/auth/keys/create.test.ts Adjusts invalid-capabilities test input to still trigger JSON parsing failure.
src/utils/key-parsing.ts Introduces shared helpers for current key name formatting and capability parsing.
src/commands/auth/keys/update.ts Uses shared parseCapabilities and updates flag description/examples.
src/commands/auth/keys/list.ts Uses resolveCurrentKeyName to compute highlighted “current key”.
src/commands/auth/keys/index.ts Updates the topic examples to show keys update with --name.
src/commands/auth/keys/get.ts Uses resolveCurrentKeyName for env/current-key override detection.
src/commands/auth/keys/current.ts Uses resolveCurrentKeyName for formatting current key output.
src/commands/auth/keys/create.ts Uses shared parseCapabilities and updates messaging/docs for new input forms.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/key-parsing.ts
Comment thread src/utils/key-parsing.ts Outdated
Comment thread src/commands/auth/keys/update.ts Outdated
Comment thread src/commands/auth/keys/create.ts Outdated
Comment thread src/commands/auth/keys/update.ts
@sacOO7 sacOO7 force-pushed the fix/auth-keys-capabilities branch from b7f671d to 6599aa0 Compare April 15, 2026 17:47
@sacOO7 sacOO7 force-pushed the fix/auth-keys-capabilities branch from 6599aa0 to 8edc9f3 Compare April 16, 2026 08:08
@sacOO7 sacOO7 changed the title Fixed capability flag inconsistency for keys create/update [DX-1097] Fixed capability flag inconsistency for keys create/update Apr 16, 2026
@sacOO7 sacOO7 force-pushed the fix/auth-keys-capabilities branch from 8edc9f3 to 8f971bd Compare April 16, 2026 08:19
@sacOO7 sacOO7 force-pushed the fix/auth-keys-capabilities branch from 8f971bd to 1b31af4 Compare April 16, 2026 08:24
@sacOO7 sacOO7 force-pushed the fix/auth-keys-capabilities branch from 1b31af4 to 14efa99 Compare April 16, 2026 08:25
@sacOO7 sacOO7 force-pushed the fix/auth-keys-capabilities branch from 14efa99 to b4f6a93 Compare April 16, 2026 08:31
- Added support for both json and comma separated capability support for keys capabilities
- Extracted key parsing logic into key-parsing.ts
@sacOO7 sacOO7 merged commit 96ef184 into main Apr 16, 2026
12 checks passed
@sacOO7 sacOO7 deleted the fix/auth-keys-capabilities branch April 16, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants