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
@@ -0,0 +1,76 @@
|
||||
"""Identity-bound local HTTP readiness; ordinary legacy health remains compatible."""
|
||||
|
||||
import json
|
||||
import threading
|
||||
from dataclasses import asdict, replace
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
import pytest
|
||||
|
||||
from nanobot.gateway.runtime import (
|
||||
GatewayHealthIdentity,
|
||||
GatewayRuntime,
|
||||
GatewayRuntimePaths,
|
||||
GatewayStartOptions,
|
||||
_gateway_health_ready,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def health_server():
|
||||
reply = {"status": 200, "body": b'{"status":"ok"}'}
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
assert self.path == "/health"
|
||||
self.send_response(reply["status"])
|
||||
self.end_headers()
|
||||
self.wfile.write(reply["body"])
|
||||
|
||||
def log_message(self, *_args):
|
||||
pass
|
||||
|
||||
server = HTTPServer(("127.0.0.1", 0), Handler)
|
||||
thread = threading.Thread(target=server.serve_forever, daemon=True)
|
||||
thread.start()
|
||||
try:
|
||||
yield server.server_address[1], reply
|
||||
finally:
|
||||
server.shutdown()
|
||||
server.server_close()
|
||||
thread.join(timeout=5)
|
||||
assert not thread.is_alive()
|
||||
|
||||
|
||||
def test_restart_requires_identity_while_legacy_health_still_works(tmp_path, health_server):
|
||||
port, reply = health_server
|
||||
runtime = GatewayRuntime(paths=GatewayRuntimePaths.for_instance(data_dir=tmp_path))
|
||||
identity = GatewayHealthIdentity("a" * 64, "b" * 32, "0.3.6")
|
||||
with runtime.foreground_instance(GatewayStartOptions(port=port)):
|
||||
runtime.publish_health_host("127.0.0.1")
|
||||
assert _gateway_health_ready("127.0.0.1", port)
|
||||
assert not runtime.verify_ready(identity) # Older / unrelated HTTP 200.
|
||||
reply["body"] = json.dumps({
|
||||
"status": "ok", "ready": True,
|
||||
"runtime": {**asdict(identity), "future_optional_field": "ignored"},
|
||||
}).encode()
|
||||
assert runtime.verify_ready(identity)
|
||||
for wrong in (
|
||||
replace(identity, instance_id="c" * 64),
|
||||
replace(identity, run_id="d" * 32),
|
||||
replace(identity, version="0.3.5"),
|
||||
):
|
||||
assert not runtime.verify_ready(wrong)
|
||||
assert not runtime.verify_ready(identity) # Port alone outlives its owner.
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status,body", [
|
||||
(503, b'{"status":"ok","ready":true}'),
|
||||
(200, b'{"status":"ok","ready":false}'),
|
||||
(200, b'{"status":"ok"}' + b' ' * 4096),
|
||||
(200, b'[]'),
|
||||
])
|
||||
def test_unready_or_invalid_response_cannot_confirm_restart(health_server, status, body):
|
||||
port, reply = health_server
|
||||
reply.update(status=status, body=body)
|
||||
assert not _gateway_health_ready("127.0.0.1", port, expected=GatewayHealthIdentity("a" * 64, "b" * 32, "0.3.6"))
|
||||
@@ -49,6 +49,41 @@ def _paths(tmp_path: Path) -> GatewayRuntimePaths:
|
||||
return GatewayRuntimePaths.for_instance(data_dir=tmp_path)
|
||||
|
||||
|
||||
def test_runtime_state_publish_keeps_existing_snapshot_readable(tmp_path):
|
||||
"""Status polling must not prevent a gateway from publishing readiness."""
|
||||
from nanobot.utils.atomic_file import _open_snapshot
|
||||
|
||||
runtime = GatewayRuntime(paths=_paths(tmp_path / "网关 home"))
|
||||
previous = {"pid": os.getpid(), "identity": "fixture", "command": ["nanobot", "gateway"]}
|
||||
current = {**previous, "health_host": "127.0.0.1"}
|
||||
runtime._write_state(previous)
|
||||
with _open_snapshot(runtime.paths.state_path) as snapshot:
|
||||
runtime._write_state(current)
|
||||
assert json.loads(snapshot.read()) == previous
|
||||
assert runtime._read_state() == current
|
||||
assert list(runtime.paths.run_dir.glob("*.tmp")) == []
|
||||
if os.name != "nt":
|
||||
assert runtime.paths.state_path.stat().st_mode & 0o777 == 0o600
|
||||
|
||||
|
||||
def test_runtime_state_reader_does_not_block_publish_while_decoding(tmp_path, monkeypatch):
|
||||
"""Pause a real status read while a readiness update replaces its record."""
|
||||
runtime = GatewayRuntime(paths=_paths(tmp_path))
|
||||
previous = {"pid": os.getpid(), "identity": "fixture"}
|
||||
current = {**previous, "health_host": "127.0.0.1"}
|
||||
runtime._write_state(previous)
|
||||
decode = json.loads
|
||||
|
||||
def publish_during_decode(value, **kwargs):
|
||||
runtime._write_state(current)
|
||||
return decode(value, **kwargs)
|
||||
|
||||
with monkeypatch.context() as patch:
|
||||
patch.setattr("nanobot.process_runtime.json.loads", publish_during_decode)
|
||||
assert runtime._read_state() == previous
|
||||
assert runtime._read_state() == current
|
||||
|
||||
|
||||
_FOREGROUND_CHILD = r"""
|
||||
import os
|
||||
import signal
|
||||
|
||||
Reference in new issue
Block a user