[test] Add tests for config.StdinGatewayConfig.UnmarshalJSON and validateAgainstCustomSchema#7597
Merged
lpcox merged 2 commits intoJun 16, 2026
Conversation
…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>
4 tasks
Contributor
There was a problem hiding this comment.
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.UnmarshalJSONinvalid-input error return andagentIDSet/legacyAPIKeySettracking behavior. - Add tests for
validateAgainstCustomSchemaerror 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
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Coverage Improvement
Functions Analyzed
StdinGatewayConfig.UnmarshalJSONinternal/configvalidateAgainstCustomSchemainternal/configWhy These Functions?
Both functions were identified by combining coverage data with code complexity analysis:
StdinGatewayConfig.UnmarshalJSONuses an alias-pattern to prevent infinite recursion during JSON decoding. The firstreturn errpath (invalid JSON input) was never exercised. Additionally, theagentIDSet/legacyAPIKeySetfield-tracking booleans had only partial coverage.validateAgainstCustomSchemafetches and compiles a JSON Schema from a URL. Thecompiler.AddResource(schemaID, ...)call on lines 276–281 — reached only when the schema's$iddiffers from the fetch URL and$idcontains an invalid percent-encoded sequence — was never tested. Similarly, thecompiler.Compilefailure path (schema with an unresolvable$ref) needed coverage.Tests Added
StdinGatewayConfig.UnmarshalJSONreturn errpath (4 sub-cases: plain text, truncated object, array, null byte)agentIDSet/legacyAPIKeySettracking for all combinations of present/absent fields (7 sub-cases)UnmarshalJSONis invoked through the standardjson.Unmarshalpath viaStdinConfigvalidateAgainstCustomSchema$idURL causescompiler.AddResource(schemaID, ...)to fail$refcausescompiler.Compileto failhttptest.NewServer+t.Cleanupcache deletion (consistent with the existing test suite)Coverage Report
Test Execution
All 14 buildable packages pass (packages requiring unavailable modules — wazero, otel, mcp-sdk — have pre-existing build failures unrelated to these changes):
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.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgreleaseassets.githubusercontent.comSee Network Configuration for more information.