-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_sorting_fix.sh
More file actions
executable file
·202 lines (166 loc) · 4.76 KB
/
test_sorting_fix.sh
File metadata and controls
executable file
·202 lines (166 loc) · 4.76 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
# Test script to verify the improved sorting
echo "=== Testing MCP Sorting Fix ==="
echo ""
# Create test directory
TEST_DIR="/tmp/mcp-sorting-test"
rm -rf "$TEST_DIR"
mkdir -p "$TEST_DIR/old"
mkdir -p "$TEST_DIR/new"
# Create old version with multiple functions
cat > "$TEST_DIR/old/test.c" << 'EOF'
#include <stdio.h>
// Function that will be deleted
void deleted_function() {
printf("This will be deleted\n");
}
// Function that will be slightly modified
void slightly_modified() {
int x = 10;
printf("Value: %d\n", x);
}
// Function that will be heavily modified
void heavily_modified() {
int a = 1;
int b = 2;
printf("Sum: %d\n", a + b);
}
// Function that will be renamed
void old_name() {
printf("Original name\n");
}
// Function that stays the same
void unchanged() {
printf("No changes\n");
}
EOF
# Create new version with changes
cat > "$TEST_DIR/new/test.c" << 'EOF'
#include <stdio.h>
// Function that will be slightly modified
void slightly_modified() {
int x = 11; // Changed value
printf("Value: %d\n", x);
}
// Function that will be heavily modified
void heavily_modified() {
// Completely rewritten
int result = 0;
for (int i = 0; i < 10; i++) {
result += i;
printf("Iteration %d: %d\n", i, result);
}
printf("Final result: %d\n", result);
}
// Function that was renamed
void new_name() {
printf("Original name\n");
}
// Function that stays the same
void unchanged() {
printf("No changes\n");
}
// New function that was added
void added_function() {
printf("This is new\n");
}
EOF
echo "1. Created test files with various change types"
echo ""
# Test the MCP server
echo "2. Testing MCP server..."
echo ""
# Initialize
INIT_RESPONSE=$(curl -s -X POST http://127.0.0.1:8011/message \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0"}
}
}')
if ! echo "$INIT_RESPONSE" | jq -e '.result' > /dev/null 2>&1; then
echo " ✗ Initialization failed"
exit 1
fi
# Compare locations
COMPARE_RESPONSE=$(curl -s -X POST http://127.0.0.1:8011/message \
-H "Content-Type: application/json" \
-d "{
\"jsonrpc\": \"2.0\",
\"id\": 2,
\"method\": \"tools/call\",
\"params\": {
\"name\": \"compare_locations\",
\"arguments\": {
\"source_path\": \"$TEST_DIR/old\",
\"target_path\": \"$TEST_DIR/new\",
\"recursive\": true
}
}
}")
COMPARISON_ID=$(echo "$COMPARE_RESPONSE" | jq -r '.result.content[0].text' | grep -oP 'Comparison ID: \K[a-f0-9-]+')
if [ -z "$COMPARISON_ID" ]; then
echo " ✗ Failed to create comparison"
exit 1
fi
echo " ✓ Comparison created: $COMPARISON_ID"
echo ""
# List changed functions
echo "3. Listing changed functions (should show modified first)..."
echo ""
LIST_RESPONSE=$(curl -s -X POST http://127.0.0.1:8011/message \
-H "Content-Type: application/json" \
-d "{
\"jsonrpc\": \"2.0\",
\"id\": 3,
\"method\": \"tools/call\",
\"params\": {
\"name\": \"list_changed_functions\",
\"arguments\": {
\"comparison_id\": \"$COMPARISON_ID\",
\"limit\": 100
}
}
}")
# Extract the list
LIST_TEXT=$(echo "$LIST_RESPONSE" | jq -r '.result.content[0].text')
echo "=== Changed Functions List ==="
echo "$LIST_TEXT"
echo ""
# Verify sorting
echo "=== Verifying Sort Order ==="
echo ""
# Extract function names in order
FUNCTIONS=$(echo "$LIST_TEXT" | grep -oP '^\d+\. \K[a-z_]+' | head -10)
# Check if modified functions come first
FIRST_FUNC=$(echo "$FUNCTIONS" | head -1)
FIRST_TYPE=$(echo "$LIST_TEXT" | grep -A1 "1. $FIRST_FUNC" | tail -1 | grep -oP '\- \K[a-z]+')
if [ "$FIRST_TYPE" = "modified" ]; then
echo "✅ SUCCESS: Modified functions appear first!"
echo " First function: $FIRST_FUNC (type: $FIRST_TYPE)"
else
echo "❌ FAILED: First function is not modified"
echo " First function: $FIRST_FUNC (type: $FIRST_TYPE)"
echo " Expected: modified"
fi
echo ""
# Check that heavily_modified comes before slightly_modified
HEAVY_POS=$(echo "$FUNCTIONS" | grep -n "heavily_modified" | cut -d: -f1)
SLIGHT_POS=$(echo "$FUNCTIONS" | grep -n "slightly_modified" | cut -d: -f1)
if [ -n "$HEAVY_POS" ] && [ -n "$SLIGHT_POS" ] && [ "$HEAVY_POS" -lt "$SLIGHT_POS" ]; then
echo "✅ SUCCESS: Heavily modified functions ranked higher than slightly modified!"
echo " heavily_modified: position $HEAVY_POS"
echo " slightly_modified: position $SLIGHT_POS"
else
echo "⚠️ Note: Could not verify magnitude-based sorting within modified functions"
fi
echo ""
# Cleanup
echo "Cleaning up test files..."
rm -rf "$TEST_DIR"
echo "Done!"