Skip to content

Agent Zero AI framework

Preserve repository thumbnails during plugin installation

Alessandro4470d206b7b3
diff --git a/plugins/_plugin_installer/AGENTS.md b/plugins/_plugin_installer/AGENTS.md
index 6e213ec7e..da3faadac 100644
--- a/plugins/_plugin_installer/AGENTS.md
+++ b/plugins/_plugin_installer/AGENTS.md
@@ -16,6 +16,7 @@
- Install third-party plugins into `usr/plugins/`, not bundled `plugins/`.
- Reject unsafe archive paths, missing manifests, invalid manifests, and plugin name conflicts.
- Run plugin install hooks and refresh plugin state after successful changes.
+- Download fallback thumbnails only when no supported thumbnail exists; repository-provided images change through Git updates.
## Work Guidance
diff --git a/plugins/_plugin_installer/README.md b/plugins/_plugin_installer/README.md
index 62b19450b..c9a7c6521 100644
--- a/plugins/_plugin_installer/README.md
+++ b/plugins/_plugin_installer/README.md
@@ -12,6 +12,7 @@ This plugin provides the built-in installation workflow for third-party plugins.
- Accepts an uploaded archive, extracts it safely, locates `plugin.yaml`, validates metadata, and moves the plugin into `usr/plugins/`.
- **Git install**
- Clones a repository to a temporary directory, validates the plugin, then installs it into `usr/plugins/`.
+ - Preserves the plugin's thumbnail and downloads a fallback only when none exists. Repository-provided thumbnails update with the plugin through Git.
- **Plugin update**
- Updates already installed Git-backed custom plugins and re-runs installation hooks.
- **Safety checks**
diff --git a/plugins/_plugin_installer/helpers/install.py b/plugins/_plugin_installer/helpers/install.py
index 9d6016688..1b8d94d8e 100644
--- a/plugins/_plugin_installer/helpers/install.py
+++ b/plugins/_plugin_installer/helpers/install.py
@@ -156,7 +156,7 @@ def install_from_zip(zip_path: str, original_filename: str | None = None) -> dic
def _download_thumbnail(thumbnail_url: str, plugin_dir: str) -> None:
- """Download thumbnail from URL to plugin_dir/webui/thumbnail.<ext>. Non-fatal."""
+ """Download a fallback thumbnail only when the plugin has none. Non-fatal."""
try:
if not thumbnail_url:
return
@@ -170,6 +170,8 @@ def _download_thumbnail(thumbnail_url: str, plugin_dir: str) -> None:
if ext not in _allowed_exts:
ext = "png"
webui_dir = Path(plugin_dir) / "webui"
+ if any((webui_dir / f"thumbnail.{suffix}").is_file() for suffix in _allowed_exts):
+ return
webui_dir.mkdir(parents=True, exist_ok=True)
dest = webui_dir / f"thumbnail.{ext}"
req = urllib.request.Request(thumbnail_url, headers={"User-Agent": "AgentZero"})
diff --git a/tests/test_plugin_git_update.py b/tests/test_plugin_git_update.py
index 035cbe6a1..6e3a7ea15 100644
--- a/tests/test_plugin_git_update.py
+++ b/tests/test_plugin_git_update.py
@@ -1,6 +1,8 @@
import subprocess
import sys
+from io import BytesIO
from pathlib import Path
+from unittest.mock import Mock
import pytest
@@ -107,6 +109,41 @@ def test_update_repo_restores_original_plugin_and_local_edit_after_conflict(tmp_
assert run_git(installed, "stash", "list") == ""
[email protected]("extension", ["png", "jpg"])
+def test_thumbnail_download_preserves_repo_image_and_allows_upstream_updates(
+ tmp_path: Path, monkeypatch, extension: str
+):
+ _, source, installed = make_plugin_repos(tmp_path)
+ (source / "webui").mkdir()
+ thumbnail_path = f"webui/thumbnail.{extension}"
+ push_source_change(source, thumbnail_path, "\x00original thumbnail\n")
+ git_helpers.update_repo(str(installed))
+ download = Mock(return_value=BytesIO(b"downloaded thumbnail"))
+ monkeypatch.setattr(install.urllib.request, "urlopen", download)
+
+ install._download_thumbnail("https://example.com/thumbnail.png", str(installed))
+
+ download.assert_not_called()
+ assert (installed / thumbnail_path).read_bytes() == b"\x00original thumbnail\n"
+ assert git_status(installed) == ""
+
+ push_source_change(source, thumbnail_path, "\x00upstream thumbnail\n")
+ git_helpers.update_repo(str(installed))
+
+ assert (installed / thumbnail_path).read_bytes() == b"\x00upstream thumbnail\n"
+ assert git_status(installed) == ""
+
+
+def test_thumbnail_download_fills_missing_image(tmp_path: Path, monkeypatch):
+ download = Mock(return_value=BytesIO(b"fallback thumbnail"))
+ monkeypatch.setattr(install.urllib.request, "urlopen", download)
+
+ install._download_thumbnail("https://example.com/thumbnail.png", str(tmp_path))
+
+ download.assert_called_once()
+ assert (tmp_path / "webui/thumbnail.png").read_bytes() == b"fallback thumbnail"
+
+
def test_plugin_hub_renders_dirty_update_errors_inline():
store = (PROJECT_ROOT / "plugins/_plugin_installer/webui/pluginInstallStore.js").read_text(encoding="utf-8")
detail = (PROJECT_ROOT / "plugins/_plugin_installer/webui/install-detail.html").read_text(encoding="utf-8")