@@ -1650,3 +1650,106 @@ func Test_AddPullRequestReviewComment(t *testing.T) {
1650
1650
})
1651
1651
}
1652
1652
}
1653
+
1654
+ func Test_ReplyToPullRequestReviewComment (t * testing.T ) {
1655
+ // Verify tool definition once
1656
+ mockClient := github .NewClient (nil )
1657
+ tool , _ := ReplyToPullRequestReviewComment (mockClient , translations .NullTranslationHelper )
1658
+
1659
+ assert .Equal (t , "reply_to_pull_request_review_comment" , tool .Name )
1660
+ assert .NotEmpty (t , tool .Description )
1661
+ assert .Contains (t , tool .InputSchema .Properties , "owner" )
1662
+ assert .Contains (t , tool .InputSchema .Properties , "repo" )
1663
+ assert .Contains (t , tool .InputSchema .Properties , "pull_number" )
1664
+ assert .Contains (t , tool .InputSchema .Properties , "comment_id" )
1665
+ assert .Contains (t , tool .InputSchema .Properties , "body" )
1666
+ assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" , "pull_number" , "comment_id" , "body" })
1667
+
1668
+ // Setup mock PR comment for success case
1669
+ mockReply := & github.PullRequestComment {
1670
+ ID : github .Ptr (int64 (456 )),
1671
+ Body : github .Ptr ("Good point, will fix!" ),
1672
+ }
1673
+
1674
+ tests := []struct {
1675
+ name string
1676
+ mockedClient * http.Client
1677
+ requestArgs map [string ]interface {}
1678
+ expectError bool
1679
+ expectedReply * github.PullRequestComment
1680
+ expectedErrMsg string
1681
+ }{
1682
+ {
1683
+ name : "successful reply creation" ,
1684
+ mockedClient : mock .NewMockedHTTPClient (
1685
+ mock .WithRequestMatchHandler (
1686
+ mock .PostReposPullsCommentsByOwnerByRepoByPullNumber ,
1687
+ http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
1688
+ w .WriteHeader (http .StatusCreated )
1689
+ json .NewEncoder (w ).Encode (mockReply )
1690
+ }),
1691
+ ),
1692
+ ),
1693
+ requestArgs : map [string ]interface {}{
1694
+ "owner" : "owner" ,
1695
+ "repo" : "repo" ,
1696
+ "pull_number" : float64 (1 ),
1697
+ "comment_id" : float64 (123 ),
1698
+ "body" : "Good point, will fix!" ,
1699
+ },
1700
+ expectError : false ,
1701
+ expectedReply : mockReply ,
1702
+ },
1703
+ {
1704
+ name : "reply creation fails" ,
1705
+ mockedClient : mock .NewMockedHTTPClient (
1706
+ mock .WithRequestMatchHandler (
1707
+ mock .PostReposPullsCommentsByOwnerByRepoByPullNumber ,
1708
+ http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
1709
+ w .WriteHeader (http .StatusNotFound )
1710
+ w .Header ().Set ("Content-Type" , "application/json" )
1711
+ _ , _ = w .Write ([]byte (`{"message": "Comment not found"}` ))
1712
+ }),
1713
+ ),
1714
+ ),
1715
+ requestArgs : map [string ]interface {}{
1716
+ "owner" : "owner" ,
1717
+ "repo" : "repo" ,
1718
+ "pull_number" : float64 (1 ),
1719
+ "comment_id" : float64 (999 ),
1720
+ "body" : "Good point, will fix!" ,
1721
+ },
1722
+ expectError : true ,
1723
+ expectedErrMsg : "failed to reply to pull request comment" ,
1724
+ },
1725
+ }
1726
+
1727
+ for _ , tc := range tests {
1728
+ t .Run (tc .name , func (t * testing.T ) {
1729
+ mockClient := github .NewClient (tc .mockedClient )
1730
+
1731
+ _ , handler := replyToPullRequestReviewComment (mockClient , translations .NullTranslationHelper )
1732
+
1733
+ request := createMCPRequest (tc .requestArgs )
1734
+
1735
+ result , err := handler (context .Background (), request )
1736
+
1737
+ if tc .name == "reply creation fails" {
1738
+ require .Error (t , err )
1739
+ assert .Contains (t , err .Error (), tc .expectedErrMsg )
1740
+ return
1741
+ }
1742
+
1743
+ require .NoError (t , err )
1744
+ assert .NotNil (t , result )
1745
+ require .Len (t , result .Content , 1 )
1746
+
1747
+ var returnedReply github.PullRequestComment
1748
+ err = json .Unmarshal ([]byte (getTextResult (t , result ).Text ), & returnedReply )
1749
+ require .NoError (t , err )
1750
+
1751
+ assert .Equal (t , * tc .expectedReply .ID , * returnedReply .ID )
1752
+ assert .Equal (t , * tc .expectedReply .Body , * returnedReply .Body )
1753
+ })
1754
+ }
1755
+ }
0 commit comments