Skip to content

Commit a77a378

Browse files
anticomputerCopilot
andcommitted
Return an empty list for an empty env in _env_names
Check `env is None` so an empty dict yields `[]` rather than the dict, honoring the list[str] | None return contract. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 03cf307 commit a77a378

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/seclab_taskflow_agent/mcp_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def _env_names(env: dict[str, Any] | None) -> list[str] | None:
179179
their values must never be written to logs. Callers log the names to keep
180180
debug output useful without leaking secrets.
181181
"""
182-
return sorted(env) if env else env
182+
return sorted(env) if env is not None else None
183183

184184

185185
def mcp_client_params(

tests/test_mcp_utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212

1313
import pytest
1414

15-
from seclab_taskflow_agent.mcp_utils import MCPNamespaceWrap, compress_name, mcp_client_params
15+
from seclab_taskflow_agent.mcp_utils import (
16+
MCPNamespaceWrap,
17+
_env_names,
18+
compress_name,
19+
mcp_client_params,
20+
)
1621

1722

1823
class _FakeTool:
@@ -183,3 +188,11 @@ def test_mcp_client_params_logs_env_names_not_secret_values(monkeypatch, caplog)
183188
# Redaction is log-only: the real env (with the resolved secret) is still
184189
# passed through to the MCP server.
185190
assert params["pkg.tb"][0]["env"]["GH_TOKEN"] == sentinel
191+
192+
193+
def test_env_names_returns_sorted_names_or_none():
194+
# Non-empty env -> sorted names; empty dict -> empty list; None -> None
195+
# (honouring the list[str] | None contract, never leaking values).
196+
assert _env_names({"B_VAR": "x", "A_VAR": "{{ env('A') }}"}) == ["A_VAR", "B_VAR"]
197+
assert _env_names({}) == []
198+
assert _env_names(None) is None

0 commit comments

Comments
 (0)