|
4 | 4 | "context" |
5 | 5 | "encoding/json" |
6 | 6 | "net/http" |
| 7 | + "net/http/httptest" |
7 | 8 | "testing" |
8 | 9 | "time" |
9 | 10 |
|
@@ -2056,6 +2057,103 @@ func Test_GetPullRequestComments(t *testing.T) { |
2056 | 2057 | } |
2057 | 2058 | } |
2058 | 2059 |
|
| 2060 | +func Test_GetPullRequestCommentsWithSuggestions(t *testing.T) { |
| 2061 | + t.Parallel() |
| 2062 | + |
| 2063 | + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 2064 | + assert.Equal(t, "/owner/repo/pull/42/threads/1964378741", r.URL.Path) |
| 2065 | + _, _ = w.Write([]byte(automatedSuggestionHTMLFixture)) |
| 2066 | + })) |
| 2067 | + defer server.Close() |
| 2068 | + |
| 2069 | + restClient, err := github.NewClient(github.WithHTTPClient(server.Client()), github.WithEnterpriseURLs(server.URL+"/", server.URL+"/")) |
| 2070 | + require.NoError(t, err) |
| 2071 | + |
| 2072 | + gqlHTTPClient := githubv4mock.NewMockedHTTPClient( |
| 2073 | + githubv4mock.NewQueryMatcher( |
| 2074 | + reviewThreadsQuery{}, |
| 2075 | + map[string]any{ |
| 2076 | + "owner": githubv4.String("owner"), |
| 2077 | + "repo": githubv4.String("repo"), |
| 2078 | + "prNum": githubv4.Int(42), |
| 2079 | + "first": githubv4.Int(30), |
| 2080 | + "commentsPerThread": githubv4.Int(100), |
| 2081 | + "after": (*githubv4.String)(nil), |
| 2082 | + }, |
| 2083 | + githubv4mock.DataResponse(map[string]any{ |
| 2084 | + "repository": map[string]any{ |
| 2085 | + "pullRequest": map[string]any{ |
| 2086 | + "reviewThreads": map[string]any{ |
| 2087 | + "nodes": []map[string]any{ |
| 2088 | + { |
| 2089 | + "id": "PRRT_kwDORGz4i851Fgp1", |
| 2090 | + "isResolved": false, |
| 2091 | + "isOutdated": false, |
| 2092 | + "isCollapsed": false, |
| 2093 | + "comments": map[string]any{ |
| 2094 | + "totalCount": 1, |
| 2095 | + "nodes": []map[string]any{ |
| 2096 | + { |
| 2097 | + "id": "PRRC_kwDORGz4i86v72Xc", |
| 2098 | + "body": "Consider adding validation.", |
| 2099 | + "path": "glmocr/cli.py", |
| 2100 | + "line": 10, |
| 2101 | + "author": map[string]any{ |
| 2102 | + "login": "copilot-pull-request-reviewer", |
| 2103 | + }, |
| 2104 | + "createdAt": "2024-01-01T12:00:00Z", |
| 2105 | + "updatedAt": "2024-01-01T12:00:00Z", |
| 2106 | + "url": "https://github.com/owner/repo/pull/42#discussion_r101", |
| 2107 | + }, |
| 2108 | + }, |
| 2109 | + }, |
| 2110 | + }, |
| 2111 | + }, |
| 2112 | + "pageInfo": map[string]any{ |
| 2113 | + "hasNextPage": false, |
| 2114 | + "hasPreviousPage": false, |
| 2115 | + "startCursor": "cursor1", |
| 2116 | + "endCursor": "cursor2", |
| 2117 | + }, |
| 2118 | + "totalCount": 1, |
| 2119 | + }, |
| 2120 | + }, |
| 2121 | + }, |
| 2122 | + }), |
| 2123 | + ), |
| 2124 | + ) |
| 2125 | + |
| 2126 | + serverTool := PullRequestRead(translations.NullTranslationHelper) |
| 2127 | + deps := BaseDeps{ |
| 2128 | + Client: restClient, |
| 2129 | + GQLClient: githubv4.NewClient(gqlHTTPClient), |
| 2130 | + } |
| 2131 | + handler := serverTool.Handler(deps) |
| 2132 | + |
| 2133 | + request := createMCPRequest(map[string]any{ |
| 2134 | + "method": "get_review_comments", |
| 2135 | + "owner": "owner", |
| 2136 | + "repo": "repo", |
| 2137 | + "pullNumber": float64(42), |
| 2138 | + }) |
| 2139 | + |
| 2140 | + result, err := handler(ContextWithDeps(context.Background(), deps), &request) |
| 2141 | + require.NoError(t, err) |
| 2142 | + require.False(t, result.IsError) |
| 2143 | + |
| 2144 | + textContent := getTextResult(t, result) |
| 2145 | + var response MinimalReviewThreadsResponse |
| 2146 | + require.NoError(t, json.Unmarshal([]byte(textContent.Text), &response)) |
| 2147 | + require.Len(t, response.ReviewThreads, 1) |
| 2148 | + require.Len(t, response.ReviewThreads[0].Comments, 1) |
| 2149 | + |
| 2150 | + suggestions := response.ReviewThreads[0].Comments[0].Suggestions |
| 2151 | + require.Len(t, suggestions, 1) |
| 2152 | + assert.Equal(t, suggestionSourceAutomated, suggestions[0].Source) |
| 2153 | + assert.Equal(t, "glmocr/cli.py", suggestions[0].Path) |
| 2154 | + assert.Contains(t, suggestions[0].Suggestion, "import re") |
| 2155 | +} |
| 2156 | + |
2059 | 2157 | func Test_GetPullRequestReviews(t *testing.T) { |
2060 | 2158 | // Verify tool definition once |
2061 | 2159 | serverTool := PullRequestRead(translations.NullTranslationHelper) |
|
0 commit comments