|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Test script for A2A wrapper module |
| 4 | +Sends tasks to the task-agent to verify functionality |
| 5 | +""" |
| 6 | +import asyncio |
| 7 | +import sys |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | +# Add ai module to path |
| 11 | +ai_src = Path(__file__).parent / "ai" / "src" |
| 12 | +sys.path.insert(0, str(ai_src)) |
| 13 | + |
| 14 | +from fuzzforge_ai.a2a_wrapper import send_agent_task, get_agent_config |
| 15 | + |
| 16 | + |
| 17 | +async def test_basic_task(): |
| 18 | + """Test sending a basic task to the agent""" |
| 19 | + print("=" * 80) |
| 20 | + print("Test 1: Basic task without model specification") |
| 21 | + print("=" * 80) |
| 22 | + |
| 23 | + result = await send_agent_task( |
| 24 | + url="http://127.0.0.1:10900/a2a/litellm_agent", |
| 25 | + message="What is 2+2? Answer in one sentence.", |
| 26 | + timeout=30 |
| 27 | + ) |
| 28 | + |
| 29 | + print(f"Context ID: {result.context_id}") |
| 30 | + print(f"Response:\n{result.text}") |
| 31 | + print() |
| 32 | + return result.context_id |
| 33 | + |
| 34 | + |
| 35 | +async def test_with_model_and_prompt(): |
| 36 | + """Test sending a task with custom model and prompt""" |
| 37 | + print("=" * 80) |
| 38 | + print("Test 2: Task with model and prompt specification") |
| 39 | + print("=" * 80) |
| 40 | + |
| 41 | + result = await send_agent_task( |
| 42 | + url="http://127.0.0.1:10900/a2a/litellm_agent", |
| 43 | + model="gpt-4o-mini", |
| 44 | + provider="openai", |
| 45 | + prompt="You are a concise Python expert. Answer in 2 sentences max.", |
| 46 | + message="Write a simple Python function that checks if a number is prime.", |
| 47 | + context="python_test", |
| 48 | + timeout=60 |
| 49 | + ) |
| 50 | + |
| 51 | + print(f"Context ID: {result.context_id}") |
| 52 | + print(f"Response:\n{result.text}") |
| 53 | + print() |
| 54 | + return result.context_id |
| 55 | + |
| 56 | + |
| 57 | +async def test_fuzzing_task(): |
| 58 | + """Test a fuzzing-related task""" |
| 59 | + print("=" * 80) |
| 60 | + print("Test 3: Fuzzing harness generation task") |
| 61 | + print("=" * 80) |
| 62 | + |
| 63 | + result = await send_agent_task( |
| 64 | + url="http://127.0.0.1:10900/a2a/litellm_agent", |
| 65 | + model="gpt-4o-mini", |
| 66 | + provider="openai", |
| 67 | + prompt="You are a security testing expert. Provide practical, working code.", |
| 68 | + message="Generate a simple fuzzing harness for a C function that parses JSON strings. Include only the essential code.", |
| 69 | + context="fuzzing_session", |
| 70 | + timeout=90 |
| 71 | + ) |
| 72 | + |
| 73 | + print(f"Context ID: {result.context_id}") |
| 74 | + print(f"Response:\n{result.text}") |
| 75 | + print() |
| 76 | + |
| 77 | + |
| 78 | +async def test_get_config(): |
| 79 | + """Test getting agent configuration""" |
| 80 | + print("=" * 80) |
| 81 | + print("Test 4: Get agent configuration") |
| 82 | + print("=" * 80) |
| 83 | + |
| 84 | + config = await get_agent_config( |
| 85 | + url="http://127.0.0.1:10900/a2a/litellm_agent", |
| 86 | + timeout=30 |
| 87 | + ) |
| 88 | + |
| 89 | + print(f"Agent Config:\n{config}") |
| 90 | + print() |
| 91 | + |
| 92 | + |
| 93 | +async def test_multi_turn(): |
| 94 | + """Test multi-turn conversation with same context""" |
| 95 | + print("=" * 80) |
| 96 | + print("Test 5: Multi-turn conversation") |
| 97 | + print("=" * 80) |
| 98 | + |
| 99 | + # First message |
| 100 | + result1 = await send_agent_task( |
| 101 | + url="http://127.0.0.1:10900/a2a/litellm_agent", |
| 102 | + message="What is the capital of France?", |
| 103 | + context="geography_quiz", |
| 104 | + timeout=30 |
| 105 | + ) |
| 106 | + print(f"Q1: What is the capital of France?") |
| 107 | + print(f"A1: {result1.text}") |
| 108 | + print() |
| 109 | + |
| 110 | + # Follow-up in same context |
| 111 | + result2 = await send_agent_task( |
| 112 | + url="http://127.0.0.1:10900/a2a/litellm_agent", |
| 113 | + message="What is the population of that city?", |
| 114 | + context="geography_quiz", # Same context |
| 115 | + timeout=30 |
| 116 | + ) |
| 117 | + print(f"Q2: What is the population of that city?") |
| 118 | + print(f"A2: {result2.text}") |
| 119 | + print() |
| 120 | + |
| 121 | + |
| 122 | +async def main(): |
| 123 | + """Run all tests""" |
| 124 | + print("\n" + "=" * 80) |
| 125 | + print("FuzzForge A2A Wrapper Test Suite") |
| 126 | + print("=" * 80 + "\n") |
| 127 | + |
| 128 | + try: |
| 129 | + # Run tests |
| 130 | + await test_basic_task() |
| 131 | + await test_with_model_and_prompt() |
| 132 | + await test_fuzzing_task() |
| 133 | + await test_get_config() |
| 134 | + await test_multi_turn() |
| 135 | + |
| 136 | + print("=" * 80) |
| 137 | + print("✅ All tests completed successfully!") |
| 138 | + print("=" * 80) |
| 139 | + |
| 140 | + except Exception as e: |
| 141 | + print(f"\n❌ Test failed with error: {e}") |
| 142 | + import traceback |
| 143 | + traceback.print_exc() |
| 144 | + return 1 |
| 145 | + |
| 146 | + return 0 |
| 147 | + |
| 148 | + |
| 149 | +if __name__ == "__main__": |
| 150 | + exit_code = asyncio.run(main()) |
| 151 | + sys.exit(exit_code) |
0 commit comments