Skip to content

Commit f8b41fe

Browse files
jbooleanclaude
andcommitted
test(contrib/modelcontextprotocol/go-sdk): fix data race in intent capture predicate test
Race detector caught `enabled` being written by the test goroutine and read by the server's callback goroutine. Switched to atomic.Bool. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent b5190ee commit f8b41fe

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

contrib/modelcontextprotocol/go-sdk/intent_capture_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package gosdk
88
import (
99
"context"
1010
"encoding/json"
11+
"sync/atomic"
1112
"testing"
1213

1314
"github.com/google/jsonschema-go/jsonschema"
@@ -26,10 +27,10 @@ func TestIntentCapturePredicate(t *testing.T) {
2627
defer tt.Stop()
2728
ctx := context.Background()
2829

29-
var enabled bool
30+
var enabled atomic.Bool
3031
server := mcp.NewServer(&mcp.Implementation{Name: "test-server", Version: "1.0.0"}, nil)
3132
AddTracing(server, WithIntentCapturePredicate(func(context.Context) bool {
32-
return enabled
33+
return enabled.Load()
3334
}))
3435

3536
var receivedArgs map[string]any
@@ -52,7 +53,7 @@ func TestIntentCapturePredicate(t *testing.T) {
5253
defer clientSession.Close()
5354

5455
// Predicate false: schema not injected, telemetry argument passed through.
55-
enabled = false
56+
enabled.Store(false)
5657
listResult, err := clientSession.ListTools(ctx, &mcp.ListToolsParams{})
5758
require.NoError(t, err)
5859
require.Len(t, listResult.Tools, 1)
@@ -70,7 +71,7 @@ func TestIntentCapturePredicate(t *testing.T) {
7071
assert.Contains(t, receivedArgs, "telemetry", "telemetry should pass through when predicate is false")
7172

7273
// Predicate true: schema injected, telemetry stripped.
73-
enabled = true
74+
enabled.Store(true)
7475
listResult, err = clientSession.ListTools(ctx, &mcp.ListToolsParams{})
7576
require.NoError(t, err)
7677
schema, ok := listResult.Tools[0].InputSchema.(map[string]any)

0 commit comments

Comments
 (0)