Skip to content

chore: end to end test coverage for ts sdk#4357

Merged
whysosaket merged 15 commits intomainfrom
feat/ts-sdk-revamp-v2.5
Mar 17, 2026
Merged

chore: end to end test coverage for ts sdk#4357
whysosaket merged 15 commits intomainfrom
feat/ts-sdk-revamp-v2.5

Conversation

@kartik-mem0
Copy link
Copy Markdown
Contributor

@kartik-mem0 kartik-mem0 commented Mar 16, 2026

What this PR does

  • 474 tests passing, 0 failures, across 26 test suites
  • Fixes 2 bugs: getAll() and search() crash without options (options! → options ?? {})
  • Wires structured exception hierarchy into _fetchWithErrorHandling (404→MemoryNotFoundError, 401→AuthenticationError, etc.)
  • Exports WebhookEvent enum (was non-exported, forcing as never casts)
  • Removes changelog entry and reverts version bump (stays at 2.4.1)
  • Preserves original E2E tests with MEM0_RUN_E2E=1 skip flag
  • Deletes superseded test files (memory.test.ts, factory.test.ts)

Test breakdown

Client SDK (154 tests across 7 files):

  • memoryClient.init.test.ts — constructor, validation, ping, error handling with exception types
  • memoryClient.crud.test.ts — add, get, getAll, update, delete, deleteAll, history
  • memoryClient.search.test.ts — v1/v2 routing, filters, no-options crash fix
  • memoryClient.batch.test.ts — batchUpdate/batchDelete payload transformation
  • memoryClient.users.test.ts — entity type routing (user/agent/app/run)
  • memoryClient.webhooks.test.ts — webhook CRUD with proper WebhookEvent enum
  • memoryClient.project.test.ts — getProject, updateProject, feedback, exports

Exception hierarchy (70 tests):

  • 8 HTTP-mapped exception classes (no dead code — all wired into client)
  • createExceptionFromResponse() factory for all status codes

OSS SDK (109 tests across 7 files):

  • memory.init.test.ts — constructor, fromConfig, disableHistory, reset
  • memory.add.test.ts — string/Message[] input, filters, metadata, infer=false
  • memory.crud.test.ts — get, update, delete, deleteAll, getAll, search, history
  • factory.unit.test.ts — all 4 factories, all providers including lmstudio
  • vector-store.unit.test.ts — MemoryVectorStore with real in-memory SQLite
  • storage.unit.test.ts — SQLiteManager, DummyHistoryManager, MemoryHistoryManager

E2E tests (skipped by default):

  • memoryClient.e2e.test.ts — client integration flows
  • memory.e2e.test.ts — OSS full add/get/search/update/delete flow

Bug fixes

  • mem0.ts:314 — options! → options ?? {} in getAll()
  • mem0.ts:365 — options! → options ?? {} in search()
  • mem0.ts:159 — _fetchWithErrorHandling now throws structured exceptions
  • mem0.ts:205 — ping() passes through MemoryError subclasses
  • mem0.types.ts:173 — WebhookEvent enum exported

Reviewer feedback addressed

  1. Fix bugs, don't test for them ✅
  2. No tautological tests ✅
  3. Split by concern ✅
  4. SDK types (no any) ✅
  5. URL matching longest-first ✅
  6. No dead code ✅
  7. Version reverted to 2.4.1 ✅
  8. deleteUsers single mock ✅
  9. Content-based LLM mock ✅
  10. E2E preserved with skip flag ✅
  11. Changelog entry removed ✅

How to test

cd mem0-ts
npx jest --no-cache # 474 pass, 111 skipped
pnpm run build # build succeeds
MEM0_RUN_E2E=1 npx jest --no-cache # includes E2E tests

Type of change

  • Bug fix (non-breaking)
  • New feature (non-breaking — structured exceptions, test infrastructure)

@whysosaket
Copy link
Copy Markdown
Member

Requested Changes

1. Fix the two known bugs instead of testing for them

getAll() and search() crash when called without options because of options! on mem0.ts:313 and mem0.ts:364. Change options! to (options ?? {}) in both places. Then write tests that assert the correct behavior (no crash), not the current broken behavior.

2. Remove tautological tests

~60% of the unit tests mock fetch to return X, call a client method, then assert the result is X. Since most methods (get, history, users, search, getAll, feedback, getWebhooks) return response.json() unchanged, these assertions test the mock, not the client.

Delete tests that assert response field values or typeof checks against mock data. Replace them with tests that verify what the client actually does: request URL construction, HTTP method, payload transformation (org/project attachment, memoryId -> memory_id, api_version -> version, v1 GET-with-params vs v2 POST-with-body routing, conditional field inclusion in update(), entity type routing in deleteUsers()).

3. Break memoryClient.unit.test.ts into multiple files

1750 lines in a single test file is too large. Split by concern:

  • memoryClient.init.test.ts — constructor, validation, ping
  • memoryClient.crud.test.ts — add, get, getAll, update, delete, deleteAll
  • memoryClient.search.test.ts — search (v1/v2 routing, filters)
  • memoryClient.batch.test.ts — batchUpdate, batchDelete
  • memoryClient.users.test.ts — users, deleteUser, deleteUsers
  • memoryClient.webhooks.test.ts — getWebhooks, createWebhook, updateWebhook, deleteWebhook
  • memoryClient.project.test.ts — getProject, updateProject, exports, feedback

The helpers and mock setup can stay in helpers.ts.

4. Replace any with SDK types

Every let result: any / let memory: any should use the actual types from mem0.types (Memory, AllUsers, MemoryHistory, etc.). This is a TypeScript SDK — the tests should catch type regressions at compile time.

5. Fix the mock fetch URL matching

String.includes() means /v1/memories/ also matches /v1/memories/search/. Sort patterns longest-first before matching so more specific routes win regardless of insertion order.

6. Don't ship dead code to main

The exception hierarchy (289 lines, 14 classes) is not integrated into the client. Either wire it into _fetchWithErrorHandling in this PR or keep it on the feature branch until it's ready.

7. Revert the version bump

2.4.1 -> 2.4.2 for a PR with no user-facing changes violates SemVer. Bump the version when the exceptions are actually integrated.

8. Fix the deleteUsers test setup bug

In the deleteUsers describe block, createClientWithMockedAxios() is called twice — the first call's mock is immediately discarded. Use a single call.

9. Fix the OSS LLM mock

The llmCallCount % 2 alternating pattern couples tests to internal call order. Mock based on prompt content or use mockResolvedValueOnce() per test so changes to the internal call sequence don't silently break everything.

10. Preserve the original E2E tests

The original memoryClient.test.ts had real integration tests. Move them to memoryClient.e2e.test.ts with a skip-by-default flag instead of replacing them entirely with mocks.

11. Remove the changelog entry

@kartik-mem0 kartik-mem0 changed the title chore: add structured exception hierarchy and comprehensive MemoryClient tests chore: end to end to test coverage for ts sdk Mar 17, 2026
@kartik-mem0 kartik-mem0 changed the title chore: end to end to test coverage for ts sdk chore: end to end test coverage for ts sdk Mar 17, 2026
@whysosaket whysosaket merged commit 3cdcb65 into main Mar 17, 2026
6 checks passed
@whysosaket whysosaket deleted the feat/ts-sdk-revamp-v2.5 branch March 17, 2026 15:43
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants