22
33import * as vscode from "vscode"
44
5- import { GLOBAL_STATE_KEYS , SECRET_STATE_KEYS } from "@roo-code/types"
5+ import { GLOBAL_STATE_KEYS , SECRET_STATE_KEYS , WORKSPACE_SETTINGS_KEYS } from "@roo-code/types"
66
77import { ContextProxy } from "../ContextProxy"
88
@@ -22,6 +22,7 @@ describe("ContextProxy", () => {
2222 let mockContext : any
2323 let mockGlobalState : any
2424 let mockSecrets : any
25+ let mockWorkspaceState : any
2526
2627 beforeEach ( async ( ) => {
2728 // Reset mocks
@@ -40,10 +41,17 @@ describe("ContextProxy", () => {
4041 delete : vi . fn ( ) . mockResolvedValue ( undefined ) ,
4142 }
4243
44+ // Mock workspaceState
45+ mockWorkspaceState = {
46+ get : vi . fn ( ) ,
47+ update : vi . fn ( ) . mockResolvedValue ( undefined ) ,
48+ }
49+
4350 // Mock the extension context
4451 mockContext = {
4552 globalState : mockGlobalState ,
4653 secrets : mockSecrets ,
54+ workspaceState : mockWorkspaceState ,
4755 extensionUri : { path : "/test/extension" } ,
4856 extensionPath : "/test/extension" ,
4957 globalStorageUri : { path : "/test/storage" } ,
@@ -82,6 +90,13 @@ describe("ContextProxy", () => {
8290 expect ( mockSecrets . get ) . toHaveBeenCalledWith ( key )
8391 }
8492 } )
93+
94+ it ( "should initialize workspace state cache with all workspace settings keys" , ( ) => {
95+ expect ( mockWorkspaceState . get ) . toHaveBeenCalledTimes ( WORKSPACE_SETTINGS_KEYS . length )
96+ for ( const key of WORKSPACE_SETTINGS_KEYS ) {
97+ expect ( mockWorkspaceState . get ) . toHaveBeenCalledWith ( key )
98+ }
99+ } )
85100 } )
86101
87102 describe ( "getGlobalState" , ( ) => {
@@ -102,41 +117,6 @@ describe("ContextProxy", () => {
102117 const result = proxy . getGlobalState ( "apiProvider" , "deepseek" )
103118 expect ( result ) . toBe ( "deepseek" )
104119 } )
105-
106- it ( "should bypass cache for pass-through state keys" , async ( ) => {
107- // Setup mock return value
108- mockGlobalState . get . mockReturnValue ( "pass-through-value" )
109-
110- // Use a pass-through key (taskHistory)
111- const result = proxy . getGlobalState ( "taskHistory" )
112-
113- // Should get value directly from original context
114- expect ( result ) . toBe ( "pass-through-value" )
115- expect ( mockGlobalState . get ) . toHaveBeenCalledWith ( "taskHistory" )
116- } )
117-
118- it ( "should respect default values for pass-through state keys" , async ( ) => {
119- // Setup mock to return undefined
120- mockGlobalState . get . mockReturnValue ( undefined )
121-
122- // Use a pass-through key with default value
123- const historyItems = [
124- {
125- id : "1" ,
126- number : 1 ,
127- ts : 1 ,
128- task : "test" ,
129- tokensIn : 1 ,
130- tokensOut : 1 ,
131- totalCost : 1 ,
132- } ,
133- ]
134-
135- const result = proxy . getGlobalState ( "taskHistory" , historyItems )
136-
137- // Should return default value when original context returns undefined
138- expect ( result ) . toBe ( historyItems )
139- } )
140120 } )
141121
142122 describe ( "updateGlobalState" , ( ) => {
@@ -150,33 +130,6 @@ describe("ContextProxy", () => {
150130 const storedValue = await proxy . getGlobalState ( "apiProvider" )
151131 expect ( storedValue ) . toBe ( "deepseek" )
152132 } )
153-
154- it ( "should bypass cache for pass-through state keys" , async ( ) => {
155- const historyItems = [
156- {
157- id : "1" ,
158- number : 1 ,
159- ts : 1 ,
160- task : "test" ,
161- tokensIn : 1 ,
162- tokensOut : 1 ,
163- totalCost : 1 ,
164- } ,
165- ]
166-
167- await proxy . updateGlobalState ( "taskHistory" , historyItems )
168-
169- // Should update original context
170- expect ( mockGlobalState . update ) . toHaveBeenCalledWith ( "taskHistory" , historyItems )
171-
172- // Setup mock for subsequent get
173- mockGlobalState . get . mockReturnValue ( historyItems )
174-
175- // Should get fresh value from original context
176- const storedValue = proxy . getGlobalState ( "taskHistory" )
177- expect ( storedValue ) . toBe ( historyItems )
178- expect ( mockGlobalState . get ) . toHaveBeenCalledWith ( "taskHistory" )
179- } )
180133 } )
181134
182135 describe ( "getSecret" , ( ) => {
@@ -391,6 +344,16 @@ describe("ContextProxy", () => {
391344 expect ( mockGlobalState . update ) . toHaveBeenCalledTimes ( expectedUpdateCalls )
392345 } )
393346
347+ it ( "should update all workspace state keys to undefined" , async ( ) => {
348+ // Reset all state
349+ await proxy . resetAllState ( )
350+
351+ // Should have called update with undefined for each workspace key
352+ for ( const key of WORKSPACE_SETTINGS_KEYS ) {
353+ expect ( mockWorkspaceState . update ) . toHaveBeenCalledWith ( key , undefined )
354+ }
355+ } )
356+
394357 it ( "should delete all secrets" , async ( ) => {
395358 // Setup initial secrets
396359 await proxy . storeSecret ( "apiKey" , "test-api-key" )
0 commit comments