Explorar el Código

Add /memories/raw created_at test

Lukas Goldschmidt hace 1 mes
padre
commit
c2a0457fe1
Se han modificado 1 ficheros con 31 adiciones y 2 borrados
  1. 31 2
      tests.sh

+ 31 - 2
tests.sh

@@ -92,6 +92,32 @@ run "POST /memories/all" \
   -d '{"user_id": "testuser"}'
 assert_json "memories/all returns array" '.results | type == "array"'
 
+RAW_MARKER="mem0-raw-created-at"
+RAW_TS="2020-01-02T03:04:05Z"
+run "POST /memories/raw — created_at override" \
+  -X POST "$BASE/memories/raw" \
+  -H "Content-Type: application/json" \
+  -d "{\"text\": \"${RAW_MARKER} override timestamp check\", \"user_id\": \"testuser\", \"metadata\": {\"created_at\": \"${RAW_TS}\", \"source\": \"tests\"}}"
+
+run "POST /memories/all — after raw insert" \
+  -X POST "$BASE/memories/all" \
+  -H "Content-Type: application/json" \
+  -d '{"user_id": "testuser"}'
+assert_json "memories/all after raw returns array" '.results | type == "array"'
+
+RAW_ID=$(echo "$LAST_JSON" | jq -r --arg marker "$RAW_MARKER" '.results[] | select(.memory | contains($marker)) | .id' | head -n1)
+RAW_CREATED=$(echo "$LAST_JSON" | jq -r --arg marker "$RAW_MARKER" '.results[] | select(.memory | contains($marker)) | .created_at' | head -n1)
+if [[ -n "$RAW_ID" ]]; then
+  ok "captured raw memory ID"
+else
+  fail "raw memory ID missing"
+fi
+if [[ "$RAW_CREATED" == "$RAW_TS" ]]; then
+  ok "raw memory created_at override respected"
+else
+  fail "raw memory created_at override missing (got '$RAW_CREATED')"
+fi
+
 run "POST /memories/search — capture marker" \
   -X POST "$BASE/memories/search" \
   -H "Content-Type: application/json" \
@@ -117,8 +143,11 @@ run "POST /memories/recent" \
   -d '{"user_id": "testuser", "limit": 5}'
 assert_json "memories recent returns array" '.results | type == "array"'
 
-if [[ -n "$MEMORY_IDS" ]]; then
-  for id in $MEMORY_IDS; do
+if [[ -n "$MEMORY_IDS" || -n "$RAW_ID" ]]; then
+  for id in $MEMORY_IDS $RAW_ID; do
+    if [[ -z "$id" ]]; then
+      continue
+    fi
     run "DELETE /memory/$id" \
       -X DELETE "$BASE/memory/$id" \
       -H "Content-Type: application/json" \