@@ -182,7 +182,6 @@ def _create_stub_module(name: str, **attrs):
182182 prepare_prompt_templates ,
183183 _get_skills_for_template ,
184184 _get_skill_script_tools ,
185- _print_prompt_with_token_count ,
186185)
187186
188187# Import constants for testing
@@ -433,88 +432,6 @@ def test_get_skill_script_tools_tool_descriptions(self):
433432 assert "skill" in desc .lower ()
434433
435434
436- class TestPrintPromptWithTokenCount :
437- """Tests for the _print_prompt_with_token_count function"""
438-
439- def test_print_prompt_with_token_count_success (self ):
440- """Test successful token counting with tiktoken available"""
441- import tiktoken
442-
443- with patch ('backend.agents.create_agent_info.logger' ) as mock_logger :
444- mock_encoding = MagicMock ()
445- mock_encoding .encode .return_value = ["token1" , "token2" , "token3" ]
446- with patch .object (tiktoken , 'get_encoding' , return_value = mock_encoding ):
447- _print_prompt_with_token_count ("test prompt content" , agent_id = 123 , stage = "TEST" )
448-
449- mock_encoding .encode .assert_called_once_with ("test prompt content" )
450- mock_logger .info .assert_called ()
451-
452- # Check that log messages contain expected content
453- log_calls = mock_logger .info .call_args_list
454- log_text = " " .join ([str (call ) for call in log_calls ])
455- assert "TEST" in log_text
456- assert "123" in log_text
457- assert "3" in log_text # Token count
458-
459- def test_print_prompt_with_token_count_tiktoken_failure (self ):
460- """Test graceful handling when tiktoken fails"""
461- import tiktoken
462-
463- with patch ('backend.agents.create_agent_info.logger' ) as mock_logger :
464- with patch .object (tiktoken , 'get_encoding' , side_effect = Exception ("tiktoken not available" )):
465- _print_prompt_with_token_count ("test prompt" , agent_id = 456 , stage = "FALLBACK" )
466-
467- # Should log a warning and then log the prompt
468- mock_logger .warning .assert_called_once ()
469- assert "Failed to count tokens: tiktoken not available" in mock_logger .warning .call_args [0 ][0 ]
470-
471- # Should still log the prompt
472- mock_logger .info .assert_called ()
473-
474- def test_print_prompt_with_token_count_default_stage (self ):
475- """Test with default stage parameter"""
476- import tiktoken
477-
478- with patch ('backend.agents.create_agent_info.logger' ) as mock_logger :
479- mock_encoding = MagicMock ()
480- mock_encoding .encode .return_value = ["a" , "b" ]
481- with patch .object (tiktoken , 'get_encoding' , return_value = mock_encoding ):
482- _print_prompt_with_token_count ("short prompt" )
483-
484- log_calls = mock_logger .info .call_args_list
485- log_text = " " .join ([str (call ) for call in log_calls ])
486- assert "PROMPT" in log_text # Default stage
487-
488- def test_print_prompt_with_token_count_empty_prompt (self ):
489- """Test with empty prompt"""
490- import tiktoken
491-
492- with patch ('backend.agents.create_agent_info.logger' ) as mock_logger :
493- mock_encoding = MagicMock ()
494- mock_encoding .encode .return_value = []
495- with patch .object (tiktoken , 'get_encoding' , return_value = mock_encoding ):
496- _print_prompt_with_token_count ("" , agent_id = 1 , stage = "EMPTY" )
497-
498- mock_encoding .encode .assert_called_once_with ("" )
499- # Should log token count of 0
500- log_calls = mock_logger .info .call_args_list
501- log_text = " " .join ([str (call ) for call in log_calls ])
502- assert "0" in log_text
503-
504- def test_print_prompt_with_token_count_none_agent_id (self ):
505- """Test with None agent_id"""
506- import tiktoken
507-
508- with patch ('backend.agents.create_agent_info.logger' ) as mock_logger :
509- mock_encoding = MagicMock ()
510- mock_encoding .encode .return_value = ["token" ]
511- with patch .object (tiktoken , 'get_encoding' , return_value = mock_encoding ):
512- _print_prompt_with_token_count ("prompt" , agent_id = None , stage = "NO_ID" )
513-
514- # Should not raise an error
515- mock_encoding .encode .assert_called_once_with ("prompt" )
516-
517-
518435class TestDiscoverLangchainTools :
519436 """Tests for the discover_langchain_tools function"""
520437
0 commit comments