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
+69
-2
@@ -7,6 +7,7 @@ import pytest
|
||||
|
||||
from nanobot.cli import entry
|
||||
from nanobot.cli.entry import _agent_invocation_args, _native_tui_candidate
|
||||
from nanobot.installation_lock import InstallationBusyError, installation_access, installation_id
|
||||
|
||||
|
||||
def test_root_command_routes_to_agent_without_copying_agent_options() -> None:
|
||||
@@ -70,7 +71,7 @@ def test_root_alias_dispatches_the_shared_agent_command(monkeypatch) -> None:
|
||||
"set_cli_process_identity",
|
||||
lambda args: calls.__setitem__("identity", args),
|
||||
)
|
||||
monkeypatch.setattr(entry, "_configure_windows_console", lambda: None)
|
||||
monkeypatch.setattr(entry, "configure_windows_console", lambda: None)
|
||||
monkeypatch.setattr(
|
||||
entry,
|
||||
"_run_agent",
|
||||
@@ -91,7 +92,7 @@ def test_desktop_handled_bare_invocation_does_not_start_python(monkeypatch) -> N
|
||||
|
||||
monkeypatch.setattr(entry.sys, "argv", ["nanobot"])
|
||||
monkeypatch.setattr(entry, "set_cli_process_identity", lambda _args: None)
|
||||
monkeypatch.setattr(entry, "_configure_windows_console", lambda: None)
|
||||
monkeypatch.setattr(entry, "configure_windows_console", lambda: None)
|
||||
monkeypatch.setattr(desktop_target, "dispatch_bare_desktop_target", lambda _args: 0)
|
||||
monkeypatch.setattr(
|
||||
entry,
|
||||
@@ -114,3 +115,69 @@ def test_classic_and_one_shot_agent_invocations_keep_the_full_cli_entrypoint() -
|
||||
assert not _native_tui_candidate(["agent", "-mhello"])
|
||||
assert not _native_tui_candidate(["agent", "--message=hello"])
|
||||
assert not _native_tui_candidate(["status"])
|
||||
|
||||
|
||||
def test_entry_refuses_dispatch_during_update(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path))
|
||||
monkeypatch.setattr(sys, "prefix", str(tmp_path / "environment"))
|
||||
monkeypatch.setattr(sys, "argv", ["nanobot", "gateway"])
|
||||
monkeypatch.setattr(entry, "_dispatch", lambda: pytest.fail("Runtime dispatched during update"))
|
||||
with installation_access(updating=True):
|
||||
with pytest.raises(SystemExit) as result:
|
||||
entry.main()
|
||||
assert result.value.code == 1
|
||||
assert "being updated" in capsys.readouterr().err
|
||||
|
||||
|
||||
@pytest.mark.parametrize("args", [["update"], ["--home", "/test", "update"], ["--home=/test", "update"]])
|
||||
def test_update_command_can_reach_its_own_lease_and_recovery(tmp_path, monkeypatch, args):
|
||||
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path))
|
||||
monkeypatch.setattr(sys, "prefix", str(tmp_path / "environment"))
|
||||
monkeypatch.setattr(sys, "argv", ["nanobot", *args])
|
||||
called = []
|
||||
monkeypatch.setattr(entry, "_dispatch", lambda: called.append(True))
|
||||
with installation_access(updating=True):
|
||||
entry.main()
|
||||
assert called == [True]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("args", [["update", "--job", "saved-id"],
|
||||
["--home=/test", "update", "--job=saved-id", "--retry-handoff"]])
|
||||
def test_saved_update_recovery_owns_runtime_before_application_imports(tmp_path, monkeypatch, args):
|
||||
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path))
|
||||
monkeypatch.setattr(sys, "prefix", str(tmp_path / "environment"))
|
||||
monkeypatch.setattr(sys, "argv", ["nanobot", *args])
|
||||
entered = []
|
||||
|
||||
def dispatch():
|
||||
with pytest.raises(InstallationBusyError):
|
||||
with installation_access(updating=True):
|
||||
pytest.fail("Recovery imported without a runtime lease")
|
||||
entered.append(True)
|
||||
|
||||
monkeypatch.setattr(entry, "_dispatch", dispatch)
|
||||
entry.main()
|
||||
assert entered == [True]
|
||||
with installation_access(updating=True):
|
||||
with pytest.raises(SystemExit):
|
||||
entry.main()
|
||||
assert entered == [True]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("action,allowed", [("stop", True), ("status", True), ("logs", True), ("restart", False)])
|
||||
def test_interrupted_installation_keeps_stop_commands_usable(tmp_path, monkeypatch, action, allowed):
|
||||
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path))
|
||||
monkeypatch.setattr(sys, "prefix", str(tmp_path / "environment"))
|
||||
pending = tmp_path / ".nanobot/run" / f"update-{installation_id()[:16]}.pending"
|
||||
pending.parent.mkdir(parents=True)
|
||||
pending.write_text("incomplete")
|
||||
monkeypatch.setattr(sys, "argv", ["nanobot", "--home", str(tmp_path / "profile"), "gateway", action])
|
||||
called = []
|
||||
monkeypatch.setattr(entry, "_dispatch", lambda: called.append(True))
|
||||
if allowed:
|
||||
entry.main()
|
||||
assert called == [True]
|
||||
else:
|
||||
with pytest.raises(SystemExit):
|
||||
entry.main()
|
||||
assert not called
|
||||
Reference in new issue
Block a user