@@ -9,8 +9,14 @@ const mockSecrets = {
99 delete : jest . fn ( ) ,
1010}
1111
12+ const mockGlobalState = {
13+ get : jest . fn ( ) ,
14+ update : jest . fn ( ) ,
15+ }
16+
1217const mockContext = {
1318 secrets : mockSecrets ,
19+ globalState : mockGlobalState ,
1420} as unknown as ExtensionContext
1521
1622describe ( "ConfigManager" , ( ) => {
@@ -40,8 +46,12 @@ describe("ConfigManager", () => {
4046 default : {
4147 config : { } ,
4248 id : "default" ,
49+ rateLimitSeconds : 5 ,
4350 } ,
4451 } ,
52+ migrations : {
53+ rateLimitMigrated : true ,
54+ } ,
4555 } ) ,
4656 )
4757
@@ -66,6 +76,9 @@ describe("ConfigManager", () => {
6676 } ) ,
6777 )
6878
79+ // Mock global state to prevent rate limit errors
80+ mockGlobalState . get . mockResolvedValue ( 5 )
81+
6982 await configManager . initConfig ( )
7083
7184 // Should have written the config with new IDs
@@ -141,6 +154,9 @@ describe("ConfigManager", () => {
141154
142155 describe ( "SaveConfig" , ( ) => {
143156 it ( "should save new config" , async ( ) => {
157+ // Mock globalState to prevent rate limit errors
158+ mockGlobalState . get . mockResolvedValue ( 5 )
159+
144160 mockSecrets . get . mockResolvedValue (
145161 JSON . stringify ( {
146162 currentApiConfigName : "default" ,
@@ -162,9 +178,10 @@ describe("ConfigManager", () => {
162178
163179 await configManager . saveConfig ( "test" , newConfig )
164180
165- // Get the actual stored config to check the generated ID
181+ // Get the actual stored config to check the generated ID and rate limit
166182 const storedConfig = JSON . parse ( mockSecrets . store . mock . calls [ 0 ] [ 1 ] )
167183 const testConfigId = storedConfig . apiConfigs . test . id
184+ const rateLimitSeconds = storedConfig . apiConfigs . test . rateLimitSeconds
168185
169186 const expectedConfig = {
170187 currentApiConfigName : "default" ,
@@ -173,6 +190,7 @@ describe("ConfigManager", () => {
173190 test : {
174191 ...newConfig ,
175192 id : testConfigId ,
193+ rateLimitSeconds,
176194 } ,
177195 } ,
178196 modeApiConfigs : {
@@ -196,6 +214,7 @@ describe("ConfigManager", () => {
196214 apiProvider : "anthropic" ,
197215 apiKey : "old-key" ,
198216 id : "test-id" ,
217+ rateLimitSeconds : 5 ,
199218 } ,
200219 } ,
201220 }
@@ -209,21 +228,14 @@ describe("ConfigManager", () => {
209228
210229 await configManager . saveConfig ( "test" , updatedConfig )
211230
212- const expectedConfig = {
213- currentApiConfigName : "default" ,
214- apiConfigs : {
215- test : {
216- apiProvider : "anthropic" ,
217- apiKey : "new-key" ,
218- id : "test-id" ,
219- } ,
220- } ,
221- }
222-
223- expect ( mockSecrets . store ) . toHaveBeenCalledWith (
224- "roo_cline_config_api_config" ,
225- JSON . stringify ( expectedConfig , null , 2 ) ,
226- )
231+ // Check that the last call to store has the correct values
232+ const storedConfig = JSON . parse ( mockSecrets . store . mock . calls [ mockSecrets . store . mock . calls . length - 1 ] [ 1 ] )
233+ expect ( storedConfig . apiConfigs . test ) . toEqual ( {
234+ apiProvider : "anthropic" ,
235+ apiKey : "new-key" ,
236+ id : "test-id" ,
237+ rateLimitSeconds : 5 ,
238+ } )
227239 } )
228240
229241 it ( "should throw error if secrets storage fails" , async ( ) => {
@@ -319,8 +331,9 @@ describe("ConfigManager", () => {
319331 id : "test-id" ,
320332 } )
321333
322- // Get the stored config to check the structure
323- const storedConfig = JSON . parse ( mockSecrets . store . mock . calls [ 0 ] [ 1 ] )
334+ // Get the last stored config to check the structure
335+ const lastCallIndex = mockSecrets . store . mock . calls . length - 1
336+ const storedConfig = JSON . parse ( mockSecrets . store . mock . calls [ lastCallIndex ] [ 1 ] )
324337 expect ( storedConfig . currentApiConfigName ) . toBe ( "test" )
325338 expect ( storedConfig . apiConfigs . test ) . toEqual ( {
326339 apiProvider : "anthropic" ,
@@ -386,8 +399,9 @@ describe("ConfigManager", () => {
386399
387400 await configManager . setCurrentConfig ( "test" )
388401
389- // Get the stored config to check the structure
390- const storedConfig = JSON . parse ( mockSecrets . store . mock . calls [ 0 ] [ 1 ] )
402+ // Get the last stored config to check the structure
403+ const lastCallIndex = mockSecrets . store . mock . calls . length - 1
404+ const storedConfig = JSON . parse ( mockSecrets . store . mock . calls [ lastCallIndex ] [ 1 ] )
391405 expect ( storedConfig . currentApiConfigName ) . toBe ( "test" )
392406 expect ( storedConfig . apiConfigs . default . id ) . toBe ( "default" )
393407 expect ( storedConfig . apiConfigs . test ) . toEqual ( {
0 commit comments