Skip to content

Commit ed03d09

Browse files
committed
♻️ Translate error messages and fix test cases
1 parent e791ac7 commit ed03d09

File tree

2 files changed

+66
-8
lines changed

2 files changed

+66
-8
lines changed

backend/agents/create_agent_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async def create_agent_config(
7979
is_manager=len(managed_agents) > 0, language=language)
8080

8181
# Get app information
82-
default_app_description = 'Nexent is an open-source agent SDK and platform' if language == 'en' else 'Nexent 是一个开源智能体SDK和平台'
82+
default_app_description = 'Nexent 是一个开源智能体SDK和平台' if language == 'zh' else 'Nexent is an open-source agent SDK and platform'
8383
app_name = tenant_config_manager.get_app_config(
8484
'APP_NAME', tenant_id=tenant_id) or "Nexent"
8585
app_description = tenant_config_manager.get_app_config(
@@ -132,7 +132,7 @@ async def create_agent_config(
132132
f"Failed to get summary for knowledge base {knowledge_name}: {e}")
133133
else:
134134
# TODO: Prompt should be refactored to yaml file
135-
knowledge_base_summary = "No knowledge base indexes are currently available.\n" if language == 'en' else "当前没有可用的知识库索引。\n"
135+
knowledge_base_summary = "当前没有可用的知识库索引。\n" if language == 'zh' else "No knowledge base indexes are currently available.\n"
136136
break # Only process the first KnowledgeBaseSearchTool found
137137
except Exception as e:
138138
logger.error(f"Failed to build knowledge base summary: {e}")

test/backend/utils/test_auth_utils.py

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from backend.consts.exceptions import UnauthorizedError, SignatureValidationError
2+
from utils import auth_utils as au
13
import time
24
import sys
35
from unittest.mock import MagicMock
@@ -22,12 +24,11 @@
2224
sys.modules['database.client'] = db_client_stub
2325

2426
# Stub database.user_tenant_db to avoid real DB interactions
25-
sys.modules['database.user_tenant_db'] = MagicMock(get_user_tenant_by_user_id=MagicMock(return_value=None))
27+
sys.modules['database.user_tenant_db'] = MagicMock(
28+
get_user_tenant_by_user_id=MagicMock(return_value=None))
2629

27-
from utils import auth_utils as au
2830

2931
# After auth_utils import succeeds, bring in real exception classes for clarity.
30-
from backend.consts.exceptions import UnauthorizedError, SignatureValidationError
3132

3233
# Pre-mock nexent core dependency pulled by consts.model
3334
sys.modules['consts'] = MagicMock()
@@ -52,8 +53,10 @@
5253

5354

5455
def test_calculate_hmac_signature_stability():
55-
sig1 = au.calculate_hmac_signature("secret", "access", "1234567890", "body")
56-
sig2 = au.calculate_hmac_signature("secret", "access", "1234567890", "body")
56+
sig1 = au.calculate_hmac_signature(
57+
"secret", "access", "1234567890", "body")
58+
sig2 = au.calculate_hmac_signature(
59+
"secret", "access", "1234567890", "body")
5760
assert sig1 == sig2
5861
assert len(sig1) == 64 # sha256 hex
5962

@@ -147,7 +150,8 @@ def test_get_current_user_id_with_mapping(monkeypatch):
147150
monkeypatch.setattr(au, "IS_SPEED_MODE", False)
148151
token = au.generate_test_jwt("user-a", 1000)
149152
# user->tenant mapping
150-
monkeypatch.setattr(au, "get_user_tenant_by_user_id", lambda u: {"tenant_id": "tenant-a"})
153+
monkeypatch.setattr(au, "get_user_tenant_by_user_id",
154+
lambda u: {"tenant_id": "tenant-a"})
151155
uid, tid = au.get_current_user_id(token)
152156
assert uid == "user-a" and tid == "tenant-a"
153157

@@ -159,3 +163,57 @@ class Req:
159163
assert au.get_user_language(Req()) == "en"
160164
assert au.get_user_language(None) == "zh"
161165

166+
167+
def test_get_supabase_client_success(monkeypatch):
168+
"""Test successful Supabase client creation"""
169+
# Mock the create_client function to return a mock client
170+
mock_client = MagicMock()
171+
monkeypatch.setattr(au, "create_client",
172+
MagicMock(return_value=mock_client))
173+
174+
# Mock environment variables
175+
monkeypatch.setattr(au, "SUPABASE_URL", "http://test-url.com")
176+
monkeypatch.setattr(au, "SUPABASE_KEY", "test-key")
177+
178+
result = au.get_supabase_client()
179+
180+
# Verify the client was created with correct parameters
181+
au.create_client.assert_called_once_with("http://test-url.com", "test-key")
182+
assert result == mock_client
183+
184+
185+
def test_get_supabase_client_exception(monkeypatch, caplog):
186+
"""Test Supabase client creation with exception"""
187+
# Mock create_client to raise an exception
188+
monkeypatch.setattr(au, "create_client", MagicMock(
189+
side_effect=Exception("Connection failed")))
190+
191+
# Mock environment variables
192+
monkeypatch.setattr(au, "SUPABASE_URL", "http://test-url.com")
193+
monkeypatch.setattr(au, "SUPABASE_KEY", "test-key")
194+
195+
result = au.get_supabase_client()
196+
197+
# Verify None is returned on exception
198+
assert result is None
199+
200+
# Verify error was logged
201+
assert "Failed to create Supabase client: Connection failed" in caplog.text
202+
203+
204+
def test_get_supabase_client_with_different_env_vars(monkeypatch):
205+
"""Test Supabase client creation with different environment variables"""
206+
mock_client = MagicMock()
207+
monkeypatch.setattr(au, "create_client",
208+
MagicMock(return_value=mock_client))
209+
210+
# Test with different URL and key
211+
monkeypatch.setattr(au, "SUPABASE_URL", "https://custom.supabase.co")
212+
monkeypatch.setattr(au, "SUPABASE_KEY", "custom-anon-key")
213+
214+
result = au.get_supabase_client()
215+
216+
# Verify the client was created with custom parameters
217+
au.create_client.assert_called_once_with(
218+
"https://custom.supabase.co", "custom-anon-key")
219+
assert result == mock_client

0 commit comments

Comments
 (0)