Agent Zero AI framework
fix(docker): load the signed Xpra ARM64 package index
Alessandroff2a5b9c9c4e
diff --git a/docker/run/AGENTS.md b/docker/run/AGENTS.mdindex 69447feae..4f9ac7b73 100644--- a/docker/run/AGENTS.md+++ b/docker/run/AGENTS.md@@ -19,7 +19,7 @@- `BRANCH` is required for branch-based Docker builds.- Preserve exposed ports for SSH, HTTP, and tunneled services unless docs and workflows are updated together.- Keep the two-runtime Python model aligned with the root contract.-- For v2.13 builds, retain the Python 3.13-compatible ATK, LibreOffice/UNO, and Xpra pins in `fs/ins/install_additional.sh`. Resolve them from the signed Debian `forky` archive dated `20260624T000000Z` and Xpra `trixie`, using build-scoped APT options that preserve normal Kali sources.+- Retain the Python 3.13-compatible ATK, LibreOffice/UNO, and Xpra pins in `fs/ins/install_additional.sh`. Resolve them from the signed Debian `forky` archive dated `20260624T000000Z` and Xpra `trixie`, using build-scoped APT options that preserve normal Kali sources. Refresh Xpra through `plugins/_desktop/helpers/refresh_xpra_index.sh` from the cloned repository; its signed compressed index avoids upstream's empty ARM64 `Packages` metadata without clearing the Debian indexes.- Do not bake secrets, local `.env` values, or user data into the image.- Runtime startup must ensure `/a0/usr/uploads` exists before supervised services start.- Runtime startup seeds APT package lists in the background only when no package index is cached (fresh images clear these at build time). Normal restarts skip the refresh; installation scripts and plugin hooks refresh metadata when installing packages.diff --git a/docker/run/fs/ins/install_additional.sh b/docker/run/fs/ins/install_additional.shindex d88ea7665..caa3d3e6c 100644--- a/docker/run/fs/ins/install_additional.sh+++ b/docker/run/fs/ins/install_additional.sh@@ -71,7 +71,7 @@ Signed-By: /usr/share/keyrings/xpra.ascArchitectures: $archEOFecho "deb [arch=$arch signed-by=/usr/share/keyrings/xpra.asc] https://xpra.org trixie main" >>/etc/apt/a0-desktop.list-apt-get "${APT_OPTIONS[@]}" update+bash /git/agent-zero/plugins/_desktop/helpers/refresh_xpra_index.sh /etc/apt/sources.list.d/xpra.sourcesDEBIAN_FRONTEND=noninteractive apt-get "${APT_OPTIONS[@]}" install -y --no-install-recommends --allow-downgrades \"${ATK_PACKAGES[@]}" \gir1.2-gtk-3.0 \diff --git a/plugins/_desktop/AGENTS.md b/plugins/_desktop/AGENTS.mdindex ae6e3b7bd..ab2735bae 100644--- a/plugins/_desktop/AGENTS.md+++ b/plugins/_desktop/AGENTS.md@@ -18,6 +18,7 @@- Apply shared `virtual_desktop.XPRA_START_ENV` defaults to Xpra launches and restarts while preserving inherited overrides. Disable local shared-memory transport for the WebSocket viewer.- Keep the Xpra server, client modules, and GTK introspection runtime present as one compatible stack; Xpra shadow sessions import all three even when users connect only through HTML5.- Route APT commands through `system_packages.run_runtime_apt` so existing Kali containers repair from the build's snapshot. Preserve the installed Xpra component version. If GTK needs a missing ATK typelib, align ATK's version-locked libraries and any installed optional components with the build's pinned snapshot version; do not fetch dependencies from rolling.+- `helpers/refresh_xpra_index.sh` owns the build/runtime Xpra index workaround: let APT authenticate `Packages.gz` directly, then move its cache to the standard package-index filename. Scope the refresh to the supplied signed Xpra source, preserve other cached indexes, and stop on authentication, download, or cache-move failures.- Keep desktop state injected into prompts accurate and bounded.- Rename open LibreOffice documents through native Save As so unsaved edits and subsequent WebUI/native saves follow the new path. `helpers/rename_office_document.py` runs with system Python/UNO, connects to the existing profile through a local named pipe, and matches the full document URL; never select a document by basename alone. Retain the document's format/filter and encryption properties, and disallow target overwrite. Closed documents retain filesystem rename behavior.- Do not expose desktop routes without the expected auth protections.diff --git a/plugins/_desktop/helpers/refresh_xpra_index.sh b/plugins/_desktop/helpers/refresh_xpra_index.shnew file mode 100644index 000000000..357e9966c--- /dev/null+++ b/plugins/_desktop/helpers/refresh_xpra_index.sh@@ -0,0 +1,19 @@+#!/bin/bash+set -e++# Xpra's ARM64 Release can mark Packages as empty while its signed gzip index is intact.+APT_OPTIONS=(+ -o "Dir::Etc::sourcelist=${1:?Xpra source file is required}"+ -o Dir::Etc::sourceparts=-+ -o APT::Get::List-Cleanup=false+ -o APT::Update::Error-Mode=any+ -o 'Acquire::IndexTargets::deb::Packages::MetaKey=$(COMPONENT)/binary-$(ARCHITECTURE)/Packages.gz'+ -o Acquire::IndexTargets::deb::Packages::KeepCompressed=true+ -o Acquire::IndexTargets::deb::Packages::KeepCompressedAs=gz+)+apt-get "${APT_OPTIONS[@]}" update+indexes="$(apt-get "${APT_OPTIONS[@]}" indextargets --format '$(FILENAME)' 'Created-By: Packages')"+# Normal package lookups expect Packages.gz instead of this target's Packages.gz.gz.+while IFS= read -r index; do+ mv -- "$index" "${index%.gz}"+done <<<"$indexes"diff --git a/plugins/_desktop/hooks.py b/plugins/_desktop/hooks.pyindex a23d26bcd..fdd41b675 100644--- a/plugins/_desktop/hooks.py+++ b/plugins/_desktop/hooks.py@@ -266,7 +266,7 @@ def _ensure_runtime_dependencies(installed: list[str], errors: list[str]) -> Nonif required_xpra_missing and not _package_candidates_available(required_xpra_missing):previous_error_count = len(errors)_ensure_xpra_repository(installed, errors)- if len(errors) > previous_error_count or not _apt_update(errors):+ if len(errors) > previous_error_count or not _apt_update(errors, xpra_only=True):returnmissing = [package for package in RUNTIME_PACKAGES if not _package_installed(package)]if not missing:@@ -329,8 +329,12 @@ def _install_runtime_packages(return False-def _apt_update(errors: list[str]) -> bool:- result = _run_apt_command(["apt-get", "update"], timeout=300)+def _apt_update(errors: list[str], *, xpra_only: bool = False) -> bool:+ command = (+ ["bash", files.get_abs_path("plugins/_desktop/helpers/refresh_xpra_index.sh"), str(XPRA_SOURCE_FILE)]+ if xpra_only else ["apt-get", "update"]+ )+ result = _run_apt_command(command, timeout=300)if result.returncode == 0:return Trueerrors.append((result.stderr or result.stdout or "apt-get update failed").strip())diff --git a/tests/test_office_document_store.py b/tests/test_office_document_store.pyindex 99223f841..f4b70166c 100644--- a/tests/test_office_document_store.py+++ b/tests/test_office_document_store.py@@ -1920,7 +1920,10 @@ def test_cleanup_hook_enables_official_xpra_repo_when_kali_lacks_candidate(tmp_passert keyring.read_bytes() == b"xpra-key"assert "URIs: https://xpra.org\n" in source.read_text(encoding="utf-8")assert "Suites: trixie" in source.read_text(encoding="utf-8")- assert calls.count(["apt-get", "update"]) == 2+ assert calls.count(["apt-get", "update"]) == 1+ assert [+ "bash", str(PROJECT_ROOT / "plugins/_desktop/helpers/refresh_xpra_index.sh"), str(source),+ ] in callsassert calls[-1][:4] == ["apt-get", "install", "-y", "--no-install-recommends"]@@ -1964,6 +1967,9 @@ def test_cleanup_hook_uses_trixie_xpra_components_for_kali_arm64(tmp_path, monkesource_text = source.read_text(encoding="utf-8")assert "URIs: https://xpra.org\n" in source_textassert "Suites: trixie" in source_text+ assert [+ "bash", str(PROJECT_ROOT / "plugins/_desktop/helpers/refresh_xpra_index.sh"), str(source),+ ] in callsassert "xpra" not in calls[-1]assert calls[-1][-3:] == [f"xpra-server={desktop_hooks.XPRA_VERSION}",@@ -1972,6 +1978,30 @@ def test_cleanup_hook_uses_trixie_xpra_components_for_kali_arm64(tmp_path, monke]+def test_cleanup_hook_stops_when_xpra_index_refresh_fails(monkeypatch):+ calls = []+ monkeypatch.setattr(desktop_hooks.os, "geteuid", lambda: 0)+ monkeypatch.setattr(desktop_hooks.shutil, "which", lambda name: f"/usr/bin/{name}")+ monkeypatch.setattr(desktop_hooks, "RUNTIME_PACKAGES", ("xpra-server",))+ monkeypatch.setattr(desktop_hooks, "_package_installed", lambda package: False)+ monkeypatch.setattr(desktop_hooks, "_package_candidates_available", lambda packages: False)+ monkeypatch.setattr(desktop_hooks, "_ensure_xpra_repository", lambda installed, errors: None)++ def run(command, **kwargs):+ calls.append(command)+ failed = command[0] == "bash"+ return types.SimpleNamespace(returncode=100 if failed else 0, stdout="", stderr="bad index signature" if failed else "")++ monkeypatch.setattr(desktop_hooks, "_run_apt_command", run)+ installed = []+ errors = []+ desktop_hooks._ensure_runtime_dependencies(installed, errors)+ assert installed == []+ assert errors == ["bad index signature"]+ assert len(calls) == 2+ assert calls[-1][0] == "bash"++def test_cleanup_hook_installs_matching_xpra_client_stack(monkeypatch):calls = []installed_state = {diff --git a/tests/test_system_packages.py b/tests/test_system_packages.pyindex 5ab4984d7..318de2e67 100644--- a/tests/test_system_packages.py+++ b/tests/test_system_packages.py@@ -52,7 +52,11 @@ def test_runtime_apt_propagates_source_write_errors(tmp_path, monkeypatch):@pytest.mark.parametrize("arch", ["amd64", "arm64"])def test_desktop_install_script_uses_compatible_architecture_packages(tmp_path, arch):- script = (Path(__file__).resolve().parents[1] / "docker/run/fs/ins/install_additional.sh").read_text()+ root = Path(__file__).resolve().parents[1]+ script = (root / "docker/run/fs/ins/install_additional.sh").read_text()+ refresh = tmp_path / "refresh_xpra_index.sh"+ refresh.write_text((root / "plugins/_desktop/helpers/refresh_xpra_index.sh").read_text())+ script = script.replace("/git/agent-zero/plugins/_desktop/helpers/refresh_xpra_index.sh", str(refresh))for path in ("/etc/apt", "/usr/share/keyrings", "/var/lib/apt/lists"):(tmp_path / path.lstrip("/")).mkdir(parents=True)script = script.replace(path, str(tmp_path / path.lstrip("/")))@@ -63,13 +67,27 @@ def test_desktop_install_script_uses_compatible_architecture_packages(tmp_path,stubs = r'''apt-get() {[[ "$(<"$SIM_ROOT/etc/apt/sources.list")" == *kali-rolling* ]] || return 1- [[ "$*" == *"Dir::Etc::sourcelist=$SIM_ROOT/etc/apt/a0-desktop.list"* ]] || return 1[[ "$*" == *"Dir::Etc::sourceparts=-"* ]] || return 1+ if [[ "$*" == *"/xpra.sources"* ]]; then+ [[ "$*" == *'MetaKey=$(COMPONENT)/binary-$(ARCHITECTURE)/Packages.gz'* ]] || return 1+ [[ "$*" == *"APT::Get::List-Cleanup=false"* ]] || return 1+ [[ "$*" == *"APT::Update::Error-Mode=any"* ]] || return 1+ else+ [[ "$*" == *"Dir::Etc::sourcelist=$SIM_ROOT/etc/apt/a0-desktop.list"* ]] || return 1+ figrep -q "signed-by=$SIM_ROOT/usr/share/keyrings/debian-archive-keyring.gpg" "$SIM_ROOT/etc/apt/a0-desktop.list" || return 1grep -q 'snapshot.debian.org/archive/debian/20260624T000000Z/' "$SIM_ROOT/etc/apt/a0-desktop.list" || return 1while [[ "$1" == -o ]]; do shift 2; doneprintf '%s\0' "$@" >> "$SIM_ROOT/apt.log"printf '\0' >> "$SIM_ROOT/apt.log"+ index="$SIM_ROOT/var/lib/apt/lists/xpra.org_dists_trixie_main_binary-${SIM_ARCH}_Packages.gz"+ if [[ "$1" == update && -f "$SIM_ROOT/etc/apt/sources.list.d/xpra.sources" ]]; then+ printf 'signed gzip index' > "$index.gz"+ elif [[ "$1" == indextargets ]]; then+ printf '%s\n' "$index.gz"+ elif [[ "$1" == install && "$*" == *xpra-common* ]]; then+ [[ "$(<"$index")" == 'signed gzip index' ]] || return 1+ fi}dpkg() { printf '%s\n' "$SIM_ARCH"; }dpkg-query() {@@ -80,6 +98,7 @@ dpkg-query() {fi}wget() { return 0; }+export -f apt-get'''result = subprocess.run(["bash", "-e", "-c", stubs + script], text=True, capture_output=True,@@ -99,3 +118,25 @@ wget() { return 0; }assert ("at-spi2-core=2.60.3-1" in installs[-1]) == (arch == "arm64")assert f"Architectures: {arch}\n" in (tmp_path / "etc/apt/sources.list.d/xpra.sources").read_text()assert f"arch={arch}" in (tmp_path / "etc/apt/a0-desktop.list").read_text()++[email protected]("failure", ["update", "indextargets", "missing_index"])+def test_xpra_index_refresh_stops_on_failure(tmp_path, failure):+ script = Path(__file__).resolve().parents[1] / "plugins/_desktop/helpers/refresh_xpra_index.sh"+ stubs = r'''+apt-get() {+ while [[ "$1" == -o ]]; do shift 2; done+ [[ "$1" != "$SIM_FAILURE" ]] || return 42+ if [[ "$1" == indextargets ]]; then+ printf '%s\n' "$SIM_ROOT/missing_Packages.gz.gz"+ fi+}+export -f apt-get+'''+ result = subprocess.run(+ ["bash", "-ec", stubs + 'bash "$1" "$SIM_ROOT/xpra.sources"', "--", str(script)],+ text=True, capture_output=True,+ env={**os.environ, "SIM_ROOT": str(tmp_path), "SIM_FAILURE": failure},+ )+ assert result.returncode == (1 if failure == "missing_index" else 42)+ assert not (tmp_path / "missing_Packages.gz").exists()