fix: prevent Test ErrorBoundary access in production mode

- Fixed sourceMapInitializer.ts to only expose debugging functions in development mode
- Previously, __testSourceMaps function was exposed in production, allowing users to trigger errors
- Added comprehensive tests to verify debugging functions are not exposed in production
- Resolves issue where users could access Test ErrorBoundary functionality in production builds

Fixes #6335
This commit is contained in:
Roo Code 2025-07-29 06:21:46 +00:00
parent 00a3738d30
commit 59aed9aad8
2 changed files with 83 additions and 1 deletions

View file

@ -0,0 +1,82 @@
import { exposeSourceMapsForDebugging } from "../sourceMapInitializer"
describe("sourceMapInitializer", () => {
describe("exposeSourceMapsForDebugging", () => {
let originalNodeEnv: string | undefined
beforeEach(() => {
originalNodeEnv = process.env.NODE_ENV
// Clear any existing debugging functions
delete (window as any).__testSourceMaps
delete (window as any).__applySourceMaps
delete (window as any).__checkSourceMap
})
afterEach(() => {
process.env.NODE_ENV = originalNodeEnv
// Clean up any debugging functions
delete (window as any).__testSourceMaps
delete (window as any).__applySourceMaps
delete (window as any).__checkSourceMap
})
it("should not expose debugging functions in production mode", () => {
// Set production mode
process.env.NODE_ENV = "production"
// Call the function
exposeSourceMapsForDebugging()
// Verify that debugging functions are NOT exposed
expect((window as any).__testSourceMaps).toBeUndefined()
expect((window as any).__applySourceMaps).toBeUndefined()
expect((window as any).__checkSourceMap).toBeUndefined()
})
it("should expose debugging functions in development mode", () => {
// Set development mode
process.env.NODE_ENV = "development"
// Call the function
exposeSourceMapsForDebugging()
// Verify that debugging functions ARE exposed
expect((window as any).__testSourceMaps).toBeDefined()
expect((window as any).__applySourceMaps).toBeDefined()
expect((window as any).__checkSourceMap).toBeDefined()
expect(typeof (window as any).__testSourceMaps).toBe("function")
expect(typeof (window as any).__applySourceMaps).toBe("function")
expect(typeof (window as any).__checkSourceMap).toBe("function")
})
it("should expose debugging functions in test mode", () => {
// Set test mode
process.env.NODE_ENV = "test"
// Call the function
exposeSourceMapsForDebugging()
// Verify that debugging functions ARE exposed
expect((window as any).__testSourceMaps).toBeDefined()
expect((window as any).__applySourceMaps).toBeDefined()
expect((window as any).__checkSourceMap).toBeDefined()
})
it("should not throw errors when called multiple times in production", () => {
// Set production mode
process.env.NODE_ENV = "production"
// Should not throw when called multiple times
expect(() => {
exposeSourceMapsForDebugging()
exposeSourceMapsForDebugging()
exposeSourceMapsForDebugging()
}).not.toThrow()
// Functions should still not be exposed
expect((window as any).__testSourceMaps).toBeUndefined()
expect((window as any).__applySourceMaps).toBeUndefined()
expect((window as any).__checkSourceMap).toBeUndefined()
})
})
})

View file

@ -113,7 +113,7 @@ export function initializeSourceMaps(): void {
* Expose source maps on the window object for debugging
*/
export function exposeSourceMapsForDebugging(): void {
if (process.env.NODE_ENV !== "production") {
if (process.env.NODE_ENV === "production") {
return
}