Skip to content

Commit 1a15617

Browse files
committed
Adding test
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
1 parent 1c22632 commit 1a15617

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

.github/workflows/test.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Test CAgent Action
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
test-pirate-agent:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Run pirate agent
17+
id: pirate
18+
uses: ./
19+
with:
20+
agent: agentcatalog/pirate
21+
prompt: "What do we ship today?"
22+
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
23+
24+
- name: Validate output and exit code
25+
run: |
26+
OUTPUT_FILE="${{ steps.pirate.outputs.output-file }}"
27+
28+
# Check that exit code is 0 (success)
29+
if [ "${{ steps.pirate.outputs.exit-code }}" != "0" ]; then
30+
echo "❌ Agent failed with exit code: ${{ steps.pirate.outputs.exit-code }}"
31+
exit 1
32+
fi
33+
echo "✅ Agent completed successfully with exit code 0"
34+
35+
# Check that output file exists
36+
if [ ! -f "$OUTPUT_FILE" ]; then
37+
echo "❌ Output file not found: $OUTPUT_FILE"
38+
exit 1
39+
fi
40+
echo "✅ Output file found: $OUTPUT_FILE"
41+
42+
# Display the output for debugging
43+
echo "--- Agent Output ---"
44+
cat "$OUTPUT_FILE"
45+
echo "--- End Output ---"
46+
47+
# Check that output contains "--- Agent: root ---"
48+
if ! grep -q "--- Agent: root ---" "$OUTPUT_FILE"; then
49+
echo "❌ Output does not contain '--- Agent: root ---'"
50+
exit 1
51+
fi
52+
echo "✅ Found '--- Agent: root ---' in output"
53+
54+
# Check that there is text after "--- Agent: root ---"
55+
# Extract everything after "--- Agent: root ---" and check if it has non-empty content
56+
AFTER_AGENT=$(sed -n '/--- Agent: root ---/,$p' "$OUTPUT_FILE" | tail -n +2 | grep -v '^$' | grep -v 'Cleaning up')
57+
58+
if [ -z "$AFTER_AGENT" ]; then
59+
echo "❌ No output found after '--- Agent: root ---'"
60+
exit 1
61+
fi
62+
63+
echo "✅ Found agent response after '--- Agent: root ---'"
64+
echo "Response preview: $(echo "$AFTER_AGENT" | head -n 1)"
65+
66+
- name: Test should fail on invalid agent
67+
id: invalid-agent
68+
continue-on-error: true
69+
uses: ./
70+
with:
71+
agent: agentcatalog/nonexistent
72+
prompt: "This should fail"
73+
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
74+
75+
- name: Verify invalid agent failed
76+
run: |
77+
if [ "${{ steps.invalid-agent.outputs.exit-code }}" == "0" ]; then
78+
echo "❌ Invalid agent should have failed but succeeded"
79+
exit 1
80+
fi
81+
echo "✅ Invalid agent correctly failed"

action.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ outputs:
5454
exit-code:
5555
description: 'Exit code from cagent run'
5656
value: ${{ steps.run-agent.outputs.exit-code }}
57+
output-file:
58+
description: 'Path to the output log file'
59+
value: ${{ steps.run-agent.outputs.output-file }}
5760

5861
runs:
5962
using: 'composite'
@@ -112,8 +115,12 @@ runs:
112115
fi
113116
114117
echo "Running: $CMD"
115-
eval $CMD
116-
EXIT_CODE=$?
118+
119+
# Capture output to both console and file
120+
OUTPUT_FILE="/tmp/cagent-output-$$.log"
121+
eval $CMD 2>&1 | tee "$OUTPUT_FILE"
122+
EXIT_CODE=${PIPESTATUS[0]}
117123
118124
echo "exit-code=$EXIT_CODE" >> $GITHUB_OUTPUT
125+
echo "output-file=$OUTPUT_FILE" >> $GITHUB_OUTPUT
119126
exit $EXIT_CODE

0 commit comments

Comments
 (0)