mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
* fix(terminal): honor Settings custom shell when Terminal button clicked (#4085) Vault/host-tree Terminal buttons wired onClick={handler}, so React passed the MouseEvent as the shell arg and skipped resolveShellSetting(terminalSettings.localShell). Only treat objects with a string command as explicit shells; wrap onClick sites. * ci: retrigger after lint-and-test runner cancel (#4085) * test(terminal): accept wrapped local-shell onClick in host-tree toolbar (#4085) Codex GH review: source assertion still expected onClick={onCreateLocalTerminal} after wrappers; update to () => onCreateLocalTerminal() so npm test passes.
85 lines
3.2 KiB
TypeScript
85 lines
3.2 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { handleCreateLocalTerminalImpl } from './AppHandlers';
|
|
|
|
type CreatedLocal = {
|
|
shell?: string;
|
|
shellArgs?: string[];
|
|
shellName?: string;
|
|
shellIcon?: string;
|
|
localStartDir?: string;
|
|
shellType?: string;
|
|
};
|
|
|
|
function createCtx(overrides?: {
|
|
localShell?: string;
|
|
localShellArgs?: string[];
|
|
discoveredShells?: Array<{ id: string; name: string; command: string; args?: string[]; icon?: string }>;
|
|
}) {
|
|
const created: CreatedLocal[] = [];
|
|
const logs: Array<{ hostLabel: string }> = [];
|
|
const localShell = overrides?.localShell ?? '';
|
|
const localShellArgs = overrides?.localShellArgs ?? [];
|
|
const discoveredShells = overrides?.discoveredShells ?? [];
|
|
const getCtx = () => ({
|
|
addConnectionLog: (entry: { hostLabel: string }) => {
|
|
logs.push(entry);
|
|
},
|
|
classifyLocalShellType: () => 'unknown',
|
|
createLocalTerminal: (options: CreatedLocal) => {
|
|
created.push(options);
|
|
return 'session-1';
|
|
},
|
|
discoveredShells,
|
|
resolveShellSetting: (
|
|
value: string,
|
|
shells: Array<{ id: string; command: string; args?: string[] }>,
|
|
customArgs?: string[],
|
|
) => {
|
|
if (!value) return null;
|
|
const match = shells.find((shell) => shell.id === value);
|
|
if (match) {
|
|
return { command: match.command, args: customArgs?.length ? customArgs : match.args };
|
|
}
|
|
return { command: value, args: customArgs?.length ? customArgs : undefined };
|
|
},
|
|
systemInfoRef: { current: { username: 'qi', hostname: 'box' } },
|
|
terminalSettings: { localShell, localShellArgs },
|
|
});
|
|
return { getCtx, created, logs };
|
|
}
|
|
|
|
test('create local terminal resolves Settings custom absolute path when no shell arg is passed', () => {
|
|
const custom = String.raw`C:\Users\lybing\AppData\Local\Programs\nu\bin\nu.exe`;
|
|
const { getCtx, created } = createCtx({ localShell: custom });
|
|
handleCreateLocalTerminalImpl(getCtx as never);
|
|
assert.equal(created.length, 1);
|
|
assert.equal(created[0].shell, custom);
|
|
});
|
|
|
|
test('create local terminal ignores MouseEvent-like first args and still uses Settings shell (#4085)', () => {
|
|
const custom = String.raw`C:\Users\lybing\AppData\Local\Programs\nu\bin\nu.exe`;
|
|
const { getCtx, created } = createCtx({ localShell: custom });
|
|
// Vault header historically used onClick={handleCreateLocalTerminal}, so React
|
|
// passes the click event as the first argument.
|
|
const fakeClickEvent = { type: 'click', target: {}, preventDefault() {} };
|
|
handleCreateLocalTerminalImpl(getCtx as never, fakeClickEvent as never);
|
|
assert.equal(created.length, 1);
|
|
assert.equal(created[0].shell, custom);
|
|
});
|
|
|
|
test('create local terminal still honors an explicit shell object', () => {
|
|
const { getCtx, created } = createCtx({ localShell: 'pwsh' });
|
|
handleCreateLocalTerminalImpl(getCtx as never, {
|
|
command: String.raw`D:\portable\zsh\zsh.exe`,
|
|
args: ['-l'],
|
|
name: 'Portable Zsh',
|
|
icon: 'zsh',
|
|
});
|
|
assert.equal(created.length, 1);
|
|
assert.equal(created[0].shell, String.raw`D:\portable\zsh\zsh.exe`);
|
|
assert.deepEqual(created[0].shellArgs, ['-l']);
|
|
assert.equal(created[0].shellName, 'Portable Zsh');
|
|
assert.equal(created[0].shellIcon, 'zsh');
|
|
});
|