[ide-mode] Close all open diffs when the CLI gets closed (#5792)

This commit is contained in:
christine betts
2025-08-08 15:38:30 +00:00
committed by GitHub
parent 5ec4ea9b4d
commit 3af4913ef3
7 changed files with 126 additions and 7 deletions

View File

@@ -122,6 +122,9 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
const [idePromptAnswered, setIdePromptAnswered] = useState(false);
const currentIDE = config.getIdeClient().getCurrentIde();
useEffect(() => {
registerCleanup(() => config.getIdeClient().disconnect());
}, [config]);
const shouldShowIdePrompt =
config.getIdeModeFeature() &&
currentIDE &&

View File

@@ -60,6 +60,14 @@ vi.mock('../contexts/SessionContext.js', () => ({
useSessionStats: vi.fn(() => ({ stats: {} })),
}));
const { mockRunExitCleanup } = vi.hoisted(() => ({
mockRunExitCleanup: vi.fn(),
}));
vi.mock('../../utils/cleanup.js', () => ({
runExitCleanup: mockRunExitCleanup,
}));
import { act, renderHook, waitFor } from '@testing-library/react';
import { vi, describe, it, expect, beforeEach, type Mock } from 'vitest';
import { useSlashCommandProcessor } from './slashCommandProcessor.js';
@@ -405,6 +413,37 @@ describe('useSlashCommandProcessor', () => {
vi.useRealTimers();
}
});
it('should call runExitCleanup when handling a "quit" action', async () => {
const quitAction = vi
.fn()
.mockResolvedValue({ type: 'quit', messages: [] });
const command = createTestCommand({
name: 'exit',
action: quitAction,
});
const result = setupProcessorHook([command]);
await waitFor(() =>
expect(result.current.slashCommands).toHaveLength(1),
);
vi.useFakeTimers();
try {
await act(async () => {
await result.current.handleSlashCommand('/exit');
});
await act(async () => {
await vi.advanceTimersByTimeAsync(200);
});
expect(mockRunExitCleanup).toHaveBeenCalledTimes(1);
} finally {
vi.useRealTimers();
}
});
});
it('should handle "submit_prompt" action returned from a file-based command', async () => {

View File

@@ -18,6 +18,7 @@ import {
ToolConfirmationOutcome,
} from '@google/gemini-cli-core';
import { useSessionStats } from '../contexts/SessionContext.js';
import { runExitCleanup } from '../../utils/cleanup.js';
import {
Message,
MessageType,
@@ -370,7 +371,8 @@ export const useSlashCommandProcessor = (
}
case 'quit':
setQuittingMessages(result.messages);
setTimeout(() => {
setTimeout(async () => {
await runExitCleanup();
process.exit(0);
}, 100);
return { type: 'handled' };