Skip to content

Commit 579dc50

Browse files
authored
Merge pull request #1046 from aramxc/add-improved-logging-to-smokeTests
chore: improve smokeTests environment validation and logging
2 parents eecaa73 + 9f39f4a commit 579dc50

File tree

2 files changed

+59
-24
lines changed

2 files changed

+59
-24
lines changed

pnpm-lock.yaml

+30-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/smokeTests.sh

+29-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Strict mode, exit on error, undefined variables, and pipe failures
4+
set -euo pipefail
5+
36
# Print some information about the environment to aid in case of troubleshooting
47

58
echo "node version:"
@@ -27,60 +30,63 @@ if (( CURRENT_NODE_VERSION < REQUIRED_NODE_VERSION )); then
2730
fi
2831

2932
# Autodetect project directory relative to this script's path
30-
PROJECT_DIR="$0"
31-
while [ -h "$PROJECT_DIR" ]; do
32-
ls=$(ls -ld "$PROJECT_DIR")
33-
link=$(expr "$ls" : '.*-> \(.*\)$')
34-
if expr "$link" : '/.*' > /dev/null; then
35-
PROJECT_DIR="$link"
36-
else
37-
PROJECT_DIR="$(dirname "$PROJECT_DIR")/$link"
38-
fi
39-
done
40-
PROJECT_DIR="$(dirname "$PROJECT_DIR")/.."
41-
PROJECT_DIR="$(cd "$PROJECT_DIR"; pwd)"
33+
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
4234

43-
cd $PROJECT_DIR
35+
cd "$PROJECT_DIR"
4436

4537
cp .env.example .env
4638

4739
pnpm install -r
4840

4941
pnpm build
5042

43+
# Create temp file and ensure cleanup
5144
OUTFILE="$(mktemp)"
52-
echo $OUTFILE
45+
trap 'rm -f "$OUTFILE"' EXIT
46+
echo "Using temporary output file: $OUTFILE"
47+
48+
# Add timeout configuration
49+
TIMEOUT=30
50+
INTERVAL=0.5
51+
TIMER=0
52+
5353
(
54-
# Wait for the ready message
54+
# Wait for the ready message with timeout
5555
while true; do
56+
if [[ $TIMER -ge $TIMEOUT ]]; then
57+
echo "Error: Timeout waiting for application to start after $TIMEOUT seconds"
58+
kill $$
59+
exit 1
60+
fi
61+
5662
if grep -q "Chat started" "$OUTFILE"; then
5763
echo "exit"; sleep 2
5864
break
5965
fi
60-
sleep 0.5
66+
67+
sleep $INTERVAL
68+
TIMER=$(echo "$TIMER + $INTERVAL" | bc)
6169
done
6270
) | pnpm start --character=characters/trump.character.json > "$OUTFILE" &
6371

6472
# Wait for process to finish
6573
wait $!
6674
RESULT=$?
75+
6776
echo "----- OUTPUT START -----"
6877
cat "$OUTFILE"
6978
echo "----- OUTPUT END -----"
7079

7180
# Check the exit code of the last command
7281
if [[ $RESULT -ne 0 ]]; then
73-
echo "Error: 'start' command exited with an error."
82+
echo "Error: 'start' command exited with an error (code: $RESULT)"
7483
exit 1
7584
fi
7685

77-
# Check if output.txt contains "Terminating and cleaning up resources..."
86+
# Check if output contains expected termination message
7887
if grep -q "Terminating and cleaning up resources..." "$OUTFILE"; then
7988
echo "Script completed successfully."
8089
else
81-
echo "Error: The output does not contain the expected string."
90+
echo "Error: The output does not contain the expected termination message."
8291
exit 1
83-
fi
84-
85-
# Clean up
86-
rm "$OUTFILE"
92+
fi

0 commit comments

Comments
 (0)