Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf1ce263

Browse files
CopilotJoannaaKL
andcommitted
Update lockdown cache to initialize once per test function
- Added ResetInstance() function to lockdown package for test cleanup- Updated lockdown_test.go to reset singleton before and after each test- Updated issues_test.go to initialize cache once per test function (4 functions)- Updated pullrequests_test.go to initialize cache once per test function (7 functions)- All tests now explicitly reset and initialize cache at the beginning of each test function- This prevents race conditions and ensures each test has proper cache stateCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
1 parentc09a3d2 commitf1ce263

File tree

5 files changed

+73
-10
lines changed

5 files changed

+73
-10
lines changed

‎pkg/github/issues_test.go‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/github/github-mcp-server/internal/githubv4mock"
1313
"github.com/github/github-mcp-server/internal/toolsnaps"
14+
"github.com/github/github-mcp-server/pkg/lockdown"
1415
"github.com/github/github-mcp-server/pkg/translations"
1516
"github.com/google/go-github/v79/github"
1617
"github.com/migueleliasweb/go-github-mock/src/mock"
@@ -20,9 +21,13 @@ import (
2021
)
2122

2223
funcTest_GetIssue(t*testing.T) {
24+
// Initialize lockdown cache once for this test
25+
defaultGQLClient:=githubv4.NewClient(nil)
26+
lockdown.ResetInstance()
27+
lockdown.GetInstance(defaultGQLClient,lockdown.WithTTL(5*time.Minute))
28+
2329
// Verify tool definition once
2430
mockClient:=github.NewClient(nil)
25-
defaultGQLClient:=githubv4.NewClient(nil)
2631
tool,_:=IssueRead(stubGetClientFn(mockClient),stubGetGQLClientFn(defaultGQLClient),stubRepoAccessCache(defaultGQLClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
2732
require.NoError(t,toolsnaps.Test(tool.Name,tool))
2833

@@ -206,6 +211,8 @@ func Test_GetIssue(t *testing.T) {
206211

207212
vargqlClient*githubv4.Client
208213
iftc.gqlHTTPClient!=nil {
214+
// Reset lockdown cache singleton when using a custom GQL client
215+
lockdown.ResetInstance()
209216
gqlClient=githubv4.NewClient(tc.gqlHTTPClient)
210217
}else {
211218
gqlClient=defaultGQLClient
@@ -1707,9 +1714,13 @@ func Test_ParseISOTimestamp(t *testing.T) {
17071714
}
17081715

17091716
funcTest_GetIssueComments(t*testing.T) {
1717+
// Initialize lockdown cache once for this test
1718+
gqlClient:=githubv4.NewClient(nil)
1719+
lockdown.ResetInstance()
1720+
lockdown.GetInstance(gqlClient,lockdown.WithTTL(5*time.Minute))
1721+
17101722
// Verify tool definition once
17111723
mockClient:=github.NewClient(nil)
1712-
gqlClient:=githubv4.NewClient(nil)
17131724
tool,_:=IssueRead(stubGetClientFn(mockClient),stubGetGQLClientFn(gqlClient),stubRepoAccessCache(gqlClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
17141725
require.NoError(t,toolsnaps.Test(tool.Name,tool))
17151726

@@ -1850,8 +1861,12 @@ func Test_GetIssueComments(t *testing.T) {
18501861
funcTest_GetIssueLabels(t*testing.T) {
18511862
t.Parallel()
18521863

1853-
//Verify tool definition
1864+
//Initialize lockdown cache once for this test
18541865
mockGQClient:=githubv4.NewClient(nil)
1866+
lockdown.ResetInstance()
1867+
lockdown.GetInstance(mockGQClient,lockdown.WithTTL(5*time.Minute))
1868+
1869+
// Verify tool definition
18551870
mockClient:=github.NewClient(nil)
18561871
tool,_:=IssueRead(stubGetClientFn(mockClient),stubGetGQLClientFn(mockGQClient),stubRepoAccessCache(mockGQClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
18571872
require.NoError(t,toolsnaps.Test(tool.Name,tool))
@@ -2616,9 +2631,13 @@ func Test_AddSubIssue(t *testing.T) {
26162631
}
26172632

26182633
funcTest_GetSubIssues(t*testing.T) {
2634+
// Initialize lockdown cache once for this test
2635+
gqlClient:=githubv4.NewClient(nil)
2636+
lockdown.ResetInstance()
2637+
lockdown.GetInstance(gqlClient,lockdown.WithTTL(5*time.Minute))
2638+
26192639
// Verify tool definition once
26202640
mockClient:=github.NewClient(nil)
2621-
gqlClient:=githubv4.NewClient(nil)
26222641
tool,_:=IssueRead(stubGetClientFn(mockClient),stubGetGQLClientFn(gqlClient),stubRepoAccessCache(gqlClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
26232642
require.NoError(t,toolsnaps.Test(tool.Name,tool))
26242643

‎pkg/github/pullrequests_test.go‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/github/github-mcp-server/internal/githubv4mock"
1111
"github.com/github/github-mcp-server/internal/toolsnaps"
12+
"github.com/github/github-mcp-server/pkg/lockdown"
1213
"github.com/github/github-mcp-server/pkg/translations"
1314
"github.com/google/go-github/v79/github"
1415
"github.com/shurcooL/githubv4"
@@ -19,9 +20,14 @@ import (
1920
)
2021

2122
funcTest_GetPullRequest(t*testing.T) {
23+
// Initialize lockdown cache once for this test
24+
gqlClient:=githubv4.NewClient(nil)
25+
lockdown.ResetInstance()
26+
lockdown.GetInstance(gqlClient,lockdown.WithTTL(5*time.Minute))
27+
2228
// Verify tool definition once
2329
mockClient:=github.NewClient(nil)
24-
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(githubv4.NewClient(nil),5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
30+
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(gqlClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
2531
require.NoError(t,toolsnaps.Test(tool.Name,tool))
2632

2733
assert.Equal(t,"pull_request_read",tool.Name)
@@ -1131,9 +1137,14 @@ func Test_SearchPullRequests(t *testing.T) {
11311137
}
11321138

11331139
funcTest_GetPullRequestFiles(t*testing.T) {
1140+
// Initialize lockdown cache once for this test
1141+
gqlClient:=githubv4.NewClient(nil)
1142+
lockdown.ResetInstance()
1143+
lockdown.GetInstance(gqlClient,lockdown.WithTTL(5*time.Minute))
1144+
11341145
// Verify tool definition once
11351146
mockClient:=github.NewClient(nil)
1136-
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(githubv4.NewClient(nil),5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
1147+
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(gqlClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
11371148
require.NoError(t,toolsnaps.Test(tool.Name,tool))
11381149

11391150
assert.Equal(t,"pull_request_read",tool.Name)
@@ -1275,9 +1286,14 @@ func Test_GetPullRequestFiles(t *testing.T) {
12751286
}
12761287

12771288
funcTest_GetPullRequestStatus(t*testing.T) {
1289+
// Initialize lockdown cache once for this test
1290+
gqlClient:=githubv4.NewClient(nil)
1291+
lockdown.ResetInstance()
1292+
lockdown.GetInstance(gqlClient,lockdown.WithTTL(5*time.Minute))
1293+
12781294
// Verify tool definition once
12791295
mockClient:=github.NewClient(nil)
1280-
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(githubv4.NewClient(nil),5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
1296+
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(gqlClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
12811297
require.NoError(t,toolsnaps.Test(tool.Name,tool))
12821298

12831299
assert.Equal(t,"pull_request_read",tool.Name)
@@ -1564,9 +1580,14 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
15641580
}
15651581

15661582
funcTest_GetPullRequestComments(t*testing.T) {
1583+
// Initialize lockdown cache once for this test
1584+
gqlClient:=githubv4.NewClient(nil)
1585+
lockdown.ResetInstance()
1586+
lockdown.GetInstance(gqlClient,lockdown.WithTTL(5*time.Minute))
1587+
15671588
// Verify tool definition once
15681589
mockClient:=github.NewClient(nil)
1569-
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(githubv4.NewClient(nil),5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
1590+
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(gqlClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
15701591
require.NoError(t,toolsnaps.Test(tool.Name,tool))
15711592

15721593
assert.Equal(t,"pull_request_read",tool.Name)
@@ -1698,9 +1719,14 @@ func Test_GetPullRequestComments(t *testing.T) {
16981719
}
16991720

17001721
funcTest_GetPullRequestReviews(t*testing.T) {
1722+
// Initialize lockdown cache once for this test
1723+
gqlClient:=githubv4.NewClient(nil)
1724+
lockdown.ResetInstance()
1725+
lockdown.GetInstance(gqlClient,lockdown.WithTTL(5*time.Minute))
1726+
17011727
// Verify tool definition once
17021728
mockClient:=github.NewClient(nil)
1703-
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(githubv4.NewClient(nil),5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
1729+
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(gqlClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
17041730
require.NoError(t,toolsnaps.Test(tool.Name,tool))
17051731

17061732
assert.Equal(t,"pull_request_read",tool.Name)
@@ -2787,9 +2813,14 @@ func TestDeletePendingPullRequestReview(t *testing.T) {
27872813
funcTestGetPullRequestDiff(t*testing.T) {
27882814
t.Parallel()
27892815

2816+
// Initialize lockdown cache once for this test
2817+
gqlClient:=githubv4.NewClient(nil)
2818+
lockdown.ResetInstance()
2819+
lockdown.GetInstance(gqlClient,lockdown.WithTTL(5*time.Minute))
2820+
27902821
// Verify tool definition once
27912822
mockClient:=github.NewClient(nil)
2792-
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(githubv4.NewClient(nil),5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
2823+
tool,_:=PullRequestRead(stubGetClientFn(mockClient),stubRepoAccessCache(gqlClient,5*time.Minute),translations.NullTranslationHelper,stubFeatureFlags(map[string]bool{"lockdown-mode":false}))
27932824
require.NoError(t,toolsnaps.Test(tool.Name,tool))
27942825

27952826
assert.Equal(t,"pull_request_read",tool.Name)

‎pkg/github/server_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ func stubGetGQLClientFn(client *githubv4.Client) GetGQLClientFn {
4141
}
4242

4343
funcstubRepoAccessCache(client*githubv4.Client,ttl time.Duration)*lockdown.RepoAccessCache {
44+
// Return the singleton instance that was initialized in TestMain
45+
// The client and ttl parameters are ignored since the instance is already created
4446
returnlockdown.GetInstance(client,lockdown.WithTTL(ttl))
4547
}
4648

‎pkg/lockdown/lockdown.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ func GetInstance(client *githubv4.Client, opts ...RepoAccessOption) *RepoAccessC
6363
returninstance
6464
}
6565

66+
// ResetInstance resets the singleton instance of RepoAccessCache.
67+
// This function is intended for testing purposes only and should not be used in production code.
68+
funcResetInstance() {
69+
instance=nil
70+
instanceOnce= sync.Once{}
71+
}
72+
6673
// newRepoAccessCache creates a new cache instance. This is a private helper function
6774
// used by GetInstance.
6875
funcnewRepoAccessCache(client*githubv4.Client,opts...RepoAccessOption)*RepoAccessCache {

‎pkg/lockdown/lockdown_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func TestRepoAccessCacheEvictsAfterTTL(t *testing.T) {
9090
t.Parallel()
9191
ctx:=t.Context()
9292

93+
// Reset singleton before test
94+
ResetInstance()
95+
deferResetInstance()
96+
9397
cache,transport:=newMockRepoAccessCache(t,5*time.Millisecond)
9498
_,_,err:=cache.GetRepoAccessInfo(ctx,testUser,testOwner,testRepo)
9599
require.NoError(t,err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp