mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: pass agent context config explicitly instead of reading env (#24759)
The CODER_AGENT_EXP_* env vars are agent-internal options. When set in the workspace environment they leak to MCP subprocesses and user shells. ReadEnvConfig() captures the values and ClearEnvVars() strips them before the reinit loop, so config survives agent restarts. NewAPI and ReadEnvConfig both use applyDefaults() to fill zero fields. The chatd test passes config via agenttest.WithContextConfigFromEnv().
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/coder/coder/v2/agent"
|
||||
"github.com/coder/coder/v2/agent/agentcontextconfig"
|
||||
"github.com/coder/coder/v2/codersdk/agentsdk"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
)
|
||||
@@ -47,3 +48,11 @@ func New(t testing.TB, coderURL *url.URL, agentToken string, opts ...func(*agent
|
||||
|
||||
return agt
|
||||
}
|
||||
|
||||
// WithContextConfigFromEnv returns an agent option that
|
||||
// populates ContextConfig from the current environment.
|
||||
func WithContextConfigFromEnv() func(*agent.Options) {
|
||||
return func(o *agent.Options) {
|
||||
o.ContextConfig = agentcontextconfig.ReadEnvConfig()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user