tests.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/usr/bin/env bash
  2. # tests.sh — mem0server endpoint tests
  3. # Usage: bash tests.sh [BASE_URL]
  4. # Default base: http://192.168.0.200:8420
  5. BASE="${1:-http://192.168.0.200:8420}"
  6. PASS=0
  7. FAIL=0
  8. # Colours
  9. GREEN='\033[0;32m'
  10. RED='\033[0;31m'
  11. CYAN='\033[0;36m'
  12. BOLD='\033[1m'
  13. RESET='\033[0m'
  14. sep() { echo -e "\n${CYAN}${BOLD}━━━ $* ━━━${RESET}"; }
  15. ok() { echo -e "${GREEN}✓ $*${RESET}"; ((PASS++)); }
  16. fail() { echo -e "${RED}✗ $*${RESET}"; ((FAIL++)); }
  17. # Run curl, pretty-print with jq, check HTTP 200
  18. run() {
  19. local label="$1"; shift
  20. echo -e "\n${BOLD}▶ $label${RESET}"
  21. local body
  22. body=$(curl -s -w "\n__STATUS__%{http_code}" "$@")
  23. local status
  24. status=$(echo "$body" | tail -1 | sed 's/__STATUS__//')
  25. local json
  26. json=$(echo "$body" | sed '$d')
  27. echo "$json" | jq . 2>/dev/null || echo "$json"
  28. if [[ "$status" == "200" ]]; then
  29. ok "HTTP $status"
  30. else
  31. fail "HTTP $status"
  32. fi
  33. }
  34. # ─────────────────────────────────────────────
  35. sep "HEALTH"
  36. # ─────────────────────────────────────────────
  37. run "GET /health" \
  38. "$BASE/health"
  39. # ─────────────────────────────────────────────
  40. sep "/memories (conversational — OpenClaw)"
  41. # ─────────────────────────────────────────────
  42. run "POST /memories — plain text" \
  43. -X POST "$BASE/memories" \
  44. -H "Content-Type: application/json" \
  45. -d '{"text": "I love building AI agents and I prefer Python over JavaScript", "user_id": "testuser"}'
  46. run "POST /memories — messages array" \
  47. -X POST "$BASE/memories" \
  48. -H "Content-Type: application/json" \
  49. -d '{
  50. "messages": [{"role": "user", "content": "I have been using Vim for 10 years and hate GUI editors"}],
  51. "user_id": "testuser"
  52. }'
  53. run "POST /memories/search — programming preferences" \
  54. -X POST "$BASE/memories/search" \
  55. -H "Content-Type: application/json" \
  56. -d '{"query": "programming preferences", "user_id": "testuser", "limit": 5}'
  57. run "POST /memories/recent" \
  58. -X POST "$BASE/memories/recent" \
  59. -H "Content-Type: application/json" \
  60. -d '{"user_id": "testuser", "limit": 5}'
  61. # ─────────────────────────────────────────────
  62. sep "/knowledge (objective facts — book-ingestor)"
  63. # ─────────────────────────────────────────────
  64. run "POST /knowledge — Gesell with metadata (LLM extraction)" \
  65. -X POST "$BASE/knowledge" \
  66. -H "Content-Type: application/json" \
  67. -d '{
  68. "text": "Silvio Gesell proposed demurrage as a mechanism to discourage hoarding of currency. He described this in The Natural Economic Order published in 1916.",
  69. "user_id": "knowledge_base",
  70. "metadata": {"source_file": "gesell_neo.pdf", "chapter": 3, "page": 47}
  71. }'
  72. run "POST /knowledge — MIDI verbatim (infer:false)" \
  73. -X POST "$BASE/knowledge" \
  74. -H "Content-Type: application/json" \
  75. -d '{
  76. "text": "MIDI SysEx messages use a 7-bit checksum computed as the twos complement of the sum of all data bytes.",
  77. "user_id": "knowledge_base",
  78. "infer": false,
  79. "metadata": {"source_file": "midi_spec.pdf", "chapter": 9, "page": 112}
  80. }'
  81. run "POST /knowledge/search — Gesell demurrage (should NOT return MIDI)" \
  82. -X POST "$BASE/knowledge/search" \
  83. -H "Content-Type: application/json" \
  84. -d '{"query": "Gesell demurrage", "user_id": "knowledge_base", "limit": 5}'
  85. run "POST /knowledge/search — free money currency hoarding" \
  86. -X POST "$BASE/knowledge/search" \
  87. -H "Content-Type: application/json" \
  88. -d '{"query": "free money currency hoarding", "user_id": "knowledge_base", "limit": 5}'
  89. run "POST /knowledge/search — MIDI checksum (should NOT return Gesell)" \
  90. -X POST "$BASE/knowledge/search" \
  91. -H "Content-Type: application/json" \
  92. -d '{"query": "MIDI checksum SysEx", "user_id": "knowledge_base", "limit": 5}'
  93. run "POST /knowledge/recent" \
  94. -X POST "$BASE/knowledge/recent" \
  95. -H "Content-Type: application/json" \
  96. -d '{"user_id": "knowledge_base", "limit": 5}'
  97. # ─────────────────────────────────────────────
  98. sep "/search (merged — both collections)"
  99. # ─────────────────────────────────────────────
  100. run "POST /search — Python programming (expect _source tags on results)" \
  101. -X POST "$BASE/search" \
  102. -H "Content-Type: application/json" \
  103. -d '{"query": "Python programming", "user_id": "testuser", "limit": 8}'
  104. run "POST /search — Gesell economic theory (cross-collection)" \
  105. -X POST "$BASE/search" \
  106. -H "Content-Type: application/json" \
  107. -d '{"query": "Gesell economic theory", "user_id": "knowledge_base", "limit": 5}'
  108. # ─────────────────────────────────────────────
  109. sep "ERROR HANDLING"
  110. # ─────────────────────────────────────────────
  111. run "POST /memories — missing text/messages (expect 400)" \
  112. -X POST "$BASE/memories" \
  113. -H "Content-Type: application/json" \
  114. -d '{"user_id": "testuser"}'
  115. run "POST /memories — infer:false ignored on /memories (no verbatim)" \
  116. -X POST "$BASE/memories" \
  117. -H "Content-Type: application/json" \
  118. -d '{"text": "This should still go through LLM extraction", "user_id": "testuser", "infer": false}'
  119. # ─────────────────────────────────────────────
  120. sep "DELETE (comment out if you want to keep test data)"
  121. # ─────────────────────────────────────────────
  122. # Uncomment to clean up after testing:
  123. # run "DELETE /memories — testuser" \
  124. # -X DELETE "$BASE/memories" \
  125. # -H "Content-Type: application/json" \
  126. # -d '{"filter": {"user_id": "testuser"}}'
  127. #
  128. # run "DELETE /knowledge — knowledge_base" \
  129. # -X DELETE "$BASE/knowledge" \
  130. # -H "Content-Type: application/json" \
  131. # -d '{"filter": {"user_id": "knowledge_base"}}'
  132. # ─────────────────────────────────────────────
  133. sep "RESULTS"
  134. # ─────────────────────────────────────────────
  135. echo -e "\n${BOLD}Passed: ${GREEN}$PASS${RESET} ${BOLD}Failed: ${RED}$FAIL${RESET}\n"