feat(agent): unify session env via EnvInfoer (#26099)

The agent resolved the session home directory two ways. agentssh went
through usershell, while agentproc called os.UserHomeDir directly and
skipped its user.Current fallback. Routing both through a single
usershell.EnvInfoer makes the resolution consistent, and agentproc
now gets the same fallback as the rest of the agent.

The shared seam is injectable, so SSH session tests can drive
environment resolution without touching real system state.
This commit is contained in:
Mathias Fredriksson
2026-06-05 21:22:23 +03:00
committed by GitHub
parent 578793be1d
commit d00ffbd828
6 changed files with 129 additions and 11 deletions
+3 -2
View File
@@ -16,6 +16,7 @@ import (
"github.com/coder/coder/v2/agent/agentchat"
"github.com/coder/coder/v2/agent/agentexec"
"github.com/coder/coder/v2/agent/agentgit"
"github.com/coder/coder/v2/agent/usershell"
"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/workspacesdk"
@@ -36,10 +37,10 @@ type API struct {
}
// NewAPI creates a new process API handler.
func NewAPI(logger slog.Logger, execer agentexec.Execer, updateEnv func(current []string) (updated []string, err error), pathStore *agentgit.PathStore, workingDir func() string) *API {
func NewAPI(logger slog.Logger, execer agentexec.Execer, pathStore *agentgit.PathStore, envInfo usershell.EnvInfoer, updateEnv func(current []string) (updated []string, err error), workingDir func() string) *API {
return &API{
logger: logger,
manager: newManager(logger, execer, updateEnv, workingDir),
manager: newManager(logger, execer, envInfo, updateEnv, workingDir),
pathStore: pathStore,
}
}