Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 15b0124

Browse files
committed
feat: add cloud environment detection utilities (CLO-646)
- Add cloud-environment.ts with utilities to detect cloud and preview environments - Add isCloudEnvironment() to check if running in Roo Code Cloud - Add getAppEnvironment() to get the app environment (development/preview/production) - Add isPreviewEnvironment(), isProductionEnvironment(), isDevelopmentEnvironment() helpers - Add comprehensive tests for all utilities This enables features to behave differently based on the cloud deployment environment, such as detecting preview environments.
1 parent f5004ac commit 15b0124

2 files changed

Lines changed: 181 additions & 0 deletions

File tree

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import {
2+
isCloudEnvironment,
3+
getAppEnvironment,
4+
isPreviewEnvironment,
5+
isProductionEnvironment,
6+
isDevelopmentEnvironment,
7+
} from "../cloud-environment"
8+
9+
describe("cloud-environment", () => {
10+
const originalEnv = process.env
11+
12+
beforeEach(() => {
13+
// Reset process.env before each test
14+
vi.resetModules()
15+
process.env = { ...originalEnv }
16+
})
17+
18+
afterAll(() => {
19+
// Restore original process.env after all tests
20+
process.env = originalEnv
21+
})
22+
23+
describe("isCloudEnvironment", () => {
24+
it("should return true when ROO_CODE_IPC_SOCKET_PATH is set", () => {
25+
process.env.ROO_CODE_IPC_SOCKET_PATH = "/tmp/test.sock"
26+
expect(isCloudEnvironment()).toBe(true)
27+
})
28+
29+
it("should return false when ROO_CODE_IPC_SOCKET_PATH is not set", () => {
30+
delete process.env.ROO_CODE_IPC_SOCKET_PATH
31+
expect(isCloudEnvironment()).toBe(false)
32+
})
33+
34+
it("should return false when ROO_CODE_IPC_SOCKET_PATH is undefined", () => {
35+
process.env.ROO_CODE_IPC_SOCKET_PATH = undefined as any
36+
expect(isCloudEnvironment()).toBe(false)
37+
})
38+
})
39+
40+
describe("getAppEnvironment", () => {
41+
it('should return "development" when ROO_CODE_APP_ENV is development', () => {
42+
process.env.ROO_CODE_APP_ENV = "development"
43+
expect(getAppEnvironment()).toBe("development")
44+
})
45+
46+
it('should return "preview" when ROO_CODE_APP_ENV is preview', () => {
47+
process.env.ROO_CODE_APP_ENV = "preview"
48+
expect(getAppEnvironment()).toBe("preview")
49+
})
50+
51+
it('should return "production" when ROO_CODE_APP_ENV is production', () => {
52+
process.env.ROO_CODE_APP_ENV = "production"
53+
expect(getAppEnvironment()).toBe("production")
54+
})
55+
56+
it("should return undefined when ROO_CODE_APP_ENV is not set", () => {
57+
delete process.env.ROO_CODE_APP_ENV
58+
expect(getAppEnvironment()).toBeUndefined()
59+
})
60+
61+
it("should return undefined when ROO_CODE_APP_ENV has invalid value", () => {
62+
process.env.ROO_CODE_APP_ENV = "invalid"
63+
expect(getAppEnvironment()).toBeUndefined()
64+
})
65+
})
66+
67+
describe("isPreviewEnvironment", () => {
68+
it('should return true when ROO_CODE_APP_ENV is "preview"', () => {
69+
process.env.ROO_CODE_APP_ENV = "preview"
70+
expect(isPreviewEnvironment()).toBe(true)
71+
})
72+
73+
it('should return false when ROO_CODE_APP_ENV is "production"', () => {
74+
process.env.ROO_CODE_APP_ENV = "production"
75+
expect(isPreviewEnvironment()).toBe(false)
76+
})
77+
78+
it('should return false when ROO_CODE_APP_ENV is "development"', () => {
79+
process.env.ROO_CODE_APP_ENV = "development"
80+
expect(isPreviewEnvironment()).toBe(false)
81+
})
82+
83+
it("should return false when ROO_CODE_APP_ENV is not set", () => {
84+
delete process.env.ROO_CODE_APP_ENV
85+
expect(isPreviewEnvironment()).toBe(false)
86+
})
87+
})
88+
89+
describe("isProductionEnvironment", () => {
90+
it('should return true when ROO_CODE_APP_ENV is "production"', () => {
91+
process.env.ROO_CODE_APP_ENV = "production"
92+
expect(isProductionEnvironment()).toBe(true)
93+
})
94+
95+
it('should return false when ROO_CODE_APP_ENV is "preview"', () => {
96+
process.env.ROO_CODE_APP_ENV = "preview"
97+
expect(isProductionEnvironment()).toBe(false)
98+
})
99+
100+
it("should return false when ROO_CODE_APP_ENV is not set", () => {
101+
delete process.env.ROO_CODE_APP_ENV
102+
expect(isProductionEnvironment()).toBe(false)
103+
})
104+
})
105+
106+
describe("isDevelopmentEnvironment", () => {
107+
it('should return true when ROO_CODE_APP_ENV is "development"', () => {
108+
process.env.ROO_CODE_APP_ENV = "development"
109+
expect(isDevelopmentEnvironment()).toBe(true)
110+
})
111+
112+
it('should return false when ROO_CODE_APP_ENV is "production"', () => {
113+
process.env.ROO_CODE_APP_ENV = "production"
114+
expect(isDevelopmentEnvironment()).toBe(false)
115+
})
116+
117+
it("should return false when ROO_CODE_APP_ENV is not set", () => {
118+
delete process.env.ROO_CODE_APP_ENV
119+
expect(isDevelopmentEnvironment()).toBe(false)
120+
})
121+
})
122+
})

