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) <noreply@anthropic.com>
This commit is contained in:
Soumil Rathi
2026-04-13 13:10:17 -07:00
co-authored by Claude Opus 4.6
parent 78cc11ef1f
commit b9d7ae5fa7
2 changed files with 16 additions and 4 deletions
@@ -92,8 +92,12 @@ export async function waitForSearchResults(
maxRetries = 4, maxRetries = 4,
): Promise<Memory[]> { ): Promise<Memory[]> {
for (let attempt = 1; attempt <= maxRetries; attempt++) { for (let attempt = 1; attempt <= maxRetries; attempt++) {
const results = await withRetry(() => client.search(query, options)); const response = await withRetry(() => client.search(query, options));
if (Array.isArray(results) && results.length > 0) { // v3 returns { results: [...] }, unwrap for backward compat
const results = Array.isArray(response)
? response
: (response?.results ?? []);
if (results.length > 0) {
return results; return results;
} }
if (attempt < maxRetries) { if (attempt < maxRetries) {
@@ -108,22 +108,30 @@ describeIntegration("MemoryClient Integration — Search & History", () => {
// ─── Edge cases ───────────────────────────────────────── // ─── Edge cases ─────────────────────────────────────────
describe("edge cases", () => { describe("edge cases", () => {
test("search for non-existent user returns empty results", async () => { 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()}` }, filters: { userId: `nonexistent-user-${randomUUID()}` },
}); });
// v3 returns { results: [...] }
const results = Array.isArray(response)
? response
: (response?.results ?? []);
expect(Array.isArray(results)).toBe(true); expect(Array.isArray(results)).toBe(true);
expect(results.length).toBe(0); expect(results.length).toBe(0);
}); });
test("search with top_k param does not throw", async () => { 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", "Tell me about integration test user",
{ {
filters: { userId: TEST_USER_ID }, filters: { userId: TEST_USER_ID },
topK: 1, topK: 1,
}, },
); );
// v3 returns { results: [...] }
const results = Array.isArray(response)
? response
: (response?.results ?? []);
expect(Array.isArray(results)).toBe(true); expect(Array.isArray(results)).toBe(true);
}); });