Skip to content

Commit 2e26f00

Browse files
committed
Refactor test workflow for API endpoints: rename job, streamline installation steps, and enhance endpoint testing with improved error handling and response validation.
1 parent 4d70f28 commit 2e26f00

File tree

1 file changed

+119
-52
lines changed

1 file changed

+119
-52
lines changed

.github/workflows/test-mcp-server.yml

Lines changed: 119 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test MCP Server
1+
name: Test API Endpoints
22

33
on:
44
push:
@@ -22,8 +22,16 @@ jobs:
2222
- name: Checkout code
2323
uses: actions/[email protected]
2424

25-
- name: Install jq
26-
run: sudo apt-get install -y jq
25+
- name: Install Python and dependencies
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.10'
29+
30+
- name: Install jq and curl
31+
run: sudo apt-get install -y jq curl
32+
33+
- name: Install Python dependencies
34+
run: pip install -r requirements.txt
2735

2836
- name: Run docker compose
2937
uses: hoverkraft-tech/[email protected]
@@ -39,56 +47,45 @@ jobs:
3947
4048
- name: Verify container readiness
4149
run: |
42-
echo "Checking Docker container status..."
4350
docker ps
44-
4551
for container in api mcp-server mcp-proxy; do
4652
if ! docker ps | grep -q "$container"; then
4753
echo "ERROR: $container is not running!"
4854
docker compose logs --tail=100 "$container"
4955
exit 1
5056
fi
5157
done
52-
5358
echo "All containers are running."
54-
echo "API container logs:"
55-
docker logs $(docker ps -q --filter name=api)
56-
57-
echo "Waiting 30 more seconds for services to stabilize..."
58-
sleep 30
5959
60-
- name: Install cmcp client (latest version)
60+
- name: Test /mcp/compile endpoint
6161
run: |
62-
pip install cmcp==0.1.0
63-
echo "cmcp version:"
64-
cmcp --version
65-
echo "cmcp help output:"
66-
cmcp --help
67-
68-
- name: Check MCP proxy port binding
69-
run: |
70-
echo "Checking if anything is listening on port 3000..."
71-
sudo lsof -i :3000 || echo "Nothing found on port 3000"
72-
curl --fail --silent http://localhost:3000/tools/list || echo "Port 3000 not responding"
73-
74-
- name: Test FastAPI endpoints
75-
run: |
76-
echo "Testing FastAPI /mcp/compile endpoint..."
62+
echo "Testing /mcp/compile endpoint..."
7763
RESPONSE=$(curl -s -S -f -X POST http://localhost:8000/mcp/compile \
7864
-H "Content-Type: application/json" \
7965
-d '{
8066
"code": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\");\n}"
8167
}' || echo "CURL_FAILED")
8268
8369
if [ "$RESPONSE" = "CURL_FAILED" ]; then
84-
echo "Failed to connect to FastAPI service"
70+
echo "Failed to connect to API service"
8571
docker ps
8672
docker logs $(docker ps -q --filter name=api)
8773
exit 1
8874
fi
75+
76+
# Check for success in response
77+
if ! echo "$RESPONSE" | jq -e '.success == true' > /dev/null; then
78+
echo "Compilation failed:"
79+
echo "$RESPONSE" | jq || echo "$RESPONSE"
80+
exit 1
81+
fi
82+
83+
echo "Compilation successful!"
8984
echo "$RESPONSE" | jq || echo "$RESPONSE"
9085
91-
echo "Testing FastAPI /mcp/compile-and-fix endpoint..."
86+
- name: Test /mcp/compile-and-fix endpoint
87+
run: |
88+
echo "Testing /mcp/compile-and-fix endpoint..."
9289
RESPONSE=$(curl -s -S -f -X POST http://localhost:8000/mcp/compile-and-fix \
9390
-H "Content-Type: application/json" \
9491
-d '{
@@ -98,40 +95,110 @@ jobs:
9895
}' || echo "CURL_FAILED")
9996
10097
if [ "$RESPONSE" = "CURL_FAILED" ]; then
101-
echo "Failed to connect to FastAPI service"
98+
echo "Failed to connect to API service"
10299
docker ps
103100
docker logs $(docker ps -q --filter name=api)
104101
exit 1
105102
fi
106-
echo "$RESPONSE" | jq || echo "$RESPONSE"
103+
104+
# Verify the response format has filename markers
105+
if ! echo "$RESPONSE" | grep -q "\[filename:"; then
106+
echo "Response does not contain filename markers:"
107+
echo "$RESPONSE"
108+
exit 1
109+
fi
110+
111+
echo "Compile and fix successful! Response contains code files in text format."
107112
108-
- name: Test MCP Server with cmcp client
113+
- name: Test /generate endpoint
109114
run: |
110-
echo "Testing MCP server compile method..."
111-
echo '{
112-
"code": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\");\n}"
113-
}' | cmcp http://localhost:3000 tools/call rust-compiler compile -d @- || {
114-
echo "MCP compile test failed"
115-
exit 1
116-
}
115+
echo "Testing /generate endpoint..."
116+
117+
# Generate the project
118+
RESPONSE=$(curl -s -S -f -X POST http://localhost:8000/generate \
119+
-H "Content-Type: application/json" \
120+
-d '{
121+
"description": "A simple command-line calculator in Rust",
122+
"requirements": "Should support addition, subtraction, multiplication, and division"
123+
}' || echo "CURL_FAILED")
117124
118-
echo "Testing MCP server compileAndFix method..."
119-
echo '{
120-
"code": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\" // Missing closing parenthesis\n}",
121-
"description": "A simple hello world program",
122-
"max_attempts": 3
123-
}' | cmcp tools/call http://localhost:3000 rust-compiler compileAndFix || {
124-
echo "MCP compileAndFix test failed"
125+
if [ "$RESPONSE" = "CURL_FAILED" ]; then
126+
echo "Failed to connect to API service"
127+
docker ps
128+
docker logs $(docker ps -q --filter name=api)
125129
exit 1
126-
}
130+
fi
131+
132+
# Extract project_id from response
133+
PROJECT_ID=$(echo "$RESPONSE" | jq -r '.project_id')
134+
echo "Project ID: $PROJECT_ID"
135+
136+
# Poll for project completion (maximum 10 attempts, 15 seconds apart)
137+
echo "Polling for project completion..."
138+
for i in {1..10}; do
139+
echo "Checking project status (attempt $i)..."
140+
STATUS_RESPONSE=$(curl -s -S -f "http://localhost:8000/project/$PROJECT_ID" || echo "CURL_FAILED")
141+
142+
if [ "$STATUS_RESPONSE" = "CURL_FAILED" ]; then
143+
echo "Failed to get project status"
144+
exit 1
145+
fi
146+
147+
STATUS=$(echo "$STATUS_RESPONSE" | jq -r '.status')
148+
echo "Current status: $STATUS"
149+
150+
if [ "$STATUS" = "completed" ]; then
151+
echo "Project generation successful!"
152+
echo "$STATUS_RESPONSE" | jq
153+
break
154+
elif [ "$STATUS" = "failed" ]; then
155+
echo "Project generation failed:"
156+
echo "$STATUS_RESPONSE" | jq
157+
exit 1
158+
fi
159+
160+
# If still processing, wait and try again
161+
if [ $i -eq 10 ]; then
162+
echo "Project generation taking too long, exiting"
163+
exit 1
164+
fi
165+
166+
echo "Waiting 15 seconds before next check..."
167+
sleep 15
168+
done
169+
170+
# Get a file from the project to verify file access works
171+
echo "Retrieving main.rs file..."
172+
FILE_RESPONSE=$(curl -s -S -f "http://localhost:8000/project/$PROJECT_ID/files/src/main.rs" || echo "CURL_FAILED")
173+
174+
if [ "$FILE_RESPONSE" = "CURL_FAILED" ]; then
175+
echo "Failed to retrieve file"
176+
exit 1
177+
fi
178+
179+
echo "Successfully retrieved file content:"
180+
echo "$FILE_RESPONSE" | head -10
181+
182+
# Test downloading the project
183+
echo "Testing project download..."
184+
DOWNLOAD_RESPONSE=$(curl -s -S -f -o "project-$PROJECT_ID.zip" "http://localhost:8000/project/$PROJECT_ID/download" || echo "CURL_FAILED")
185+
186+
if [ "$DOWNLOAD_RESPONSE" = "CURL_FAILED" ]; then
187+
echo "Failed to download project"
188+
exit 1
189+
fi
190+
191+
# Verify zip file was created
192+
if [ ! -f "project-$PROJECT_ID.zip" ]; then
193+
echo "Project zip file not created"
194+
exit 1
195+
fi
196+
197+
echo "Project download successful!"
198+
ls -la "project-$PROJECT_ID.zip"
127199
128200
- name: Check Docker logs on failure
129201
if: failure()
130202
run: |
131203
echo "Checking Docker logs for troubleshooting..."
132204
docker compose logs || echo "Failed to get logs"
133-
134-
- name: Check MCP proxy logs
135-
run: |
136-
echo "MCP proxy logs:"
137-
docker logs $(docker ps -a -q --filter name=mcp-proxy) || echo "Failed to get MCP proxy logs"

0 commit comments

Comments
 (0)