summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
diff options
context:
space:
mode:
authorJacob MacDonald <[email protected]>2025-06-13 21:21:40 -0700
committerGitHub <[email protected]>2025-06-14 04:21:40 +0000
commitd5c6bb9740a52d87b71d812e698d0e88abf10caa (patch)
tree7cb990c0adbd1d76d60a655d3dfa15e22db033e3 /packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
parent1452bb4ca4ffe3b5c13aab81baaf510d4c45f06f (diff)
Add `/compress` command to force a compression of the context (#986)
Related to https://b.corp.google.com/issues/423605555 - I figured this might be a simpler solution to start with, while still also being useful on its own even if we do implement that.
Diffstat (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.test.ts')
-rw-r--r--packages/cli/src/ui/hooks/slashCommandProcessor.test.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
index c2873bd6..73669651 100644
--- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
+++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
@@ -62,6 +62,7 @@ import {
getMCPServerStatus,
MCPDiscoveryState,
getMCPDiscoveryState,
+ GeminiClient,
} from '@gemini-cli/core';
import { useSessionStats } from '../contexts/SessionContext.js';
@@ -100,6 +101,8 @@ describe('useSlashCommandProcessor', () => {
let mockOpenEditorDialog: ReturnType<typeof vi.fn>;
let mockPerformMemoryRefresh: ReturnType<typeof vi.fn>;
let mockSetQuittingMessages: ReturnType<typeof vi.fn>;
+ let mockTryCompressChat: ReturnType<typeof vi.fn>;
+ let mockGeminiClient: GeminiClient;
let mockConfig: Config;
let mockCorgiMode: ReturnType<typeof vi.fn>;
const mockUseSessionStats = useSessionStats as Mock;
@@ -115,8 +118,13 @@ describe('useSlashCommandProcessor', () => {
mockOpenEditorDialog = vi.fn();
mockPerformMemoryRefresh = vi.fn().mockResolvedValue(undefined);
mockSetQuittingMessages = vi.fn();
+ mockTryCompressChat = vi.fn();
+ mockGeminiClient = {
+ tryCompressChat: mockTryCompressChat,
+ } as unknown as GeminiClient;
mockConfig = {
getDebugMode: vi.fn(() => false),
+ getGeminiClient: () => mockGeminiClient,
getSandbox: vi.fn(() => 'test-sandbox'),
getModel: vi.fn(() => 'test-model'),
getProjectRoot: vi.fn(() => '/test/dir'),
@@ -944,4 +952,35 @@ Add any other context about the problem here.
expect(commandResult).toBe(true);
});
});
+
+ describe('/compress command', () => {
+ it('should call tryCompressChat(true)', async () => {
+ const { handleSlashCommand } = getProcessor();
+ mockTryCompressChat.mockImplementationOnce(async (force?: boolean) => {
+ // TODO: Check that we have a pending compression item in the history.
+ expect(force).toBe(true);
+ return {
+ originalTokenCount: 100,
+ newTokenCount: 50,
+ };
+ });
+
+ await act(async () => {
+ handleSlashCommand('/compress');
+ });
+ expect(mockGeminiClient.tryCompressChat).toHaveBeenCalledWith(true);
+ expect(mockAddItem).toHaveBeenNthCalledWith(
+ 2,
+ expect.objectContaining({
+ type: MessageType.COMPRESSION,
+ compression: {
+ isPending: false,
+ originalTokenCount: 100,
+ newTokenCount: 50,
+ },
+ }),
+ expect.any(Number),
+ );
+ });
+ });
});