Skip to content

fix(memory): resolve Vitest false positive for expected rejection#3893

Open
JosephDoUrden wants to merge 1 commit intomodelcontextprotocol:mainfrom
JosephDoUrden:fix/memory-vitest-false-positive
Open

fix(memory): resolve Vitest false positive for expected rejection#3893
JosephDoUrden wants to merge 1 commit intomodelcontextprotocol:mainfrom
JosephDoUrden:fix/memory-vitest-false-positive

Conversation

@JosephDoUrden
Copy link
Copy Markdown

Summary

  • Fix Vitest reporting a false-positive "Unhandled Errors" warning for the "should throw error for non-existent entity" test in the memory server
  • Wrap the addObservations call in an async closure before asserting with .rejects.toThrow(), so Vitest's global unhandled rejection handler does not capture the expected error before the assertion intercepts it

Fixes #3073

Root cause

addObservations is an async function that throws synchronously inside a .map() callback. When passed directly to expect().rejects.toThrow(), the resulting Promise rejection is seen by Vitest's global rejection handler before the .rejects wrapper can intercept it. Wrapping in async () => { await ... } ensures the rejection is properly scoped.

Changes

  • src/memory/__tests__/knowledge-graph.test.ts: Wrap the assertion in an async closure

Test plan

  • All 45 memory server tests pass (npx vitest run)
  • No "Unhandled Errors" warning in test output

AI Disclosure

AI assistance (Claude) was used for issue research. The implementation was written and reviewed by the author.

Wrap the addObservations call in an async closure before asserting with
.rejects.toThrow(). This prevents Vitest's global unhandled rejection
handler from capturing the expected error before the assertion can
intercept it, eliminating the false-positive "Unhandled Errors" warning
that was failing CI.

Fixes modelcontextprotocol#3073
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vitest False Positive in PR Added in-memory locks for the process, fix for Bug #2579 temporary measure. #3060

1 participant