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[]> { export async function acquireInstalledConnection(): Promise<McpOptions[]> {
// 让用户选择连接类型 // 让用户选择连接类型
@ -88,14 +74,6 @@ export async function acquireInstalledConnection(): Promise<McpOptions[]> {
placeHolder: t('please-enter-cwd-placeholder') 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 commands = commandString.split(' ');
const command = commands[0]; const command = commands[0];

View File

@ -1,8 +1,8 @@
import { getFirstValidPathFromCommand, getWorkspaceConnectionConfig, getWorkspacePath, McpOptions, panels, saveWorkspaceConnectionConfig } from "../global.js"; import { getFirstValidPathFromCommand, getWorkspaceConnectionConfig, getWorkspacePath, McpOptions, panels, saveWorkspaceConnectionConfig } from "../global.js";
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { t } from "../i18n/index.js"; import { t } from "../i18n/index.js";
import { exec } from 'child_process';
import { promisify } from 'util'; import { promisify } from 'util';
import { spawn } from 'node:child_process';
export async function deleteUserConnection(item: McpOptions[] | McpOptions) { 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[]> { export async function acquireUserCustomConnection(): Promise<McpOptions[]> {
// 让用户选择连接类型 // 让用户选择连接类型
const connectionType = await vscode.window.showQuickPick(['STDIO', 'SSE', 'STREAMABLE_HTTP'], { 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') 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 commands = commandString.split(' ');
const command = commands[0]; const command = commands[0];

View File

@ -10,11 +10,12 @@ suite('连接管理测试', () => {
let quickPickStub: sinon.SinonStub; let quickPickStub: sinon.SinonStub;
setup(async () => { setup(async () => {
// mock showQuickPick // mock选择连接类型
// quickPickStub = sinon.stub(vscode.window, 'showQuickPick'); quickPickStub = sinon.stub(vscode.window, 'showQuickPick');
// // mock showInputBox // mock 连接地址和认证输入框
// inputBoxStub = sinon.stub(vscode.window, 'showInputBox'); inputBoxStub = sinon.stub(vscode.window, 'showInputBox');
await vscode.commands.executeCommand('workbench.view.extension.openmcp-sidebar'); await vscode.commands.executeCommand('workbench.view.extension.openmcp-sidebar');
deleteAllConnection();
}); });
@ -22,18 +23,36 @@ suite('连接管理测试', () => {
sinon.restore(); sinon.restore();
}); });
const deleteAllConnection = async () => {
//在开始之前删除所有链接
}
test('新建STDIO连接', async function () { test('新建STDIO连接', async function () {
this.timeout(15000); this.timeout(15000);
// await vscode.commands.executeCommand('openmcp.sidebar.workspace-connection.addConnection'); quickPickStub.onFirstCall().resolves('STDIO');
// quickPickStub.onFirstCall().resolves('STDIO'); inputBoxStub.onFirstCall().resolves('echo'); // command
// await new Promise(resolve => setTimeout(resolve, 5000)); inputBoxStub.onSecondCall().resolves(''); // cwd
// inputBoxStub.onFirstCall().resolves('echo'); // command
// await new Promise(resolve => setTimeout(resolve, 5000)); await vscode.commands.executeCommand('openmcp.sidebar.installed-connection.addConnection');
// inputBoxStub.onSecondCall().resolves(''); // cwd
await vscode.commands.executeCommand('openmcp.sidebar.workspace-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('新建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 () { test('等待以便观察窗口', async function () {
this.timeout(15000); this.timeout(15000);

824
yarn.lock

File diff suppressed because it is too large Load Diff