@@ -3,13 +3,15 @@ package errors
33import (
44 "context"
55 "fmt"
6+ "net/http"
7+ "strings"
8+ "testing"
9+ "time"
10+
611 "github.com/google/go-github/v92/github"
712 "github.com/modelcontextprotocol/go-sdk/mcp"
813 "github.com/stretchr/testify/assert"
914 "github.com/stretchr/testify/require"
10- "net/http"
11- "testing"
12- "time"
1315)
1416
1517func TestGitHubErrorContext (t * testing.T ) {
@@ -689,6 +691,34 @@ func TestNewGitHubAPIErrorResponse_RateLimits(t *testing.T) {
689691}
690692
691693func TestNewGitHubAPIErrorResponse_ValidationMessages (t * testing.T ) {
694+ t .Run ("large validation error lists are formatted without preallocating from their length" , func (t * testing.T ) {
695+ const errorCount = 1000
696+ validationErrors := make ([]github.Error , errorCount )
697+ for i := range validationErrors {
698+ validationErrors [i ] = github.Error {
699+ Resource : "Repository" ,
700+ Field : fmt .Sprintf ("field-%d" , i ),
701+ Code : "invalid" ,
702+ }
703+ }
704+
705+ originalErr := & github.ErrorResponse {
706+ Response : & http.Response {StatusCode : http .StatusUnprocessableEntity },
707+ Message : "Validation Failed" ,
708+ Errors : validationErrors ,
709+ }
710+ result := NewGitHubAPIErrorResponse (
711+ ContextWithGitHubErrors (context .Background ()),
712+ "API call failed" ,
713+ nil ,
714+ originalErr ,
715+ )
716+
717+ text := requireErrorText (t , result )
718+ assert .Equal (t , errorCount + 1 , len (strings .Split (text , "\n " )))
719+ assert .Contains (t , text , "Repository.field-999 (invalid)" )
720+ })
721+
692722 t .Run ("ruleset ErrorResponse includes sanitized structured validation messages" , func (t * testing.T ) {
693723 ctx := ContextWithGitHubErrors (context .Background ())
694724
0 commit comments