|
| 1 | +#!/bin/bash |
| 2 | +# Test bot task list queries in various languages |
| 3 | + |
| 4 | +set -e |
| 5 | + |
| 6 | +PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 7 | +DEV_CONFIG_DIR="$PROJECT_ROOT/.dev-config" |
| 8 | + |
| 9 | +# Colors |
| 10 | +GREEN='\033[0;32m' |
| 11 | +RED='\033[0;31m' |
| 12 | +YELLOW='\033[1;33m' |
| 13 | +NC='\033[0m' |
| 14 | + |
| 15 | +# Get web port from config or use default |
| 16 | +WEB_PORT=${WEB_PORT:-19842} |
| 17 | + |
| 18 | +# Test queries in various languages |
| 19 | +QUERIES=( |
| 20 | + # English |
| 21 | + "list" |
| 22 | + "tasks" |
| 23 | + "status" |
| 24 | + "what tasks are running" |
| 25 | + "show me the tasks" |
| 26 | + "any active processes" |
| 27 | + |
| 28 | + # Chinese |
| 29 | + "任务" |
| 30 | + "列表" |
| 31 | + "状态" |
| 32 | + "有哪些任务" |
| 33 | + "现在有哪些任务" |
| 34 | + "目前有什么任务" |
| 35 | + "查看任务" |
| 36 | + "显示进程" |
| 37 | + |
| 38 | + # Japanese |
| 39 | + "タスク" |
| 40 | + "タスク一覧" |
| 41 | + "実行中のタスク" |
| 42 | + |
| 43 | + # Korean |
| 44 | + "작업 목록" |
| 45 | + "실행 중인 작업" |
| 46 | + |
| 47 | + # Spanish |
| 48 | + "tareas" |
| 49 | + "lista de tareas" |
| 50 | + "mostrar tareas" |
| 51 | +) |
| 52 | + |
| 53 | +echo -e "${YELLOW}Testing bot task list queries...${NC}" |
| 54 | +echo "Web port: $WEB_PORT" |
| 55 | +echo "" |
| 56 | + |
| 57 | +# First, register a fake session to have something to show |
| 58 | +echo -e "${YELLOW}Registering test session...${NC}" |
| 59 | +curl -s -X POST "http://127.0.0.1:$WEB_PORT/api/v1/daemon/sessions" \ |
| 60 | + -H "Content-Type: application/json" \ |
| 61 | + -d '{"session_id":"test-session-123","profile":"default","client_type":"claude-code"}' \ |
| 62 | + > /dev/null 2>&1 || true |
| 63 | +echo "" |
| 64 | + |
| 65 | +SESSION_ID="" |
| 66 | + |
| 67 | +for query in "${QUERIES[@]}"; do |
| 68 | + echo -e "${YELLOW}Query:${NC} $query" |
| 69 | + |
| 70 | + # Build request |
| 71 | + if [ -z "$SESSION_ID" ]; then |
| 72 | + REQUEST="{\"message\":\"$query\"}" |
| 73 | + else |
| 74 | + REQUEST="{\"message\":\"$query\",\"session_id\":\"$SESSION_ID\"}" |
| 75 | + fi |
| 76 | + |
| 77 | + # Send request and capture response |
| 78 | + RESPONSE=$(curl -s -X POST "http://127.0.0.1:$WEB_PORT/api/v1/bot/chat" \ |
| 79 | + -H "Content-Type: application/json" \ |
| 80 | + -d "$REQUEST" 2>&1) |
| 81 | + |
| 82 | + # Extract session ID from first response |
| 83 | + if [ -z "$SESSION_ID" ]; then |
| 84 | + SESSION_ID=$(echo "$RESPONSE" | grep -o '"session_id":"[^"]*"' | head -1 | cut -d'"' -f4) |
| 85 | + fi |
| 86 | + |
| 87 | + # Extract content from SSE response |
| 88 | + CONTENT=$(echo "$RESPONSE" | grep 'event: done' -A1 | grep 'data:' | sed 's/data: //' | jq -r '.content' 2>/dev/null || echo "$RESPONSE") |
| 89 | + |
| 90 | + # Check if response mentions tasks/processes |
| 91 | + if echo "$CONTENT" | grep -qiE '进程|任务|process|task|session|连接|idle|busy|waiting|没有'; then |
| 92 | + echo -e "${GREEN}✓ Response mentions tasks/processes${NC}" |
| 93 | + else |
| 94 | + echo -e "${RED}✗ Response does NOT mention tasks/processes${NC}" |
| 95 | + fi |
| 96 | + |
| 97 | + # Show first 200 chars of response |
| 98 | + echo -e "Response: ${CONTENT:0:200}..." |
| 99 | + echo "" |
| 100 | + |
| 101 | + # Clear session for next query to test fresh |
| 102 | + curl -s -X POST "http://127.0.0.1:$WEB_PORT/api/v1/bot/chat" \ |
| 103 | + -H "Content-Type: application/json" \ |
| 104 | + -d "{\"session_id\":\"$SESSION_ID\",\"clear\":true}" > /dev/null 2>&1 |
| 105 | + |
| 106 | + sleep 0.5 |
| 107 | +done |
| 108 | + |
| 109 | +echo -e "${GREEN}Done!${NC}" |
0 commit comments