;
diff --git a/webui/src/components/remote/RemoteInstances.tsx b/webui/src/components/remote/RemoteInstances.tsx
index 26bac669f..914029c30 100644
--- a/webui/src/components/remote/RemoteInstances.tsx
+++ b/webui/src/components/remote/RemoteInstances.tsx
@@ -2,7 +2,7 @@ import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState
import { Loader2, PlugZap } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
-import { needsRemoteSetup, type RemoteDirectory } from "@/lib/remote-instances";
+import { groupRemoteProfiles, needsRemoteSetup, type RemoteDirectory } from "@/lib/remote-instances";
import { useHostSessions } from "./useHostSessions";
import { HostNavigationContext, HostSwitcher, RemoteHostMenu, type HostPicker } from "./HostSwitcher";
import { useSidebarHostBridge } from "./useSidebarHostBridge";
@@ -101,7 +101,8 @@ export function RemoteInstances({ children }: { children: ReactNode }) {
const picker: HostPicker = {
kind: "shell", name: selected?.name || t("remote.localShort"), hostname: selected?.hostname || directory?.machine_name || "nanobot",
localName: directory?.machine_name || "nanobot", currentId: selected?.id || null, recentIds: hosts.recentIds,
- profiles: (directory?.profiles || []).map(({ id, name, host }) => ({ id, name, host, state: hostStates[id] })),
+ profiles: groupRemoteProfiles(directory?.profiles || [], selected?.id || null)
+ .map(({ profile: { id, name, host } }) => ({ id, name, host, state: hostStates[id] })),
pending, error: message, offline: !!offline,
select: (id) => {
if (!id) selectLocal();
diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.json
index 2361f5cc8..2284d22f9 100644
--- a/webui/src/i18n/locales/en/common.json
+++ b/webui/src/i18n/locales/en/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "Forget",
+ "switchHint": "To use another authorization, disconnect the open connection first.",
+ "title": "This nanobot is already saved",
+ "saveAndOpen": "Save and open",
+ "pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
+ "details": "Connection details",
+ "detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
+ "connection": "Connection {{count}}",
+ "manageConnection": "Manage connection {{count}}",
+ "forgetConnection": "Forget connection",
+ "forgetTitle": "Forget this connection?",
+ "forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
+ },
"activeForgetWarning": "All tabs using this connection will disconnect. Unsaved work may be lost.",
"saved": "Saved",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
- "profile_limit": "You can save up to 20 servers.",
+ "profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.json
index 6f3e274cc..4fd1bdc70 100644
--- a/webui/src/i18n/locales/es/common.json
+++ b/webui/src/i18n/locales/es/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "Forget",
+ "switchHint": "To use another authorization, disconnect the open connection first.",
+ "title": "This nanobot is already saved",
+ "saveAndOpen": "Save and open",
+ "pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
+ "details": "Connection details",
+ "detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
+ "connection": "Connection {{count}}",
+ "manageConnection": "Manage connection {{count}}",
+ "forgetConnection": "Forget connection",
+ "forgetTitle": "Forget this connection?",
+ "forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
+ },
"activeForgetWarning": "Se desconectarán todas las pestañas que usen esta conexión. El trabajo sin guardar puede perderse.",
"saved": "Guardado",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
- "profile_limit": "You can save up to 20 servers.",
+ "profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.json
index cd6aee42a..234792e87 100644
--- a/webui/src/i18n/locales/fr/common.json
+++ b/webui/src/i18n/locales/fr/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "Forget",
+ "switchHint": "To use another authorization, disconnect the open connection first.",
+ "title": "This nanobot is already saved",
+ "saveAndOpen": "Save and open",
+ "pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
+ "details": "Connection details",
+ "detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
+ "connection": "Connection {{count}}",
+ "manageConnection": "Manage connection {{count}}",
+ "forgetConnection": "Forget connection",
+ "forgetTitle": "Forget this connection?",
+ "forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
+ },
"activeForgetWarning": "Tous les onglets utilisant cette connexion seront déconnectés. Le travail non enregistré peut être perdu.",
"saved": "Enregistré",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
- "profile_limit": "You can save up to 20 servers.",
+ "profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.json
index a2bce9c50..ea30ae7f3 100644
--- a/webui/src/i18n/locales/id/common.json
+++ b/webui/src/i18n/locales/id/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "Forget",
+ "switchHint": "To use another authorization, disconnect the open connection first.",
+ "title": "This nanobot is already saved",
+ "saveAndOpen": "Save and open",
+ "pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
+ "details": "Connection details",
+ "detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
+ "connection": "Connection {{count}}",
+ "manageConnection": "Manage connection {{count}}",
+ "forgetConnection": "Forget connection",
+ "forgetTitle": "Forget this connection?",
+ "forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
+ },
"activeForgetWarning": "Semua tab yang memakai koneksi ini akan terputus. Pekerjaan yang belum disimpan dapat hilang.",
"saved": "Tersimpan",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
- "profile_limit": "You can save up to 20 servers.",
+ "profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.json
index 6e39159ee..ab303e86e 100644
--- a/webui/src/i18n/locales/ja/common.json
+++ b/webui/src/i18n/locales/ja/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "Forget",
+ "switchHint": "To use another authorization, disconnect the open connection first.",
+ "title": "This nanobot is already saved",
+ "saveAndOpen": "Save and open",
+ "pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
+ "details": "Connection details",
+ "detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
+ "connection": "Connection {{count}}",
+ "manageConnection": "Manage connection {{count}}",
+ "forgetConnection": "Forget connection",
+ "forgetTitle": "Forget this connection?",
+ "forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
+ },
"activeForgetWarning": "この接続を使用しているすべてのタブが切断されます。未保存の内容が失われる可能性があります。",
"saved": "保存済み",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
- "profile_limit": "You can save up to 20 servers.",
+ "profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.json
index 2c1701434..4eb5e9bb5 100644
--- a/webui/src/i18n/locales/ko/common.json
+++ b/webui/src/i18n/locales/ko/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "Forget",
+ "switchHint": "To use another authorization, disconnect the open connection first.",
+ "title": "This nanobot is already saved",
+ "saveAndOpen": "Save and open",
+ "pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
+ "details": "Connection details",
+ "detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
+ "connection": "Connection {{count}}",
+ "manageConnection": "Manage connection {{count}}",
+ "forgetConnection": "Forget connection",
+ "forgetTitle": "Forget this connection?",
+ "forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
+ },
"activeForgetWarning": "이 연결을 사용하는 모든 탭의 연결이 끊어집니다. 저장하지 않은 내용이 손실될 수 있습니다.",
"saved": "저장됨",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
- "profile_limit": "You can save up to 20 servers.",
+ "profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.json
index 605fc5ad9..4294ec87e 100644
--- a/webui/src/i18n/locales/pt-BR/common.json
+++ b/webui/src/i18n/locales/pt-BR/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "Forget",
+ "switchHint": "To use another authorization, disconnect the open connection first.",
+ "title": "This nanobot is already saved",
+ "saveAndOpen": "Save and open",
+ "pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
+ "details": "Connection details",
+ "detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
+ "connection": "Connection {{count}}",
+ "manageConnection": "Manage connection {{count}}",
+ "forgetConnection": "Forget connection",
+ "forgetTitle": "Forget this connection?",
+ "forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
+ },
"activeForgetWarning": "Todas as abas que usam esta conexão serão desconectadas. O trabalho não salvo pode ser perdido.",
"saved": "Salvo",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
- "profile_limit": "You can save up to 20 servers.",
+ "profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.json
index 2927be7f8..a72a557fb 100644
--- a/webui/src/i18n/locales/vi/common.json
+++ b/webui/src/i18n/locales/vi/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "Forget",
+ "switchHint": "To use another authorization, disconnect the open connection first.",
+ "title": "This nanobot is already saved",
+ "saveAndOpen": "Save and open",
+ "pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
+ "details": "Connection details",
+ "detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
+ "connection": "Connection {{count}}",
+ "manageConnection": "Manage connection {{count}}",
+ "forgetConnection": "Forget connection",
+ "forgetTitle": "Forget this connection?",
+ "forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
+ },
"activeForgetWarning": "Tất cả thẻ đang dùng kết nối này sẽ bị ngắt. Nội dung chưa lưu có thể bị mất.",
"saved": "Đã lưu",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
- "profile_limit": "You can save up to 20 servers.",
+ "profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.json
index ae22ecb02..0e6e11ffd 100644
--- a/webui/src/i18n/locales/zh-CN/common.json
+++ b/webui/src/i18n/locales/zh-CN/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "忘记",
+ "switchHint": "要使用另一份授权,请先断开当前连接。",
+ "title": "这个 nanobot 已连接过",
+ "saveAndOpen": "保存并打开",
+ "pairHint": "服务器列表只保留一条。这次授权也会保存,已有连接不会被删除。",
+ "details": "连接详情",
+ "detailsHint": "这些连接指向同一个 nanobot。选择一个使用,或管理它的授权。",
+ "connection": "连接 {{count}}",
+ "manageConnection": "管理连接 {{count}}",
+ "forgetConnection": "忘记此连接",
+ "forgetTitle": "忘记此连接?",
+ "forgetHint": "只移除此电脑上的这条连接,其他连接和服务器上的数据会保留。"
+ },
"activeForgetWarning": "也会断开正在使用此连接的标签页,未保存的内容可能丢失。",
"saved": "已保存",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "无法读取已保存的连接,原文件未被覆盖。",
"invalid_profile": "请检查服务器地址、端口和连接选项。",
"profile_not_found": "这个连接已不存在,请刷新列表。",
- "profile_limit": "最多可以保存 20 台服务器。",
+ "profile_limit": "最多保存 20 条连接。请先在连接详情中移除不再使用的授权,或忘记不再使用的服务器。",
"connection_limit": "请先断开一台服务器,再建立新连接。",
"disconnect_before_edit": "请先断开这个服务器,再编辑连接信息。",
"local_io_error": "无法保存或打开连接,请检查本机文件权限。",
diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.json
index 5750073c4..9a0bbd132 100644
--- a/webui/src/i18n/locales/zh-TW/common.json
+++ b/webui/src/i18n/locales/zh-TW/common.json
@@ -1,5 +1,19 @@
{
"remote": {
+ "sameInstance": {
+ "forgetAction": "忘記",
+ "switchHint": "若要使用另一份授權,請先中斷目前連線。",
+ "title": "這個 nanobot 已連線過",
+ "saveAndOpen": "儲存並開啟",
+ "pairHint": "伺服器清單只保留一筆。這次授權也會儲存,已有連線不會被刪除。",
+ "details": "連線詳情",
+ "detailsHint": "這些連線指向同一個 nanobot。選擇一個使用,或管理它的授權。",
+ "connection": "連線 {{count}}",
+ "manageConnection": "管理連線 {{count}}",
+ "forgetConnection": "忘記此連線",
+ "forgetTitle": "忘記此連線?",
+ "forgetHint": "只移除此電腦上的這筆連線,其他連線與伺服器上的資料會保留。"
+ },
"activeForgetWarning": "也會中斷正在使用此連線的分頁,未儲存的內容可能遺失。",
"saved": "已儲存",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
- "profile_limit": "You can save up to 20 servers.",
+ "profile_limit": "最多儲存 20 筆連線。請先在連線詳情中移除不再使用的授權,或忘記不再使用的伺服器。",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
diff --git a/webui/src/lib/remote-instances.ts b/webui/src/lib/remote-instances.ts
index 330a121b9..4ad4097ff 100644
--- a/webui/src/lib/remote-instances.ts
+++ b/webui/src/lib/remote-instances.ts
@@ -15,10 +15,36 @@ export interface RemoteProfile {
view_id?: string;
connection_error?: string;
paired?: boolean;
+ /** Opaque grouping ID supplied only after the local backend verifies receipts. */
+ instance_id?: string;
revoke_command?: string;
authorized_until?: number;
}
+export interface RemoteProfileGroup {
+ id: string;
+ profile: RemoteProfile;
+ connections: RemoteProfile[];
+}
+
+/** One visible instance; keep every underlying grant available in details. */
+export function groupRemoteProfiles(profiles: RemoteProfile[], currentId: string | null): RemoteProfileGroup[] {
+ const groups = new Map();
+ for (const profile of profiles) {
+ const id = profile.instance_id || profile.id;
+ const group = groups.get(id) || [];
+ group.push(profile);
+ groups.set(id, group);
+ }
+ return [...groups].map(([id, connections]) => {
+ const preferred = connections.find((item) => item.id === currentId)
+ || connections.find((item) => item.connected)
+ || [...connections].reverse().find((item) => item.authorized_until != null && item.authorized_until * 1000 > Date.now())
+ || connections[0];
+ return { id, profile: { ...preferred, name: connections[0].name }, connections };
+ });
+}
+
/** Persistent setup problems need a repair path, not an endless Retry button. */
export function needsRemoteSetup(code: string): boolean {
return /^(pair_|host_key_|ssh_auth_failed$|ssh_agent_refused$|ssh_key_permissions$|ssh_config_|local_file_not_found$|remote_auth_failed$|incompatible_gateway$|webui_disabled$|profile_not_found$)/.test(code);
diff --git a/webui/src/tests/quick-pair.test.tsx b/webui/src/tests/quick-pair.test.tsx
index a499d0af9..b437f9acc 100644
--- a/webui/src/tests/quick-pair.test.tsx
+++ b/webui/src/tests/quick-pair.test.tsx
@@ -65,6 +65,22 @@ async function reviewed() {
}
describe("quick pairing", () => {
+ it("explains an existing instance and saves its additional authorization only on confirmation", async () => {
+ mocks.action.mockImplementation(async (action: string) => {
+ if (action === "remote.pair_preview") return { ...preview, existing_connection: { id: "saved-server", name: "My team", connected: true } };
+ if (action === "remote.pair_finish") return { id: "saved-server" };
+ return {};
+ });
+ returnedView();
+ await screen.findByRole("heading", { name: "This nanobot is already saved" });
+ expect(screen.getByText("My team")).toBeVisible();
+ expect(screen.getByText(i18n.t("remote.sameInstance.pairHint"))).toBeVisible();
+ expect(mocks.action.mock.calls.some(([action]) => action === "remote.pair_finish")).toBe(false);
+ expect(mocks.connect).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole("button", { name: "Save and open" }));
+ await waitFor(() => expect(mocks.connect).toHaveBeenCalledWith("saved-server", expect.any(Function)));
+ expect(mocks.action).toHaveBeenCalledWith("remote.pair_finish", { id: "request-1", code: "nbpc1.encrypted" }, 65000);
+ });
it("introduces remote access with the original logo and no duplicate instruction spacer", async () => {
view();
await waitFor(() => expect(screen.getByRole("button", { name: "Copy command" })).toBeEnabled());
diff --git a/webui/src/tests/remote-instances.test.tsx b/webui/src/tests/remote-instances.test.tsx
index 5a00c734c..00f079755 100644
--- a/webui/src/tests/remote-instances.test.tsx
+++ b/webui/src/tests/remote-instances.test.tsx
@@ -91,6 +91,51 @@ function chooseExistingSSH() {
}
describe("remote instance UX", () => {
+ it("shows one verified instance in management and the switcher while retaining both grants in details", async () => {
+ const second = { ...profile, id: "f1b18099-61d5-41d7-9c1d-6f647f7000e5", paired: true, instance_id: profile.id };
+ mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, paired: true, instance_id: profile.id }, second] });
+ view();
+ await openDirectory();
+ expect(screen.getAllByRole("button", { name: "Team server ubuntu@example.test" })).toHaveLength(1);
+ fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
+ fireEvent.click(screen.getByRole("menuitem", { name: "Connection details" }));
+ const details = await screen.findByRole("dialog", { name: "Connection details" });
+ expect(within(details).getByRole("button", { name: /^Connection 1 / })).toBeVisible();
+ expect(within(details).getByRole("button", { name: /^Connection 2 / })).toBeVisible();
+ fireEvent.pointerDown(within(details).getByRole("button", { name: "Manage connection 1" }), { button: 0, ctrlKey: false });
+ fireEvent.click(screen.getByRole("menuitem", { name: "Forget connection" }));
+ expect(await screen.findByRole("dialog", { name: "Forget this connection?" })).toHaveTextContent(i18n.t("remote.sameInstance.forgetHint"));
+ expect(screen.getByRole("button", { name: "Forget", exact: true })).toBeVisible();
+ expect(screen.getByRole("button", { name: "Forget", exact: true }).firstElementChild).not.toHaveClass("truncate");
+ expect(screen.queryByRole("button", { name: "Forget server", exact: true })).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
+ expect(mocks.request).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
+ fireEvent.pointerDown(screen.getByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false });
+ expect(await screen.findAllByRole("menuitem", { name: "Team server ubuntu@example.test" })).toHaveLength(1);
+ });
+
+ it("keeps same-address unverified instances separate and shows their config paths", async () => {
+ mocks.read.mockResolvedValue({ available: true, profiles: [profile, { ...profile, id: "another", config_path: "/srv/other/config.json" }] });
+ view(); await openDirectory();
+ expect(screen.getAllByRole("button", { name: "Team server ubuntu@example.test" })).toHaveLength(2);
+ expect(screen.getByTitle("/srv/other/config.json")).toBeVisible();
+ expect(screen.getByTitle(profile.config_path)).toBeVisible();
+ });
+
+ it("requires disconnecting before opening another authorization of an already-connected instance", async () => {
+ const second = { ...profile, id: "second-grant", connected: true, paired: true, instance_id: profile.id };
+ mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, paired: true, instance_id: profile.id }, second] });
+ view(); await openDirectory();
+ fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
+ fireEvent.click(screen.getByRole("menuitem", { name: "Connection details" }));
+ const details = await screen.findByRole("dialog", { name: "Connection details" });
+ expect(within(details).getByRole("button", { name: /^Connection 1 / })).toBeDisabled();
+ expect(within(details).getByRole("button", { name: /^Connection 2 / })).toBeEnabled();
+ expect(within(details).getByText(i18n.t("remote.sameInstance.switchHint"))).toBeVisible();
+ expect(within(details).getByRole("button", { name: "Manage connection 1" })).toBeEnabled();
+ expect(mocks.request).not.toHaveBeenCalled();
+ });
it("manages connections without changing the remote host, route, frame or authorization", async () => {
view();
await chooseHost("Team server ubuntu@example.test");
diff --git a/webui/src/tests/remote-profile-groups.test.ts b/webui/src/tests/remote-profile-groups.test.ts
new file mode 100644
index 000000000..f54ab82b7
--- /dev/null
+++ b/webui/src/tests/remote-profile-groups.test.ts
@@ -0,0 +1,27 @@
+import { describe, expect, it } from "vitest";
+import { groupRemoteProfiles, type RemoteProfile } from "@/lib/remote-instances";
+
+const profile: RemoteProfile = { id: "one", name: "Team", host: "ubuntu@server", port: 22,
+ ssh_config: "", identity_file: "", config_path: "/srv/bot/config.json", runtime_user: "", connected: false };
+
+describe("remote instance grouping", () => {
+ it("does not guess from names, addresses, or restart-scoped gateway IDs", () => {
+ expect(groupRemoteProfiles([profile, { ...profile, id: "two" }], null)).toHaveLength(2);
+ expect(groupRemoteProfiles([{ ...profile, gateway_id: "same" }, { ...profile, id: "two", gateway_id: "same" }], null)).toHaveLength(2);
+ });
+ it("keeps all grants but selects the current view before a connected or newer grant", () => {
+ const old = { ...profile, instance_id: "instance" };
+ const renewed = { ...old, id: "two", name: "auto-generated", connected: true };
+ const groups = groupRemoteProfiles([old, renewed], "one");
+ expect(groups).toHaveLength(1);
+ expect(groups[0].connections).toEqual([old, renewed]);
+ expect(groups[0].profile.id).toBe("one");
+ expect(groupRemoteProfiles([old, renewed], null)[0].profile).toMatchObject({ id: "two", name: "Team" });
+ });
+ it("prefers a usable grant when none is selected and does not mutate the directory", () => {
+ const items = [Object.freeze({ ...profile, instance_id: "same", authorized_until: 1 }),
+ Object.freeze({ ...profile, id: "two", instance_id: "same", authorized_until: Date.now() / 1000 + 1000 })];
+ expect(groupRemoteProfiles(items, null)[0].profile.id).toBe("two");
+ expect(items[0].id).toBe("one");
+ });
+});