Skip to content
Open
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
83 changes: 0 additions & 83 deletions test/backend/agents/test_create_agent_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def _create_stub_module(name: str, **attrs):
prepare_prompt_templates,
_get_skills_for_template,
_get_skill_script_tools,
_print_prompt_with_token_count,
)

# Import constants for testing
Expand Down Expand Up @@ -433,88 +432,6 @@ def test_get_skill_script_tools_tool_descriptions(self):
assert "skill" in desc.lower()


class TestPrintPromptWithTokenCount:
"""Tests for the _print_prompt_with_token_count function"""

def test_print_prompt_with_token_count_success(self):
"""Test successful token counting with tiktoken available"""
import tiktoken

with patch('backend.agents.create_agent_info.logger') as mock_logger:
mock_encoding = MagicMock()
mock_encoding.encode.return_value = ["token1", "token2", "token3"]
with patch.object(tiktoken, 'get_encoding', return_value=mock_encoding):
_print_prompt_with_token_count("test prompt content", agent_id=123, stage="TEST")

mock_encoding.encode.assert_called_once_with("test prompt content")
mock_logger.info.assert_called()

# Check that log messages contain expected content
log_calls = mock_logger.info.call_args_list
log_text = " ".join([str(call) for call in log_calls])
assert "TEST" in log_text
assert "123" in log_text
assert "3" in log_text # Token count

def test_print_prompt_with_token_count_tiktoken_failure(self):
"""Test graceful handling when tiktoken fails"""
import tiktoken

with patch('backend.agents.create_agent_info.logger') as mock_logger:
with patch.object(tiktoken, 'get_encoding', side_effect=Exception("tiktoken not available")):
_print_prompt_with_token_count("test prompt", agent_id=456, stage="FALLBACK")

# Should log a warning and then log the prompt
mock_logger.warning.assert_called_once()
assert "Failed to count tokens: tiktoken not available" in mock_logger.warning.call_args[0][0]

# Should still log the prompt
mock_logger.info.assert_called()

def test_print_prompt_with_token_count_default_stage(self):
"""Test with default stage parameter"""
import tiktoken

with patch('backend.agents.create_agent_info.logger') as mock_logger:
mock_encoding = MagicMock()
mock_encoding.encode.return_value = ["a", "b"]
with patch.object(tiktoken, 'get_encoding', return_value=mock_encoding):
_print_prompt_with_token_count("short prompt")

log_calls = mock_logger.info.call_args_list
log_text = " ".join([str(call) for call in log_calls])
assert "PROMPT" in log_text # Default stage

def test_print_prompt_with_token_count_empty_prompt(self):
"""Test with empty prompt"""
import tiktoken

with patch('backend.agents.create_agent_info.logger') as mock_logger:
mock_encoding = MagicMock()
mock_encoding.encode.return_value = []
with patch.object(tiktoken, 'get_encoding', return_value=mock_encoding):
_print_prompt_with_token_count("", agent_id=1, stage="EMPTY")

mock_encoding.encode.assert_called_once_with("")
# Should log token count of 0
log_calls = mock_logger.info.call_args_list
log_text = " ".join([str(call) for call in log_calls])
assert "0" in log_text

def test_print_prompt_with_token_count_none_agent_id(self):
"""Test with None agent_id"""
import tiktoken

with patch('backend.agents.create_agent_info.logger') as mock_logger:
mock_encoding = MagicMock()
mock_encoding.encode.return_value = ["token"]
with patch.object(tiktoken, 'get_encoding', return_value=mock_encoding):
_print_prompt_with_token_count("prompt", agent_id=None, stage="NO_ID")

# Should not raise an error
mock_encoding.encode.assert_called_once_with("prompt")


class TestDiscoverLangchainTools:
"""Tests for the discover_langchain_tools function"""

Expand Down
Loading