forked from passeth/seedream_evasepic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli_ux.sh
More file actions
executable file
·157 lines (132 loc) · 5.7 KB
/
Copy pathtest_cli_ux.sh
File metadata and controls
executable file
·157 lines (132 loc) · 5.7 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
#!/bin/bash
# Test script to verify CLI UX enhancements (ANSI color codes)
set -u
SCRIPT_DIR="plugins/seedream-evasepic/skills/analyze-reference-video/scripts"
echo "=== Testing download-reference.sh ==="
bash "$SCRIPT_DIR/download-reference.sh"
echo "Exit code: $?"
echo "====================================="
echo "=== Testing extract-frames.sh ==="
bash "$SCRIPT_DIR/extract-frames.sh"
echo "Exit code: $?"
echo "====================================="
echo "=== Testing transcribe.sh ==="
bash "$SCRIPT_DIR/transcribe.sh"
echo "Exit code: $?"
echo "====================================="
echo "=== Testing yt-dlp argument separator ==="
TMP_DIR="$(mktemp -d)"
trap 'rm -rf -- "$TMP_DIR"' EXIT
cat > "$TMP_DIR/yt-dlp" <<'EOF'
#!/bin/bash
set -eu
printf '%s\n' "$@" > "${YT_DLP_ARGS_FILE:?}"
output=""
while [ "$#" -gt 0 ]; do
if [ "$1" = "-o" ]; then
shift
output="${1:-}"
break
fi
shift
done
if [ -n "$output" ]; then
mkdir -p -- "$(dirname -- "$output")"
: > "$output"
fi
EOF
chmod +x "$TMP_DIR/yt-dlp"
ARGS_FILE="$TMP_DIR/yt-dlp.args"
MALICIOUS_URL="--exec=touch /tmp/seedream-evasepic-pwned"
PATH="$TMP_DIR:$PATH" \
YT_DLP_ARGS_FILE="$ARGS_FILE" \
bash "$SCRIPT_DIR/download-reference.sh" "$MALICIOUS_URL" "$TMP_DIR/reference.mp4" >/dev/null
separator_line="$(grep -n -x -F -- "--" "$ARGS_FILE" | tail -n 1 | cut -d: -f1)"
url_line="$(grep -n -F -- "$MALICIOUS_URL" "$ARGS_FILE" | tail -n 1 | cut -d: -f1)"
if [ -z "$separator_line" ] || [ -z "$url_line" ] || [ "$url_line" -ne $((separator_line + 1)) ]; then
echo "FAIL: yt-dlp URL must be passed immediately after --" >&2
cat "$ARGS_FILE" >&2
exit 1
fi
echo "PASS: yt-dlp URL is protected by -- argument separator"
echo "====================================="
echo "=== Testing awk fallback variable binding ==="
if grep -n -F 'awk "BEGIN' "$SCRIPT_DIR/extract-frames.sh"; then
echo "FAIL: extract-frames.sh must not interpolate shell variables into an awk program string" >&2
exit 1
fi
if ! grep -n -F 'awk -v nf="$NUM_FRAMES" -v dur="$DURATION"' "$SCRIPT_DIR/extract-frames.sh"; then
echo "FAIL: extract-frames.sh must pass NUM_FRAMES and DURATION to awk with -v bindings" >&2
exit 1
fi
echo "PASS: awk fallback keeps dynamic values out of the awk program string"
echo "====================================="
echo "=== Testing error message clarity for missing arguments ==="
if ! bash "$SCRIPT_DIR/download-reference.sh" 2>&1 | grep -q "Error: Missing required argument(s)."; then
echo "FAIL: download-reference.sh did not print explicit error message" >&2
exit 1
fi
echo "PASS: download-reference.sh prints explicit error message"
echo "====================================="
echo "=== Testing usage block for invalid arguments ==="
if ! bash "$SCRIPT_DIR/transcribe.sh" "dummy.wav" "invalid_model" 2>&1 | grep -q "Usage: transcribe.sh <audio_path> \[model\]"; then
echo "FAIL: transcribe.sh did not print usage block for invalid model" >&2
exit 1
fi
echo "PASS: transcribe.sh prints usage block for invalid model"
if ! bash "$SCRIPT_DIR/extract-frames.sh" "dummy.mp4" "dummy_dir" "invalid_num" 2>&1 | grep -q "Usage: extract-frames.sh <video_path> <output_dir> \[num_frames\]"; then
echo "FAIL: extract-frames.sh did not print usage block for invalid num_frames" >&2
exit 1
fi
echo "PASS: extract-frames.sh prints usage block for invalid num_frames"
echo "====================================="
echo "=== Testing ANSI color codes in Python inline output ==="
if ! grep -q '\\033\[0;36mLoading whisper model' "$SCRIPT_DIR/transcribe.sh"; then
echo "FAIL: transcribe.sh Python inline script does not contain ANSI color for 'Loading whisper model'" >&2
exit 1
fi
if ! grep -q '\\033\[0;32mTranscript and segment files written' "$SCRIPT_DIR/transcribe.sh"; then
echo "FAIL: transcribe.sh Python inline script does not contain ANSI color for completion" >&2
exit 1
fi
echo "PASS: transcribe.sh Python inline script contains trusted ANSI color codes"
echo "====================================="
echo "=== Testing help flag position flexibility ==="
if ! bash "$SCRIPT_DIR/download-reference.sh" "dummy_url" "--help" | grep -q "Download Reference Video Script"; then
echo "FAIL: download-reference.sh did not recognize --help as second argument" >&2
exit 1
fi
echo "PASS: download-reference.sh recognizes --help at any position"
echo "====================================="
echo "=== Testing usage block on file not found error ==="
if ! bash "$SCRIPT_DIR/transcribe.sh" "dummy_nonexistent.wav" "base" 2>&1 | grep -q "Usage: transcribe.sh <audio_path> \[model\]"; then
echo "FAIL: transcribe.sh did not print usage block for file not found error" >&2
exit 1
fi
echo "PASS: transcribe.sh prints usage block for file not found error"
echo "====================================="
echo "=== Testing ffprobe dependency preflight ==="
DUMMY_VIDEO="$TMP_DIR/ffprobe-preflight.mp4"
: > "$DUMMY_VIDEO"
set +e
ffprobe_output="$(
FFMPEG="/bin/true" \
FFPROBE="$TMP_DIR/missing-ffprobe" \
bash "$SCRIPT_DIR/extract-frames.sh" "$DUMMY_VIDEO" "$TMP_DIR/ffprobe-output" 12 2>&1
)"
ffprobe_status=$?
set -e
if [ "$ffprobe_status" -ne 1 ] || ! grep -q -F "Error: ffprobe not found." <<< "$ffprobe_output"; then
echo "FAIL: extract-frames.sh must fail before probing when ffprobe is unavailable" >&2
printf '%s\n' "$ffprobe_output" >&2
exit 1
fi
if ! grep -q -F "Install with: brew install ffmpeg" <<< "$ffprobe_output"; then
echo "FAIL: ffprobe preflight must provide an actionable installation command" >&2
exit 1
fi
echo "PASS: extract-frames.sh reports a missing ffprobe before metadata processing"
echo "====================================="
echo "=== Testing actual terminal control neutralization ==="
bash ./test_terminal_output.sh
echo "====================================="