@@ -46,48 +46,54 @@ trap 'rm -f "$OUTFILE"' EXIT
46
46
echo " Using temporary output file: $OUTFILE "
47
47
48
48
# Add timeout configuration
49
- TIMEOUT=1800 # 3 minutes represented as 1800 tenths of a second
49
+ TIMEOUT=300 # 30 seconds represented as 1800 tenths of a second
50
50
INTERVAL=5 # Represent 0.5 seconds as 5 tenths of a second
51
51
TIMER=0
52
52
53
+ # Start the application and capture logs in the background
54
+ pnpm start --character=characters/trump.character.json > " $OUTFILE " 2>&1 &
55
+
56
+ APP_PID=$! # Capture the PID of the background process
57
+
53
58
(
54
59
# Wait for the ready message with timeout
55
60
while true ; do
56
61
if (( TIMER >= TIMEOUT )) ; then
57
- echo " Error: Timeout waiting for application to start after $(( TIMEOUT / 10 )) seconds"
58
- echo " Logs from $OUTFILE :"
59
- cat " $OUTFILE "
60
- pkill -f " pnpm start"
61
- exit 1
62
+ >&2 echo " ERROR: Timeout waiting for application to start after $(( TIMEOUT / 10 )) seconds"
63
+ kill $APP_PID # Terminate the pnpm process
64
+ exit 1
62
65
fi
63
66
64
- if grep -q " Chat started " " $OUTFILE " ; then
65
- echo " exit " ; sleep 2
66
- break
67
+ if grep -q " REST API bound to 0.0.0.0 " " $OUTFILE " ; then
68
+ >&2 echo " SUCCESS: Direct Client API is ready! Proceeding... "
69
+ break
67
70
fi
68
71
69
72
sleep 0.5
70
73
TIMER=$(( TIMER + INTERVAL))
71
74
done
72
- ) | pnpm start --character=characters/trump.character.json > " $OUTFILE " &
75
+ )
76
+
77
+ # Gracefully terminate the application if needed
78
+ kill $APP_PID
79
+ wait $APP_PID 2> /dev/null || true # Ensure the process is cleaned up
73
80
74
- # Wait for process to finish
75
- wait $!
76
81
RESULT=$?
77
82
83
+ # Output logs
78
84
echo " ----- OUTPUT START -----"
79
85
cat " $OUTFILE "
80
86
echo " ----- OUTPUT END -----"
81
87
82
- # Check the exit code of the last command
88
+ # Check the application exit code
83
89
if [[ $RESULT -ne 0 ]]; then
84
- echo " Error: 'start' command exited with an error (code: $RESULT )"
90
+ echo " Error: 'pnpm start' command exited with an error (code: $RESULT )"
85
91
exit 1
86
92
fi
87
93
88
- # Check if output contains expected termination message
89
- if grep -q " Terminating and cleaning up resources... " " $OUTFILE " ; then
90
- echo " Script completed successfully."
94
+ # Final validation
95
+ if grep -q " Server closed successfully " " $OUTFILE " ; then
96
+ echo " Smoke Test completed successfully."
91
97
else
92
98
echo " Error: The output does not contain the expected termination message."
93
99
exit 1
0 commit comments