fix(droiddeckctl): logs latest works without root

`logs latest` pulled the session folder under getFilesDir(), which adb
cannot read on an unrooted device, so it always failed with "Permission
denied" and droiddeck-scenario kept no logs for failed runs.

The agent bridge gets a `logs` method that writes the Share logs archive
to the app's external files folder (agent-logs/), and droiddeckctl pulls
that zip and unpacks it into the destination with the session's files at
the top, as before. Builds without the method still get the old pull.
This commit is contained in:
angelrenefm authored and Kurt Himebauch committed 2026-11-05 13:52:43 -05:00
1 parent 4b6cba0a6d
commit 2fb066507a
7 files changed
+128 -6

No files matched your search

+29 -1
View File
@@ -16,6 +16,7 @@ import sys
import tempfile
import time
import uuid
import zipfile
import zlib
from pathlib import Path
@@ -421,6 +422,23 @@ def start_session(adb: str, serial: str, request: dict) -> dict:
return confirm_start(adb, serial, request, current["session"])
def unpack_logs(archive: Path, destination: Path, session_id: str) -> None:
"""Unpack a Share logs zip so the session's own files sit at the top of destination."""
try:
with zipfile.ZipFile(archive) as z:
for entry in z.infolist():
name = entry.filename
if name.startswith(session_id + "/"):
name = name[len(session_id) + 1:]
target = (destination / name).resolve()
if entry.is_dir() or not name or not target.is_relative_to(destination):
continue
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(z.read(entry))
except (OSError, zipfile.BadZipFile) as exc:
raise ControlError(f"Could not unpack the session logs: {exc}", "LOG_PULL_FAILED") from exc
def require_commands(adb: str, serial: str) -> dict:
access = checked(provider_call(adb, serial, "access"), "ACCESS_FAILED")
if access.get("commands") is not True:
@@ -741,7 +759,17 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict:
if not remote_dir or not session.get("id") or not session.get("artifactsAvailable"):
raise ControlError("No session artifact directory is available", "NO_SESSION_LOGS")
destination = Path(args.destination or session["id"]).expanduser().resolve()
result = run_adb(adb, serial, "pull", remote_dir, str(destination), timeout=120)
exported = provider_call(adb, serial, "logs", timeout=args.timeout + 40)
if (exported.get("error") or {}).get("code") == "UNKNOWN_COMMAND":
# Older builds have no logs method; their private folder only pulls on a rooted device.
result = run_adb(adb, serial, "pull", remote_dir, str(destination), timeout=120)
else:
zip_path = checked(exported, "LOG_PULL_FAILED")["zip"]
with tempfile.TemporaryDirectory() as temp:
local_zip = Path(temp) / "logs.zip"
result = run_adb(adb, serial, "pull", zip_path, str(local_zip), timeout=120)
if result.returncode == 0:
unpack_logs(local_zip, destination, exported.get("sessionId") or session["id"])
if result.returncode != 0:
detail = (result.stderr or result.stdout).decode(errors="replace").strip()
raise ControlError(detail or "adb pull failed", "LOG_PULL_FAILED")