tests.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. PORT="${MCP_PORT:-${PORT:-8550}}"
  4. URL="${ATLAS_HEALTH_URL:-http://127.0.0.1:${PORT}/health}"
  5. ENTITY_SUBJECT="${ATLAS_TEST_SUBJECT:-Joe Biden}"
  6. DEBUG_PATH="${ATLAS_TEST_DEBUG_PATH:-/tmp/atlas-debug/${ENTITY_SUBJECT// /_}.ttl}"
  7. log() {
  8. printf '\n[%s] %s\n' "$(date +'%H:%M:%S')" "$1"
  9. }
  10. if ! command -v curl >/dev/null 2>&1; then
  11. echo "curl is required for tests.sh"
  12. exit 1
  13. fi
  14. if ! command -v jq >/dev/null 2>&1; then
  15. echo "jq is required for tests.sh"
  16. exit 1
  17. fi
  18. if ! command -v mcporter >/dev/null 2>&1; then
  19. echo "mcporter is required for tests.sh"
  20. exit 1
  21. fi
  22. log "1) Checking Atlas health endpoint"
  23. health_response="$(curl -fsS "$URL")"
  24. echo "$health_response" | jq
  25. if ! printf '%s' "$health_response" | grep -q '"status":"ok"'; then
  26. echo "Expected health status ok"
  27. exit 1
  28. fi
  29. if ! printf '%s' "$health_response" | grep -q '"tools"'; then
  30. echo "Expected tools in health response"
  31. exit 1
  32. fi
  33. if [[ -n "${CONFIG:-}" ]]; then
  34. log "2) Resolving a known entity via mcporter"
  35. resolve_out="$({ mcporter --config "$CONFIG" call atlas.resolve_entity subject="$ENTITY_SUBJECT" debug=true debug_path="$DEBUG_PATH"; } 2>&1)"
  36. printf '%s\n' "$resolve_out"
  37. if ! printf '%s' "$resolve_out" | grep -q '"canonical_label"'; then
  38. echo "Expected canonical_label in resolve output"
  39. exit 1
  40. fi
  41. if ! printf '%s' "$resolve_out" | grep -q '"wikidata_payload"'; then
  42. echo "Expected wikidata_payload in resolve output"
  43. exit 1
  44. fi
  45. if ! printf '%s' "$resolve_out" | grep -q '"raw_claims"'; then
  46. echo "Expected raw_claims in debug output"
  47. exit 1
  48. fi
  49. if ! printf '%s' "$resolve_out" | grep -q '"derived_claims"'; then
  50. echo "Expected derived_claims in debug output"
  51. exit 1
  52. fi
  53. if [[ -f "$DEBUG_PATH" ]]; then
  54. log "3) Debug Turtle dumped to $DEBUG_PATH"
  55. head -n 40 "$DEBUG_PATH"
  56. else
  57. echo "Expected debug Turtle at $DEBUG_PATH"
  58. exit 1
  59. fi
  60. else
  61. log "2) CONFIG not set, skipping mcporter resolve smoke test"
  62. fi
  63. log "All Atlas checks passed."