瀏覽代碼

Add cleanup to test script

Lukas Goldschmidt 1 月之前
父節點
當前提交
4f466a8d10
共有 1 個文件被更改,包括 19 次插入0 次删除
  1. 19 0
      test_memories.mjs

+ 19 - 0
test_memories.mjs

@@ -8,6 +8,8 @@ async function run() {
   const timestamp = new Date().toISOString();
   const text = `openclaw-mem0-python plugin test at ${timestamp}`;
 
+  const baseUrl = process.env.MEM0_BASE_URL || "http://192.168.0.200:8420";
+
   console.log("Writing memory...");
   const writeResult = await plugin.write({ text, userId });
   console.log("Write result:", writeResult);
@@ -40,6 +42,23 @@ async function run() {
   } else {
     console.log("No knowledge sources found; skipping book tests.");
   }
+
+  console.log("Cleaning up test memories...");
+  const allRes = await fetch(`${baseUrl}/memories/all`, {
+    method: "POST",
+    headers: { "Content-Type": "application/json" },
+    body: JSON.stringify({ user_id: userId }),
+  }).then((r) => r.json());
+
+  const ids = (allRes?.results || []).map((r) => r.id).filter(Boolean);
+  for (const id of ids) {
+    await fetch(`${baseUrl}/memory/${id}`, {
+      method: "DELETE",
+      headers: { "Content-Type": "application/json" },
+      body: JSON.stringify({ collection: "conversational" }),
+    });
+  }
+  console.log(`Cleanup done (${ids.length} deleted).`);
 }
 
 run().catch((err) => {