test(credential_pool): align with .env-first seed precedence - #19021
Closed
Sanjays2402 wants to merge 1 commit into
Closed
Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
`_seed_from_env` was intentionally flipped to prefer `~/.hermes/.env` over `os.environ` in commit 2ef1ad2 ("fix: prefer ~/.hermes/.env over os.environ when seeding credential pool", fixes NousResearch#18254). That change introduced a private `_get_env_prefer_dotenv` helper and stopped using `get_env_value` (which is os.environ-first). The unit test `test_os_environ_still_wins_over_dotenv` was written for the **old** `get_env_value`-based behaviour (predates 2ef1ad2) and was never updated, so it failed on `main`: AssertionError: assert 'sk-dotenv-stale' == 'sk-env-fresh-xyz' Rename + rewrite to assert the **current**, deliberate behaviour: `.env` wins over `os.environ`, with a docstring explaining *why* (stale shell env vars from parent processes like Codex CLI shadowing deliberate user edits to .env, leading to cached 401s in auth.json). The cousin `Auth*` tests below already exercise os.environ-first semantics for `_resolve_api_key_provider_secret` (which still uses `get_env_value`), so the two precedence policies are now both pinned. Validation: $ pytest tests/tools/test_credential_pool_env_fallback.py -q 9 passed in 1.59s No production code change. Fixes the failure observed on `main` (run 25250051126): `tests/tools/test_credential_pool_env_fallback.py::TestCredentialPoolSeedsFromDotEnv::test_os_environ_still_wins_over_dotenv` Refs: NousResearch#18254 (precedence flip), NousResearch#18757 (cousin os.getenv \u2192 get_env_value fix on `auth.py` base_url path).
Collaborator
|
This looks implemented on current Automated hermes-sweeper review evidence:
Thanks for identifying the stale assertion; the same contract is now covered on main, so this PR is safe to close as already implemented. |
This was referenced Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes one
Testsfailure observed onmain(and therefore propagating to every open PR):Reference run: 25250051126 on
5d3be898a.Root cause
The test docstring says:
…which was true for
_seed_from_envuntil commit 2ef1ad280 ("fix: prefer ~/.hermes/.env over os.environ when seeding credential pool", fixes #18254). That commit introduced a private_get_env_prefer_dotenvhelper and deliberately flipped the precedence:The fix was correct (#18254 reported real users hitting silent 401s with stale
auth.jsoncaches), but the unit test was never updated to match.Fix
Rename + rewrite the test to assert the current, deliberate behaviour:
.envwins overos.environ, with a docstring explaining why (stale shell env vars from parent processes shadowing deliberate.envedits, leading to cached 401s inauth.json).The cousin
Auth*tests below already exerciseos.environ-first semantics for_resolve_api_key_provider_secret(which still usesget_env_value), so the two precedence policies are both pinned now.Validation
Refs
os.getenv→get_env_valuefix onauth.pybase_url pathScope
Out of scope
The other ~10 main-CI failures — separate focused PRs (#18972, #18974, #18977, #18979 already up).