@@ -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,73 @@ 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+ if ( ! workspace ) {
176+ vscode . window . showInformationMessage ( "No workspace connected." ) ;
177+ return ;
178+ }
179+
180+ const duration = await vscode . window . showInputBox ( {
181+ title : "Speed Test Duration" ,
182+ prompt : "Duration for the speed test (e.g., 5s, 10s, 1m)" ,
183+ value : "5s" ,
184+ validateInput : ( v ) => {
185+ return / ^ \d + [ s m h ] $ / . test ( v . trim ( ) )
186+ ? null
187+ : "Enter a duration like 5s, 10s, or 1m" ;
188+ } ,
189+ } ) ;
190+ if ( duration === undefined ) {
191+ return ;
192+ }
193+
194+ const result = await withCancellableProgress (
195+ async ( { signal } ) => {
196+ const baseUrl = this . requireExtensionBaseUrl ( ) ;
197+ const safeHost = toSafeHost ( baseUrl ) ;
198+ const binary = await this . cliManager . fetchBinary ( this . extensionClient ) ;
199+ const version = semver . parse ( await cliUtils . version ( binary ) ) ;
200+ const featureSet = featureSetForVersion ( version ) ;
201+ const configDir = this . pathResolver . getGlobalConfigDir ( safeHost ) ;
202+ const configs = vscode . workspace . getConfiguration ( ) ;
203+ const auth = resolveCliAuth ( configs , featureSet , baseUrl , configDir ) ;
204+ const globalFlags = getGlobalFlags ( configs , auth ) ;
205+ const workspaceName = createWorkspaceIdentifier ( workspace ) ;
206+
207+ return cliUtils . speedtest ( binary , globalFlags , workspaceName , {
208+ signal,
209+ duration : duration . trim ( ) ,
210+ } ) ;
211+ } ,
212+ {
213+ location : vscode . ProgressLocation . Notification ,
214+ title : `Running ${ duration . trim ( ) } speed test...` ,
215+ cancellable : true ,
216+ } ,
217+ ) ;
218+
219+ if ( ! result . ok ) {
220+ if ( ! result . cancelled ) {
221+ this . logger . error ( "Speed test failed" , result . error ) ;
222+ vscode . window . showErrorMessage (
223+ `Speed test failed: ${ result . error instanceof Error ? result . error . message : String ( result . error ) } ` ,
224+ ) ;
225+ }
226+ return ;
227+ }
228+
229+ const doc = await vscode . workspace . openTextDocument ( {
230+ content : result . value ,
231+ language : "json" ,
232+ } ) ;
233+ vscode . window . showTextDocument ( doc ) ;
234+ }
235+
165236 /**
166237 * View the logs for the currently connected workspace.
167238 */
@@ -505,7 +576,7 @@ export class Commands {
505576 const configDir = this . pathResolver . getGlobalConfigDir ( safeHost ) ;
506577 const configs = vscode . workspace . getConfiguration ( ) ;
507578 const auth = resolveCliAuth ( configs , featureSet , baseUrl , configDir ) ;
508- const globalFlags = getGlobalFlags ( configs , auth ) ;
579+ const globalFlags = getGlobalShellFlags ( configs , auth ) ;
509580 terminal . sendText (
510581 `${ escapeCommandArg ( binary ) } ${ globalFlags . join ( " " ) } ssh ${ app . workspace_name } ` ,
511582 ) ;
0 commit comments