From b313f12043f094a1fad150bd4a9b6525c9ddeecd Mon Sep 17 00:00:00 2001 From: Lemelson <97357844+Lemelson@users.noreply.github.com> Date: Thu, 8 Oct 2026 14:38:16 +0300 Subject: [PATCH 1/2] Fix PyTCP compatibility for pymobiledevice3 9.31.0 --- .github/workflows/ci.yml | 6 +++-- CONTRIBUTING.md | 11 ++++++-- README.md | 15 +++++++++-- Tests/Python/test_dependencies.py | 44 +++++++++++++++++++++++++++++++ docs/COMPATIBILITY.md | 1 + docs/INSTALLATION.md | 8 +++++- docs/TROUBLESHOOTING.md | 34 +++++++++++++++++++++++- 7 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 Tests/Python/test_dependencies.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c8123a..f297b8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,8 +36,10 @@ jobs: uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 with: python-version: "3.13" - - name: Install worker dependency - run: python -m pip install 'pymobiledevice3==9.31.0' + - name: Install compatible worker dependencies + run: python -m pip install 'pymobiledevice3==9.31.0' 'pmd-pytcp>=0.0.4,<0.1.0' + - name: Check installed dependencies + run: python -m pip check - name: Run worker tests env: PYTHONDONTWRITEBYTECODE: "1" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 17b6872..45bb28b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,14 +16,21 @@ Use GitHub Security Advisories, not a public issue, for security or privacy bugs ```bash brew install uv -uv tool install --python 3.13 'pymobiledevice3==9.31.0' +uv tool install --python 3.13 --with 'pmd-pytcp>=0.0.4,<0.1.0' \ + 'pymobiledevice3==9.31.0' swift test -PYTHONDONTWRITEBYTECODE=1 uv run --with 'pymobiledevice3==9.31.0' \ +PYTHONDONTWRITEBYTECODE=1 uv run --python 3.13 \ + --with 'pymobiledevice3==9.31.0' --with 'pmd-pytcp>=0.0.4,<0.1.0' \ python -m unittest discover -s Tests/Python -v ``` See [Installation](docs/INSTALLATION.md) for the complete setup. +The transitive `pmd-pytcp` bound is required by pymobiledevice3 9.31.0's +synchronous tunnel API. Keep installation, test commands, and CI aligned when +changing either dependency. The Python suite checks the real installed API; +it does not replace physical-iPhone tests of Start, Restore GPS, and reconnect. + ## Pull requests - Keep changes focused and explain the user-visible behavior. diff --git a/README.md b/README.md index 978c1b5..ed1d2af 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ GeoShift does not attempt to conceal simulation or bypass third-party rules. | Swift | 6.2 or newer | | Python | 3.11–3.13; 3.13 recommended | | pymobiledevice3 | 9.31.0 | +| pmd-pytcp | >=0.0.4, <0.1.0 (synchronous API) | | Physical iPhone | iOS 17+ with Developer Mode | | Cable-free pairing | iOS 27 RemotePairing; currently beta-tested | | iOS Simulator | Not targeted; use Xcode's built-in controls | @@ -84,9 +85,14 @@ Install the backend in an isolated `uv` environment: ```bash brew install uv -uv tool install --python 3.13 'pymobiledevice3==9.31.0' +uv tool install --python 3.13 --with 'pmd-pytcp>=0.0.4,<0.1.0' \ + 'pymobiledevice3==9.31.0' ``` +Keep the `pmd-pytcp` bound: pymobiledevice3 9.31.0 uses its synchronous API, +which changed in 0.1.0. For an existing installation, use the +[backend repair command](docs/TROUBLESHOOTING.md#queuefull-or-unawaited-coroutine-errors). + Clone, build, and install GeoShift: ```bash @@ -143,7 +149,8 @@ and apply it again; choose **Restore GPS** before restarting whenever possible. ```bash swift test -PYTHONDONTWRITEBYTECODE=1 uv run --with 'pymobiledevice3==9.31.0' \ +PYTHONDONTWRITEBYTECODE=1 uv run --python 3.13 \ + --with 'pymobiledevice3==9.31.0' --with 'pmd-pytcp>=0.0.4,<0.1.0' \ python -m unittest discover -s Tests/Python -v ./Scripts/package_app.sh release ``` @@ -151,6 +158,10 @@ PYTHONDONTWRITEBYTECODE=1 uv run --with 'pymobiledevice3==9.31.0' \ The package script builds the localized resource bundle, creates `GeoShift.app`, and applies an ad-hoc signature. +Python tests check the installed backend versions and the real synchronous +PyTCP API without opening a tunnel. Connecting, changing location, and verifying +Restore GPS in Maps still require a physical iPhone. + ## Documentation - [Installation](docs/INSTALLATION.md) diff --git a/Tests/Python/test_dependencies.py b/Tests/Python/test_dependencies.py new file mode 100644 index 0000000..2842c2f --- /dev/null +++ b/Tests/Python/test_dependencies.py @@ -0,0 +1,44 @@ +"""Guard the real userspace-tunnel dependency contract without an iPhone.""" + +import inspect +import unittest +from importlib.metadata import version + +from packaging.specifiers import SpecifierSet +from pmd_pytcp import stack +from pmd_pytcp.socket.tcp__socket import TcpSocket +from pmd_pytcp.socket.udp__socket import UdpSocket + + +class DependencyCompatibilityTests(unittest.TestCase): + def test_installed_backend_versions_are_compatible(self): + for package, supported in ( + ("pymobiledevice3", "==9.31.0"), + ("pmd-pytcp", ">=0.0.4,<0.1.0"), + ): + with self.subTest(package=package): + installed = version(package) + self.assertIn( + installed, + SpecifierSet(supported), + f"{package} {installed} is incompatible; install {package}{supported}", + ) + + def test_userspace_tunnel_dependencies_have_synchronous_api(self): + # pymobiledevice3 9.31.0 calls these functions directly or in a thread. + # Async replacements return unawaited coroutines and can flood its queue. + for owner, methods in ( + (stack, ("start", "stop")), + (TcpSocket, ("connect", "send", "recv", "close")), + (UdpSocket, ("recv", "sendto", "close")), + ): + for name in methods: + with self.subTest(owner=owner.__name__, method=name): + self.assertFalse( + inspect.iscoroutinefunction(getattr(owner, name)), + f"{owner.__name__}.{name} must be synchronous for pymobiledevice3 9.31.0", + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/docs/COMPATIBILITY.md b/docs/COMPATIBILITY.md index 476c705..fe710ad 100644 --- a/docs/COMPATIBILITY.md +++ b/docs/COMPATIBILITY.md @@ -6,6 +6,7 @@ | Swift | 6.2+ | Required by `Package.swift` | | Python | 3.11–3.13 | Python 3.13 is recommended | | pymobiledevice3 | 9.31.0 | Installed separately, not bundled | +| pmd-pytcp | >=0.0.4, <0.1.0 | Synchronous API required by pymobiledevice3 9.31.0 | | Physical iPhone | iOS 17+ | Developer Mode and a trusted Mac are required | | iOS 27 Wi-Fi pairing | Beta-tested | Device-initiated RemotePairing, no cable required | | Older iOS pairing | USB first | Later trusted Wi-Fi reconnect may work | diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md index 70f7008..1a1a178 100644 --- a/docs/INSTALLATION.md +++ b/docs/INSTALLATION.md @@ -10,6 +10,7 @@ ad-hoc signed macOS app, copies it to `/Applications`, and opens it. - Xcode 26 or a Swift 6.2 toolchain - Python 3.11–3.13 - `pymobiledevice3` 9.31.0 +- `pmd-pytcp` >=0.0.4, <0.1.0 (the synchronous API required by that backend) - a physical iPhone with Developer Mode enabled GeoShift does not target the iOS Simulator. Xcode already includes location @@ -21,10 +22,15 @@ The recommended installation keeps `pymobiledevice3` isolated with `uv`: ```bash brew install uv -uv tool install --python 3.13 'pymobiledevice3==9.31.0' +uv tool install --python 3.13 --with 'pmd-pytcp>=0.0.4,<0.1.0' \ + 'pymobiledevice3==9.31.0' ``` GeoShift also checks common Homebrew, pipx, and local-bin locations. +Those environments must use the same compatible versions. The app selects an +existing interpreter; packaging does not install or repair Python dependencies. +For an existing incompatible uv installation, use the +[backend repair command](TROUBLESHOOTING.md#queuefull-or-unawaited-coroutine-errors). ## Build and install GeoShift diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md index 394ed53..306f55c 100644 --- a/docs/TROUBLESHOOTING.md +++ b/docs/TROUBLESHOOTING.md @@ -37,11 +37,43 @@ signal; Maps is the practical sensor-side verification. ```bash brew install uv -uv tool install --python 3.13 'pymobiledevice3==9.31.0' +uv tool install --python 3.13 --with 'pmd-pytcp>=0.0.4,<0.1.0' \ + 'pymobiledevice3==9.31.0' ``` Then reopen GeoShift. +## `QueueFull` or unawaited coroutine errors + +If the iPhone is already trusted but the tunnel fails with `QueueFull` or +warnings that `start`, `connect`, `recv`, or `send` was never awaited, check the +backend environment. pymobiledevice3 9.31.0 calls the synchronous PyTCP API; +`pmd-pytcp` 0.1.0 and newer changed those methods to async. + +Repair an existing uv installation by recreating the tool environment: + +```bash +uv tool install --force --python 3.13 --with 'pmd-pytcp>=0.0.4,<0.1.0' \ + 'pymobiledevice3==9.31.0' +``` + +Then choose **Restart** in GeoShift so the worker uses the repaired environment. +For a pipx or Homebrew backend, apply the same dependency bounds in the Python +environment GeoShift actually selects, or install the recommended uv backend. +Re-pairing the phone does not resolve this API mismatch. + +The rapid `QueueFull` flood comes from upstream asyncio callbacks within a +tunnel attempt. GeoShift's reconnect delay does not rate-limit those callbacks; +log rotation limits disk use but does not stop the error loop. The compatible +dependency bound removes this known trigger. General error deduplication remains +a separate improvement; pending Restore GPS requests must keep retrying. + +While restoring, the interface currently says it is waiting for a trusted +connection even when diagnostics contain a tunnel/backend error. That text alone +does not prove that trust or pairing is broken. Inspect diagnostics before +re-pairing; distinguishing device discovery from tunnel failure in the interface +remains a separate improvement. + ## Command-Q is refused GeoShift stays open when it cannot confirm either a completed clear or a durable From 8e80e3e9ee947a64fe7fa0ab22c38de6e9d61e77 Mon Sep 17 00:00:00 2001 From: Lemelson <97357844+Lemelson@users.noreply.github.com> Date: Tue, 3 Nov 2026 00:25:52 +0100 Subject: [PATCH 2/2] Detect incompatible pmd-pytcp before opening a tunnel pymobiledevice3 9.x calls PyTCP synchronously; pmd-pytcp 0.1.0+ is async, so an unpinned backend never opens a tunnel and floods QueueFull. The worker now checks this up front, logs the repair command once a minute, and reports problem=incompatibleBackend in status.json, which the app shows as a dedicated status message. Restore GPS keeps retrying. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 15 ++++ Sources/GeoShift/KeeperController.swift | 11 ++- .../Resources/en.lproj/Localizable.strings | 1 + Sources/GeoShift/Resources/keeper.py | 60 +++++++++++++++ .../Resources/ru.lproj/Localizable.strings | 1 + Sources/GeoShift/StatusParser.swift | 14 ++++ Sources/GeoShift/WorkerStatus.swift | 1 + Tests/GeoShiftTests/LocalizationTests.swift | 2 + Tests/GeoShiftTests/StatusParserTests.swift | 41 ++++++++++ Tests/Python/test_keeper.py | 77 +++++++++++++++++++ docs/TROUBLESHOOTING.md | 20 +++-- 11 files changed, 232 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 574d363..13b04e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to GeoShift are documented here. +## Unreleased + +### Fixed + +- Fresh backend installs no longer resolve `pmd-pytcp` 0.1.0 or newer, whose + async API breaks pymobiledevice3 9.31.0's userspace tunnel and floods the log + with `asyncio.queues.QueueFull` ([#4](https://github.com/Lemelson/GeoShift/issues/4)). + Installation, test, and CI commands now pin `pmd-pytcp>=0.0.4,<0.1.0`. + +### Added + +- The worker detects an incompatible `pmd-pytcp` before opening a tunnel, logs + the repair command once a minute instead of looping on `QueueFull`, and the + app shows a dedicated status message. + ## 1.5.2 — 2026-07-21 ### Added diff --git a/Sources/GeoShift/KeeperController.swift b/Sources/GeoShift/KeeperController.swift index 1d8ffe9..aecd0ba 100644 --- a/Sources/GeoShift/KeeperController.swift +++ b/Sources/GeoShift/KeeperController.swift @@ -271,10 +271,15 @@ final class KeeperController { configuration: configuration, workerStatus: workerStatus ) - detail = statusDetail( - state: state, - configuration: configuration + detail = StatusParser.hasIncompatibleBackend( + configuration: configuration, + workerStatus: workerStatus ) + ? localization.text("status.incompatibleBackend") + : statusDetail( + state: state, + configuration: configuration + ) } private func recoverOnLaunch() async { diff --git a/Sources/GeoShift/Resources/en.lproj/Localizable.strings b/Sources/GeoShift/Resources/en.lproj/Localizable.strings index 4e5590f..98046f5 100644 --- a/Sources/GeoShift/Resources/en.lproj/Localizable.strings +++ b/Sources/GeoShift/Resources/en.lproj/Localizable.strings @@ -94,6 +94,7 @@ "status.gpsEvery" = "GPS refresh every"; "status.connecting" = "The background service is connecting"; "status.notConfirmed" = "Real GPS is not confirmed; choose Restore GPS"; +"status.incompatibleBackend" = "The pymobiledevice3 backend has an incompatible pmd-pytcp. Repair it with the command in Diagnostics, then choose Restart."; "error.commandFailed" = "The command failed."; "error.previousOperation" = "The previous operation failed. Try again or open Diagnostics for connection details."; diff --git a/Sources/GeoShift/Resources/keeper.py b/Sources/GeoShift/Resources/keeper.py index 0612408..9bd6b23 100644 --- a/Sources/GeoShift/Resources/keeper.py +++ b/Sources/GeoShift/Resources/keeper.py @@ -5,6 +5,7 @@ import asyncio import errno import fcntl +import inspect import json import logging import math @@ -12,6 +13,7 @@ import signal import time from contextlib import suppress +from importlib import metadata from logging.handlers import RotatingFileHandler from pathlib import Path @@ -42,6 +44,10 @@ STOP_GRACE_SECONDS = 12 APP_HEARTBEAT_TIMEOUT_SECONDS = 5 * 60 APP_HEARTBEAT_FUTURE_TOLERANCE_SECONDS = 60 +BACKEND_REPAIR_COMMAND = ( + "uv tool install --force --python 3.13 --with 'pmd-pytcp>=0.0.4,<0.1.0' " + "'pymobiledevice3==9.31.0'" +) class ConfigurationError(ValueError): @@ -52,6 +58,10 @@ class AmbiguousDeviceError(RuntimeError): pass +class IncompatibleBackendError(RuntimeError): + pass + + class AppCleanupLease: def __init__(self, descriptor: int): self.descriptor = descriptor @@ -229,6 +239,7 @@ def write_status( message: str | None = None, path: Path | None = None, required: bool = False, + problem: str | None = None, ) -> None: path = path or STATUS_PATH payload = { @@ -239,6 +250,8 @@ def write_status( "message": message, "updatedAt": time.time(), } + if problem: + payload["problem"] = problem path.parent.mkdir(parents=True, exist_ok=True) temporary_path = path.with_name(f".{path.name}.{os.getpid()}.tmp") try: @@ -308,7 +321,36 @@ async def resolve_target_device(saved_udid: str | None) -> tuple[str, bool]: return available_udids[0], False +def backend_incompatibility( + pymobiledevice3_version: str | None = None, + pytcp_start=None, +) -> str | None: + # pymobiledevice3 9.x calls the synchronous PyTCP API. pmd-pytcp 0.1.0+ + # made it async, so the tunnel never opens and asyncio floods QueueFull. + try: + pymobiledevice3_version = pymobiledevice3_version or metadata.version("pymobiledevice3") + if pytcp_start is None: + from pmd_pytcp import stack + + pytcp_start = stack.start + except (ImportError, metadata.PackageNotFoundError): + return None + if not pymobiledevice3_version.startswith("9.") or not inspect.iscoroutinefunction(pytcp_start): + return None + try: + pytcp_version = metadata.version("pmd-pytcp") + except metadata.PackageNotFoundError: + pytcp_version = "unknown" + return ( + f"pmd-pytcp {pytcp_version} is incompatible with pymobiledevice3 " + f"{pymobiledevice3_version}; repair the backend with: {BACKEND_REPAIR_COMMAND}" + ) + + async def open_target_tunnel(target_udid: str, uses_remote_pairing: bool): + problem = backend_incompatibility() + if problem: + raise IncompatibleBackendError(problem) tunnel = UserspaceRsdTunnel(serial=target_udid, autopair=not uses_remote_pairing) if not uses_remote_pairing: return tunnel, await asyncio.wait_for(tunnel.aopen(), timeout=CONNECT_TIMEOUT_SECONDS) @@ -456,6 +498,7 @@ async def run_worker(stop_event: asyncio.Event) -> None: target_udid = previous_status.get("deviceUDID") if simulation_may_be_active else None last_logged_request_id = "" waiting_log_time = 0.0 + backend_log_time = 0.0 expired_heartbeat_request = "" cleanup_lease = None @@ -643,6 +686,23 @@ async def run_worker(stop_event: asyncio.Event) -> None: target_udid, message, ) + except IncompatibleBackendError as error: + now = time.monotonic() + if now - backend_log_time >= 60: + logger.error("%s", error) + backend_log_time = now + should_simulate, cleanup_lease = simulation_request_decision( + config, + cleanup_lease, + ) + write_status( + "failed" if should_simulate else "clearPending", + config["requestID"], + simulation_may_be_active, + target_udid, + str(error), + problem="incompatibleBackend", + ) except AmbiguousDeviceError as error: logger.error("%s", error) write_status( diff --git a/Sources/GeoShift/Resources/ru.lproj/Localizable.strings b/Sources/GeoShift/Resources/ru.lproj/Localizable.strings index 3de6c5f..adbcc20 100644 --- a/Sources/GeoShift/Resources/ru.lproj/Localizable.strings +++ b/Sources/GeoShift/Resources/ru.lproj/Localizable.strings @@ -93,6 +93,7 @@ "status.active" = "Симуляция активна"; "status.gpsEvery" = "GPS каждые"; "status.connecting" = "Фоновый сервис подключается"; +"status.incompatibleBackend" = "В бэкенде pymobiledevice3 несовместимая версия pmd-pytcp. Почините его командой из диагностики и нажмите «Перезапустить»."; "status.notConfirmed" = "Реальный GPS не подтверждён; нажмите «Вернуть GPS»"; "error.commandFailed" = "Команда завершилась с ошибкой."; diff --git a/Sources/GeoShift/StatusParser.swift b/Sources/GeoShift/StatusParser.swift index 4a56f48..0a8df85 100644 --- a/Sources/GeoShift/StatusParser.swift +++ b/Sources/GeoShift/StatusParser.swift @@ -1,6 +1,20 @@ import Foundation enum StatusParser { + static let incompatibleBackendProblem = "incompatibleBackend" + + static func hasIncompatibleBackend( + configuration: KeeperConfiguration?, + workerStatus: WorkerStatus? + ) -> Bool { + guard let configuration, let workerStatus else { + return false + } + return workerStatus.requestID == configuration.requestID + && workerStatus.problem == incompatibleBackendProblem + && [.failed, .clearPending].contains(workerStatus.phase) + } + static func state( launchctlOutput: String, configuration: KeeperConfiguration?, diff --git a/Sources/GeoShift/WorkerStatus.swift b/Sources/GeoShift/WorkerStatus.swift index c3c1255..45e770f 100644 --- a/Sources/GeoShift/WorkerStatus.swift +++ b/Sources/GeoShift/WorkerStatus.swift @@ -19,4 +19,5 @@ struct WorkerStatus: Codable, Equatable, Sendable { let simulationMayBeActive: Bool let message: String? let updatedAt: Double + var problem: String? = nil } diff --git a/Tests/GeoShiftTests/LocalizationTests.swift b/Tests/GeoShiftTests/LocalizationTests.swift index 12deb99..9c3b2b1 100644 --- a/Tests/GeoShiftTests/LocalizationTests.swift +++ b/Tests/GeoShiftTests/LocalizationTests.swift @@ -39,11 +39,13 @@ struct LocalizationTests { #expect(localization.text("header.subtitle") == "Control iPhone GPS simulation from your Mac") #expect(localization.text("settings.language") == "App language") #expect(AppLanguage.english.selectionLabel == "🇬🇧 English") + #expect(localization.text("status.incompatibleBackend").contains("pmd-pytcp")) localization.language = .russian #expect(localization.text("header.subtitle").contains("симуляцией GPS")) #expect(localization.text("settings.language") == "Язык приложения") #expect(AppLanguage.russian.selectionLabel == "🇷🇺 Русский") + #expect(localization.text("status.incompatibleBackend").contains("«Перезапустить»")) #expect(KeeperError.commandFailed("The command timed out after 5 seconds.") .description(using: localization) == "Команда завершилась с ошибкой.") } diff --git a/Tests/GeoShiftTests/StatusParserTests.swift b/Tests/GeoShiftTests/StatusParserTests.swift index c93c53e..a5e7a04 100644 --- a/Tests/GeoShiftTests/StatusParserTests.swift +++ b/Tests/GeoShiftTests/StatusParserTests.swift @@ -134,6 +134,47 @@ struct StatusParserTests { ) } + @Test("An incompatible backend reported for the current request is surfaced") + func incompatibleBackendIsSurfaced() throws { + var failed = status(.failed, mayBeActive: false) + failed.problem = StatusParser.incompatibleBackendProblem + var pending = status(.clearPending, mayBeActive: true) + pending.problem = StatusParser.incompatibleBackendProblem + var recovered = status(.active, mayBeActive: true) + recovered.problem = StatusParser.incompatibleBackendProblem + + #expect(StatusParser.hasIncompatibleBackend(configuration: enabled, workerStatus: failed)) + #expect(StatusParser.hasIncompatibleBackend( + configuration: configuration(enabled: false), + workerStatus: pending + )) + #expect(!StatusParser.hasIncompatibleBackend(configuration: enabled, workerStatus: recovered)) + #expect(!StatusParser.hasIncompatibleBackend( + configuration: enabled, + workerStatus: status(.failed, mayBeActive: false) + )) + + let otherRequest = WorkerStatus( + phase: .failed, + requestID: "old-request", + deviceUDID: "phone", + simulationMayBeActive: false, + message: nil, + updatedAt: 0, + problem: StatusParser.incompatibleBackendProblem + ) + #expect(!StatusParser.hasIncompatibleBackend(configuration: enabled, workerStatus: otherRequest)) + } + + @Test("Worker status decodes with and without a problem code") + func problemCodeIsOptional() throws { + let legacy = Data(#"{"phase":"failed","requestID":"request","deviceUDID":null,"simulationMayBeActive":false,"message":null,"updatedAt":1}"#.utf8) + let current = Data(#"{"phase":"failed","requestID":"request","deviceUDID":null,"simulationMayBeActive":false,"message":"x","updatedAt":1,"problem":"incompatibleBackend"}"#.utf8) + + #expect(try JSONDecoder().decode(WorkerStatus.self, from: legacy).problem == nil) + #expect(try JSONDecoder().decode(WorkerStatus.self, from: current).problem == "incompatibleBackend") + } + private func status(_ phase: WorkerStatus.Phase, mayBeActive: Bool) -> WorkerStatus { WorkerStatus( phase: phase, diff --git a/Tests/Python/test_keeper.py b/Tests/Python/test_keeper.py index 8ec3d5c..30ba62a 100644 --- a/Tests/Python/test_keeper.py +++ b/Tests/Python/test_keeper.py @@ -387,6 +387,7 @@ async def aopen(self): return provider with ( + patch.object(keeper, "backend_incompatibility", return_value=None), patch.object(keeper, "UserspaceRsdTunnel", FakeTunnel), patch.object( keeper.tunnel_service, @@ -436,5 +437,81 @@ async def must_not_resolve(*args, **kwargs): await keeper.run_worker(asyncio.Event()) +class BackendCompatibilityTests(unittest.IsolatedAsyncioTestCase): + def test_async_pytcp_is_reported_for_pymobiledevice3_9(self): + async def async_start(): + pass + + problem = keeper.backend_incompatibility("9.31.0", async_start) + + self.assertIn("incompatible with pymobiledevice3 9.31.0", problem) + self.assertIn(keeper.BACKEND_REPAIR_COMMAND, problem) + + def test_synchronous_pytcp_and_newer_backends_are_not_flagged(self): + async def async_start(): + pass + + def sync_start(): + pass + + self.assertIsNone(keeper.backend_incompatibility("9.31.0", sync_start)) + self.assertIsNone(keeper.backend_incompatibility("10.0.0", async_start)) + + async def test_incompatible_backend_never_opens_a_tunnel(self): + class MustNotOpen: + def __init__(self, *args, **kwargs): + raise AssertionError("An incompatible backend must not start a tunnel") + + with ( + patch.object(keeper, "backend_incompatibility", return_value="pmd-pytcp is async"), + patch.object(keeper, "UserspaceRsdTunnel", MustNotOpen), + ): + with self.assertRaises(keeper.IncompatibleBackendError): + await keeper.open_target_tunnel("target-phone", False) + + async def test_incompatible_backend_keeps_restore_pending_with_problem_code(self): + with tempfile.TemporaryDirectory() as directory: + config_path = Path(directory) / "config.json" + status_path = Path(directory) / "status.json" + config_path.write_text(json.dumps({ + "cityID": "moscow", + "cityName": "Москва", + "country": "Россия", + "latitude": 55.7558, + "longitude": 37.6173, + "retrySeconds": 5, + "refreshSeconds": 10, + "requestID": "restore-request", + "simulationEnabled": False, + })) + stop_event = asyncio.Event() + + async def target_phone(saved_udid): + return "target-phone", True + + async def stop_after_first_attempt(*args, **kwargs): + stop_event.set() + return False + + with ( + patch.object(keeper, "CONFIG_PATH", config_path), + patch.object(keeper, "STATUS_PATH", status_path), + patch.object(keeper, "resolve_target_device", target_phone), + patch.object(keeper, "backend_incompatibility", return_value="pmd-pytcp is async"), + patch.object( + keeper, + "wait_until_timeout_or_config_change", + stop_after_first_attempt, + ), + ): + await keeper.run_worker(stop_event) + + status = keeper.read_status(status_path) + self.assertEqual(status["phase"], "clearPending") + self.assertEqual(status["problem"], "incompatibleBackend") + self.assertEqual(status["message"], "pmd-pytcp is async") + self.assertTrue(status["simulationMayBeActive"]) + + if __name__ == "__main__": unittest.main() diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md index 306f55c..9b49032 100644 --- a/docs/TROUBLESHOOTING.md +++ b/docs/TROUBLESHOOTING.md @@ -50,6 +50,11 @@ warnings that `start`, `connect`, `recv`, or `send` was never awaited, check the backend environment. pymobiledevice3 9.31.0 calls the synchronous PyTCP API; `pmd-pytcp` 0.1.0 and newer changed those methods to async. +Current GeoShift builds check this before opening a tunnel: the status says +the backend has an incompatible `pmd-pytcp`, and Diagnostics show the repair +command below once a minute instead of a `QueueFull` flood. Older builds show +only the flood. + Repair an existing uv installation by recreating the tool environment: ```bash @@ -65,14 +70,13 @@ Re-pairing the phone does not resolve this API mismatch. The rapid `QueueFull` flood comes from upstream asyncio callbacks within a tunnel attempt. GeoShift's reconnect delay does not rate-limit those callbacks; log rotation limits disk use but does not stop the error loop. The compatible -dependency bound removes this known trigger. General error deduplication remains -a separate improvement; pending Restore GPS requests must keep retrying. - -While restoring, the interface currently says it is waiting for a trusted -connection even when diagnostics contain a tunnel/backend error. That text alone -does not prove that trust or pairing is broken. Inspect diagnostics before -re-pairing; distinguishing device discovery from tunnel failure in the interface -remains a separate improvement. +dependency bound and the pre-tunnel check remove this known trigger. General +error deduplication remains a separate improvement; pending Restore GPS +requests keep retrying and send the clear after the repair and **Restart**. + +For other tunnel errors, the interface still says Restore GPS is waiting for a +trusted connection. That text alone does not prove that trust or pairing is +broken. Inspect diagnostics before re-pairing. ## Command-Q is refused