mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
fix(client): Correctly latch hasFailedCompressionAttempt flag (#13002)
This commit is contained in:
@@ -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 () => {
|
it('should not trigger summarization if token count is below threshold', async () => {
|
||||||
const MOCKED_TOKEN_LIMIT = 1000;
|
const MOCKED_TOKEN_LIMIT = 1000;
|
||||||
|
|||||||
@@ -742,7 +742,8 @@ export class GeminiClient {
|
|||||||
info.compressionStatus ===
|
info.compressionStatus ===
|
||||||
CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT
|
CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT
|
||||||
) {
|
) {
|
||||||
this.hasFailedCompressionAttempt = !force && true;
|
this.hasFailedCompressionAttempt =
|
||||||
|
this.hasFailedCompressionAttempt || !force;
|
||||||
} else if (info.compressionStatus === CompressionStatus.COMPRESSED) {
|
} else if (info.compressionStatus === CompressionStatus.COMPRESSED) {
|
||||||
if (newHistory) {
|
if (newHistory) {
|
||||||
this.chat = await this.startChat(newHistory);
|
this.chat = await this.startChat(newHistory);
|
||||||
|
|||||||
Reference in New Issue
Block a user