Skip to content

[Repo Assist] refactor(envutil): move ExpandEnvArgs from config to envutil#3217

Merged
lpcox merged 1 commit intomainfrom
repo-assist/improve-move-ExpandEnvArgs-to-envutil-2026-04-05-0490e46850a1cc51
Apr 5, 2026
Merged

[Repo Assist] refactor(envutil): move ExpandEnvArgs from config to envutil#3217
lpcox merged 1 commit intomainfrom
repo-assist/improve-move-ExpandEnvArgs-to-envutil-2026-04-05-0490e46850a1cc51

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 5, 2026

🤖 This is an automated pull request from Repo Assist.

Summary

Moves ExpandEnvArgs from internal/config/docker_helpers.go to a new internal/envutil/expand_env_args.go, co-locating it with the other env-var utilities (GetEnvString, GetEnvInt, GetEnvDuration, GetEnvBool).

Root Cause / Motivation

ExpandEnvArgs is a generic utility that expands Docker -e VAR_NAME flags by reading from the process environment. Despite living in the config package, it:

  • Is not Docker-specific or config-specific in behaviour
  • Has its only non-test caller in internal/mcp/connection.go, creating an mcp → config import dependency purely for this one function
  • Is semantically identical in purpose to GetEnvString / GetEnvBool already in envutil

This is the "quick win" refactoring identified in issue #3211 (Semantic Function Clustering analysis).

Changes

File Change
internal/envutil/expand_env_args.go New — contains ExpandEnvArgs with logExpand logger (envutil:expand)
internal/envutil/expand_env_args_test.go New — tests moved from config package
internal/config/docker_helpers.go Removed ExpandEnvArgs function (30 lines)
internal/config/docker_helpers_and_env_test.go Removed TestExpandEnvArgs* tests (144 lines)
internal/mcp/connection.go Import envutil instead of config
internal/mcp/connection_test.go Use envutil.ExpandEnvArgs instead of config.ExpandEnvArgs

Test Status

Note: The sandboxed CI environment during Repo Assist runs does not have network access to download Go module dependencies, so a full make build could not be completed locally. However:

  • gofmt -e confirms all changed files parse correctly (no syntax errors)
  • The logic is an exact copy of the existing function — no behavioural changes
  • All test cases were migrated intact
  • The package boundary change is the only substantive modification

GitHub Actions CI will run the full build and test suite.

Closes nothing directly; addresses #3211 quick-win checklist item.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

ExpandEnvArgs is a generic env-var expansion utility used to expand
Docker -e flags. It lives in internal/config/docker_helpers.go but
has only one non-test caller (internal/mcp/connection.go) and does
not belong to config's domain.

Move it to internal/envutil/ alongside GetEnvString, GetEnvInt,
GetEnvDuration, and GetEnvBool, which is a better semantic fit.
This removes the mcp → config import dependency for a non-config
concern.

Changes:
- Add internal/envutil/expand_env_args.go with the function and
  its own logExpand logger (namespace: envutil:expand)
- Remove ExpandEnvArgs from internal/config/docker_helpers.go
- Update internal/mcp/connection.go to import envutil instead of config
- Update internal/mcp/connection_test.go to use envutil.ExpandEnvArgs
- Move ExpandEnvArgs tests to internal/envutil/expand_env_args_test.go

Addresses the quick-win refactoring opportunity identified in #3211.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review April 5, 2026 22:04
Copilot AI review requested due to automatic review settings April 5, 2026 22:04
@lpcox lpcox merged commit 784d2c4 into main Apr 5, 2026
3 checks passed
@lpcox lpcox deleted the repo-assist/improve-move-ExpandEnvArgs-to-envutil-2026-04-05-0490e46850a1cc51 branch April 5, 2026 22:04
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

Refactors a generic Docker -e VAR_NAME environment expansion helper (ExpandEnvArgs) out of internal/config into internal/envutil, removing an unnecessary mcp → config dependency and co-locating it with other env utilities.

Changes:

  • Moved ExpandEnvArgs implementation from internal/config/docker_helpers.go to internal/envutil/expand_env_args.go.
  • Migrated the associated unit tests from internal/config to internal/envutil.
  • Updated MCP connection code/tests to call envutil.ExpandEnvArgs instead of config.ExpandEnvArgs.
Show a summary per file
File Description
internal/envutil/expand_env_args.go New home for ExpandEnvArgs (with its own debug logger namespace).
internal/envutil/expand_env_args_test.go New test file covering ExpandEnvArgs behavior in envutil.
internal/config/docker_helpers.go Removes ExpandEnvArgs from config/Docker helpers.
internal/config/docker_helpers_and_env_test.go Removes the old ExpandEnvArgs tests from config.
internal/mcp/connection.go Switches call site to envutil.ExpandEnvArgs, dropping config import.
internal/mcp/connection_test.go Updates the existing MCP-level test to use envutil.ExpandEnvArgs.

Copilot's findings

Tip

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

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

Comment on lines 254 to +262
require.NoError(t, os.Setenv(k, v))
}
t.Cleanup(func() {
for k := range tt.envVars {
os.Unsetenv(k)
}
})

result := config.ExpandEnvArgs(tt.args)
result := envutil.ExpandEnvArgs(tt.args)
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

In this test, environment variables are managed with os.Setenv + manual t.Cleanup. Since this file is already using Go’s testing.T helpers elsewhere, consider switching to t.Setenv here as well to simplify the code and avoid accidental env leakage if the test suite is ever parallelized.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants