#!/bin/bash # Test Ledger API set -e PORT=8081 BASE_URL="http://localhost:${PORT}" echo "=== Testing Ledger API ===" # Start API in background export LEDGER_API_AUTH=false export LEDGER_API_PORT=$PORT cd /opt/agent-governance/ledger python3 api.py > /tmp/ledger-api.log 2>&1 & API_PID=$! sleep 3 cleanup() { kill $API_PID 2>/dev/null || true } trap cleanup EXIT # Test endpoints echo "" echo "1. Health Check:" curl -s "${BASE_URL}/health" echo "" echo "" echo "2. Root:" curl -s "${BASE_URL}/" echo "" echo "" echo "3. List Agents:" curl -s "${BASE_URL}/agents" echo "" echo "" echo "4. Get Stats:" curl -s "${BASE_URL}/stats" echo "" echo "" echo "5. Create Test Agent:" curl -s -X POST "${BASE_URL}/agents" \ -H "Content-Type: application/json" \ -d '{"agent_id":"api-test-agent","current_tier":0}' echo "" echo "" echo "6. List Violations:" curl -s "${BASE_URL}/violations" echo "" echo "" echo "7. List Promotions:" curl -s "${BASE_URL}/promotions" echo "" echo "" echo "8. Orchestration Summary:" curl -s "${BASE_URL}/orchestration/summary" echo "" echo "" echo "=== All Tests Complete ==="