File size: 4,359 Bytes
9222e8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Unit tests for simplified Bielik service
Tests the API structure without running actual models
"""
import os
import json
from unittest.mock import Mock, AsyncMock, patch

# Skip llama-cpp installation during testing
os.environ["SKIP_LLAMA_INSTALL"] = "1"

# Mock the registry before importing main
mock_registry = Mock()
mock_registry.get_available_model_names.return_value = ["bielik-1.5b-transformer", "bielik-11b-transformer"]
mock_registry.get_model_info.return_value = {"type": "transformers", "device": "cuda:0"}

@patch("app.main.registry", mock_registry)
def test_app_structure():
    """Test that simplified app has correct endpoints"""
    from app.main import app
    
    # Get all routes
    routes = {route.path: route.methods for route in app.routes}
    
    # Check required endpoints exist
    assert "/" in routes, "Root endpoint missing"
    assert "/health" in routes, "Health endpoint missing"
    assert "/models" in routes, "Models endpoint missing"
    assert "/chat" in routes, "Chat endpoint missing"
    assert "/generate" in routes, "Generate endpoint missing"
    
    # Check methods
    assert "GET" in routes["/health"], "Health should be GET"
    assert "GET" in routes["/models"], "Models should be GET"
    assert "POST" in routes["/chat"], "Chat should be POST"
    assert "POST" in routes["/generate"], "Generate should be POST"
    
    print("βœ… App structure correct")
    print(f"   Routes: {list(routes.keys())}")

@patch("app.main.registry", mock_registry)
def test_no_business_logic():
    """Verify no domain/infill endpoints exist"""
    from app.main import app
    
    routes = {route.path for route in app.routes}
    
    # These should NOT exist
    forbidden_routes = ["/enhance", "/compare", "/infill", "/compare-infill", "/user/me"]
    
    for route in forbidden_routes:
        assert route not in routes, f"Business logic endpoint {route} should not exist"
    
    print("βœ… No business logic endpoints found")

@patch("app.main.registry", mock_registry)
def test_request_schemas():
    """Test request/response schemas are valid"""
    from app.main import ChatRequest, GenerateRequest, ChatResponse, GenerateResponse
    from app.main import Message, HealthResponse, ModelsResponse
    
    # Test ChatRequest
    chat_req = ChatRequest(
        model="bielik-1.5b-transformer",
        messages=[Message(role="user", content="Hello")]
    )
    assert chat_req.model == "bielik-1.5b-transformer"
    assert len(chat_req.messages) == 1
    print("βœ… ChatRequest schema valid")
    
    # Test GenerateRequest
    gen_req = GenerateRequest(
        model="bielik-1.5b-transformer",
        prompt="Hello world"
    )
    assert gen_req.model == "bielik-1.5b-transformer"
    assert gen_req.prompt == "Hello world"
    print("βœ… GenerateRequest schema valid")
    
    # Test HealthResponse
    health = HealthResponse(
        status="ok",
        gpu_available=True,
        models_available=2
    )
    assert health.status == "ok"
    print("βœ… HealthResponse schema valid")
    
    # Test ModelsResponse
    models_resp = ModelsResponse(models=[])
    assert isinstance(models_resp.models, list)
    print("βœ… ModelsResponse schema valid")

@patch("app.main.registry", mock_registry)
def test_default_values():
    """Test that requests have sensible defaults"""
    from app.main import ChatRequest, GenerateRequest, Message
    
    # Chat with minimal fields
    chat = ChatRequest(
        model="test",
        messages=[Message(role="user", content="test")]
    )
    assert chat.max_tokens == 150
    assert chat.temperature == 0.7
    assert chat.top_p == 0.9
    print("βœ… Chat defaults correct")
    
    # Generate with minimal fields
    gen = GenerateRequest(
        model="test",
        prompt="test"
    )
    assert gen.max_tokens == 150
    assert gen.temperature == 0.7
    assert gen.top_p == 0.9
    print("βœ… Generate defaults correct")

if __name__ == "__main__":
    print("\n=== Testing Simplified Bielik Service ===\n")
    
    try:
        test_app_structure()
        test_no_business_logic()
        test_request_schemas()
        test_default_values()
        
        print("\nβœ… All tests passed!")
        print("\n=== Phase 1 Verification Complete ===")
    except AssertionError as e:
        print(f"\n❌ Test failed: {e}")
        exit(1)