feat: prompt users to run /terminal-setup with yes/no (#16235)

Co-authored-by: Vedant Mahajan <Vedant.04.mahajan@gmail.com>
This commit is contained in:
Ishaan Gupta
2026-02-25 03:18:28 +05:30
committed by GitHub
parent e13a3ada4a
commit b7d1cb2a58
4 changed files with 245 additions and 39 deletions
@@ -5,7 +5,12 @@
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { terminalSetup, VSCODE_SHIFT_ENTER_SEQUENCE } from './terminalSetup.js';
import {
terminalSetup,
VSCODE_SHIFT_ENTER_SEQUENCE,
shouldPromptForTerminalSetup,
} from './terminalSetup.js';
import { terminalCapabilityManager } from './terminalCapabilityManager.js';
// Mock dependencies
const mocks = vi.hoisted(() => ({
@@ -195,4 +200,51 @@ describe('terminalSetup', () => {
expect(mocks.writeFile).toHaveBeenCalled();
});
});
describe('shouldPromptForTerminalSetup', () => {
it('should return false when kitty protocol is already enabled', async () => {
vi.mocked(
terminalCapabilityManager.isKittyProtocolEnabled,
).mockReturnValue(true);
const result = await shouldPromptForTerminalSetup();
expect(result).toBe(false);
});
it('should return false when both Shift+Enter and Ctrl+Enter bindings already exist', async () => {
vi.mocked(
terminalCapabilityManager.isKittyProtocolEnabled,
).mockReturnValue(false);
process.env['TERM_PROGRAM'] = 'vscode';
const existingBindings = [
{
key: 'shift+enter',
command: 'workbench.action.terminal.sendSequence',
args: { text: VSCODE_SHIFT_ENTER_SEQUENCE },
},
{
key: 'ctrl+enter',
command: 'workbench.action.terminal.sendSequence',
args: { text: VSCODE_SHIFT_ENTER_SEQUENCE },
},
];
mocks.readFile.mockResolvedValue(JSON.stringify(existingBindings));
const result = await shouldPromptForTerminalSetup();
expect(result).toBe(false);
});
it('should return true when keybindings file does not exist', async () => {
vi.mocked(
terminalCapabilityManager.isKittyProtocolEnabled,
).mockReturnValue(false);
process.env['TERM_PROGRAM'] = 'vscode';
mocks.readFile.mockRejectedValue(new Error('ENOENT'));
const result = await shouldPromptForTerminalSetup();
expect(result).toBe(true);
});
});
});