Files
Netcatty/domain/terminalSidePanelAutoOpen.test.ts
T
陈大猫andCodex b6bff4df6b feat(browser): browse host services from terminal side panels (#3701)
* Codex worktree snapshot: startup-cleanup

Co-authored-by: Codex

* fix(browser): close malformed proxy connections without a reply

* feat(browser): embed host browsing in terminal side panels

* style(browser): blend compact browser chrome into terminal panels

* feat(browser): open terminal links internally with a system browser preference

* fix(browser): retain the first terminal link during panel mount replay

* fix(browser): release contexts when their split pane closes

* style(browser): remove the downloads panel shadow

* fix(browser): ignore late downloads after panel closure

* fix(browser): mount browser content on terminal auto-open

* fix(browser): preserve empty-vault recovery with bookmarks

* fix(browser): expose actions for supported terminal types

* fix(browser): retain open requests before the panel mounts

* fix(browser): align vault actions with supported hosts

* fix(browser): share download controls across host contexts

* fix(browser): keep vault browser requests on visible sessions

* fix(browser): release contexts after workspace detach

* fix(browser): enforce WebRTC routing on page contents

* fix(browser): skip unsupported sessions in open requests

* style(browser): encode glyphs in ASCII-safe source
2026-10-17 02:26:36 +08:00

105 lines
3.8 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
TERMINAL_SIDE_PANEL_AUTO_OPEN_TABS,
resolveTerminalSidePanelAutoOpen,
resolveSessionSidePanelAutoOpen,
type TerminalSidePanelAutoOpenTab,
} from "./terminalSidePanelAutoOpen.ts";
import { TERMINAL_SIDE_PANEL_TAB_DEFAULT_ORDER } from "../application/state/terminalSidePanelTabs.ts";
test("terminal side panel auto-open stays off by default", () => {
assert.equal(
resolveTerminalSidePanelAutoOpen({
enabled: false,
selectedTab: "scripts",
sftpAvailable: true,
}),
null,
);
});
test("terminal side panel auto-open returns the selected non-SFTP pane", () => {
assert.equal(
resolveTerminalSidePanelAutoOpen({
enabled: true,
selectedTab: "scripts",
sftpAvailable: false,
}),
"scripts",
);
});
test("terminal side panel auto-open skips SFTP when the session cannot use it", () => {
assert.equal(
resolveTerminalSidePanelAutoOpen({
enabled: true,
selectedTab: "sftp",
sftpAvailable: false,
}),
null,
);
});
test("terminal side panel auto-open accepts every selectable side pane", () => {
const tabs: TerminalSidePanelAutoOpenTab[] = [...TERMINAL_SIDE_PANEL_TAB_DEFAULT_ORDER];
assert.deepEqual(TERMINAL_SIDE_PANEL_AUTO_OPEN_TABS, TERMINAL_SIDE_PANEL_TAB_DEFAULT_ORDER);
assert.deepEqual(
tabs.map((selectedTab) =>
resolveTerminalSidePanelAutoOpen({
enabled: true,
selectedTab,
sftpAvailable: true,
}),
),
tabs,
);
});
const preferences = {
terminalEnabled: true,
terminalTab: "notes" as const,
localEnabled: true,
localTab: "sftp" as const,
legacySftpEnabled: false,
};
test("local sessions use their separate auto-open preference", () => {
assert.equal(resolveSessionSidePanelAutoOpen({ ...preferences, session: { protocol: "local" } }), "sftp");
assert.equal(resolveSessionSidePanelAutoOpen({ ...preferences, localEnabled: false, session: { protocol: "local" } }), null);
});
test("SSH, mosh and legacy sessions use remote preferences", () => {
for (const protocol of ["ssh", "mosh", undefined] as const) {
assert.equal(resolveSessionSidePanelAutoOpen({ ...preferences, session: { protocol } }), "notes");
assert.equal(resolveSessionSidePanelAutoOpen({ ...preferences, terminalTab: "sftp", localEnabled: false, session: { protocol } }), "sftp");
}
});
test("legacy SFTP auto-open preserves remote behavior without overriding local opt-out", () => {
const options = { ...preferences, terminalEnabled: false, localEnabled: false, legacySftpEnabled: true };
assert.equal(resolveSessionSidePanelAutoOpen({ ...options, session: { protocol: "local" } }), null);
assert.equal(resolveSessionSidePanelAutoOpen({ ...options, session: { protocol: "ssh" } }), "sftp");
});
test("explicit per-session SFTP requests take priority on supported transports", () => {
for (const protocol of ["ssh", "mosh", "local", undefined] as const) {
assert.equal(resolveSessionSidePanelAutoOpen({ ...preferences, localEnabled: false, session: { protocol, autoOpenSidePanel: "sftp" } }), "sftp");
}
for (const protocol of ["serial", "telnet", "plugin:example"] as const) {
assert.equal(resolveSessionSidePanelAutoOpen({ ...preferences, terminalTab: "sftp", legacySftpEnabled: true, session: { protocol, autoOpenSidePanel: "sftp" } }), null);
}
});
test("Browser auto-open skips unsupported terminal protocols", () => {
for (const protocol of ['ssh', 'mosh', 'local', undefined] as const) {
assert.equal(resolveSessionSidePanelAutoOpen({ ...preferences, terminalTab: 'browser', localTab: 'browser', session: { protocol } }), 'browser');
}
for (const protocol of ['telnet', 'serial', 'et', 'plugin:example'] as const) {
assert.equal(resolveSessionSidePanelAutoOpen({ ...preferences, terminalTab: 'browser', session: { protocol } }), null);
}
});