mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-10-25 17:36:29 +08:00
fix(bash): skip dotenv entries without values
This commit is contained in:
1 parent
5f54fc5beb
commit
faa554ea31
3 files changed
+34
-1
No files matched your search
@@ -202,7 +202,7 @@ SAFETY:
|
||||
if os.path.exists(env_file):
|
||||
try:
|
||||
from dotenv import dotenv_values
|
||||
dotenv_vars = dotenv_values(env_file)
|
||||
dotenv_vars = {key: value for key, value in dotenv_values(env_file).items() if value is not None}
|
||||
env.update(dotenv_vars)
|
||||
logger.debug(f"[Bash] Loaded {len(dotenv_vars)} variables from {env_file}")
|
||||
except ImportError:
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# ADR 013: fix(bash): skip dotenv entries without values
|
||||
|
||||
## Context
|
||||
|
||||
A valid dotenv line containing only a key is parsed as None. Injecting it into the subprocess environment makes every shell command fail with a TypeError.
|
||||
|
||||
## Decision
|
||||
|
||||
Forward only assigned dotenv values, retaining an inherited environment value when the dotenv entry has no assignment.
|
||||
|
||||
## Consequences
|
||||
|
||||
Empty assigned values remain valid and override inheritance. Bare declarations no longer prevent command execution.
|
||||
|
||||
## Acceptance
|
||||
|
||||
The regression in `tests/test_cow32_bash_bare_dotenv.py` fails on `5f54fc5beb55e522091ebfbe3a11aece9bb7d502` and passes with this decision. Related existing tests must pass. Validation uses local fixtures without external services or model calls.
|
||||
@@ -0,0 +1,16 @@
|
||||
import sys
|
||||
from agent.tools.bash.bash import Bash
|
||||
|
||||
def test_bare_dotenv_key_does_not_break_native_shell(tmp_path, monkeypatch):
|
||||
home = tmp_path / "home"
|
||||
folder = home / ".cow"
|
||||
folder.mkdir(parents=True)
|
||||
(folder / ".env").write_text("COW_BARE_KEY\nCOW_EMPTY_KEY=\n")
|
||||
monkeypatch.setenv("HOME", str(home))
|
||||
monkeypatch.setenv("USERPROFILE", str(home))
|
||||
monkeypatch.setenv("COW_BARE_KEY", "inherited")
|
||||
monkeypatch.setenv("COW_EMPTY_KEY", "old")
|
||||
command = f"{sys.executable} -c \"import os; print(os.environ['COW_BARE_KEY'] + ':' + os.environ['COW_EMPTY_KEY'])\""
|
||||
result = Bash({"cwd": str(tmp_path)}).execute({"command": command})
|
||||
assert result.status == "success", result.result
|
||||
assert "inherited:" in result.result["output"]
|
||||
Reference in new issue
Block a user