mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
chore: treat extension .env as optional (#11116)
This commit is contained in:
parent
946ae80561
commit
20d1f1f282
2 changed files with 47 additions and 7 deletions
|
|
@ -46,6 +46,11 @@ vi.mock("@dotenvx/dotenvx", () => ({
|
|||
config: vi.fn(),
|
||||
}))
|
||||
|
||||
// Mock fs so the extension module can safely check for optional .env.
|
||||
vi.mock("fs", () => ({
|
||||
existsSync: vi.fn().mockReturnValue(false),
|
||||
}))
|
||||
|
||||
const mockBridgeOrchestratorDisconnect = vi.fn().mockResolvedValue(undefined)
|
||||
|
||||
const mockCloudServiceInstance = {
|
||||
|
|
@ -238,6 +243,36 @@ describe("extension.ts", () => {
|
|||
authStateChangedHandler = undefined
|
||||
})
|
||||
|
||||
test("does not call dotenvx.config when optional .env does not exist", async () => {
|
||||
vi.resetModules()
|
||||
vi.clearAllMocks()
|
||||
|
||||
const fs = await import("fs")
|
||||
vi.mocked(fs.existsSync).mockReturnValue(false)
|
||||
|
||||
const dotenvx = await import("@dotenvx/dotenvx")
|
||||
|
||||
const { activate } = await import("../extension")
|
||||
await activate(mockContext)
|
||||
|
||||
expect(dotenvx.config).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test("calls dotenvx.config when optional .env exists", async () => {
|
||||
vi.resetModules()
|
||||
vi.clearAllMocks()
|
||||
|
||||
const fs = await import("fs")
|
||||
vi.mocked(fs.existsSync).mockReturnValue(true)
|
||||
|
||||
const dotenvx = await import("@dotenvx/dotenvx")
|
||||
|
||||
const { activate } = await import("../extension")
|
||||
await activate(mockContext)
|
||||
|
||||
expect(dotenvx.config).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test("authStateChangedHandler calls BridgeOrchestrator.disconnect when logged-out event fires", async () => {
|
||||
const { CloudService, BridgeOrchestrator } = await import("@roo-code/cloud")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,20 @@
|
|||
import * as vscode from "vscode"
|
||||
import * as dotenvx from "@dotenvx/dotenvx"
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
|
||||
// Load environment variables from .env file
|
||||
try {
|
||||
// Specify path to .env file in the project root directory
|
||||
const envPath = path.join(__dirname, "..", ".env")
|
||||
dotenvx.config({ path: envPath })
|
||||
} catch (e) {
|
||||
// Silently handle environment loading errors
|
||||
console.warn("Failed to load environment variables:", e)
|
||||
// The extension-level .env is optional (not shipped in production builds).
|
||||
// Avoid calling dotenvx when the file doesn't exist, otherwise dotenvx emits
|
||||
// a noisy [MISSING_ENV_FILE] error to the extension host console.
|
||||
const envPath = path.join(__dirname, "..", ".env")
|
||||
if (fs.existsSync(envPath)) {
|
||||
try {
|
||||
dotenvx.config({ path: envPath })
|
||||
} catch (e) {
|
||||
// Best-effort only: never fail extension activation due to optional env loading.
|
||||
console.warn("Failed to load environment variables:", e)
|
||||
}
|
||||
}
|
||||
|
||||
import type { CloudUserInfo, AuthState } from "@roo-code/types"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue