---
id: 10228
title: Refactor MailboxService and PermissionService tests to use concrete testDbPath
state: CLOSED
labels:
  - enhancement
  - ai
  - testing
assignees:
  - neo-gemini-pro
createdAt: '2026-04-23T10:32:28Z'
updatedAt: '2026-04-23T11:34:30Z'
githubUrl: 'https://github.com/neomjs/neo/issues/10228'
author: neo-gemini-pro
commentsCount: 0
parentIssue: null
subIssues: []
subIssuesCompleted: 0
subIssuesTotal: 0
blockedBy: []
blocking: []
closedAt: '2026-04-23T11:34:30Z'
---
# Refactor MailboxService and PermissionService tests to use concrete testDbPath

## Context
On 2026-04-22 (session 15852d91) and 2026-04-23 (session 8968b9f6), the production AgentIdentity nodes were wiped.

## The Problem
This was traced back to a test-pollution anti-pattern in the Playwright test suite. Tests like `MailboxService.spec.mjs` and `PermissionService.spec.mjs` attempt to isolate themselves using an in-memory database override (`aiConfig.storagePaths.graph = ':memory:';`). However, if `LifecycleService._initPromise` is already set (because a prior test initialized the `LifecycleService` with the default production SQLite path), the `:memory:` override is silently ignored. When the test's `beforeEach` hook then executes `storage.clear()`, it wipes the production data instead of the intended in-memory database.

## The Architectural Reality
Other specs (e.g., `DreamService`, `SemanticGraphExtractor`) use concrete `testDbPath` temporary files per test. This provides a robust isolation boundary and eliminates the leak surface.

## The Fix
Refactor `test/playwright/unit/ai/mcp/server/memory-core/services/MailboxService.spec.mjs` and `test/playwright/unit/ai/mcp/server/memory-core/services/PermissionService.spec.mjs` to use concrete `testDbPath` temporary files instead of the `:memory:` aiConfig mutation.

## Acceptance Criteria
- `MailboxService.spec.mjs` uses `testDbPath` tmp files for database isolation.
- `PermissionService.spec.mjs` uses `testDbPath` tmp files for database isolation.
- The `:memory:` override mutation is removed from both specs.
- Specs pass reliably without wiping the production database.

Origin Session ID: e068b094-fcae-436a-a9ab-c513246f7f71

## Timeline

- 2026-04-23T10:32:29Z @neo-gemini-pro added the `enhancement` label
- 2026-04-23T10:32:29Z @neo-gemini-pro added the `ai` label
- 2026-04-23T10:32:29Z @neo-gemini-pro added the `testing` label
- 2026-04-23T11:07:47Z @neo-gemini-pro assigned to @neo-gemini-pro
- 2026-04-23T11:09:27Z @neo-opus-ada cross-referenced by PR #10227
- 2026-04-23T11:09:57Z @neo-gemini-pro cross-referenced by PR #10229
- 2026-04-23T11:34:30Z @tobiu referenced in commit `fe513a1` - "test(core): refactor mailbox/permission specs to use testDbPath (#10228) (#10229)

* test(core): refactor mailbox/permission specs to use testDbPath (#10228)

* Refactor MailboxService.spec.mjs and PermissionService.spec.mjs to use concrete temporary sqlite files (`testDbPath`) instead of the vulnerable `:memory:` override.
* Include documentation updates in `seedAgentIdentities.mjs` and `IdentitySchema.md` explaining the test pollution hazard that led to this refactor.

* fix(memory-core): exclude AgentIdentity and BroadcastSentinel from apoptosis (#10229)

---------

Co-authored-by: tobiu <tobiasuhlig78@gmail.com>"
- 2026-04-23T11:34:30Z @tobiu closed this issue

