feat(remote): rename servers without interrupting host sessions

This commit is contained in:
Xubin Ren committed 2026-10-02 11:36:34 +08:00
1 parent 47c587217d
commit 719a5c3fcf
19 files changed
+294 -8

No files matched your search

+35
View File
@@ -83,6 +83,41 @@ async def test_new_local_manager_has_new_view_identity_for_same_remote(manager,
assert "view_id" not in manager.path.read_text()
async def test_rename_connected_profile_only_changes_display_name(manager, ssh):
key = await save(manager)
await manager.action("connect", {"id": key})
before = json.loads(manager.path.read_text())
live = manager.connections[key]
result = await manager.action("rename", {"id": key, "name": " 腾讯云 nanobot "})
assert result["profiles"][0]["name"] == "腾讯云 nanobot"
assert result["profiles"][0]["connected"] is True
before[key]["name"] = "腾讯云 nanobot"
assert json.loads(manager.path.read_text()) == before
assert RemoteInstances(manager.path.parent).snapshot()["profiles"][0]["name"] == "腾讯云 nanobot"
assert manager.connections[key] is live
ssh.tunnel.pause.assert_not_awaited()
ssh.tunnel.close.assert_not_awaited()
assert ssh.probe.await_count == 1
@pytest.mark.parametrize("name", [None, 7, {}, "", " ", "a" * 65, "a\nb", "a\x00b", "a\x7fb"])
async def test_rename_invalid_name_does_not_change_saved_profile(manager, name):
key = await save(manager)
before = manager.path.read_bytes()
with pytest.raises(RemoteError, match="invalid_name"):
await manager.action("rename", {"id": key, "name": name})
assert manager.path.read_bytes() == before
async def test_rename_validates_id_and_does_not_merge_matching_names(manager):
first = await save(manager)
second = await save(manager, host="other-host")
await manager.action("rename", {"id": first, "name": "x" * 64})
assert manager._read()[second].name == "Team"
with pytest.raises(RemoteError, match="profile_not_found"):
await manager.action("rename", {"id": "missing", "name": "Team"})
async def test_unchanged_save_allows_retry_after_browser_load_failure(manager, ssh):
key = await save(manager)
await manager.action("connect", {"id": key})
+24
View File
@@ -279,6 +279,30 @@ async def test_same_name_or_ip_never_groups_different_pairing_destinations(tmp_p
assert len({item["instance_id"] for item in result["profiles"]}) == 2
async def test_rename_paired_instance_updates_only_verified_sibling_grants(tmp_path):
manager = RemoteInstances(tmp_path)
first = read_request((await manager.action("pair_start", {}))["command"].split()[-1])
original = receipt(first)
await manager.action("pair_finish", {"id": first.id, "code": seal(first, original)})
requests = [first]
for path in [original.config_path, "/srv/different/config.json"]:
request = read_request((await manager.action("pair_start", {}))["command"].split()[-1])
value = original.model_copy(update={"id": request.id, "ssh_key": request.ssh_key, "config_path": path})
await manager.action("pair_finish", {"id": request.id, "code": seal(request, value)})
requests.append(request)
before = manager._read()
receipts = {item.id: manager.pairing.path(item.id).joinpath("receipt").read_bytes() for item in requests}
live = SimpleNamespace(tunnel=SimpleNamespace(active=True), error="", gateway_id="live-session",
proxy=SimpleNamespace(pause=AsyncMock()))
manager.connections[first.id] = live
result = await manager.action("rename", {"id": requests[1].id, "name": "My cloud"})
assert [p["name"] for p in result["profiles"]] == ["My cloud", "My cloud", original.hostname]
for item in requests:
assert manager.pairing.path(item.id).joinpath("receipt").read_bytes() == receipts[item.id]
assert manager._read()[item.id].model_dump(exclude={"name"}) == before[item.id].model_dump(exclude={"name"})
live.proxy.pause.assert_not_awaited()
@pytest.mark.parametrize("healthy", [True, False])
async def test_repair_retains_route_and_reuses_only_a_healthy_existing_connection(tmp_path, monkeypatch, healthy):
manager = RemoteInstances(tmp_path)