@@ -46,6 +46,11 @@ vi.mock("@dotenvx/dotenvx", () => ({
4646 config : vi . fn ( ) ,
4747} ) )
4848
49+ // Mock fs so the extension module can safely check for optional .env.
50+ vi . mock ( "fs" , ( ) => ( {
51+ existsSync : vi . fn ( ) . mockReturnValue ( false ) ,
52+ } ) )
53+
4954const mockBridgeOrchestratorDisconnect = vi . fn ( ) . mockResolvedValue ( undefined )
5055
5156const mockCloudServiceInstance = {
@@ -239,6 +244,36 @@ describe("extension.ts", () => {
239244 authStateChangedHandler = undefined
240245 } )
241246
247+ test ( "does not call dotenvx.config when optional .env does not exist" , async ( ) => {
248+ vi . resetModules ( )
249+ vi . clearAllMocks ( )
250+
251+ const fs = await import ( "fs" )
252+ vi . mocked ( fs . existsSync ) . mockReturnValue ( false )
253+
254+ const dotenvx = await import ( "@dotenvx/dotenvx" )
255+
256+ const { activate } = await import ( "../extension" )
257+ await activate ( mockContext )
258+
259+ expect ( dotenvx . config ) . not . toHaveBeenCalled ( )
260+ } )
261+
262+ test ( "calls dotenvx.config when optional .env exists" , async ( ) => {
263+ vi . resetModules ( )
264+ vi . clearAllMocks ( )
265+
266+ const fs = await import ( "fs" )
267+ vi . mocked ( fs . existsSync ) . mockReturnValue ( true )
268+
269+ const dotenvx = await import ( "@dotenvx/dotenvx" )
270+
271+ const { activate } = await import ( "../extension" )
272+ await activate ( mockContext )
273+
274+ expect ( dotenvx . config ) . toHaveBeenCalledTimes ( 1 )
275+ } )
276+
242277 test ( "authStateChangedHandler calls BridgeOrchestrator.disconnect when logged-out event fires" , async ( ) => {
243278 const { CloudService, BridgeOrchestrator } = await import ( "@roo-code/cloud" )
244279
0 commit comments