refactor(memory): remove facade test shims#1893
Conversation
📝 WalkthroughWalkthroughAdds architecture docs (plan, spec, tasks) for an agent-memory test-seams refactor, removes MemoryPresenter's private test-only compat/runtime accessor methods, and refactors memoryPresenter.test.ts to use a new memoryRuntimeForTests helper exposing service-level runtime state instead of inline type casts. No production behavior changes. ChangesAgent memory test seams refactor
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/main/presenter/memoryPresenter.test.ts (1)
57-123: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoffFlat-spread runtime seam risks silent key collisions.
memoryRuntimeForTestsmerges six independently-typedgetMutableRuntimeStateForTests()results into one flat object via spread. This currently works because none of the exposed keys collide, but nothing prevents a future addition (e.g. a new field onmaintenanceorpersona) from silently shadowing an existing key from another service, with no compiler error to catch it since each source object is spread rather than namespaced.Consider namespacing by service to make the seam self-documenting and collision-proof:
♻️ Suggested restructuring
function memoryRuntimeForTests(presenter: MemoryPresenter) { const internals = presenter as unknown as MemoryPresenterRuntimeTestSeams return { embeddingService: internals.embedding, vectorStoreService: internals.vectorStore, - ...internals.embedding.getMutableRuntimeStateForTests(), - ...internals.vectorStore.getMutableRuntimeStateForTests(), - ...internals.maintenance.getMutableRuntimeStateForTests(), - ...internals.reflection.getMutableRuntimeStateForTests(), - ...internals.persona.getMutableRuntimeStateForTests(), - ...internals.workingMemory.getMutableRuntimeStateForTests(), + embedding: internals.embedding.getMutableRuntimeStateForTests(), + vectorStore: internals.vectorStore.getMutableRuntimeStateForTests(), + maintenance: internals.maintenance.getMutableRuntimeStateForTests(), + reflection: internals.reflection.getMutableRuntimeStateForTests(), + persona: internals.persona.getMutableRuntimeStateForTests(), + workingMemory: internals.workingMemory.getMutableRuntimeStateForTests(), warmEmbeddingConnection: (...) } }This is a larger mechanical change touching every call site in this ~7000-line test file, so it's optional given the current lack of collisions.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/main/presenter/memoryPresenter.test.ts` around lines 57 - 123, `memoryRuntimeForTests` currently flattens multiple `getMutableRuntimeStateForTests()` results into one object with spreads, which can silently shadow keys if any service adds a duplicate field. Update the seam in `memoryPresenter.test.ts` to keep each service’s runtime state namespaced under its service key (for example, embedding/vectorStore/maintenance/etc.) instead of merging them into a single flat shape, and adjust any test helpers or call sites that read those properties to use the namespaced access.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test/main/presenter/memoryPresenter.test.ts`:
- Around line 57-123: `memoryRuntimeForTests` currently flattens multiple
`getMutableRuntimeStateForTests()` results into one object with spreads, which
can silently shadow keys if any service adds a duplicate field. Update the seam
in `memoryPresenter.test.ts` to keep each service’s runtime state namespaced
under its service key (for example, embedding/vectorStore/maintenance/etc.)
instead of merging them into a single flat shape, and adjust any test helpers or
call sites that read those properties to use the namespaced access.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 72c2fe94-2d67-4e0e-ba76-0b9740a97575
📒 Files selected for processing (5)
docs/architecture/agent-memory-test-seams/plan.mddocs/architecture/agent-memory-test-seams/spec.mddocs/architecture/agent-memory-test-seams/tasks.mdsrc/main/presenter/memoryPresenter/index.tstest/main/presenter/memoryPresenter.test.ts
Summary by CodeRabbit