fix(env): strip export prefix in dotenv key scan for cleanup (review fix)

This commit is contained in:
keepConcentration 2026-07-31 15:35:21 +09:00 committed by Teknium
parent 968b66338c
commit 61b2fa7937
2 changed files with 18 additions and 0 deletions

View File

@ -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)

View File

@ -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"