Skip to content

Commit 0f5077c

Browse files
committed
adding the test running part
1 parent 8f51022 commit 0f5077c

File tree

2 files changed

+173
-2
lines changed

2 files changed

+173
-2
lines changed

.github/workflows/agentex-tutorials-test.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13+
- name: Checkout agentex-python repo
14+
uses: actions/checkout@v4
15+
1316
- name: Install UV
1417
run: |
1518
curl -LsSf https://astral.sh/uv/install.sh | sh
@@ -43,3 +46,103 @@ jobs:
4346
4447
# Verify all deps are up
4548
docker compose ps
49+
50+
- name: Run Parallel Tutorial Tests
51+
working-directory: .
52+
run: |
53+
54+
# Find all tutorial directories
55+
tutorial_paths=()
56+
for dir in $(find . -name "manifest.yaml" -exec dirname {} \; | sort); do
57+
tutorial_paths+=("${dir#./}") # Remove leading ./
58+
done
59+
60+
echo "Found ${#tutorial_paths[@]} tutorials:"
61+
printf ' %s\n' "${tutorial_paths[@]}"
62+
63+
# Run tests in parallel with unique ports
64+
pids=()
65+
failed_tests=()
66+
passed_tests=()
67+
68+
for i in "${!tutorial_paths[@]}"; do
69+
tutorial="${tutorial_paths[$i]}"
70+
port=$((8000 + i))
71+
72+
echo ""
73+
echo "========================================="
74+
echo "Starting test $((i+1))/${#tutorial_paths[@]}: $tutorial (port $port)"
75+
echo "========================================="
76+
77+
# Modify manifest.yaml to use unique port
78+
manifest_path="$tutorial/manifest.yaml"
79+
if [ -f "$manifest_path" ]; then
80+
# Backup original manifest
81+
cp "$manifest_path" "$manifest_path.backup"
82+
83+
# Update port in manifest (modify the line containing 'port: 8000' or 'port: XXXX')
84+
sed -i "s/port: [0-9]*/port: $port/" "$manifest_path"
85+
86+
echo "Updated $manifest_path to use port $port"
87+
fi
88+
89+
# Run test in background with unique port
90+
(
91+
cd "../../../agentex-python/examples/tutorials"
92+
AGENTEX_API_BASE_URL="http://localhost:5003" \
93+
./run_agent_test.sh "../../scale-agentex/agentex/examples/tutorials/$tutorial"
94+
95+
if [ $? -eq 0 ]; then
96+
echo "✅ PASSED: $tutorial (port $port)"
97+
echo "$tutorial" > "/tmp/passed_$i.txt"
98+
else
99+
echo "❌ FAILED: $tutorial (port $port)"
100+
echo "$tutorial" > "/tmp/failed_$i.txt"
101+
fi
102+
103+
# Restore original manifest
104+
cd "../../scale-agentex/agentex/examples/tutorials"
105+
if [ -f "$tutorial/manifest.yaml.backup" ]; then
106+
mv "$tutorial/manifest.yaml.backup" "$tutorial/manifest.yaml"
107+
fi
108+
) &
109+
110+
pids+=($!)
111+
done
112+
113+
# Wait for all tests to complete
114+
echo ""
115+
echo "Waiting for all tests to complete..."
116+
for pid in "${pids[@]}"; do
117+
wait "$pid"
118+
done
119+
120+
# Collect results
121+
for i in "${!tutorial_paths[@]}"; do
122+
if [ -f "/tmp/passed_$i.txt" ]; then
123+
passed_tests+=($(cat "/tmp/passed_$i.txt"))
124+
elif [ -f "/tmp/failed_$i.txt" ]; then
125+
failed_tests+=($(cat "/tmp/failed_$i.txt"))
126+
fi
127+
done
128+
129+
# Print summary
130+
echo ""
131+
echo "========================================="
132+
echo "TEST SUMMARY"
133+
echo "========================================="
134+
echo "Total: ${#tutorial_paths[@]}"
135+
echo "Passed: ${#passed_tests[@]}"
136+
echo "Failed: ${#failed_tests[@]}"
137+
138+
if [ ${#failed_tests[@]} -gt 0 ]; then
139+
echo ""
140+
echo "Failed tests:"
141+
for test in "${failed_tests[@]}"; do
142+
echo " ❌ $test"
143+
done
144+
exit 1
145+
else
146+
echo ""
147+
echo "🎉 All tests passed!"
148+
fi

examples/tutorials/run_agent_test.sh

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#
88
# Usage:
99
# ./run_agent_test.sh <tutorial_path> # Run single tutorial test
10+
# ./run_agent_test.sh --build-cli <tutorial_path> # Build CLI from source and run test
1011
# ./run_agent_test.sh --view-logs <tutorial_path> # View logs for specific tutorial
1112
# ./run_agent_test.sh --view-logs # View most recent agent logs
1213
#
@@ -28,10 +29,13 @@ AGENTEX_SERVER_PORT=5003
2829
# Parse arguments
2930
TUTORIAL_PATH=""
3031
VIEW_LOGS=false
32+
BUILD_CLI=false
3133

3234
for arg in "$@"; do
3335
if [[ "$arg" == "--view-logs" ]]; then
3436
VIEW_LOGS=true
37+
elif [[ "$arg" == "--build-cli" ]]; then
38+
BUILD_CLI=true
3539
else
3640
TUTORIAL_PATH="$arg"
3741
fi
@@ -105,7 +109,8 @@ start_agent() {
105109
cd "$tutorial_path" || return 1
106110

107111
# Start the agent in background and capture PID
108-
uv run agentex agents run --manifest manifest.yaml > "$logfile" 2>&1 &
112+
local agentex_cmd=$(get_agentex_command)
113+
$agentex_cmd agents run --manifest manifest.yaml > "$logfile" 2>&1 &
109114
local pid=$!
110115

111116
# Return to original directory
@@ -275,6 +280,58 @@ execute_tutorial_test() {
275280
fi
276281
}
277282

283+
# Function to build CLI from source
284+
build_cli() {
285+
echo -e "${YELLOW}🔨 Building CLI from source...${NC}"
286+
287+
# Navigate to the repo root (two levels up from examples/tutorials)
288+
local repo_root="../../"
289+
local original_dir="$PWD"
290+
291+
cd "$repo_root" || {
292+
echo -e "${RED}❌ Failed to navigate to repo root${NC}"
293+
return 1
294+
}
295+
296+
# Check if rye is available
297+
if ! command -v rye &> /dev/null; then
298+
echo -e "${RED}❌ rye is required to build the CLI${NC}"
299+
echo "Please install rye: curl -sSf https://rye.astral.sh/get | bash"
300+
cd "$original_dir"
301+
return 1
302+
fi
303+
304+
# Build the CLI
305+
echo -e "${YELLOW}Running rye sync --all-features...${NC}"
306+
if ! rye sync --all-features; then
307+
echo -e "${RED}❌ Failed to sync dependencies${NC}"
308+
cd "$original_dir"
309+
return 1
310+
fi
311+
312+
echo -e "${YELLOW}Running rye build...${NC}"
313+
if ! rye build; then
314+
echo -e "${RED}❌ Failed to build package${NC}"
315+
cd "$original_dir"
316+
return 1
317+
fi
318+
319+
echo -e "${GREEN}✅ CLI built successfully${NC}"
320+
cd "$original_dir"
321+
return 0
322+
}
323+
324+
# Function to get the appropriate agentex command
325+
get_agentex_command() {
326+
if [ "$BUILD_CLI" = true ]; then
327+
# Use the local build via rye run from repo root
328+
echo "../../rye run agentex"
329+
else
330+
# Use the system-installed version
331+
echo "uv run agentex"
332+
fi
333+
}
334+
278335
# Main execution function
279336
main() {
280337
# Handle --view-logs flag
@@ -293,11 +350,13 @@ main() {
293350
echo ""
294351
echo "Usage:"
295352
echo " ./run_agent_test.sh <tutorial_path> # Run single tutorial test"
353+
echo " ./run_agent_test.sh --build-cli <tutorial_path> # Build CLI from source and run test"
296354
echo " ./run_agent_test.sh --view-logs <tutorial_path> # View logs for specific tutorial"
297355
echo " ./run_agent_test.sh --view-logs # View most recent agent logs"
298356
echo ""
299-
echo "Example:"
357+
echo "Examples:"
300358
echo " ./run_agent_test.sh 00_sync/000_hello_acp"
359+
echo " ./run_agent_test.sh --build-cli 00_sync/000_hello_acp"
301360
exit 1
302361
fi
303362

@@ -311,6 +370,15 @@ main() {
311370

312371
echo ""
313372

373+
# Build CLI if requested
374+
if [ "$BUILD_CLI" = true ]; then
375+
if ! build_cli; then
376+
echo -e "${RED}❌ Failed to build CLI from source${NC}"
377+
exit 1
378+
fi
379+
echo ""
380+
fi
381+
314382
# Execute the single tutorial test
315383
if execute_tutorial_test "$TUTORIAL_PATH"; then
316384
echo ""

0 commit comments

Comments
 (0)