opencommit
opencommit copied to clipboard
fix: resolve test conflicts with .env environment variables
trafficstars
This PR fixes test failures caused by environment variables from the user's .env file interfering with test expectations.
Changes Made
- Jest Global Hooks: Added
globalSetupandglobalTeardownto backup and restore the .env file during testing - Environment Variable Cleanup: Clear OCO_ environment variables during test execution to prevent interference
- Test Environment Reset: Modified the test's
resetEnvfunction to avoid restoring OCO_ environment variables
Problem Solved
Previously, when users had OCO_ environment variables set in their .env file (like OCO_MODEL=gpt-5-mini, OCO_TOKENS_MAX_OUTPUT=8192), these would override the expected default values in tests, causing failures.
Solution
The fix ensures that:
- The .env file is temporarily backed up during test runs
- OCO_ environment variables are cleared from process.env
- Tests run with clean, predictable defaults
- The .env file is restored after testing
This maintains backward compatibility while ensuring reliable test execution.