From 9f5de8347f0a381323a673c5e9103458306ad801 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 22 Jun 2026 00:20:44 +0000 Subject: [PATCH 1/2] Add TestConnectionPoolGet_ClosedState to cover closed connection branch Adds a test that exercises the ConnectionStateClosed early-exit path in SessionConnectionPool.Get() (connection_pool.go lines 232-235). Previously, Get() had 86.7% coverage. With this test, it reaches 100%. The test directly inserts a closed-state ConnectionMetadata into the pool map (same approach used by TestCleanupIdleConnections_AlreadyClosedState) and asserts that Get returns (nil, false) without removing the entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/launcher/connection_pool_test.go | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/launcher/connection_pool_test.go b/internal/launcher/connection_pool_test.go index a23ce99b0..84ee75d08 100644 --- a/internal/launcher/connection_pool_test.go +++ b/internal/launcher/connection_pool_test.go @@ -55,6 +55,36 @@ func TestConnectionPoolGetNonExistent(t *testing.T) { assert.Nil(t, conn) } +// TestConnectionPoolGet_ClosedState verifies that Get returns (nil, false) for a +// connection that is present in the pool map but has been marked ConnectionStateClosed. +// This covers the early-exit branch in connection_pool.go Get(). +func TestConnectionPoolGet_ClosedState(t *testing.T) { + ctx := context.Background() + pool := NewSessionConnectionPool(ctx) + defer pool.Stop() + + // Directly insert a closed connection to exercise the branch that + // is normally only reached via internal state transitions. + key := ConnectionKey{BackendID: "backend1", SessionID: "session1"} + pool.mu.Lock() + pool.connections[key] = &ConnectionMetadata{ + Connection: &mcp.Connection{}, + CreatedAt: time.Now(), + LastUsedAt: time.Now(), + State: ConnectionStateClosed, + } + pool.mu.Unlock() + + require.Equal(t, 1, pool.Size(), "connection should be in pool before Get") + + conn, exists := pool.Get("backend1", "session1") + + assert.Nil(t, conn, "Get should return nil connection for a closed entry") + assert.False(t, exists, "Get should return false for a closed entry") + // Get does not remove the entry — cleanup is handled by cleanupIdleConnections. + assert.Equal(t, 1, pool.Size(), "Get should not remove the closed entry from the pool") +} + func TestConnectionPoolDelete(t *testing.T) { ctx := context.Background() pool := NewSessionConnectionPool(ctx) From c76521fc147d55ca77ce097a6a234fce5f49cef7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Jun 2026 14:51:58 +0000 Subject: [PATCH 2/2] Address review feedback in connection pool closed-state test --- internal/launcher/connection_pool_test.go | 25 +++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/internal/launcher/connection_pool_test.go b/internal/launcher/connection_pool_test.go index 84ee75d08..7345bca83 100644 --- a/internal/launcher/connection_pool_test.go +++ b/internal/launcher/connection_pool_test.go @@ -60,20 +60,27 @@ func TestConnectionPoolGetNonExistent(t *testing.T) { // This covers the early-exit branch in connection_pool.go Get(). func TestConnectionPoolGet_ClosedState(t *testing.T) { ctx := context.Background() - pool := NewSessionConnectionPool(ctx) + pool := NewSessionConnectionPoolWithConfig(ctx, PoolConfig{ + IdleTimeout: 1 * time.Hour, + CleanupInterval: 24 * time.Hour, + MaxErrorCount: DefaultMaxErrorCount, + }) defer pool.Stop() // Directly insert a closed connection to exercise the branch that // is normally only reached via internal state transitions. key := ConnectionKey{BackendID: "backend1", SessionID: "session1"} - pool.mu.Lock() - pool.connections[key] = &ConnectionMetadata{ - Connection: &mcp.Connection{}, - CreatedAt: time.Now(), - LastUsedAt: time.Now(), - State: ConnectionStateClosed, - } - pool.mu.Unlock() + now := time.Now() + func() { + pool.mu.Lock() + defer pool.mu.Unlock() + pool.connections[key] = &ConnectionMetadata{ + Connection: &mcp.Connection{}, + CreatedAt: now, + LastUsedAt: now, + State: ConnectionStateClosed, + } + }() require.Equal(t, 1, pool.Size(), "connection should be in pool before Get")