mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 21:35:59 +00:00
fix: report a gamescope that cannot start and ignore Agent answers that are not objects
This commit is contained in:
1 parent
3b6b304f55
commit
24f0b97c08
2 files changed
+27
-2
No files matched your search
@@ -1134,9 +1134,11 @@ def read_status(path):
|
||||
return None
|
||||
for encoding in ("utf-16", "utf-8-sig"):
|
||||
try:
|
||||
return json.loads(data.decode(encoding))
|
||||
value = json.loads(data.decode(encoding))
|
||||
except (UnicodeDecodeError, ValueError):
|
||||
continue
|
||||
if isinstance(value, dict):
|
||||
return value
|
||||
return None
|
||||
|
||||
|
||||
@@ -1211,7 +1213,11 @@ def agent_job(root, action, uid, product="", folder="", locale="enUS", country="
|
||||
except OSError:
|
||||
pass
|
||||
with open(output, "ab") as log:
|
||||
child = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=log, stderr=log, env=env)
|
||||
try:
|
||||
child = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=log, stderr=log, env=env)
|
||||
except OSError as error:
|
||||
emit("ERROR", "stopped gamescope: %s" % error)
|
||||
return 1
|
||||
seen = None
|
||||
while True:
|
||||
done = child.poll() is not None
|
||||
|
||||
@@ -1187,6 +1187,25 @@ class AgentJobTest(Harness):
|
||||
self.assertEqual(BNET["agent_job"](self.root, "uninstall", "gryphon", poll=0), 0)
|
||||
self.assertEqual(self.lines[-1], ("DONE", json.dumps({"uninstalled": "gryphon"})))
|
||||
|
||||
def test_a_gamescope_that_cannot_start_is_reported(self):
|
||||
self.install()
|
||||
|
||||
def missing(cmd, **kwargs):
|
||||
raise FileNotFoundError("gamescope")
|
||||
|
||||
with mock.patch.object(BNET["subprocess"], "Popen", missing):
|
||||
self.assertEqual(BNET["agent_job"](self.root, "update", "gryphon", poll=0), 1)
|
||||
self.assertEqual(self.lines[-1], ("ERROR", "stopped gamescope: gamescope"))
|
||||
|
||||
def test_an_agent_answer_that_is_not_an_object_is_ignored(self):
|
||||
path = self.tmp / "answer.json"
|
||||
for value in ([1, 2], "text", 3, None):
|
||||
with self.subTest(value):
|
||||
path.write_bytes(json.dumps(value).encode("utf-16"))
|
||||
self.assertIsNone(BNET["read_status"](str(path)))
|
||||
path.write_bytes(json.dumps({"state": 1004}).encode("utf-8"))
|
||||
self.assertEqual(BNET["read_status"](str(path)), {"state": 1004})
|
||||
|
||||
def test_a_large_agent_log_is_rotated_before_a_job(self):
|
||||
self.install()
|
||||
os.makedirs(self.tmp / "cache")
|
||||
|
||||
Reference in new issue
Block a user