Skip to content

[test] Add tests for config.normalizeAgentID, effectiveAgentID, and validateToolResponseFilters#7530

Merged
lpcox merged 4 commits into
mainfrom
test/coverage-normalize-agent-id-tool-response-filters-a0f6dcb95eb1f743
Jun 14, 2026
Merged

[test] Add tests for config.normalizeAgentID, effectiveAgentID, and validateToolResponseFilters#7530
lpcox merged 4 commits into
mainfrom
test/coverage-normalize-agent-id-tool-response-filters-a0f6dcb95eb1f743

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Coverage Improvement

Brings three under-tested internal/config functions to 100% coverage.

Functions Analyzed

Function Package Previous Coverage New Coverage
GatewayConfig.normalizeAgentID internal/config 80.0% 100%
GatewayConfig.effectiveAgentID internal/config 85.7% 100%
validateToolResponseFilters internal/config 86.7% 100%

Why These Functions?

All three had the highest complexity-to-coverage gap in the internal/config package — each had concrete uncovered branches containing non-trivial logic:

  • normalizeAgentID: The conflict-detection branch (both gateway.agent_id and gateway.api_key set to different values) and the nil-receiver guard were both uncovered.
  • effectiveAgentID: The nil-receiver guard was uncovered.
  • validateToolResponseFilters: Both the gojq.WithEnvironLoader closure body and the gojq.Compile error path were uncovered.

Tests Added

internal/config/config_core_agent_id_coverage_test.go (new file)

  • TestEffectiveAgentID — 6 table-driven sub-cases:

    • nil receiver (returns "")
    • explicit field set
    • non-explicit AgentID non-empty
    • APIKey fallback (AgentID empty)
    • zero value (both empty)
    • prefer AgentID over APIKey when non-explicit
  • TestNormalizeAgentID — 6 table-driven sub-cases:

    • nil receiver no-op
    • only api_key set (legacy deprecation path)
    • both set to the same value (no conflict)
    • both set to different values (conflict warning path — the key uncovered branch)
    • only agent_id set (explicit path)
    • neither set (zero-value no-op)
  • ✅ 5 LoadFromFile integration tests exercising all four TOML field combinations, including the agent_id/api_key conflict path end-to-end.

internal/config/validate_helpers_coverage_test.go (modified)

  • $ENV.SOME_VARIABLE filter — forces gojq to invoke the WithEnvironLoader closure during compilation, covering the env-loader branch.
  • $undefinedVar | .field filter — parses OK but fails at gojq.Compile with "variable not defined", covering the compile-error return path.

Coverage Report

Before:
  GatewayConfig.normalizeAgentID       80.0%
  GatewayConfig.effectiveAgentID       85.7%
  validateToolResponseFilters          86.7%
  internal/config total                97.3%

After:
  GatewayConfig.normalizeAgentID      100.0%
  GatewayConfig.effectiveAgentID      100.0%
  validateToolResponseFilters         100.0%
  internal/config total                97.6%
  all testable packages total          98.4%

Test Execution

All tests pass (run with -tags "tty_stub testify_yaml_fail" to avoid unavailable module dependencies in the CI sandbox):

ok  	github.com/github/gh-aw-mcpg/internal/config	(all tests pass)

gofmt and go vet clean on all changed files.


Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

Warning

Firewall blocked 6 domains

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

  • go.opentelemetry.io
  • go.yaml.in
  • golang.org
  • google.golang.org
  • gopkg.in
  • proxy.golang.org

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

network:
  allowed:
    - defaults
    - "go.opentelemetry.io"
    - "go.yaml.in"
    - "golang.org"
    - "google.golang.org"
    - "gopkg.in"
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by Test Coverage Improver · 2.8K AIC · ⊞ 28.7K ·

…ToolResponseFilters

Three under-tested functions brought to 100% coverage:

- GatewayConfig.normalizeAgentID (80% → 100%)
  - New: nil receiver no-op path
  - New: conflict-detection path when both agent_id and api_key
    are set to different values (logs deprecation + conflict warning)
  - New: integration via LoadFromFile with TOML configs covering
    all four combinations of the two fields

- GatewayConfig.effectiveAgentID (85.7% → 100%)
  - New: nil receiver path (returns empty string)
  - New: all four resolution branches (explicit, non-explicit
    non-empty AgentID, APIKey fallback, zero-value)

- validateToolResponseFilters (86.7% → 100%)
  - New: $ENV.KEY filter forces the gojq WithEnvironLoader
    closure to execute during compilation
  - New: $undefinedVar filter parses successfully but fails at
    the gojq.Compile step (variable not defined error)

Overall internal/config package coverage: 97.3% → 97.6%
Overall across all testable packages: 98.3% → 98.4%

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

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

This PR improves test coverage in internal/config by adding targeted unit/integration tests for gateway agent ID normalization/resolution and for jq tool-response-filter validation edge cases (including gojq compile-time branches).

Changes:

  • Added a new test file covering GatewayConfig.effectiveAgentID, GatewayConfig.normalizeAgentID, and several LoadFromFile agent_id/api_key combinations.
  • Extended validateToolResponseFilters direct-call tests to exercise the gojq environ-loader option path and the gojq compile-error (non-parse) path.
Show a summary per file
File Description
internal/config/validate_helpers_coverage_test.go Adds two direct-call cases to cover gojq env-loader invocation and gojq compile-error handling in tool_response_filters validation.
internal/config/config_core_agent_id_coverage_test.go New tests for agent ID precedence/normalization and TOML LoadFromFile integration coverage for agent_id/api_key combinations.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment thread internal/config/validate_helpers_coverage_test.go Outdated
Comment thread internal/config/validate_helpers_coverage_test.go Outdated
Comment thread internal/config/config_core_agent_id_coverage_test.go
lpcox and others added 3 commits June 14, 2026 10:19
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox June 14, 2026 17:19 View session
GitHub Advanced Security finished work on behalf of lpcox June 14, 2026 17:21
@lpcox lpcox merged commit d4943ca into main Jun 14, 2026
26 checks passed
@lpcox lpcox deleted the test/coverage-normalize-agent-id-tool-response-filters-a0f6dcb95eb1f743 branch June 14, 2026 17:22
Copilot stopped work on behalf of lpcox due to an error June 14, 2026 17:34
Copilot stopped work on behalf of lpcox due to an error June 14, 2026 17:37
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