From b9d7ae5fa7cbcb49b926c769f007b578c4709e35 Mon Sep 17 00:00:00 2001 From: Soumil Rathi Date: Mon, 13 Apr 2026 13:10:17 -0700 Subject: [PATCH] fix: update integration tests for v3 search response format v3 search returns {results: [...]} instead of a bare array. Updated waitForSearchResults helper and search edge case tests to unwrap the v3 envelope. Co-Authored-By: Claude Opus 4.6 (1M context) --- mem0-ts/src/client/tests/integration/helpers.ts | 8 ++++++-- mem0-ts/src/client/tests/integration/search.test.ts | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/mem0-ts/src/client/tests/integration/helpers.ts b/mem0-ts/src/client/tests/integration/helpers.ts index c85baa189..1eb137264 100644 --- a/mem0-ts/src/client/tests/integration/helpers.ts +++ b/mem0-ts/src/client/tests/integration/helpers.ts @@ -92,8 +92,12 @@ export async function waitForSearchResults( maxRetries = 4, ): Promise { for (let attempt = 1; attempt <= maxRetries; attempt++) { - const results = await withRetry(() => client.search(query, options)); - if (Array.isArray(results) && results.length > 0) { + const response = await withRetry(() => client.search(query, options)); + // v3 returns { results: [...] }, unwrap for backward compat + const results = Array.isArray(response) + ? response + : (response?.results ?? []); + if (results.length > 0) { return results; } if (attempt < maxRetries) { diff --git a/mem0-ts/src/client/tests/integration/search.test.ts b/mem0-ts/src/client/tests/integration/search.test.ts index 1f3e9cf89..9f3a51610 100644 --- a/mem0-ts/src/client/tests/integration/search.test.ts +++ b/mem0-ts/src/client/tests/integration/search.test.ts @@ -108,22 +108,30 @@ describeIntegration("MemoryClient Integration — Search & History", () => { // ─── Edge cases ───────────────────────────────────────── describe("edge cases", () => { test("search for non-existent user returns empty results", async () => { - const results = await client.search("anything", { + const response = await client.search("anything", { filters: { userId: `nonexistent-user-${randomUUID()}` }, }); + // v3 returns { results: [...] } + const results = Array.isArray(response) + ? response + : (response?.results ?? []); expect(Array.isArray(results)).toBe(true); expect(results.length).toBe(0); }); test("search with top_k param does not throw", async () => { - const results = await client.search( + const response = await client.search( "Tell me about integration test user", { filters: { userId: TEST_USER_ID }, topK: 1, }, ); + // v3 returns { results: [...] } + const results = Array.isArray(response) + ? response + : (response?.results ?? []); expect(Array.isArray(results)).toBe(true); });