fix: VSCode desktop connection (#7120)

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
This commit is contained in:
Muhammad Atif Ali 2023-04-14 17:32:18 +03:00 committed by GitHub
parent 942aba3a66
commit bb43713d38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -1407,5 +1407,14 @@ func expandDirectory(dir string) (string, error) {
}
dir = filepath.Join(home, dir[1:])
}
return os.ExpandEnv(dir), nil
dir = os.ExpandEnv(dir)
if !filepath.IsAbs(dir) {
home, err := userHomeDir()
if err != nil {
return "", err
}
dir = filepath.Join(home, dir)
}
return dir, nil
}

View File

@ -1391,6 +1391,22 @@ func TestAgent_Startup(t *testing.T) {
require.Equal(t, homeDir, client.getStartup().ExpandedDirectory)
})
t.Run("NotAbsoluteDirectory", func(t *testing.T) {
t.Parallel()
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
StartupScript: "true",
StartupScriptTimeout: 30 * time.Second,
Directory: "coder/coder",
}, 0)
assert.Eventually(t, func() bool {
return client.getStartup().Version != ""
}, testutil.WaitShort, testutil.IntervalFast)
homeDir, err := os.UserHomeDir()
require.NoError(t, err)
require.Equal(t, filepath.Join(homeDir, "coder/coder"), client.getStartup().ExpandedDirectory)
})
t.Run("HomeEnvironmentVariable", func(t *testing.T) {
t.Parallel()

View File

@ -38,6 +38,12 @@ To support any infrastructure and software stack, Coder provides a generic appro
}
```
> Note: The `dir` attribute can be set in multiple ways, for example:
>
> - `~/coder`
> - `/home/coder/coder`
> - `coder` (relative to the home directory)
- If you want the template to support any repository via [parameters](./parameters.md)
```hcl