fix(env): strip export prefix in dotenv key scan for cleanup (review fix)
This commit is contained in:
parent
968b66338c
commit
61b2fa7937
|
|
@ -84,6 +84,8 @@ def _env_keys_defined_in_dotenv(path: Path) -> set[str]:
|
|||
line = line.strip()
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
if line.startswith("export "):
|
||||
line = line[7:]
|
||||
key = line.split("=", 1)[0].strip()
|
||||
if key:
|
||||
keys.add(key)
|
||||
|
|
|
|||
|
|
@ -265,3 +265,19 @@ def test_known_key_explicitly_set_in_user_env_is_kept(tmp_path, monkeypatch):
|
|||
load_hermes_dotenv(hermes_home=home)
|
||||
|
||||
assert os.getenv("HERMES_ACP_AUTH_METHOD") == "claude_code_cli"
|
||||
|
||||
|
||||
def test_export_prefixed_known_key_in_user_env_is_kept(tmp_path, monkeypatch):
|
||||
"""A known Hermes key defined with the bash-compatible ``export KEY=value``
|
||||
form in the profile .env must be recognized as defined and survive the
|
||||
cleanup - mirrors the ``export `` stripping in config.py's load_env()
|
||||
(#6659).
|
||||
"""
|
||||
home = tmp_path / "hermes"
|
||||
home.mkdir()
|
||||
(home / ".env").write_text(
|
||||
"export HERMES_ACP_AUTH_METHOD=claude_code_cli\n", encoding="utf-8"
|
||||
)
|
||||
monkeypatch.setenv("HERMES_ACP_AUTH_METHOD", "cursor_login")
|
||||
load_hermes_dotenv(hermes_home=home)
|
||||
assert os.getenv("HERMES_ACP_AUTH_METHOD") == "claude_code_cli"
|
||||
|
|
|
|||
Loading…
Reference in New Issue