Skip to content

fix(memory): run the file-path tests in a temporary directory - #4937

Merged
cliffhall merged 2 commits into
v2/mainfrom
v2/fix/4922-memory-file-path-test-isolation
Oct 1, 2026
Merged

cliffhall merged 2 commits into
v2/mainfrom
v2/fix/4922-memory-file-path-test-isolation

Conversation

@cliffhall

@cliffhall cliffhall commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Closes #4922

Description

The memory server's file-path tests no longer write the real default graph files, so they stop failing intermittently.

  • ensureMemoryFilePath takes the directory its default files live in, defaulting to the package directory. The server still calls it with no argument.
  • __tests__/file-path.test.ts creates a temporary directory per test and removes it afterwards, instead of writing memory.json and memory.jsonl beside the source.
  • One added test covers the no-argument call (a relative MEMORY_FILE_PATH resolves against the package directory); it touches no file.

Server Details

  • Server: memory
  • Changes to: the file-path helper's signature (an optional parameter) and its tests. No tool, resource, prompt or configuration changes.

Motivation and Context

See #4922. The issue left the second writer unidentified; it is the server itself. index.ts calls main() at module load, and main() runs ensureMemoryFilePath() on the package directory. Every test file that imports ../index.js therefore runs the migration in its own Vitest worker, in parallel with this file's tests, and renamed memory.json away between the test's write and its assertion.

Thanks to @kkkhs, whose #4926 took the same approach (an optional base directory on the helper). That PR targeted main and is closed under the contribution policy; this is the change made through the maintainers' flow against v2/main.

How Has This Been Tested?

No client-observable change, so the evidence is targeted probes (macOS, Node 26):

  • npm run local:gate exits 0 on this branch (head 478db6a).
  • npm test -w src/memory 20 times in a row: 0 failures (88 tests each). Before the change the issue records roughly one failure in ten runs.
  • Nothing is left in the package directory: after those runs src/memory holds no memory.json or memory.jsonl, and git status is clean.

Not tested: the failure was not reproduced on demand before the fix, so the before side rests on the two occurrences recorded on the issue.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the MCP Protocol Documentation (not applicable: no protocol feature touched)
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly (not applicable: nothing user-facing changed)
  • I have added a changeset (npm run changeset) if this changes what a TypeScript server publishes (patch, .changeset/memory-file-path-base-dir.md)
  • I have tested this with an LLM client (not applicable: no server-facing change)
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options (none added)

Additional context

Changeset: a patch for @modelcontextprotocol/server-memory. The server's behavior does not change (the new parameter is never passed outside tests), but the compiled index.js does, so the entry says the change is internal.

main() still runs at import in every test file and still reads the package directory. That is pre-existing and harmless to these tests now; #4854 rewrites the suite around an in-process harness.

🤖 Generated with Claude Code

ensureMemoryFilePath takes the directory its default files live in, defaulting
to the package directory. The file-path tests pass a per-test temporary
directory instead of writing memory.json and memory.jsonl beside the source,
where the main() that every importing test file starts migrated them away
mid-test.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@changeset-bot

changeset-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 478db6a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/server-memory Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The published TypeScript change requires a patch changeset.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Isolates memory file-path tests from shared package files to prevent intermittent failures.

Changes:

  • Adds an injectable base directory to ensureMemoryFilePath.
  • Uses per-test temporary directories and verifies default behavior.
File Description
src/​memory/​index.ts Adds configurable base-directory handling.
src/​memory/​__tests__/​file-path.test.ts Isolates migration tests in temporary directories.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/memory/index.ts
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1: one finding, fixed.

  • Add a patch changeset for the published API change (src/memory/index.ts): added in 478db6a as .changeset/memory-file-path-base-dir.md. The PR body no longer argues for omitting it.

npm run local:gate exits 0 at 478db6a. Requesting round 2.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused change resolves the shared-file race while preserving production behavior and covering the new seam.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 2: clean (no findings; round 1's changeset finding marked resolved). The review loop ends here.

@cliffhall
cliffhall merged commit 1847ad0 into v2/main Oct 1, 2026
31 checks passed
@cliffhall
cliffhall deleted the v2/fix/4922-memory-file-path-test-isolation branch October 1, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory: file-path tests write the real default graph files and fail intermittently

2 participants