From 92a0c702cf96523df619e59941ff819e75a061fd Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Wed, 28 May 2025 16:56:55 -0400 Subject: [PATCH] internal/mcp: run conformance tests on 1.24 with a GOEXPERIMENT setting Support the conformance tests on 1.24, if the user has set GOEXPERIMENT=synctest The API is different, but other than that it works fine. Change-Id: I08ffbe094b39a73cd1fc26e7dcf6f22158b2df1d Reviewed-on: https://go-review.googlesource.com/c/tools/+/677015 LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Findley --- mcp/conformance_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mcp/conformance_test.go b/mcp/conformance_test.go index b2e4146..1f8c22a 100644 --- a/mcp/conformance_test.go +++ b/mcp/conformance_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -//go:build go1.25 +//go:build go1.24 && goexperiment.synctest package mcp @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2" + "golang.org/x/tools/internal/testenv" "golang.org/x/tools/txtar" ) @@ -58,6 +59,7 @@ type conformanceTest struct { // TODO(rfindley): add client conformance tests. func TestServerConformance(t *testing.T) { + testenv.NeedsGoExperiment(t, "synctest") var tests []*conformanceTest dir := filepath.Join("testdata", "conformance", "server") if err := filepath.WalkDir(dir, func(path string, _ fs.DirEntry, err error) error { @@ -86,9 +88,12 @@ func TestServerConformance(t *testing.T) { // By comparison, gopls has a complicated framework based on progress // reporting and careful accounting to detect when all 'expected' work // on the server is complete. - synctest.Test(t, func(t *testing.T) { - runServerTest(t, test) - }) + synctest.Run(func() { runServerTest(t, test) }) + + // TODO: in 1.25, use the following instead: + // synctest.Test(t, func(t *testing.T) { + // runServerTest(t, test) + // }) }) } } @@ -186,7 +191,7 @@ func runServerTest(t *testing.T, test *conformanceTest) { if !seenServer { arch.Files = append(arch.Files, serverFile) } - if err := os.WriteFile(test.path, txtar.Format(arch), 0666); err != nil { + if err := os.WriteFile(test.path, txtar.Format(arch), 0o666); err != nil { t.Fatalf("os.WriteFile(%q) failed: %v", test.path, err) } } else {