You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor Docker -e passthrough handling into shared envutil walker (#6034)
Semantic clustering flagged duplicated Docker `-e VAR` passthrough
scanning in `launcher` and `envutil`. This change consolidates that
traversal into one helper so expansion and logging stay aligned as
Docker env-arg handling evolves.
- **Shared env-arg traversal**
- Added `envutil.WalkDockerEnvArgs(args, fn)` to centralize detection of
Docker passthrough args in the form `-e VAR`.
- The helper only visits passthrough entries; explicit assignments like
`-e VAR=value` and incomplete trailing `-e` flags are ignored by
construction.
- **`ExpandEnvArgs` now delegates**
- Reworked `internal/envutil/expand_env_args.go` to use the shared
walker when building expanded `-e VAR=value` pairs.
- Keeps existing behavior for unset vars and explicit `VAR=value` args
while removing the duplicated loop skeleton.
- **Launcher logging now delegates**
- Reworked `internal/launcher/log_helpers.go` to use the same walker for
passthrough logging.
- Preserves sanitized logging for present values and distinguishes
empty-but-present variables from missing ones.
- **Focused coverage**
- Added walker-specific tests covering set, empty, missing,
explicit-assignment, and trailing-flag cases.
- Updated launcher log helper coverage for empty passthrough values.
- **Docs**
- Updated `AGENTS.md` to reflect that `internal/envutil/` now owns
Docker env-arg helper behavior in addition to general env utilities.
```go
// envutil
func WalkDockerEnvArgs(args []string, fn func(index int, varName, value string, found bool))
// launcher
envutil.WalkDockerEnvArgs(args, func(_ int, varName, value string, found bool) {
if !found {
log.Printf("[LAUNCHER] ✗ WARNING: Env passthrough for %s requested but NOT FOUND in MCPG process", varName)
return
}
if value != "" {
log.Printf("[LAUNCHER] ✓ Env passthrough: %s=%s (from MCPG process)", varName, sanitize.TruncateSecret(value))
return
}
log.Printf("[LAUNCHER] ⚠️ Env passthrough for %s is empty in MCPG process", varName)
})
```
0 commit comments