The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): plugins tab reports a refused desktop half, not installed
kshitijk4pooraa2f4af3c6ef
diff --git a/apps/desktop/src/lib/browser-desktop-plugins.test.ts b/apps/desktop/src/lib/browser-desktop-plugins.test.tsindex f15b5c30a6e..e6f6644ffc8 100644--- a/apps/desktop/src/lib/browser-desktop-plugins.test.ts+++ b/apps/desktop/src/lib/browser-desktop-plugins.test.ts@@ -5,6 +5,7 @@ import { discoverRuntimePlugins } from '@/contrib/runtime-loader'import { clearWebappSession, seedWebappSession } from '@/test/webapp-session'import { installBrowserDesktopBridge } from './browser-desktop-bridge'+import { createBrowserDesktopPluginsBridge } from './browser-desktop-plugins'// The server half (hermes_cli/web_routers/desktop_plugins.py) is pinned in// tests/hermes_cli/test_webapp_desktop_plugins.py; this is the server's answer for one plugin.@@ -81,4 +82,28 @@ describe('browser-hosted Desktop plugins', () => {expect(register).toHaveBeenCalledTimes(1)expect(requested.filter(route => route.startsWith('/api/fs/'))).toEqual([])})++ it('names the desktop halves the server refused, so the install tab does not report them installed', async () => {+ const api = vi.fn(async () => ({ refused: [{ name: 'radar', reason: 'links are not installed' }], touched: [] }))+ const files = { readDir: vi.fn(), readFileText: vi.fn() }+ const bridge = createBrowserDesktopPluginsBridge({ api: api as never, files: files as never })++ await expect(bridge.reconcileDesktopPluginsReport?.()).resolves.toEqual({+ published: [],+ refused: [{ name: 'radar', reason: 'links are not installed' }]+ })+ expect(api).toHaveBeenCalledWith({ method: 'POST', path: '/api/desktop-plugins/reconcile' })+ })++ it('treats an older server that only sends touched paths as refusing nothing', async () => {+ const api = vi.fn(async () => ({ touched: ['/plugins/radar'] }))+ const files = { readDir: vi.fn(), readFileText: vi.fn() }+ const bridge = createBrowserDesktopPluginsBridge({ api: api as never, files: files as never })++ await expect(bridge.reconcileDesktopPlugins?.()).resolves.toEqual(['/plugins/radar'])+ await expect(bridge.reconcileDesktopPluginsReport?.()).resolves.toEqual({+ published: ['/plugins/radar'],+ refused: []+ })+ })})diff --git a/apps/desktop/src/lib/browser-desktop-plugins.ts b/apps/desktop/src/lib/browser-desktop-plugins.tsindex c8509ddc2c0..d93702ca9ce 100644--- a/apps/desktop/src/lib/browser-desktop-plugins.ts+++ b/apps/desktop/src/lib/browser-desktop-plugins.ts@@ -2,7 +2,12 @@ import type { HermesApiRequest, HermesReadFileTextResult } from '@/global'type DesktopPluginsBridge = Pick<Window['hermesDesktop'],- 'desktopPluginsRoot' | 'readDir' | 'readFileText' | 'readPluginSource' | 'reconcileDesktopPlugins'+ | 'desktopPluginsRoot'+ | 'readDir'+ | 'readFileText'+ | 'readPluginSource'+ | 'reconcileDesktopPlugins'+ | 'reconcileDesktopPluginsReport'>interface BrowserDesktopPluginsOptions {@@ -27,6 +32,12 @@ export function createBrowserDesktopPluginsBridge({ api, files }: BrowserDesktopconst readFile = (path: string) => get<HermesReadFileTextResult>('read', path)+ const reconcile = () =>+ api<{ refused?: { name: string; reason: string }[]; touched: string[] }>({+ method: 'POST',+ path: '/api/desktop-plugins/reconcile'+ })+return {desktopPluginsRoot: async () => {root = (await api<{ root: string }>({ path: '/api/desktop-plugins/root' })).root@@ -36,8 +47,13 @@ export function createBrowserDesktopPluginsBridge({ api, files }: BrowserDesktopreadDir: path => (inside(path) ? get('list', path) : files.readDir(path)),readFileText: path => (inside(path) ? readFile(path) : files.readFileText(path)),readPluginSource: readFile,- // The server copies agent+desktop packages' desktop halves into the folder, as Electron does.- reconcileDesktopPlugins: async () =>- (await api<{ touched: string[] }>({ method: 'POST', path: '/api/desktop-plugins/reconcile' })).touched+ // The server copies agent+desktop packages' desktop halves into the folder, as Electron does, and+ // names the ones it refused, so an install whose half was refused is not reported as installed.+ reconcileDesktopPlugins: async () => (await reconcile()).touched,+ reconcileDesktopPluginsReport: async () => {+ const { refused = [], touched } = await reconcile()++ return { published: touched, refused }+ }}}diff --git a/hermes_cli/desktop_plugin_halves.py b/hermes_cli/desktop_plugin_halves.pyindex 92ef5cb7edd..5b8b29fc834 100644--- a/hermes_cli/desktop_plugin_halves.py+++ b/hermes_cli/desktop_plugin_halves.py@@ -196,7 +196,8 @@ def materialize_desktop_half(package_dir: Path, app_root: Path, name: str) -> Pa"""Copy *package_dir*'s desktop half to ``<app_root>/<name>/``: its ``desktop/`` folder, or thepackage root (minus :data:`ROOT_LAYOUT_SKIP`) when ``plugin.js`` sits at the root, as theinstallers publish a root-layout repository. Returns the folder when it was copied or adopted, ``None`` when it is- already current, absent, refused (a link or an oversized tree), or a user's own plugin."""+ already current, absent, or a user's own plugin. Raises :class:`OSError` with the reason when the tree is refused+ (a link or an oversized tree), as Electron's ``materializeDesktopHalf`` throws."""found = _desktop_entry(package_dir, name)if found is None:return None@@ -247,8 +248,7 @@ def materialize_desktop_half(package_dir: Path, app_root: Path, name: str) -> Pa# plain-tree rule rather than copy a link to anywhere on the host into the served folder.refused = check_desktop_tree(source_dir, package_dir, linked_root=linked, skip=ROOT_LAYOUT_SKIP)if refused:- logger.warning("desktop-plugins: not copying the desktop half of %s: %s", name, refused)- return None+ raise OSError(refused)publish_desktop_tree(source_dir, target, marker, ignore=ignore)return target@@ -269,8 +269,16 @@ def reconcile_desktop_halves(hermes_root: Path, app_root: Path) -> list[str]:"""Materialize every local home's desktop halves into *app_root* (first home wins for a name inseveral profiles, the default home first) and drop copies whose package is gone. Returns thefolders it wrote or removed."""+ return reconcile_desktop_halves_report(hermes_root, app_root)["touched"]+++def reconcile_desktop_halves_report(hermes_root: Path, app_root: Path) -> dict:+ """:func:`reconcile_desktop_halves`, also naming each package whose desktop half it refused or could not+ read (``refused``: ``{"name", "reason"}``), as Electron's ``reconcileDesktopPluginsReport`` does. A refused+ half leaves its name to a later home's half, and is not reported once that half is published."""with ROOT_WRITER:touched: list[str] = []+ refused: list[dict[str, str]] = []seen: set[str] = set()homes = [hermes_root, *(hermes_root / "profiles" / name for name in _list_dirs(hermes_root / "profiles"))]for home in homes:@@ -281,8 +289,9 @@ def reconcile_desktop_halves(hermes_root: Path, app_root: Path) -> list[str]:try:result = materialize_desktop_half(plugins_root / name, app_root, name)except OSError as exc:- # One unreadable package must not stop every other half from loading.- logger.warning("desktop-plugins: skipping unreadable package %s: %s", name, exc)+ # One unreadable or refused package must not stop every other half from loading.+ logger.warning("desktop-plugins: skipping package %s: %s", name, exc)+ refused.append({"name": name, "reason": str(exc)})continueif result is not None or desktop_source(plugins_root / name) is not None:seen.add(name)@@ -300,4 +309,4 @@ def reconcile_desktop_halves(hermes_root: Path, app_root: Path) -> list[str]:else:shutil.rmtree(folder, ignore_errors=True)touched.append(str(folder))- return touched+ return {"touched": touched, "refused": [entry for entry in refused if entry["name"] not in seen]}diff --git a/hermes_cli/web_routers/desktop_plugins.py b/hermes_cli/web_routers/desktop_plugins.pyindex b310527538b..e6dee4d69b5 100644--- a/hermes_cli/web_routers/desktop_plugins.py+++ b/hermes_cli/web_routers/desktop_plugins.py@@ -22,7 +22,7 @@ from pathlib import Pathfrom fastapi import APIRouter, HTTPException-from hermes_cli.desktop_plugin_halves import reconcile_desktop_halves+from hermes_cli.desktop_plugin_halves import reconcile_desktop_halves, reconcile_desktop_halves_reportfrom hermes_cli.desktop_plugin_install import DESKTOP_PLUGINS_DIR, desktop_plugins_rootfrom hermes_constants import get_default_hermes_root@@ -113,8 +113,10 @@ async def desktop_plugins_root_route() -> dict:@router.post("/api/desktop-plugins/reconcile")async def reconcile_desktop_plugins() -> dict:- """Electron's ``reconcileDesktopPlugins``: re-run the copy after an install, update or removal."""- return {"touched": await asyncio.to_thread(reconcile_desktop_halves, get_default_hermes_root(), desktop_plugins_root())}+ """Electron's ``reconcileDesktopPluginsReport``: re-run the copy after an install, update or removal, and+ name each package whose desktop half it refused and no later profile published, so the install tab does not+ report it as installed."""+ return await asyncio.to_thread(reconcile_desktop_halves_report, get_default_hermes_root(), desktop_plugins_root())@router.get("/api/desktop-plugins/list")diff --git a/tests/hermes_cli/test_webapp_desktop_plugin_halves.py b/tests/hermes_cli/test_webapp_desktop_plugin_halves.pyindex a45384421b3..e8e5d8964d9 100644--- a/tests/hermes_cli/test_webapp_desktop_plugin_halves.py+++ b/tests/hermes_cli/test_webapp_desktop_plugin_halves.py@@ -134,3 +134,41 @@ def test_a_root_layout_package_brings_its_desktop_half_as_the_installers_publish(package / "plugin.js").unlink()webapp.post("/api/desktop-plugins/reconcile")assert "radar" not in _loaded(webapp)+++def _refusing_package(home, name, source, outside):+ """A root-layout package whose root holds a link: the plain-tree check refuses its desktop half."""+ package = home / "plugins" / name+ package.mkdir(parents=True)+ (package / "plugin.js").write_text(source, encoding="utf-8")+ (package / "leak.txt").symlink_to(outside)+ return package+++def test_a_refused_update_is_reported_and_the_working_copy_stays(webapp, hermes_root, tmp_path):+ package = hermes_root / "plugins" / "radar"+ package.mkdir(parents=True)+ (package / "plugin.js").write_text("v1", encoding="utf-8")+ assert _loaded(webapp)["radar"][0] == "v1"++ (tmp_path / "secret").write_text("x", encoding="utf-8")+ (package / "leak.txt").symlink_to(tmp_path / "secret")+ (package / "plugin.js").write_text("v2", encoding="utf-8")+ later = os.stat(package / "plugin.js").st_mtime_ns + 10**9+ os.utime(package / "plugin.js", ns=(later, later))++ body = webapp.post("/api/desktop-plugins/reconcile").json()+ assert body["touched"] == []+ assert [(entry["name"], "leak.txt" in entry["reason"]) for entry in body["refused"]] == [("radar", True)]+ assert _loaded(webapp)["radar"][0] == "v1"+++def test_a_refused_package_leaves_its_name_to_a_profiles_half(webapp, hermes_root, tmp_path):+ (tmp_path / "secret").write_text("x", encoding="utf-8")+ _refusing_package(hermes_root, "radar", "default", tmp_path / "secret")+ profile = hermes_root / "profiles" / "work" / "plugins" / "radar"+ profile.mkdir(parents=True)+ (profile / "plugin.js").write_text("work", encoding="utf-8")++ assert webapp.post("/api/desktop-plugins/reconcile").json()["refused"] == []+ assert _loaded(webapp)["radar"][0] == "work"