fix: Android E2E — use adb reverse instead of Platform.environment for Stalwart ports

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 <noreply@anthropic.com>
This commit is contained in:
Thomas Güttler
2026-04-25 21:49:31 +02:00
co-authored by Claude Sonnet 4.6
parent d3646e350b
commit 40cbf0b3b0
+10 -4
View File
@@ -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"