diff --git a/packages/core/src/core/client.test.ts b/packages/core/src/core/client.test.ts index e362243054..f6f8e98c40 100644 --- a/packages/core/src/core/client.test.ts +++ b/packages/core/src/core/client.test.ts @@ -511,6 +511,31 @@ describe('Gemini Client (client.ts)', () => { ); }); }); + it('should correctly latch hasFailedCompressionAttempt flag', async () => { + // 1. Setup: Call setup() from this test file + // This helper function mocks the compression service for us. + const { client } = setup({ + originalTokenCount: 100, + newTokenCount: 200, // Inflated + compressionStatus: + CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT, + }); + + // 2. Test Step 1: Trigger a non-forced failure + await client.tryCompressChat('prompt-1', false); // force = false + + // 3. Assert Step 1: Check that the flag became true + // eslint-disable-next-line @typescript-eslint/no-explicit-any + expect((client as any).hasFailedCompressionAttempt).toBe(true); + + // 4. Test Step 2: Trigger a forced failure + + await client.tryCompressChat('prompt-2', true); // force = true + + // 5. Assert Step 2: Check that the flag REMAINS true + // eslint-disable-next-line @typescript-eslint/no-explicit-any + expect((client as any).hasFailedCompressionAttempt).toBe(true); + }); it('should not trigger summarization if token count is below threshold', async () => { const MOCKED_TOKEN_LIMIT = 1000; diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index 43a8a5ae00..f7d915bc9a 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -742,7 +742,8 @@ export class GeminiClient { info.compressionStatus === CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT ) { - this.hasFailedCompressionAttempt = !force && true; + this.hasFailedCompressionAttempt = + this.hasFailedCompressionAttempt || !force; } else if (info.compressionStatus === CompressionStatus.COMPRESSED) { if (newHistory) { this.chat = await this.startChat(newHistory);