mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-26 19:07:17 +00:00
* feat(local-terminal): support optional startup command on local terminal hosts * fix(local-terminal): validate saved local launch target before overlaying startup command
108 lines
3.9 KiB
TypeScript
108 lines
3.9 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import {
|
|
createLocalShellHost,
|
|
getLocalShellHostSubtitle,
|
|
getVaultHostRowSubtitle,
|
|
resolveHostDefaultLocalShell,
|
|
} from './localShellHost';
|
|
|
|
test('createLocalShellHost builds a grouped local-protocol host', () => {
|
|
const host = createLocalShellHost({
|
|
label: 'Project A CMD',
|
|
shell: 'powershell',
|
|
shellName: 'Windows PowerShell',
|
|
shellIcon: 'powershell',
|
|
group: 'Projects/A',
|
|
startDir: ' /home/user/work ',
|
|
startupCommand: 'npm run dev',
|
|
tags: ['local', 'build'],
|
|
});
|
|
|
|
assert.equal(host.protocol, 'local');
|
|
assert.equal(host.hostname, 'localhost');
|
|
assert.equal(host.username, '');
|
|
assert.equal(host.label, 'Project A CMD');
|
|
assert.equal(host.group, 'Projects/A');
|
|
assert.equal(host.localShell, 'powershell');
|
|
assert.equal(host.localShellName, 'Windows PowerShell');
|
|
assert.equal(host.localShellIcon, 'powershell');
|
|
assert.equal(host.localStartDir, '/home/user/work');
|
|
assert.equal(host.startupCommand, 'npm run dev');
|
|
assert.deepEqual(host.tags, ['local', 'build']);
|
|
assert.ok(host.id.startsWith('local-'));
|
|
});
|
|
|
|
test('createLocalShellHost preserves startupCommand verbatim when non-empty and clears blank input', () => {
|
|
const withLeadingSpace = createLocalShellHost({ startupCommand: ' echo secret' });
|
|
assert.equal(withLeadingSpace.startupCommand, ' echo secret');
|
|
|
|
const multiLine = createLocalShellHost({ startupCommand: 'source .venv/bin/activate\npytest' });
|
|
assert.equal(multiLine.startupCommand, 'source .venv/bin/activate\npytest');
|
|
|
|
assert.equal(createLocalShellHost({ startupCommand: '' }).startupCommand, undefined);
|
|
assert.equal(createLocalShellHost({ startupCommand: ' \n\t ' }).startupCommand, undefined);
|
|
});
|
|
|
|
test('createLocalShellHost falls back to defaults for empty input', () => {
|
|
const host = createLocalShellHost({});
|
|
assert.equal(host.label, 'Local Shell');
|
|
assert.equal(host.localShell, undefined);
|
|
assert.equal(host.localShellName, undefined);
|
|
assert.equal(host.localStartDir, undefined);
|
|
assert.deepEqual(host.tags, ['local']);
|
|
assert.equal(host.group, '');
|
|
assert.equal(host.os, 'linux');
|
|
});
|
|
|
|
test('createLocalShellHost preserves explicit id when editing', () => {
|
|
const host = createLocalShellHost({ id: 'local-existing', label: 'Renamed' });
|
|
assert.equal(host.id, 'local-existing');
|
|
});
|
|
|
|
test('getVaultHostRowSubtitle uses shell name for local hosts', () => {
|
|
assert.equal(
|
|
getVaultHostRowSubtitle({ protocol: 'local', localShellName: 'CMD', username: '', hostname: 'localhost' }),
|
|
'CMD',
|
|
);
|
|
assert.equal(
|
|
getVaultHostRowSubtitle({ protocol: 'local', username: '', hostname: 'localhost' }),
|
|
'Local Shell',
|
|
);
|
|
assert.equal(
|
|
getVaultHostRowSubtitle(
|
|
{ protocol: 'local', username: '', hostname: 'localhost' },
|
|
{ localFallback: '本地终端' },
|
|
),
|
|
'本地终端',
|
|
);
|
|
});
|
|
|
|
test('getVaultHostRowSubtitle keeps user@host for remote hosts', () => {
|
|
assert.equal(
|
|
getVaultHostRowSubtitle({ protocol: 'ssh', username: 'root', hostname: 'example.com' }),
|
|
'root@example.com',
|
|
);
|
|
assert.equal(
|
|
getVaultHostRowSubtitle({ protocol: 'telnet', username: '', hostname: '10.0.0.1' }),
|
|
'@10.0.0.1',
|
|
);
|
|
});
|
|
|
|
test('getLocalShellHostSubtitle ignores whitespace-only names and allows a fallback', () => {
|
|
assert.equal(getLocalShellHostSubtitle({ protocol: 'local', localShellName: ' ' }), 'Local Shell');
|
|
assert.equal(
|
|
getLocalShellHostSubtitle({ protocol: 'local', localShellName: '' }, '本地终端'),
|
|
'本地终端',
|
|
);
|
|
});
|
|
|
|
test('clearing the configured executable does not pass its old custom args to the backend default', () => {
|
|
const effective = resolveHostDefaultLocalShell(createLocalShellHost({}), {
|
|
terminalSettings: { localShell: '', localShellArgs: ['--norc'] },
|
|
resolveShellSetting: () => null,
|
|
});
|
|
assert.equal(effective.localShell, '');
|
|
assert.equal(effective.localShellArgs, undefined);
|
|
});
|