Skip to content

let your agent control your phone

A cloud phone supports only the ops its host lists

ShawnPana7569e8946538
diff --git a/src/phone_harness/remote.py b/src/phone_harness/remote.py
index cb17118..90e1f3d 100644
--- a/src/phone_harness/remote.py
+++ b/src/phone_harness/remote.py
@@ -135,10 +135,13 @@ class Remote(Backend):
self._ops = set(self._call("GET", "/ops")["ops"])
return self._ops
+ # Ops answered here without asking the host: bookkeeping for a phone
+ # nobody's screen shows. Every other op, including the ones with a local
+ # method that only shapes the result, exists only if the host lists it.
+ LOCAL_OPS = frozenset({"session.refocus", "session.detail", "focus.probe", "focus.diff"})
+
def supports(self, op):
- # What the far side offers, plus the local bookkeeping ops (focus,
- # refocus) that mean nothing for a phone nobody's screen shows.
- return op in self._known() or getattr(self, self._slot(op), None) is not None
+ return op in self.LOCAL_OPS or op in self._known()
def send(self, op, **kw):
if not self.supports(op):
diff --git a/tests/test_transfer.py b/tests/test_transfer.py
index 7f5be43..adbd6c0 100644
--- a/tests/test_transfer.py
+++ b/tests/test_transfer.py
@@ -49,6 +49,18 @@ class FakePhone:
return "com.apple.mobilesafari"
+class RemoteSupport(unittest.TestCase):
+ def test_an_op_the_host_does_not_list_is_unsupported_even_with_a_local_method(self):
+ from phone_harness.remote import Remote
+ r = Remote("https://api.test/iphone/c/tok", "t")
+ r._ops = {"screen.capture", "input.tap"} # what the host said
+ self.assertTrue(r.supports("screen.capture"))
+ self.assertTrue(r.supports("focus.probe")) # local bookkeeping
+ self.assertFalse(r.supports("url.open")) # has _url_open, but the host lacks it
+ with self.assertRaises(Unsupported):
+ r.send("url.open", url="https://x")
+
+
class Transfer(unittest.TestCase):
def setUp(self):
Store.objects = {}