mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-17 15:20:11 +02:00
refactor: extract pure promotedEnv() from conductor-env-shim
Single source of truth for GSTACK_* key promotion semantics. The ambient promoteConductorEnv() becomes a wrapper; behavior-preserving. Needed by the hermetic env builder which must not mutate process.env. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,12 +7,30 @@
|
||||
*
|
||||
* Import this for its side effect: `import "../lib/conductor-env-shim";`
|
||||
*/
|
||||
export function promoteConductorEnv(): void {
|
||||
for (const key of ["ANTHROPIC_API_KEY", "OPENAI_API_KEY"] as const) {
|
||||
if (!process.env[key] && process.env[`GSTACK_${key}`]) {
|
||||
process.env[key] = process.env[`GSTACK_${key}`];
|
||||
const PROMOTED_KEYS = ["ANTHROPIC_API_KEY", "OPENAI_API_KEY"] as const;
|
||||
|
||||
/**
|
||||
* Pure form: returns a copy of `base` with each GSTACK_-prefixed key promoted
|
||||
* to its canonical name when the canonical is empty. Single source of truth
|
||||
* for promotion semantics — used by the ambient mutator below and by the
|
||||
* hermetic env builder (test/helpers/hermetic-env.ts), which must not mutate
|
||||
* process.env.
|
||||
*/
|
||||
export function promotedEnv(base: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
||||
const out: NodeJS.ProcessEnv = { ...base };
|
||||
for (const key of PROMOTED_KEYS) {
|
||||
if (!out[key] && out[`GSTACK_${key}`]) {
|
||||
out[key] = out[`GSTACK_${key}`];
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function promoteConductorEnv(): void {
|
||||
const promoted = promotedEnv(process.env);
|
||||
for (const key of PROMOTED_KEYS) {
|
||||
if (promoted[key]) process.env[key] = promoted[key];
|
||||
}
|
||||
}
|
||||
|
||||
promoteConductorEnv();
|
||||
|
||||
Reference in New Issue
Block a user