From 40cbf0b3b06ac35d374a0848e090883e5446dac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCttler?= Date: Sat, 25 Apr 2026 21:49:31 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Android=20E2E=20=E2=80=94=20use=20adb=20?= =?UTF-8?q?reverse=20instead=20of=20Platform.environment=20for=20Stalwart?= =?UTF-8?q?=20ports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Platform.environment is empty inside the Android app process, so the dynamic IMAP/SMTP port numbers exported by the test script were never visible to the Dart test code. The test fell back to its defaults (127.0.0.1:1430/1025), which aren't reachable inside the emulator. Replace the export STALWART_IMAP_HOST=10.0.2.2 approach with adb reverse tcp:1430 tcp:$STALWART_IMAP_PORT adb reverse tcp:1025 tcp:$STALWART_SMTP_PORT so the emulator's loopback ports 1430/1025 forward to the actual random host ports — matching the test's hard-coded defaults exactly. Clean up the forwarding rules in the EXIT trap. Co-Authored-By: Claude Sonnet 4.6 --- stalwart-dev/integration_android_test.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/stalwart-dev/integration_android_test.sh b/stalwart-dev/integration_android_test.sh index e952cc6..3ced05d 100755 --- a/stalwart-dev/integration_android_test.sh +++ b/stalwart-dev/integration_android_test.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash # Starts Stalwart on random ports, then runs Flutter UI integration tests on a # connected Android emulator. Boots the sharedinbox_test AVD automatically if -# no emulator is already running. The emulator reaches the host via 10.0.2.2. +# no emulator is already running. Uses adb reverse to forward the fixed default +# ports (IMAP 1430, SMTP 1025) on the emulator to the actual random host ports. # # Run inside nix develop: # stalwart-dev/integration_android_test.sh @@ -19,6 +20,7 @@ STALWART_TMPDIR="$(mktemp -d /tmp/stalwart-dev-XXXXXX)" export STALWART_TMPDIR cleanup() { + "${ADB:-adb}" -s "${EMULATOR_ID:-}" reverse --remove-all 2>/dev/null || true kill "${STALWART_PID:-}" 2>/dev/null || true wait "${STALWART_PID:-}" 2>/dev/null || true } @@ -45,6 +47,7 @@ if [ -z "$EMULATOR_ID" ]; then EMULATOR_BOOT_PID=$! # Extend cleanup to also kill the emulator we started. cleanup() { + "${ADB:-adb}" -s "${EMULATOR_ID:-}" reverse --remove-all 2>/dev/null || true kill "${STALWART_PID:-}" 2>/dev/null || true wait "${STALWART_PID:-}" 2>/dev/null || true kill "${EMULATOR_BOOT_PID:-}" 2>/dev/null || true @@ -108,9 +111,12 @@ ts "stalwart ready — IMAP=:${STALWART_IMAP_PORT:-?} SMTP=:${STALWART_SMTP_POR ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" -# Android emulator reaches the host machine via 10.0.2.2, not 127.0.0.1. -export STALWART_IMAP_HOST="10.0.2.2" -export STALWART_SMTP_HOST="10.0.2.2" +# Platform.environment is empty inside the Android app process, so env vars set +# by this script never reach the test code. Instead, use adb reverse to forward +# the fixed "template" ports that the test defaults to (1430 IMAP, 1025 SMTP) +# on the emulator through to the actual random Stalwart ports on the host. +"$ADB" -s "$EMULATOR_ID" reverse tcp:1430 tcp:"$STALWART_IMAP_PORT" +"$ADB" -s "$EMULATOR_ID" reverse tcp:1025 tcp:"$STALWART_SMTP_PORT" ts "flutter test start" fvm flutter test integration_test/ -d "$EMULATOR_ID" | grep -Ev "was tree-shaken|Tree-shaking can be disabled"