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
+8 -1
View File
@@ -107,6 +107,10 @@ type Config struct {
// where users will land when they connect via SSH. Default is the home
// directory of the user.
WorkingDirectory func() string
// EnvInfo sources the session command environment. Default is
// usershell.SystemEnvInfo. A container override still applies per
// session when ExperimentalContainers is enabled.
EnvInfo usershell.EnvInfoer
// X11DisplayOffset is the offset to add to the X11 display number.
// Default is 10.
X11DisplayOffset *int
@@ -189,6 +193,9 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
return home
}
}
if config.EnvInfo == nil {
config.EnvInfo = &usershell.SystemEnvInfo{}
}
if config.ReportConnection == nil {
config.ReportConnection = func(uuid.UUID, MagicSessionType, string) func(int, string) { return func(int, string) {} }
}
@@ -619,7 +626,7 @@ func (s *Server) sessionStart(logger slog.Logger, session ssh.Session, env []str
ptyLabel = "yes"
}
var ei usershell.EnvInfoer
ei := s.config.EnvInfo
var err error
if s.config.ExperimentalContainers && container != "" {
ei, err = agentcontainers.EnvInfo(ctx, s.Execer, container, containerUser)