generated from amazon-archives/__template_Apache-2.0
    
        
        - 
                Notifications
    
You must be signed in to change notification settings  - Fork 45
 
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Parent Issue: #195
Objective
Create comprehensive integration tests and end-to-end demo workflow for Travel Assistant and Flight Booking agents.
Implementation References
- Strands Agent Architecture: https://github.com/aarora79/amazon-bedrock-agentcore-samples/tree/feature/demo1-simple-dual-observability/01-tutorials/06-AgentCore-observability/07-simple-dual-observability
 - Test Patterns: https://github.com/awslabs/amazon-bedrock-agentcore-samples/tree/main/02-use-cases/SRE-agent
 
Test Structure
Unit Tests
Travel Assistant Agent Tests
import pytest
from src.agents.travel_assistant import TravelAssistantAgent
class TestTravelAssistant:
    """Test Travel Assistant agent skills"""
    
    @pytest.fixture
    def agent(self):
        return TravelAssistantAgent()
    
    def test_search_flights_success(self, agent):
        """Test successful flight search"""
        result = agent.search_flights(
            from_city="SF",
            to_city="NY",
            departure_date="2025-11-15"
        )
        assert "flights" in result
        assert len(result["flights"]) > 0
        assert result["flights"][0]["flight_number"]
    
    def test_search_flights_empty_result(self, agent):
        """Test flight search with no results"""
        result = agent.search_flights(
            from_city="XYZ",
            to_city="ABC",
            departure_date="2025-01-01"
        )
        assert "flights" in result
        assert len(result["flights"]) == 0
    
    def test_get_recommendations(self, agent):
        """Test flight recommendations"""
        result = agent.get_recommendations(
            flights=[],
            preferences={"max_price": 500, "preferred_airline": "United"}
        )
        assert "recommendations" in result
    
    def test_create_trip_plan(self, agent):
        """Test trip plan creation"""
        result = agent.create_trip_plan(
            flights={"outbound": 1, "return": 2},
            passengers=[{"name": "John", "email": "john@example.com"}]
        )
        assert "trip_id" in result
        assert result["status"] == "created"Flight Booking Agent Tests
class TestFlightBookingAgent:
    """Test Flight Booking agent skills"""
    
    def test_check_availability(self, agent):
        """Test seat availability check"""
        result = agent.check_availability(flight_id=1)
        assert "available_seats" in result
        assert result["available_seats"] >= 0
    
    def test_reserve_flight(self, agent):
        """Test flight reservation"""
        result = agent.reserve_flight(
            flight_id=1,
            passengers=[{"name": "John", "email": "john@example.com"}]
        )
        assert "booking_number" in result
        assert result["status"] == "pending"
    
    def test_confirm_booking(self, agent):
        """Test booking confirmation"""
        result = agent.confirm_booking(booking_number="BK001")
        assert result["status"] == "confirmed"
        assert "confirmation_code" in result
    
    def test_process_payment(self, agent):
        """Test payment processing"""
        result = agent.process_payment(
            booking_number="BK001",
            amount=250.00,
            method="credit_card"
        )
        assert result["status"] == "completed"
        assert "transaction_id" in resultIntegration Tests
Agent Discovery & Communication
class TestAgentCommunication:
    """Test agent-to-agent communication"""
    
    @pytest.fixture
    async def registry_client(self):
        """Create registry client"""
        return RegistryClient("http://registry:5000")
    
    @pytest.fixture
    async def travel_assistant(self):
        """Create travel assistant agent client"""
        return AgentClient("http://travel-assistant:8001")
    
    async def test_discover_booking_agent(self, registry_client):
        """Test discovering Flight Booking Agent"""
        agents = await registry_client.search_agents(
            query="flight booking",
            tags=["booking"]
        )
        assert len(agents) > 0
        assert agents[0]["name"] == "Flight Booking Agent"
        assert "endpoint" in agents[0]
    
    async def test_travel_assistant_calls_booking_agent(
        self,
        travel_assistant,
        registry_client
    ):
        """Test Travel Assistant discovers and calls Flight Booking Agent"""
        # Search for booking agent
        booking_agents = await registry_client.search_agents(
            query="flight booking"
        )
        booking_agent = booking_agents[0]
        
        # Create trip plan (which calls booking agent internally)
        result = await travel_assistant.create_trip_plan(
            from_city="SF",
            to_city="NY",
            departure_date="2025-11-15",
            passengers=1
        )
        
        assert result["status"] == "created"
        assert "booking_reference" in resultEnd-to-End Tests
