fix(webui): offer restart in installed channel rows (NAN-334) (#6392)
* fix(webui): offer restart in installed channel rows (NAN-334) * fix(webui): align channel restart icon and hover hint * fix(webui): explain channel installs blocked by restart
This commit is contained in:
1 parent
08ca3b4525
commit
169062be11
17 files changed
+178
-52
No files matched your search
@@ -1408,13 +1408,34 @@ async def test_nanobot_feature_channel_action_can_apply_without_restart(
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nanobot_feature_install_only_does_not_start_channel(
|
||||
@pytest.mark.parametrize("installed_now", [True, False])
|
||||
async def test_nanobot_feature_install_only_tracks_pending_restart_without_starting_channel(
|
||||
bus: MagicMock,
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
installed_now: bool,
|
||||
) -> None:
|
||||
runtime_calls: list[tuple[str, str, str | None]] = []
|
||||
|
||||
def features_payload(**_kwargs: Any) -> dict[str, Any]:
|
||||
return {
|
||||
"features": [{
|
||||
"name": name,
|
||||
"type": "channel",
|
||||
"enabled": False,
|
||||
"installed": True,
|
||||
"ready": False,
|
||||
"status": "not_enabled",
|
||||
"requires_restart": True,
|
||||
} for name in ("whatsapp", "email")],
|
||||
"enabled_count": 0,
|
||||
}
|
||||
|
||||
monkeypatch.setattr(
|
||||
"nanobot.webui.settings_routes.nanobot_features_payload",
|
||||
features_payload,
|
||||
)
|
||||
|
||||
def feature_action(
|
||||
action: str,
|
||||
query: dict[str, list[str]],
|
||||
@@ -1425,18 +1446,7 @@ async def test_nanobot_feature_install_only_does_not_start_channel(
|
||||
assert action == "enable"
|
||||
assert query == {"name": ["whatsapp"], "install_only": ["true"]}
|
||||
assert allow_install is True
|
||||
return {
|
||||
"features": [{
|
||||
"name": "whatsapp",
|
||||
"type": "channel",
|
||||
"enabled": False,
|
||||
"installed": True,
|
||||
"ready": False,
|
||||
"status": "not_enabled",
|
||||
}],
|
||||
"enabled_count": 0,
|
||||
"requires_restart": False,
|
||||
}
|
||||
return {**features_payload(), "requires_restart": installed_now}
|
||||
|
||||
async def channel_feature_action(
|
||||
action: str,
|
||||
@@ -1465,7 +1475,28 @@ async def test_nanobot_feature_install_only_does_not_start_channel(
|
||||
|
||||
assert response.status_code == 200
|
||||
assert runtime_calls == []
|
||||
assert response.json()["features"][0]["enabled"] is False
|
||||
features = response.json()["features"]
|
||||
assert features[0]["enabled"] is False
|
||||
assert [feature["restart_pending"] for feature in features] == [installed_now, False]
|
||||
|
||||
# Refreshing the catalog keeps the pending installation tied to its channel.
|
||||
refreshed = await _http_get(
|
||||
f"http://127.0.0.1:{channel.config.port}/api/settings/nanobot-features",
|
||||
headers={"Authorization": f"Bearer {channel.gateway.tokens.issue_api_token(300)}"},
|
||||
)
|
||||
assert refreshed.status_code == 200
|
||||
assert [feature["restart_pending"] for feature in refreshed.json()["features"]] == [
|
||||
installed_now, False,
|
||||
]
|
||||
|
||||
# A new gateway owns a fresh runtime; installed support is ready to configure.
|
||||
restarted = _ch(bus, session_manager=SessionManager(tmp_path), port=_free_port())
|
||||
after_restart = await _http_get(
|
||||
f"http://127.0.0.1:{restarted.config.port}/api/settings/nanobot-features",
|
||||
headers={"Authorization": f"Bearer {restarted.gateway.tokens.issue_api_token(300)}"},
|
||||
)
|
||||
assert after_restart.status_code == 200
|
||||
assert all(not feature["restart_pending"] for feature in after_restart.json()["features"])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -454,6 +454,7 @@ class SystemSettingsHandler:
|
||||
self.logger = logger
|
||||
self._admission = admission
|
||||
self._channel_connectors: dict[str, ChannelConnector] = {}
|
||||
self._pending_channel_restarts: set[str] = set()
|
||||
self._remove_pending_work: Callable[[], None] | None = None
|
||||
self._closing_connectors = False
|
||||
self._update_jobs = UpdateJobService()
|
||||
@@ -793,6 +794,8 @@ class SystemSettingsHandler:
|
||||
action,
|
||||
)
|
||||
return SettingsRouteResult.failure(status, message)
|
||||
if install_only and payload.get("requires_restart"):
|
||||
self._pending_channel_restarts.add((query_first(request.query, "name") or "").strip())
|
||||
if not install_only:
|
||||
payload = await self._apply_feature_runtime_change(
|
||||
action,
|
||||
@@ -812,16 +815,22 @@ class SystemSettingsHandler:
|
||||
payload: dict[str, Any],
|
||||
operations: SystemSettingsOperations,
|
||||
) -> dict[str, Any]:
|
||||
if operations.channel_runtime_status is None:
|
||||
return payload
|
||||
try:
|
||||
return with_channel_runtime_status(
|
||||
payload,
|
||||
operations.channel_runtime_status(),
|
||||
)
|
||||
except Exception:
|
||||
self.logger.exception("failed to load channel runtime status")
|
||||
return payload
|
||||
if operations.channel_runtime_status is not None:
|
||||
try:
|
||||
payload = with_channel_runtime_status(
|
||||
payload,
|
||||
operations.channel_runtime_status(),
|
||||
)
|
||||
except Exception:
|
||||
self.logger.exception("failed to load channel runtime status")
|
||||
return {
|
||||
**payload,
|
||||
"features": [
|
||||
{**feature, "restart_pending": feature["name"] in self._pending_channel_restarts}
|
||||
if feature["type"] == "channel" else feature
|
||||
for feature in payload["features"]
|
||||
],
|
||||
}
|
||||
|
||||
async def _apply_feature_runtime_change(
|
||||
self,
|
||||
|
||||
Reference in new issue
Block a user