Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/cli/src/ui/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,19 @@ export const AppContainer = (props: AppContainerProps) => {
}
})();
registerCleanup(async () => {
const ideClient = await IdeClient.getInstance();
await ideClient.disconnect();
try {
await Promise.race([
(async () => {
const ideClient = await IdeClient.getInstance();
await ideClient.disconnect();
})(),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Cleanup timeout')), 2000),
),
]);
} catch {
// Ignore timeout or other errors
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [config]);
Expand Down
26 changes: 25 additions & 1 deletion packages/cli/src/ui/commands/ideCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,31 @@ async function setIdeModeAndSyncConnection(
}

export const ideCommand = async (): Promise<SlashCommand> => {
const ideClient = await IdeClient.getInstance();
let ideClient: IdeClient;
try {
ideClient = await Promise.race([
IdeClient.getInstance(),
new Promise<IdeClient>((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 1000),
),
]);
} catch {
return {
name: 'ide',
get description() {
return t('manage IDE integration (loading...)');
},
kind: CommandKind.BUILT_IN,
action: async (): Promise<SlashCommandActionReturn> => ({
type: 'message',
messageType: 'info',
content: t(
'IDE integration is still loading. Please try again in a moment.',
),
}),
};
}

const currentIDE = ideClient.getCurrentIde();
if (!currentIDE) {
return {
Expand Down
12 changes: 9 additions & 3 deletions packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ vi.mock('@qwen-code/qwen-code-core', async (importOriginal) => {
...original,
logSlashCommand,
getIdeInstaller: vi.fn().mockReturnValue(null),
IdeClient: {
getInstance: vi.fn().mockResolvedValue({
addStatusChangeListener: vi.fn(),
removeStatusChangeListener: vi.fn(),
}),
},
};
});

Expand Down Expand Up @@ -175,12 +181,12 @@ describe('useSlashCommandProcessor', () => {

await waitFor(() => {
expect(result.current.slashCommands).toHaveLength(1);
expect(mockBuiltinLoadCommands).toHaveBeenCalledTimes(2);
expect(mockFileLoadCommands).toHaveBeenCalledTimes(2);
expect(mockMcpLoadCommands).toHaveBeenCalledTimes(2);
});

expect(result.current.slashCommands[0]?.name).toBe('test');
expect(mockBuiltinLoadCommands).toHaveBeenCalledTimes(1);
expect(mockFileLoadCommands).toHaveBeenCalledTimes(1);
expect(mockMcpLoadCommands).toHaveBeenCalledTimes(1);
});

it('should provide an immutable array of commands to consumers', async () => {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/ui/hooks/slashCommandProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export const useSlashCommandProcessor = (
(async () => {
const ideClient = await IdeClient.getInstance();
ideClient.addStatusChangeListener(listener);
reloadCommands();
})();

return () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/ide/process-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ async function getProcessInfo(pid: number): Promise<{
'| ConvertTo-Json',
'}',
].join(' ');
const { stdout } = await execAsync(`powershell "${powershellCommand}"`);
const { stdout } = await execAsync(`powershell "${powershellCommand}"`, {
timeout: 5000,
});
const output = stdout.trim();
if (!output) return { parentPid: 0, name: '', command: '' };
const {
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/services/shellExecutionService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ describe('ShellExecutionService child_process fallback', () => {

expect(mockCpSpawn).toHaveBeenCalledWith(
'ls -l',
[],
expect.objectContaining({ shell: 'bash' }),
);
expect(result.exitCode).toBe(0);
Expand Down Expand Up @@ -826,7 +825,6 @@ describe('ShellExecutionService child_process fallback', () => {

expect(mockCpSpawn).toHaveBeenCalledWith(
'dir "foo bar"',
[],
expect.objectContaining({
shell: true,
detached: false,
Expand All @@ -840,7 +838,6 @@ describe('ShellExecutionService child_process fallback', () => {

expect(mockCpSpawn).toHaveBeenCalledWith(
'ls "foo bar"',
[],
expect.objectContaining({
shell: 'bash',
detached: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/shellExecutionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class ShellExecutionService {
try {
const isWindows = os.platform() === 'win32';

const child = cpSpawn(commandToExecute, [], {
const child = cpSpawn(commandToExecute, {
cwd,
stdio: ['ignore', 'pipe', 'pipe'],
windowsVerbatimArguments: true,
Expand Down