-
Notifications
You must be signed in to change notification settings - Fork 41
Add speedtest command #864
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,6 +146,53 @@ export class Commands { | |
| this.logger.debug("Login complete to deployment:", url); | ||
| } | ||
|
|
||
| /** | ||
| * Run a speed test against the currently connected workspace and display the | ||
| * results in a new editor document. | ||
| */ | ||
| public async speedTest(): Promise<void> { | ||
| if (!this.workspace) { | ||
| vscode.window.showInformationMessage("No workspace connected."); | ||
| return; | ||
| } | ||
|
|
||
| await withProgress( | ||
| { | ||
| location: vscode.ProgressLocation.Notification, | ||
| title: "Running speed test...", | ||
| }, | ||
| async () => { | ||
| const baseUrl = this.requireExtensionBaseUrl(); | ||
| const safeHost = toSafeHost(baseUrl); | ||
| const binary = await this.cliManager.fetchBinary(this.extensionClient); | ||
| const version = semver.parse(await cliUtils.version(binary)); | ||
| const featureSet = featureSetForVersion(version); | ||
| const configDir = this.pathResolver.getGlobalConfigDir(safeHost); | ||
| const configs = vscode.workspace.getConfiguration(); | ||
| const auth = resolveCliAuth(configs, featureSet, baseUrl, configDir); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we only pass the |
||
| const workspaceName = createWorkspaceIdentifier(this.workspace!); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should avoid these kinds of |
||
|
|
||
| try { | ||
| const stdout = await cliUtils.speedtest( | ||
| binary, | ||
| auth, | ||
| workspaceName, | ||
| ); | ||
| const doc = await vscode.workspace.openTextDocument({ | ||
| content: stdout, | ||
| language: "json", | ||
| }); | ||
| await vscode.window.showTextDocument(doc); | ||
| } catch (error) { | ||
|
Comment on lines
+181
to
+186
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO I think we should show a save dialog instead of opening an untitled window. We can show the save dialog then an info dialog that confirms it's been saved with a button to open the file in the editor |
||
| this.logger.error("Speed test failed", error); | ||
| vscode.window.showErrorMessage( | ||
| `Speed test failed: ${error instanceof Error ? error.message : String(error)}`, | ||
| ); | ||
| } | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * View the logs for the currently connected workspace. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ import os from "node:os"; | |
| import path from "node:path"; | ||
| import { promisify } from "node:util"; | ||
|
|
||
| import type { CliAuth } from "../cliConfig"; | ||
|
|
||
| /** | ||
| * Custom error thrown when a binary file is locked (typically on Windows). | ||
| */ | ||
|
|
@@ -72,6 +74,34 @@ export async function version(binPath: string): Promise<string> { | |
| return json.version; | ||
| } | ||
|
|
||
| /** | ||
| * Run a speed test against the specified workspace and return the JSON output. | ||
| * Throw if unable to execute the binary or parse the output. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This here does not parse the output so this is inaccurate |
||
| */ | ||
| export async function speedtest( | ||
| binPath: string, | ||
| auth: CliAuth, | ||
| workspaceName: string, | ||
| ): Promise<string> { | ||
| const result = await promisify(execFile)(binPath, [ | ||
| ...authArgs(auth), | ||
| "speedtest", | ||
| workspaceName, | ||
| "--output", | ||
| "json", | ||
| ]); | ||
| return result.stdout; | ||
| } | ||
|
|
||
| /** | ||
| * Build CLI auth flags for execFile (no shell escaping). | ||
| */ | ||
| function authArgs(auth: CliAuth): string[] { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure that this function exists elsewhere already, |
||
| return auth.mode === "url" | ||
| ? ["--url", auth.url] | ||
| : ["--global-config", auth.configDir]; | ||
| } | ||
|
|
||
| export interface RemovalResult { | ||
| fileName: string; | ||
| error: unknown; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/usr/bin/env bash | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make this a JS file and run it using node so it's cross-platform |
||
|
|
||
| # Prints each argument on its own line, so tests can verify exact args. | ||
| for arg in "$@"; do | ||
| echo "$arg" | ||
| done | ||
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.
Should we pass the cancellation token to the CLI here? Also possibly use the
-targument and mention that in the title: https://coder.com/docs/reference/cli/speedtest#-t---time