internal/jsonrpc2_v2,mcp: remove unneeded dependencies

Remove dependencies on the eventtest and testenv packages from
jsonrpc2_v2 and mcp packages, in preparation for forking.

Change-Id: Id0efb0c3187629f6fb1822cc853ec52acea41b0d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/682696
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Rob Findley 2025-06-19 00:29:02 +00:00 • committed by Gopher Robot
commit 8bc9a9a9f5

View file

@ -8,18 +8,26 @@ import (
"context"
"errors"
"fmt"
"runtime"
"runtime/debug"
"testing"
"time"
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
"golang.org/x/tools/internal/stack/stacktest"
"golang.org/x/tools/internal/testenv"
)
// needsLocalhostNet skips t if networking does not work for ports opened
// with "localhost".
// forked from golang.org/x/tools/internal/testenv.
func needsLocalhostNet(t testing.TB) {
switch runtime.GOOS {
case "js", "wasip1":
t.Skipf(`Listening on "localhost" fails on %s; see https://go.dev/issue/59718`, runtime.GOOS)
}
}
func TestIdleTimeout(t *testing.T) {
testenv.NeedsLocalhostNet(t)
stacktest.NoLeak(t)
needsLocalhostNet(t)
// Use a panicking time.AfterFunc instead of context.WithTimeout so that we
// get a goroutine dump on failure. We expect the test to take on the order of
@ -158,7 +166,6 @@ func (fakeHandler) Handle(ctx context.Context, req *jsonrpc2.Request) (any, erro
}
func TestServe(t *testing.T) {
stacktest.NoLeak(t)
ctx := context.Background()
tests := []struct {
@ -166,7 +173,7 @@ func TestServe(t *testing.T) {
factory func(context.Context, testing.TB) (jsonrpc2.Listener, error)
}{
{"tcp", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {
testenv.NeedsLocalhostNet(t)
needsLocalhostNet(t)
return jsonrpc2.NetListener(ctx, "tcp", "localhost:0", jsonrpc2.NetListenOptions{})
}},
{"pipe", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {