File size: 5,224 Bytes
ed5b955
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python3
"""
Test script for Modal integration in production
Tests the deployed Modal endpoint and HF Space integration
"""

import os
import sys
import requests
import pytest

# Production Modal URL
MODAL_URL = "https://mcp-model-labs--surf-spot-finder-mcp-api-find-spots.modal.run"
HEALTH_URL = "https://mcp-model-labs--surf-spot-finder-mcp-health-check.modal.run"

def test_modal_health_endpoint():
    """Test the Modal health check endpoint"""
    try:
        response = requests.get(HEALTH_URL, timeout=10)
        response.raise_for_status()
        
        result = response.json()
        assert result.get("status") == "healthy"
        assert result.get("service") == "surf-spot-finder-mcp"
        print("βœ… Modal health check passed")
        
    except Exception as e:
        pytest.fail(f"Health check failed: {e}")

def test_modal_surf_endpoint():
    """Test the Modal surf spot finder endpoint"""
    payload = {
        "location": "MΓ‘laga, Spain",
        "max_distance": 50,
        "num_spots": 3,
        "preferences": {"skill_level": "intermediate"}
    }
    
    try:
        response = requests.post(MODAL_URL, json=payload, timeout=30)
        response.raise_for_status()
        
        result = response.json()
        
        assert result.get("ok") == True
        assert result.get("success") == True
        assert "user_location" in result
        assert "spots" in result
        assert len(result["spots"]) > 0
        
        # Check spot structure
        spot = result["spots"][0]
        required_fields = ["name", "score", "latitude", "longitude", "distance_km", "explanation", "conditions", "breakdown"]
        for field in required_fields:
            assert field in spot, f"Missing field: {field}"
        
        assert isinstance(spot["score"], (int, float))
        assert 0 <= spot["score"] <= 100
        
        print(f"βœ… Found {len(result['spots'])} surf spots")
        print(f"πŸ„β€β™‚οΈ Best spot: {spot['name']} (Score: {spot['score']}/100)")
        
    except Exception as e:
        pytest.fail(f"Modal surf endpoint failed: {e}")

def test_hf_space_integration():
    """Test HF Space MCP client with Modal"""
    # Set Modal URL environment variable
    os.environ["MODAL_URL"] = MODAL_URL
    
    # Add hf_space to path
    hf_space_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "hf_space")
    sys.path.insert(0, hf_space_path)
    
    try:
        from mcp_client import find_best_spots
        
        result = find_best_spots(
            user_location="MΓ‘laga, Spain",
            max_distance_km=50,
            top_n=3,
            prefs={"skill_level": "intermediate"}
        )
        
        assert result.get("ok") == True
        assert "results" in result
        assert len(result["results"]) > 0
        
        # Check result structure matches HF Space expectations
        spot = result["results"][0]
        required_fields = ["name", "score", "latitude", "longitude", "distance_km", "explanation", "conditions", "breakdown"]
        for field in required_fields:
            assert field in spot, f"Missing field: {field}"
        
        print(f"βœ… HF Space client integration working")
        print(f"πŸ€– AI Summary: {result.get('ai_summary', 'N/A')}")
        
    except ImportError:
        pytest.skip("HF Space MCP client not available")
    except Exception as e:
        pytest.fail(f"HF Space integration failed: {e}")

def test_different_locations():
    """Test Modal endpoint with different locations"""
    test_locations = [
        ("Lisbon, Portugal", "European Atlantic coast"),
        ("Los Angeles, California", "US Pacific coast"),
        ("Sydney, Australia", "Australian coast")
    ]
    
    for location, description in test_locations:
        payload = {
            "location": location,
            "max_distance": 100,
            "num_spots": 2,
            "preferences": {"skill_level": "advanced"}
        }
        
        try:
            response = requests.post(MODAL_URL, json=payload, timeout=30)
            response.raise_for_status()
            
            result = response.json()
            assert result.get("ok") == True
            
            print(f"βœ… {description}: {len(result.get('spots', []))} spots found")
            
        except Exception as e:
            print(f"⚠️  {description} test failed: {e}")
            # Don't fail the test for remote locations that might not have spots

if __name__ == "__main__":
    print("πŸ„β€β™‚οΈ Testing Modal Production Integration")
    print("=" * 60)
    
    print("\n1. Testing Modal health endpoint...")
    test_modal_health_endpoint()
    
    print("\n2. Testing Modal surf endpoint...")
    test_modal_surf_endpoint()
    
    print("\n3. Testing HF Space integration...")
    test_hf_space_integration()
    
    print("\n4. Testing different locations...")
    test_different_locations()
    
    print("\n" + "=" * 60)
    print("πŸŽ‰ All Modal integration tests completed!")
    print(f"βœ… Production Modal URL: {MODAL_URL}")
    print("πŸ”— Modal Dashboard: https://modal.com/apps/mcp-model-labs/main/deployed/surf-spot-finder-mcp")