diff --git a/cmd/workspace/up/up.go b/cmd/workspace/up/up.go index a8976b1227..464fdb8945 100644 --- a/cmd/workspace/up/up.go +++ b/cmd/workspace/up/up.go @@ -614,13 +614,15 @@ func (cmd *UpCmd) prepareWorkspace(client client2.BaseWorkspaceClient) { targetIDE = cmd.IDE } - if !cmd.Platform.Enabled && ide.ReusesAuthSock(targetIDE) { - cmd.SSHAuthSockID = util.RandStringBytes(10) - log.Debug("reusing SSH_AUTH_SOCK", cmd.SSHAuthSockID) - } else if cmd.Platform.Enabled && ide.ReusesAuthSock(targetIDE) { - log.Debug( - "reusing SSH_AUTH_SOCK is not supported with platform mode, consider launching the IDE from the platform UI", - ) + if ide.ReusesAuthSock(targetIDE) { + if cmd.Platform.Enabled { + log.Debug( + "reusing SSH_AUTH_SOCK is not supported with platform mode, consider launching the IDE from the platform UI", + ) + } else { + cmd.SSHAuthSockID = util.RandStringBytes(10) + log.Debug("reusing SSH_AUTH_SOCK", cmd.SSHAuthSockID) + } } } diff --git a/cmd/workspace/up/up_test.go b/cmd/workspace/up/up_test.go index 3b59d6b70c..edfe71215a 100644 --- a/cmd/workspace/up/up_test.go +++ b/cmd/workspace/up/up_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/devsy-org/devsy/cmd/flags" + client2 "github.com/devsy-org/devsy/pkg/client" "github.com/devsy-org/devsy/pkg/config" "github.com/devsy-org/devsy/pkg/flags/names" "github.com/devsy-org/devsy/pkg/ide/opener" @@ -456,6 +457,50 @@ func mustBuildManifest(t *testing.T, remoteUser string) *snapshotpkg.Manifest { return manifest } +type prepareWorkspaceClient struct { + client2.BaseWorkspaceClient + workspaceConfig *provider2.Workspace +} + +func (c prepareWorkspaceClient) WorkspaceConfig() *provider2.Workspace { + return c.workspaceConfig +} + +func TestUpCmd_PrepareWorkspaceSSHAuthSock(t *testing.T) { + tests := []struct { + name string + ide string + platformMode bool + wantAuthSock bool + }{ + {name: "browser IDE", ide: string(config.IDEOpenVSCode), wantAuthSock: true}, + { + name: "browser IDE in platform mode", + ide: string(config.IDEOpenVSCode), + platformMode: true, + }, + {name: "IDE without auth socket reuse", ide: "none"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cmd := &UpCmd{} + cmd.Platform.Enabled = tt.platformMode + cmd.prepareWorkspace(prepareWorkspaceClient{ + workspaceConfig: &provider2.Workspace{ + IDE: provider2.WorkspaceIDEConfig{Name: tt.ide}, + }, + }) + + if tt.wantAuthSock { + assert.Len(t, cmd.SSHAuthSockID, 10) + } else { + assert.Empty(t, cmd.SSHAuthSockID) + } + }) + } +} + func TestBuildUpCmd_DoesNotMutateCallerGlobalFlags(t *testing.T) { g := &flags.GlobalFlags{Provider: "default-provider", ResultFormat: ""}