-
Notifications
You must be signed in to change notification settings - Fork 0
Add channels:inspect command to open dashboard #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { Args, Flags } from "@oclif/core"; | ||
| import chalk from "chalk"; | ||
|
|
||
| import { AblyBaseCommand } from "../../base-command.js"; | ||
| import openUrl from "../../utils/open-url.js"; | ||
|
|
||
| export default class ChannelsInspect extends AblyBaseCommand { | ||
| static override args = { | ||
| channel: Args.string({ | ||
| description: "The name of the channel to inspect in the Ably dashboard", | ||
| required: true, | ||
| }), | ||
| }; | ||
|
|
||
| static override description = | ||
| "Open the Ably dashboard to inspect a specific channel"; | ||
|
|
||
| static override examples = ["<%= config.bin %> <%= command.id %> my-channel"]; | ||
|
|
||
| static override flags = { | ||
| ...AblyBaseCommand.globalFlags, | ||
| app: Flags.string({ | ||
| description: "App ID to use (uses current app if not specified)", | ||
| env: "ABLY_APP_ID", | ||
| }), | ||
| }; | ||
|
|
||
| async run(): Promise<void> { | ||
| const { args, flags } = await this.parse(ChannelsInspect); | ||
|
|
||
| const currentAccount = this.configManager.getCurrentAccount(); | ||
| const accountId = currentAccount?.accountId; | ||
| if (!accountId) { | ||
| this.error( | ||
| `No account configured. Please log in first with ${chalk.cyan('"ably accounts login"')}.`, | ||
| ); | ||
| } | ||
|
|
||
| const appId = flags.app ?? this.configManager.getCurrentAppId(); | ||
| if (!appId) { | ||
| this.error( | ||
| `No app selected. Please select an app first with ${chalk.cyan('"ably apps switch"')} or specify one with ${chalk.cyan("--app")}.`, | ||
| ); | ||
| } | ||
|
|
||
| let dashboardHost = flags["dashboard-host"] ?? "https://ably.com"; | ||
| if (dashboardHost && !/^https?:\/\//i.test(dashboardHost)) { | ||
| dashboardHost = `https://${dashboardHost}`; | ||
| } | ||
| const url = `${dashboardHost}/accounts/${accountId}/apps/${appId}/channels/${encodeURIComponent(args.channel)}`; | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| await openUrl(url, this); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; | ||
| import { runCommand } from "@oclif/test"; | ||
| import { getMockConfigManager } from "../../../helpers/mock-config-manager.js"; | ||
|
|
||
| describe("channels:inspect command", () => { | ||
| const originalEnv = process.env.ABLY_WEB_CLI_MODE; | ||
|
|
||
| afterEach(() => { | ||
| if (originalEnv === undefined) { | ||
| delete process.env.ABLY_WEB_CLI_MODE; | ||
| } else { | ||
| process.env.ABLY_WEB_CLI_MODE = originalEnv; | ||
| } | ||
|
|
||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe("normal CLI mode", () => { | ||
| beforeEach(() => { | ||
| delete process.env.ABLY_WEB_CLI_MODE; | ||
| }); | ||
|
|
||
| it("should open browser with correct dashboard URL", async () => { | ||
| const mockConfig = getMockConfigManager(); | ||
| const accountId = mockConfig.getCurrentAccount()!.accountId!; | ||
| const appId = mockConfig.getCurrentAppId()!; | ||
|
|
||
| const { stdout } = await runCommand( | ||
| ["channels:inspect", "my-channel"], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(stdout).toContain("Opening"); | ||
| expect(stdout).toContain("in your browser"); | ||
| expect(stdout).toContain( | ||
| `https://ably.com/accounts/${accountId}/apps/${appId}/channels/my-channel`, | ||
| ); | ||
| }); | ||
|
|
||
| it("should URL-encode special characters in channel name", async () => { | ||
| const mockConfig = getMockConfigManager(); | ||
| const accountId = mockConfig.getCurrentAccount()!.accountId!; | ||
| const appId = mockConfig.getCurrentAppId()!; | ||
|
|
||
| const { stdout } = await runCommand( | ||
| ["channels:inspect", "my-channel/foo#bar"], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(stdout).toContain( | ||
| `https://ably.com/accounts/${accountId}/apps/${appId}/channels/my-channel%2Ffoo%23bar`, | ||
| ); | ||
| }); | ||
|
|
||
| it("should error when no account is configured", async () => { | ||
| const mockConfig = getMockConfigManager(); | ||
| mockConfig.clearAccounts(); | ||
|
|
||
| const { error } = await runCommand( | ||
| ["channels:inspect", "my-channel"], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(error).toBeDefined(); | ||
| expect(error?.message).toContain("No account configured"); | ||
| expect(error?.message).toContain("ably accounts login"); | ||
| }); | ||
|
|
||
| it("should error when no app is selected", async () => { | ||
| const mockConfig = getMockConfigManager(); | ||
| mockConfig.setCurrentAppIdForAccount(undefined); | ||
|
|
||
| const { error } = await runCommand( | ||
| ["channels:inspect", "my-channel"], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(error).toBeDefined(); | ||
| expect(error?.message).toContain("No app selected"); | ||
| expect(error?.message).toContain("ably apps switch"); | ||
| expect(error?.message).toContain("--app"); | ||
| }); | ||
|
|
||
| it("should use --app flag over current app", async () => { | ||
| const mockConfig = getMockConfigManager(); | ||
| const accountId = mockConfig.getCurrentAccount()!.accountId!; | ||
|
|
||
| const { stdout } = await runCommand( | ||
| ["channels:inspect", "my-channel", "--app", "custom-app-id"], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(stdout).toContain( | ||
| `https://ably.com/accounts/${accountId}/apps/custom-app-id/channels/my-channel`, | ||
| ); | ||
| }); | ||
|
|
||
| it("should use --app flag when no current app is set", async () => { | ||
| const mockConfig = getMockConfigManager(); | ||
| const accountId = mockConfig.getCurrentAccount()!.accountId!; | ||
| mockConfig.setCurrentAppIdForAccount(undefined); | ||
|
|
||
| const { stdout } = await runCommand( | ||
| ["channels:inspect", "my-channel", "--app", "override-app"], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(stdout).toContain( | ||
| `https://ably.com/accounts/${accountId}/apps/override-app/channels/my-channel`, | ||
| ); | ||
| }); | ||
|
|
||
| it("should use --dashboard-host flag to override base URL", async () => { | ||
| const mockConfig = getMockConfigManager(); | ||
| const accountId = mockConfig.getCurrentAccount()!.accountId!; | ||
| const appId = mockConfig.getCurrentAppId()!; | ||
|
|
||
| const { stdout } = await runCommand( | ||
| [ | ||
| "channels:inspect", | ||
| "my-channel", | ||
| "--dashboard-host", | ||
| "https://staging.ably.com", | ||
| ], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(stdout).toContain( | ||
| `https://staging.ably.com/accounts/${accountId}/apps/${appId}/channels/my-channel`, | ||
| ); | ||
| expect(stdout).not.toContain("https://ably.com/accounts"); | ||
| }); | ||
|
|
||
| it("should prepend https:// when --dashboard-host has no scheme", async () => { | ||
| const mockConfig = getMockConfigManager(); | ||
| const accountId = mockConfig.getCurrentAccount()!.accountId!; | ||
| const appId = mockConfig.getCurrentAppId()!; | ||
|
|
||
| const { stdout } = await runCommand( | ||
| [ | ||
| "channels:inspect", | ||
| "my-channel", | ||
| "--dashboard-host", | ||
| "staging.ably.com", | ||
| ], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(stdout).toContain( | ||
| `https://staging.ably.com/accounts/${accountId}/apps/${appId}/channels/my-channel`, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("web CLI mode", () => { | ||
| beforeEach(() => { | ||
| process.env.ABLY_WEB_CLI_MODE = "true"; | ||
| }); | ||
|
|
||
| it("should display URL without opening browser", async () => { | ||
| const mockConfig = getMockConfigManager(); | ||
| const accountId = mockConfig.getCurrentAccount()!.accountId!; | ||
| const appId = mockConfig.getCurrentAppId()!; | ||
|
|
||
| const { stdout } = await runCommand( | ||
| ["channels:inspect", "my-channel"], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(stdout).toContain("Visit"); | ||
| expect(stdout).toContain( | ||
| `https://ably.com/accounts/${accountId}/apps/${appId}/channels/my-channel`, | ||
| ); | ||
| expect(stdout).not.toContain("Opening"); | ||
| expect(stdout).not.toContain("in your browser"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("help", () => { | ||
| it("should display help with --help flag", async () => { | ||
| const { stdout } = await runCommand( | ||
| ["channels:inspect", "--help"], | ||
| import.meta.url, | ||
| ); | ||
|
|
||
| expect(stdout).toContain("Open the Ably dashboard to inspect"); | ||
| expect(stdout).toContain("USAGE"); | ||
| expect(stdout).toContain("ARGUMENTS"); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web CLI mode may lack account config
Medium Severity
In web CLI mode,
channels:inspectstill requiresthis.configManager.getCurrentAccount()andgetCurrentAppId()to be configured, and errors out if they aren’t. Since web CLI mode typically relies on environment-provided context rather than local config, this can make the new command unusable in the intended environment even thoughopenUrlsupports web CLI output.