Skip to content

Commit 2e294a4

Browse files
committed
Refactor terminal handling with clean helper functions
- Add is_terminal() to check terminal capabilities - Add safe_tput() wrapper for terminal commands - Remove repetitive terminal checks throughout code - Keep animation for local development, skip in CI - Fixes 'No value for xterm-256color' errors in GitHub Actions
1 parent c7eddce commit 2e294a4

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

integration/run_tests.sh

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ NC='\033[0m' # No Color
1212
# Change to integration directory
1313
cd "$(dirname "$0")"
1414

15+
# Check if we're in a terminal with proper capabilities
16+
is_terminal() {
17+
[ -t 1 ] && [ -n "$TERM" ]
18+
}
19+
20+
# Safe tput wrapper
21+
safe_tput() {
22+
if is_terminal; then
23+
tput "$@" 2>/dev/null || true
24+
fi
25+
}
26+
1527
# Docker compose command wrapper
1628
docker_compose() {
1729
if docker compose version &>/dev/null 2>&1; then
@@ -72,7 +84,7 @@ show_animation() {
7284
local frame=0
7385

7486
# Hide cursor
75-
tput civis
87+
safe_tput civis
7688

7789
while true; do
7890
printf "\r ${spinners[$((frame % ${#spinners[@]}))]} Running tests..."
@@ -86,27 +98,36 @@ run_tests() {
8698
# Create a log file for mcp-front output
8799
export MCP_LOG_FILE="/tmp/mcp-front-test.log"
88100

89-
# Start animation in background
90-
show_animation &
91-
local anim_pid=$!
101+
# Start animation in background (skip in CI)
102+
local anim_pid=""
103+
if is_terminal; then
104+
show_animation &
105+
anim_pid=$!
106+
else
107+
echo " Running tests..."
108+
fi
92109

93110
# Run tests, capturing output
94111
if go test -timeout 15m &>/tmp/test-output.log; then
95112
# Kill animation and clear line
96-
kill $anim_pid 2>/dev/null || true
97-
wait $anim_pid 2>/dev/null || true
98-
printf "\r\033[K"
99-
tput cnorm # Show cursor again
113+
if [ -n "$anim_pid" ]; then
114+
kill $anim_pid 2>/dev/null || true
115+
wait $anim_pid 2>/dev/null || true
116+
printf "\r\033[K"
117+
fi
118+
safe_tput cnorm # Show cursor again
100119

101120
# Success - print minimal output
102121
echo -e "${GREEN}✓ All tests passed${NC}"
103122
return 0
104123
else
105124
# Kill animation and clear line
106-
kill $anim_pid 2>/dev/null || true
107-
wait $anim_pid 2>/dev/null || true
108-
printf "\r\033[K"
109-
tput cnorm # Show cursor again
125+
if [ -n "$anim_pid" ]; then
126+
kill $anim_pid 2>/dev/null || true
127+
wait $anim_pid 2>/dev/null || true
128+
printf "\r\033[K"
129+
fi
130+
safe_tput cnorm # Show cursor again
110131
# Failure - show details
111132
echo -e "${RED}❌ Tests failed${NC}"
112133
echo ""

0 commit comments

Comments
 (0)