opencommit icon indicating copy to clipboard operation
opencommit copied to clipboard

fix: resolve test conflicts with .env environment variables

Open jcppkkk opened this issue 3 weeks ago • 0 comments
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 globalSetup and globalTeardown to 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 resetEnv function 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:

  1. The .env file is temporarily backed up during test runs
  2. OCO_ environment variables are cleared from process.env
  3. Tests run with clean, predictable defaults
  4. The .env file is restored after testing

This maintains backward compatibility while ensuring reliable test execution.

jcppkkk avatar Oct 31 '25 03:10 jcppkkk