Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ linters:
- ineffassign
- intrange
- unused
- usetesting
exclusions:
generated: lax
presets:
Expand All @@ -40,6 +41,14 @@ linters:
- "all"
- -QF1008
- -ST1000
usetesting:
context-background: true
context-todo: true
os-chdir: true
os-mkdir-temp: true
os-setenv: true
os-create-temp: true
os-temp-dir: true
formatters:
exclusions:
generated: lax
Expand Down
7 changes: 2 additions & 5 deletions internal/toolsnaps/toolsnaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ type dummyTool struct {

// withIsolatedWorkingDir creates a temp dir, changes to it, and restores the original working dir after the test.
func withIsolatedWorkingDir(t *testing.T) {
dir := t.TempDir()
origDir, err := os.Getwd()
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, os.Chdir(origDir)) })
require.NoError(t, os.Chdir(dir))
t.Helper()
t.Chdir(t.TempDir())
}

func TestSnapshotDoesNotExistNotInCI(t *testing.T) {
Expand Down
24 changes: 12 additions & 12 deletions pkg/errors/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestGitHubErrorContext(t *testing.T) {
t.Run("API errors can be added to context and retrieved", func(t *testing.T) {
// Given a context with GitHub error tracking enabled
ctx := ContextWithGitHubErrors(context.Background())
ctx := ContextWithGitHubErrors(t.Context())

// Create a mock GitHub response
resp := &github.Response{
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestGitHubErrorContext(t *testing.T) {

t.Run("GraphQL errors can be added to context and retrieved", func(t *testing.T) {
// Given a context with GitHub error tracking enabled
ctx := ContextWithGitHubErrors(context.Background())
ctx := ContextWithGitHubErrors(t.Context())

originalErr := fmt.Errorf("GraphQL query failed")

Expand All @@ -65,7 +65,7 @@ func TestGitHubErrorContext(t *testing.T) {

t.Run("Raw API errors can be added to context and retrieved", func(t *testing.T) {
// Given a context with GitHub error tracking enabled
ctx := ContextWithGitHubErrors(context.Background())
ctx := ContextWithGitHubErrors(t.Context())

// Create a mock HTTP response
resp := &http.Response{
Expand All @@ -92,7 +92,7 @@ func TestGitHubErrorContext(t *testing.T) {

t.Run("multiple errors can be accumulated in context", func(t *testing.T) {
// Given a context with GitHub error tracking enabled
ctx := ContextWithGitHubErrors(context.Background())
ctx := ContextWithGitHubErrors(t.Context())

// When we add multiple API errors
resp1 := &github.Response{Response: &http.Response{StatusCode: 404}}
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestGitHubErrorContext(t *testing.T) {
// is shared, allowing middleware to inspect errors that were added later.

// Given a context with GitHub error tracking enabled
originalCtx := ContextWithGitHubErrors(context.Background())
originalCtx := ContextWithGitHubErrors(t.Context())

// Simulate a middleware that captures the context early
var middlewareCtx context.Context
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestGitHubErrorContext(t *testing.T) {

t.Run("context without GitHub errors returns error", func(t *testing.T) {
// Given a regular context without GitHub error tracking
ctx := context.Background()
ctx := t.Context()

// When we try to retrieve errors
apiErrors, err := GetGitHubAPIErrors(ctx)
Expand All @@ -207,7 +207,7 @@ func TestGitHubErrorContext(t *testing.T) {

t.Run("ContextWithGitHubErrors resets existing errors", func(t *testing.T) {
// Given a context with existing errors
ctx := ContextWithGitHubErrors(context.Background())
ctx := ContextWithGitHubErrors(t.Context())
resp := &github.Response{Response: &http.Response{StatusCode: 404}}
ctx, err := NewGitHubAPIErrorToCtx(ctx, "existing error", resp, fmt.Errorf("error"))
require.NoError(t, err)
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestGitHubErrorContext(t *testing.T) {

t.Run("NewGitHubAPIErrorResponse creates MCP error result and stores context error", func(t *testing.T) {
// Given a context with GitHub error tracking enabled
ctx := ContextWithGitHubErrors(context.Background())
ctx := ContextWithGitHubErrors(t.Context())

resp := &github.Response{Response: &http.Response{StatusCode: 422}}
originalErr := fmt.Errorf("validation failed")
Expand All @@ -266,7 +266,7 @@ func TestGitHubErrorContext(t *testing.T) {

t.Run("NewGitHubGraphQLErrorResponse creates MCP error result and stores context error", func(t *testing.T) {
// Given a context with GitHub error tracking enabled
ctx := ContextWithGitHubErrors(context.Background())
ctx := ContextWithGitHubErrors(t.Context())

originalErr := fmt.Errorf("mutation failed")

Expand All @@ -289,7 +289,7 @@ func TestGitHubErrorContext(t *testing.T) {

t.Run("NewGitHubAPIStatusErrorResponse creates MCP error result from status code", func(t *testing.T) {
// Given a context with GitHub error tracking enabled
ctx := ContextWithGitHubErrors(context.Background())
ctx := ContextWithGitHubErrors(t.Context())

resp := &github.Response{Response: &http.Response{StatusCode: 422}}
body := []byte(`{"message": "Validation Failed"}`)
Expand All @@ -316,7 +316,7 @@ func TestGitHubErrorContext(t *testing.T) {

t.Run("NewGitHubAPIErrorToCtx with uninitialized context does not error", func(t *testing.T) {
// Given a regular context without GitHub error tracking initialized
ctx := context.Background()
ctx := t.Context()

// Create a mock GitHub response
resp := &github.Response{
Expand Down Expand Up @@ -392,7 +392,7 @@ func TestMiddlewareScenario(t *testing.T) {
// Simulate a realistic HTTP middleware scenario

// 1. Request comes in, middleware sets up error tracking
ctx := ContextWithGitHubErrors(context.Background())
ctx := ContextWithGitHubErrors(t.Context())

// 2. Middleware stores reference to context for later inspection
var middlewareCtx context.Context
Expand Down
25 changes: 12 additions & 13 deletions pkg/github/actions_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package github

import (
"context"
"encoding/json"
"net/http"
"testing"
Expand Down Expand Up @@ -93,7 +92,7 @@ func Test_ActionsList_ListWorkflows(t *testing.T) {
handler := toolDef.Handler(deps)

request := createMCPRequest(tc.requestArgs)
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.Equal(t, tc.expectError, result.IsError)
Expand Down Expand Up @@ -148,7 +147,7 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
"repo": "repo",
"resource_id": "ci.yml",
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.False(t, result.IsError)
Expand Down Expand Up @@ -196,7 +195,7 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
"owner": "owner",
"repo": "repo",
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.False(t, result.IsError)
Expand Down Expand Up @@ -253,7 +252,7 @@ func Test_ActionsGet_GetWorkflow(t *testing.T) {
"repo": "repo",
"resource_id": "ci.yml",
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.False(t, result.IsError)
Expand Down Expand Up @@ -296,7 +295,7 @@ func Test_ActionsGet_GetWorkflowRun(t *testing.T) {
"repo": "repo",
"resource_id": "12345",
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.False(t, result.IsError)
Expand Down Expand Up @@ -388,7 +387,7 @@ func Test_ActionsRunTrigger_RunWorkflow(t *testing.T) {
handler := toolDef.Handler(deps)

request := createMCPRequest(tc.requestArgs)
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.Equal(t, tc.expectError, result.IsError)
Expand Down Expand Up @@ -430,7 +429,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
"repo": "repo",
"run_id": float64(12345),
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.False(t, result.IsError)
Expand Down Expand Up @@ -461,7 +460,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
"repo": "repo",
"run_id": float64(12345),
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.True(t, result.IsError)
Expand All @@ -484,7 +483,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
"owner": "owner",
"repo": "repo",
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.True(t, result.IsError)
Expand Down Expand Up @@ -537,7 +536,7 @@ func Test_ActionsGetJobLogs_SingleJob(t *testing.T) {
"repo": "repo",
"job_id": float64(123),
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.False(t, result.IsError)
Expand Down Expand Up @@ -600,7 +599,7 @@ func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
"run_id": float64(456),
"failed_only": true,
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.False(t, result.IsError)
Expand Down Expand Up @@ -650,7 +649,7 @@ func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
"run_id": float64(456),
"failed_only": true,
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

require.NoError(t, err)
require.False(t, result.IsError)
Expand Down
5 changes: 2 additions & 3 deletions pkg/github/code_scanning_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package github

import (
"context"
"encoding/json"
"net/http"
"testing"
Expand Down Expand Up @@ -90,7 +89,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
request := createMCPRequest(tc.requestArgs)

// Call handler with new signature
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

// Verify results
if tc.expectError {
Expand Down Expand Up @@ -216,7 +215,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
request := createMCPRequest(tc.requestArgs)

// Call handler with new signature
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

// Verify results
if tc.expectError {
Expand Down
7 changes: 3 additions & 4 deletions pkg/github/context_tools_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package github

import (
"context"
"encoding/json"
"net/http"
"testing"
Expand Down Expand Up @@ -103,7 +102,7 @@ func Test_GetMe(t *testing.T) {
handler := serverTool.Handler(deps)

request := createMCPRequest(tc.requestArgs)
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)
require.NoError(t, err)

if tc.expectToolError {
Expand Down Expand Up @@ -341,7 +340,7 @@ func Test_GetTeams(t *testing.T) {
handler := serverTool.Handler(deps)

request := createMCPRequest(tc.requestArgs)
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)
require.NoError(t, err)

if tc.expectToolError {
Expand Down Expand Up @@ -484,7 +483,7 @@ func Test_GetTeamMembers(t *testing.T) {
handler := serverTool.Handler(tc.deps)

request := createMCPRequest(tc.requestArgs)
result, err := handler(ContextWithDeps(context.Background(), tc.deps), &request)
result, err := handler(ContextWithDeps(t.Context(), tc.deps), &request)
require.NoError(t, err)

if tc.expectToolError {
Expand Down
6 changes: 2 additions & 4 deletions pkg/github/copilot_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package github

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -698,7 +697,6 @@ func TestAssignCopilotToIssue(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {

t.Parallel()
// Setup client with mock
client := githubv4.NewClient(tc.mockedClient)
Expand All @@ -711,7 +709,7 @@ func TestAssignCopilotToIssue(t *testing.T) {
request := createMCPRequest(tc.requestArgs)

// Disable polling in tests to avoid timeouts
ctx := ContextWithPollConfig(context.Background(), PollConfig{MaxAttempts: 0})
ctx := ContextWithPollConfig(t.Context(), PollConfig{MaxAttempts: 0})
ctx = ContextWithDeps(ctx, deps)

// Call handler
Expand Down Expand Up @@ -832,7 +830,7 @@ func Test_RequestCopilotReview(t *testing.T) {

request := createMCPRequest(tc.requestArgs)

result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

if tc.expectError {
require.NoError(t, err)
Expand Down
5 changes: 2 additions & 3 deletions pkg/github/dependabot_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package github

import (
"context"
"encoding/json"
"net/http"
"testing"
Expand Down Expand Up @@ -81,7 +80,7 @@ func Test_GetDependabotAlert(t *testing.T) {
request := createMCPRequest(tc.requestArgs)

// Call handler
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

// Verify results
if tc.expectError {
Expand Down Expand Up @@ -218,7 +217,7 @@ func Test_ListDependabotAlerts(t *testing.T) {

request := createMCPRequest(tc.requestArgs)

result, err := handler(ContextWithDeps(context.Background(), deps), &request)
result, err := handler(ContextWithDeps(t.Context(), deps), &request)

if tc.expectError {
require.NoError(t, err)
Expand Down
Loading
Loading