ui(remote): illustrate access to a remote nanobot

This commit is contained in:
Xubin Ren committed 2026-10-02 11:36:34 +08:00
1 parent 83a131c207
commit e6d0303511
14 files changed
+122 -80

No files matched your search

+38 -25
View File
@@ -133,31 +133,26 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
const description = preview || reviewingReturn ? "remote.pair.confirmLinkDescription" : restartAvailable ? "remote.pair.introHint"
: manual ? "remote.pair.codeHint" : copied ? "remote.pair.afterCopyHint" : "remote.pair.introHint";
const showCopied = copied && !manual && !preview && !restartAvailable;
const showIllustration = !preview && !manual && !reviewingReturn && !restartAvailable;
const showBusy = pending && busyVisible;
const actionLabel = restartAvailable ? "remote.pair.restart" : reviewingReturn ? error ? "remote.retry" : "remote.pair.review" : preview ? saved ? "remote.retry" : "remote.connect"
: manual ? "remote.pair.review" : copied ? "remote.pair.copyAgain" : "remote.pair.copy";
const busyLabel = waitingForLocal ? "remote.pair.waitingForLocal" : preview ? "remote.connecting" : !restartAvailable && (manual || returned)
? "remote.pair.checkingLink" : "remote.pair.preparing";
return <>
<DialogHeader className="shrink-0 pr-5 text-left">
<div aria-live="polite" aria-atomic="true" className="space-y-1.5">
<DialogTitle className="flex min-h-5 items-center gap-2">
{showCopied && <Check aria-hidden="true" className="h-5 w-5 shrink-0 motion-safe:animate-in motion-safe:fade-in duration-150" />}
{t(title)}
</DialogTitle>
<div className="grid">
<DialogDescription className="col-start-1 row-start-1">{t(description)}</DialogDescription>
{/* Reserve the longer instruction in either state, including translated text.
It is only a layout spacer, never a second screen-reader announcement. */}
{!preview && !manual && !reviewingReturn && <p aria-hidden="true" className="invisible pointer-events-none col-start-1 row-start-1 select-none text-sm">
{t(showCopied ? "remote.pair.introHint" : "remote.pair.afterCopyHint")}
</p>}
return <div className="flex min-h-0 flex-col">
<div className="-mx-1 min-h-0 overflow-y-auto overscroll-contain px-1">
<DialogHeader className={showIllustration ? "space-y-0 text-center sm:text-center" : "pr-5 text-left"}>
{showIllustration && <RemoteConnectionIllustration />}
<div aria-live="polite" aria-atomic="true" className="space-y-1.5">
<DialogTitle className={showIllustration ? "flex min-h-5 items-center justify-center gap-2 text-xl leading-snug tracking-normal" : "flex min-h-5 items-center gap-2"}>
{showCopied && <Check aria-hidden="true" className="h-5 w-5 shrink-0 motion-safe:animate-in motion-safe:fade-in duration-150" />}
{t(title)}
</DialogTitle>
<DialogDescription>{t(description)}</DialogDescription>
</div>
</div>
</DialogHeader>
<div className="-mx-1 min-h-0 space-y-4 overflow-y-auto overscroll-contain px-1">
{preview ? <div className="space-y-4">
</DialogHeader>
{preview ? <div className="space-y-4 pt-4">
<div className="rounded-2xl bg-muted/50 p-4">
<p className="font-medium">{preview.hostname}</p>
<p className="mt-1 break-all text-xs text-muted-foreground">{preview.host}</p>
@@ -174,16 +169,16 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
summary={<><ChevronDown aria-hidden className="h-3.5 w-3.5 shrink-0 transition-transform group-data-[state=open]/disclosure:rotate-180 motion-reduce:transition-none" />{t("remote.pair.route")}</>}><PairRouteSettings id={saved} /></Disclosure>
</div>}
</div> : restartAvailable ? null : <>
{manual && <div className="space-y-2"><label htmlFor={codeId} className="sr-only">{t("remote.pair.code")}</label>
{manual && <div className="space-y-2 pt-4"><label htmlFor={codeId} className="sr-only">{t("remote.pair.code")}</label>
<Textarea ref={manualInput} id={codeId} value={code} onChange={(event) => { setCode(event.target.value); setError(""); }} placeholder="nbpc1.…" autoComplete="off" spellCheck={false} disabled={busy || expired} className="min-h-20 resize-none break-all font-mono text-xs" />
</div>}
<div>
<DisclosureContent id={panelId} open={panel === "command" && !!request?.command}>
<DisclosureContent id={panelId} open={panel === "command" && !!request?.command} className="pt-4">
<div className="rounded-2xl bg-muted/50 p-3">
<code className="block max-h-32 select-text overflow-y-auto break-all text-[11px] leading-5" aria-label={t("remote.pair.command")}>{request?.command}</code>
</div>
</DisclosureContent>
<DisclosureContent open={panel === "help"}>
<DisclosureContent open={panel === "help"} className="pt-4">
<div className="space-y-2 rounded-2xl bg-muted/50 p-3 text-xs leading-5 text-muted-foreground">
<p className="font-medium text-foreground">{t("remote.pair.helpTitle")}</p>
<p>{t("remote.pair.requirements")}</p>
@@ -193,10 +188,10 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
</DisclosureContent>
</div>
</>}
{expired && !saved && <p role="status" className="text-xs leading-5 text-muted-foreground">{t("remote.pair.expired")}</p>}
{error && <p role="alert" className="flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{t(error, { defaultValue: t("remote.errors.unknown") })}</p>}
{expired && !saved && <p role="status" className="mt-4 text-xs leading-5 text-muted-foreground">{t("remote.pair.expired")}</p>}
{error && <p role="alert" className="mt-4 flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{t(error, { defaultValue: t("remote.errors.unknown") })}</p>}
</div>
<div className={preview ? "flex shrink-0 flex-col-reverse gap-2 pt-1 sm:flex-row sm:items-center sm:justify-between" : "flex shrink-0 flex-col gap-2 pt-1"}>
<div className={preview ? "flex shrink-0 flex-col-reverse gap-2 pt-5 sm:flex-row sm:items-center sm:justify-between" : "flex shrink-0 flex-col gap-2 pt-5"}>
{preview && (!saved ? <Button variant="ghost" disabled={busy} onClick={() => { setPreview(null); setError(""); if (!request?.command) setManual(true); }}><ArrowLeft className="mr-1 h-4 w-4" />{t("remote.back")}</Button>
: <Button variant="ghost" onClick={() => { connections?.cancel(); onClose(); }}>{t("common.cancel")}</Button>
)}
@@ -220,5 +215,23 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
</DropdownMenu>
</div>}
</div>
</>;
</div>;
}
/** Decorative overview, not a live connection-status indicator. */
function RemoteConnectionIllustration() {
return <svg viewBox="0 0 208 88" width="184" height="78" aria-hidden="true" focusable="false" className="mx-auto mb-4 shrink-0 text-foreground/70" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
<path d="M78 51 C111 65 114 28 146 36" className="text-muted-foreground/50" strokeWidth="2.5" />
<rect x="10" y="25" width="68" height="43" rx="3" />
<path d="M4 68 H84 V70 A5 5 0 0 1 79 75 H9 A5 5 0 0 1 4 70 Z" />
<g className="text-muted-foreground">
<rect x="27" y="34" width="34" height="26" rx="2" />
<path d="M32 39 h.01 M36 39 h.01 M40 39 h.01" strokeWidth="2.5" />
</g>
<rect x="146" y="10" width="50" height="70" rx="3" />
<image href="/brand/nanobot_mark.svg" x="155" y="17" width="32" height="32" />
<path d="M146 53 H196 M146 66 H196 M152 60 H177 M152 73 H177 M152 80 V83 H158 V80 M184 80 V83 H190 V80" />
<circle cx="188" cy="60" r="1.8" />
<circle cx="188" cy="73" r="1.8" />
</svg>;
}
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "Connecting to local nanobot…",
"expiringDevice": "Authorization expires {{date}}.",
"expiredDevice": "Authorization expired. Pair this server again before reconnecting.",
"introHint": "Run one command in your server terminal to connect.",
"introHint": "Run one command on your server to access nanobot from this computer.",
"copiedTitle": "Command copied",
"afterCopyHint": "Paste it into your server terminal. After authorizing, open the returned link on this computer.",
"copyAgain": "Copy again",
@@ -123,7 +123,7 @@
"current": "Currently using",
"remote": "Remote",
"returnLocal": "Back to local nanobot",
"add": "Add server",
"add": "Connect to remote nanobot",
"addTitle": "Connect to a server",
"addDescription": "Connect to an existing nanobot. Chats and settings stay on the server.",
"host": "SSH address",
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "Conectando con nanobot en este equipo…",
"expiringDevice": "La autorización vence el {{date}}.",
"expiredDevice": "La autorización ha vencido. Vuelve a emparejar este servidor antes de reconectar.",
"introHint": "Ejecuta un comando en la terminal de tu servidor para conectarte.",
"introHint": "Ejecuta un comando en tu servidor para acceder a nanobot desde este ordenador.",
"copiedTitle": "Comando copiado",
"afterCopyHint": "Pégalo en la terminal de tu servidor. Tras autorizar, abre el enlace que aparece en este ordenador.",
"copyAgain": "Copiar de nuevo",
@@ -123,7 +123,7 @@
"current": "Currently using",
"remote": "Remote",
"returnLocal": "Back to local nanobot",
"add": "Add server",
"add": "Conectar con nanobot remoto",
"addTitle": "Connect to a server",
"addDescription": "Connect to an existing nanobot. Chats and settings stay on the server.",
"host": "SSH address",
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "Connexion à nanobot sur cet ordinateur…",
"expiringDevice": "L’autorisation expire le {{date}}.",
"expiredDevice": "L’autorisation a expiré. Associez à nouveau ce serveur avant de vous reconnecter.",
"introHint": "Exécutez une commande dans le terminal du serveur pour vous connecter.",
"introHint": "Exécutez une commande sur votre serveur pour accéder à nanobot depuis cet ordinateur.",
"copiedTitle": "Commande copiée",
"afterCopyHint": "Collez-la dans le terminal du serveur. Après autorisation, ouvrez le lien affiché sur cet ordinateur.",
"copyAgain": "Copier à nouveau",
@@ -123,7 +123,7 @@
"current": "Currently using",
"remote": "Remote",
"returnLocal": "Back to local nanobot",
"add": "Add server",
"add": "Se connecter à nanobot distant",
"addTitle": "Connect to a server",
"addDescription": "Connect to an existing nanobot. Chats and settings stay on the server.",
"host": "SSH address",
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "Menghubungkan ke nanobot di komputer ini…",
"expiringDevice": "Otorisasi berakhir pada {{date}}.",
"expiredDevice": "Otorisasi telah berakhir. Pasangkan ulang server ini sebelum menyambungkan kembali.",
"introHint": "Jalankan satu perintah di terminal server untuk terhubung.",
"introHint": "Jalankan satu perintah di server untuk mengakses nanobot dari komputer ini.",
"copiedTitle": "Perintah disalin",
"afterCopyHint": "Tempel dan jalankan di terminal server. Setelah memberi izin, buka tautan yang muncul di komputer ini.",
"copyAgain": "Salin lagi",
@@ -123,7 +123,7 @@
"current": "Currently using",
"remote": "Remote",
"returnLocal": "Back to local nanobot",
"add": "Add server",
"add": "Hubungkan ke nanobot jarak jauh",
"addTitle": "Connect to a server",
"addDescription": "Connect to an existing nanobot. Chats and settings stay on the server.",
"host": "SSH address",
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "このコンピューターの nanobot に接続しています…",
"expiringDevice": "認証は {{date}} に期限切れになります。",
"expiredDevice": "認証の期限が切れました。再接続する前にペアリングし直してください。",
"introHint": "サーバーのターミナルでコマンドを実行して接続します。",
"introHint": "サーバーでコマンドを実行すると、このパソコンから nanobot にアクセスできます。",
"copiedTitle": "コマンドをコピーしました",
"afterCopyHint": "サーバーのターミナルに貼り付けて実行します。承認後、表示されたリンクをこのパソコンで開いてください。",
"copyAgain": "もう一度コピー",
@@ -123,7 +123,7 @@
"current": "Currently using",
"remote": "Remote",
"returnLocal": "Back to local nanobot",
"add": "Add server",
"add": "リモートの nanobot に接続",
"addTitle": "Connect to a server",
"addDescription": "Connect to an existing nanobot. Chats and settings stay on the server.",
"host": "SSH address",
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "이 컴퓨터의 nanobot에 연결 중…",
"expiringDevice": "인증이 {{date}}에 만료됩니다.",
"expiredDevice": "인증이 만료되었습니다. 다시 연결하기 전에 서버를 다시 페어링하세요.",
"introHint": "서버 터미널에서 명령어를 실행해 연결하세요.",
"introHint": "서버에서 명령어 하나를 실행하면 이 컴퓨터에서 nanobot에 접속할 수 있습니다.",
"copiedTitle": "명령어 복사 완료",
"afterCopyHint": "서버 터미널에 붙여넣어 실행하세요. 승인 후 표시된 링크를 이 컴퓨터에서 여세요.",
"copyAgain": "다시 복사",
@@ -123,7 +123,7 @@
"current": "Currently using",
"remote": "Remote",
"returnLocal": "Back to local nanobot",
"add": "Add server",
"add": "원격 nanobot에 연결",
"addTitle": "Connect to a server",
"addDescription": "Connect to an existing nanobot. Chats and settings stay on the server.",
"host": "SSH address",
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "Conectando ao nanobot neste computador…",
"expiringDevice": "A autorização expira em {{date}}.",
"expiredDevice": "A autorização expirou. Pareie este servidor novamente antes de reconectar.",
"introHint": "Execute um comando no terminal do servidor para conectar.",
"introHint": "Execute um comando no servidor para acessar o nanobot neste computador.",
"copiedTitle": "Comando copiado",
"afterCopyHint": "Cole no terminal do servidor. Após autorizar, abra o link exibido neste computador.",
"copyAgain": "Copiar novamente",
@@ -123,7 +123,7 @@
"current": "Currently using",
"remote": "Remote",
"returnLocal": "Back to local nanobot",
"add": "Add server",
"add": "Conectar ao nanobot remoto",
"addTitle": "Connect to a server",
"addDescription": "Connect to an existing nanobot. Chats and settings stay on the server.",
"host": "SSH address",
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "Đang kết nối với nanobot trên máy tính này…",
"expiringDevice": "Quyền truy cập hết hạn vào {{date}}.",
"expiredDevice": "Quyền truy cập đã hết hạn. Hãy ghép nối lại máy chủ trước khi kết nối lại.",
"introHint": "Chạy một lệnh trong terminal máy chủ để kết nối.",
"introHint": "Chạy một lệnh trên máy chủ để truy cập nanobot từ máy tính này.",
"copiedTitle": "Đã sao chép lệnh",
"afterCopyHint": "Dán và chạy trong terminal máy chủ. Sau khi cấp quyền, mở liên kết được trả về trên máy tính này.",
"copyAgain": "Sao chép lại",
@@ -123,7 +123,7 @@
"current": "Currently using",
"remote": "Remote",
"returnLocal": "Back to local nanobot",
"add": "Add server",
"add": "Kết nối với nanobot từ xa",
"addTitle": "Connect to a server",
"addDescription": "Connect to an existing nanobot. Chats and settings stay on the server.",
"host": "SSH address",
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "正在连接本机 nanobot…",
"expiringDevice": "授权将于 {{date}} 到期。",
"expiredDevice": "授权已到期,重新连接前请再次配对。",
"introHint": "在服务器终端运行一条命令,即可开始连接。",
"introHint": "在服务器上运行一条命令,即可从这台电脑访问 nanobot。",
"copiedTitle": "命令已复制",
"afterCopyHint": "去服务器终端粘贴运行。确认授权后,点击返回链接回到这里。",
"copyAgain": "再次复制",
@@ -123,7 +123,7 @@
"current": "正在使用",
"remote": "远程",
"returnLocal": "切回本地 nanobot",
"add": "添加服务器",
"add": "连接远程 nanobot",
"addTitle": "连接服务器",
"addDescription": "连接已运行的 nanobot,聊天和设置留在服务器。",
"host": "SSH 地址",
+2 -2
View File
@@ -6,7 +6,7 @@
"waitingForLocal": "正在連線到本機 nanobot…",
"expiringDevice": "授權將於 {{date}} 到期。",
"expiredDevice": "授權已到期,重新連線前請再次配對。",
"introHint": "在伺服器終端執行一條指令,即可開始連線。",
"introHint": "在伺服器上執行一條指令,即可從這台電腦存取 nanobot。",
"copiedTitle": "指令已複製",
"afterCopyHint": "到伺服器終端貼上執行。確認授權後,點擊返回連結回到這裡。",
"copyAgain": "再次複製",
@@ -123,7 +123,7 @@
"current": "Currently using",
"remote": "Remote",
"returnLocal": "Back to local nanobot",
"add": "新增伺服器",
"add": "連線至遠端 nanobot",
"addTitle": "連線伺服器",
"addDescription": "連線至已執行的 nanobot,聊天和設定留在伺服器。",
"host": "SSH address",
+5 -5
View File
@@ -697,7 +697,7 @@ describe("App layout", () => {
fireEvent.click(await screen.findByRole("menuitem", { name: "Manage connections…" }));
expect(await screen.findByRole("heading", { name: "Remote connections" })).toBeVisible();
expect(sidebar).toBeVisible();
fireEvent.click(await screen.findByRole("button", { name: "Add server" }));
fireEvent.click(await screen.findByRole("button", { name: "Connect to remote nanobot" }));
fireEvent.pointerDown(screen.getByRole("button", { name: "Other ways" }), { button: 0, ctrlKey: false });
fireEvent.click(screen.getByRole("menuitem", { name: "Use existing SSH settings" }));
const host = await screen.findByRole("textbox", { name: "SSH address" });
@@ -712,7 +712,7 @@ describe("App layout", () => {
window.history.replaceState(null, "", "#/remote");
window.dispatchEvent(new PopStateEvent("popstate"));
});
expect(await screen.findByRole("button", { name: "Add server" })).toBeVisible();
expect(await screen.findByRole("button", { name: "Connect to remote nanobot" })).toBeVisible();
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
expect(within(sidebar).queryByRole("button", { name: "Remote connections" })).not.toBeInTheDocument();
});
@@ -740,8 +740,8 @@ describe("App layout", () => {
expect(window.location.hash).toBe("#/remote");
expect(screen.queryByRole("button", { name: "Remote connections" })).not.toBeInTheDocument();
await waitFor(() => expect(document.body.style.pointerEvents).not.toBe("none"));
await user.click(screen.getByRole("button", { name: "Add server" }));
expect(await screen.findByRole("dialog", { name: "Add server" })).toBeVisible();
await user.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
expect(await screen.findByRole("dialog", { name: "Connect to remote nanobot" })).toBeVisible();
});
it("releases the mobile sidebar modal when switching to a server", async () => {
@@ -780,7 +780,7 @@ describe("App layout", () => {
"/api/remote-instances": { available: true, profiles: [] },
});
render(<App />);
expect(await screen.findByRole("button", { name: "Add server" })).toBeVisible();
expect(await screen.findByRole("button", { name: "Connect to remote nanobot" })).toBeVisible();
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
expect(screen.getByRole("navigation", { name: "Sidebar navigation" })).toBeVisible();
expect(screen.queryByRole("navigation", { name: "Settings sections" })).not.toBeInTheDocument();
+33 -4
View File
@@ -65,6 +65,35 @@ async function reviewed() {
}
describe("quick pairing", () => {
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());
const dialog = screen.getByRole("dialog");
expect(dialog).toHaveAccessibleName("Connect to remote nanobot");
expect(dialog).toHaveAccessibleDescription(i18n.t("remote.pair.introHint"));
const illustration = dialog.querySelector('image[href="/brand/nanobot_mark.svg"]')?.closest("svg");
expect(illustration).toHaveAttribute("aria-hidden", "true");
expect(illustration).toHaveAttribute("focusable", "false");
expect(dialog.querySelector(".invisible")).toBeNull();
expect(screen.queryByText(i18n.t("remote.pair.afterCopyHint"))).toBeNull();
fireEvent.click(screen.getByRole("button", { name: "Copy command" }));
await screen.findByRole("heading", { name: "Command copied" });
expect(dialog.querySelector('image[href="/brand/nanobot_mark.svg"]')?.closest("svg")).toBe(illustration);
expect(screen.queryByText(i18n.t("remote.pair.introHint"))).toBeNull();
});
it("keeps the illustration out of code entry and authorization review", async () => {
view();
await waitFor(() => expect(screen.getByRole("button", { name: "Copy command" })).toBeEnabled());
chooseOtherWay("Use a connection code instead");
const dialog = screen.getByRole("dialog");
expect(dialog.querySelector('image[href="/brand/nanobot_mark.svg"]')).toBeNull();
fireEvent.change(screen.getByRole("textbox", { name: "Connection code" }), { target: { value: "nbpc1.encrypted" } });
fireEvent.click(screen.getByRole("button", { name: "Review connection" }));
await screen.findByRole("heading", { name: "Open this nanobot?" });
expect(dialog.querySelector('image[href="/brand/nanobot_mark.svg"]')).toBeNull();
expect(screen.getByText(i18n.t("remote.pair.access"))).toBeVisible();
expect(mocks.connect).not.toHaveBeenCalled();
});
it("reviews through the real NanobotClient after its socket opens", async () => {
const socket = {
readyState: 0,
@@ -143,7 +172,7 @@ describe("quick pairing", () => {
render(<Dialog open><DialogContent><QuickPairSetup returned={{ id: "request-1", code: "nbpc1.encrypted" }} onSSH={vi.fn()} onClose={vi.fn()} /></DialogContent></Dialog>);
expect(screen.getByRole("heading", { name: "Review connection" })).toBeVisible();
expect(screen.queryByRole("button", { name: "Copy command" })).toBeNull();
expect(screen.queryByText("Run one command in your server terminal to connect.")).toBeNull();
expect(screen.queryByText(i18n.t("remote.pair.introHint"))).toBeNull();
expect(screen.getByRole("button", { name: "Review connection" })).toBeDisabled();
expect(mocks.connect).not.toHaveBeenCalled();
});
@@ -152,7 +181,7 @@ describe("quick pairing", () => {
await waitFor(() => expect(screen.getByRole("button", { name: "Copy command" })).toBeEnabled());
expect(screen.getByText(/For Linux servers/).closest(".inline-disclosure")).toHaveAttribute("aria-hidden", "true");
expect(screen.queryByRole("menuitem")).toBeNull();
expect(screen.getByText(/After authorizing/)).toHaveAttribute("aria-hidden", "true");
expect(screen.queryByText(i18n.t("remote.pair.afterCopyHint"))).toBeNull();
chooseOtherWay("Requirements & help");
expect(screen.getByText(/For Linux servers/)).toBeVisible();
expect(screen.getByText(/Commands expire after 10 minutes/)).toBeVisible();
@@ -223,7 +252,7 @@ describe("quick pairing", () => {
view();
await waitFor(() => expect(screen.getByRole("button", { name: "Copy command" })).toBeEnabled());
fireEvent.click(screen.getByRole("button", { name: "Copy command" }));
expect(screen.getByRole("heading", { name: "Add server" })).toBeVisible();
expect(screen.getByRole("heading", { name: "Connect to remote nanobot" })).toBeVisible();
await act(async () => finish(true));
expect(screen.getByRole("heading", { name: "Command copied" })).toBeVisible();
expect(screen.getByText(/Paste it into your server terminal/)).toBeVisible();
@@ -240,7 +269,7 @@ describe("quick pairing", () => {
fireEvent.click(screen.getByRole("button", { name: "Copy command" }));
await screen.findByRole("alert");
expect(screen.getByText(request().command)).toBeVisible();
expect(screen.getByRole("heading", { name: "Add server" })).toBeVisible();
expect(screen.getByRole("heading", { name: "Connect to remote nanobot" })).toBeVisible();
expect(screen.queryByRole("button", { name: "Copy again" })).toBeNull();
});
it("keeps a manual code when returning to the simpler command screen", async () => {
+26 -26
View File
@@ -95,7 +95,7 @@ describe("remote instance UX", () => {
fireEvent.click(await screen.findByRole("button", { name: "Team server ubuntu@example.test" }));
expect(await screen.findByText("Connecting to Team server…")).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "Cancel switch" }));
expect(screen.getByRole("button", { name: "Add server" })).toBeEnabled();
expect(screen.getByRole("button", { name: "Connect to remote nanobot" })).toBeEnabled();
await act(async () => finish(connection));
expect(readSelectedRemote()).toBeNull();
expect(screen.queryByTitle("nanobot on Team server")).toBeNull();
@@ -168,7 +168,7 @@ describe("remote instance UX", () => {
hosts: ssh_config ? [{ host: "cloud-team", source: ssh_config, ssh_config }] : [],
}));
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: "ubuntu@203.0.113.1" } });
fireEvent.click(screen.getByRole("button", { name: "Connection options" }));
@@ -184,7 +184,7 @@ describe("remote instance UX", () => {
it("keeps an existing private key path when file selection is cancelled", async () => {
mocks.request.mockResolvedValue({ path: null });
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.click(screen.getByRole("button", { name: "Connection options" }));
fireEvent.change(screen.getByRole("textbox", { name: "Private key path (optional)" }), { target: { value: "/local/ssh-key" } });
@@ -197,14 +197,14 @@ describe("remote instance UX", () => {
let finish!: (value: unknown) => void;
mocks.request.mockImplementation(() => new Promise((resolve) => { finish = resolve; }));
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.click(screen.getByRole("button", { name: "Connection options" }));
fireEvent.click(screen.getByRole("button", { name: "Choose file: Private key path (optional)" }));
expect(screen.getByRole("button", { name: "Connect" })).toBeDisabled();
expect(screen.getByText("Choose a file in the system dialog…")).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.click(screen.getByRole("button", { name: "Connection options" }));
await act(async () => finish({ path: "/old/choice" }));
@@ -213,7 +213,7 @@ describe("remote instance UX", () => {
async function addAndInspect() {
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: profile.host } });
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
@@ -357,7 +357,7 @@ describe("remote instance UX", () => {
expect(screen.getByRole("navigation", { name: "Sidebar navigation" })).toBeVisible();
expect(screen.getByText("Local nanobot")).toBeInTheDocument();
expect(screen.getByText("Currently using")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Add server" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Connect to remote nanobot" })).toBeInTheDocument();
});
it("keeps the connection action accessible when the sidebar is collapsed", async () => {
@@ -399,7 +399,7 @@ describe("remote instance UX", () => {
view();
await openDirectory();
expect(screen.getByText("本地 nanobot")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "添加服务器" }));
fireEvent.click(screen.getByRole("button", { name: "连接远程 nanobot" }));
chooseExistingSSH();
expect(screen.getByRole("heading", { name: "连接服务器" })).toBeInTheDocument();
expect(screen.getByRole("dialog", { name: "连接服务器" })).toBeVisible();
@@ -530,7 +530,7 @@ describe("remote instance UX", () => {
if (action === "remote.save") return { id: profile.id };
throw new Error("ssh_auth_failed");
});
view(); await openDirectory(); fireEvent.click(screen.getByRole("button", { name: "Add server" }));
view(); await openDirectory(); fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: "ubuntu@example.test" } });
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
@@ -579,7 +579,7 @@ describe("remote instance UX", () => {
it("imports a pasted SSH command into the existing connection options", async () => {
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
const address = screen.getByRole("textbox", { name: "SSH address" });
fireEvent.change(address, { target: { value: 'ssh -p2222 -i "~/.ssh/team key" -l ubuntu example.test' } });
@@ -602,7 +602,7 @@ describe("remote instance UX", () => {
if (action === "remote.save") return { id: profile.id };
throw new Error("ssh_agent_refused");
});
view(); await openDirectory(); fireEvent.click(screen.getByRole("button", { name: "Add server" }));
view(); await openDirectory(); fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
const address = screen.getByRole("textbox", { name: "SSH address" });
fireEvent.change(address, { target: { value: "ssh -p 2222 ubuntu@example.test" } });
@@ -617,7 +617,7 @@ describe("remote instance UX", () => {
});
it("doesn't save or execute a command with unsupported flags", async () => {
view(); await openDirectory(); fireEvent.click(screen.getByRole("button", { name: "Add server" }));
view(); await openDirectory(); fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
const address = screen.getByRole("textbox", { name: "SSH address" });
fireEvent.change(address, { target: { value: "ssh -o ProxyCommand=unsafe team" } });
@@ -629,7 +629,7 @@ describe("remote instance UX", () => {
it("closes a successful add dialog so returning local shows the directory", async () => {
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: profile.host } });
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
@@ -644,7 +644,7 @@ describe("remote instance UX", () => {
mocks.request.mockImplementation(async (action: string) => action === "remote.save" ? { id: profile.id }
: new Promise<RemoteConnection>((resolve) => { finish = resolve; }));
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: profile.host } });
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
@@ -665,7 +665,7 @@ describe("remote instance UX", () => {
return {};
});
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: profile.host } });
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
@@ -686,7 +686,7 @@ describe("remote instance UX", () => {
return new Promise<{ fingerprint: string; challenge: string }>((resolve) => { finish = resolve; });
});
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: profile.host } });
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
@@ -710,25 +710,25 @@ describe("remote instance UX", () => {
expect(mocks.read).not.toHaveBeenCalled();
expect(mocks.discover).not.toHaveBeenCalled();
expect(screen.queryByRole("button", { name: "Remote connections" })).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Add server" })).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Connect to remote nanobot" })).not.toBeInTheDocument();
});
it("keeps the directory quiet and offers one focused add-server dialog", async () => {
mocks.read.mockResolvedValue({ available: true, profiles: [] });
view(); await openDirectory();
expect(mocks.discover).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
const host = screen.getByRole("textbox", { name: "SSH address" });
const dialog = screen.getByRole("dialog", { name: "Connect to a server" });
expect(dialog).toContainElement(host);
expect(host).toHaveFocus();
expect(within(dialog).getAllByRole("textbox")).toHaveLength(1);
expect(screen.getByRole("button", { name: "Add server", hidden: true })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Connect to remote nanobot", hidden: true })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Connect" })).toBeDisabled();
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
expect(screen.getByRole("button", { name: "Add server" })).toHaveFocus();
expect(screen.getByRole("button", { name: "Connect to remote nanobot" })).toHaveFocus();
expect(screen.getByRole("heading", { name: "Remote connections" })).toBeVisible();
});
@@ -749,7 +749,7 @@ describe("remote instance UX", () => {
mocks.read.mockResolvedValue({ available: true, profiles: [] });
mocks.request.mockImplementation(() => new Promise<{ id: string }>((resolve) => { finish = resolve; }));
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: "ubuntu@example.test" } });
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
@@ -799,7 +799,7 @@ describe("remote instance UX", () => {
{ host: "staging", source: "/home/test/.ssh/hosts", ssh_config: "" },
], files: ["/home/test/.ssh/config"], incomplete: false });
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
await screen.findByRole("button", { name: "Use team-sg" });
expect(mocks.request).not.toHaveBeenCalled();
@@ -822,7 +822,7 @@ describe("remote instance UX", () => {
it("reads a custom SSH config and carries that path to the selected profile", async () => {
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
fireEvent.click(screen.getByRole("button", { name: "Connection options" }));
mocks.discover.mockResolvedValue({ hosts: [{ host: "team", source: "/team/ssh_config", ssh_config: "/team/ssh_config" }], files: ["/team/ssh_config"], incomplete: false });
@@ -840,7 +840,7 @@ describe("remote instance UX", () => {
it("keeps manual entry available for an invalid discovery response", async () => {
mocks.discover.mockResolvedValue({ hosts: [{}], files: [], incomplete: false });
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
await screen.findByRole("alert");
expect(screen.getByRole("textbox", { name: "SSH address" })).toBeVisible();
@@ -853,7 +853,7 @@ describe("remote instance UX", () => {
? Promise.resolve({ hosts: [{ host: "custom-team", source: ssh_config, ssh_config }], files: [ssh_config], incomplete: false })
: new Promise((resolve) => { finishOld = resolve; }));
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
await waitFor(() => expect(finishOld).toBeDefined());
fireEvent.click(screen.getByRole("button", { name: "Connection options" }));
@@ -868,7 +868,7 @@ describe("remote instance UX", () => {
it("keeps manual setup available when discovery fails and does not clear cached hosts", async () => {
mocks.discover.mockResolvedValue({ hosts: [{ host: "team", source: "/config", ssh_config: "/config" }], files: ["/config"], incomplete: false });
view(); await openDirectory();
fireEvent.click(screen.getByRole("button", { name: "Add server" }));
fireEvent.click(screen.getByRole("button", { name: "Connect to remote nanobot" }));
chooseExistingSSH();
await screen.findByRole("button", { name: "Use team" });
mocks.discover.mockRejectedValue(new Error("ssh_config_unreadable"));