fix: resolve test conflicts with .env environment variables - #526
Conversation
- 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.
2feaf1b to
2073a37
Compare
di-sukharev
left a comment
There was a problem hiding this comment.
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.
|
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. |
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.envpath. 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 additionalOCO_*shell variables set, now passes all 19 tests (four failed before the follow-up).