Skip to content

[test] Add tests for config.expandMapInPlace#9084

Merged
lpcox merged 2 commits into
mainfrom
test/expand-map-in-place-coverage-5193f9f2d525ce0d
Jul 11, 2026
Merged

[test] Add tests for config.expandMapInPlace#9084
lpcox merged 2 commits into
mainfrom
test/expand-map-in-place-coverage-5193f9f2d525ce0d

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Function Analyzed

  • Package: internal/config
  • Function: expandMapInPlace
  • File: internal/config/expand.go
  • Previous Coverage: 0% (no direct tests)
  • New Coverage: All branches covered
  • Complexity: Medium

Why This Function?

expandMapInPlace is an internal helper used in two call sites (convertStdinServerConfig) to expand ${VAR} expressions in both the env and headers maps of each MCP server configuration. Despite being called by the critical config loading path, it had zero direct unit tests.

The function has three distinct code paths:

  1. Empty/nil map fast path — returns nil without calling expandEnvVariables
  2. Happy path — calls expandEnvVariables, replaces *m with the expanded copy
  3. Error path — wraps the underlying error with server name and field description in the format: server %q: failed to expand %s: %w

Tests Added

  • Empty/nil map (triggers fast path)
  • All variables defined (in-place mutation verified)
  • Literal values pass through unchanged
  • Undefined variable produces wrapped error mentioning server name
  • Error message includes fieldDesc from call site
  • Pointer semantics: caller sees expanded map after return
  • Mixed defined/undefined variables
  • Variable expanded to empty string is valid
  • Error wraps underlying undefined-variable error (var name visible)
  • Server name with special chars is quoted in error message

Coverage

Before: 0% direct coverage (no tests for expandMapInPlace)

After: All 3 branches covered (empty fast path, happy path, error path)


Generated by Test Coverage Improver

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • awmgmcpg
  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by Test Coverage Improver · 489.7 AIC · ⊞ 6.9K ·

expandMapInPlace has zero direct test coverage despite having three
distinct code paths:

1. Empty/nil map fast path - returns nil without calling expandEnvVariables
2. Happy path - expands variables in map values and updates *m in place
3. Error path - wraps underlying error with server name and field description
   using the format: server %q: failed to expand %s: %w

Tests cover:
- nil map (pointer to nil - empty fast path)
- empty map (empty fast path)
- all variables defined (in-place mutation verified by caller)
- literal values pass through unchanged
- undefined variable produces wrapped error mentioning server name
- error includes fieldDesc from call site (env vars vs HTTP headers)
- pointer semantics: caller sees expanded map after return
- mixed defined/undefined variables
- variable expanded to empty string is valid
- error wraps the underlying undefined-variable error (var name visible)
- server name with special chars is quoted in error message (%q format)

Previous coverage: 0% (no direct tests)
After this change: all branches of expandMapInPlace are covered

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review July 11, 2026 12:41
Copilot AI review requested due to automatic review settings July 11, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds direct unit tests for internal/config.expandMapInPlace, an internal helper on the stdin config conversion path, to ensure ${VAR} expansion behavior (fast-path, success, and wrapped-error path) is covered and stable.

Changes:

  • Introduces a new unit test suite covering nil/empty fast path, successful expansion, and wrapped error formatting.
  • Verifies caller-visible pointer semantics (map replacement) and key edge cases (empty-string expansion, mixed defined/undefined vars).
Show a summary per file
File Description
internal/config/expand_map_in_place_test.go Adds branch-covering unit tests for expandMapInPlace behavior and error wrapping.

Review details

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment on lines +66 to +71
assert.True(t, strings.Contains(errStr, "my-server"),
"error should mention the server name, got: %q", errStr)
assert.True(t, strings.Contains(errStr, "environment variable(s)"),
"error should mention the field description, got: %q", errStr)
assert.True(t, strings.Contains(errStr, "failed to expand"),
"error should contain 'failed to expand', got: %q", errStr)
Comment on lines +89 to +90
// Save a reference to the original map to verify identity changes.
// expandMapInPlace replaces *m with a new map, so the pointer target changes.
@lpcox

lpcox commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Done in the latest commit. Replaced all assert.True(strings.Contains(...)) calls with assert.Contains, removed the unused strings import, and updated the misleading map-identity comment to accurately describe what the test verifies.

Copilot finished work on behalf of lpcox July 11, 2026 12:47
Copilot AI requested a review from lpcox July 11, 2026 12:47
@lpcox lpcox merged commit e4fbdcf into main Jul 11, 2026
23 checks passed
@lpcox lpcox deleted the test/expand-map-in-place-coverage-5193f9f2d525ce0d branch July 11, 2026 18:33
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.

3 participants