Agent Zero AI framework
Fix Office desktop runtime on arm64
Alessandro6d9dedb82176
diff --git a/docker/run/fs/ins/install_additional.sh b/docker/run/fs/ins/install_additional.shindex 1b7c10368..6237d649c 100644--- a/docker/run/fs/ins/install_additional.sh+++ b/docker/run/fs/ins/install_additional.sh@@ -101,8 +101,6 @@ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \gvfs \libglib2.0-bin \xfce4-terminal \- pulseaudio \- pulseaudio-utils \x11-xserver-utils \xdotool \xauth \diff --git a/helpers/virtual_desktop.py b/helpers/virtual_desktop.pyindex 3e2cf5f3a..55d33808f 100644--- a/helpers/virtual_desktop.py+++ b/helpers/virtual_desktop.py@@ -120,6 +120,9 @@ def session_url(token: str, *, title: str = "Desktop") -> str:{"path": base_path,"title": title,+ "encoding": "jpeg",+ "quality": "85",+ "speed": "80","sharing": "true","clipboard": "true","clipboard_direction": "both",@@ -127,7 +130,7 @@ def session_url(token: str, *, title: str = "Desktop") -> str:"clipboard_preferred_format": "text/plain","printing": "true","file_transfer": "true",- "sound": "true",+ "sound": "false","offscreen": "false","floating_menu": "false","xpramenu": "false",diff --git a/plugins/_office/helpers/libreoffice_desktop.py b/plugins/_office/helpers/libreoffice_desktop.pyindex 07bce12aa..19d4c927a 100644--- a/plugins/_office/helpers/libreoffice_desktop.py+++ b/plugins/_office/helpers/libreoffice_desktop.py@@ -1035,8 +1035,6 @@ def collect_desktop_status() -> dict[str, Any]:"xfce4-terminal": shutil.which("xfce4-terminal") or "","xfce4-settings-manager": shutil.which("xfce4-settings-manager") or "","gio": shutil.which("gio") or "",- "pulseaudio": shutil.which("pulseaudio") or "",- "pactl": shutil.which("pactl") or "",}missing = [name@@ -1046,8 +1044,6 @@ def collect_desktop_status() -> dict[str, Any]:"xfce4-terminal","xfce4-settings-manager","gio",- "pulseaudio",- "pactl",)if not binaries[name]]@@ -1152,10 +1148,12 @@ def _xpra_shadow_command(xpra: str, session: DesktopSession) -> list[str]:"--open-files=no","--open-url=no","--printing=yes",- "--audio=yes",- "--pulseaudio=auto",- "--speaker=on",+ "--audio=no",+ "--speaker=off","--microphone=off",+ "--encoding=jpeg",+ "--quality=85",+ "--speed=80",f"--bind-tcp=127.0.0.1:{session.xpra_port}","--resize-display=yes",f"--log-dir={session.profile_dir}",diff --git a/plugins/_office/hooks.py b/plugins/_office/hooks.pyindex c751869d5..9bcac0140 100644--- a/plugins/_office/hooks.py+++ b/plugins/_office/hooks.py@@ -15,6 +15,7 @@ XPRA_SOURCE_FILE = Path("/etc/apt/sources.list.d/xpra.sources")XPRA_KEYRING_FILE = Path("/usr/share/keyrings/xpra.asc")XPRA_KEY_URL = "https://xpra.org/xpra.asc"SUPERVISOR_FILE = Path("/etc/supervisor/conf.d/a0_office_collabora.conf")+SUPERVISOR_PROGRAM = "a0_office_collabora"RUNTIME_DIRS = [Path("/a0/tmp/_office/collabora"),Path("/a0/usr/plugins/_office/collabora"),@@ -44,7 +45,9 @@ RUNTIME_PACKAGES = ("libreoffice-impress","libreoffice-gtk3","python3-uno",- "xpra",+ "xpra-server",+ "xpra-client",+ "xpra-client-gtk3","xpra-x11","xpra-html5","xfce4-session",@@ -56,8 +59,6 @@ RUNTIME_PACKAGES = ("gvfs","libglib2.0-bin","xfce4-terminal",- "pulseaudio",- "pulseaudio-utils","x11-xserver-utils","xdotool","xauth",@@ -106,6 +107,7 @@ def cleanup_stale_runtime_state(force: bool = False) -> dict[str, Any]:except Exception as exc:errors.append(f"{path}: {exc}")+ _retire_supervisor_program(errors)_purge_packages(removed, errors, installed_packages=stale_packages)try:@@ -122,6 +124,7 @@ def cleanup_stale_runtime_state(force: bool = False) -> dict[str, Any]:if retired_packages:_purge_packages(removed, errors, installed_packages=retired_packages)+ _retire_supervisor_program(errors)_ensure_runtime_dependencies(installed, errors)_cleanup_desktop_sessions(errors)@@ -158,6 +161,62 @@ def _kill_old_processes(errors: list[str]) -> None:errors.append((result.stderr or result.stdout or "pkill coolwsd failed").strip())+def _retire_supervisor_program(errors: list[str]) -> None:+ if not shutil.which("supervisorctl"):+ return+ status = _supervisorctl("status", SUPERVISOR_PROGRAM)+ status_output = _supervisor_output(status)+ if status.returncode != 0:+ if _supervisor_absent(status_output):+ return+ errors.append(status_output or f"supervisorctl status {SUPERVISOR_PROGRAM} failed")+ return++ stopped = _supervisorctl("stop", SUPERVISOR_PROGRAM)+ stopped_output = _supervisor_output(stopped)+ if stopped.returncode != 0 and not _supervisor_absent(stopped_output):+ errors.append(stopped_output or f"supervisorctl stop {SUPERVISOR_PROGRAM} failed")+ return++ removed = _supervisorctl("remove", SUPERVISOR_PROGRAM)+ removed_output = _supervisor_output(removed)+ if removed.returncode != 0 and not _supervisor_absent(removed_output):+ errors.append(removed_output or f"supervisorctl remove {SUPERVISOR_PROGRAM} failed")+ return++ for command in (("reread",), ("update",)):+ result = _supervisorctl(*command)+ output = _supervisor_output(result)+ if result.returncode != 0 and not _supervisor_absent(output):+ errors.append(output or f"supervisorctl {' '.join(command)} failed")+++def _supervisorctl(*args: str) -> subprocess.CompletedProcess[str]:+ return subprocess.run(+ ["supervisorctl", *args],+ check=False,+ text=True,+ capture_output=True,+ timeout=15,+ )+++def _supervisor_output(result: subprocess.CompletedProcess[str]) -> str:+ return (result.stderr or result.stdout or "").strip()+++def _supervisor_absent(output: str) -> bool:+ normalized = output.lower()+ return (+ "no such process" in normalized+ or "no such group" in normalized+ or "not running" in normalized+ or "unix:///var/run/supervisor.sock" in normalized+ or "connection refused" in normalized+ or "no such file" in normalized+ )++def _installed_packages(packages: tuple[str, ...]) -> list[str]:if not shutil.which("dpkg-query"):return []@@ -210,7 +269,8 @@ def _ensure_runtime_dependencies(installed: list[str], errors: list[str]) -> Nonif not _apt_update(errors):return- if "xpra" in missing and not _package_candidate_available("xpra"):+ xpra_missing = [package for package in missing if package.startswith("xpra")]+ if xpra_missing and not _package_candidates_available(xpra_missing):previous_error_count = len(errors)_ensure_xpra_repository(installed, errors)if len(errors) > previous_error_count or not _apt_update(errors):@@ -260,9 +320,15 @@ def _package_candidate_available(package: str) -> bool:)if result.returncode != 0:return True+ if not result.stdout.strip():+ return Falsereturn "Candidate: (none)" not in result.stdout+def _package_candidates_available(packages: list[str]) -> bool:+ return all(_package_candidate_available(package) for package in packages)++def _ensure_xpra_repository(installed: list[str], errors: list[str]) -> None:if not _package_installed("ca-certificates"):result = subprocess.run(@@ -303,12 +369,18 @@ def _xpra_repository_source() -> str:codename = os_release.get("VERSION_CODENAME", "")arch = _dpkg_architecture()- if os_id == "kali":+ if os_id == "kali" and arch == "amd64":uri = "https://xpra.org/beta"suite = "sid"- elif codename in {"sid", "forky"}:+ elif os_id == "kali":+ uri = "https://xpra.org"+ suite = "trixie"+ elif codename in {"sid", "forky"} and arch == "amd64":uri = "https://xpra.org/beta"suite = codename+ elif codename in {"sid", "forky"}:+ uri = "https://xpra.org"+ suite = "trixie"else:uri = "https://xpra.org"suite = codename or "trixie"diff --git a/tests/test_office_canvas_setup.py b/tests/test_office_canvas_setup.pyindex ccbfb2cab..f7ed3ca0f 100644--- a/tests/test_office_canvas_setup.py+++ b/tests/test_office_canvas_setup.py@@ -228,7 +228,10 @@ def test_official_libreoffice_desktop_route_and_packages_are_declared():assert "xpramenu" in primitiveassert "floating_menu" in primitiveassert '"file_transfer": "true"' in primitive- assert '"sound": "true"' in primitive+ assert '"sound": "false"' in primitive+ assert '"encoding": "jpeg"' in primitive+ assert '"quality": "85"' in primitive+ assert '"speed": "80"' in primitiveassert '"printing": "true"' in primitiveassert "offscreen" in primitiveassert "xpra" in desktop@@ -245,9 +248,12 @@ def test_official_libreoffice_desktop_route_and_packages_are_declared():assert "--open-url=no" in desktopassert "--printing=yes" in desktopassert "--cursors=no" not in desktop- assert "--audio=yes" in desktop- assert "--speaker=on" in desktop+ assert "--audio=no" in desktop+ assert "--speaker=off" in desktopassert "--microphone=off" in desktop+ assert "--encoding=jpeg" in desktop+ assert "--quality=85" in desktop+ assert "--speed=80" in desktopassert "_restart_xpra_shadow(session)" not in desktopassert 'result["reload"] = True' not in desktopassert "MAX_SCREEN_WIDTH}x{MAX_SCREEN_HEIGHT}x24" in desktop@@ -287,7 +293,7 @@ def test_official_libreoffice_desktop_route_and_packages_are_declared():assert "libglib2.0-bin" in installassert "xfce4-terminal" in installassert "firefox-esr" not in install- assert "pulseaudio" in install+ assert "pulseaudio" not in installassert "x11-xserver-utils" in installassert "xauth" in installassert "Linux Desktop Interface" in linux_desktop_skilldiff --git a/tests/test_office_document_store.py b/tests/test_office_document_store.pyindex 3b6f2d56d..9e8f83d65 100644--- a/tests/test_office_document_store.py+++ b/tests/test_office_document_store.py@@ -374,8 +374,6 @@ def test_official_libreoffice_desktop_status_and_url_contract(tmp_path, monkeypa"xfce4-terminal","xfce4-settings-manager","gio",- "pulseaudio",- "pactl",}else "",)@@ -392,7 +390,10 @@ def test_official_libreoffice_desktop_status_and_url_contract(tmp_path, monkeypaassert "xpramenu=false" in urlassert "floating_menu=false" in urlassert "file_transfer=true" in url- assert "sound=true" in url+ assert "sound=false" in url+ assert "encoding=jpeg" in url+ assert "quality=85" in url+ assert "speed=80" in urlassert "printing=true" in url@@ -742,6 +743,48 @@ def test_cleanup_hook_reruns_when_stale_packages_exist_after_old_marker(tmp_pathassert result["removed"] == ["coolwsd"]+def test_cleanup_hook_removes_retired_supervisor_program_after_marker(tmp_path, monkeypatch):+ marker = tmp_path / "state" / "cleanup.done"+ marker.parent.mkdir(parents=True)+ marker.write_text("ok\n", encoding="utf-8")+ calls = []++ monkeypatch.setattr(hooks, "APT_SOURCE_FILE", tmp_path / "missing.sources")+ monkeypatch.setattr(hooks, "APT_KEYRING_FILE", tmp_path / "missing.gpg")+ monkeypatch.setattr(hooks, "SUPERVISOR_FILE", tmp_path / "missing.conf")+ monkeypatch.setattr(hooks, "RUNTIME_DIRS", [])+ monkeypatch.setattr(hooks, "CLEANUP_MARKER", marker)+ monkeypatch.setattr(hooks, "_installed_packages", lambda packages: [])+ monkeypatch.setattr(hooks, "_ensure_runtime_dependencies", lambda installed, errors: None)+ monkeypatch.setattr(hooks, "_cleanup_desktop_sessions", lambda errors: None)+ monkeypatch.setattr(hooks.shutil, "which", lambda name: "/usr/bin/supervisorctl" if name == "supervisorctl" else "")++ def fake_supervisorctl(*args):+ calls.append(args)+ if args == ("status", hooks.SUPERVISOR_PROGRAM):+ return types.SimpleNamespace(+ returncode=0,+ stdout="a0_office_collabora BACKOFF can't find command\n",+ stderr="",+ )+ return types.SimpleNamespace(returncode=0, stdout="", stderr="")++ monkeypatch.setattr(hooks, "_supervisorctl", fake_supervisorctl)++ result = hooks.cleanup_stale_runtime_state()++ assert result["ok"] is True+ assert result["skipped"] is True+ assert result["errors"] == []+ assert calls == [+ ("status", hooks.SUPERVISOR_PROGRAM),+ ("stop", hooks.SUPERVISOR_PROGRAM),+ ("remove", hooks.SUPERVISOR_PROGRAM),+ ("reread",),+ ("update",),+ ]++def test_cleanup_hook_installs_missing_libreoffice_desktop_dependencies(monkeypatch):calls = []installed_state = {"xpra": False}@@ -792,7 +835,7 @@ def test_cleanup_hook_enables_official_xpra_repo_when_kali_lacks_candidate(tmp_pdef fake_run(command, **kwargs):calls.append(command)if command[:2] == ["apt-cache", "policy"]:- return types.SimpleNamespace(returncode=0, stdout="Candidate: (none)\n", stderr="")+ return types.SimpleNamespace(returncode=0, stdout="", stderr="")if command[:2] == ["apt-get", "install"]:installed_state["xpra"] = Truereturn types.SimpleNamespace(returncode=0, stdout="", stderr="")@@ -812,6 +855,50 @@ def test_cleanup_hook_enables_official_xpra_repo_when_kali_lacks_candidate(tmp_passert calls[-1][:4] == ["apt-get", "install", "-y", "--no-install-recommends"]+def test_cleanup_hook_uses_trixie_xpra_components_for_kali_arm64(tmp_path, monkeypatch):+ calls = []+ installed_state = {"xpra-server": False, "xpra-x11": False, "xpra-html5": False, "ca-certificates": True}+ keyring = tmp_path / "keyrings" / "xpra.asc"+ source = tmp_path / "sources.list.d" / "xpra.sources"++ monkeypatch.setattr(hooks.os, "geteuid", lambda: 0)+ monkeypatch.setattr(+ hooks.shutil,+ "which",+ lambda name: f"/usr/bin/{name}" if name in {"apt-get", "dpkg-query", "apt-cache"} else "",+ )+ monkeypatch.setattr(hooks, "RUNTIME_PACKAGES", ("xpra-server", "xpra-x11", "xpra-html5"))+ monkeypatch.setattr(hooks, "XPRA_KEYRING_FILE", keyring)+ monkeypatch.setattr(hooks, "XPRA_SOURCE_FILE", source)+ monkeypatch.setattr(hooks, "_download", lambda url: b"xpra-key")+ monkeypatch.setattr(hooks, "_read_os_release", lambda: {"ID": "kali", "VERSION_CODENAME": "kali-rolling"})+ monkeypatch.setattr(hooks, "_dpkg_architecture", lambda: "arm64")+ monkeypatch.setattr(hooks, "_package_installed", lambda package: installed_state.get(package, False))++ def fake_run(command, **kwargs):+ calls.append(command)+ if command[:2] == ["apt-cache", "policy"]:+ return types.SimpleNamespace(returncode=0, stdout="", stderr="")+ if command[:2] == ["apt-get", "install"]:+ for package in command[4:]:+ installed_state[package] = True+ return types.SimpleNamespace(returncode=0, stdout="", stderr="")++ monkeypatch.setattr(hooks.subprocess, "run", fake_run)+ installed = []+ errors = []++ hooks._ensure_runtime_dependencies(installed, errors)++ assert errors == []+ assert installed == ["xpra-server", "xpra-x11", "xpra-html5"]+ source_text = source.read_text(encoding="utf-8")+ assert "URIs: https://xpra.org\n" in source_text+ assert "Suites: trixie" in source_text+ assert "xpra" not in calls[-1]+ assert calls[-1][-3:] == ["xpra-server", "xpra-x11", "xpra-html5"]++def test_self_update_launch_invokes_office_cleanup(monkeypatch, tmp_path):manager = load_self_update_manager()calls = []