Skip to content

Fix: json output for subscribe sub-commands#193

Draft
sacOO7 wants to merge 2 commits intomainfrom
fix/json-output-for-subscribe-commands
Draft

Fix: json output for subscribe sub-commands#193
sacOO7 wants to merge 2 commits intomainfrom
fix/json-output-for-subscribe-commands

Conversation

@sacOO7
Copy link
Contributor

@sacOO7 sacOO7 commented Mar 26, 2026

There was no progress indicator for subscribe commands in json mode, so added relevant json logging for the same. All subscribe commands are well addressed.

@vercel
Copy link

vercel bot commented Mar 26, 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 Mar 26, 2026 9:51am

Request Review

@sacOO7 sacOO7 changed the title Fix: json output for subscribe commands/sub-commands Fix: json output for subscribe sub-commands Mar 26, 2026
@sacOO7 sacOO7 force-pushed the fix/json-output-for-subscribe-commands branch from 3835c37 to 10fab1a Compare March 26, 2026 09:23
);
this.log(formatListening("Listening for occupancy events."));
}
this.logJsonStatus(
Copy link
Contributor Author

@sacOO7 sacOO7 Mar 26, 2026

Choose a reason for hiding this comment

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

Internally checks if json flag is enabled, if not, then it won't print anything.

Copy link

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

Adds standardized JSON status/progress signals for long-running subscribe and hold commands so --json consumers can distinguish “connecting” vs “ready”, and updates docs/tests accordingly.

Changes:

  • Introduces JsonStatusType enum and updates logJsonStatus call sites to use it.
  • Emits status=subscribing and status=listening JSON records across subscribe commands (including Chat room commands via setupRoomStatusHandler).
  • Updates documentation/templates and adjusts affected unit tests for NDJSON output.

Reviewed changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/unit/commands/spaces/subscribe.test.ts Adjusts JSON test to handle multi-line NDJSON output.
test/unit/commands/spaces/members/subscribe.test.ts Adjusts JSON test to handle multi-line NDJSON output.
src/utils/json-status.ts Adds enum for standardized JSON status values.
src/commands/spaces/subscribe.ts Emits subscribing/listening JSON status for space updates subscribe.
src/commands/spaces/occupancy/subscribe.ts Emits subscribing/listening JSON status for space occupancy subscribe.
src/commands/spaces/members/subscribe.ts Emits subscribing/listening JSON status for members subscribe.
src/commands/spaces/members/enter.ts Replaces raw "holding" with JsonStatusType.Holding.
src/commands/spaces/locks/subscribe.ts Emits subscribing/listening JSON status for locks subscribe.
src/commands/spaces/locks/acquire.ts Replaces raw "holding" with JsonStatusType.Holding.
src/commands/spaces/locations/subscribe.ts Emits subscribing/listening JSON status for locations subscribe.
src/commands/spaces/locations/set.ts Replaces raw "holding" with JsonStatusType.Holding.
src/commands/spaces/cursors/subscribe.ts Emits subscribing/listening JSON status for cursors subscribe.
src/commands/spaces/cursors/set.ts Replaces raw "holding" with JsonStatusType.Holding.
src/commands/rooms/typing/subscribe.ts Adds subscribingMessage so room handler emits JSON subscribing status.
src/commands/rooms/reactions/subscribe.ts Adds subscribingMessage so room handler emits JSON subscribing status.
src/commands/rooms/presence/subscribe.ts Moves success/listening handling into room status handler and adds subscribing/listening messages.
src/commands/rooms/occupancy/subscribe.ts Adds subscribingMessage so room handler emits JSON subscribing status.
src/commands/rooms/messages/subscribe.ts Adds subscribingMessage so room handler emits JSON subscribing status.
src/commands/rooms/messages/reactions/subscribe.ts Adds subscribingMessage so room handler emits JSON subscribing status.
src/commands/logs/subscribe.ts Emits subscribing/listening JSON status for logs subscribe.
src/commands/logs/push/subscribe.ts Emits subscribing/listening JSON status for push logs subscribe.
src/commands/logs/connection-lifecycle/subscribe.ts Emits subscribing/listening JSON status for connection lifecycle logs subscribe.
src/commands/logs/channel-lifecycle/subscribe.ts Emits subscribing/listening JSON status for channel lifecycle logs subscribe.
src/commands/channels/subscribe.ts Emits subscribing/listening JSON status for channel subscribe.
src/commands/channels/presence/update.ts Replaces raw "holding" with JsonStatusType.Holding.
src/commands/channels/presence/subscribe.ts Emits subscribing/listening JSON status for channel presence subscribe.
src/commands/channels/presence/enter.ts Replaces raw "holding" with JsonStatusType.Holding.
src/commands/channels/occupancy/subscribe.ts Emits subscribing/listening JSON status for channel occupancy subscribe.
src/commands/channels/annotations/subscribe.ts Emits subscribing/listening JSON status for annotations subscribe.
src/chat-base-command.ts Extends room status handler to emit JSON subscribing/listening/disconnected statuses.
src/base-command.ts Uses enum for timeout completion status.
AGENTS.md Documents JsonStatusType usage rules and subscribe/hold patterns.
.claude/skills/ably-review/SKILL.md Updates review checklist to match new JsonStatusType convention.
.claude/skills/ably-new-command/references/patterns.md Updates command templates with new JSON status lifecycle.
.claude/skills/ably-codebase-review/SKILL.md Updates codebase review checklist for JsonStatusType + subscribe lifecycle.

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

Comment on lines +99 to +105
const lines = stdout.trim().split("\n").filter(Boolean);
const eventLine = lines.find((l) => {
const parsed = JSON.parse(l);
return parsed.type === "event";
});
expect(eventLine).toBeDefined();
const result = JSON.parse(eventLine!);
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

This test parses each stdout line with JSON.parse inside find(). If any non-JSON line is present (Node warnings, accidental human output), JSON.parse will throw and fail the test. Prefer using the existing NDJSON helpers (e.g. parseNdjsonLines/captureJsonLogs) or wrap parsing in try/catch and skip non-JSON lines before filtering for type === "event".

Copilot uses AI. Check for mistakes.
Comment on lines +105 to 112
const lines = stdout.trim().split("\n").filter(Boolean);
const eventLine = lines.find((l) => {
const parsed = JSON.parse(l);
return parsed.type === "event";
});
expect(eventLine).toBeDefined();
const result = JSON.parse(eventLine!);
expect(result.type).toBe("event");
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

This test assumes every non-empty stdout line is valid JSON and calls JSON.parse during find(). That will throw if any non-JSON output appears (Node warnings, progress messages, etc.). Use the shared NDJSON test helpers (parseNdjsonLines/captureJsonLogs) or defensively skip non-JSON lines when searching for the event record.

Copilot uses AI. Check for mistakes.
Comment on lines 1624 to 1626
if (this.shouldOutputJson(flags)) {
this.logJsonStatus("complete", message, flags);
this.logJsonStatus(JsonStatusType.Complete, message, flags);
} else {
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

logJsonStatus is now documented/used with JsonStatusType, but the method signature still accepts status: string, so passing raw strings will continue to compile and can silently violate the new convention. Consider typing the parameter as status: JsonStatusType (or JsonStatusType | string temporarily) to enforce the rule at compile time.

Copilot uses AI. Check for mistakes.
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.

2 participants