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:
Xubin Renandchengyongru authored and GitHub committed 2026-10-21 19:16:56 +08:00
1 parent 76da55994b
commit fbb61a373f
216 files changed
+27948 -1084

No files matched your search

@@ -1,12 +1,15 @@
import asyncio
from unittest.mock import AsyncMock, MagicMock
import pytest
from nanobot.bus.events import OutboundMessage
from nanobot.bus.queue import MessageBus
from nanobot.channels import manager as manager_module
from nanobot.channels.base import BaseChannel
from nanobot.channels.manager import ChannelManager
from nanobot.config.schema import Config
from nanobot.runtime_admission import RuntimeBusyError
def make_manager():
@@ -15,10 +18,66 @@ def make_manager():
channel = MagicMock(spec=BaseChannel)
channel.send = AsyncMock()
channel.stop = AsyncMock()
channel.has_pending_delivery = False
manager.channels["websocket"] = channel
return manager, channel
async def test_delivery_has_no_idle_gap_between_queue_dispatch_and_send(monkeypatch):
manager, channel = make_manager()
started, release = asyncio.Event(), asyncio.Event()
observations = []
consume = manager.bus.consume_outbound
def require_busy():
if manager.bus.admission.paused:
observations.append("parked")
return
with pytest.raises(RuntimeBusyError):
with manager.bus.admission.pause_if_idle(lambda: False):
pytest.fail("Delivery was incorrectly reported idle")
observations.append("busy")
assert not manager.bus.admission.paused
async def dequeue():
message = await consume()
asyncio.get_running_loop().call_soon(require_busy)
return message
async def send(message):
started.set()
await release.wait()
monkeypatch.setattr(manager.bus, "consume_outbound", dequeue)
channel.send.side_effect = send
await manager.bus.publish_outbound(OutboundMessage("websocket", "chat", "final reply"))
require_busy()
manager._dispatch_task = asyncio.create_task(manager._dispatch_outbound())
try:
await asyncio.wait_for(started.wait(), 2)
assert manager.bus.outbound_size == 0
require_busy()
assert observations == ["busy", "busy", "busy"]
release.set()
await wait_until(lambda: not manager.has_pending_delivery)
with manager.bus.admission.pause_if_idle(lambda: False):
assert manager.bus.admission.paused
# A late producer may queue a lifecycle notice while the consumer
# is awaiting an empty queue. It must remain parked until admission
# is restored, rather than start new transport writes under the gate.
await manager.bus.publish_outbound(OutboundMessage("websocket", "chat", "late notice"))
await wait_until(lambda: manager._outbound_dispatching)
await wait_until(lambda: len(observations) == 4)
channel.send.assert_awaited_once()
assert not manager.bus.admission.paused
await wait_until(lambda: not manager.has_pending_delivery)
assert [call.args[0].content for call in channel.send.await_args_list] == ["final reply", "late notice"]
assert observations == ["busy", "busy", "busy", "parked"]
finally:
release.set()
await manager.stop_all()
async def wait_until(predicate):
async with asyncio.timeout(2):
while not predicate():
+11 -11
View File
@@ -306,12 +306,17 @@ def test_special_setup_validation_is_owned_by_channel_package(name: str):
@pytest.mark.parametrize("name", ["feishu", "linear", "qq", "weixin", "whatsapp"])
def test_interactive_connector_is_owned_by_channel_package(name: str):
from nanobot.channels.connect import ManagedChannelConnector
plugin = load_channel_package(name)
assert plugin is not None
assert plugin.connector is not None
assert plugin.connector.startswith(f"nanobot.channels.{name}.")
assert plugin.load_connector().__class__.__module__ == f"nanobot.channels.{name}.connect"
connector = plugin.load_connector()
assert connector.__class__.__module__ == f"nanobot.channels.{name}.connect"
assert isinstance(connector, ManagedChannelConnector)
assert connector.has_pending_work is False
def test_descriptor_defaults_cover_onboarding_fields_without_runtime_import():
@@ -3559,9 +3564,8 @@ async def test_stop_all_cancels_dispatcher_and_stops_channels():
providers=SimpleNamespace(groq=SimpleNamespace(api_key="")),
)
mgr = ChannelManager.__new__(ChannelManager)
mgr = ChannelManager(Config.model_validate({"channels": {"websocket": {"enabled": False}}}), MessageBus())
mgr.config = fake_config
mgr.bus = MessageBus()
ch = _StartableChannel(fake_config, mgr.bus)
mgr.channels = {"startable": ch}
@@ -3641,9 +3645,8 @@ async def test_stop_all_handles_channel_exception():
providers=SimpleNamespace(groq=SimpleNamespace(api_key="")),
)
mgr = ChannelManager.__new__(ChannelManager)
mgr = ChannelManager(Config.model_validate({"channels": {"websocket": {"enabled": False}}}), MessageBus())
mgr.config = fake_config
mgr.bus = MessageBus()
mgr.channels = {"stopfailing": _StopFailingChannel(fake_config, mgr.bus)}
mgr._channel_tasks = {}
mgr._outbound_tasks = {}
@@ -3678,9 +3681,8 @@ async def test_stop_all_handles_channel_stop_cancelled_task():
providers=SimpleNamespace(groq=SimpleNamespace(api_key="")),
)
mgr = ChannelManager.__new__(ChannelManager)
mgr = ChannelManager(Config.model_validate({"channels": {"websocket": {"enabled": False}}}), MessageBus())
mgr.config = fake_config
mgr.bus = MessageBus()
next_channel = _StartableChannel(fake_config, mgr.bus)
mgr.channels = {
"stopcancelled": _StopCancelledChannel(fake_config, mgr.bus),
@@ -3704,9 +3706,8 @@ async def test_start_all_no_channels_logs_warning():
providers=SimpleNamespace(groq=SimpleNamespace(api_key="")),
)
mgr = ChannelManager.__new__(ChannelManager)
mgr = ChannelManager(Config.model_validate({"channels": {"websocket": {"enabled": False}}}), MessageBus())
mgr.config = fake_config
mgr.bus = MessageBus()
mgr.channels = {} # No channels
mgr._dispatch_task = None
@@ -3724,9 +3725,8 @@ async def test_start_all_creates_dispatch_task():
providers=SimpleNamespace(groq=SimpleNamespace(api_key="")),
)
mgr = ChannelManager.__new__(ChannelManager)
mgr = ChannelManager(Config.model_validate({"channels": {"websocket": {"enabled": False}}}), MessageBus())
mgr.config = fake_config
mgr.bus = MessageBus()
ch = _StartableChannel(fake_config, mgr.bus)
mgr.channels = {"startable": ch}
+53
View File
@@ -33,6 +33,7 @@ from nanobot.cron.bound_runner import run_bound_cron_job
from nanobot.cron.service import CronService
from nanobot.cron.types import CronSchedule
from nanobot.providers.base import GenerationSettings, LLMResponse, ToolCallRequest
from nanobot.runtime_admission import RuntimeBusyError, RuntimeMaintenanceError
from nanobot.session.manager import SessionManager
@@ -62,6 +63,58 @@ async def drain(manager):
await asyncio.sleep(0.01)
async def test_parked_gateway_neither_initializes_nor_records_scheduled_delivery(tmp_path):
manager = make_manager(tmp_path)
try:
with manager.bus.admission.pause_before_start():
manager._dispatch_task = asyncio.create_task(manager._dispatch_outbound())
await asyncio.sleep(0)
assert not manager._outbox.path.exists()
with pytest.raises(RuntimeMaintenanceError):
await manager.bus.publish_outbound(message())
with pytest.raises(RuntimeMaintenanceError):
await manager._recover_scheduled()
assert not manager._outbox.path.exists()
assert manager.bus.outbound_size == 0
await manager.bus.publish_outbound(message())
assert manager._outbox.path.exists()
finally:
await manager.stop_all()
async def test_scheduled_recovery_remains_busy_while_waiting_for_a_send_slot(tmp_path, monkeypatch):
manager = make_manager(tmp_path)
channel = MagicMock(spec=BaseChannel, send=AsyncMock(), stop=AsyncMock())
channel.has_pending_delivery = False
manager.channels["whatsapp"] = channel
manager._outbox.record(message())
manager._outbound_slots = asyncio.Semaphore(0)
queued = asyncio.Event()
queue = manager._queue_outbound
async def wait_for_slot(channel, msg):
queued.set()
await queue(channel, msg)
monkeypatch.setattr(manager, "_queue_outbound", wait_for_slot)
recovery = asyncio.create_task(manager._recover_scheduled())
try:
await asyncio.wait_for(queued.wait(), 2)
assert not manager._outbound_tasks
with pytest.raises(RuntimeBusyError):
with manager.bus.admission.pause_if_idle(lambda: False):
pytest.fail("Durable recovery was admitted during maintenance")
manager._outbound_slots.release()
await asyncio.wait_for(recovery, 2)
await drain(manager)
channel.send.assert_awaited_once()
assert rows(manager._outbox)[0]["status"] == "sent"
finally:
recovery.cancel()
await asyncio.gather(recovery, return_exceptions=True)
await manager.stop_all()
@pytest.mark.parametrize("legacy_message,one_shot,origin", [
(False, False, "whatsapp"), (True, False, "whatsapp"), (True, True, "whatsapp"),
(True, False, "websocket"),