mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
refactor(ide): Improve IDE detection discovery (#6765)
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
} from 'vitest';
|
||||
import { IdeClient, IDEConnectionStatus } from './ide-client.js';
|
||||
import * as fs from 'node:fs';
|
||||
import { getIdeProcessId } from './process-utils.js';
|
||||
import { getIdeProcessInfo } from './process-utils.js';
|
||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
||||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
||||
@@ -51,7 +51,7 @@ describe('IdeClient', () => {
|
||||
let mockHttpTransport: Mocked<StreamableHTTPClientTransport>;
|
||||
let mockStdioTransport: Mocked<StdioClientTransport>;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
// Reset singleton instance for test isolation
|
||||
(IdeClient as unknown as { instance: IdeClient | undefined }).instance =
|
||||
undefined;
|
||||
@@ -68,7 +68,10 @@ describe('IdeClient', () => {
|
||||
vi.mocked(getIdeInfo).mockReturnValue({
|
||||
displayName: 'VS Code',
|
||||
} as IdeInfo);
|
||||
vi.mocked(getIdeProcessId).mockResolvedValue(12345);
|
||||
vi.mocked(getIdeProcessInfo).mockResolvedValue({
|
||||
pid: 12345,
|
||||
command: 'test-ide',
|
||||
});
|
||||
vi.mocked(os.tmpdir).mockReturnValue('/tmp');
|
||||
|
||||
// Mock MCP client and transports
|
||||
@@ -88,6 +91,8 @@ describe('IdeClient', () => {
|
||||
vi.mocked(Client).mockReturnValue(mockClient);
|
||||
vi.mocked(StreamableHTTPClientTransport).mockReturnValue(mockHttpTransport);
|
||||
vi.mocked(StdioClientTransport).mockReturnValue(mockStdioTransport);
|
||||
|
||||
await IdeClient.getInstance();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -99,7 +104,7 @@ describe('IdeClient', () => {
|
||||
const config = { port: '8080' };
|
||||
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||
|
||||
const ideClient = IdeClient.getInstance();
|
||||
const ideClient = await IdeClient.getInstance();
|
||||
await ideClient.connect();
|
||||
|
||||
expect(fs.promises.readFile).toHaveBeenCalledWith(
|
||||
@@ -120,7 +125,7 @@ describe('IdeClient', () => {
|
||||
const config = { stdio: { command: 'test-cmd', args: ['--foo'] } };
|
||||
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||
|
||||
const ideClient = IdeClient.getInstance();
|
||||
const ideClient = await IdeClient.getInstance();
|
||||
await ideClient.connect();
|
||||
|
||||
expect(StdioClientTransport).toHaveBeenCalledWith({
|
||||
@@ -140,7 +145,7 @@ describe('IdeClient', () => {
|
||||
};
|
||||
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||
|
||||
const ideClient = IdeClient.getInstance();
|
||||
const ideClient = await IdeClient.getInstance();
|
||||
await ideClient.connect();
|
||||
|
||||
expect(StreamableHTTPClientTransport).toHaveBeenCalled();
|
||||
@@ -156,7 +161,7 @@ describe('IdeClient', () => {
|
||||
);
|
||||
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '9090';
|
||||
|
||||
const ideClient = IdeClient.getInstance();
|
||||
const ideClient = await IdeClient.getInstance();
|
||||
await ideClient.connect();
|
||||
|
||||
expect(StreamableHTTPClientTransport).toHaveBeenCalledWith(
|
||||
@@ -176,7 +181,7 @@ describe('IdeClient', () => {
|
||||
process.env['GEMINI_CLI_IDE_SERVER_STDIO_COMMAND'] = 'env-cmd';
|
||||
process.env['GEMINI_CLI_IDE_SERVER_STDIO_ARGS'] = '["--bar"]';
|
||||
|
||||
const ideClient = IdeClient.getInstance();
|
||||
const ideClient = await IdeClient.getInstance();
|
||||
await ideClient.connect();
|
||||
|
||||
expect(StdioClientTransport).toHaveBeenCalledWith({
|
||||
@@ -194,7 +199,7 @@ describe('IdeClient', () => {
|
||||
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '9090';
|
||||
|
||||
const ideClient = IdeClient.getInstance();
|
||||
const ideClient = await IdeClient.getInstance();
|
||||
await ideClient.connect();
|
||||
|
||||
expect(StreamableHTTPClientTransport).toHaveBeenCalledWith(
|
||||
@@ -211,7 +216,7 @@ describe('IdeClient', () => {
|
||||
new Error('File not found'),
|
||||
);
|
||||
|
||||
const ideClient = IdeClient.getInstance();
|
||||
const ideClient = await IdeClient.getInstance();
|
||||
await ideClient.connect();
|
||||
|
||||
expect(StreamableHTTPClientTransport).not.toHaveBeenCalled();
|
||||
|
||||
Reference in New Issue
Block a user