Skip to content

[test] Add tests for config.StdinGatewayConfig.UnmarshalJSON and validateAgainstCustomSchema#7597

Merged
lpcox merged 2 commits into
mainfrom
test-coverage-config-stdin-gateway-unmarshal-353818501c2ec5b4
Jun 16, 2026
Merged

[test] Add tests for config.StdinGatewayConfig.UnmarshalJSON and validateAgainstCustomSchema#7597
lpcox merged 2 commits into
mainfrom
test-coverage-config-stdin-gateway-unmarshal-353818501c2ec5b4

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Coverage Improvement

Functions Analyzed

Function Package Previous Coverage New Coverage Δ
StdinGatewayConfig.UnmarshalJSON internal/config 80.0% 90.0% +10%
validateAgainstCustomSchema internal/config 86.2% 93.1% +6.9%

Why These Functions?

Both functions were identified by combining coverage data with code complexity analysis:

  • StdinGatewayConfig.UnmarshalJSON uses an alias-pattern to prevent infinite recursion during JSON decoding. The first return err path (invalid JSON input) was never exercised. Additionally, the agentIDSet / legacyAPIKeySet field-tracking booleans had only partial coverage.

  • validateAgainstCustomSchema fetches and compiles a JSON Schema from a URL. The compiler.AddResource(schemaID, ...) call on lines 276–281 — reached only when the schema's $id differs from the fetch URL and $id contains an invalid percent-encoded sequence — was never tested. Similarly, the compiler.Compile failure path (schema with an unresolvable $ref) needed coverage.

Tests Added

StdinGatewayConfig.UnmarshalJSON

  • ✅ Invalid JSON input → first return err path (4 sub-cases: plain text, truncated object, array, null byte)
  • agentIDSet / legacyAPIKeySet tracking for all combinations of present/absent fields (7 sub-cases)
  • ✅ Scalar field values are decoded correctly alongside the tracking booleans
  • ✅ Custom UnmarshalJSON is invoked through the standard json.Unmarshal path via StdinConfig

validateAgainstCustomSchema

  • ✅ Schema with invalid percent-encoded $id URL causes compiler.AddResource(schemaID, ...) to fail
  • ✅ Schema with an unresolvable $ref causes compiler.Compile to fail
  • Both use httptest.NewServer + t.Cleanup cache deletion (consistent with the existing test suite)

Coverage Report

Before:
  config/config_stdin.go:54 (StdinGatewayConfig.UnmarshalJSON): 80.0%
  config/validation.go:228  (validateAgainstCustomSchema):       86.2%
  config package total:                                          97.6%

After:
  config/config_stdin.go:54 (StdinGatewayConfig.UnmarshalJSON): 90.0%
  config/validation.go:228  (validateAgainstCustomSchema):       93.1%
  config package total:                                          97.8%

Test Execution

All 14 buildable packages pass (packages requiring unavailable modules — wazero, otel, mcp-sdk — have pre-existing build failures unrelated to these changes):

ok  github.com/github/gh-aw-mcpg/internal/auth
ok  github.com/github/gh-aw-mcpg/internal/config   1.644s
ok  github.com/github/gh-aw-mcpg/internal/difc
ok  github.com/github/gh-aw-mcpg/internal/envutil
ok  github.com/github/gh-aw-mcpg/internal/httputil
ok  github.com/github/gh-aw-mcpg/internal/logger
ok  github.com/github/gh-aw-mcpg/internal/mcpresult
ok  github.com/github/gh-aw-mcpg/internal/oidc
ok  github.com/github/gh-aw-mcpg/internal/sanitize
ok  github.com/github/gh-aw-mcpg/internal/strutil
ok  github.com/github/gh-aw-mcpg/internal/syncutil
ok  github.com/github/gh-aw-mcpg/internal/sys
ok  github.com/github/gh-aw-mcpg/internal/tty
ok  github.com/github/gh-aw-mcpg/internal/version

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

Warning

Firewall blocked 7 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
  • releaseassets.githubusercontent.com

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"
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

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

…instCustomSchema

Cover previously-untested paths in the config package:

1. StdinGatewayConfig.UnmarshalJSON (80% → 90%):
   - Invalid JSON input triggers the first return-error path
   - Field-tracking for agentIDSet / legacyAPIKeySet across all cases
   - Scalar field values are decoded correctly
   - UnmarshalJSON is invoked via the standard json.Unmarshal path

2. validateAgainstCustomSchema (86.2% → 93.1%):
   - Schema with an invalid percent-encoded $id URL causes
     compiler.AddResource(schemaID, ...) to fail → returns
     'failed to compile custom schema' error
   - Schema with a dangling $ref causes compiler.Compile to fail →
     same error class

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

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 targeted unit tests in internal/config to increase branch coverage for stdin gateway JSON unmarshaling and custom-schema validation, focusing on previously unexercised error/edge paths.

Changes:

  • Add tests for StdinGatewayConfig.UnmarshalJSON invalid-input error return and agentIDSet / legacyAPIKeySet tracking behavior.
  • Add tests for validateAgainstCustomSchema error branches: invalid $id (AddResource failure) and schema compile failure.
Show a summary per file
File Description
internal/config/stdin_gateway_unmarshal_test.go Adds new unit tests covering additional error/branch paths for stdin gateway unmarshaling and custom schema validation.

Copilot's findings

Tip

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

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

Comment thread internal/config/stdin_gateway_unmarshal_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox June 16, 2026 17:12 View session
@lpcox lpcox merged commit 66c547b into main Jun 16, 2026
27 checks passed
@lpcox lpcox deleted the test-coverage-config-stdin-gateway-unmarshal-353818501c2ec5b4 branch June 16, 2026 17:13
GitHub Advanced Security finished work on behalf of lpcox June 16, 2026 17:14
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