|
| 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" |
0 commit comments