@@ -1505,3 +1505,106 @@ func Test_AddPullRequestReviewComment(t *testing.T) {
1505
1505
})
1506
1506
}
1507
1507
}
1508
+
1509
+ func Test_ReplyToPullRequestReviewComment (t * testing.T ) {
1510
+ // Verify tool definition once
1511
+ mockClient := github .NewClient (nil )
1512
+ tool , _ := replyToPullRequestReviewComment (mockClient , translations .NullTranslationHelper )
1513
+
1514
+ assert .Equal (t , "reply_to_pull_request_review_comment" , tool .Name )
1515
+ assert .NotEmpty (t , tool .Description )
1516
+ assert .Contains (t , tool .InputSchema .Properties , "owner" )
1517
+ assert .Contains (t , tool .InputSchema .Properties , "repo" )
1518
+ assert .Contains (t , tool .InputSchema .Properties , "pull_number" )
1519
+ assert .Contains (t , tool .InputSchema .Properties , "comment_id" )
1520
+ assert .Contains (t , tool .InputSchema .Properties , "body" )
1521
+ assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" , "pull_number" , "comment_id" , "body" })
1522
+
1523
+ // Setup mock PR comment for success case
1524
+ mockReply := & github.PullRequestComment {
1525
+ ID : github .Ptr (int64 (456 )),
1526
+ Body : github .Ptr ("Good point, will fix!" ),
1527
+ }
1528
+
1529
+ tests := []struct {
1530
+ name string
1531
+ mockedClient * http.Client
1532
+ requestArgs map [string ]interface {}
1533
+ expectError bool
1534
+ expectedReply * github.PullRequestComment
1535
+ expectedErrMsg string
1536
+ }{
1537
+ {
1538
+ name : "successful reply creation" ,
1539
+ mockedClient : mock .NewMockedHTTPClient (
1540
+ mock .WithRequestMatchHandler (
1541
+ mock .PostReposPullsCommentsByOwnerByRepoByPullNumber ,
1542
+ http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
1543
+ w .WriteHeader (http .StatusCreated )
1544
+ json .NewEncoder (w ).Encode (mockReply )
1545
+ }),
1546
+ ),
1547
+ ),
1548
+ requestArgs : map [string ]interface {}{
1549
+ "owner" : "owner" ,
1550
+ "repo" : "repo" ,
1551
+ "pull_number" : float64 (1 ),
1552
+ "comment_id" : float64 (123 ),
1553
+ "body" : "Good point, will fix!" ,
1554
+ },
1555
+ expectError : false ,
1556
+ expectedReply : mockReply ,
1557
+ },
1558
+ {
1559
+ name : "reply creation fails" ,
1560
+ mockedClient : mock .NewMockedHTTPClient (
1561
+ mock .WithRequestMatchHandler (
1562
+ mock .PostReposPullsCommentsByOwnerByRepoByPullNumber ,
1563
+ http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
1564
+ w .WriteHeader (http .StatusNotFound )
1565
+ w .Header ().Set ("Content-Type" , "application/json" )
1566
+ _ , _ = w .Write ([]byte (`{"message": "Comment not found"}` ))
1567
+ }),
1568
+ ),
1569
+ ),
1570
+ requestArgs : map [string ]interface {}{
1571
+ "owner" : "owner" ,
1572
+ "repo" : "repo" ,
1573
+ "pull_number" : float64 (1 ),
1574
+ "comment_id" : float64 (999 ),
1575
+ "body" : "Good point, will fix!" ,
1576
+ },
1577
+ expectError : true ,
1578
+ expectedErrMsg : "failed to reply to pull request comment" ,
1579
+ },
1580
+ }
1581
+
1582
+ for _ , tc := range tests {
1583
+ t .Run (tc .name , func (t * testing.T ) {
1584
+ mockClient := github .NewClient (tc .mockedClient )
1585
+
1586
+ _ , handler := replyToPullRequestReviewComment (mockClient , translations .NullTranslationHelper )
1587
+
1588
+ request := createMCPRequest (tc .requestArgs )
1589
+
1590
+ result , err := handler (context .Background (), request )
1591
+
1592
+ if tc .name == "reply creation fails" {
1593
+ require .Error (t , err )
1594
+ assert .Contains (t , err .Error (), tc .expectedErrMsg )
1595
+ return
1596
+ }
1597
+
1598
+ require .NoError (t , err )
1599
+ assert .NotNil (t , result )
1600
+ require .Len (t , result .Content , 1 )
1601
+
1602
+ var returnedReply github.PullRequestComment
1603
+ err = json .Unmarshal ([]byte (getTextResult (t , result ).Text ), & returnedReply )
1604
+ require .NoError (t , err )
1605
+
1606
+ assert .Equal (t , * tc .expectedReply .ID , * returnedReply .ID )
1607
+ assert .Equal (t , * tc .expectedReply .Body , * returnedReply .Body )
1608
+ })
1609
+ }
1610
+ }
0 commit comments