fix(client): Correctly latch hasFailedCompressionAttempt flag (#13002)

This commit is contained in:
Paresh Joshi
2025-12-04 23:42:45 +05:30
committed by GitHub
parent 205d0f456e
commit 2d1c1ac567
2 changed files with 27 additions and 1 deletions

View File

@@ -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;

View File

@@ -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);