Coverage for agentos/tests/test_production_agent.py: 0%

66 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-07-09 09:19 +0800

1"""Tests for agentos/agent/production_agent.py.""" 

2 

3import os 

4 

5import pytest 

6 

7from agentos.agent.agent_builder import _MockProvider 

8from agentos.agent.production_agent import AgentResult, ProductionAgent 

9 

10 

11class TestAgentResult: 

12 def test_success_result(self): 

13 r = AgentResult(success=True, output="task done", total_steps=3) 

14 assert r.success is True 

15 assert r.output == "task done" 

16 assert r.total_steps == 3 

17 

18 def test_failure_result(self): 

19 r = AgentResult(success=False, error="something went wrong") 

20 assert r.success is False 

21 assert r.error == "something went wrong" 

22 

23 def test_all_fields(self): 

24 r = AgentResult( 

25 success=True, 

26 output="result", 

27 error=None, 

28 total_steps=5, 

29 total_tokens=1200, 

30 total_cost_usd=0.003, 

31 total_latency_ms=450.5, 

32 tool_calls=3, 

33 ) 

34 assert r.total_tokens == 1200 

35 assert r.total_cost_usd == 0.003 

36 assert r.tool_calls == 3 

37 

38 

39class TestProductionAgent: 

40 @pytest.fixture(autouse=True) 

41 def setup(self): 

42 for key in ["DEEPSEEK_API_KEY", "OPENAI_API_KEY", "ANTHROPIC_API_KEY"]: 

43 os.environ.pop(key, None) 

44 

45 def test_init_with_defaults(self): 

46 agent = ProductionAgent() 

47 assert agent is not None 

48 

49 def test_init_with_mock_provider(self): 

50 provider = _MockProvider() 

51 agent = ProductionAgent(provider=provider) 

52 assert agent is not None 

53 

54 def test_init_with_custom_max_steps(self): 

55 agent = ProductionAgent(max_steps=5) 

56 assert agent is not None 

57 

58 def test_init_with_system_prompt(self): 

59 agent = ProductionAgent(system_prompt="Be concise.") 

60 assert agent is not None 

61 

62 def test_init_with_include_skills_false(self): 

63 agent = ProductionAgent(include_skills=False) 

64 assert agent is not None 

65 

66 def test_init_with_verbose(self): 

67 agent = ProductionAgent(verbose=True) 

68 assert agent is not None 

69 

70 def test_run_with_mock_provider(self): 

71 provider = _MockProvider() 

72 agent = ProductionAgent(provider=provider, include_skills=False) 

73 result = agent.run("What is 1+1?") 

74 assert isinstance(result, AgentResult) 

75 

76 def test_run_returns_agent_result_structure(self): 

77 provider = _MockProvider() 

78 agent = ProductionAgent(provider=provider, include_skills=False) 

79 result = agent.run("Say hello") 

80 assert isinstance(result, AgentResult) 

81 assert isinstance(result.success, bool) 

82 assert isinstance(result.output, str) 

83 

84 def test_get_tool_count(self): 

85 provider = _MockProvider() 

86 agent = ProductionAgent(provider=provider, include_skills=False) 

87 count = agent.get_tool_count() 

88 assert isinstance(count, int) 

89 assert count >= 0 

90 

91 def test_list_tools(self): 

92 provider = _MockProvider() 

93 agent = ProductionAgent(provider=provider, include_skills=False) 

94 tools = agent.list_tools() 

95 assert isinstance(tools, list)