fix(runtime): release 2.7.1 with consistent ADB and failure diagnostics

This commit is contained in:
chenmingxuan committed 2026-11-05 11:40:49 +08:00
1 parent b2316ca249
commit 8bf59897bb
24 files changed
+792 -45

No files matched your search

@@ -25,6 +25,7 @@ import pytest
import cv2
from artemis.context import ArtemisContext
from artemis.config.settings import settings
from artemis.controllers.unified_controller import UnifiedMobileController
from artemis.drivers.mock.mock_driver import MockDeviceDriver
from artemis.utils.video import (
@@ -42,6 +43,55 @@ from artemis.utils.video import (
)
@pytest.mark.asyncio
@pytest.mark.parametrize("host,port", [("127.0.0.1", 5037), ("192.0.2.10", 5038)])
async def test_scrcpy_uses_selected_adb_binary_and_endpoint(monkeypatch, tmp_path, host, port):
import os
adb = str(tmp_path / "platform tools" / "adb.exe")
monkeypatch.setattr("artemis.runtime.adb_endpoint.toolchain.resolve", lambda _: adb)
monkeypatch.setattr(settings, "ADB_HOST", host)
monkeypatch.setattr(settings, "ADB_PORT", port)
monkeypatch.setenv("ADB", "other-adb")
monkeypatch.setenv("ADB_SERVER_SOCKET", "tcp:unrelated:5999")
command = ["scrcpy", "--no-playback"]
with patch("asyncio.create_subprocess_exec", AsyncMock()) as spawn:
await UnifiedMobileController._spawn_scrcpy(command)
environment = spawn.call_args.kwargs["env"]
assert environment["ADB"] == adb
assert environment["ADB_SERVER_SOCKET"] == f"tcp:{'localhost' if port == 5037 else host}:{port}"
assert environment["ADB_HOST"] == host
assert environment["ADB_PORT"] == str(port)
assert spawn.call_args.args == tuple(command)
assert os.environ["ADB"] == "other-adb"
assert os.environ["ADB_SERVER_SOCKET"] == "tcp:unrelated:5999"
@pytest.mark.asyncio
async def test_scrcpy_does_not_fall_back_to_an_unselected_adb(monkeypatch):
monkeypatch.setattr("artemis.runtime.adb_endpoint.toolchain.resolve", lambda _: None)
with patch("asyncio.create_subprocess_exec", AsyncMock()) as spawn:
with pytest.raises(FileNotFoundError, match="adb"):
await UnifiedMobileController._spawn_scrcpy(["scrcpy"])
spawn.assert_not_awaited()
@pytest.mark.asyncio
async def test_direct_android_recording_also_uses_selected_adb(monkeypatch, tmp_path):
from artemis.drivers.android.adb_driver import AndroidAdbDriver
adb = str(tmp_path / "platform-tools" / "adb.exe")
monkeypatch.setattr("artemis.runtime.adb_endpoint.toolchain.resolve", lambda _: adb)
monkeypatch.setattr(settings, "ADB_HOST", "192.0.2.10")
monkeypatch.setattr(settings, "ADB_PORT", 5038)
driver = AndroidAdbDriver("fixture-device", MagicMock())
with patch("asyncio.create_subprocess_exec", AsyncMock()) as spawn:
await driver.start_video_recording(tmp_path)
assert spawn.await_count == 1
assert spawn.call_args.kwargs["env"]["ADB"] == adb
assert spawn.call_args.kwargs["env"]["ADB_SERVER_SOCKET"] == "tcp:192.0.2.10:5038"
@pytest.mark.asyncio
async def test_audio_extraction_rejects_silent_video_without_running_ffmpeg(tmp_path):
silent_video = tmp_path / "silent.mp4"