Skip to content

fix: resolve test conflicts with .env environment variables - #526

Merged
di-sukharev merged 3 commits into
di-sukharev:masterfrom
cometjc:fix/test-env-conflict
Sep 9, 2026
Merged

di-sukharev merged 3 commits into
di-sukharev:masterfrom
cometjc:fix/test-env-conflict

Conversation

@cometjc

@cometjc cometjc commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

Configuration unit tests could pick up a developer's OCO_* environment variables and working-directory .env, causing default and persistence assertions to fail.

The suite now starts each test with the ambient OCO_* variables cleared and loads the config module with a temporary default .env path. Explicit fixture paths still exercise local/global precedence, and the original working directory and environment are restored. No user configuration files are renamed or edited.

The existing reasoning-token validation test now imports the real validator and checks its exit status, fixing an assertion that previously passed on a missing-import ReferenceError.

Validation: lint/typecheck and formatting passed; all 184 unit tests passed. Running the config suite from a disposable directory containing a conflicting .env, with additional OCO_* shell variables set, now passes all 19 tests (four failed before the follow-up).

@di-sukharev di-sukharev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test reproducibility problem is real, but moving the actual .env file from global setup is unsafe. Please isolate the tests through temporary paths or explicit environment values without modifying the user file.

Comment thread test/jest-global-setup.ts Outdated
- Add Jest global setup/teardown hooks to backup and restore .env file
- Clear OCO_ environment variables during test execution
- Modify test resetEnv function to prevent OCO_ env vars from interfering
- Prevent .env file from interfering with test expectations

This fixes the issue where tests were failing due to environment variables
from the user's .env file overriding the expected default config values.
@cometjc
cometjc force-pushed the fix/test-env-conflict branch from 2feaf1b to 2073a37 Compare September 4, 2026 07:46

@di-sukharev di-sukharev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for removing the setup/teardown that moved the working .env file. I finished the remaining isolation gap: calls relying on the default env path, including setConfig, now read a temporary fixture in this test suite. I also fixed the existing validator test so it checks the actual exit behavior instead of passing on a ReferenceError.

Verified all 184 unit tests, lint/typecheck, and formatting, plus a separate run with a conflicting .env and ambient OCO_* values: all 19 config tests pass. The change is confined to the config test file and is ready to merge once the updated CI checks pass.

@di-sukharev
di-sukharev merged commit 250d49a into di-sukharev:master Sep 9, 2026
5 checks passed
@di-sukharev

Copy link
Copy Markdown
Owner

All done and merged into master. Thanks for addressing the review and for the contribution!

I added a small follow-up to isolate the default .env path used by setConfig as well, and corrected an existing validator test that was passing on a missing-import error. All 184 unit tests and the GitHub checks passed; I also verified the config suite with a conflicting .env and OCO_* shell variables. No user configuration files are moved or modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants