11import "reflect-metadata" ;
22
3- // Mock modelScaling module
4- jest . mock ( "@constants/modelScaling" , ( ) => ( {
5- __esModule : true ,
6- autoScaleAvailableModels : [
7- {
8- id : "qwen/qwen-2.5-coder-32b-instruct" ,
9- description : "Cheap, fast, slightly better than GPT4o-mini" ,
10- maxWriteTries : 2 ,
11- maxGlobalTries : 5 ,
12- } ,
13- {
14- id : "anthropic/claude-3.5-sonnet:beta" ,
15- description : "Scaled model for retry attempts" ,
16- maxWriteTries : 3 ,
17- maxGlobalTries : 10 ,
18- } ,
19- {
20- id : "openai/gpt-4o-2024-11-20" ,
21- description : "Scaled model for retry attempts" ,
22- maxWriteTries : 5 ,
23- maxGlobalTries : 15 ,
24- } ,
25- {
26- id : "openai/o1-mini" ,
27- description : "Final model for complex cases (currently inactive)" ,
28- maxWriteTries : 2 ,
29- maxGlobalTries : 20 ,
30- } ,
31- ] ,
32- getModelForTryCount : (
33- tryCount : string | null ,
34- globalTries : number ,
35- ) : string => {
36- const models = [
37- {
38- id : "qwen/qwen-2.5-coder-32b-instruct" ,
39- maxWriteTries : 2 ,
40- maxGlobalTries : 5 ,
41- } ,
42- {
43- id : "anthropic/claude-3.5-sonnet:beta" ,
44- maxWriteTries : 3 ,
45- maxGlobalTries : 10 ,
46- } ,
47- {
48- id : "openai/gpt-4o-2024-11-20" ,
49- maxWriteTries : 5 ,
50- maxGlobalTries : 15 ,
51- } ,
52- {
53- id : "openai/o1-mini" ,
54- maxWriteTries : 2 ,
55- maxGlobalTries : 20 ,
56- } ,
57- ] ;
58-
59- if ( ! tryCount ) return models [ 0 ] . id ;
60-
61- const tries = parseInt ( tryCount , 10 ) ;
62-
63- for ( let i = 0 ; i < models . length ; i ++ ) {
64- const previousTriesSum = models
65- . slice ( 0 , i )
66- . reduce ( ( sum , model ) => sum + model . maxWriteTries , 0 ) ;
67-
68- if (
69- tries >= previousTriesSum + models [ i ] . maxWriteTries ||
70- globalTries >= models [ i ] . maxGlobalTries
71- ) {
72- continue ;
73- }
74-
75- return models [ i ] . id ;
76- }
77-
78- return models [ models . length - 1 ] . id ;
79- } ,
80- } ) ) ;
81-
823// Mock chalk with a default export that matches how it's used
834jest . mock ( "chalk" , ( ) => ( {
845 __esModule : true ,
@@ -102,3 +23,41 @@ jest.mock("chalk", () => ({
10223 strikethrough : jest . fn ( ( text ) => text ) ,
10324 } ,
10425} ) ) ;
26+
27+ // Global mock for ModelInfo
28+ jest . mock ( "@services/LLM/ModelInfo" , ( ) => {
29+ const originalModule = jest . requireActual ( "@services/LLM/ModelInfo" ) ;
30+
31+ return {
32+ ...originalModule ,
33+ ModelInfo : jest . fn ( ) . mockImplementation ( ( ) => ( {
34+ initialize : jest . fn ( ) . mockResolvedValue ( undefined ) ,
35+ ensureInitialized : jest . fn ( ) . mockResolvedValue ( undefined ) ,
36+ getCurrentModel : jest . fn ( ) . mockReturnValue ( "gpt-4" ) ,
37+ getCurrentModelInfo : jest . fn ( ) . mockReturnValue ( {
38+ id : "gpt-4" ,
39+ context_length : 8192 ,
40+ top_provider : {
41+ max_completion_tokens : 4096 ,
42+ } ,
43+ } ) ,
44+ setCurrentModel : jest . fn ( ) . mockResolvedValue ( undefined ) ,
45+ getModelInfo : jest . fn ( ) . mockResolvedValue ( {
46+ id : "gpt-4" ,
47+ context_length : 8192 ,
48+ top_provider : {
49+ max_completion_tokens : 4096 ,
50+ } ,
51+ } ) ,
52+ isModelAvailable : jest . fn ( ) . mockResolvedValue ( true ) ,
53+ getAllModels : jest . fn ( ) . mockResolvedValue ( [ "gpt-4" ] ) ,
54+ getCurrentModelContextLength : jest . fn ( ) . mockResolvedValue ( 8192 ) ,
55+ getModelContextLength : jest . fn ( ) . mockResolvedValue ( 8192 ) ,
56+ getCurrentModelMaxCompletionTokens : jest . fn ( ) . mockResolvedValue ( 4096 ) ,
57+ getModelMaxCompletionTokens : jest . fn ( ) . mockResolvedValue ( 4096 ) ,
58+ logCurrentModelUsage : jest . fn ( ) . mockResolvedValue ( undefined ) ,
59+ } ) ) ,
60+ } ;
61+ } ) ;
62+
63+ process . env . IS_UNIT_TEST = "true" ;
0 commit comments