Skip to content

Agent Mesh

mobile: implement Dart-based McpClient, fix OIDC & mock MCP servers and add Android wrapper scaffolding

Antonio Ojeaa5da424c94e6
diff --git a/.gitignore b/.gitignore
index e1bc71e2..be801a20 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,3 +38,6 @@ tests/integration/scratch/
__pycache__/
.venv/
*.egg-info/
+keys.db
+mobile/logcat.txt
+
diff --git a/internal/node/store.go b/internal/node/store.go
index 0da700e1..e6e2cec9 100644
--- a/internal/node/store.go
+++ b/internal/node/store.go
@@ -55,6 +55,9 @@ func GetDefaultDataDir() (string, error) {
}
func NewStore(dir string) (*Store, error) {
+ if err := os.MkdirAll(dir, 0700); err != nil {
+ return nil, fmt.Errorf("failed to create data directory: %w", err)
+ }
dbPath := filepath.Join(dir, "agent.db")
db, err := bbolt.Open(dbPath, 0600, &bbolt.Options{Timeout: 5 * time.Second})
if err != nil {
diff --git a/mobile/mobile_e2e.sh b/mobile/mobile_e2e.sh
index 1cfbbdb7..c78fdfa2 100755
--- a/mobile/mobile_e2e.sh
+++ b/mobile/mobile_e2e.sh
@@ -19,101 +19,157 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
REPO_ROOT=$(cd "$SCRIPT_DIR/.." &> /dev/null && pwd)
cd "$REPO_ROOT"
-# Helper to kill background processes on exit
-NODE_PID=""
-HUB_PID=""
-OIDC_PID=""
-HOST_MOCK_PID=""
+# Helper to kill background processes and docker containers on exit
cleanup() {
- echo "[E2E] Cleaning up background processes..."
- if [ -n "$NODE_PID" ]; then kill "$NODE_PID" || true; fi
- if [ -n "$HUB_PID" ]; then kill "$HUB_PID" || true; fi
- if [ -n "$OIDC_PID" ]; then kill "$OIDC_PID" || true; fi
- if [ -n "$HOST_MOCK_PID" ]; then kill "$HOST_MOCK_PID" || true; fi
+ echo "[E2E] Cleaning up background processes and containers..."
+ echo "=== DOCKER LOGS: sam-hub ==="
+ docker logs sam-hub 2>&1 || true
+ echo "=== DOCKER LOGS: host-node ==="
+ docker logs host-node 2>&1 || true
+ echo "=== DOCKER LOGS: host-mock-mcp ==="
+ docker logs host-mock-mcp 2>&1 || true
+ echo "==============================="
+ docker kill host-node sam-hub mock-oidc host-mock-mcp >/dev/null 2>&1 || true
+ docker network rm sam-net >/dev/null 2>&1 || true
rm -rf /tmp/host-node-data
}
trap cleanup EXIT
-# 1. Setup local DNS for mock-oidc
-if ! grep -q "mock-oidc" /etc/hosts; then
- echo "127.0.0.1 mock-oidc" | sudo tee -a /etc/hosts
-fi
-
-# 2. Build host binaries
+# 1. Build host binaries and docker images
make build
+make docker-build-hub docker-build-node docker-build-mock-oidc
-# 3. Build Android x86_64 FFI library using the Makefile and copy to Flutter jniLibs
+# 2. Build Android x86_64 FFI library using the Makefile and copy to Flutter jniLibs
make mobile-ffi-android-x86_64
mkdir -p mobile/sam-node-app/android/app/src/main/jniLibs/x86_64
cp bin/android-x86_64/libsam.so mobile/sam-node-app/android/app/src/main/jniLibs/x86_64/libsam.so
-# 4. Start the mock OIDC server
-python3 tests/e2e/docker/mock_oidc.py &
-OIDC_PID=$!
+# Create Docker bridge network
+docker network create sam-net || true
+
+# 3. Start the mock OIDC server container
+docker run --name mock-oidc \
+ --network sam-net \
+ -p 18080:18080 \
+ -d --rm \
+ sam-mock-oidc:local
# Wait for OIDC server to be ready
timeout 15s bash -c 'until curl -s http://127.0.0.1:18080/ >/dev/null; do sleep 0.5; done'
-# 5. Start the Hub
-bin/sam-hub \
- --bind-address 127.0.0.1:37001 \
+# 4. Start the Hub container
+docker run --name sam-hub \
+ --network sam-net \
+ -p 37001:37001 \
+ -p 37002:37002 \
+ -v "$REPO_ROOT/tests/e2e/fixtures/default-policy.yaml:/policy.yaml" \
+ -d --rm \
+ sam-hub:local \
+ --bind-address 0.0.0.0:37001 \
+ --listen /ip4/0.0.0.0/tcp/37002 \
+ --external-multiaddr /ip4/10.0.2.2/tcp/37002,/dns4/sam-hub/tcp/37002 \
--issuer http://mock-oidc:18080 \
--mesh public-mesh \
+ --policy-file /policy.yaml \
--insecure-skip-tls-verify \
- --allow-loopback &
-HUB_PID=$!
+ --allow-loopback \
+ --log-level debug
# Wait for Hub to be ready
timeout 15s bash -c 'until curl -s http://127.0.0.1:37001/info >/dev/null; do sleep 0.5; done'
-# 6. Enroll and Start the External Node on Host
+# 5. Enroll and Start the External Node on Host inside Docker
rm -rf /tmp/host-node-data
+mkdir -p /tmp/host-node-data
+
HOST_JWT=$(curl -s -X POST -d "grant_type=client_credentials&client_id=test-client&client_secret=test-secret" http://127.0.0.1:18080/token | jq -r .access_token)
-bin/sam-node enroll \
- --data-dir /tmp/host-node-data \
- --hub http://127.0.0.1:37001 \
+docker run --name host-node \
+ --network sam-net \
+ -p 8081:8081 \
+ -v /tmp/host-node-data:/data \
+ --add-host=host.docker.internal:host-gateway \
+ -d --rm \
+ sam-node:local \
+ run \
+ --data-dir /data \
+ --hub http://sam-hub:37001 \
--jwt "$HOST_JWT" \
- --allow-loopback
-
-bin/sam-node run \
- --data-dir /tmp/host-node-data \
- --hub http://127.0.0.1:37001 \
- --bind-addr 127.0.0.1:8081 \
+ --bind-addr 0.0.0.0:8081 \
--api-token host-token \
- --allow-loopback &
-NODE_PID=$!
+ --allow-loopback \
+ --enable-relay \
+ --log-level debug
# Wait for external node to be ready
timeout 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'
-# Start a local Mock MCP Server on host at port 9091
-python3 -c '
+# Start a local Mock MCP Server container on port 9091
+docker run --name host-mock-mcp \
+ --network sam-net \
+ -p 9091:9091 \
+ -d --rm \
+ python:3.12 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!"}
- ]
+ content_length = int(self.headers["Content-Length"])
+ post_data = self.rfile.read(content_length)
+ req = json.loads(post_data.decode("utf-8"))
+ method = req.get("method")
+ req_id = req.get("id")
+ res_data = None
+ if method == "initialize":
+ res_data = {
+ "jsonrpc": "2.0",
+ "id": req_id,
+ "result": {
+ "protocolVersion": "2024-11-05",
+ "capabilities": {},
+ "serverInfo": {"name": "mock-mcp-server", "version": "1.0.0"}
+ }
}
- }).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 server
+ elif method == "tools/list":
+ res_data = {
+ "jsonrpc": "2.0",
+ "id": req_id,
+ "result": {
+ "tools": [
+ {
+ "name": "host-tool",
+ "description": "test tool on host",
+ "inputSchema": {"type": "object", "properties": {}}
+ }
+ ]
+ }
+ }
+ elif method == "tools/call":
+ params = req.get("params", {})
+ if params.get("name") == "host-tool":
+ res_data = {
+ "jsonrpc": "2.0",
+ "id": req_id,
+ "result": {
+ "content": [{"type": "text", "text": "Hello from Host!"}]
+ }
+ }
+ if res_data is not None:
+ self.send_response(200)
+ self.send_header("Content-Type", "application/json")
+ self.end_headers()
+ self.wfile.write(json.dumps(res_data).encode("utf-8"))
+ else:
+ self.send_response(202)
+ self.end_headers()
+HTTPServer(("0.0.0.0", 9091), S).serve_forever()
+'
+
+# Register a dummy MCP service on the host node pointing to the local mock server container (using container name)
curl -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:9091"}' \
+ -d '{"service":{"type":"SERVICE_TYPE_MCP","name":"host-tool","description":"test tool on host"},"targetUrl":"http://host-mock-mcp:9091"}' \
http://127.0.0.1:8081/sam/service/register
# 7. Start the Android Emulator and run the Flutter integration test
@@ -128,9 +184,9 @@ TEST_PID=$!
# 8. Monitor host node's MCP tool list to verify discovery of emulator-tool
echo "[E2E] Verifying host node can discover emulator-tool..."
DISCOVERED=0
-for i in {1..45}; do
+for i in {1..120}; do
if [ -f "$REPO_ROOT/bin/mcp-client" ]; then
- TOOLS=$("$REPO_ROOT/bin/mcp-client" -url http://127.0.0.1:8081/mcp -tool list_tools 2>/dev/null || true)
+ TOOLS=$("$REPO_ROOT/bin/mcp-client" -token host-token -url http://127.0.0.1:8081/mcp -tool find_remote_tools 2>/dev/null || true)
if echo "$TOOLS" | grep -q "emulator-tool"; then
echo "[E2E] Host successfully discovered emulator-tool!"
DISCOVERED=1
@@ -144,7 +200,13 @@ done
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)
+ EMULATOR_PEER_ID=$(echo "$TOOLS" | jq -r '.[] | select(.tool_name | contains("emulator-tool")) | .peer_id' | head -n 1)
+ EMULATOR_TOOL_NAME=$(echo "$TOOLS" | jq -r '.[] | select(.tool_name | contains("emulator-tool")) | .tool_name' | head -n 1)
+ CALL_RESULT=$("$REPO_ROOT/bin/mcp-client" \
+ -token host-token \
+ -url http://127.0.0.1:8081/mcp \
+ -tool call_remote_tool \
+ -args "{\"peer_id\":\"$EMULATOR_PEER_ID\",\"tool_name\":\"$EMULATOR_TOOL_NAME\"}" 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!"
diff --git a/mobile/sam-node-app/.gitignore b/mobile/sam-node-app/.gitignore
new file mode 100644
index 00000000..3820a95c
--- /dev/null
+++ b/mobile/sam-node-app/.gitignore
@@ -0,0 +1,45 @@
+# Miscellaneous
+*.class
+*.log
+*.pyc
+*.swp
+.DS_Store
+.atom/
+.build/
+.buildlog/
+.history
+.svn/
+.swiftpm/
+migrate_working_dir/
+
+# IntelliJ related
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# The .vscode folder contains launch configuration and tasks you configure in
+# VS Code which you may wish to be included in version control, so this line
+# is commented out by default.
+#.vscode/
+
+# Flutter/Dart/Pub related
+**/doc/api/
+**/ios/Flutter/.last_build_id
+.dart_tool/
+.flutter-plugins-dependencies
+.pub-cache/
+.pub/
+/build/
+/coverage/
+
+# Symbolication related
+app.*.symbols
+
+# Obfuscation related
+app.*.map.json
+
+# Android Studio will place build artifacts here
+/android/app/debug
+/android/app/profile
+/android/app/release
diff --git a/mobile/sam-node-app/.metadata b/mobile/sam-node-app/.metadata
new file mode 100644
index 00000000..aa8e03dc
--- /dev/null
+++ b/mobile/sam-node-app/.metadata
@@ -0,0 +1,30 @@
+# This file tracks properties of this Flutter project.
+# Used by Flutter tool to assess capabilities and perform upgrades etc.
+#
+# This file should be version controlled and should not be manually edited.
+
+version:
+ revision: "ad70ec4617166f1c38e5d2bfd388af71fda14f06"
+ channel: "stable"
+
+project_type: app
+
+# Tracks metadata for the flutter migrate command
+migration:
+ platforms:
+ - platform: root
+ create_revision: ad70ec4617166f1c38e5d2bfd388af71fda14f06
+ base_revision: ad70ec4617166f1c38e5d2bfd388af71fda14f06
+ - platform: android
+ create_revision: ad70ec4617166f1c38e5d2bfd388af71fda14f06
+ base_revision: ad70ec4617166f1c38e5d2bfd388af71fda14f06
+
+ # User provided section
+
+ # List of Local paths (relative to this file) that should be
+ # ignored by the migrate tool.
+ #
+ # Files that are not part of the templates will be ignored by default.
+ unmanaged_files:
+ - 'lib/main.dart'
+ - 'ios/Runner.xcodeproj/project.pbxproj'
diff --git a/mobile/sam-node-app/README.md b/mobile/sam-node-app/README.md
new file mode 100644
index 00000000..86082cb1
--- /dev/null
+++ b/mobile/sam-node-app/README.md
@@ -0,0 +1,17 @@
+# sam_agent
+
+A new Flutter project.
+
+## Getting Started
+
+This project is a starting point for a Flutter application.
+
+A few resources to get you started if this is your first Flutter project:
+
+- [Learn Flutter](https://docs.flutter.dev/get-started/learn-flutter)
+- [Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
+- [Flutter learning resources](https://docs.flutter.dev/reference/learning-resources)
+
+For help getting started with Flutter development, view the
+[online documentation](https://docs.flutter.dev/), which offers tutorials,
+samples, guidance on mobile development, and a full API reference.
diff --git a/mobile/sam-node-app/analysis_options.yaml b/mobile/sam-node-app/analysis_options.yaml
new file mode 100644
index 00000000..0d290213
--- /dev/null
+++ b/mobile/sam-node-app/analysis_options.yaml
@@ -0,0 +1,28 @@
+# This file configures the analyzer, which statically analyzes Dart code to
+# check for errors, warnings, and lints.
+#
+# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
+# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
+# invoked from the command line by running `flutter analyze`.
+
+# The following line activates a set of recommended lints for Flutter apps,
+# packages, and plugins designed to encourage good coding practices.
+include: package:flutter_lints/flutter.yaml
+
+linter:
+ # The lint rules applied to this project can be customized in the
+ # section below to disable rules from the `package:flutter_lints/flutter.yaml`
+ # included above or to enable additional rules. A list of all available lints
+ # and their documentation is published at https://dart.dev/lints.
+ #
+ # Instead of disabling a lint rule for the entire project in the
+ # section below, it can also be suppressed for a single line of code
+ # or a specific dart file by using the `// ignore: name_of_lint` and
+ # `// ignore_for_file: name_of_lint` syntax on the line or in the file
+ # producing the lint.
+ rules:
+ # avoid_print: false # Uncomment to disable the `avoid_print` rule
+ # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
+
+# Additional information about this file can be found at
+# https://dart.dev/guides/language/analysis-options
diff --git a/mobile/sam-node-app/android/.gitignore b/mobile/sam-node-app/android/.gitignore
new file mode 100644
index 00000000..be3943c9
--- /dev/null
+++ b/mobile/sam-node-app/android/.gitignore
@@ -0,0 +1,14 @@
+gradle-wrapper.jar
+/.gradle
+/captures/
+/gradlew
+/gradlew.bat
+/local.properties
+GeneratedPluginRegistrant.java
+.cxx/
+
+# Remember to never publicly share your keystore.
+# See https://flutter.dev/to/reference-keystore
+key.properties
+**/*.keystore
+**/*.jks
diff --git a/mobile/sam-node-app/android/app/build.gradle.kts b/mobile/sam-node-app/android/app/build.gradle.kts
new file mode 100644
index 00000000..e079f03d
--- /dev/null
+++ b/mobile/sam-node-app/android/app/build.gradle.kts
@@ -0,0 +1,45 @@
+plugins {
+ id("com.android.application")
+ // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
+ id("dev.flutter.flutter-gradle-plugin")
+}
+
+android {
+ namespace = "com.example.sam_agent"
+ compileSdk = flutter.compileSdkVersion
+ ndkVersion = flutter.ndkVersion
+
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
+ }
+
+ defaultConfig {
+ // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
+ applicationId = "com.example.sam_agent"
+ // You can update the following values to match your application needs.
+ // For more information, see: https://flutter.dev/to/review-gradle-config.
+ minSdk = flutter.minSdkVersion
+ targetSdk = flutter.targetSdkVersion
+ versionCode = flutter.versionCode
+ versionName = flutter.versionName
+ }
+
+ buildTypes {
+ release {
+ // TODO: Add your own signing config for the release build.
+ // Signing with the debug keys for now, so `flutter run --release` works.
+ signingConfig = signingConfigs.getByName("debug")
+ }
+ }
+}
+
+kotlin {
+ compilerOptions {
+ jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
+ }
+}
+
+flutter {
+ source = "../.."
+}
diff --git a/mobile/sam-node-app/android/app/src/debug/AndroidManifest.xml b/mobile/sam-node-app/android/app/src/debug/AndroidManifest.xml
new file mode 100644
index 00000000..399f6981
--- /dev/null
+++ b/mobile/sam-node-app/android/app/src/debug/AndroidManifest.xml
@@ -0,0 +1,7 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- The INTERNET permission is required for development. Specifically,
+ the Flutter tool needs it to communicate with the running application
+ to allow setting breakpoints, to provide hot reload, etc.
+ -->
+ <uses-permission android:name="android.permission.INTERNET"/>
+</manifest>
diff --git a/mobile/sam-node-app/android/app/src/main/AndroidManifest.xml b/mobile/sam-node-app/android/app/src/main/AndroidManifest.xml
new file mode 100644
index 00000000..4e6e2cfc
--- /dev/null
+++ b/mobile/sam-node-app/android/app/src/main/AndroidManifest.xml
@@ -0,0 +1,45 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+ <application
+ android:label="sam_agent"
+ android:name="${applicationName}"
+ android:icon="@mipmap/ic_launcher">
+ <activity
+ android:name=".MainActivity"
+ android:exported="true"
+ android:launchMode="singleTop"
+ android:taskAffinity=""
+ android:theme="@style/LaunchTheme"
+ android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
+ android:hardwareAccelerated="true"
+ android:windowSoftInputMode="adjustResize">
+ <!-- Specifies an Android theme to apply to this Activity as soon as
+ the Android process has started. This theme is visible to the user
+ while the Flutter UI initializes. After that, this theme continues
+ to determine the Window background behind the Flutter UI. -->
+ <meta-data
+ android:name="io.flutter.embedding.android.NormalTheme"
+ android:resource="@style/NormalTheme"
+ />
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ <!-- Don't delete the meta-data below.
+ This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
+ <meta-data
+ android:name="flutterEmbedding"
+ android:value="2" />
+ </application>
+ <!-- Required to query activities that can process text, see:
+ https://developer.android.com/training/package-visibility and
+ https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
+
+ In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
+ <queries>
+ <intent>
+ <action android:name="android.intent.action.PROCESS_TEXT"/>
+ <data android:mimeType="text/plain"/>
+ </intent>
+ </queries>
+</manifest>
diff --git a/mobile/sam-node-app/android/app/src/main/kotlin/com/example/sam_agent/MainActivity.kt b/mobile/sam-node-app/android/app/src/main/kotlin/com/example/sam_agent/MainActivity.kt
new file mode 100644
index 00000000..1c867092
--- /dev/null
+++ b/mobile/sam-node-app/android/app/src/main/kotlin/com/example/sam_agent/MainActivity.kt
@@ -0,0 +1,5 @@
+package com.example.sam_agent
+
+import io.flutter.embedding.android.FlutterActivity
+
+class MainActivity : FlutterActivity()
diff --git a/mobile/sam-node-app/android/app/src/main/res/drawable-v21/launch_background.xml b/mobile/sam-node-app/android/app/src/main/res/drawable-v21/launch_background.xml
new file mode 100644
index 00000000..f74085f3
--- /dev/null
+++ b/mobile/sam-node-app/android/app/src/main/res/drawable-v21/launch_background.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Modify this file to customize your launch splash screen -->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="?android:colorBackground" />
+
+ <!-- You can insert your own image assets here -->
+ <!-- <item>
+ <bitmap
+ android:gravity="center"
+ android:src="@mipmap/launch_image" />
+ </item> -->
+</layer-list>
diff --git a/mobile/sam-node-app/android/app/src/main/res/drawable/launch_background.xml b/mobile/sam-node-app/android/app/src/main/res/drawable/launch_background.xml
new file mode 100644
index 00000000..304732f8
--- /dev/null
+++ b/mobile/sam-node-app/android/app/src/main/res/drawable/launch_background.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Modify this file to customize your launch splash screen -->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@android:color/white" />
+
+ <!-- You can insert your own image assets here -->
+ <!-- <item>
+ <bitmap
+ android:gravity="center"
+ android:src="@mipmap/launch_image" />
+ </item> -->
+</layer-list>
diff --git a/mobile/sam-node-app/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/mobile/sam-node-app/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 00000000..db77bb4b
Binary files /dev/null and b/mobile/sam-node-app/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/mobile/sam-node-app/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/mobile/sam-node-app/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 00000000..17987b79
Binary files /dev/null and b/mobile/sam-node-app/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/mobile/sam-node-app/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/mobile/sam-node-app/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 00000000..09d43914
Binary files /dev/null and b/mobile/sam-node-app/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/mobile/sam-node-app/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/mobile/sam-node-app/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 00000000..d5f1c8d3
Binary files /dev/null and b/mobile/sam-node-app/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/mobile/sam-node-app/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/mobile/sam-node-app/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 00000000..4d6372ee
Binary files /dev/null and b/mobile/sam-node-app/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/mobile/sam-node-app/android/app/src/main/res/values-night/styles.xml b/mobile/sam-node-app/android/app/src/main/res/values-night/styles.xml
new file mode 100644
index 00000000..06952be7
--- /dev/null
+++ b/mobile/sam-node-app/android/app/src/main/res/values-night/styles.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
+ <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
+ <!-- Show a splash screen on the activity. Automatically removed when
+ the Flutter engine draws its first frame -->
+ <item name="android:windowBackground">@drawable/launch_background</item>
+ </style>
+ <!-- Theme applied to the Android Window as soon as the process has started.
+ This theme determines the color of the Android Window while your
+ Flutter UI initializes, as well as behind your Flutter UI while its
+ running.
+
+ This Theme is only used starting with V2 of Flutter's Android embedding. -->
+ <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
+ <item name="android:windowBackground">?android:colorBackground</item>
+ </style>
+</resources>
diff --git a/mobile/sam-node-app/android/app/src/main/res/values/styles.xml b/mobile/sam-node-app/android/app/src/main/res/values/styles.xml
new file mode 100644
index 00000000..cb1ef880
--- /dev/null
+++ b/mobile/sam-node-app/android/app/src/main/res/values/styles.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
+ <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
+ <!-- Show a splash screen on the activity. Automatically removed when
+ the Flutter engine draws its first frame -->
+ <item name="android:windowBackground">@drawable/launch_background</item>
+ </style>
+ <!-- Theme applied to the Android Window as soon as the process has started.
+ This theme determines the color of the Android Window while your
+ Flutter UI initializes, as well as behind your Flutter UI while its
+ running.
+
+ This Theme is only used starting with V2 of Flutter's Android embedding. -->
+ <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
+ <item name="android:windowBackground">?android:colorBackground</item>
+ </style>
+</resources>
diff --git a/mobile/sam-node-app/android/app/src/profile/AndroidManifest.xml b/mobile/sam-node-app/android/app/src/profile/AndroidManifest.xml
new file mode 100644
index 00000000..399f6981
--- /dev/null
+++ b/mobile/sam-node-app/android/app/src/profile/AndroidManifest.xml
@@ -0,0 +1,7 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- The INTERNET permission is required for development. Specifically,
+ the Flutter tool needs it to communicate with the running application
+ to allow setting breakpoints, to provide hot reload, etc.
+ -->
+ <uses-permission android:name="android.permission.INTERNET"/>
+</manifest>
diff --git a/mobile/sam-node-app/android/build.gradle.kts b/mobile/sam-node-app/android/build.gradle.kts
new file mode 100644
index 00000000..dbee657b
--- /dev/null
+++ b/mobile/sam-node-app/android/build.gradle.kts
@@ -0,0 +1,24 @@
+allprojects {
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+
+val newBuildDir: Directory =
+ rootProject.layout.buildDirectory
+ .dir("../../build")
+ .get()
+rootProject.layout.buildDirectory.value(newBuildDir)
+
+subprojects {
+ val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
+ project.layout.buildDirectory.value(newSubprojectBuildDir)
+}
+subprojects {
+ project.evaluationDependsOn(":app")
+}
+
+tasks.register<Delete>("clean") {
+ delete(rootProject.layout.buildDirectory)
+}
diff --git a/mobile/sam-node-app/android/gradle.properties b/mobile/sam-node-app/android/gradle.properties
new file mode 100644
index 00000000..e96108cf
--- /dev/null
+++ b/mobile/sam-node-app/android/gradle.properties
@@ -0,0 +1,6 @@
+org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
+android.useAndroidX=true
+# This newDsl flag was added by the Flutter template
+android.newDsl=false
+# This builtInKotlin flag was added by the Flutter template
+android.builtInKotlin=false
diff --git a/mobile/sam-node-app/android/gradle/wrapper/gradle-wrapper.properties b/mobile/sam-node-app/android/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..2d428bfb
--- /dev/null
+++ b/mobile/sam-node-app/android/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-all.zip
diff --git a/mobile/sam-node-app/android/settings.gradle.kts b/mobile/sam-node-app/android/settings.gradle.kts
new file mode 100644
index 00000000..c21f0c5b
--- /dev/null
+++ b/mobile/sam-node-app/android/settings.gradle.kts
@@ -0,0 +1,26 @@
+pluginManagement {
+ val flutterSdkPath =
+ run {
+ val properties = java.util.Properties()
+ file("local.properties").inputStream().use { properties.load(it) }
+ val flutterSdkPath = properties.getProperty("flutter.sdk")
+ require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
+ flutterSdkPath
+ }
+
+ includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
+
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+
+plugins {
+ id("dev.flutter.flutter-plugin-loader") version "1.0.0"
+ id("com.android.application") version "9.0.1" apply false
+ id("org.jetbrains.kotlin.android") version "2.3.20" apply false
+}
+
+include(":app")
diff --git a/mobile/sam-node-app/integration_test/e2e_test.dart b/mobile/sam-node-app/integration_test/e2e_test.dart
index 808aa174..ba594e34 100644
--- a/mobile/sam-node-app/integration_test/e2e_test.dart
+++ b/mobile/sam-node-app/integration_test/e2e_test.dart
@@ -54,7 +54,8 @@ void main() {
'bindAddr': '0.0.0.0:8080', // sidecar HTTP server inside phone
'apiToken': 'test-token',
'allowLoopback': true,
- 'enableRelay': false,
+ 'enableRelay': true,
+ 'logLevel': 'debug',
});
expect(startErr, isNull);
@@ -68,23 +69,53 @@ void main() {
// 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': [
+ mockMcpServer.listen((HttpRequest request) async {
+ try {
+ final content = await utf8.decoder.bind(request).join();
+ final body = jsonDecode(content);
+ final method = body['method'] as String?;
+ final id = body['id'];
+
+ dynamic result;
+ if (method == 'initialize') {
+ result = {
+ 'protocolVersion': '2024-11-05',
+ 'capabilities': {},
+ 'serverInfo': {'name': 'mock-emulator-mcp', 'version': '1.0.0'}
+ };
+ } else if (method == 'tools/list') {
+ result = {
+ 'tools': [
{
- 'type': 'text',
- 'text': 'Hello from Android!'
+ 'name': 'emulator-tool',
+ 'description': 'test tool on emulator',
+ 'inputSchema': {'type': 'object', 'properties': {}}
}
]
- }
- }));
- request.response.close();
+ };
+ } else if (method == 'tools/call') {
+ result = {
+ 'content': [
+ {'type': 'text', 'text': 'Hello from Android!'}
+ ]
+ };
+ }
+
+ request.response
+ ..headers.contentType = ContentType.json
+ ..statusCode = HttpStatus.ok
+ ..write(jsonEncode({
+ 'jsonrpc': '2.0',
+ 'id': id,
+ 'result': result,
+ }));
+ } catch (e) {
+ request.response
+ ..statusCode = HttpStatus.internalServerError
+ ..write(e.toString());
+ } finally {
+ await request.response.close();
+ }
});
// Register a dummy MCP service inside the Android emulator
@@ -106,76 +137,76 @@ void main() {
);
expect(regResponse.statusCode, equals(200));
- // Discover host-tool from inside the emulator via its local MCP API
- final listToolsUrl = 'http://127.0.0.1:8080/mcp';
+ // Discover host-tool from inside the emulator via its local MCP API using McpClient
+ final client = McpClient('http://127.0.0.1:8080/mcp', 'test-token');
+ var initialized = false;
+ for (var i = 0; i < 10; i++) {
+ try {
+ await client.initialize();
+ initialized = true;
+ break;
+ } catch (e) {
+ print('E2E McpClient initialization attempt failed: $e');
+ }
+ await Future.delayed(const Duration(seconds: 1));
+ }
+ expect(initialized, isTrue, reason: 'Emulator failed to initialize McpClient session');
+
var discovered = false;
+ String hostToolName = 'host-tool';
+ String hostPeerId = '';
for (var i = 0; i < 30; i++) {
try {
- final listResponse = await http.post(
- Uri.parse(listToolsUrl),
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer test-token',
- },
- body: jsonEncode({
- 'jsonrpc': '2.0',
- 'method': 'tools/list',
- 'params': {},
- 'id': 1
- }),
- );
- if (listResponse.statusCode == 200) {
- final listData = jsonDecode(listResponse.body);
- final result = listData['result'];
- if (result != null && result['tools'] != null) {
- final tools = result['tools'] as List;
- if (tools.any((t) => t['name'] == 'host-tool')) {
+ final callResult = await client.post('tools/call', {
+ 'name': 'find_remote_tools',
+ 'arguments': {}
+ });
+ print('E2E Discovered Tools Result: $callResult');
+ if (callResult != null && callResult['content'] != null) {
+ final contentList = callResult['content'] as List;
+ if (contentList.isNotEmpty) {
+ final text = contentList[0]['text'] as String;
+ final tools = jsonDecode(text) as List;
+ final matched = tools.firstWhere(
+ (t) => (t['tool_name'] as String).contains('host-tool'),
+ orElse: () => null,
+ );
+ if (matched != null) {
+ hostToolName = matched['tool_name'] as String;
+ hostPeerId = matched['peer_id'] as String;
discovered = true;
break;
}
}
}
} catch (e) {
- // ignore network setup transient errors
+ print('E2E Discovery attempt failed: $e');
}
await Future.delayed(const Duration(seconds: 1));
}
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';
+ // Call host-tool from inside the emulator via its local MCP API using McpClient
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;
- }
+ final callResult = await client.post('tools/call', {
+ 'name': 'call_remote_tool',
+ 'arguments': {
+ 'peer_id': hostPeerId,
+ 'tool_name': hostToolName,
+ }
+ });
+ print('E2E Call Result: $callResult');
+ if (callResult != null && callResult['content'] != null) {
+ final content = callResult['content'] as List;
+ if (content.any((c) => c['text'].contains('Hello from Host!'))) {
+ called = true;
+ break;
}
}
} catch (e) {
- // ignore network setup transient errors
+ print('E2E Call attempt failed: $e');
}
await Future.delayed(const Duration(seconds: 1));
}
@@ -189,4 +220,100 @@ void main() {
final stopErr = samLib.stop();
expect(stopErr, isNull);
});
+
+ tearDownAll(() async {
+ try {
+ final appDir = await getApplicationDocumentsDirectory();
+ final file = File('${appDir.path}/sam_e2e_data/node.log');
+ if (file.existsSync()) {
+ print('=== MOBILE GO NODE LOGS ===');
+ print(file.readAsStringSync());
+ print('===========================');
+ } else {
+ print('No node.log file found at ${file.path}');
+ }
+ } catch (e) {
+ print('Failed to print node.log: $e');
+ }
+ });
+}
+
+class McpClient {
+ final String url;
+ final String token;
+ String? sessionId;
+
+ McpClient(this.url, this.token);
+
+ Future<dynamic> post(String method, Map<String, dynamic> params) async {
+ final Map<String, String> headers = {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json, text/event-stream',
+ 'Authorization': 'Bearer $token',
+ };
+ if (sessionId != null) {
+ headers['Mcp-Session-Id'] = sessionId!;
+ }
+
+ final Map<String, dynamic> bodyMap = {
+ 'jsonrpc': '2.0',
+ 'method': method,
+ 'params': params,
+ };
+ if (!method.startsWith('notifications/')) {
+ bodyMap['id'] = 1;
+ }
+
+ final response = await http.post(
+ Uri.parse(url),
+ headers: headers,
+ body: jsonEncode(bodyMap),
+ );
+
+ // Save session ID if returned in headers
+ final returnedSessionId = response.headers['mcp-session-id'] ?? response.headers['Mcp-Session-Id'];
+ if (returnedSessionId != null) {
+ sessionId = returnedSessionId;
+ }
+
+ if (response.statusCode < 200 || response.statusCode >= 300) {
+ throw Exception('HTTP error ${response.statusCode}: ${response.body}');
+ }
+
+ // Parse the SSE body
+ final body = response.body;
+ String jsonData = '';
+ for (var line in body.split('\n')) {
+ if (line.startsWith('data: ')) {
+ jsonData = line.substring(6);
+ break;
+ }
+ }
+
+ if (jsonData.isEmpty) {
+ if (method.startsWith('notifications/')) {
+ return null;
+ }
+ throw Exception('No data block found in SSE response: $body');
+ }
+
+ final dataObj = jsonDecode(jsonData);
+ if (dataObj['error'] != null) {
+ throw Exception('JSON-RPC error: ${dataObj['error']}');
+ }
+ return dataObj['result'];
+ }
+
+ Future<void> initialize() async {
+ await post('initialize', {
+ 'protocolVersion': '2024-11-05',
+ 'capabilities': {},
+ 'clientInfo': {
+ 'name': 'e2e-dart-client',
+ 'version': '1.0.0'
+ }
+ });
+
+ await post('notifications/initialized', {});
+ }
}
diff --git a/mobile/sam-node-app/pubspec.lock b/mobile/sam-node-app/pubspec.lock
new file mode 100644
index 00000000..f484b628
--- /dev/null
+++ b/mobile/sam-node-app/pubspec.lock
@@ -0,0 +1,460 @@
+# Generated by pub
+# See https://dart.dev/tools/pub/glossary#lockfile
+packages:
+ args:
+ dependency: transitive
+ description:
+ name: args
+ sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.7.0"
+ async:
+ dependency: transitive
+ description:
+ name: async
+ sha256: e2eb0491ba5ddb6177742d2da23904574082139b07c1e33b8503b9f46f3e1a37
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.13.1"
+ boolean_selector:
+ dependency: transitive
+ description:
+ name: boolean_selector
+ sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.1.2"
+ characters:
+ dependency: transitive
+ description:
+ name: characters
+ sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.4.1"
+ clock:
+ dependency: transitive
+ description:
+ name: clock
+ sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.1.2"
+ code_assets:
+ dependency: transitive
+ description:
+ name: code_assets
+ sha256: bf394f466ba9205f1812a0433b392d6af280f155f56651eda7c18cc32ed493b8
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.2.1"
+ collection:
+ dependency: transitive
+ description:
+ name: collection
+ sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.19.1"
+ crypto:
+ dependency: transitive
+ description:
+ name: crypto
+ sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.7"
+ fake_async:
+ dependency: transitive
+ description:
+ name: fake_async
+ sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.3.3"
+ ffi:
+ dependency: "direct main"
+ description:
+ name: ffi
+ sha256: "6d7fd89431262d8f3125e81b50d3847a091d846eafcd4fdb88dd06f36d705a45"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.2.0"
+ file:
+ dependency: transitive
+ description:
+ name: file
+ sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4
+ url: "https://pub.dev"
+ source: hosted
+ version: "7.0.1"
+ flutter:
+ dependency: "direct main"
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ flutter_driver:
+ dependency: transitive
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ flutter_lints:
+ dependency: "direct dev"
+ description:
+ name: flutter_lints
+ sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.2"
+ flutter_test:
+ dependency: "direct dev"
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ fuchsia_remote_debug_protocol:
+ dependency: transitive
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ hooks:
+ dependency: transitive
+ description:
+ name: hooks
+ sha256: "9a62a50b50b769a737bc0a8ff381f333529df3ab746b2f6b02e83760231455ba"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.0.2"
+ http:
+ dependency: "direct main"
+ description:
+ name: http
+ sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.6.0"
+ http_parser:
+ dependency: transitive
+ description:
+ name: http_parser
+ sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
+ url: "https://pub.dev"
+ source: hosted
+ version: "4.1.2"
+ integration_test:
+ dependency: "direct dev"
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ jni:
+ dependency: transitive
+ description:
+ name: jni
+ sha256: c2230682d5bc2362c1c9e8d3c7f406d9cbba23ab3f2e203a025dd47e0fb2e68f
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.0.0"
+ jni_flutter:
+ dependency: transitive
+ description:
+ name: jni_flutter
+ sha256: "8b59e590786050b1cd866677dddaf76b1ade5e7bc751abe04b86e84d379d3ba6"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.0.1"
+ leak_tracker:
+ dependency: transitive
+ description:
+ name: leak_tracker
+ sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
+ url: "https://pub.dev"
+ source: hosted
+ version: "11.0.2"
+ leak_tracker_flutter_testing:
+ dependency: transitive
+ description:
+ name: leak_tracker_flutter_testing
+ sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.10"
+ leak_tracker_testing:
+ dependency: transitive
+ description:
+ name: leak_tracker_testing
+ sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.2"
+ lints:
+ dependency: transitive
+ description:
+ name: lints
+ sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.0"
+ logging:
+ dependency: transitive
+ description:
+ name: logging
+ sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.3.0"
+ matcher:
+ dependency: transitive
+ description:
+ name: matcher
+ sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.12.19"
+ material_color_utilities:
+ dependency: transitive
+ description:
+ name: material_color_utilities
+ sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.13.0"
+ meta:
+ dependency: transitive
+ description:
+ name: meta
+ sha256: "1741988757a65eb6b36abe716829688cf01910bbf91c34354ff7ec1c3de2b349"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.18.0"
+ objective_c:
+ dependency: transitive
+ description:
+ name: objective_c
+ sha256: "6cb691c686fa2838c6deb34980d426145c2a5d537491cb83d463c33cdbc726ed"
+ url: "https://pub.dev"
+ source: hosted
+ version: "9.4.1"
+ package_config:
+ dependency: transitive
+ description:
+ name: package_config
+ sha256: f096c55ebb7deb7e384101542bfba8c52696c1b56fca2eb62827989ef2353bbc
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.2.0"
+ path:
+ dependency: transitive
+ description:
+ name: path
+ sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.9.1"
+ path_provider:
+ dependency: "direct main"
+ description:
+ name: path_provider
+ sha256: a7f4874f987173da295a61c181b8ee71dab59b332a486b391babf26a1b884825
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.1.6"
+ path_provider_android:
+ dependency: transitive
+ description:
+ name: path_provider_android
+ sha256: "69cbd515a62b94d32a7944f086b2f82b4ac40a1d45bebfc00813a430ab2dabcd"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.3.1"
+ path_provider_foundation:
+ dependency: transitive
+ description:
+ name: path_provider_foundation
+ sha256: "2a376b7d6392d80cd3705782d2caa734ca4727776db0b6ec36ef3f1855197699"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.6.0"
+ path_provider_linux:
+ dependency: transitive
+ description:
+ name: path_provider_linux
+ sha256: "58c2005f147315b11e9b4a7bc889cd5203e250cba8e3f012dae259b4972b5c16"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.2.2"
+ path_provider_platform_interface:
+ dependency: transitive
+ description:
+ name: path_provider_platform_interface
+ sha256: "484838772624c3a4b94f1e44a3e19897fee738f2d5c4ce448443b0417f7c9dda"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.1.3"
+ path_provider_windows:
+ dependency: transitive
+ description:
+ name: path_provider_windows
+ sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.3.0"
+ platform:
+ dependency: transitive
+ description:
+ name: platform
+ sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.1.6"
+ plugin_platform_interface:
+ dependency: transitive
+ description:
+ name: plugin_platform_interface
+ sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.1.8"
+ process:
+ dependency: transitive
+ description:
+ name: process
+ sha256: c6248e4526673988586e8c00bb22a49210c258dc91df5227d5da9748ecf79744
+ url: "https://pub.dev"
+ source: hosted
+ version: "5.0.5"
+ pub_semver:
+ dependency: transitive
+ description:
+ name: pub_semver
+ sha256: "5bfcf68ca79ef689f8990d1160781b4bad40a3bd5e5218ad4076ddb7f4081585"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.2.0"
+ record_use:
+ dependency: transitive
+ description:
+ name: record_use
+ sha256: "2551bd8eecfe95d14ae75f6021ad0248be5c27f138c2ec12fcb52b500b3ba1ed"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.6.0"
+ sky_engine:
+ dependency: transitive
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ source_span:
+ dependency: transitive
+ description:
+ name: source_span
+ sha256: "56a02f1f4cd1a2d96303c0144c93bd6d909eea6bee6bf5a0e0b685edbd4c47ab"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.10.2"
+ stack_trace:
+ dependency: transitive
+ description:
+ name: stack_trace
+ sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.12.1"
+ stream_channel:
+ dependency: transitive
+ description:
+ name: stream_channel
+ sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.1.4"
+ string_scanner:
+ dependency: transitive
+ description:
+ name: string_scanner
+ sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.4.1"
+ sync_http:
+ dependency: transitive
+ description:
+ name: sync_http
+ sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.3.1"
+ term_glyph:
+ dependency: transitive
+ description:
+ name: term_glyph
+ sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.2.2"
+ test_api:
+ dependency: transitive
+ description:
+ name: test_api
+ sha256: "949a932224383300f01be9221c39180316445ecb8e7547f70a41a35bf421fb9e"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.7.11"
+ typed_data:
+ dependency: transitive
+ description:
+ name: typed_data
+ sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.4.0"
+ vector_math:
+ dependency: transitive
+ description:
+ name: vector_math
+ sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.2.0"
+ vm_service:
+ dependency: transitive
+ description:
+ name: vm_service
+ sha256: "0016aef94fc66495ac78af5859181e3f3bf2026bd8eecc72b9565601e19ab360"
+ url: "https://pub.dev"
+ source: hosted
+ version: "15.2.0"
+ web:
+ dependency: transitive
+ description:
+ name: web
+ sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.1.1"
+ webdriver:
+ dependency: transitive
+ description:
+ name: webdriver
+ sha256: "2f3a14ca026957870cfd9c635b83507e0e51d8091568e90129fbf805aba7cade"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.1.0"
+ xdg_directories:
+ dependency: transitive
+ description:
+ name: xdg_directories
+ sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.1.0"
+ yaml:
+ dependency: transitive
+ description:
+ name: yaml
+ sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.1.3"
+sdks:
+ dart: ">=3.10.3 <4.0.0"
+ flutter: ">=3.38.4"
diff --git a/mobile/sam-node-app/test/widget_test.dart b/mobile/sam-node-app/test/widget_test.dart
new file mode 100644
index 00000000..d49235c8
--- /dev/null
+++ b/mobile/sam-node-app/test/widget_test.dart
@@ -0,0 +1,30 @@
+// This is a basic Flutter widget test.
+//
+// To perform an interaction with a widget in your test, use the WidgetTester
+// utility in the flutter_test package. For example, you can send tap and scroll
+// gestures. You can also use WidgetTester to find child widgets in the widget
+// tree, read text, and verify that the values of widget properties are correct.
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+import 'package:sam_agent/main.dart';
+
+void main() {
+ testWidgets('Counter increments smoke test', (WidgetTester tester) async {
+ // Build our app and trigger a frame.
+ await tester.pumpWidget(const MyApp());
+
+ // Verify that our counter starts at 0.
+ expect(find.text('0'), findsOneWidget);
+ expect(find.text('1'), findsNothing);
+
+ // Tap the '+' icon and trigger a frame.
+ await tester.tap(find.byIcon(Icons.add));
+ await tester.pump();
+
+ // Verify that our counter has incremented.
+ expect(find.text('0'), findsNothing);
+ expect(find.text('1'), findsOneWidget);
+ });
+}
diff --git a/mobile/sam-node-ffi/ffi/ffi.go b/mobile/sam-node-ffi/ffi/ffi.go
index 40a9dd6b..6121203c 100644
--- a/mobile/sam-node-ffi/ffi/ffi.go
+++ b/mobile/sam-node-ffi/ffi/ffi.go
@@ -21,11 +21,14 @@ import (
"errors"
"fmt"
"net/http"
+ "os"
+ "path/filepath"
"strings"
"sync"
"time"
"github.com/google/sam/internal/node"
+ golog "github.com/ipfs/go-log/v2"
"github.com/multiformats/go-multiaddr"
)
@@ -66,6 +69,29 @@ func StartNode(configJSON string) error {
return fmt.Errorf("failed to parse config JSON: %w", err)
}
+ lvl := golog.LevelInfo
+ if config.LogLevel != "" {
+ if l, err := golog.LevelFromString(config.LogLevel); err == nil {
+ lvl = l
+ }
+ }
+
+ if config.DataDir != "" {
+ _ = os.MkdirAll(config.DataDir, 0700)
+ logFilePath := filepath.Join(config.DataDir, "node.log")
+ golog.SetupLogging(golog.Config{
+ File: logFilePath,
+ Level: lvl,
+ Stderr: false,
+ Stdout: false,
+ })
+ } else {
+ golog.SetupLogging(golog.Config{
+ Level: lvl,
+ Stderr: true,
+ })
+ }
+
store, err := node.NewStore(config.DataDir)
if err != nil {
return fmt.Errorf("failed to open store: %w", err)
@@ -231,6 +257,15 @@ func GetNodeID() string {
// EnrollNode enrolls a node.
func EnrollNode(dataDir string, hubURL string, jwt string, allowLoopback bool) error {
+ _ = os.MkdirAll(dataDir, 0700)
+ logFilePath := filepath.Join(dataDir, "node.log")
+ golog.SetupLogging(golog.Config{
+ File: logFilePath,
+ Level: golog.LevelDebug,
+ Stderr: false,
+ Stdout: false,
+ })
+
store, err := node.NewStore(dataDir)
if err != nil {
return fmt.Errorf("failed to open store: %w", err)
diff --git a/tests/e2e/docker/mock_oidc.py b/tests/e2e/docker/mock_oidc.py
index 1d93fb7d..fbd5da4b 100644
--- a/tests/e2e/docker/mock_oidc.py
+++ b/tests/e2e/docker/mock_oidc.py
@@ -49,15 +49,18 @@ JWKS = {
]
}
+import os
+ISSUER = os.getenv('OIDC_ISSUER', 'http://mock-oidc:18080')
+
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/.well-known/openid-configuration':
body = {
- 'issuer': 'http://mock-oidc:18080',
- 'authorization_endpoint': 'http://mock-oidc:18080/auth',
- 'token_endpoint': 'http://mock-oidc:18080/token',
- 'device_authorization_endpoint': 'http://mock-oidc:18080/device/code',
- 'jwks_uri': 'http://mock-oidc:18080/keys'
+ 'issuer': ISSUER,
+ 'authorization_endpoint': f'{ISSUER}/auth',
+ 'token_endpoint': f'{ISSUER}/token',
+ 'device_authorization_endpoint': f'{ISSUER}/device/code',
+ 'jwks_uri': f'{ISSUER}/keys'
}
data = json.dumps(body).encode('utf-8')
self.send_response(200)
@@ -109,7 +112,7 @@ class Handler(BaseHTTPRequestHandler):
groups = ['admin']
payload = {
- 'iss': 'http://mock-oidc:18080',
+ 'iss': ISSUER,
'aud': 'sam-mesh-audience',
'sub': 'test-user',
'exp': int(time.time()) + 3600,