Context
PR #12423 review surfaced (operator-flagged) a widespread test anti-pattern: specs mutate the aiConfig Provider singleton in their setup blocks without restoring it. aiConfig is imported once per module graph and mutations stick; dynamic re-imports do not yield a clean instance. This is a latent cross-test corruption hazard.
The Problem
~11 specs write aiConfig.storagePaths.graph (and .autoIngestFileSystem, .engines.chroma.database) in beforeEach / describe-setup without restore, e.g.: GraphService.spec, MC ChromaManager.spec, McpServerToolLimits.spec, WriteSideInvariant.spec, SessionSummarization.spec, MC Server.spec, SessionService.spec / SessionService.ResumeValidation.spec, MemorySessionIngestor.spec, ConceptIngestor.spec, QueryReRanker.spec, DreamService.spec.
Single-spec and parallel (--workers>1, per-file isolation) runs mask the collision; a full-suite --workers=1 run is where the singleton persists across files and one spec's config bleeds into the next. CI's per-file isolation + retries hide it — this is exactly the class that passes CI but is latently wrong.
The Architectural Reality
aiConfig is a Neo Provider singleton (one instance per module graph; not reconstructed by re-import).
- Correct precedent in-tree:
test/playwright/unit/ai/mcp/server/shared/services/DestructiveOperationGuard.spec.mjs:223-234 captures originalGraphPath = aiConfig.storagePaths.graph, mutates, and restores it in a finally — the capture/restore pattern the other specs lack.
The Fix (lead prescription)
A shared test-isolation helper that snapshots the mutated aiConfig keys at setup and restores them in afterEach/afterAll (capture/restore), adopted across the ~11 specs. (Alternative shapes — a fresh per-test config Provider, or a scoped-override API — can be weighed during implementation; the snapshot/restore helper is the minimal, precedent-backed fix.)
Acceptance Criteria
Out of Scope
- Redesigning
aiConfig Provider semantics.
- The #12423 chunking-semantic-soundness concern (separate; design-space → Ideation).
Decision Record impact
none.
Related
- Surfaced in: PR #12423 review.
- Correct-pattern precedent:
DestructiveOperationGuard.spec.
Origin Session ID: 4cfb33e9-9d3a-4af7-afa8-e3d71ed4bcc7
Retrieval Hint: "aiConfig Provider singleton test mutation no restore cross-test pollution --workers=1 snapshot restore helper #12423"
Context
PR #12423 review surfaced (operator-flagged) a widespread test anti-pattern: specs mutate the
aiConfigProvider singleton in their setup blocks without restoring it.aiConfigis imported once per module graph and mutations stick; dynamic re-imports do not yield a clean instance. This is a latent cross-test corruption hazard.The Problem
~11 specs write
aiConfig.storagePaths.graph(and.autoIngestFileSystem,.engines.chroma.database) inbeforeEach/ describe-setup without restore, e.g.:GraphService.spec, MCChromaManager.spec,McpServerToolLimits.spec,WriteSideInvariant.spec,SessionSummarization.spec, MCServer.spec,SessionService.spec/SessionService.ResumeValidation.spec,MemorySessionIngestor.spec,ConceptIngestor.spec,QueryReRanker.spec,DreamService.spec.Single-spec and parallel (
--workers>1, per-file isolation) runs mask the collision; a full-suite--workers=1run is where the singleton persists across files and one spec's config bleeds into the next. CI's per-file isolation + retries hide it — this is exactly the class that passes CI but is latently wrong.The Architectural Reality
aiConfigis a Neo Provider singleton (one instance per module graph; not reconstructed by re-import).test/playwright/unit/ai/mcp/server/shared/services/DestructiveOperationGuard.spec.mjs:223-234capturesoriginalGraphPath = aiConfig.storagePaths.graph, mutates, and restores it in afinally— the capture/restore pattern the other specs lack.The Fix (lead prescription)
A shared test-isolation helper that snapshots the mutated
aiConfigkeys at setup and restores them inafterEach/afterAll(capture/restore), adopted across the ~11 specs. (Alternative shapes — a fresh per-test config Provider, or a scoped-override API — can be weighed during implementation; the snapshot/restore helper is the minimal, precedent-backed fix.)Acceptance Criteria
aiConfigkeys around each affected spec.aiConfig.*writes remain in their setup.--workers=1run is green with no cross-spec config bleed.Out of Scope
aiConfigProvider semantics.Decision Record impact
none.Related
DestructiveOperationGuard.spec.Origin Session ID: 4cfb33e9-9d3a-4af7-afa8-e3d71ed4bcc7 Retrieval Hint: "aiConfig Provider singleton test mutation no restore cross-test pollution --workers=1 snapshot restore helper #12423"