Skip to content

Conversation

@m-hulbert
Copy link
Contributor

@m-hulbert m-hulbert commented Oct 10, 2025

Description

This PR fixes issues with the channel-rules commands;

  • channel-rules create
  • channel-rules update
  • channel-rules delete

channel-rules create

  • Was always failing because it was passing channelNamepsace instead of id in the request.
  • Correctly handles null being returned for batchingInterval and conflationInterval.

channel-rules update and channel-rules delete

  • These commands would complete but with an error. They now correctly handle null being returned for batchingInterval and conflationInterval.

Summary by CodeRabbit

  • New Features
    • None
  • Bug Fixes
    • More consistent display of batchingInterval and conflationInterval in create, update, and delete outputs, including proper handling of null/zero values.
  • Refactor
    • JSON output for channel rule namespaces now uses an id field for the namespace identifier, replacing the previous key.
  • Documentation
    • None
  • Tests
    • None
  • Chores
    • None

@m-hulbert m-hulbert requested a review from a team October 10, 2025 12:23
@m-hulbert m-hulbert self-assigned this Oct 10, 2025
@m-hulbert m-hulbert requested review from zknill and removed request for a team October 10, 2025 12:23
@vercel
Copy link

vercel bot commented Oct 10, 2025

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

Project Deployment Preview Comments Updated (UTC)
cli-web-cli Ready Ready Preview Comment Oct 10, 2025 1:44pm

@coderabbitai
Copy link

coderabbitai bot commented Oct 10, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Renamed Namespace payload field from channelNamespace to id and updated create command to map name to id. Adjusted logging conditions for batchingInterval and conflationInterval across create, update, and delete commands to use loose null checks (!= null). No changes to command signatures or overall control flow.

Changes

Cohort / File(s) Summary of edits
Channel rules commands: payload and logging checks
src/commands/apps/channel-rules/create.ts, src/commands/apps/channel-rules/update.ts, src/commands/apps/channel-rules/delete.ts
Create: map name -> Namespace.id (was channelNamespace); broaden interval logging checks to use != null. Update/Delete: replace strict undefined checks with loose null checks for batchingInterval and conflationInterval in human-readable output paths.
Control API types: Namespace shape
src/services/control-api.ts
Namespace interface change: remove channelNamespace:string; add id:string. No logic changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant CLI as Channel Rules CLI
  participant API as Control API

  U->>CLI: apps channel-rules create/update/delete
  Note over CLI: Build payload using Namespace.id<br/>(renamed from channelNamespace)
  CLI->>API: createNamespace/updateNamespace/deleteNamespace
  API-->>CLI: Response (Namespace)
  alt --json flag
    CLI-->>U: JSON output
  else human-readable
    Note over CLI: Log batchingInterval / conflationInterval<br/>when value != null
    CLI-->>U: Text summary
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

Thump goes my paw on the meadow’s floor,
We swapped a name, just one field more.
Intervals peek when not quite null,
Logs now gleam with a tidier pull.
I nibble docs in carrot hues—
Hop, hop! to ship these channel rules. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly summarizes the primary changes by referencing both the correction of property names and handling of null values in the channel rule commands, matching the pull request objectives in a concise, specific sentence.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/commands/apps/channel-rules/create.ts (1)

122-136: Update tests to expect id instead of channelNamespace
Tests in test/unit/commands/channel-rule/create.test.ts.skip and test/integration/control-api.test.ts still assert on channelNamespace in the POST body—change those to id to match the updated payload key.

src/services/control-api.ts (1)

221-238: Update tests to use id instead of channelNamespace
All assertions in test/unit/commands/channel-rule/create.test.ts.skip and test/integration/control-api.test.ts still post { channelNamespace: … }. Replace every channelNamespace key with id to match the updated payload.

🧹 Nitpick comments (4)
src/services/control-api.ts (2)

47-64: Align Namespace types with API nulls for intervals.

The API may return null for batchingInterval and conflationInterval. Reflect this in types to avoid unsoundness.

Apply:

 export interface Namespace {
   appId: string;
   authenticated?: boolean;
   batchingEnabled?: boolean;
-  batchingInterval?: number;
+  batchingInterval?: number | null;
   conflationEnabled?: boolean;
-  conflationInterval?: number;
+  conflationInterval?: number | null;
   conflationKey?: string;
   created: number;
   exposeTimeSerial?: boolean;
   id: string;
   modified: number;
   persistLast?: boolean;
   persisted: boolean;
   populateChannelRegistry?: boolean;
   pushEnabled: boolean;
   tlsOnly?: boolean;
 }

555-571: Preserve API error codes to enable friendly auth errors in commands.

