chore: consolidate docker-compose and add integration tests

- Merge infrastructure/docker-compose.yml + docker-compose.app.yml into root docker-compose.yml with profiles (infra/app).
- Add healthchecks for mysql/redis/rabbitmq/mci-server/channel-service and depends_on conditions.
- Rewrite scripts/local-up.sh to use profiles and wait for healthy states.
- Add curl to mci-server and channel-service Docker images for healthchecks.
- Add npm test script to admin-web (type-check + build smoke test).
- Add scripts/test-external-api.sh covering 11 API endpoints.
- Verify Java (7/7), Python (6/6), npm build, external API (11/11), and UI flows.
This commit is contained in:
2026-07-07 13:35:41 +08:00
parent 033580aa52
commit 51a373e06c
9 changed files with 347 additions and 138 deletions

View File

@@ -4,47 +4,42 @@ set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
echo "Creating shared network..."
docker network create mci-network 2>/dev/null || true
wait_for_healthy() {
local service=$1
local max_retries=${2:-60}
local retry_count=0
local container_name
echo "Starting local infrastructure..."
docker compose -f infrastructure/docker-compose.yml up -d
echo "Waiting for $service to become healthy..."
while [ "$retry_count" -lt "$max_retries" ]; do
container_name=$(docker compose --profile infra --profile app ps -q "$service" 2>/dev/null | head -n1)
echo "Waiting for MySQL..."
MAX_RETRIES=60
RETRY_COUNT=0
until docker exec mci-mysql mysql -uroot -proot -e "SELECT 1" > /dev/null 2>&1; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]; then
echo "MySQL did not become ready within ${MAX_RETRIES} seconds."
exit 1
fi
sleep 1
done
if [ -n "$container_name" ]; then
local status
status=$(docker inspect --format='{{.State.Health.Status}}' "$container_name" 2>/dev/null || true)
if [ "$status" = "healthy" ]; then
echo "$service is healthy."
return 0
fi
fi
echo "Waiting for Redis..."
RETRY_COUNT=0
until docker exec mci-redis redis-cli ping | grep -q "PONG"; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ "$RETRY_COUNT" -ge 30 ]; then
echo "Redis did not become ready within 30 seconds."
exit 1
fi
sleep 1
done
retry_count=$((retry_count + 1))
sleep 2
done
echo "Waiting for RabbitMQ..."
RETRY_COUNT=0
until curl -s -o /dev/null -w "%{http_code}" http://guest:guest@localhost:15672/api/overview | grep -q "200"; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ "$RETRY_COUNT" -ge 30 ]; then
echo "RabbitMQ did not become ready within 30 seconds."
exit 1
fi
sleep 1
done
echo "$service did not become healthy within $((max_retries * 2)) seconds."
docker compose --profile infra --profile app logs --tail=50 "$service"
return 1
}
echo "Local infrastructure is ready."
echo "Starting infrastructure services..."
docker compose --profile infra up -d
wait_for_healthy mysql 60
wait_for_healthy redis 30
wait_for_healthy rabbitmq 60
echo "Infrastructure is ready."
echo "MySQL: jdbc:mysql://localhost:3306/sino_mci"
echo "Redis: localhost:6379"
echo "RabbitMQ: localhost:5672 / http://localhost:15672"
@@ -52,7 +47,13 @@ echo "SeaweedFS: http://localhost:9333"
if [ "$1" == "--with-apps" ]; then
echo "Starting application services..."
docker compose -f docker-compose.app.yml up -d --build
# Include infra profile so that depends_on conditions can resolve.
docker compose --profile infra --profile app up -d --build
wait_for_healthy mci-server 90
wait_for_healthy channel-service 60
echo "Application services are ready."
echo "Admin Web: http://localhost"
echo "Backend API: http://localhost:8080/msg-platform"
echo "Channel Service: http://localhost:8000"

159
scripts/test-external-api.sh Executable file
View File

