@@ -3227,3 +3227,174 @@ func getLatestPendingReviewQuery(p getLatestPendingReviewQueryParams) githubv4mo
32273227 ),
32283228 )
32293229}
3230+
3231+ func TestResolveReviewThread (t * testing.T ) {
3232+ t .Parallel ()
3233+
3234+ tests := []struct {
3235+ name string
3236+ requestArgs map [string ]any
3237+ mockedClient * http.Client
3238+ expectToolError bool
3239+ expectedToolErrMsg string
3240+ expectedResult string
3241+ }{
3242+ {
3243+ name : "successful resolve thread" ,
3244+ requestArgs : map [string ]any {
3245+ "method" : "resolve_thread" ,
3246+ "owner" : "owner" ,
3247+ "repo" : "repo" ,
3248+ "pullNumber" : float64 (42 ),
3249+ "threadId" : "PRRT_kwDOTest123" ,
3250+ },
3251+ mockedClient : githubv4mock .NewMockedHTTPClient (
3252+ githubv4mock .NewMutationMatcher (
3253+ struct {
3254+ ResolveReviewThread struct {
3255+ Thread struct {
3256+ ID githubv4.ID
3257+ IsResolved githubv4.Boolean
3258+ }
3259+ } `graphql:"resolveReviewThread(input: $input)"`
3260+ }{},
3261+ githubv4.ResolveReviewThreadInput {
3262+ ThreadID : githubv4 .ID ("PRRT_kwDOTest123" ),
3263+ },
3264+ nil ,
3265+ githubv4mock .DataResponse (map [string ]any {
3266+ "resolveReviewThread" : map [string ]any {
3267+ "thread" : map [string ]any {
3268+ "id" : "PRRT_kwDOTest123" ,
3269+ "isResolved" : true ,
3270+ },
3271+ },
3272+ }),
3273+ ),
3274+ ),
3275+ expectedResult : "review thread resolved successfully" ,
3276+ },
3277+ {
3278+ name : "successful unresolve thread" ,
3279+ requestArgs : map [string ]any {
3280+ "method" : "unresolve_thread" ,
3281+ "owner" : "owner" ,
3282+ "repo" : "repo" ,
3283+ "pullNumber" : float64 (42 ),
3284+ "threadId" : "PRRT_kwDOTest123" ,
3285+ },
3286+ mockedClient : githubv4mock .NewMockedHTTPClient (
3287+ githubv4mock .NewMutationMatcher (
3288+ struct {
3289+ UnresolveReviewThread struct {
3290+ Thread struct {
3291+ ID githubv4.ID
3292+ IsResolved githubv4.Boolean
3293+ }
3294+ } `graphql:"unresolveReviewThread(input: $input)"`
3295+ }{},
3296+ githubv4.UnresolveReviewThreadInput {
3297+ ThreadID : githubv4 .ID ("PRRT_kwDOTest123" ),
3298+ },
3299+ nil ,
3300+ githubv4mock .DataResponse (map [string ]any {
3301+ "unresolveReviewThread" : map [string ]any {
3302+ "thread" : map [string ]any {
3303+ "id" : "PRRT_kwDOTest123" ,
3304+ "isResolved" : false ,
3305+ },
3306+ },
3307+ }),
3308+ ),
3309+ ),
3310+ expectedResult : "review thread unresolved successfully" ,
3311+ },
3312+ {
3313+ name : "empty threadId for resolve" ,
3314+ requestArgs : map [string ]any {
3315+ "method" : "resolve_thread" ,
3316+ "owner" : "owner" ,
3317+ "repo" : "repo" ,
3318+ "pullNumber" : float64 (42 ),
3319+ "threadId" : "" ,
3320+ },
3321+ mockedClient : githubv4mock .NewMockedHTTPClient (),
3322+ expectToolError : true ,
3323+ expectedToolErrMsg : "threadId is required" ,
3324+ },
3325+ {
3326+ name : "empty threadId for unresolve" ,
3327+ requestArgs : map [string ]any {
3328+ "method" : "unresolve_thread" ,
3329+ "owner" : "owner" ,
3330+ "repo" : "repo" ,
3331+ "pullNumber" : float64 (42 ),
3332+ "threadId" : "" ,
3333+ },
3334+ mockedClient : githubv4mock .NewMockedHTTPClient (),
3335+ expectToolError : true ,
3336+ expectedToolErrMsg : "threadId is required" ,
3337+ },
3338+ {
3339+ name : "thread not found" ,
3340+ requestArgs : map [string ]any {
3341+ "method" : "resolve_thread" ,
3342+ "owner" : "owner" ,
3343+ "repo" : "repo" ,
3344+ "pullNumber" : float64 (42 ),
3345+ "threadId" : "PRRT_invalid" ,
3346+ },
3347+ mockedClient : githubv4mock .NewMockedHTTPClient (
3348+ githubv4mock .NewMutationMatcher (
3349+ struct {
3350+ ResolveReviewThread struct {
3351+ Thread struct {
3352+ ID githubv4.ID
3353+ IsResolved githubv4.Boolean
3354+ }
3355+ } `graphql:"resolveReviewThread(input: $input)"`
3356+ }{},
3357+ githubv4.ResolveReviewThreadInput {
3358+ ThreadID : githubv4 .ID ("PRRT_invalid" ),
3359+ },
3360+ nil ,
3361+ githubv4mock .ErrorResponse ("Could not resolve to a PullRequestReviewThread with the id of 'PRRT_invalid'" ),
3362+ ),
3363+ ),
3364+ expectToolError : true ,
3365+ expectedToolErrMsg : "Could not resolve to a PullRequestReviewThread" ,
3366+ },
3367+ }
3368+
3369+ for _ , tc := range tests {
3370+ t .Run (tc .name , func (t * testing.T ) {
3371+ t .Parallel ()
3372+
3373+ // Setup client with mock
3374+ client := githubv4 .NewClient (tc .mockedClient )
3375+ serverTool := PullRequestReviewWrite (translations .NullTranslationHelper )
3376+ deps := BaseDeps {
3377+ GQLClient : client ,
3378+ }
3379+ handler := serverTool .Handler (deps )
3380+
3381+ // Create call request
3382+ request := createMCPRequest (tc .requestArgs )
3383+
3384+ // Call handler
3385+ result , err := handler (ContextWithDeps (context .Background (), deps ), & request )
3386+ require .NoError (t , err )
3387+
3388+ textContent := getTextResult (t , result )
3389+
3390+ if tc .expectToolError {
3391+ require .True (t , result .IsError )
3392+ assert .Contains (t , textContent .Text , tc .expectedToolErrMsg )
3393+ return
3394+ }
3395+
3396+ require .False (t , result .IsError )
3397+ assert .Equal (t , tc .expectedResult , textContent .Text )
3398+ })
3399+ }
3400+ }
0 commit comments