Revert "Shell approval rework" (#11143)

This commit is contained in:
cornmander
2025-10-14 18:55:28 -04:00
committed by GitHub
parent 6f0107e7b7
commit bd5c158a62
12 changed files with 279 additions and 661 deletions
@@ -24,14 +24,9 @@ const mockSerializeTerminalToObject = vi.hoisted(() => vi.fn());
vi.mock('@lydell/node-pty', () => ({
spawn: mockPtySpawn,
}));
vi.mock('node:child_process', async (importOriginal) => {
const actual =
(await importOriginal()) as typeof import('node:child_process');
return {
...actual,
spawn: mockCpSpawn,
};
});
vi.mock('child_process', () => ({
spawn: mockCpSpawn,
}));
vi.mock('../utils/textUtils.js', () => ({
isBinary: mockIsBinary,
}));
@@ -470,15 +465,15 @@ describe('ShellExecutionService', () => {
});
describe('Platform-Specific Behavior', () => {
it('should use powershell.exe on Windows', async () => {
it('should use cmd.exe on Windows', async () => {
mockPlatform.mockReturnValue('win32');
await simulateExecution('dir "foo bar"', (pty) =>
pty.onExit.mock.calls[0][0]({ exitCode: 0, signal: null }),
);
expect(mockPtySpawn).toHaveBeenCalledWith(
'powershell.exe',
['-NoProfile', '-Command', 'dir "foo bar"'],
'cmd.exe',
'/c dir "foo bar"',
expect.any(Object),
);
});
@@ -642,9 +637,9 @@ describe('ShellExecutionService child_process fallback', () => {
});
expect(mockCpSpawn).toHaveBeenCalledWith(
'bash',
['-c', 'ls -l'],
expect.objectContaining({ shell: false, detached: true }),
'ls -l',
[],
expect.objectContaining({ shell: 'bash' }),
);
expect(result.exitCode).toBe(0);
expect(result.signal).toBeNull();
@@ -910,19 +905,18 @@ describe('ShellExecutionService child_process fallback', () => {
});
describe('Platform-Specific Behavior', () => {
it('should use powershell.exe on Windows', async () => {
it('should use cmd.exe on Windows', async () => {
mockPlatform.mockReturnValue('win32');
await simulateExecution('dir "foo bar"', (cp) =>
cp.emit('exit', 0, null),
);
expect(mockCpSpawn).toHaveBeenCalledWith(
'powershell.exe',
['-NoProfile', '-Command', 'dir "foo bar"'],
'dir "foo bar"',
[],
expect.objectContaining({
shell: false,
shell: true,
detached: false,
windowsVerbatimArguments: false,
}),
);
});
@@ -932,10 +926,10 @@ describe('ShellExecutionService child_process fallback', () => {
await simulateExecution('ls "foo bar"', (cp) => cp.emit('exit', 0, null));
expect(mockCpSpawn).toHaveBeenCalledWith(
'bash',
['-c', 'ls "foo bar"'],
'ls "foo bar"',
[],
expect.objectContaining({
shell: false,
shell: 'bash',
detached: true,
}),
);
@@ -12,7 +12,6 @@ import { TextDecoder } from 'node:util';
import os from 'node:os';
import type { IPty } from '@lydell/node-pty';
import { getCachedEncodingForBuffer } from '../utils/systemEncoding.js';
import { getShellConfiguration } from '../utils/shell-utils.js';
import { isBinary } from '../utils/textUtils.js';
import pkg from '@xterm/headless';
import {
@@ -190,14 +189,12 @@ export class ShellExecutionService {
): ShellExecutionHandle {
try {
const isWindows = os.platform() === 'win32';
const { executable, argsPrefix } = getShellConfiguration();
const spawnArgs = [...argsPrefix, commandToExecute];
const child = cpSpawn(executable, spawnArgs, {
const child = cpSpawn(commandToExecute, [], {
cwd,
stdio: ['ignore', 'pipe', 'pipe'],
windowsVerbatimArguments: isWindows ? false : undefined,
shell: false,
windowsVerbatimArguments: true,
shell: isWindows ? true : 'bash',
detached: !isWindows,
env: {
...process.env,
@@ -403,10 +400,13 @@ export class ShellExecutionService {
try {
const cols = shellExecutionConfig.terminalWidth ?? 80;
const rows = shellExecutionConfig.terminalHeight ?? 30;
const { executable, argsPrefix } = getShellConfiguration();
const args = [...argsPrefix, commandToExecute];
const isWindows = os.platform() === 'win32';
const shell = isWindows ? 'cmd.exe' : 'bash';
const args = isWindows
? `/c ${commandToExecute}`
: ['-c', commandToExecute];
const ptyProcess = ptyInfo.module.spawn(executable, args, {
const ptyProcess = ptyInfo.module.spawn(shell, args, {
cwd,
name: 'xterm',
cols,