mirror of
https://github.com/thedotmack/claude-mem.git
synced 2026-07-03 12:32:32 +08:00
Tests (`tests/sdk/`)
-------------------
Five focused integration tests covering the SDK's contract. Each uses
the project's existing skip-if-no-db pattern (gating on both
`CLAUDE_MEM_TEST_POSTGRES_URL` and `CLAUDE_MEM_SERVER_DATABASE_URL` so
the suite runs under both the CI harness and the SDK's own env), and
the live-Chroma tests also gate on `uvx --version` (same pattern as
`tests/integration/chroma-vector-sync.test.ts`).
- `create-cmem-client.test.ts`: schema bootstrap idempotency; second
`createCmemClient` reuses the persisted `sdk-tenant.json`; per-test
`CLAUDE_MEM_DATA_DIR` under `os.tmpdir()` keeps host state untouched.
- `capture.test.ts`: `capture` writes exactly one `agent_events` row +
one `observation_generation_jobs` row (status `queued`); `captureBatch`
does the same per event in a single tx. Plus a static "no-Redis"
import-guard at the source level.
- `generate.test.ts`: `captureAndGenerate` with a stub `CmemProvider`
returning minimal-valid agent XML — verifies the observation row,
`observation_sources` link, and `completed` job state without
calling a live LLM API.
- `search.test.ts`: empty-query → `listByProject`; Chroma error path
via `ChromaMcpManager.callTool` monkey-patch (cleaner than killing
chroma-mcp mid-run) → asserts `{ chroma: false, degraded: true,
error: { message } }`; `context()` shape with degraded surfaced.
- `close.test.ts`: consumer-supplied pool stays open after
`client.close()`; SDK-owned pool closes; subsequent calls throw
"cmem-sdk: client is closed"; `close()` is idempotent.
Test count: 2065 → 2071 pass, 22 → 23 skip, 0 fail. The skips expand
to ~12 integration assertions when `CLAUDE_MEM_TEST_POSTGRES_URL` +
uvx are available.
Example (`examples/sdk-node/`)
------------------------------
Plain-Node (not Bun) script proving the headline requirement: capture
→ generate → search inline, with no worker or daemon running. ESM
module imports `claude-mem/sdk` from the local `file:../../` package.
- `index.mjs`: reads `CLAUDE_MEM_SERVER_DATABASE_URL` +
`ANTHROPIC_API_KEY` from env, bails clearly if missing, runs
`captureAndGenerate` then `search` then `context` and logs results,
then `client.close()`.
- `package.json`: type `module`, single dep `claude-mem`.
- `README.md`: prereqs (Postgres URL, API key, uvx), run command,
note that no worker is needed.
`node --check examples/sdk-node/index.mjs` → OK.
Docs (`docs/public/sdk.mdx` + nav)
----------------------------------
New Mintlify page "Using claude-mem in your app (SDK)" — 1341 words.
Covers:
- Headline: in-process capture/compress/search with no worker.
- Quick-start with minimal code sample.
- `createCmemClient` options table.
- Architecture diagram (mirror of the plan's top-of-file diagram,
marking Chroma REQUIRED).
- Chroma section: install uv/uvx; explanation of the
required-at-construction gate; runtime degradation semantics
(`{ degraded: true }` + `logger.error`).
- Tenancy: default-team + default-project bootstrap via
`sdk-tenant.json` vs. passing explicit `teamId`/`projectId`.
- Provider configuration: env-based (`ANTHROPIC_API_KEY` etc.) vs.
options-based (`{ apiKey, model, provider }`) vs. user-supplied
`CmemProvider` instance.
- Lifecycle: `close()` ownership rules.
- Error handling: Chroma init rejection, FTS fallback `{ degraded:
true }`, "client is closed" after `close()`.
`docs/public/docs.json` — new top-level nav group "SDK & Embedding"
(icon `code`) with the single `sdk` page, inserted after
"Configuration & Development". JSON validity confirmed.
Verification:
- `npm run build`: green; check:sdk-bundle clean.
- `dist/sdk/index.js`: 214.07 KB (no SDK runtime change in this phase).
- `npm run typecheck`: 0 errors.
- `bun test`: 2071 pass / 0 fail / 23 skip across 180 files.
Plan §8 (plans/2026-05-25-cmem-sdk-and-server-rename.md).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>