From d18422e1f8a28cc21272061a46408b21a101abbc Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 26 May 2022 01:47:41 +0000 Subject: [PATCH 1/7] fix: add coder executable to PATH --- agent/agent.go | 1 + 1 file changed, 1 insertion(+) diff --git a/agent/agent.go b/agent/agent.go index 18eaf6935c82c..fe8bc51bd3dd5 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -363,6 +363,7 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri // If using backslashes, it's unable to find the executable. executablePath = strings.ReplaceAll(executablePath, "\\", "/") cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, executablePath)) + cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s:%s`, os.Getenv("PATH"), executablePath)) // These prevent the user from having to specify _anything_ to successfully commit. // Both author and committer must be set! cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_AUTHOR_EMAIL=%s`, metadata.OwnerEmail)) From 2fa0e2d7e7b736a1514831e9e2ad797dcac3384d Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 26 May 2022 01:57:40 +0000 Subject: [PATCH 2/7] fix path list separator on windows --- agent/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/agent.go b/agent/agent.go index fe8bc51bd3dd5..c31c217098327 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -363,7 +363,7 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri // If using backslashes, it's unable to find the executable. executablePath = strings.ReplaceAll(executablePath, "\\", "/") cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, executablePath)) - cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s:%s`, os.Getenv("PATH"), executablePath)) + cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%s%s`, os.Getenv("PATH"), os.PathListSeparator, executablePath)) // These prevent the user from having to specify _anything_ to successfully commit. // Both author and committer must be set! cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_AUTHOR_EMAIL=%s`, metadata.OwnerEmail)) From 3e3247d2e21eed7c4114b4b83cf151b096e12bce Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 26 May 2022 02:07:35 +0000 Subject: [PATCH 3/7] Add test for PATH --- agent/agent.go | 2 +- agent/agent_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/agent/agent.go b/agent/agent.go index c31c217098327..6f39aabdad5fb 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -363,7 +363,7 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri // If using backslashes, it's unable to find the executable. executablePath = strings.ReplaceAll(executablePath, "\\", "/") cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, executablePath)) - cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%s%s`, os.Getenv("PATH"), os.PathListSeparator, executablePath)) + cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%b%s`, os.Getenv("PATH"), os.PathListSeparator, executablePath)) // These prevent the user from having to specify _anything_ to successfully commit. // Both author and committer must be set! cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_AUTHOR_EMAIL=%s`, metadata.OwnerEmail)) diff --git a/agent/agent_test.go b/agent/agent_test.go index cb476116eb435..cd052260f2b25 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -68,6 +68,20 @@ func TestAgent(t *testing.T) { require.True(t, strings.HasSuffix(strings.TrimSpace(string(output)), "gitssh --")) }) + t.Run("PATHHasCoder", func(t *testing.T) { + t.Parallel() + session := setupSSHSession(t, agent.Metadata{}) + command := "sh -c 'echo $PATH'" + if runtime.GOOS == "windows" { + command = "cmd.exe /c echo %PATH%" + } + output, err := session.Output(command) + require.NoError(t, err) + ex, err := os.Executable() + require.NoError(t, err) + require.True(t, strings.HasSuffix(strings.TrimSpace(string(output)), ex), string(output)) + }) + t.Run("SessionTTY", func(t *testing.T) { t.Parallel() if runtime.GOOS == "windows" { From aa5d78ea68077d90e5989f84b4207a7fd1546343 Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 26 May 2022 15:57:15 +0000 Subject: [PATCH 4/7] try to fix windows test --- agent/agent_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/agent_test.go b/agent/agent_test.go index cd052260f2b25..2d5e43bbadc3f 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -79,7 +79,7 @@ func TestAgent(t *testing.T) { require.NoError(t, err) ex, err := os.Executable() require.NoError(t, err) - require.True(t, strings.HasSuffix(strings.TrimSpace(string(output)), ex), string(output)) + require.True(t, strings.Contains(strings.TrimSpace(string(output)), ex), string(output), ex) }) t.Run("SessionTTY", func(t *testing.T) { From 1487c871d1668a61eb8da02c43caa15b9a74dcc4 Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 26 May 2022 17:20:10 +0000 Subject: [PATCH 5/7] try to fix windows test --- agent/agent_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/agent/agent_test.go b/agent/agent_test.go index 2d5e43bbadc3f..95565272df51c 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -78,6 +78,7 @@ func TestAgent(t *testing.T) { output, err := session.Output(command) require.NoError(t, err) ex, err := os.Executable() + t.Log(ex) require.NoError(t, err) require.True(t, strings.Contains(strings.TrimSpace(string(output)), ex), string(output), ex) }) From fcfb1ebfd3a08dcbb1a115c23af6dc479dc0cdad Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 26 May 2022 17:40:03 +0000 Subject: [PATCH 6/7] try to fix windows test --- agent/agent.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 6f39aabdad5fb..b580720462026 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -359,11 +359,11 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri if err != nil { return nil, xerrors.Errorf("getting os executable: %w", err) } + cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%v%s`, os.Getenv("PATH"), filepath.ListSeparator, executablePath)) // Git on Windows resolves with UNIX-style paths. // If using backslashes, it's unable to find the executable. - executablePath = strings.ReplaceAll(executablePath, "\\", "/") - cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, executablePath)) - cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%b%s`, os.Getenv("PATH"), os.PathListSeparator, executablePath)) + unixExecutablePath := strings.ReplaceAll(executablePath, "\\", "/") + cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, unixExecutablePath)) // These prevent the user from having to specify _anything_ to successfully commit. // Both author and committer must be set! cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_AUTHOR_EMAIL=%s`, metadata.OwnerEmail)) From 18fce7e537273250d4b6a46094d5aa72e6dce413 Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 26 May 2022 17:41:51 +0000 Subject: [PATCH 7/7] try to fix windows test --- agent/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/agent.go b/agent/agent.go index b580720462026..26f013589c384 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -359,7 +359,7 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri if err != nil { return nil, xerrors.Errorf("getting os executable: %w", err) } - cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%v%s`, os.Getenv("PATH"), filepath.ListSeparator, executablePath)) + cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%c%s`, os.Getenv("PATH"), filepath.ListSeparator, executablePath)) // Git on Windows resolves with UNIX-style paths. // If using backslashes, it's unable to find the executable. unixExecutablePath := strings.ReplaceAll(executablePath, "\\", "/")