src/shared/cloud-environment.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Cloud environment detection utilities.
3+
*
4+
* These utilities help detect when the extension is running in a cloud
5+
* environment (Roo Code Cloud) and determine the deployment environment
6+
* (development, preview, production).
7+
*/
8+
9+
/**
10+
* Possible app environment values.
11+
* - 'development': Local development environment
12+
* - 'preview': Preview/staging environment (e.g., Vercel preview deployments)
13+
* - 'production': Production environment
14+
*/
15+
export type AppEnvironment = "development" | "preview" | "production"
16+
17+
/**
18+
* Checks if the extension is running in Roo Code Cloud.
19+
* This is determined by the presence of the ROO_CODE_IPC_SOCKET_PATH environment variable,
20+
* which is set by the cloud worker when spawning VS Code.
21+
*/
22+
export function isCloudEnvironment(): boolean {
23+
return typeof process.env.ROO_CODE_IPC_SOCKET_PATH === "string"
24+
}
25+
26+
/**
27+
* Gets the app environment (development, preview, or production).
28+
* This is determined by the ROO_CODE_APP_ENV environment variable set by the cloud worker.
29+
* Returns undefined if not running in a cloud environment or if the variable is not set.
30+
*/
31+
export function getAppEnvironment(): AppEnvironment | undefined {
32+
const appEnv = process.env.ROO_CODE_APP_ENV
33+
if (appEnv === "development" || appEnv === "preview" || appEnv === "production") {
34+
return appEnv
35+
}
36+
return undefined
37+
}
38+
39+
/**
40+
* Checks if the extension is running in a preview environment.
41+
* Preview environments are typically used for testing features before production.
42+
*/
43+
export function isPreviewEnvironment(): boolean {
44+
return getAppEnvironment() === "preview"
45+
}
46+
47+
/**
48+
* Checks if the extension is running in a production environment.
49+
*/
50+
export function isProductionEnvironment(): boolean {
51+
return getAppEnvironment() === "production"
52+
}
53+
54+
/**
55+
* Checks if the extension is running in a development environment.
56+
*/
57+
export function isDevelopmentEnvironment(): boolean {
58+
return getAppEnvironment() === "development"
59+
}

0 commit comments

Comments
 (0)