mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 04:50:52 +00:00
* perf(terminal): stop per-second churn while connecting and while idle - Connecting sessions: the 200 ms progress animation and 1 s countdown were Terminal state threaded into the TerminalView ctx, so every connecting session (hidden tabs and startup restores included) re-rendered Terminal + TerminalView up to six times a second. Terminal now only publishes the timeout deadline and real progress events; the connection dialog animates and counts down locally (connectionTicker.ts). HostConnectionTestDialog keeps passing progress/timeLeft as before. - Monitor runtime: polled every second unconditionally and woke every subscriber each time because takenAt always changes. It now polls at 1 s only while something is monitored (here or in another window), 10 s otherwise, and skips notifying for unchanged idle replies. - Auto-reconnect progress log: capped at the newest 300 lines (it grew by a few lines every 5 s retry for as long as an outage lasted). - App Lock: report activity at most once a second instead of an IPC per keystroke / wheel tick / pointer event. - Tray/Dock: the renderer resends hosts only when the host list changed, and the main process rebuilds the macOS Dock menu (sort + one native item per host) only then, not on every session status change. Real app, profiling build, main -> this change: 3 SSH sessions connecting (3 s) 14 commits / 35.3 ms -> 8 / 1.7 ms idle (10 s) 13 commits / 3.1 ms -> 2 / 0.1 ms Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(terminal): update observe-popup reconnect deps assertion for capped progress logs CI failed because #4118 wrapped setProgressLogs in useCallback to apply capConnectionProgressLogs and added it to scheduleAutoReconnect deps. The observe-popup source assertion still expected the old deps list. The attachExistingSession early-return behavior is unchanged; only the stale dependency regex needed updating. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
228 lines
8.6 KiB
TypeScript
228 lines
8.6 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
|
|
import type { Host, TerminalSession } from '../types';
|
|
import type { TerminalPopupPayload } from '../domain/systemManager/types';
|
|
import { resolveTerminalPopupHost, resolveTerminalPopupReuseId } from './TerminalPopupPage';
|
|
import { resolveShellSetting } from '../lib/useDiscoveredShells';
|
|
|
|
const source = readFileSync(new URL('./TerminalPopupPage.tsx', import.meta.url), 'utf8');
|
|
const terminalSource = readFileSync(new URL('./Terminal.tsx', import.meta.url), 'utf8');
|
|
const terminalLayerSource = readFileSync(new URL('./TerminalLayer.tsx', import.meta.url), 'utf8');
|
|
|
|
const vaultHost = (overrides: Partial<Host> = {}): Host => ({
|
|
id: 'host-1',
|
|
label: 'Prod',
|
|
hostname: 'prod.example.com',
|
|
username: 'deploy',
|
|
port: 22,
|
|
protocol: 'ssh',
|
|
tags: [],
|
|
os: 'linux',
|
|
moshEnabled: true,
|
|
...overrides,
|
|
});
|
|
|
|
const sourceSession = (overrides: Partial<TerminalSession> = {}): TerminalSession => ({
|
|
id: 'session-1',
|
|
hostId: 'host-1',
|
|
hostLabel: 'Prod',
|
|
hostname: 'prod.example.com',
|
|
username: 'deploy',
|
|
status: 'connected',
|
|
protocol: 'ssh',
|
|
port: 22,
|
|
moshEnabled: false,
|
|
...overrides,
|
|
});
|
|
|
|
const popupPayload = (sourceSessionValue: TerminalSession): TerminalPopupPayload => ({
|
|
title: 'Prod · docker: api',
|
|
parentSessionId: sourceSessionValue.id,
|
|
sourceSession: sourceSessionValue,
|
|
startupCommand: 'docker exec -it abc123 sh',
|
|
});
|
|
|
|
test('resolveTerminalPopupHost honors source session transport over saved Mosh host settings', () => {
|
|
const host = resolveTerminalPopupHost(popupPayload(sourceSession()), [vaultHost()]);
|
|
|
|
assert.equal(host.id, 'host-1');
|
|
assert.equal(host.hostname, 'prod.example.com');
|
|
assert.equal(host.protocol, 'ssh');
|
|
assert.equal(host.moshEnabled, false);
|
|
assert.equal(host.etEnabled, false);
|
|
});
|
|
|
|
test('resolveTerminalPopupHost resolves the settings shell for saved local hosts with a system default shell', () => {
|
|
const localHost = vaultHost({
|
|
protocol: 'local',
|
|
hostname: 'localhost',
|
|
username: '',
|
|
port: undefined,
|
|
localShell: undefined,
|
|
});
|
|
const defaultLocalShell = {
|
|
discoveredShells: [],
|
|
resolveShellSetting,
|
|
terminalSettings: { localShell: 'fish', localShellArgs: [] },
|
|
};
|
|
|
|
const withContext = resolveTerminalPopupHost(
|
|
popupPayload(sourceSession({ protocol: 'local', port: undefined })),
|
|
[localHost],
|
|
{ defaultLocalShell },
|
|
);
|
|
assert.equal(withContext.localShell, 'fish');
|
|
|
|
// Without the context (e.g. callers that cannot resolve it) the vault host
|
|
// keeps its saved (empty) shell — the caller decides how to handle it.
|
|
const withoutContext = resolveTerminalPopupHost(
|
|
popupPayload(sourceSession({ protocol: 'local', port: undefined })),
|
|
[localHost],
|
|
);
|
|
assert.equal(withoutContext.localShell, undefined);
|
|
});
|
|
|
|
test('resolveTerminalPopupHost still falls back to source session details when the host is missing', () => {
|
|
const host = resolveTerminalPopupHost(popupPayload(sourceSession({ hostId: 'missing' })), []);
|
|
|
|
assert.equal(host.id, 'missing');
|
|
assert.equal(host.label, 'Prod');
|
|
assert.equal(host.protocol, 'ssh');
|
|
assert.equal(host.moshEnabled, false);
|
|
});
|
|
|
|
test('resolveTerminalPopupHost preserves plugin transport and configuration for copied windows', () => {
|
|
const providerId = 'com.example.transport.connection';
|
|
const protocol = `plugin:${providerId}` as const;
|
|
const pluginConnection = {
|
|
providerId,
|
|
authenticationProviderId: 'com.example.transport.auth',
|
|
configuration: { endpoint: 'gateway.example', features: ['importers'] },
|
|
credentialId: 'credential-reference-1234',
|
|
};
|
|
|
|
const host = resolveTerminalPopupHost(
|
|
popupPayload(sourceSession({
|
|
protocol,
|
|
pluginConnection,
|
|
hostId: 'missing-plugin-host',
|
|
hostname: 'provider-placeholder.example',
|
|
})),
|
|
[],
|
|
);
|
|
|
|
assert.equal(host.protocol, protocol);
|
|
assert.deepEqual(host.pluginConnection, pluginConnection);
|
|
assert.notEqual(host.pluginConnection, pluginConnection);
|
|
});
|
|
|
|
test('resolveTerminalPopupHost does not turn command popups into serial sessions without serial config', () => {
|
|
const host = resolveTerminalPopupHost(
|
|
popupPayload(sourceSession({ protocol: 'serial' })),
|
|
[vaultHost({ protocol: 'serial' })],
|
|
);
|
|
|
|
assert.equal(host.protocol, 'ssh');
|
|
assert.equal(host.moshEnabled, false);
|
|
});
|
|
|
|
test('resolveTerminalPopupHost preserves serial settings when attaching a live session', () => {
|
|
const serialConfig = {
|
|
path: '/dev/ttyUSB0',
|
|
baudRate: 115200,
|
|
lineMode: true,
|
|
localEcho: true,
|
|
} as const;
|
|
const payload = popupPayload(sourceSession({
|
|
protocol: 'serial',
|
|
hostname: serialConfig.path,
|
|
port: serialConfig.baudRate,
|
|
serialConfig,
|
|
}));
|
|
payload.attachSessionId = payload.sourceSession.id;
|
|
|
|
const host = resolveTerminalPopupHost(payload, [vaultHost({ protocol: 'serial', serialConfig })]);
|
|
|
|
assert.equal(host.protocol, 'serial');
|
|
assert.deepEqual(host.serialConfig, serialConfig);
|
|
assert.match(source, /serialConfig=\{isAttachMode \? config\.sourceSession\.serialConfig : undefined\}/);
|
|
});
|
|
|
|
test('resolveTerminalPopupReuseId uses the explicit reuse id from the prepared source session', () => {
|
|
assert.equal(
|
|
resolveTerminalPopupReuseId(popupPayload(sourceSession({ reuseConnectionFromSessionId: 'session-1' }))),
|
|
'session-1',
|
|
);
|
|
|
|
assert.equal(
|
|
resolveTerminalPopupReuseId(popupPayload(sourceSession({ reuseConnectionFromSessionId: undefined }))),
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
test('popup terminals resolve complete host config and pass jump hosts into Terminal', () => {
|
|
assert.match(source, /proxyProfiles,\s+knownHosts,\s+snippets,\s+snippetPackages,\s+groupConfigs,/);
|
|
assert.match(source, /deleteSelectedSnippets,/);
|
|
assert.match(source, /resolveTerminalPopupHost\(config,\s*hosts,\s*\{\s+groupConfigs,\s+proxyProfiles,/);
|
|
assert.match(source, /resolveTerminalChainHosts\(\{\s+host,\s+hosts,\s+groupConfigs,\s+proxyProfiles,/);
|
|
assert.match(source, /chainHosts=\{chainHosts\}/);
|
|
// Popup has no AppSideEffects listener; bulk delete must hit this vault instance.
|
|
assert.match(source, /onDeleteSnippets=\{deleteSelectedSnippets\}/);
|
|
});
|
|
|
|
test('popup terminals use their window-local vault readiness', () => {
|
|
assert.match(source, /vaultInitializedOverride=\{vaultInitialized\}/);
|
|
});
|
|
|
|
test('popup provider tree mounts authentication and paste confirmation hosts', () => {
|
|
assert.match(source, /import \{ PluginAuthenticationHost \} from '\.\/plugins\/PluginAuthenticationHost';/);
|
|
assert.match(
|
|
source,
|
|
/<I18nProvider locale=\{settings\.uiLanguage\}>\s+<TerminalPopupPageInner\s+settings=\{settings\}\s+allowTerminalStart=\{allowTerminalStart\}\s+\/>\s+<PluginAuthenticationHost \/>\s+<MultilinePasteConfirmHost \/>\s+<\/I18nProvider>/,
|
|
);
|
|
});
|
|
|
|
test('attach popup close preparation has a bounded timeout', () => {
|
|
assert.match(source, /Promise\.race\(\[/);
|
|
assert.match(source, /Attach close preparation timed out/);
|
|
assert.match(source, /1500/);
|
|
});
|
|
|
|
test('terminal exit auto-close setting reaches tabs, workspaces, and popups', () => {
|
|
assert.match(
|
|
terminalLayerSource,
|
|
/resolveTerminalSessionExitIntent\(\s+evt,[\s\S]*?terminalSettings\?\.autoCloseOnExit \?\? false,\s+\)/,
|
|
);
|
|
assert.match(
|
|
terminalSource,
|
|
/const onSessionExitRef = useRef\(onSessionExit\);[\s\S]*?useLayoutEffect\(\(\) => \{\s+onSessionExitRef\.current = onSessionExit;\s+\}, \[onSessionExit\]\);/,
|
|
);
|
|
assert.match(
|
|
terminalSource,
|
|
/onSessionExitRef\.current\?\.\(closedSessionId, evt\)/,
|
|
);
|
|
assert.match(
|
|
source,
|
|
/shouldCloseTerminalPopupOnExit\(evt, \{\s+autoCloseOnExit: settings\.terminalSettings\.autoCloseOnExit,\s+isAttachMode,\s+\}\)/,
|
|
);
|
|
assert.match(
|
|
source,
|
|
/shouldRevealTerminalPopupOnExit\(evt, \{\s+autoCloseOnExit: settings\.terminalSettings\.autoCloseOnExit,\s+isAttachMode,\s+\}\)[\s\S]*?revealTerminal\(\);\s+return;[\s\S]*?setStartupError/,
|
|
);
|
|
});
|
|
|
|
test('an attached observe popup never owns automatic reconnect', () => {
|
|
const reconnectStart = terminalSource.indexOf('const scheduleAutoReconnect = useCallback');
|
|
const reconnectEnd = terminalSource.indexOf('const prepareRestoredReconnect', reconnectStart);
|
|
const reconnectSource = terminalSource.slice(reconnectStart, reconnectEnd);
|
|
assert.match(reconnectSource, /if \(attachExistingSession\) return false;/);
|
|
assert.match(reconnectSource, /\[attachExistingSession, host, setProgressLogs, t, terminalSettings, updateStatus\]/);
|
|
assert.match(terminalSource, /const startReconnect = async[\s\S]*?if \(attachExistingSession\) return;/);
|
|
assert.match(
|
|
terminalSource,
|
|
/useEffect\(\(\) => \{\s+if \(attachExistingSession\) return undefined;\s+return terminalReconnectRegistry\.register/,
|
|
);
|
|
});
|