fix: restore automatic startup of local ADB server

This commit is contained in:
chenmingxuan committed 2026-10-09 10:17:07 +08:00
1 parent f826bdf3b0
commit 49873e7f05
9 files changed
+211 -23

No files matched your search

+29 -1
View File
@@ -70,6 +70,34 @@ def test_adb_session_builds_explicit_endpoint_command_and_environment():
assert environment[ADB_ENDPOINT_ID_ENV] == endpoint.identity
@pytest.mark.parametrize("host", ["127.0.0.1", "localhost", "::1"])
def test_local_endpoint_allows_adb_auto_start_without_changing_task_identity(host):
endpoint = AdbServerEndpoint(host, 5037)
session = AdbSession(endpoint, adb_path="adb")
inherited = {
"ADB_SERVER_SOCKET": "tcp:remote.example:5040",
"ANDROID_ADB_SERVER_ADDRESS": "remote.example",
"ANDROID_ADB_SERVER_PORT": "5040",
}
assert session.command(["devices"]) == ["adb", "-H", "localhost", "-P", "5037", "devices"]
environment = session.environment(inherited)
assert environment["ADB_SERVER_SOCKET"] == "tcp:localhost:5037"
assert environment["ADB_HOST"] == host
assert environment[ADB_ENDPOINT_ID_ENV] == endpoint.identity
assert inherited["ADB_SERVER_SOCKET"] == "tcp:remote.example:5040"
@pytest.mark.parametrize(
("host", "port"), [("127.0.0.1", 5038), ("::1", 5038), ("server.example", 5037)]
)
def test_forwarded_endpoint_never_uses_local_daemon_auto_start(host, port):
endpoint = AdbServerEndpoint(host, port)
session = AdbSession(endpoint, adb_path="adb")
assert session.command(["devices"])[2] == host
assert session.environment({})["ADB_SERVER_SOCKET"] == endpoint.socket
@pytest.mark.asyncio
async def test_connect_activates_forwarded_server_after_success(monkeypatch):
captured: dict[str, object] = {}
@@ -253,7 +281,7 @@ async def test_use_local_server_restores_standard_endpoint(monkeypatch):
assert result["success"] is True
assert result["endpoint"] == AdbServerEndpoint("127.0.0.1", 5037).to_dict()
assert settings.ADB_PORT == 5037
assert os.environ["ADB_SERVER_SOCKET"] == "tcp:127.0.0.1:5037"
assert os.environ["ADB_SERVER_SOCKET"] == "tcp:localhost:5037"
@pytest.mark.asyncio