Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
test: implement bidirectional MCP tool execution validation in mobile E2E tests and pin runner to ubuntu-22.04
Antonio Ojeac6d955ce8055
diff --git a/.github/workflows/test_flutter.yaml b/.github/workflows/test_flutter.yamlindex 32d485b6..0ea9c0e0 100644--- a/.github/workflows/test_flutter.yaml+++ b/.github/workflows/test_flutter.yaml@@ -51,7 +51,7 @@ jobs:working-directory: mobile/sam-node-appe2e-android:- runs-on: ubuntu-latest+ runs-on: ubuntu-22.04steps:- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6- uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6diff --git a/mobile/mobile_e2e.sh b/mobile/mobile_e2e.shindex c92cd43b..d6ac6fa6 100755--- a/mobile/mobile_e2e.sh+++ b/mobile/mobile_e2e.sh@@ -23,11 +23,13 @@ cd "$REPO_ROOT"NODE_PID=""HUB_PID=""OIDC_PID=""+HOST_MOCK_PID=""cleanup() {echo "[E2E] Cleaning up background processes..."if [ -n "$NODE_PID" ]; then kill "$NODE_PID" || true; fiif [ -n "$HUB_PID" ]; then kill "$HUB_PID" || true; fiif [ -n "$OIDC_PID" ]; then kill "$OIDC_PID" || true; fi+ if [ -n "$HOST_MOCK_PID" ]; then kill "$HOST_MOCK_PID" || true; firm -rf /tmp/host-node-data}trap cleanup EXIT@@ -84,11 +86,33 @@ NODE_PID=$!# Wait for external node to be readytimeout 15s bash -c 'until curl -s -X POST -H "Authorization: Bearer host-token" -d "{\"jsonrpc\":\"2.0\",\"method\":\"ping\",\"id\":1}" http://127.0.0.1:8081/mcp >/dev/null; do sleep 0.5; done'-# Register a dummy MCP service on the host node+# Start a local Mock MCP Server on host at port 9091+python3 -c '+from http.server import HTTPServer, BaseHTTPRequestHandler+import json+class S(BaseHTTPRequestHandler):+ def do_POST(self):+ self.send_response(200)+ self.send_header("Content-Type", "application/json")+ self.end_headers()+ self.wfile.write(json.dumps({+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {"type": "text", "text": "Hello from Host!"}+ ]+ }+ }).encode("utf-8"))+HTTPServer(("127.0.0.1", 9091), S).serve_forever()+' &+HOST_MOCK_PID=$!++# Register a dummy MCP service on the host node pointing to the local mock servercurl -s -X POST \-H "Content-Type: application/json" \-H "Authorization: Bearer host-token" \- -d '{"service":{"type":"SERVICE_TYPE_MCP","name":"host-tool","description":"test tool on host"},"targetUrl":"http://127.0.0.1:8081"}' \+ -d '{"service":{"type":"SERVICE_TYPE_MCP","name":"host-tool","description":"test tool on host"},"targetUrl":"http://127.0.0.1:9091"}' \http://127.0.0.1:8081/sam/service/register# 7. Start the Android Emulator and run the Flutter integration test@@ -115,13 +139,38 @@ for i in {1..45}; dosleep 1done+# 9. Call emulator-tool from the host node to verify end-to-end communication+CALLED=0+if [ "$DISCOVERED" -eq 1 ]; then+ echo "[E2E] Calling emulator-tool from host node..."+ CALL_RESULT=$("$REPO_ROOT/bin/mcp-client" -url http://127.0.0.1:8081/mcp -tool emulator-tool 2>/dev/null || true)+ echo "[E2E] Call result: $CALL_RESULT"+ if echo "$CALL_RESULT" | grep -q "Hello from Android!"; then+ echo "[E2E] Host successfully executed emulator-tool!"+ CALLED=1+ else+ echo "[E2E] FAILED: Host failed to execute emulator-tool"+ fi+fi+# Wait for integration test execution to finalizewait $TEST_PID+TEST_EXIT_STATUS=$?if [ "$DISCOVERED" -ne 1 ]; thenecho "[E2E] FAILED: Host failed to discover emulator-tool"exit 1fi+if [ "$CALLED" -ne 1 ]; then+ echo "[E2E] FAILED: Host failed to execute emulator-tool"+ exit 1+fi++if [ "$TEST_EXIT_STATUS" -ne 0 ]; then+ echo "[E2E] FAILED: Emulator integration test failed with exit code $TEST_EXIT_STATUS"+ exit 1+fi+echo "[E2E] SUCCESS: Bidirectional mobile E2E test passed!"exit 0diff --git a/mobile/sam-node-app/integration_test/e2e_test.dart b/mobile/sam-node-app/integration_test/e2e_test.dartindex f4fa1a5d..808aa174 100644--- a/mobile/sam-node-app/integration_test/e2e_test.dart+++ b/mobile/sam-node-app/integration_test/e2e_test.dart@@ -66,6 +66,27 @@ void main() {expect(nodeID, isNotEmpty);expect(nodeID, isNot('unauthenticated'));+ // Start local Mock MCP Server inside the Android emulator+ final mockMcpServer = await HttpServer.bind(InternetAddress.loopbackIPv4, 9090);+ mockMcpServer.listen((HttpRequest request) {+ request.response+ ..headers.contentType = ContentType.json+ ..statusCode = HttpStatus.ok+ ..write(jsonEncode({+ 'jsonrpc': '2.0',+ 'id': 1,+ 'result': {+ 'content': [+ {+ 'type': 'text',+ 'text': 'Hello from Android!'+ }+ ]+ }+ }));+ request.response.close();+ });+// Register a dummy MCP service inside the Android emulatorfinal registerUrl = 'http://127.0.0.1:8080/sam/service/register';final regResponse = await http.post(@@ -80,7 +101,7 @@ void main() {'name': 'emulator-tool','description': 'test tool inside emulator'},- 'targetUrl': 'http://127.0.0.1:8080' // dummy loopback inside emulator+ 'targetUrl': 'http://127.0.0.1:9090' // point to local Dart mock server}),);expect(regResponse.statusCode, equals(200));@@ -121,10 +142,50 @@ void main() {}expect(discovered, isTrue, reason: 'Emulator failed to discover host-tool');+ // Call host-tool from inside the emulator via its local MCP API+ final callToolUrl = 'http://127.0.0.1:8080/mcp';+ var called = false;+ for (var i = 0; i < 10; i++) {+ try {+ final callResponse = await http.post(+ Uri.parse(callToolUrl),+ headers: {+ 'Content-Type': 'application/json',+ 'Authorization': 'Bearer test-token',+ },+ body: jsonEncode({+ 'jsonrpc': '2.0',+ 'method': 'tools/call',+ 'params': {+ 'name': 'host-tool',+ 'arguments': {}+ },+ 'id': 1+ }),+ );+ if (callResponse.statusCode == 200) {+ final callData = jsonDecode(callResponse.body);+ final result = callData['result'];+ if (result != null && result['content'] != null) {+ final content = result['content'] as List;+ if (content.any((c) => c['text'].contains('Hello from Host!'))) {+ called = true;+ break;+ }+ }+ }+ } catch (e) {+ // ignore network setup transient errors+ }+ await Future.delayed(const Duration(seconds: 1));+ }+ expect(called, isTrue, reason: 'Emulator failed to execute host-tool');+// Wait some time to let the host verify connection and discover emulator-tool- await Future.delayed(const Duration(seconds: 5));+ await Future.delayed(const Duration(seconds: 10));// Cleanup & Stop+ await mockMcpServer.close();final stopErr = samLib.stop();expect(stopErr, isNull);});