refactor: simplify CLI Apps route await
This commit is contained in:
@@ -8,7 +8,6 @@ request mapping and response shaping.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
|
||||||
import json
|
import json
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@@ -310,12 +309,7 @@ class WebUISettingsRouter:
|
|||||||
"yes",
|
"yes",
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
payload_result = (
|
payload = await cli_apps_payload(installed_only=installed_only)
|
||||||
cli_apps_payload(installed_only=True)
|
|
||||||
if installed_only
|
|
||||||
else cli_apps_payload()
|
|
||||||
)
|
|
||||||
payload = await payload_result if inspect.isawaitable(payload_result) else payload_result
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self.logger.exception("failed to load CLI Apps payload")
|
self.logger.exception("failed to load CLI Apps payload")
|
||||||
return self._error_response(500, "failed to load CLI Apps")
|
return self._error_response(500, "failed to load CLI Apps")
|
||||||
|
|||||||
@@ -415,9 +415,8 @@ async def test_cli_apps_routes_require_token_and_return_payload(
|
|||||||
tmp_path: Path,
|
tmp_path: Path,
|
||||||
monkeypatch: pytest.MonkeyPatch,
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
) -> None:
|
) -> None:
|
||||||
monkeypatch.setattr(
|
async def payload(*, installed_only: bool = False) -> dict[str, Any]:
|
||||||
"nanobot.webui.settings_routes.cli_apps_payload",
|
return {
|
||||||
lambda: {
|
|
||||||
"apps": [
|
"apps": [
|
||||||
{
|
{
|
||||||
"name": "gimp",
|
"name": "gimp",
|
||||||
@@ -438,7 +437,11 @@ async def test_cli_apps_routes_require_token_and_return_payload(
|
|||||||
],
|
],
|
||||||
"installed_count": 0,
|
"installed_count": 0,
|
||||||
"catalog_updated_at": "2026-04-18",
|
"catalog_updated_at": "2026-04-18",
|
||||||
},
|
}
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"nanobot.webui.settings_routes.cli_apps_payload",
|
||||||
|
payload,
|
||||||
)
|
)
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
"nanobot.webui.settings_routes.cli_apps_action",
|
"nanobot.webui.settings_routes.cli_apps_action",
|
||||||
@@ -487,7 +490,8 @@ async def test_cli_apps_catalog_does_not_block_other_webui_http_routes(
|
|||||||
entered = asyncio.Event()
|
entered = asyncio.Event()
|
||||||
release = asyncio.Event()
|
release = asyncio.Event()
|
||||||
|
|
||||||
async def slow_payload() -> dict[str, Any]:
|
async def slow_payload(*, installed_only: bool = False) -> dict[str, Any]:
|
||||||
|
assert installed_only is False
|
||||||
entered.set()
|
entered.set()
|
||||||
with suppress(asyncio.TimeoutError):
|
with suppress(asyncio.TimeoutError):
|
||||||
await asyncio.wait_for(release.wait(), 2.0)
|
await asyncio.wait_for(release.wait(), 2.0)
|
||||||
@@ -532,7 +536,7 @@ async def test_cli_apps_route_supports_installed_only_payload(
|
|||||||
) -> None:
|
) -> None:
|
||||||
calls: list[bool] = []
|
calls: list[bool] = []
|
||||||
|
|
||||||
def payload(*, installed_only: bool = False) -> dict[str, Any]:
|
async def payload(*, installed_only: bool = False) -> dict[str, Any]:
|
||||||
calls.append(installed_only)
|
calls.append(installed_only)
|
||||||
return {"apps": [], "installed_count": 0, "catalog_updated_at": None}
|
return {"apps": [], "installed_count": 0, "catalog_updated_at": None}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user