@memoryrelay/plugin-memoryrelay-ai 0.12.11 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,87 @@
1
+ ---
2
+ name: testing-memoryrelay
3
+ description: "Use when writing, running, or debugging tests for the MemoryRelay plugin, adding test coverage for new tools or hooks, or investigating test failures."
4
+ ---
5
+
6
+ # Testing MemoryRelay
7
+
8
+ Test runner: **Vitest**. All tests run without a live API.
9
+
10
+ ## Commands
11
+
12
+ | Command | Purpose |
13
+ |---------|---------|
14
+ | `npm test` | Run all tests once (`vitest run`) |
15
+ | `npm run test:watch` | Watch mode (`vitest`) |
16
+ | `npm run test:coverage` | Coverage report (`vitest run --coverage`) |
17
+
18
+ ## Test Files
19
+
20
+ | File | Scope |
21
+ |------|-------|
22
+ | `index.test.ts` | Integration tests: API client, tools, hooks, retry logic, pattern detection, channel filtering, tool groups, workflow instructions |
23
+ | `src/debug-logger.test.ts` | DebugLogger unit tests: circular buffer, filtering by tool/status, stats, formatting |
24
+ | `src/status-reporter.test.ts` | StatusReporter unit tests: failure tracking, report building, formatting |
25
+
26
+ ## Mock Pattern
27
+
28
+ Tests use `MockMemoryRelayClient` -- an in-memory implementation that replaces the real API client:
29
+
30
+ ```typescript
31
+ import { describe, test, expect, beforeEach, vi } from "vitest";
32
+
33
+ class MockMemoryRelayClient {
34
+ private memories: Memory[] = [];
35
+ private nextId = 1;
36
+ async store(content, metadata?) { /* push to array, return Memory */ }
37
+ async search(query, limit?, threshold?) { /* keyword .includes() match */ }
38
+ async list(limit?, offset?) { /* .slice() */ }
39
+ async get(id) { /* .find(), throws if missing */ }
40
+ async delete(id) { /* .splice(), throws if missing */ }
41
+ async health() { return { status: "healthy" }; }
42
+ async stats() { return { total_memories: this.memories.length }; }
43
+ }
44
+ ```
45
+
46
+ Instantiate fresh per test with `beforeEach(() => { client = new MockMemoryRelayClient("test_key", "test_agent"); })`.
47
+
48
+ ## What to Test per Tool
49
+
50
+ | Area | Checks |
51
+ |------|--------|
52
+ | Input validation | Required params present, types correct |
53
+ | Success path | API response formatted correctly, data stored/returned |
54
+ | Error handling | Non-existent IDs throw, empty results return `[]` |
55
+ | Deduplication | `deduplicate=true` prevents near-duplicate storage |
56
+ | Session injection | `session_id` auto-applied from active session |
57
+ | Retry logic | Network errors and 5xx retried; 4xx not retried |
58
+ | Timeouts | 30s timeout via `AbortController` |
59
+
60
+ ## Testing Hooks
61
+
62
+ **`before_agent_start`** -- workflow injection and auto-recall:
63
+
64
+ - Verify workflow instructions are built from enabled tool groups
65
+ - Mock `client.search()` to test auto-recall injects context
66
+ - Test channel exclusion skips auto-recall for blocklisted channels
67
+
68
+ **`agent_end`** -- auto-capture:
69
+
70
+ - Test pattern detection (`shouldCapture`) with regex matching
71
+ - Verify length bounds (20-2000 chars)
72
+ - Confirm privacy blocklist rejects passwords, SSNs, API keys
73
+ - Test tier logic: `off`, `conservative`, `smart`, `aggressive`
74
+
75
+ ## Testing Gateway Methods
76
+
77
+ | Check | How |
78
+ |-------|-----|
79
+ | Response format | Assert returned object shape matches API contract |
80
+ | Error surfaces | `detail` field extracted (FastAPI format), falls back to `message` |
81
+ | HTTP method | GET with query params for search/check; POST with body for create/link |
82
+
83
+ ## Unit Test Patterns
84
+
85
+ **DebugLogger**: Uses `vi.mock("fs")`. Test circular buffer (`maxEntries`), `getRecentLogs(n)`, `getToolLogs(name)`, `getErrorLogs()`, `getStats()`, `clear()`, `formatEntry()`.
86
+
87
+ **StatusReporter**: Instantiate with real `DebugLogger`. Test `recordFailure`/`recordSuccess` toggle, `buildReport` shape, `formatReport`/`formatCompact` output, disconnected status handling.