@@ -560,112 +560,6 @@ func Test_GetIssue_FieldValues_Enriched(t *testing.T) {
560560 assert .Equal (t , "2.5" , returnedIssue .FieldValues [1 ].Value )
561561}
562562
563- func Test_AddIssueComment (t * testing.T ) {
564- // Verify tool definition once
565- serverTool := AddIssueComment (translations .NullTranslationHelper )
566- tool := serverTool .Tool
567- require .NoError (t , toolsnaps .Test (tool .Name , tool ))
568-
569- assert .Equal (t , "add_issue_comment" , tool .Name )
570- assert .NotEmpty (t , tool .Description )
571-
572- assert .Contains (t , tool .InputSchema .(* jsonschema.Schema ).Properties , "owner" )
573- assert .Contains (t , tool .InputSchema .(* jsonschema.Schema ).Properties , "repo" )
574- assert .Contains (t , tool .InputSchema .(* jsonschema.Schema ).Properties , "issue_number" )
575- assert .Contains (t , tool .InputSchema .(* jsonschema.Schema ).Properties , "comment_id" )
576- assert .Contains (t , tool .InputSchema .(* jsonschema.Schema ).Properties , "body" )
577- assert .Contains (t , tool .InputSchema .(* jsonschema.Schema ).Properties , "reaction" )
578- assert .ElementsMatch (t , tool .InputSchema .(* jsonschema.Schema ).Required , []string {"owner" , "repo" , "issue_number" })
579-
580- // Setup mock comment for success case
581- mockComment := & github.IssueComment {
582- ID : github .Ptr (int64 (123 )),
583- Body : github .Ptr ("This is a test comment" ),
584- User : & github.User {
585- Login : github .Ptr ("testuser" ),
586- },
587- HTMLURL : github .Ptr ("https://github.com/owner/repo/issues/42#issuecomment-123" ),
588- }
589-
590- tests := []struct {
591- name string
592- mockedClient * http.Client
593- requestArgs map [string ]any
594- expectError bool
595- expectedComment * github.IssueComment
596- expectedErrMsg string
597- }{
598- {
599- name : "successful comment creation" ,
600- mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
601- PostReposIssuesCommentsByOwnerByRepoByIssueNumber : mockResponse (t , http .StatusCreated , mockComment ),
602- }),
603- requestArgs : map [string ]any {
604- "owner" : "owner" ,
605- "repo" : "repo" ,
606- "issue_number" : float64 (42 ),
607- "body" : "This is a test comment" ,
608- },
609- expectError : false ,
610- expectedComment : mockComment ,
611- },
612- {
613- name : "comment creation fails" ,
614- mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
615- PostReposIssuesCommentsByOwnerByRepoByIssueNumber : http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
616- w .WriteHeader (http .StatusUnprocessableEntity )
617- _ , _ = w .Write ([]byte (`{"message": "Invalid request"}` ))
618- }),
619- }),
620- requestArgs : map [string ]any {
621- "owner" : "owner" ,
622- "repo" : "repo" ,
623- "issue_number" : float64 (42 ),
624- "body" : "This is a test comment" ,
625- },
626- expectError : true ,
627- expectedErrMsg : "failed to create comment" ,
628- },
629- }
630-
631- for _ , tc := range tests {
632- t .Run (tc .name , func (t * testing.T ) {
633- // Setup client with mock
634- client := mustNewGHClient (t , tc .mockedClient )
635- deps := BaseDeps {
636- Client : client ,
637- }
638- handler := serverTool .Handler (deps )
639-
640- // Create call request
641- request := createMCPRequest (tc .requestArgs )
642-
643- // Call handler
644- result , err := handler (ContextWithDeps (context .Background (), deps ), & request )
645-
646- if tc .expectError {
647- require .NoError (t , err )
648- require .True (t , result .IsError )
649- errorContent := getErrorResult (t , result )
650- assert .Contains (t , errorContent .Text , tc .expectedErrMsg )
651- return
652- }
653-
654- require .NoError (t , err )
655-
656- // Parse the result and get the text content if no error
657- textContent := getTextResult (t , result )
658-
659- // Unmarshal and verify the result contains minimal response
660- var minimalResponse MinimalResponse
661- err = json .Unmarshal ([]byte (textContent .Text ), & minimalResponse )
662- require .NoError (t , err )
663- assert .Equal (t , fmt .Sprintf ("%d" , tc .expectedComment .GetID ()), minimalResponse .ID )
664- assert .Equal (t , tc .expectedComment .GetHTMLURL (), minimalResponse .URL )
665- })
666- }
667- }
668-
669563func Test_SearchIssues (t * testing.T ) {
670564 // Verify tool definition once
671565 serverTool := SearchIssues (translations .NullTranslationHelper )
@@ -4316,6 +4210,10 @@ func TestAddIssueComment(t *testing.T) {
43164210 ID : github .Ptr (int64 (789 )),
43174211 Content : github .Ptr ("heart" ),
43184212 }
4213+ mockIssueComment := & github.IssueComment {
4214+ ID : github .Ptr (int64 (999 )),
4215+ IssueURL : github .Ptr ("https://api.github.com/repos/owner/repo/issues/42" ),
4216+ }
43194217 commentCreatedAfterReactionFailure := & atomic.Bool {}
43204218
43214219 tests := []struct {
@@ -4353,6 +4251,7 @@ func TestAddIssueComment(t *testing.T) {
43534251 {
43544252 name : "successful reaction to issue comment" ,
43554253 mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
4254+ GetReposIssuesCommentByOwnerByRepoByCommentID : mockResponse (t , http .StatusOK , mockIssueComment ),
43564255 PostReposIssuesCommentsReactionsByOwnerByRepoByCommentID : mockResponse (t , http .StatusCreated , mockReaction ),
43574256 }),
43584257 requestArgs : map [string ]any {
@@ -4363,6 +4262,42 @@ func TestAddIssueComment(t *testing.T) {
43634262 "reaction" : "heart" ,
43644263 },
43654264 },
4265+ {
4266+ name : "issue comment reaction requires matching issue_number" ,
4267+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
4268+ GetReposIssuesCommentByOwnerByRepoByCommentID : mockResponse (t , http .StatusOK , & github.IssueComment {
4269+ ID : github .Ptr (int64 (999 )),
4270+ IssueURL : github .Ptr ("https://api.github.com/repos/owner/repo/issues/43" ),
4271+ }),
4272+ }),
4273+ requestArgs : map [string ]any {
4274+ "owner" : "owner" ,
4275+ "repo" : "repo" ,
4276+ "issue_number" : float64 (42 ),
4277+ "comment_id" : float64 (999 ),
4278+ "reaction" : "heart" ,
4279+ },
4280+ expectToolError : true ,
4281+ expectedToolErrMsg : "comment_id does not belong to issue_number 42" ,
4282+ },
4283+ {
4284+ name : "issue comment lookup fails" ,
4285+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
4286+ GetReposIssuesCommentByOwnerByRepoByCommentID : func (w http.ResponseWriter , _ * http.Request ) {
4287+ w .WriteHeader (http .StatusNotFound )
4288+ _ , _ = w .Write ([]byte (`{"message": "Not Found"}` ))
4289+ },
4290+ }),
4291+ requestArgs : map [string ]any {
4292+ "owner" : "owner" ,
4293+ "repo" : "repo" ,
4294+ "issue_number" : float64 (42 ),
4295+ "comment_id" : float64 (999 ),
4296+ "reaction" : "heart" ,
4297+ },
4298+ expectToolError : true ,
4299+ expectedToolErrMsg : "failed to get issue comment" ,
4300+ },
43664301 {
43674302 name : "successful comment and reaction to issue" ,
43684303 mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
0 commit comments