1+ #!/usr/bin/env python3
2+ """
3+ Example usage of the coding agent test automation framework
4+ """
5+ import os
6+ import sys
7+
8+ # Add the parent directory to path so we can import the test modules
9+ sys .path .insert (0 , os .path .join (os .path .dirname (__file__ ), '..' ))
10+
11+ from tests .mocks import MockMCPToolClient , MockLLMClient
12+ from tests .run_tests import run_tests , run_unit_tests , run_integration_tests
13+ import yaml
14+
15+
16+ def demonstrate_mock_mcp_client ():
17+ """Demonstrate mock MCP client usage"""
18+ print ("=== Mock MCP Client Demo ===" )
19+
20+ # Create GitHub mock client
21+ github_config = {'mcp_server_name' : 'github' , 'command' : ['mock' ]}
22+ github_client = MockMCPToolClient (github_config )
23+
24+ # Show available tools
25+ tools = github_client .list_tools ()
26+ print (f"GitHub tools: { [tool ['name' ] for tool in tools ]} " )
27+
28+ # Search for issues
29+ issues = github_client .call_tool ('search_issues' , {'q' : 'label:"coding agent"' })
30+ print (f"Found { len (issues ['items' ])} mock issues" )
31+
32+ # Get issue details
33+ issue = github_client .call_tool ('get_issue' , {'issue_number' : 1 })
34+ print (f"Issue: { issue ['title' ]} " )
35+
36+ # Add comment
37+ comment = github_client .call_tool ('add_issue_comment' , {
38+ 'issue_number' : 1 ,
39+ 'body' : 'This is a test comment'
40+ })
41+ print (f"Added comment: { comment ['body' ]} " )
42+ print ()
43+
44+
45+ def demonstrate_mock_llm_client ():
46+ """Demonstrate mock LLM client usage"""
47+ print ("=== Mock LLM Client Demo ===" )
48+
49+ config = {'llm' : {'provider' : 'mock' }}
50+ llm_client = MockLLMClient (config )
51+
52+ # Send system prompt
53+ llm_client .send_system_prompt ("You are a helpful coding assistant." )
54+
55+ # Send user message
56+ llm_client .send_user_message ("Please help me with issue #1" )
57+
58+ # Get responses
59+ response1 , _ = llm_client .get_response ()
60+ print (f"Response 1: { response1 } " )
61+
62+ response2 , _ = llm_client .get_response ()
63+ print (f"Response 2: { response2 } " )
64+
65+ # Show interaction history
66+ print (f"System prompt: { llm_client .system_prompt } " )
67+ print (f"User messages: { llm_client .user_messages } " )
68+ print ()
69+
70+
71+ def demonstrate_test_workflow ():
72+ """Demonstrate the complete test workflow"""
73+ print ("=== Test Workflow Demo ===" )
74+
75+ # Load test config
76+ config_path = os .path .join (os .path .dirname (__file__ ), 'test_config.yaml' )
77+ with open (config_path , 'r' ) as f :
78+ config = yaml .safe_load (f )
79+
80+ print ("Test configuration loaded:" )
81+ print (f" LLM Provider: { config ['llm' ]['provider' ]} " )
82+ print (f" GitHub Bot Label: { config ['github' ]['bot_label' ]} " )
83+ print (f" GitLab Bot Label: { config ['gitlab' ]['bot_label' ]} " )
84+ print ()
85+
86+ # Create mock clients
87+ github_client = MockMCPToolClient ({'mcp_server_name' : 'github' , 'command' : ['mock' ]})
88+ gitlab_client = MockMCPToolClient ({'mcp_server_name' : 'gitlab' , 'command' : ['mock' ]})
89+ llm_client = MockLLMClient (config )
90+
91+ print ("Mock clients created successfully!" )
92+ print (f" GitHub client has { len (github_client .mock_data ['issues' ])} mock issues" )
93+ print (f" GitLab client has { len (gitlab_client .mock_data ['issues' ])} mock issues" )
94+ print (f" LLM client has { len (llm_client .response_queue )} default responses" )
95+ print ()
96+
97+
98+ def run_sample_tests ():
99+ """Run sample tests to show the framework in action"""
100+ print ("=== Running Sample Tests ===" )
101+
102+ # Run unit tests
103+ print ("Running unit tests..." )
104+ unit_success = run_unit_tests ()
105+ print (f"Unit tests: { 'PASSED' if unit_success else 'FAILED' } " )
106+
107+ # Run integration tests
108+ print ("Running integration tests..." )
109+ integration_success = run_integration_tests ()
110+ print (f"Integration tests: { 'PASSED' if integration_success else 'FAILED' } " )
111+
112+ # Overall result
113+ overall_success = unit_success and integration_success
114+ print (f"Overall result: { 'PASSED' if overall_success else 'FAILED' } " )
115+ print ()
116+
117+
118+ def main ():
119+ """Main demo function"""
120+ print ("Coding Agent Test Automation Framework Demo" )
121+ print ("=" * 50 )
122+ print ()
123+
124+ try :
125+ demonstrate_mock_mcp_client ()
126+ demonstrate_mock_llm_client ()
127+ demonstrate_test_workflow ()
128+ run_sample_tests ()
129+
130+ print ("✅ Demo completed successfully!" )
131+ print ()
132+ print ("To run the full test suite manually:" )
133+ print (" python3 -m tests.run_tests" )
134+ print (" python3 -m tests.run_tests --unit" )
135+ print (" python3 -m tests.run_tests --integration" )
136+
137+ except Exception as e :
138+ print (f"❌ Demo failed: { e } " )
139+ sys .exit (1 )
140+
141+
142+ if __name__ == '__main__' :
143+ main ()
0 commit comments