Skip to content

[test] Add tests for config.StdinServerConfig.UnmarshalJSON#5825

Merged
lpcox merged 1 commit into
mainfrom
add-tests-stdin-unmarshal-coverage-215dce1f6ac00c76
May 16, 2026
Merged

[test] Add tests for config.StdinServerConfig.UnmarshalJSON#5825
lpcox merged 1 commit into
mainfrom
add-tests-stdin-unmarshal-coverage-215dce1f6ac00c76

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Test Coverage Improvement: StdinServerConfig.UnmarshalJSON

Function Analyzed

  • Package: internal/config
  • Function: StdinServerConfig.UnmarshalJSON
  • Previous Coverage: 79.2%
  • New Coverage: 91.7%
  • Complexity: Medium (multiple branches for JSON parsing, legacy field aliases, and unknown field collection)

Why This Function?

StdinServerConfig.UnmarshalJSON is a custom JSON unmarshaler that handles several complex scenarios: legacy snake_case field aliases (connect_timeout, tool_timeout), collecting unknown fields into AdditionalProperties, and setting the toolTimeoutFieldName tracker. Five branches covering error paths and edge cases were completely untested.

Tests Added

  • ✅ Invalid JSON input returns error (first unmarshal error path)
  • connect_timeout with non-integer string value returns error
  • tool_timeout with non-integer string value returns error
  • connect_timeout as float returns error (only integers accepted)
  • tool_timeout as float returns error (only integers accepted)
  • null for connect_timeout decodes to pointer-to-zero (documents actual behavior)
  • ✅ Both camelCase and snake_case timeout fields present: camelCase wins
  • ✅ Only snake_case tool_timeout sets toolTimeoutFieldName to "tool_timeout"
  • ✅ camelCase toolTimeout keeps default toolTimeoutFieldName as "toolTimeout"
  • ✅ Unknown fields are collected in AdditionalProperties; known fields are excluded

Coverage Report

Before: 79.2% (UnmarshalJSON)
After:  91.7% (UnmarshalJSON)
Improvement: +12.5%

Test Execution

All 10 new sub-tests pass:

--- PASS: TestStdinServerConfig_UnmarshalJSON_ErrorPaths (0.00s)
    --- PASS: .../invalid_JSON_returns_error
    --- PASS: .../connect_timeout_with_non-integer_value_returns_error
    --- PASS: .../tool_timeout_with_non-integer_value_returns_error
    --- PASS: .../connect_timeout_as_float_returns_error
    --- PASS: .../tool_timeout_as_float_returns_error
    --- PASS: .../connect_timeout_as_null_is_treated_as_zero
    --- PASS: .../both_legacy_timeout_fields_present_simultaneously
    --- PASS: .../only_tool_timeout_snake_case_sets_toolTimeoutFieldName
    --- PASS: .../toolTimeout_camelCase_keeps_default_toolTimeoutFieldName
    --- PASS: .../unknown_fields_are_collected_in_AdditionalProperties

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

Warning

Firewall blocked 8 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
  • invalidhostthatdoesnotexist12345.com
  • proxy.golang.org
  • sum.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"
    - "invalidhostthatdoesnotexist12345.com"
    - "proxy.golang.org"
    - "sum.golang.org"

See Network Configuration for more information.

Generated by Test Coverage Improver · ● 8.8M ·

Cover previously untested branches in UnmarshalJSON:
- invalid JSON input returns error
- connect_timeout with non-integer value returns error
- tool_timeout with non-integer value returns error
- connect_timeout/tool_timeout as floats return error
- null for connect_timeout decodes to pointer to 0
- both camelCase and snake_case timeout fields present simultaneously
- only snake_case tool_timeout sets toolTimeoutFieldName correctly
- unknown fields are collected in AdditionalProperties

Coverage improvement: UnmarshalJSON 79.2% → 91.7%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review May 16, 2026 16:57
Copilot AI review requested due to automatic review settings May 16, 2026 16:57
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

Adds focused unit coverage for StdinServerConfig.UnmarshalJSON, documenting legacy timeout alias handling, error paths, field precedence, and additional-property collection.

Changes:

  • Adds subtests for invalid JSON and invalid legacy timeout values.
  • Covers snake_case vs camelCase timeout precedence and toolTimeoutField tracking.
  • Verifies unknown fields are retained in AdditionalProperties.
Show a summary per file
File Description
internal/config/config_stdin_unmarshal_coverage_test.go New unit tests for StdinServerConfig.UnmarshalJSON branches and edge cases.

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: 0

@lpcox lpcox merged commit bdc7597 into main May 16, 2026
21 checks passed
@lpcox lpcox deleted the add-tests-stdin-unmarshal-coverage-215dce1f6ac00c76 branch May 16, 2026 16:59
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