@@ -8,14 +8,15 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
88import {
99 ChatCompressionService ,
1010 findCompressSplitPoint ,
11+ modelStringToModelConfigAlias ,
1112} from './chatCompressionService.js' ;
1213import type { Content , GenerateContentResponse } from '@google/genai' ;
1314import { CompressionStatus } from '../core/turn.js' ;
1415import { tokenLimit } from '../core/tokenLimits.js' ;
1516import type { GeminiChat } from '../core/geminiChat.js' ;
1617import type { Config } from '../config/config.js' ;
1718import { getInitialChatHistory } from '../utils/environmentContext.js' ;
18- import type { ContentGenerator } from '../core/contentGenerator .js' ;
19+ import { DEFAULT_GEMINI_MODEL } from '../config/models .js' ;
1920
2021vi . mock ( '../core/tokenLimits.js' ) ;
2122vi . mock ( '../telemetry/loggers.js' ) ;
@@ -101,11 +102,34 @@ describe('findCompressSplitPoint', () => {
101102 } ) ;
102103} ) ;
103104
105+ describe ( 'modelStringToModelConfigAlias' , ( ) => {
106+ it ( 'should return the default model for unexpected aliases' , ( ) => {
107+ expect ( modelStringToModelConfigAlias ( 'gemini-flash-flash' ) ) . toBe (
108+ DEFAULT_GEMINI_MODEL ,
109+ ) ;
110+ } ) ;
111+
112+ it ( 'should handle valid names' , ( ) => {
113+ expect ( modelStringToModelConfigAlias ( 'gemini-3-pro-preview' ) ) . toBe (
114+ 'chat-compression-3-pro' ,
115+ ) ;
116+ expect ( modelStringToModelConfigAlias ( 'gemini-2.5-pro' ) ) . toBe (
117+ 'chat-compression-2.5-pro' ,
118+ ) ;
119+ expect ( modelStringToModelConfigAlias ( 'gemini-2.5-flash' ) ) . toBe (
120+ 'chat-compression-2.5-flash' ,
121+ ) ;
122+ expect ( modelStringToModelConfigAlias ( 'gemini-2.5-flash-lite' ) ) . toBe (
123+ 'chat-compression-2.5-flash-lite' ,
124+ ) ;
125+ } ) ;
126+ } ) ;
127+
104128describe ( 'ChatCompressionService' , ( ) => {
105129 let service : ChatCompressionService ;
106130 let mockChat : GeminiChat ;
107131 let mockConfig : Config ;
108- const mockModel = 'gemini-pro' ;
132+ const mockModel = 'gemini-2.5- pro' ;
109133 const mockPromptId = 'test-prompt-id' ;
110134
111135 beforeEach ( ( ) => {
@@ -114,9 +138,22 @@ describe('ChatCompressionService', () => {
114138 getHistory : vi . fn ( ) ,
115139 getLastPromptTokenCount : vi . fn ( ) . mockReturnValue ( 500 ) ,
116140 } as unknown as GeminiChat ;
141+
142+ const mockGenerateContent = vi . fn ( ) . mockResolvedValue ( {
143+ candidates : [
144+ {
145+ content : {
146+ parts : [ { text : 'Summary' } ] ,
147+ } ,
148+ } ,
149+ ] ,
150+ } as unknown as GenerateContentResponse ) ;
151+
117152 mockConfig = {
118153 getCompressionThreshold : vi . fn ( ) ,
119- getContentGenerator : vi . fn ( ) ,
154+ getBaseLlmClient : vi . fn ( ) . mockReturnValue ( {
155+ generateContent : mockGenerateContent ,
156+ } ) ,
120157 isInteractive : vi . fn ( ) . mockReturnValue ( false ) ,
121158 } as unknown as Config ;
122159
@@ -190,18 +227,6 @@ describe('ChatCompressionService', () => {
190227 vi . mocked ( mockChat . getHistory ) . mockReturnValue ( history ) ;
191228 vi . mocked ( mockChat . getLastPromptTokenCount ) . mockReturnValue ( 800 ) ;
192229 vi . mocked ( tokenLimit ) . mockReturnValue ( 1000 ) ;
193- const mockGenerateContent = vi . fn ( ) . mockResolvedValue ( {
194- candidates : [
195- {
196- content : {
197- parts : [ { text : 'Summary' } ] ,
198- } ,
199- } ,
200- ] ,
201- } as unknown as GenerateContentResponse ) ;
202- vi . mocked ( mockConfig . getContentGenerator ) . mockReturnValue ( {
203- generateContent : mockGenerateContent ,
204- } as unknown as ContentGenerator ) ;
205230
206231 const result = await service . compress (
207232 mockChat ,
@@ -215,7 +240,7 @@ describe('ChatCompressionService', () => {
215240 expect ( result . info . compressionStatus ) . toBe ( CompressionStatus . COMPRESSED ) ;
216241 expect ( result . newHistory ) . not . toBeNull ( ) ;
217242 expect ( result . newHistory ! [ 0 ] . parts ! [ 0 ] . text ) . toBe ( 'Summary' ) ;
218- expect ( mockGenerateContent ) . toHaveBeenCalled ( ) ;
243+ expect ( mockConfig . getBaseLlmClient ( ) . generateContent ) . toHaveBeenCalled ( ) ;
219244 } ) ;
220245
221246 it ( 'should force compress even if under threshold' , async ( ) => {
@@ -229,19 +254,6 @@ describe('ChatCompressionService', () => {
229254 vi . mocked ( mockChat . getLastPromptTokenCount ) . mockReturnValue ( 100 ) ;
230255 vi . mocked ( tokenLimit ) . mockReturnValue ( 1000 ) ;
231256
232- const mockGenerateContent = vi . fn ( ) . mockResolvedValue ( {
233- candidates : [
234- {
235- content : {
236- parts : [ { text : 'Summary' } ] ,
237- } ,
238- } ,
239- ] ,
240- } as unknown as GenerateContentResponse ) ;
241- vi . mocked ( mockConfig . getContentGenerator ) . mockReturnValue ( {
242- generateContent : mockGenerateContent ,
243- } as unknown as ContentGenerator ) ;
244-
245257 const result = await service . compress (
246258 mockChat ,
247259 mockPromptId ,
@@ -265,7 +277,7 @@ describe('ChatCompressionService', () => {
265277 vi . mocked ( tokenLimit ) . mockReturnValue ( 1000 ) ;
266278
267279 const longSummary = 'a' . repeat ( 1000 ) ; // Long summary to inflate token count
268- const mockGenerateContent = vi . fn ( ) . mockResolvedValue ( {
280+ vi . mocked ( mockConfig . getBaseLlmClient ( ) . generateContent ) . mockResolvedValue ( {
269281 candidates : [
270282 {
271283 content : {
@@ -274,9 +286,6 @@ describe('ChatCompressionService', () => {
274286 } ,
275287 ] ,
276288 } as unknown as GenerateContentResponse ) ;
277- vi . mocked ( mockConfig . getContentGenerator ) . mockReturnValue ( {
278- generateContent : mockGenerateContent ,
279- } as unknown as ContentGenerator ) ;
280289
281290 const result = await service . compress (
282291 mockChat ,
0 commit comments