Complete Workflow Test
class TestEndToEndWorkflow:
    """Test complete user workflow"""
    
    @pytest.mark.asyncio
    async def test_complete_trip_booking_workflow(self):
        """Test: search → recommend → book → confirm"""
        
        # Step 1: User searches for flights
        search_result = await client.post(
            "http://travel-assistant:8001/api/search-flights",
            json={
                "from": "SF",
                "to": "NY",
                "date": "2025-11-15",
                "passengers": 2
            }
        )
        assert search_result.status_code == 200
        flights = search_result.json()["flights"]
        assert len(flights) > 0
        
        # Step 2: System provides recommendations
        recommendations = await client.post(
            "http://travel-assistant:8001/api/get-recommendations",
            json={"flights": flights, "preferences": {"max_price": 500}}
        )
        assert recommendations.status_code == 200
        
        # Step 3: User creates trip plan
        trip_plan = await client.post(
            "http://travel-assistant:8001/api/create-trip-plan",
            json={
                "flights": [flights[0]["id"]],
                "passengers": [
                    {"name": "John Smith", "email": "john@example.com"},
                    {"name": "Jane Smith", "email": "jane@example.com"}
                ]
            }
        )
        assert trip_plan.status_code == 200
        booking = trip_plan.json()
        
        # Step 4: Flight Booking Agent confirms reservation
        confirmation = await client.post(
            "http://flight-booking:8002/api/confirm-booking",
            json={"booking_number": booking["booking_number"]}
        )
        assert confirmation.status_code == 200
        assert confirmation.json()["status"] == "confirmed"
        
        # Step 5: Process payment
        payment = await client.post(
            "http://flight-booking:8002/api/process-payment",
            json={
                "booking_number": booking["booking_number"],
                "amount": booking["total_price"],
                "method": "credit_card"
            }
        )
        assert payment.status_code == 200Demo Script
Manual Testing Script
#!/bin/bash
set -e
echo "Starting Agent Integration Demo"
echo "================================"
# Service endpoints
TRAVEL_API="http://localhost:8001/api"
BOOKING_API="http://localhost:8002/api"
REGISTRY_API="http://localhost:5000/api/v0.1"
# Step 1: Verify services are running
echo "Step 1: Verifying services..."
curl -s "$TRAVEL_API/health" > /dev/null && echo "✓ Travel Assistant running"
curl -s "$BOOKING_API/health" > /dev/null && echo "✓ Flight Booking running"
curl -s "$REGISTRY_API/agents" > /dev/null && echo "✓ Registry running"
# Step 2: Discover agents
echo -e "\nStep 2: Discovering agents in registry..."
AGENTS=$(curl -s "$REGISTRY_API/agents?query=booking")
echo "Found agents: $(echo $AGENTS | jq length) agents registered"
# Step 3: Search flights
echo -e "\nStep 3: Searching for flights (SF → NY)..."
SEARCH_RESULT=$(curl -s -X POST "$TRAVEL_API/search-flights" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "SF",
    "to": "NY",
    "date": "2025-11-15",
    "passengers": 1
  }')
FLIGHTS=$(echo $SEARCH_RESULT | jq '.flights | length')
echo "Found $FLIGHTS flights"
echo $SEARCH_RESULT | jq '.flights[0]'
# Step 4: Get recommendations
echo -e "\nStep 4: Getting flight recommendations..."
RECS=$(curl -s -X POST "$TRAVEL_API/get-recommendations" \
  -H "Content-Type: application/json" \
  -d "{
    \"flights\": $(echo $SEARCH_RESULT | jq '.flights'),
    \"preferences\": {\"max_price\": 500}
  }")
echo "Recommendations: $(echo $RECS | jq '.recommendations | length') options"
# Step 5: Create trip plan (triggers booking agent call)
echo -e "\nStep 5: Creating trip plan (calls Flight Booking Agent)..."
TRIP=$(curl -s -X POST "$TRAVEL_API/create-trip-plan" \
  -H "Content-Type: application/json" \
  -d '{
    "flights": [1],
    "passengers": [{"name": "John Smith", "email": "john@example.com"}]
  }')
BOOKING_NUM=$(echo $TRIP | jq -r '.booking_number')
echo "Trip plan created: $BOOKING_NUM"
# Step 6: Confirm booking
echo -e "\nStep 6: Confirming booking..."
CONFIRM=$(curl -s -X POST "$BOOKING_API/confirm-booking" \
  -H "Content-Type: application/json" \
  -d "{\"booking_number\": \"$BOOKING_NUM\"}")
echo "Booking status: $(echo $CONFIRM | jq -r '.status')"
# Step 7: Process payment
echo -e "\nStep 7: Processing payment..."
PAYMENT=$(curl -s -X POST "$BOOKING_API/process-payment" \
  -H "Content-Type: application/json" \
  -d "{
    \"booking_number\": \"$BOOKING_NUM\",
    \"amount\": 250.00,
    \"method\": \"credit_card\"
  }")
echo "Payment status: $(echo $PAYMENT | jq -r '.status')"
echo -e "\n✓ Complete workflow executed successfully!"Test Coverage Goals
- Unit Tests: Minimum 80% coverage per agent
 - Integration Tests: All agent-to-agent communication paths
 - E2E Tests: Complete user workflows
 - Performance Tests: Response time < 500ms for agent calls
 
CI/CD Integration
GitHub Actions Workflow
name: Integration Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    services:
      registry:
        image: mcp-gateway-registry:latest
        ports:
          - 5000:5000
      travel-assistant:
        image: travel-assistant:latest
        ports:
          - 8001:8001
      flight-booking:
        image: flight-booking:latest
        ports:
          - 8002:8002
    
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      - name: Install dependencies
        run: pip install pytest pytest-asyncio aiohttp
      - name: Run tests
        run: pytest tests/ -v --cov
      - name: Run integration demo
        run: bash scripts/demo.shAcceptance Criteria
- Unit tests written for all agent skills
 - Integration tests for agent communication
 - End-to-end workflow test complete
 - Demo script executable and working
 - Test coverage > 80%
 - All tests passing in CI/CD
 - Performance tests show < 500ms response times
 - Documentation of test scenarios
 
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request