MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / loadCliEnv

Function loadCliEnv

cli/src/__tests__/test-utils.ts:113–147  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

111}
112
113function loadCliEnv(): Record<string, string> {
114 if (cachedEnv) {
115 return cachedEnv
116 }
117
118 try {
119 ensureCliEnvDefaults()
120 // NOTE: Inline require() is used for lazy loading - the env module depends on
121 // Infisical secrets which may not be available at module load time in test environments
122 const { env } = require('../../../packages/internal/src/env') as {
123 env: Record<string, unknown>
124 }
125
126 cachedEnv = Object.entries(env).reduce<Record<string, string>>(
127 (acc, [key, value]) => {
128 if (value !== undefined && value !== null) {
129 acc[key] = String(value)
130 }
131 return acc
132 },
133 {},
134 )
135
136 return cachedEnv
137 } catch (error) {
138 const message =
139 error instanceof Error
140 ? error.message
141 : 'unknown error loading environment'
142 throw new Error(
143 `Failed to load CLI environment via packages/internal/src/env: ${message}. ` +
144 'Run commands via "infisical run -- bun …" or export the required variables.',
145 )
146 }
147}
148
149export function ensureCliTestEnv(): void {
150 loadCliEnv()

Callers 2

ensureCliTestEnvFunction · 0.85
getDefaultCliEnvFunction · 0.85

Calls 1

ensureCliEnvDefaultsFunction · 0.85

Tested by

no test coverage detected