Skip to content

Refactor Docker -e passthrough handling into shared envutil walker#6034

Merged
lpcox merged 7 commits into
mainfrom
copilot/refactor-semantic-function-clustering-analysis
May 19, 2026
Merged

Refactor Docker -e passthrough handling into shared envutil walker#6034
lpcox merged 7 commits into
mainfrom
copilot/refactor-semantic-function-clustering-analysis

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

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.
// 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)
})

Copilot AI linked an issue May 19, 2026 that may be closed by this pull request
4 tasks
Copilot AI changed the title [WIP] Refactor based on semantic function clustering analysis findings Refactor Docker -e passthrough handling into shared envutil walker May 19, 2026
Copilot finished work on behalf of lpcox May 19, 2026 23:08
Copilot AI requested a review from lpcox May 19, 2026 23:08
@lpcox lpcox marked this pull request as ready for review May 19, 2026 23:27
Copilot AI review requested due to automatic review settings May 19, 2026 23:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR consolidates Docker -e VAR passthrough argument detection into a single helper in internal/envutil, then reuses it to keep environment expansion behavior and launcher passthrough logging consistent as the Docker arg handling evolves.

Changes:

  • Added envutil.WalkDockerEnvArgs to centralize traversal of Docker passthrough env args (-e VAR, excluding -e VAR=value and trailing -e).
  • Refactored envutil.ExpandEnvArgs to delegate passthrough detection to the shared walker.
  • Refactored launcher passthrough logging to use the shared walker and added coverage for empty-but-present env vars.
Show a summary per file
File Description
internal/launcher/log_helpers.go Replaces bespoke -e scanning with envutil.WalkDockerEnvArgs and logs empty-but-present vars distinctly.
internal/launcher/log_helpers_test.go Adds a test to cover logging behavior when a passthrough variable is present but empty.
internal/envutil/expand_env_args.go Introduces WalkDockerEnvArgs and refactors ExpandEnvArgs to reuse it.
internal/envutil/expand_env_args_test.go Adds walker-focused tests for set/empty/missing vars and ignores explicit assignments/trailing -e.
AGENTS.md Updates project structure note to reflect Docker env-arg utilities living in internal/envutil/.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment thread internal/envutil/expand_env_args.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpcox lpcox merged commit 96b68d8 into main May 19, 2026
16 checks passed
@lpcox lpcox deleted the copilot/refactor-semantic-function-clustering-analysis branch May 19, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] Semantic Function Clustering Analysis

3 participants