mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
fix: wait for Steam navigation readiness
This commit is contained in:
1 parent
ea8feebea7
commit
ab7390e844
4 files changed
+81
-6
No files matched your search
@@ -1032,6 +1032,28 @@ def request_timeout(req, default):
|
||||
return timeout
|
||||
|
||||
|
||||
def wait_for_steam_ui(agent_dir, timeout=120):
|
||||
"""Wait for Steam's initialized shared app store before sending a navigation URL."""
|
||||
timeout = request_timeout({"timeout": timeout}, 120)
|
||||
deadline = time.monotonic() + timeout
|
||||
expression = "Boolean(globalThis.appStore?.m_bIsInitialized)"
|
||||
while True:
|
||||
remaining = deadline - time.monotonic()
|
||||
if remaining <= 0:
|
||||
raise AgentError("STEAM_UI_TIMEOUT", "Steam's UI router did not become ready")
|
||||
try:
|
||||
result = cdp_eval(agent_dir, expression, await_promise=False,
|
||||
timeout=min(5, max(0.25, remaining)))
|
||||
if result.get("value") is True:
|
||||
return
|
||||
except OSError:
|
||||
pass
|
||||
except AgentError as error:
|
||||
if error.code not in ("NO_DEVTOOLS", "DEVTOOLS_UNREACHABLE", "NO_TARGET", "TIMEOUT"):
|
||||
raise
|
||||
time.sleep(min(0.25, max(0, deadline - time.monotonic())))
|
||||
|
||||
|
||||
def handle(agent_dir, req):
|
||||
kind = req.get("kind")
|
||||
if kind == "ping":
|
||||
@@ -1055,6 +1077,7 @@ def handle(agent_dir, req):
|
||||
if not isinstance(url, str) or not re.fullmatch(
|
||||
r"steam://(?:open/downloads|uninstall/[1-9][0-9]{0,9})", url):
|
||||
raise AgentError("INVALID_REQUEST", "Steam navigation URL is not supported")
|
||||
wait_for_steam_ui(agent_dir, req.get("timeout", 120))
|
||||
try:
|
||||
subprocess.Popen(["steam", url], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL, start_new_session=True)
|
||||
|
||||
@@ -197,13 +197,30 @@ class AgentTest(unittest.TestCase):
|
||||
self.assertEqual("UNAVAILABLE", answer["error"]["code"])
|
||||
|
||||
def test_steam_url_uses_client_argv_for_supported_navigation(self):
|
||||
with patch.object(agent.subprocess, "Popen") as popen:
|
||||
with patch.object(agent, "wait_for_steam_ui") as ready, patch.object(agent.subprocess, "Popen") as popen:
|
||||
answer = self.ask({"kind": "steam-url", "url": "steam://open/downloads"})
|
||||
self.assertTrue(answer["ok"])
|
||||
self.assertTrue(answer["launched"])
|
||||
ready.assert_called_once_with(self.dir, 120)
|
||||
self.assertEqual(["steam", "steam://open/downloads"], popen.call_args.args[0])
|
||||
self.assertTrue(popen.call_args.kwargs["start_new_session"])
|
||||
|
||||
def test_steam_url_waits_for_initialized_ui_router(self):
|
||||
with patch.object(agent, "cdp_eval", side_effect=[OSError("DevTools restarted"),
|
||||
{"value": False}, {"value": True}]) as evaluate, \
|
||||
patch.object(agent.time, "sleep"):
|
||||
agent.wait_for_steam_ui(self.dir, timeout=2)
|
||||
self.assertEqual(3, evaluate.call_count)
|
||||
self.assertIn("appStore", evaluate.call_args.args[1])
|
||||
|
||||
def test_steam_url_is_not_forwarded_when_ui_readiness_times_out(self):
|
||||
with patch.object(agent, "wait_for_steam_ui", side_effect=agent.AgentError("STEAM_UI_TIMEOUT", "not ready")), \
|
||||
patch.object(agent.subprocess, "Popen") as popen:
|
||||
answer = self.ask({"kind": "steam-url", "url": "steam://open/downloads"})
|
||||
self.assertFalse(answer["ok"])
|
||||
self.assertEqual("STEAM_UI_TIMEOUT", answer["error"]["code"])
|
||||
popen.assert_not_called()
|
||||
|
||||
def test_steam_url_rejects_untrusted_routes_and_argument_injection(self):
|
||||
for url in ("steam://open/settings", "steam://nav/library", "steam://open/downloads\n--exec", "https://example.com"):
|
||||
with self.subTest(url=url), patch.object(agent.subprocess, "Popen") as popen:
|
||||
|
||||
Reference in new issue
Block a user