File size: 3,739 Bytes
198f016
 
 
 
80b95e8
198f016
 
 
80b95e8
198f016
80b95e8
198f016
 
80b95e8
198f016
80b95e8
198f016
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Test script for Phi-2 model loading and basic functionality.
Tests both embedding and generation models.
"""

import sys
import os
import warnings

warnings.filterwarnings("ignore")

# Add parent directory to path to import src modules
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))

from src.config_loader import load_config


def test_config_loading():
    """Test configuration loading"""
    try:
        config = load_config("config.yaml")
        print("βœ“ Configuration loaded successfully")

        # Validate required keys
        assert "embedding" in config
        assert "generator" in config
        assert "retrieval" in config
        print("βœ“ Configuration structure is valid")

        return config
    except Exception as e:
        print(f"βœ— Configuration test failed: {e}")
        return None


def test_embedder_imports():
    """Test embedder module can be imported"""
    try:
        from src.embedder import embed_documents

        print("βœ“ Embedder module imports successfully")
        return True
    except Exception as e:
        print(f"βœ— Embedder import failed: {e}")
        return False


def test_generator_imports():
    """Test generator module can be imported"""
    try:
        from src.generator import generate_commit_message, fallback_commit_message

        print("βœ“ Generator module imports successfully")
        return True
    except Exception as e:
        print(f"βœ— Generator import failed: {e}")
        return False


def test_retriever_imports():
    """Test retriever module can be imported"""
    try:
        from src.retriever import search_documents

        print("βœ“ Retriever module imports successfully")
        return True
    except Exception as e:
        print(f"βœ— Retriever import failed: {e}")
        return False


def test_diff_analyzer():
    """Test diff analyzer module"""
    try:
        from src.diff_analyzer import get_staged_diff_chunks

        print("βœ“ Diff analyzer module imports successfully")

        # Test basic functionality (should work even without git repo)
        file_list, chunks = get_staged_diff_chunks()
        print(
            f"βœ“ Diff analyzer executes (found {len(file_list)} files, {len(chunks)} chunks)"
        )
        return True
    except Exception as e:
        print(f"βœ— Diff analyzer test failed: {e}")
        return False


def test_fallback_functionality():
    """Test fallback functions work without models"""
    try:
        from src.generator import fallback_commit_message

        # Test fallback message generation
        message = fallback_commit_message(["file1.py", "file2.py"])
        print(f"βœ“ Fallback commit message: '{message}'")

        return True
    except Exception as e:
        print(f"βœ— Fallback functionality test failed: {e}")
        return False


if __name__ == "__main__":
    print("Running CodeMind functionality tests...\n")

    # Run all tests
    tests = [
        test_config_loading,
        test_embedder_imports,
        test_generator_imports,
        test_retriever_imports,
        test_diff_analyzer,
        test_fallback_functionality,
    ]

    passed = 0
    total = len(tests)

    for test in tests:
        try:
            result = test()
            if result:
                passed += 1
        except Exception as e:
            print(f"βœ— Test {test.__name__} crashed: {e}")
        print()

    print(f"Tests passed: {passed}/{total}")

    if passed == total:
        print("πŸŽ‰ All tests passed! CodeMind is ready for use.")
    else:
        print("⚠️  Some tests failed. Check dependencies and configuration.")

    sys.exit(0 if passed == total else 1)

# pylint: skip-file