@@ -1655,6 +1655,116 @@ func Test_RequestCopilotReview(t *testing.T) {
1655
1655
}
1656
1656
}
1657
1657
1658
+ func Test_UpdatePullRequestComment (t * testing.T ) {
1659
+ // Verify tool definition once
1660
+ mockClient := github .NewClient (nil )
1661
+ tool , _ := UpdatePullRequestComment (stubGetClientFn (mockClient ), translations .NullTranslationHelper )
1662
+
1663
+ assert .Equal (t , "update_pull_request_comment" , tool .Name )
1664
+ assert .NotEmpty (t , tool .Description )
1665
+ assert .Contains (t , tool .InputSchema .Properties , "owner" )
1666
+ assert .Contains (t , tool .InputSchema .Properties , "repo" )
1667
+ assert .Contains (t , tool .InputSchema .Properties , "commentId" )
1668
+ assert .Contains (t , tool .InputSchema .Properties , "body" )
1669
+ assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" , "commentId" , "body" })
1670
+
1671
+ // Setup mock comment for success case
1672
+ mockUpdatedComment := & github.PullRequestComment {
1673
+ ID : github .Ptr (int64 (456 )),
1674
+ Body : github .Ptr ("Updated comment text here" ),
1675
+ HTMLURL : github .Ptr ("https://github.com/owner/repo/pull/1#discussion_r456" ),
1676
+ Path : github .Ptr ("file1.txt" ),
1677
+ UpdatedAt : & github.Timestamp {Time : time .Now ()},
1678
+ User : & github.User {
1679
+ Login : github .Ptr ("testuser" ),
1680
+ },
1681
+ }
1682
+
1683
+ tests := []struct {
1684
+ name string
1685
+ mockedClient * http.Client
1686
+ requestArgs map [string ]interface {}
1687
+ expectError bool
1688
+ expectedComment * github.PullRequestComment
1689
+ expectedErrMsg string
1690
+ }{
1691
+ {
1692
+ name : "successful update" ,
1693
+ mockedClient : httpMock (
1694
+ NewJSONResponder (200 , mockUpdatedComment ),
1695
+ ),
1696
+ requestArgs : map [string ]interface {}{
1697
+ "owner" : "testowner" ,
1698
+ "repo" : "testrepo" ,
1699
+ "commentId" : float64 (456 ),
1700
+ "body" : "Updated comment text here" ,
1701
+ },
1702
+ expectError : false ,
1703
+ expectedComment : mockUpdatedComment ,
1704
+ },
1705
+ {
1706
+ name : "missing required parameters" ,
1707
+ mockedClient : httpMock (
1708
+ NewJSONResponder (200 , mockUpdatedComment ),
1709
+ ),
1710
+ requestArgs : map [string ]interface {}{
1711
+ "owner" : "testowner" ,
1712
+ "repo" : "testrepo" ,
1713
+ // Missing commentId and body
1714
+ },
1715
+ expectError : true ,
1716
+ expectedErrMsg : "commentId is required" ,
1717
+ },
1718
+ {
1719
+ name : "http error" ,
1720
+ mockedClient : httpMock (
1721
+ NewStringResponder (400 , "Bad Request" ),
1722
+ ),
1723
+ requestArgs : map [string ]interface {}{
1724
+ "owner" : "testowner" ,
1725
+ "repo" : "testrepo" ,
1726
+ "commentId" : float64 (456 ),
1727
+ "body" : "Invalid body" , // Changed this to a non-empty string
1728
+ },
1729
+ expectError : true ,
1730
+ expectedErrMsg : "failed to update pull request comment" ,
1731
+ },
1732
+ }
1733
+
1734
+ for _ , tc := range tests {
1735
+ t .Run (tc .name , func (t * testing.T ) {
1736
+ client := github .NewClient (tc .mockedClient )
1737
+ _ , handler := UpdatePullRequestComment (stubGetClientFn (client ), translations .NullTranslationHelper )
1738
+
1739
+ request := createMCPRequest (tc .requestArgs )
1740
+
1741
+ // Call handler
1742
+ result , err := handler (context .Background (), request )
1743
+ require .NoError (t , err )
1744
+
1745
+ textContent := getTextResult (t , result )
1746
+
1747
+ if tc .expectError {
1748
+ require .True (t , result .IsError )
1749
+ assert .Contains (t , textContent .Text , tc .expectedErrMsg )
1750
+ return
1751
+ }
1752
+
1753
+ // Parse the result for success case
1754
+ require .False (t , result .IsError )
1755
+
1756
+ var returnedComment * github.PullRequestComment
1757
+ err = json .Unmarshal ([]byte (textContent .Text ), & returnedComment )
1758
+ require .NoError (t , err )
1759
+
1760
+ // Verify comment details
1761
+ assert .Equal (t , * tc .expectedComment .ID , * returnedComment .ID )
1762
+ assert .Equal (t , * tc .expectedComment .Body , * returnedComment .Body )
1763
+ assert .Equal (t , * tc .expectedComment .HTMLURL , * returnedComment .HTMLURL )
1764
+ })
1765
+ }
1766
+ }
1767
+
1658
1768
func TestCreatePendingPullRequestReview (t * testing.T ) {
1659
1769
t .Parallel ()
1660
1770
0 commit comments