To support handling error.code === 40100 in commands (per guidelines), include the response code when available.

As a minimal change, attach code if present:

-      let errorMessage = `API request failed (${response.status} ${response.statusText})`;
+      let errorMessage = `API request failed (${response.status} ${response.statusText})`;
+      let errorCode: unknown = undefined;
       if (
         typeof responseData === "object" &&
         responseData !== null &&
         "message" in responseData &&
         typeof responseData.message === "string"
       ) {
         errorMessage += `: ${responseData.message}`;
+        if ("code" in responseData) {
+          // preserve code for downstream handling
+          // eslint-disable-next-line @typescript-eslint/no-explicit-any
+          errorCode = (responseData as any).code;
+        }
       } else if (
         typeof responseData === "string" &&
         responseData.length < 100
       ) {
         // Include short string responses directly
         errorMessage += `: ${responseData}`;
       }
-      throw new Error(errorMessage);
+      const err = new Error(errorMessage) as Error & { code?: unknown; status?: number };
+      if (errorCode !== undefined) err.code = errorCode;
+      err.status = response.status;
+      throw err;

Commands can then check for (error as any).code === 40100 to print a login hint. As per coding guidelines.

src/commands/apps/channel-rules/delete.ts (1)

45-51: Avoid appId shadowing inside try.

Inner let appId shadows the outer variable, so catch blocks may log undefined appId. Assign to the outer variable instead.

Apply:

-      let appId = flags.app;
+      appId = flags.app;
       if (!appId) {
         appId = await this.resolveAppId(flags);
       }
src/commands/apps/channel-rules/create.ts (1)

94-100: Remove appId shadowing inside try.

Inner let appId hides the outer variable; errors in the try block will yield undefined appId in catch output. Assign to the outer variable.

Apply:

-      let appId = flags.app;
+      appId = flags.app;
       if (!appId) {
         appId = await this.resolveAppId(flags);
       }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3da394f and f7d1b50.

📒 Files selected for processing (4)
  • src/commands/apps/channel-rules/create.ts (3 hunks)
  • src/commands/apps/channel-rules/delete.ts (2 hunks)
  • src/commands/apps/channel-rules/update.ts (2 hunks)
  • src/services/control-api.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/commands/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/AI-Assistance.mdc)

src/commands/**/*.ts: Commands should follow the oclif structure: export default class MyCommand extends Command { ... }
Command should support auth via the standard auth helper (import { getAuth } from '../../helpers/auth') and use it in the run method.
Use try/catch for error handling in commands, and provide user-friendly error messages (e.g., handle error.code === 40100 for authentication failures).
Do not use direct HTTP requests (e.g., fetch) for data plane APIs; use the Ably SDK instead.
Do not use hardcoded endpoint URLs; use configuration values (e.g., flags.controlHost, config.controlHost) when constructing URLs.
Do not use non-standard command structures (e.g., export default class { async execute(args) { ... } }); always use the oclif Command class.

Files:

  • src/commands/apps/channel-rules/update.ts
  • src/commands/apps/channel-rules/create.ts
  • src/commands/apps/channel-rules/delete.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/Development.mdc)

**/*.{ts,tsx}: Use TypeScript and follow best practice naming conventions
ESLint is used to ensure all code adheres best practices; ensure you check that all code passes the linter before concluding your work.

Files:

  • src/commands/apps/channel-rules/update.ts
  • src/commands/apps/channel-rules/create.ts
  • src/services/control-api.ts
  • src/commands/apps/channel-rules/delete.ts
src/commands/**/*.{ts,js}

📄 CodeRabbit inference engine (.cursor/rules/Development.mdc)

Follow oclif framework best practices as described in the oclif documentation.

Files:

  • src/commands/apps/channel-rules/update.ts
  • src/commands/apps/channel-rules/create.ts
  • src/commands/apps/channel-rules/delete.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: setup
  • GitHub Check: e2e-cli
  • GitHub Check: test
🔇 Additional comments (3)
src/commands/apps/channel-rules/update.ts (1)

308-312: Good null-handling; avoids toString on null.

Switching to != null correctly skips logging when values are null or undefined, preventing runtime errors and matching API behavior.

Also applies to: 320-324

src/commands/apps/channel-rules/delete.ts (1)

138-142: Correct null-handling for interval logging.

Using != null avoids logging and formatting null values. Good fix.

Also applies to: 150-154

src/commands/apps/channel-rules/create.ts (1)

212-216: Correctly handle null intervals in output.

The != null checks prevent logging nulls and avoid calling toString on null. Good.

Also applies to: 224-228

);
}

if (createdNamespace.batchingInterval !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should these be falsy checks?

        if (!createdNamespace.batchingInterval) {

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