fix:移除无用的stdio校验

This commit is contained in:
li1553770945 2025-06-29 21:36:42 +08:00
parent 4b3bbbed66
commit 21eea00818
4 changed files with 541 additions and 408 deletions

View File

@ -44,20 +44,6 @@ export async function deleteInstalledConnection(item: McpOptions[] | McpOptions)
}
}
export async function validateAndGetCommandPath(commandString: string, cwd?: string): Promise<string> {
try {
const commands = commandString.split(' ');
const command = commands[0];
const args = commands.slice(1);
const process = spawn(command, args || [], { shell: true, cwd });
process.disconnect();
return '';
} catch (error) {
console.log(error);
throw new Error(`Cannot find command: ${commandString.split(' ')[0]}`);
}
}
export async function acquireInstalledConnection(): Promise<McpOptions[]> {
// 让用户选择连接类型
@ -88,14 +74,6 @@ export async function acquireInstalledConnection(): Promise<McpOptions[]> {
placeHolder: t('please-enter-cwd-placeholder')
});
// 校验 command + cwd 是否有效
try {
const commandPath = await validateAndGetCommandPath(commandString, cwd);
console.log('Command Path:', commandPath);
} catch (error) {
vscode.window.showErrorMessage(`Invalid command: ${error}`);
return [];
}
const commands = commandString.split(' ');
const command = commands[0];

View File

@ -1,8 +1,8 @@
import { getFirstValidPathFromCommand, getWorkspaceConnectionConfig, getWorkspacePath, McpOptions, panels, saveWorkspaceConnectionConfig } from "../global.js";
import * as vscode from 'vscode';
import { t } from "../i18n/index.js";
import { exec } from 'child_process';
import { promisify } from 'util';
import { spawn } from 'node:child_process';
export async function deleteUserConnection(item: McpOptions[] | McpOptions) {
// 弹出确认对话框
@ -46,18 +46,6 @@ export async function deleteUserConnection(item: McpOptions[] | McpOptions) {
}
}
export async function validateAndGetCommandPath(command: string, cwd?: string): Promise<string> {
const execAsync = promisify(exec);
try {
const { stdout } = await execAsync(`which ${command.split(' ')[0]}`, { cwd });
return stdout.trim();
} catch (error) {
throw new Error(`Cannot find command: ${command.split(' ')[0]}`);
}
}
export async function acquireUserCustomConnection(): Promise<McpOptions[]> {
// 让用户选择连接类型
const connectionType = await vscode.window.showQuickPick(['STDIO', 'SSE', 'STREAMABLE_HTTP'], {
@ -87,14 +75,6 @@ export async function acquireUserCustomConnection(): Promise<McpOptions[]> {
placeHolder: t('please-enter-cwd-placeholder')
});
// 校验 command + cwd 是否有效
try {
const commandPath = await validateAndGetCommandPath(commandString, cwd);
console.log('Command Path:', commandPath);
} catch (error) {
vscode.window.showErrorMessage(`Invalid command: ${error}`);
return [];
}
const commands = commandString.split(' ');
const command = commands[0];

View File

@ -4,41 +4,60 @@ import * as sinon from 'sinon';
suite('连接管理测试', () => {
vscode.window.showInformationMessage('开始测试连接管理');
vscode.window.showInformationMessage('开始测试连接管理');
let inputBoxStub: sinon.SinonStub;
let quickPickStub: sinon.SinonStub;
let inputBoxStub: sinon.SinonStub;
let quickPickStub: sinon.SinonStub;
setup(async () => {
// mock showQuickPick
// quickPickStub = sinon.stub(vscode.window, 'showQuickPick');
// // mock showInputBox
// inputBoxStub = sinon.stub(vscode.window, 'showInputBox');
await vscode.commands.executeCommand('workbench.view.extension.openmcp-sidebar');
setup(async () => {
// mock选择连接类型
quickPickStub = sinon.stub(vscode.window, 'showQuickPick');
// mock 连接地址和认证输入框
inputBoxStub = sinon.stub(vscode.window, 'showInputBox');
await vscode.commands.executeCommand('workbench.view.extension.openmcp-sidebar');
deleteAllConnection();
});
});
teardown(() => {
sinon.restore();
});
teardown(() => {
sinon.restore();
});
test('新建STDIO连接', async function () {
this.timeout(15000);
// await vscode.commands.executeCommand('openmcp.sidebar.workspace-connection.addConnection');
// quickPickStub.onFirstCall().resolves('STDIO');
// await new Promise(resolve => setTimeout(resolve, 5000));
// inputBoxStub.onFirstCall().resolves('echo'); // command
// await new Promise(resolve => setTimeout(resolve, 5000));
// inputBoxStub.onSecondCall().resolves(''); // cwd
const deleteAllConnection = async () => {
//在开始之前删除所有链接
}
test('新建STDIO连接', async function () {
this.timeout(15000);
quickPickStub.onFirstCall().resolves('STDIO');
inputBoxStub.onFirstCall().resolves('echo'); // command
inputBoxStub.onSecondCall().resolves(''); // cwd
await vscode.commands.executeCommand('openmcp.sidebar.workspace-connection.addConnection');
});
await vscode.commands.executeCommand('openmcp.sidebar.installed-connection.addConnection');
});
test('新建SSE连接', async function () {
quickPickStub.onFirstCall().resolves('SSE');
inputBoxStub.onFirstCall().resolves('http://localhost/sse'); // command
inputBoxStub.onSecondCall().resolves(''); // cwd
await vscode.commands.executeCommand('openmcp.sidebar.installed-connection.addConnection');
test('等待以便观察窗口', async function () {
this.timeout(15000);
await new Promise(resolve => setTimeout(resolve, 10000));
});
});
test('新建StreamableHttp连接', async function () {
quickPickStub.onFirstCall().resolves('STREAMABLE_HTTP');
inputBoxStub.onFirstCall().resolves('http://localhost/mcp'); // command
inputBoxStub.onSecondCall().resolves(''); // cwd
await vscode.commands.executeCommand('openmcp.sidebar.installed-connection.addConnection');
});
test('等待以便观察窗口', async function () {
this.timeout(15000);
await new Promise(resolve => setTimeout(resolve, 10000));
});
});

824
yarn.lock

File diff suppressed because it is too large Load Diff