Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
sdk/js: address review on the stdio server tests
Mrunal Pendem2809e8be05f0
diff --git a/sdk/js/src/mcp-server.test.ts b/sdk/js/src/mcp-server.test.tsindex f4dbee73..e3f5414c 100644--- a/sdk/js/src/mcp-server.test.ts+++ b/sdk/js/src/mcp-server.test.ts@@ -19,6 +19,7 @@ import { createServer } from "node:http";import { mkdtemp, writeFile, rm } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";+import { fileURLToPath } from "node:url";import { spawn } from "node:child_process";import { peerIdFromString } from "@libp2p/peer-id";import { Client } from "@modelcontextprotocol/sdk/client/index.js";@@ -181,7 +182,7 @@ test("CLI configuration failures and help write no non-MCP stdout", async () =>for (const args of [[], ["--help"], ["--token", "must-not-appear"]]) {const env = { ...process.env };for (const key of Object.keys(env)) if (key.startsWith("AGENTMESH_")) delete env[key];- const child = spawn(process.execPath, [new URL("./cli.js", import.meta.url).pathname, ...args], { env });+ const child = spawn(process.execPath, [fileURLToPath(new URL("./cli.js", import.meta.url)), ...args], { env });let stdout = "", stderr = "";child.stdout.on("data", (data) => { stdout += String(data); });child.stderr.on("data", (data) => { stderr += String(data); });@@ -200,7 +201,7 @@ test("CLI rejects relative credential and identity paths", async () => {const env: NodeJS.ProcessEnv = { ...process.env };for (const key of Object.keys(env)) if (key.startsWith("AGENTMESH_")) delete env[key];Object.assign(env, { AGENTMESH_CONTROL_PLANE_URL: "http://127.0.0.1:9", [name]: "relative/path" });- const child = spawn(process.execPath, [new URL("./cli.js", import.meta.url).pathname], { env });+ const child = spawn(process.execPath, [fileURLToPath(new URL("./cli.js", import.meta.url))], { env });let stdout = "", stderr = "";child.stdout.on("data", (data) => { stdout += String(data); });child.stderr.on("data", (data) => { stderr += String(data); });@@ -268,7 +269,7 @@ test("EOF and SIGTERM abort enrollment without leaving a process running", { timAGENTMESH_CONTROL_PLANE_URL: `http://127.0.0.1:${address.port}`,AGENTMESH_STATE_DIR: join(directory, stop), AGENTMESH_BOOTSTRAP_TOKEN_PATH: token,});- const child = spawn(process.execPath, [new URL("./cli.js", import.meta.url).pathname], { env });+ const child = spawn(process.execPath, [fileURLToPath(new URL("./cli.js", import.meta.url))], { env });t.after(() => { if (child.exitCode === null) child.kill("SIGKILL"); });let stdout = "", stderr = "";child.stdout.on("data", (data) => { stdout += String(data); });diff --git a/tests/integration/sdk_mcp_stdio_test.go b/tests/integration/sdk_mcp_stdio_test.goindex 10f8881c..5ca57f5a 100644--- a/tests/integration/sdk_mcp_stdio_test.go+++ b/tests/integration/sdk_mcp_stdio_test.go@@ -175,8 +175,11 @@ func TestNativeSDKMCPStdio(t *testing.T) {t.Fatalf("restart changed identity: %s -> %s", firstPeer, details.PeerID)}tools, err := session.ListTools(ctx, nil)- if err != nil || len(tools.Tools) != 5 {- t.Fatalf("tools/list: %v, want five tools", err)+ if err != nil {+ t.Fatalf("tools/list: %v", err)+ }+ if got, want := len(tools.Tools), 5; got != want {+ t.Fatalf("tools/list: got %d tools, want %d", got, want)}for _, tool := range tools.Tools {if got, want := contract(tool.InputSchema), contracts[tool.Name]; !reflect.DeepEqual(got, want) {@@ -187,13 +190,13 @@ func TestNativeSDKMCPStdio(t *testing.T) {invoke("describe_remote_tool", map[string]any{"peer_id": peer, "tool_name": "mcp://calc/add"}, false)result := invoke("call_remote_tool", map[string]any{"peer_id": peer, "tool_name": "mcp://calc/add", "arguments": map[string]any{"a": 1, "b": 2}}, false)if text, ok := result.Content[0].(*mcp.TextContent); !ok || text.Text != "3" {- t.Fatalf("unexpected tool result: %v", result.Content)+ t.Fatalf("unexpected tool result: got %v, want text content %q", result.Content, "3")}before := calls.Load()invoke("call_remote_tool", map[string]any{"peer_id": peer, "tool_name": "mcp://denied/add"}, true)invoke("call_remote_tool", map[string]any{"peer_id": peer, "tool_name": "mcp://calc/add", "required_labels": "region=unattested"}, true)- if calls.Load() != before {- t.Fatal("a refused call reached the backend")+ if got, want := calls.Load(), before; got != want {+ t.Fatalf("a refused call reached the backend: got %d backend calls, want %d", got, want)}found := invoke("find_remote_tools", map[string]any{}, false)var rows []struct {