Files
Netcatty/domain/quickConnect.test.ts
T
57089a3abf feat: temporary network device mode and tab-bar quick connect (#3793)
* feat(ssh): opt temporary connections into network device mode

Saved hosts and group-backed clones keep their own device type. SSH
connections with no saved host, including external launches and quick
connect, can start in network device mode when the new Terminal setting
is on. The setting stays off unless the user turns it on.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* feat(terminal): quick connect typed addresses from the tab switcher

The tab-bar quick switcher now offers the typed address when it already
parses as a connection target. Choosing that row opens the existing
quick connect wizard, including from a terminal tab where the vault
surface is hidden.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(ssh): keep temporary Mosh and ET off network device mode

Those transports are stored as SSH plus a flag. Stamping network device
mode onto them made raw-host checks skip the copy-session working
directory probe. Plain temporary SSH still opts in.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(ssh): read temporary connection settings at connect time

VaultView keeps a stale onConnect callback because its memo ignores that
prop. Read both temporary-connection toggles from a ref when connecting
so turning them on or off applies in the same session.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(terminal): stop word queries from opening quick connect

Show the switcher quick-connect row only for address-like input, and
place it after matching hosts so Enter still connects to a saved host.
Translate the Hosts, Tabs, and New Workspace labels.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(terminal): keep matching tabs ahead of quick connect

An address that matches an open session or workspace was still the
default Enter target when no saved host matched. Put that row after
those tabs so Enter switches to the existing one.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
2026-10-20 18:29:41 +08:00

146 lines
4.4 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import {
isQuickConnectInput,
isSwitcherQuickConnectInput,
parseQuickConnectInput,
} from "./quickConnect";
test("quick connect keeps plain user@host targets unchanged", () => {
assert.deepEqual(parseQuickConnectInput("root@10.2.0.8"), {
hostname: "10.2.0.8",
username: "root",
port: undefined,
});
assert.deepEqual(parseQuickConnectInput("10.2.0.8:2200"), {
hostname: "10.2.0.8",
username: undefined,
port: 2200,
});
});
test("quick connect keeps the asset selector in the JumpServer username", () => {
assert.deepEqual(parseQuickConnectInput("root@10.2.0.8@jump.corp.example"), {
hostname: "jump.corp.example",
username: "root@10.2.0.8",
port: undefined,
isJumpServerLogin: true,
});
assert.equal(isQuickConnectInput("root@10.2.0.8@jump.corp.example"), true);
});
test("quick connect parses the four-part JumpServer login from issue 3523", () => {
assert.deepEqual(
parseQuickConnectInput("chenyi@root@10.2.0.8@devjumpserver.example.cn"),
{
hostname: "devjumpserver.example.cn",
username: "chenyi@root@10.2.0.8",
port: undefined,
isJumpServerLogin: true,
},
);
});
test("quick connect applies a suffix port to the JumpServer endpoint", () => {
assert.deepEqual(parseQuickConnectInput("chenyi@root@10.2.0.8@jump:2222"), {
hostname: "jump",
username: "chenyi@root@10.2.0.8",
port: 2222,
isJumpServerLogin: true,
});
});
test("ssh command ports apply to the JumpServer endpoint", () => {
assert.deepEqual(parseQuickConnectInput("ssh -p 2222 chenyi@root@10.2.0.8@jump.corp.example"), {
hostname: "jump.corp.example",
username: "chenyi@root@10.2.0.8",
port: 2222,
isJumpServerLogin: true,
});
assert.deepEqual(parseQuickConnectInput("ssh -o Port=2200 chenyi@root@10.2.0.8@jump"), {
hostname: "jump",
username: "chenyi@root@10.2.0.8",
port: 2200,
isJumpServerLogin: true,
});
});
test("ssh HostName override keeps the JumpServer login name", () => {
assert.deepEqual(
parseQuickConnectInput("ssh -o HostName=actual-jump.example -p 2222 chenyi@root@10.2.0.8@jump"),
{
hostname: "actual-jump.example",
username: "chenyi@root@10.2.0.8",
port: 2222,
isJumpServerLogin: true,
},
);
assert.deepEqual(
parseQuickConnectInput("ssh -o HostName=actual-jump.example chenyi@root@10.2.0.8@alias_name"),
{
hostname: "actual-jump.example",
username: "chenyi@root@10.2.0.8",
port: undefined,
isJumpServerLogin: true,
},
);
});
test("ordinary SSH options still resolve single-@ targets", () => {
assert.deepEqual(parseQuickConnectInput("ssh -p 2200 deploy@host.example"), {
hostname: "host.example",
username: "deploy",
port: 2200,
});
assert.deepEqual(parseQuickConnectInput("ssh -o HostName=actual.example -l deploy alias"), {
hostname: "actual.example",
username: "deploy",
port: undefined,
});
assert.deepEqual(parseQuickConnectInput("ssh -o HostName=actual.example deploy@alias_name"), {
hostname: "actual.example",
username: "deploy",
port: undefined,
});
assert.deepEqual(parseQuickConnectInput("ssh -l user@realm host.example"), {
hostname: "host.example",
username: "user@realm",
port: undefined,
});
assert.deepEqual(parseQuickConnectInput("ssh -o User=user@realm host.example"), {
hostname: "host.example",
username: "user@realm",
port: undefined,
});
});
test("quick connect rejects malformed multi-@ inputs", () => {
assert.equal(parseQuickConnectInput("a@b@c@d@e"), null);
assert.equal(parseQuickConnectInput("bad user@10.2.0.8@jump"), null);
assert.equal(parseQuickConnectInput("root@10.2.0.8@"), null);
assert.equal(parseQuickConnectInput("root@bad host@jump"), null);
});
test("switcher quick connect accepts only address-like input", () => {
for (const label of ["lab", "web01", "prod", "lab-switch", "localhost"]) {
assert.equal(isQuickConnectInput(label), true);
assert.equal(isSwitcherQuickConnectInput(label), false);
}
for (const address of [
"10.1.1.1",
"root@10.2.0.8:2222",
"example.com",
"host:2222",
"user@lab",
"[::1]",
"fe80::1",
"[2001:db8::1]:2222",
]) {
assert.equal(isSwitcherQuickConnectInput(address), true, address);
}
assert.equal(isSwitcherQuickConnectInput("core switch"), false);
assert.equal(isSwitcherQuickConnectInput("host:99999"), false);
});