import fs from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; import { afterEach, describe, expect, it } from 'vitest'; import { loadEnv } from '../src/env.js'; const loadedKey = 'OPENCODE_PROXY_TEST_ENV_LOADED'; const existingKey = 'OPENCODE_PROXY_TEST_ENV_EXISTING'; afterEach(() => { delete process.env[loadedKey]; delete process.env[existingKey]; }); describe('.env loading', () => { it('loads values without overriding the process environment', async () => { const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'opencode-proxy-env-')); const envPath = path.join(directory, '.env'); await fs.writeFile(envPath, `${loadedKey}=from-file\n${existingKey}=from-file\n`); process.env[existingKey] = 'from-process'; try { loadEnv(envPath); expect(process.env[loadedKey]).toBe('from-file'); expect(process.env[existingKey]).toBe('from-process'); } finally { await fs.rm(directory, { recursive: true, force: true }); } }); });