Found while building the pre-push gate (#4871, PR #4920). Not caused by that PR, which changes no server code.
Problem
src/memory/__tests__/file-path.test.ts failed once inside an npm run local:gate run and then passed seven consecutive re-runs of npm test -w src/memory with no change in between:
FAIL __tests__/file-path.test.ts > ensureMemoryFilePath > without MEMORY_FILE_PATH environment variable > should use new file when both old and new files exist
AssertionError: expected false to be true
❯ __tests__/file-path.test.ts:158:29
157| expect(newFileExists).toBe(true);
158| expect(oldFileExists).toBe(true);
So src/memory/memory.json was gone by the time the test checked for it, although the test had just written it.
What is known, and what is not
- The tests in this file do not use a temporary directory. They write, migrate and delete the real default paths beside the source,
src/memory/memory.json and src/memory/memory.jsonl, the same paths the server itself uses when MEMORY_FILE_PATH is unset.
- Anything else that calls
ensureMemoryFilePath() with no MEMORY_FILE_PATH while this test runs will migrate memory.json away (rename to memory.jsonl) between the test's write and its assertion. Candidates: another test file in the same Vitest run (files run in parallel), or a memory server started from this checkout at that moment.
- The actual second writer was not identified. It reproduced once in roughly ten runs on macOS, Node 26.
Expected
The suite gives the same result every run. The file-path tests should not share state with anything else: point them at a per-test temporary directory (which needs ensureMemoryFilePath to take its base directory as a parameter, or an equivalent seam) instead of the package directory. Writing into the package directory also means a failed run can leave a memory.json or memory.jsonl behind in the working tree.
Notes
Found while building the pre-push gate (#4871, PR #4920). Not caused by that PR, which changes no server code.
Problem
src/memory/__tests__/file-path.test.tsfailed once inside annpm run local:gaterun and then passed seven consecutive re-runs ofnpm test -w src/memorywith no change in between:So
src/memory/memory.jsonwas gone by the time the test checked for it, although the test had just written it.What is known, and what is not
src/memory/memory.jsonandsrc/memory/memory.jsonl, the same paths the server itself uses whenMEMORY_FILE_PATHis unset.ensureMemoryFilePath()with noMEMORY_FILE_PATHwhile this test runs will migratememory.jsonaway (rename tomemory.jsonl) between the test's write and its assertion. Candidates: another test file in the same Vitest run (files run in parallel), or a memory server started from this checkout at that moment.Expected
The suite gives the same result every run. The file-path tests should not share state with anything else: point them at a per-test temporary directory (which needs
ensureMemoryFilePathto take its base directory as a parameter, or an equivalent seam) instead of the package directory. Writing into the package directory also means a failed run can leave amemory.jsonormemory.jsonlbehind in the working tree.Notes
verify:no-test-retries), so this has to be fixed at the cause.