fix(cua): pre-create API call must use 127.0.0.1 not 10.0.2.2 on host

The CUA script runs on the CI runner (host), not inside the emulator.
10.0.2.2 is the emulator's special address for the host — it is only
reachable FROM INSIDE the emulator. Calling it from the runner always
fails, so _precreate_test_session returned None, and the session_list
phase fell back to the weak 'screen visible' assertion instead of the
strong 'pre-created session must appear' check.

Fix: replace 10.0.2.2 → 127.0.0.1 before making the pre-create call.
Localhost URLs (100.x.x.x, custom dev server) pass through unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Dennis V
2026-06-23 00:06:32 +00:00
parent cdbea50287
commit bbe8af9378

View File

@@ -621,7 +621,12 @@ def _precreate_test_session(opencode_url: str, title: str = "cua-smoke-sessions-
pre-existing sessions from the server on connect (not just an empty screen). pre-existing sessions from the server on connect (not just an empty screen).
""" """
import urllib.request import urllib.request
url = f"{opencode_url.rstrip('/')}/session" # The CUA script runs on the HOST machine, not inside the emulator.
# When opencode_url uses the Android emulator's host-route (10.0.2.2),
# translate it to localhost for this pre-create call — 10.0.2.2 is
# only reachable from *inside* the emulator, not from the host/CI runner.
api_base = opencode_url.replace("10.0.2.2", "127.0.0.1")
url = f"{api_base.rstrip('/')}/session"
data = json.dumps({"title": title}).encode() data = json.dumps({"title": title}).encode()
req = urllib.request.Request( req = urllib.request.Request(
url, data=data, method="POST", url, data=data, method="POST",
@@ -631,10 +636,10 @@ def _precreate_test_session(opencode_url: str, title: str = "cua-smoke-sessions-
with urllib.request.urlopen(req, timeout=10) as resp: with urllib.request.urlopen(req, timeout=10) as resp:
body = json.loads(resp.read()) body = json.loads(resp.read())
session_id = body.get("id", "unknown") session_id = body.get("id", "unknown")
print(f" [pre-create] session created via API: id={session_id!r}, title={title!r}") print(f" [pre-create] session created via API ({api_base}): id={session_id!r}, title={title!r}")
return title return title
except Exception as exc: except Exception as exc:
print(f" [pre-create] WARNING: could not pre-create session: {exc}") print(f" [pre-create] WARNING: could not pre-create session at {api_base}: {exc}")
print(f" [pre-create] session_list phase will skip the 'must show sessions' assertion") print(f" [pre-create] session_list phase will skip the 'must show sessions' assertion")
return None return None