Skip to content

Commit d9e0e0c

Browse files
committed
Reuse cache
1 parent 5da1d0a commit d9e0e0c

File tree

1 file changed

+60
-77
lines changed

1 file changed

+60
-77
lines changed

pkg/github/issues_test.go

Lines changed: 60 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,64 @@ import (
2222
func Test_GetIssue(t *testing.T) {
2323
// Verify tool definition once
2424
mockClient := github.NewClient(nil)
25-
defaultGQLClient := githubv4.NewClient(nil)
26-
tool, _ := IssueRead(stubGetClientFn(mockClient), stubGetGQLClientFn(defaultGQLClient), stubRepoAccessCache(defaultGQLClient, 5*time.Minute), translations.NullTranslationHelper, stubFeatureFlags(map[string]bool{"lockdown-mode": false}))
25+
type repoAccessQuery struct {
26+
Repository struct {
27+
IsPrivate githubv4.Boolean
28+
Collaborators struct {
29+
Edges []struct {
30+
Permission githubv4.String
31+
Node struct {
32+
Login githubv4.String
33+
}
34+
}
35+
} `graphql:"collaborators(query: $username, first: 1)"`
36+
} `graphql:"repository(owner: $owner, name: $name)"`
37+
}
38+
39+
lockdownHTTPClient := githubv4mock.NewMockedHTTPClient(
40+
githubv4mock.NewQueryMatcher(
41+
repoAccessQuery{},
42+
map[string]any{
43+
"owner": githubv4.String("github"),
44+
"name": githubv4.String("github-mcp-server"),
45+
"username": githubv4.String("testuser"),
46+
},
47+
githubv4mock.DataResponse(map[string]any{
48+
"repository": map[string]any{
49+
"isPrivate": true,
50+
"collaborators": map[string]any{
51+
"edges": []any{},
52+
},
53+
},
54+
}),
55+
),
56+
githubv4mock.NewQueryMatcher(
57+
repoAccessQuery{},
58+
map[string]any{
59+
"owner": githubv4.String("owner"),
60+
"name": githubv4.String("repo"),
61+
"username": githubv4.String("testuser"),
62+
},
63+
githubv4mock.DataResponse(map[string]any{
64+
"repository": map[string]any{
65+
"isPrivate": false,
66+
"collaborators": map[string]any{
67+
"edges": []any{
68+
map[string]any{
69+
"permission": "READ",
70+
"node": map[string]any{
71+
"login": "testuser",
72+
},
73+
},
74+
},
75+
},
76+
},
77+
}),
78+
),
79+
)
80+
defaultGQLClient := githubv4.NewClient(lockdownHTTPClient)
81+
repoAccessCache := stubRepoAccessCache(defaultGQLClient, 15*time.Minute)
82+
tool, _ := IssueRead(stubGetClientFn(mockClient), stubGetGQLClientFn(defaultGQLClient), repoAccessCache, translations.NullTranslationHelper, stubFeatureFlags(map[string]bool{"lockdown-mode": false}))
2783
require.NoError(t, toolsnaps.Test(tool.Name, tool))
2884

2985
assert.Equal(t, "issue_read", tool.Name)
@@ -55,7 +111,6 @@ func Test_GetIssue(t *testing.T) {
55111
tests := []struct {
56112
name string
57113
mockedClient *http.Client
58-
gqlHTTPClient *http.Client
59114
requestArgs map[string]interface{}
60115
expectHandlerError bool
61116
expectResultError bool
@@ -104,36 +159,6 @@ func Test_GetIssue(t *testing.T) {
104159
mockIssue,
105160
),
106161
),
107-
gqlHTTPClient: githubv4mock.NewMockedHTTPClient(
108-
githubv4mock.NewQueryMatcher(
109-
struct {
110-
Repository struct {
111-
IsPrivate githubv4.Boolean
112-
Collaborators struct {
113-
Edges []struct {
114-
Permission githubv4.String
115-
Node struct {
116-
Login githubv4.String
117-
}
118-
}
119-
} `graphql:"collaborators(query: $username, first: 1)"`
120-
} `graphql:"repository(owner: $owner, name: $name)"`
121-
}{},
122-
map[string]any{
123-
"owner": githubv4.String("github"),
124-
"name": githubv4.String("github-mcp-server"),
125-
"username": githubv4.String("testuser"),
126-
},
127-
githubv4mock.DataResponse(map[string]any{
128-
"repository": map[string]any{
129-
"isPrivate": true,
130-
"collaborators": map[string]any{
131-
"edges": []any{},
132-
},
133-
},
134-
}),
135-
),
136-
),
137162
requestArgs: map[string]interface{}{
138163
"method": "get",
139164
"owner": "github",
@@ -151,43 +176,6 @@ func Test_GetIssue(t *testing.T) {
151176
mockIssue,
152177
),
153178
),
154-
gqlHTTPClient: githubv4mock.NewMockedHTTPClient(
155-
githubv4mock.NewQueryMatcher(
156-
struct {
157-
Repository struct {
158-
IsPrivate githubv4.Boolean
159-
Collaborators struct {
160-
Edges []struct {
161-
Permission githubv4.String
162-
Node struct {
163-
Login githubv4.String
164-
}
165-
}
166-
} `graphql:"collaborators(query: $username, first: 1)"`
167-
} `graphql:"repository(owner: $owner, name: $name)"`
168-
}{},
169-
map[string]any{
170-
"owner": githubv4.String("owner"),
171-
"name": githubv4.String("repo"),
172-
"username": githubv4.String("testuser"),
173-
},
174-
githubv4mock.DataResponse(map[string]any{
175-
"repository": map[string]any{
176-
"isPrivate": false,
177-
"collaborators": map[string]any{
178-
"edges": []any{
179-
map[string]any{
180-
"permission": "READ",
181-
"node": map[string]any{
182-
"login": "testuser",
183-
},
184-
},
185-
},
186-
},
187-
},
188-
}),
189-
),
190-
),
191179
requestArgs: map[string]interface{}{
192180
"method": "get",
193181
"owner": "owner",
@@ -204,15 +192,10 @@ func Test_GetIssue(t *testing.T) {
204192
t.Run(tc.name, func(t *testing.T) {
205193
client := github.NewClient(tc.mockedClient)
206194

207-
var gqlClient *githubv4.Client
208-
if tc.gqlHTTPClient != nil {
209-
gqlClient = githubv4.NewClient(tc.gqlHTTPClient)
210-
} else {
211-
gqlClient = defaultGQLClient
212-
}
195+
gqlClient := defaultGQLClient
213196

214197
flags := stubFeatureFlags(map[string]bool{"lockdown-mode": tc.lockdownEnabled})
215-
_, handler := IssueRead(stubGetClientFn(client), stubGetGQLClientFn(gqlClient), stubRepoAccessCache(gqlClient, 15*time.Minute), translations.NullTranslationHelper, flags)
198+
_, handler := IssueRead(stubGetClientFn(client), stubGetGQLClientFn(gqlClient), repoAccessCache, translations.NullTranslationHelper, flags)
216199

217200
request := createMCPRequest(tc.requestArgs)
218201
result, err := handler(context.Background(), request)

0 commit comments

Comments
 (0)