@@ -0,0 +1,159 @@
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
BASE_URL="${BASE_URL:-http://localhost/msg-platform}"
CHANNEL_URL="${CHANNEL_URL:-http://localhost:8000}"
command -v curl >/dev/null 2>&1 || { echo "curl is required but not installed."; exit 1; }
command -v jq >/dev/null 2>&1 || { echo "jq is required but not installed."; exit 1; }
PASS_COUNT=0
FAIL_COUNT=0
TENANT_CODE="ext-test-$(date +%s)"
make_request() {
local method=$1
local url=$2
local payload=$3
shift 3
local headers=("$@")
if [ "$method" = "GET" ]; then
curl -s -S -X GET "${headers[@]}" "$url"
elif [ -n "$payload" ]; then
curl -s -S -X "$method" "${headers[@]}" -H "Content-Type: application/json" -d "$payload" "$url"
else
curl -s -S -X "$method" "${headers[@]}" -H "Content-Type: application/json" "$url"
fi
}
assert_code_zero() {
local name=$1
local response=$2
local code
code=$(echo "$response" | jq -r '.code // .errcode // empty')
if [ "$code" = "0" ]; then
echo "[PASS] $name"
PASS_COUNT=$((PASS_COUNT + 1))
return 0
else
echo "[FAIL] $name (code=$code)"
echo " response: $response"
FAIL_COUNT=$((FAIL_COUNT + 1))
return 1
fi
}
# 1. Create tenant
echo "==> 1. Create tenant"
TENANT_RESPONSE=$(make_request POST "$BASE_URL/api/v1/account/tenant" \
'{"tenantCode":"'"$TENANT_CODE"'","tenantName":"External API Test"}')
assert_code_zero "Create tenant" "$TENANT_RESPONSE"
# 2. Create channel subject
echo "==> 2. Create channel subject"
SUBJECT_RESPONSE=$(make_request POST "$BASE_URL/api/v1/channel-subject" \
'{"channelType":"wecom","subjectCode":"sino","subjectName":"Sino Test"}' \
-H "X-Tenant-Code: $TENANT_CODE")
assert_code_zero "Create channel subject" "$SUBJECT_RESPONSE"
# 3. Create channel account
echo "==> 3. Create channel account"
ACCOUNT_RESPONSE=$(make_request POST "$BASE_URL/api/v1/channel-account" \
'{"accountType":1,"channelType":"wecom","accountId":"ZhangSan","accountName":"张三"}' \
-H "X-Tenant-Code: $TENANT_CODE")
assert_code_zero "Create channel account" "$ACCOUNT_RESPONSE"
ACCOUNT_ID=$(echo "$ACCOUNT_RESPONSE" | jq -r '.data.id')
# 4. Create conversation
echo "==> 4. Create conversation"
CONVERSATION_RESPONSE=$(make_request POST "$BASE_URL/api/v1/conversation" \
'{"conversationType":2,"channelType":"wecom","channelConversationId":"room-test-'"$(date +%s)"'","conversationName":"Test Group"}' \
-H "X-Tenant-Code: $TENANT_CODE")
assert_code_zero "Create conversation" "$CONVERSATION_RESPONSE"
CONVERSATION_ID=$(echo "$CONVERSATION_RESPONSE" | jq -r '.data.id')
# 5. Bind account to conversation
echo "==> 5. Bind account to conversation"
BIND_RESPONSE=$(make_request POST "$BASE_URL/api/v1/conversation/$CONVERSATION_ID/bind-account" \
"{\"accountId\":$ACCOUNT_ID,\"bindingType\":1,\"sortOrder\":1}" \
-H "X-Tenant-Code: $TENANT_CODE")
assert_code_zero "Bind account to conversation" "$BIND_RESPONSE"
# 6. Test send
echo "==> 6. Test send"
SEND_RESPONSE=$(make_request POST "$BASE_URL/api/v1/send/test" \
"{\"targetType\":\"conversation\",\"targetValue\":{\"conversation_id\":$CONVERSATION_ID},\"contentType\":\"text\",\"content\":{\"text\":\"hello from external api test\"},\"channelStrategy\":{\"channel_type\":\"wecom\",\"strategy\":\"primary\"}}" \
-H "X-Tenant-Code: $TENANT_CODE")
assert_code_zero "Test send" "$SEND_RESPONSE"
TASK_ID=$(echo "$SEND_RESPONSE" | jq -r '.data.taskId')
# 7. Query send records
echo "==> 7. Query send records"
RECORDS_RESPONSE=$(make_request GET "$BASE_URL/api/v1/send/$TASK_ID/records" "" \
-H "X-Tenant-Code: $TENANT_CODE")
assert_code_zero "Query send records" "$RECORDS_RESPONSE"
# 8. Receive inbound message
echo "==> 8. Receive inbound message"
EVENT_ID="evt-$(date +%s)-$RANDOM"
INBOUND_RESPONSE=$(make_request POST "$BASE_URL/api/v1/inbound/receive" \
"{\"eventId\":\"$EVENT_ID\",\"channelType\":\"wecom\",\"channelSubjectId\":1,\"eventType\":\"message\",\"messageSource\":\"realtime\",\"conversationId\":$CONVERSATION_ID,\"accountId\":$ACCOUNT_ID,\"content\":{\"text\":\"hello inbound\"},\"rawPayload\":{},\"businessContext\":{}}" \
-H "X-Tenant-Code: $TENANT_CODE")
assert_code_zero "Receive inbound message" "$INBOUND_RESPONSE"
# 9. Channel-service health
echo "==> 9. Channel-service health"
HEALTH_RESPONSE=$(curl -s -S "$CHANNEL_URL/health")
if echo "$HEALTH_RESPONSE" | jq -e '.status == "ok"' >/dev/null 2>&1; then
echo "[PASS] Channel-service health"
PASS_COUNT=$((PASS_COUNT + 1))
else
echo "[FAIL] Channel-service health"
echo " response: $HEALTH_RESPONSE"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
# 10. WeChat personal login start
echo "==> 10. WeChat personal login start"
LOGIN_RESPONSE=$(make_request POST "$CHANNEL_URL/v1/wechat-personal/login/start" \
'{"account_id":"bot-test-'"$(date +%s)"'","account_name":"Test Bot"}')
if echo "$LOGIN_RESPONSE" | jq -e '.login_id' >/dev/null 2>&1; then
echo "[PASS] WeChat personal login start"
PASS_COUNT=$((PASS_COUNT + 1))
else
echo "[FAIL] WeChat personal login start"
echo " response: $LOGIN_RESPONSE"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
# 11. WeChat personal send text (after confirming a login)
echo "==> 11. WeChat personal send text"
BOT_ID="bot-send-$(date +%s)"
make_request POST "$CHANNEL_URL/v1/wechat-personal/login/start" \
'{"account_id":"'"$BOT_ID"'"}' >/dev/null
make_request POST "$CHANNEL_URL/v1/wechat-personal/login/$BOT_ID/confirm" "{}" >/dev/null
SEND_TEXT_RESPONSE=$(make_request POST "$CHANNEL_URL/v1/wechat-personal/send/text" \
'{"account_id":"'"$BOT_ID"'","conversation_id":"room-test","text":"hello"}')
if echo "$SEND_TEXT_RESPONSE" | jq -e '.success == true' >/dev/null 2>&1; then
echo "[PASS] WeChat personal send text"
PASS_COUNT=$((PASS_COUNT + 1))
else
echo "[FAIL] WeChat personal send text"
echo " response: $SEND_TEXT_RESPONSE"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
echo ""
echo "========================="
echo "Total: $((PASS_COUNT + FAIL_COUNT)), Passed: $PASS_COUNT, Failed: $FAIL_COUNT"
echo "========================="
if [ "$FAIL_COUNT" -gt 0 ]; then
exit 1
fi