@@ -6639,6 +6639,195 @@ func TestAddIssueCommentHandler(t *testing.T) {
66396639 }
66406640}
66416641
6642+ func TestUpdateIssueCommentSchema (t * testing.T ) {
6643+ t .Parallel ()
6644+
6645+ tool := UpdateIssueComment (translations .NullTranslationHelper ).Tool
6646+ require .NoError (t , toolsnaps .Test (tool .Name , tool ))
6647+
6648+ assert .Equal (t , "update_issue_comment" , tool .Name )
6649+ assert .NotEmpty (t , tool .Description )
6650+ schema := tool .InputSchema .(* jsonschema.Schema )
6651+ assert .Contains (t , schema .Properties , "owner" )
6652+ assert .Contains (t , schema .Properties , "repo" )
6653+ assert .Contains (t , schema .Properties , "comment_id" )
6654+ assert .Contains (t , schema .Properties , "body" )
6655+ assert .ElementsMatch (t , schema .Required , []string {"owner" , "repo" , "comment_id" , "body" })
6656+
6657+ resolved , err := schema .Resolve (nil )
6658+ require .NoError (t , err )
6659+
6660+ baseArgs := map [string ]any {
6661+ "owner" : "owner" ,
6662+ "repo" : "repo" ,
6663+ "comment_id" : 456 ,
6664+ "body" : "Updated comment" ,
6665+ }
6666+ tests := []struct {
6667+ name string
6668+ args map [string ]any
6669+ isValid bool
6670+ }{
6671+ {
6672+ name : "valid arguments" ,
6673+ args : map [string ]any {},
6674+ isValid : true ,
6675+ },
6676+ {
6677+ name : "missing required body" ,
6678+ args : map [string ]any {"body" : nil },
6679+ isValid : false ,
6680+ },
6681+ {
6682+ name : "empty body" ,
6683+ args : map [string ]any {"body" : "" },
6684+ isValid : false ,
6685+ },
6686+ {
6687+ name : "zero comment ID" ,
6688+ args : map [string ]any {"comment_id" : 0 },
6689+ isValid : false ,
6690+ },
6691+ {
6692+ name : "fractional comment ID" ,
6693+ args : map [string ]any {"comment_id" : 1.5 },
6694+ isValid : false ,
6695+ },
6696+ }
6697+
6698+ for _ , tc := range tests {
6699+ t .Run (tc .name , func (t * testing.T ) {
6700+ t .Parallel ()
6701+
6702+ args := maps .Clone (baseArgs )
6703+ maps .Copy (args , tc .args )
6704+ err := resolved .Validate (args )
6705+ if tc .isValid {
6706+ require .NoError (t , err )
6707+ return
6708+ }
6709+ require .Error (t , err )
6710+ })
6711+ }
6712+ }
6713+
6714+ func TestUpdateIssueCommentHandler (t * testing.T ) {
6715+ t .Parallel ()
6716+
6717+ updatedComment := & github.IssueComment {
6718+ ID : github .Ptr (int64 (456 )),
6719+ Body : github .Ptr ("Updated comment" ),
6720+ HTMLURL : github .Ptr ("https://github.com/owner/repo/issues/42#issuecomment-456" ),
6721+ }
6722+
6723+ tests := []struct {
6724+ name string
6725+ mockedClient * http.Client
6726+ requestArgs map [string ]any
6727+ expectToolError bool
6728+ expectedToolErrMsg string
6729+ }{
6730+ {
6731+ name : "successful update" ,
6732+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
6733+ PatchReposIssuesCommentByOwnerByRepoByCommentID : expectRequestBody (t , map [string ]any {
6734+ "body" : "Updated comment" ,
6735+ }).andThen (mockResponse (t , http .StatusOK , updatedComment )),
6736+ }),
6737+ requestArgs : map [string ]any {
6738+ "owner" : "owner" ,
6739+ "repo" : "repo" ,
6740+ "comment_id" : float64 (456 ),
6741+ "body" : "Updated comment" ,
6742+ },
6743+ },
6744+ {
6745+ name : "missing body" ,
6746+ requestArgs : map [string ]any {
6747+ "owner" : "owner" ,
6748+ "repo" : "repo" ,
6749+ "comment_id" : float64 (456 ),
6750+ },
6751+ expectToolError : true ,
6752+ expectedToolErrMsg : "missing required parameter: body" ,
6753+ },
6754+ {
6755+ name : "empty body" ,
6756+ requestArgs : map [string ]any {
6757+ "owner" : "owner" ,
6758+ "repo" : "repo" ,
6759+ "comment_id" : float64 (456 ),
6760+ "body" : "" ,
6761+ },
6762+ expectToolError : true ,
6763+ expectedToolErrMsg : "body cannot be empty when provided" ,
6764+ },
6765+ {
6766+ name : "negative comment ID" ,
6767+ requestArgs : map [string ]any {
6768+ "owner" : "owner" ,
6769+ "repo" : "repo" ,
6770+ "comment_id" : float64 (- 1 ),
6771+ "body" : "Updated comment" ,
6772+ },
6773+ expectToolError : true ,
6774+ expectedToolErrMsg : "comment_id must be greater than 0" ,
6775+ },
6776+ {
6777+ name : "fractional comment ID" ,
6778+ requestArgs : map [string ]any {
6779+ "owner" : "owner" ,
6780+ "repo" : "repo" ,
6781+ "comment_id" : float64 (1.5 ),
6782+ "body" : "Updated comment" ,
6783+ },
6784+ expectToolError : true ,
6785+ expectedToolErrMsg : "parameter comment_id is not a valid number" ,
6786+ },
6787+ {
6788+ name : "API error" ,
6789+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
6790+ PatchReposIssuesCommentByOwnerByRepoByCommentID : mockResponse (t , http .StatusNotFound , `{"message": "Not Found"}` ),
6791+ }),
6792+ requestArgs : map [string ]any {
6793+ "owner" : "owner" ,
6794+ "repo" : "repo" ,
6795+ "comment_id" : float64 (456 ),
6796+ "body" : "Updated comment" ,
6797+ },
6798+ expectToolError : true ,
6799+ expectedToolErrMsg : "failed to update issue comment" ,
6800+ },
6801+ }
6802+
6803+ for _ , tc := range tests {
6804+ t .Run (tc .name , func (t * testing.T ) {
6805+ t .Parallel ()
6806+
6807+ client := mustNewGHClient (t , tc .mockedClient )
6808+ deps := BaseDeps {Client : client }
6809+ serverTool := UpdateIssueComment (translations .NullTranslationHelper )
6810+ handler := serverTool .Handler (deps )
6811+
6812+ request := createMCPRequest (tc .requestArgs )
6813+ result , err := handler (ContextWithDeps (context .Background (), deps ), & request )
6814+ require .NoError (t , err )
6815+
6816+ if tc .expectToolError {
6817+ require .True (t , result .IsError )
6818+ assert .Contains (t , getErrorResult (t , result ).Text , tc .expectedToolErrMsg )
6819+ return
6820+ }
6821+
6822+ require .False (t , result .IsError )
6823+ var response MinimalResponse
6824+ require .NoError (t , json .Unmarshal ([]byte (getTextResult (t , result ).Text ), & response ))
6825+ assert .Equal (t , "456" , response .ID )
6826+ assert .Equal (t , "https://github.com/owner/repo/issues/42#issuecomment-456" , response .URL )
6827+ })
6828+ }
6829+ }
6830+
66426831func Test_RemoveSubIssue (t * testing.T ) {
66436832 // Verify tool definition once
66446833 serverTool := SubIssueWrite (translations .NullTranslationHelper )
0 commit comments