Skip to content

Remove test that can panic #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025

Conversation

williammartin
Copy link
Collaborator

@williammartin williammartin commented May 27, 2025

Description

This PR removes a test that was both trying to simulate an error that can't happen, and causing bizarre failures elsewhere. For example, when another test failed (simulated with a t.FailNow in Test_GetMe, it would also get this panic:

➜  github-mcp-server git:(main) go test -count=1 ./pkg/github
--- FAIL: Test_GetMe (0.00s)
2025/05/27 19:50:15 http: panic serving 127.0.0.1:62114: go-github-mock: no more mocks available for /repos/owner/repo/contents/src
goroutine 629 [running]:
net/http.(*conn).serve.func1()
        /opt/homebrew/opt/go/libexec/src/net/http/server.go:1947 +0xb0
panic({0x104ec20c0?, 0x14000c0a030?})
        /opt/homebrew/opt/go/libexec/src/runtime/panic.go:792 +0x124
github.com/migueleliasweb/go-github-mock/src/mock.(*FIFOResponseHandler).ServeHTTP(0x14000c16140?, {0x104fb8fb0?, 0x140008c4a80?}, 0x0?)
        /Users/williammartin/go/pkg/mod/github.com/migueleliasweb/go-github-mock@v1.3.0/src/mock/server.go:41 +0x1b8
github.com/gorilla/mux.(*Router).ServeHTTP(0x14000147140, {0x104fb8fb0, 0x140008c4a80}, 0x14000c16000)
        /Users/williammartin/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x194
net/http.serverHandler.ServeHTTP({0x14000c020f0?}, {0x104fb8fb0?, 0x140008c4a80?}, 0x1?)
        /opt/homebrew/opt/go/libexec/src/net/http/server.go:3301 +0xbc
net/http.(*conn).serve(0x1400071c480, {0x104fb9390, 0x140006d8510})
        /opt/homebrew/opt/go/libexec/src/net/http/server.go:2102 +0x52c
created by net/http.(*Server).Serve in goroutine 956
        /opt/homebrew/opt/go/libexec/src/net/http/server.go:3454 +0x3d8
FAIL
FAIL    github.com/github/github-mcp-server/pkg/github  0.306s
FAIL

This is because:

			mockedClient: mock.NewMockedHTTPClient(
				mock.WithRequestMatch(
					mock.GetReposContentsByOwnerByRepoByPath,
				),
			),

Was registering a handler with no responses which would then panic here when a request came in: https://github.com/migueleliasweb/go-github-mock/blob/dd6b28752862d0748bf5cee28fc1d69b0475eb3f/src/mock/server.go#L40-L45

Unfortunately, this panic would never bubble up a test failure in this test, but presumably because it was in a goroutine, would asynchronously result in strange failures in other places. Haven't totally dug into why because it's not that important beyond fixing it.

@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 18:06
@williammartin williammartin requested a review from a team as a code owner May 27, 2025 18:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

SamMorrowDrums
SamMorrowDrums previously approved these changes May 27, 2025
"path": []string{"src"},
},
expectedResult: nil,
expectError: "no repository resource content found",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this expectError field is never actually used because all the tests set expectedErrorMsg.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@williammartin williammartin merged commit 7e026fc into main May 27, 2025
16 checks passed
@williammartin williammartin deleted the wm/fix-non-isolated-repository-resource-tests branch May 27, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants