Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions cmd/workspace/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
45 changes: 45 additions & 0 deletions cmd/workspace/up/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: ""}

Expand Down
Loading