@@ -255,4 +255,77 @@ describe("ContextProxy", () => {
255255 expect ( proxy . getGlobalState ( "unknownKey" ) ) . toBe ( "some-value" )
256256 } )
257257 } )
258+
259+ describe ( "resetAllState" , ( ) => {
260+ it ( "should clear all in-memory caches" , async ( ) => {
261+ // Setup initial state in caches
262+ await proxy . setValues ( {
263+ apiModelId : "gpt-4" , // global state
264+ openAiApiKey : "test-api-key" , // secret
265+ unknownKey : "some-value" , // unknown
266+ } )
267+
268+ // Verify initial state
269+ expect ( proxy . getGlobalState ( "apiModelId" ) ) . toBe ( "gpt-4" )
270+ expect ( proxy . getSecret ( "openAiApiKey" ) ) . toBe ( "test-api-key" )
271+ expect ( proxy . getGlobalState ( "unknownKey" ) ) . toBe ( "some-value" )
272+
273+ // Reset all state
274+ await proxy . resetAllState ( )
275+
276+ // Caches should be reinitialized with values from the context
277+ // Since our mock globalState.get returns undefined by default,
278+ // the cache should now contain undefined values
279+ expect ( proxy . getGlobalState ( "apiModelId" ) ) . toBeUndefined ( )
280+ expect ( proxy . getGlobalState ( "unknownKey" ) ) . toBeUndefined ( )
281+ } )
282+
283+ it ( "should update all global state keys to undefined" , async ( ) => {
284+ // Setup initial state
285+ await proxy . updateGlobalState ( "apiModelId" , "gpt-4" )
286+ await proxy . updateGlobalState ( "apiProvider" , "openai" )
287+
288+ // Reset all state
289+ await proxy . resetAllState ( )
290+
291+ // Should have called update with undefined for each key
292+ for ( const key of GLOBAL_STATE_KEYS ) {
293+ expect ( mockGlobalState . update ) . toHaveBeenCalledWith ( key , undefined )
294+ }
295+
296+ // Total calls should include initial setup + reset operations
297+ const expectedUpdateCalls = 2 + GLOBAL_STATE_KEYS . length
298+ expect ( mockGlobalState . update ) . toHaveBeenCalledTimes ( expectedUpdateCalls )
299+ } )
300+
301+ it ( "should delete all secrets" , async ( ) => {
302+ // Setup initial secrets
303+ await proxy . storeSecret ( "apiKey" , "test-api-key" )
304+ await proxy . storeSecret ( "openAiApiKey" , "test-openai-key" )
305+
306+ // Reset all state
307+ await proxy . resetAllState ( )
308+
309+ // Should have called delete for each key
310+ for ( const key of SECRET_KEYS ) {
311+ expect ( mockSecrets . delete ) . toHaveBeenCalledWith ( key )
312+ }
313+
314+ // Total calls should equal the number of secret keys
315+ expect ( mockSecrets . delete ) . toHaveBeenCalledTimes ( SECRET_KEYS . length )
316+ } )
317+
318+ it ( "should reinitialize caches after reset" , async ( ) => {
319+ // Spy on initialization methods
320+ const initStateCache = jest . spyOn ( proxy as any , "initializeStateCache" )
321+ const initSecretCache = jest . spyOn ( proxy as any , "initializeSecretCache" )
322+
323+ // Reset all state
324+ await proxy . resetAllState ( )
325+
326+ // Should reinitialize caches
327+ expect ( initStateCache ) . toHaveBeenCalledTimes ( 1 )
328+ expect ( initSecretCache ) . toHaveBeenCalledTimes ( 1 )
329+ } )
330+ } )
258331} )
0 commit comments