@@ -21,13 +21,17 @@ import { toError } from "./error/errorUtils";
2121import { featureSetForVersion } from "./featureSet" ;
2222import { type Logger } from "./logging/logger" ;
2323import { type LoginCoordinator } from "./login/loginCoordinator" ;
24- import { withProgress } from "./progress" ;
24+ import { withCancellableProgress , withProgress } from "./progress" ;
2525import { maybeAskAgent , maybeAskUrl } from "./promptUtils" ;
2626import {
2727 RECOMMENDED_SSH_SETTINGS ,
2828 applySettingOverrides ,
2929} from "./remote/sshOverrides" ;
30- import { getGlobalFlags , resolveCliAuth } from "./settings/cli" ;
30+ import {
31+ getGlobalFlags ,
32+ getGlobalShellFlags ,
33+ resolveCliAuth ,
34+ } from "./settings/cli" ;
3135import { escapeCommandArg , toRemoteAuthority , toSafeHost } from "./util" ;
3236import { vscodeProposed } from "./vscodeProposed" ;
3337import {
@@ -162,6 +166,74 @@ export class Commands {
162166 this . logger . debug ( "Login complete to deployment:" , url ) ;
163167 }
164168
169+ /**
170+ * Run a speed test against the currently connected workspace and display the
171+ * results in a new editor document.
172+ */
173+ public async speedTest ( ) : Promise < void > {
174+ const workspace = this . workspace ;
175+ const client = this . remoteWorkspaceClient ;
176+ if ( ! workspace || ! client ) {
177+ vscode . window . showInformationMessage ( "No workspace connected." ) ;
178+ return ;
179+ }
180+
181+ const duration = await vscode . window . showInputBox ( {
182+ title : "Speed Test Duration" ,
183+ prompt : "Duration for the speed test (e.g., 5s, 10s, 1m)" ,
184+ value : "5s" ,
185+ } ) ;
186+ if ( duration === undefined ) {
187+ return ;
188+ }
189+
190+ const result = await withCancellableProgress (
191+ async ( { signal } ) => {
192+ const baseUrl = client . getAxiosInstance ( ) . defaults . baseURL ;
193+ if ( ! baseUrl ) {
194+ throw new Error ( "No deployment URL for the connected workspace" ) ;
195+ }
196+ const safeHost = toSafeHost ( baseUrl ) ;
197+ const binary = await this . cliManager . fetchBinary ( client ) ;
198+ const version = semver . parse ( await cliUtils . version ( binary ) ) ;
199+ const featureSet = featureSetForVersion ( version ) ;
200+ const configDir = this . pathResolver . getGlobalConfigDir ( safeHost ) ;
201+ const configs = vscode . workspace . getConfiguration ( ) ;
202+ const auth = resolveCliAuth ( configs , featureSet , baseUrl , configDir ) ;
203+ const globalFlags = getGlobalFlags ( configs , auth ) ;
204+ const workspaceName = createWorkspaceIdentifier ( workspace ) ;
205+
206+ return cliUtils . speedtest ( binary , globalFlags , workspaceName , {
207+ signal,
208+ duration : duration . trim ( ) ,
209+ } ) ;
210+ } ,
211+ {
212+ location : vscode . ProgressLocation . Notification ,
213+ title : `Running ${ duration . trim ( ) } speed test...` ,
214+ cancellable : true ,
215+ } ,
216+ ) ;
217+
218+ if ( result . ok ) {
219+ const doc = await vscode . workspace . openTextDocument ( {
220+ content : result . value ,
221+ language : "json" ,
222+ } ) ;
223+ await vscode . window . showTextDocument ( doc ) ;
224+ return ;
225+ }
226+
227+ if ( result . cancelled ) {
228+ return ;
229+ }
230+
231+ this . logger . error ( "Speed test failed" , result . error ) ;
232+ vscode . window . showErrorMessage (
233+ `Speed test failed: ${ toError ( result . error ) . message } ` ,
234+ ) ;
235+ }
236+
165237 /**
166238 * View the logs for the currently connected workspace.
167239 */
@@ -505,7 +577,7 @@ export class Commands {
505577 const configDir = this . pathResolver . getGlobalConfigDir ( safeHost ) ;
506578 const configs = vscode . workspace . getConfiguration ( ) ;
507579 const auth = resolveCliAuth ( configs , featureSet , baseUrl , configDir ) ;
508- const globalFlags = getGlobalFlags ( configs , auth ) ;
580+ const globalFlags = getGlobalShellFlags ( configs , auth ) ;
509581 terminal . sendText (
510582 `${ escapeCommandArg ( binary ) } ${ globalFlags . join ( " " ) } ssh ${ app . workspace_name } ` ,
511583 ) ;
0 commit comments