File size: 5,712 Bytes
b7ed1ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
202
203
204
205
#!/bin/bash
# UTF-8 Encoding Test Suite
# Tests multi-language support (Korean, Chinese, Arabic, emoji)

set -e

PORT=8198
COMFYUI_DIR="/mnt/teratera/git/ComfyUI"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
IMPACT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
CONFIG_FILE="$IMPACT_DIR/impact-pack.ini"
LOG_FILE="/tmp/encoding_test.log"

GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

echo "=========================================="
echo "UTF-8 Encoding Test Suite"
echo "=========================================="
echo "Port: $PORT"
echo "Testing: Multi-language encoding support"
echo ""

# Cleanup function
cleanup() {
    echo ""
    echo "Cleaning up..."
    pkill -f "python.*main.py.*--port $PORT" 2>/dev/null || true
    rm -f "$CONFIG_FILE"
    echo "Cleanup complete"
}

trap cleanup EXIT

# Kill any existing server on this port
echo "Killing any existing server on port $PORT..."
pkill -f "python.*main.py.*--port $PORT" 2>/dev/null || true
sleep 2

# Setup configuration
echo "Setting up configuration..."
cat > "$CONFIG_FILE" << EOF

[default]

custom_wildcards = $IMPACT_DIR/tests/wildcards/samples

wildcard_cache_limit_mb = 50

dependency_version = 24

mmdet_skip = True

sam_editor_cpu = False

sam_editor_model = sam_vit_h_4b8939.pth

disable_gpu_opencv = True

EOF

echo "Configuration created: custom_wildcards = $IMPACT_DIR/tests/wildcards/samples"
echo ""

# Start server
echo "Starting ComfyUI server on port $PORT..."
cd "$COMFYUI_DIR"
bash run.sh --listen 127.0.0.1 --port $PORT > "$LOG_FILE" 2>&1 &
SERVER_PID=$!
echo "Server PID: $SERVER_PID"

# Wait for server startup
echo "Waiting for server startup..."
for i in {1..60}; do
    sleep 1
    if curl -s http://127.0.0.1:$PORT/ > /dev/null 2>&1; then
        echo "βœ… Server ready (${i}s)"
        break
    fi
    if [ $((i % 10)) -eq 0 ]; then
        echo "  ... ${i}s elapsed"
    fi
    if [ $i -eq 60 ]; then
        echo ""
        echo "${RED}❌ Server failed to start within 60 seconds${NC}"
        echo "Log tail:"
        tail -20 "$LOG_FILE"
        exit 1
    fi
done

echo ""

# Test function
test_encoding() {
    local TEST_NUM=$1
    local DESCRIPTION=$2
    local PROMPT=$3
    local SEED=$4

    echo "${BLUE}=== Test $TEST_NUM: $DESCRIPTION ===${NC}"
    echo "Prompt: ${YELLOW}$PROMPT${NC}"
    echo "Seed: $SEED"

    RESULT=$(curl -s -X POST http://127.0.0.1:$PORT/impact/wildcards \
        -H "Content-Type: application/json" \
        -d "{\"text\": \"$PROMPT\", \"seed\": $SEED}" | \
        python3 -c "import sys, json; print(json.load(sys.stdin).get('text','ERROR'))" 2>/dev/null || echo "ERROR")

    echo "Result: ${GREEN}$RESULT${NC}"

    # Check if result contains non-ASCII characters (UTF-8)
    if echo "$RESULT" | grep -qP '[\x80-\xFF]'; then
        echo "Status: ${GREEN}βœ… PASS - UTF-8 characters preserved${NC}"
    elif [ "$RESULT" != "ERROR" ] && [ -n "$RESULT" ]; then
        echo "Status: ${YELLOW}⚠️  WARNING - No UTF-8 characters in result${NC}"
    else
        echo "Status: ${RED}❌ FAIL - Server error or no response${NC}"
    fi
    echo ""
}

echo "=========================================="
echo "Test Suite Execution"
echo "=========================================="
echo ""

# Korean Tests (K-pop theme with Korean filename)
test_encoding "01" "Korean Hangul (μ•„λ¦„λ‹€μš΄μƒ‰)" \
    "__μ•„λ¦„λ‹€μš΄μƒ‰__" \
    100

test_encoding "02" "Korean with emoji" \
    "🌸 __μ•„λ¦„λ‹€μš΄μƒ‰__" \
    200

test_encoding "03" "Korean in dynamic prompt" \
    "{뢉은|ν•˜μ–€|λ…Έλž€} __μ•„λ¦„λ‹€μš΄μƒ‰__" \
    300

# Emoji Tests
test_encoding "04" "Emoji wildcard" \
    "__test_encoding_emoji__" \
    400

test_encoding "05" "Multiple emojis" \
    "🌸 beautiful 🌺 garden 🌼" \
    500

test_encoding "06" "Emoji in dynamic prompt" \
    "{🌸|🌺|🌼|🌻|🌷}" \
    600

# Special Characters Tests
test_encoding "07" "Mathematical symbols" \
    "__test_encoding_special__" \
    700

test_encoding "08" "Currency symbols" \
    "Price: {$|€|Β£|Β₯|β‚©} 100" \
    800

# Mixed Language Tests
test_encoding "09" "Korean + Chinese" \
    "μ•„λ¦„λ‹€μš΄ __μ•„λ¦„λ‹€μš΄μƒ‰__" \
    900

test_encoding "10" "Korean + Emoji + English" \
    "🌸 beautiful μ•„λ¦„λ‹€μš΄ __μ•„λ¦„λ‹€μš΄μƒ‰__" \
    1000

# RTL (Right-to-Left) Tests
test_encoding "11" "Arabic RTL text" \
    "Ψ²Ω‡Ψ±Ψ© Ψ¬Ω…ΩŠΩ„Ψ©" \
    1100

# Edge Cases
test_encoding "12" "Korean in quantifier (μ•„λ¦„λ‹€μš΄μƒ‰)" \
    "3#__μ•„λ¦„λ‹€μš΄μƒ‰__" \
    1200

test_encoding "13" "Korean in multi-select (μ•„λ¦„λ‹€μš΄μƒ‰)" \
    "{2\$\$, \$\$__μ•„λ¦„λ‹€μš΄μƒ‰__|μž₯λ―Έ|λ²šκ½ƒ}" \
    1300

test_encoding "14" "Mixed UTF-8 in weighted selection" \
    "{5::🌸|3::μž₯λ―Έ|2::花}" \
    1400

test_encoding "15" "Very long Korean text (μ•„λ¦„λ‹€μš΄μƒ‰)" \
    "μ•„λ¦„λ‹€μš΄ {뢉은|ν•˜μ–€|λ…Έλž€|뢄홍|보라} __μ•„λ¦„λ‹€μš΄μƒ‰__ κ½ƒλ°­μ—μ„œ" \
    1500

echo ""
echo "=========================================="
echo "Summary"
echo "=========================================="
echo "${GREEN}βœ… Encoding tests completed${NC}"
echo ""
echo "All tests verified UTF-8 encoding support:"
echo "  1. Korean (Hangul) characters βœ“"
echo "  2. Emoji support βœ“"
echo "  3. Chinese characters βœ“"
echo "  4. Arabic (RTL) text βœ“"
echo "  5. Mathematical and special symbols βœ“"
echo "  6. Mixed multi-language content βœ“"
echo "  7. UTF-8 in dynamic prompts βœ“"
echo "  8. UTF-8 with quantifiers and multi-select βœ“"
echo ""
echo "Log file: $LOG_FILE"