Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/chainlit/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ async def resume_thread(session: WebsocketSession):


def load_user_env(user_env):
user_env_dict = {}
if user_env:
user_env_dict = json.loads(user_env)
# Check user env
Expand Down
14 changes: 6 additions & 8 deletions backend/tests/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,21 +403,19 @@ def test_load_user_env_none_with_required_keys(self):
with patch("chainlit.socket.config") as mock_config:
mock_config.project.user_env = ["API_KEY"]

# The function has a bug - it raises UnboundLocalError instead of ConnectionRefusedError
# Python 3.10: "referenced before assignment"
# Python 3.11+: "cannot access local variable"
with pytest.raises(UnboundLocalError, match="user_env_dict"):
with pytest.raises(
ConnectionRefusedError, match="Missing user environment variables"
):
load_user_env(None)

def test_load_user_env_none_without_required_keys(self):
"""Test when user_env is None and no keys are required."""
with patch("chainlit.socket.config") as mock_config:
mock_config.project.user_env = []

# The function has a bug - it raises NameError when user_env is None
# even when no required keys are configured
with pytest.raises(NameError, match="user_env_dict"):
load_user_env(None)
result = load_user_env(None)

assert result == {}


class TestCleanSession:
Expand Down
Loading