feat(update): integrate managed installs and recoverable in-app updates (#6168)
Add owner-aware Stable and Preview updates with explicit consent, verified release plans, protected process handoff and bounded service recovery. Keep configuration and conversations separate from program rollback. Include the compact About controls, Windows long-path support, native package recovery checks and optional macOS Dock lifecycle integration. Preserve documented guidance for installations owned by other managers. This code integration does not publish packages, enable signing or advance the public update channel. Co-authored-by: chengyongru <61816729+chengyongru@users.noreply.github.com>
This commit is contained in:
1 parent
76da55994b
commit
fbb61a373f
216 files changed
+27948
-1084
No files matched your search
+86
-17
@@ -3,8 +3,9 @@ import json
|
||||
import re
|
||||
import shutil
|
||||
import signal
|
||||
import sys
|
||||
import urllib.error
|
||||
from contextlib import contextmanager, suppress
|
||||
from contextlib import contextmanager, nullcontext, suppress
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
@@ -48,6 +49,8 @@ runner = CliRunner()
|
||||
def mock_webui_bundle(monkeypatch) -> MagicMock:
|
||||
prepare_bundle = MagicMock()
|
||||
monkeypatch.setattr(cli_webui, "_prepare_webui_bundle_for_gateway", prepare_bundle)
|
||||
monkeypatch.setattr(cli_webui, "dock_icon", lambda *_args, **_kwargs: nullcontext())
|
||||
monkeypatch.setattr(cli_webui, "request_gateway_icon", lambda *_args, **_kwargs: None)
|
||||
return prepare_bundle
|
||||
|
||||
|
||||
@@ -93,6 +96,10 @@ class _GatewayAgentContractStub:
|
||||
tools = ToolRegistry()
|
||||
subagents = MagicMock(spec=SubagentManager)
|
||||
|
||||
@contextmanager
|
||||
def maintenance(self):
|
||||
yield
|
||||
|
||||
async def discard_session(self, _session_key: str) -> None:
|
||||
pass
|
||||
|
||||
@@ -1717,7 +1724,7 @@ def test_agent_uses_workspace_directory_for_cron_store(monkeypatch, tmp_path: Pa
|
||||
monkeypatch.setattr("nanobot.bus.queue.MessageBus", lambda: object())
|
||||
|
||||
class _FakeCron:
|
||||
def __init__(self, store_path: Path) -> None:
|
||||
def __init__(self, store_path: Path, *, admission=None) -> None:
|
||||
seen["cron_store"] = store_path
|
||||
|
||||
class _FakeAgentLoop:
|
||||
@@ -1767,7 +1774,7 @@ def test_agent_workspace_override_does_not_migrate_legacy_cron(
|
||||
monkeypatch.setattr("nanobot.config.paths.get_cron_dir", lambda: legacy_dir)
|
||||
|
||||
class _FakeCron:
|
||||
def __init__(self, store_path: Path) -> None:
|
||||
def __init__(self, store_path: Path, *, admission=None) -> None:
|
||||
seen["cron_store"] = store_path
|
||||
|
||||
class _FakeAgentLoop:
|
||||
@@ -1823,7 +1830,7 @@ def test_agent_custom_config_workspace_does_not_migrate_legacy_cron(
|
||||
monkeypatch.setattr("nanobot.config.paths.get_cron_dir", lambda: legacy_dir)
|
||||
|
||||
class _FakeCron:
|
||||
def __init__(self, store_path: Path) -> None:
|
||||
def __init__(self, store_path: Path, *, admission=None) -> None:
|
||||
seen["cron_store"] = store_path
|
||||
|
||||
class _FakeAgentLoop:
|
||||
@@ -1853,9 +1860,8 @@ def test_agent_custom_config_workspace_does_not_migrate_legacy_cron(
|
||||
assert not (custom_workspace / "cron" / "jobs.json").exists()
|
||||
|
||||
|
||||
def test_agent_overrides_workspace_path(mock_agent_runtime):
|
||||
workspace_path = Path("/tmp/agent-workspace")
|
||||
|
||||
@pytest.mark.parametrize("workspace_path", [Path("/tmp/agent-workspace"), Path("relative-agent-workspace")])
|
||||
def test_agent_overrides_workspace_path(mock_agent_runtime, workspace_path):
|
||||
result = runner.invoke(app, ["agent", "-m", "hello", "-w", str(workspace_path)])
|
||||
|
||||
assert result.exit_code == 0
|
||||
@@ -2174,7 +2180,7 @@ def test_heartbeat_empty_response_is_not_evaluated(
|
||||
return [{"key": "telegram:u1"}]
|
||||
|
||||
class _FakeCron:
|
||||
def __init__(self, _store_path: Path) -> None:
|
||||
def __init__(self, _store_path: Path, *, admission=None) -> None:
|
||||
self.on_job = None
|
||||
seen["cron"] = self
|
||||
|
||||
@@ -2367,6 +2373,36 @@ def test_webui_background_points_to_the_single_persistent_gateway_command(
|
||||
assert not config_file.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("managed", [False, True], ids=["explicit-detach", "fresh-installer"])
|
||||
@pytest.mark.parametrize("no_dock", [False, True])
|
||||
def test_webui_detached_gateway_does_not_retain_launcher_lease(monkeypatch, tmp_path, managed, no_dock):
|
||||
config = tmp_path / "config.json"
|
||||
_patch_webui_provider_ready(monkeypatch)
|
||||
_patch_gateway_ports_free(monkeypatch)
|
||||
seen = _patch_webui_managed_gateway(monkeypatch)
|
||||
requested = []
|
||||
monkeypatch.setattr(cli_webui, "request_gateway_icon",
|
||||
lambda instance, *, enabled: requested.append((instance, enabled)))
|
||||
if managed:
|
||||
prefix = tmp_path / "managed"
|
||||
prefix.mkdir()
|
||||
(prefix / "nanobot-install.json").write_text(json.dumps({
|
||||
"schema_version": 1, "owner": "nanobot-installer", "environment": str(prefix), "extras": [],
|
||||
}))
|
||||
monkeypatch.setattr(sys, "prefix", str(prefix))
|
||||
result = runner.invoke(app, ["webui", "--config", str(config), "--yes", "--no-open",
|
||||
*([] if managed else ["--detach"]),
|
||||
*(["--no-dock"] if no_dock else [])])
|
||||
assert result.exit_code == 0, result.output
|
||||
assert "start_options" in seen
|
||||
assert "attached_runtime" not in seen
|
||||
assert "lease_release_wait_for_stop" not in seen
|
||||
assert "Stop nanobot" in result.stdout
|
||||
assert len(requested) == 1
|
||||
assert requested[0][0].parent == tmp_path / "run"
|
||||
assert requested[0][1] is not no_dock
|
||||
|
||||
|
||||
def test_webui_dev_starts_vite_sidecar_and_gateway(monkeypatch, tmp_path: Path) -> None:
|
||||
config_file = tmp_path / "config.json"
|
||||
config_file.write_text("{}", encoding="utf-8")
|
||||
@@ -2725,6 +2761,35 @@ def test_launch_browser_uses_unix_launcher_on_linux(monkeypatch) -> None:
|
||||
assert opened == ["http://127.0.0.1:8765/"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("no_dock", [False, True])
|
||||
def test_webui_dock_lifetime_wraps_the_attached_client(monkeypatch, tmp_path, no_dock):
|
||||
config_file = tmp_path / "config.json"
|
||||
config_file.write_text("{}")
|
||||
_patch_gateway_ports_free(monkeypatch)
|
||||
_patch_webui_provider_ready(monkeypatch)
|
||||
_patch_webui_managed_gateway(monkeypatch)
|
||||
events = []
|
||||
|
||||
@contextmanager
|
||||
def desktop(url, *, instance, enabled):
|
||||
assert url.startswith("http://127.0.0.1:")
|
||||
assert instance.parent == tmp_path / "run"
|
||||
assert enabled is not no_dock
|
||||
events.append("icon attached")
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
events.append("icon detached")
|
||||
|
||||
monkeypatch.setattr(cli_webui, "dock_icon", desktop)
|
||||
monkeypatch.setattr(cli_webui, "_attach_to_background_gateway",
|
||||
lambda *_args, **_kwargs: events.append("gateway attached"))
|
||||
result = runner.invoke(app, ["webui", "--config", str(config_file), "--no-open", "--yes",
|
||||
*(["--no-dock"] if no_dock else [])])
|
||||
assert result.exit_code == 0, result.output
|
||||
assert events == ["icon attached", "gateway attached", "icon detached"]
|
||||
|
||||
|
||||
def test_webui_foreground_attaches_to_existing_managed_gateway(monkeypatch, tmp_path: Path) -> None:
|
||||
config_file = tmp_path / "config.json"
|
||||
config_file.write_text("{}")
|
||||
@@ -3151,7 +3216,7 @@ def test_gateway_uses_workspace_directory_for_cron_store(monkeypatch, tmp_path:
|
||||
seen: dict[str, Path] = {}
|
||||
|
||||
class _StopCron:
|
||||
def __init__(self, store_path: Path) -> None:
|
||||
def __init__(self, store_path: Path, *, admission=None) -> None:
|
||||
seen["cron_store"] = store_path
|
||||
raise _StopGatewayError("stop")
|
||||
|
||||
@@ -3221,7 +3286,7 @@ def test_gateway_unbound_agent_cron_is_skipped(
|
||||
monkeypatch.setattr("nanobot.session.manager.SessionManager", _FakeSessionManager)
|
||||
|
||||
class _FakeCron:
|
||||
def __init__(self, _store_path: Path) -> None:
|
||||
def __init__(self, _store_path: Path, *, admission=None) -> None:
|
||||
self.on_job = None
|
||||
seen["cron"] = self
|
||||
|
||||
@@ -3334,7 +3399,7 @@ def test_gateway_bound_cron_runs_as_session_turn(
|
||||
monkeypatch.setattr("nanobot.session.manager.SessionManager", _FakeSessionManager)
|
||||
|
||||
class _FakeCron:
|
||||
def __init__(self, _store_path: Path) -> None:
|
||||
def __init__(self, _store_path: Path, *, admission=None) -> None:
|
||||
self.on_job = None
|
||||
seen["cron"] = self
|
||||
|
||||
@@ -3526,7 +3591,7 @@ def test_gateway_local_trigger_queue_submits_agent_turns(
|
||||
config,
|
||||
message_bus=lambda: bus,
|
||||
session_manager=lambda _workspace: _FakeSessionManager(),
|
||||
cron_service=lambda _store_path: _FakeCronService(),
|
||||
cron_service=lambda _store_path, **_kwargs: _FakeCronService(),
|
||||
)
|
||||
|
||||
class _FakeMemory:
|
||||
@@ -3687,7 +3752,7 @@ def test_gateway_workspace_override_does_not_migrate_legacy_cron(
|
||||
seen: dict[str, Path] = {}
|
||||
|
||||
class _StopCron:
|
||||
def __init__(self, store_path: Path) -> None:
|
||||
def __init__(self, store_path: Path, *, admission=None) -> None:
|
||||
seen["cron_store"] = store_path
|
||||
raise _StopGatewayError("stop")
|
||||
|
||||
@@ -3726,7 +3791,7 @@ def test_gateway_custom_config_workspace_does_not_migrate_legacy_cron(
|
||||
seen: dict[str, Path] = {}
|
||||
|
||||
class _StopCron:
|
||||
def __init__(self, store_path: Path) -> None:
|
||||
def __init__(self, store_path: Path, *, admission=None) -> None:
|
||||
seen["cron_store"] = store_path
|
||||
raise _StopGatewayError("stop")
|
||||
|
||||
@@ -3879,7 +3944,7 @@ def test_gateway_health_endpoint_binds_and_serves_expected_responses(
|
||||
return None
|
||||
|
||||
class _FakeCronService:
|
||||
def __init__(self, _store_path: Path) -> None:
|
||||
def __init__(self, _store_path: Path, *, admission=None) -> None:
|
||||
self.on_job = None
|
||||
|
||||
async def start(self) -> None:
|
||||
@@ -3971,6 +4036,10 @@ def test_gateway_health_endpoint_binds_and_serves_expected_responses(
|
||||
assert health_writer.closed is True
|
||||
assert "HTTP/1.0 200 OK" in health_response
|
||||
health_body = json.loads(health_response.split("\r\n\r\n", 1)[1])
|
||||
assert health_body.pop("maintenance") is False
|
||||
identity = health_body.pop("runtime")
|
||||
assert identity["version"] == cli_commands.__version__
|
||||
assert identity["instance_id"] and identity["run_id"]
|
||||
assert health_body == {
|
||||
"status": "ok",
|
||||
"process": "alive",
|
||||
@@ -4114,7 +4183,7 @@ def test_gateway_agent_task_owns_initial_mcp_provider_close(
|
||||
seen["channels_stopped"] = True
|
||||
|
||||
class _FakeCronService:
|
||||
def __init__(self, _store_path: Path) -> None:
|
||||
def __init__(self, _store_path: Path, *, admission=None) -> None:
|
||||
self.on_job = None
|
||||
|
||||
async def start(self) -> None:
|
||||
@@ -4251,7 +4320,7 @@ def test_gateway_shutdown_event_exits_forever_runtime_tasks(
|
||||
await asyncio.wait_for(channel_finished.wait(), timeout=1)
|
||||
|
||||
class _FakeCronService:
|
||||
def __init__(self, _store_path: Path) -> None:
|
||||
def __init__(self, _store_path: Path, *, admission=None) -> None:
|
||||
self.on_job = None
|
||||
|
||||
async def start(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user