mirror of
https://github.com/thedotmack/claude-mem
synced 2026-04-25 17:15:04 +02:00
fix: remove leaky mock.module() for project-name that polluted parallel workers (#1299)
Top-level mock.module() in context-reinjection-guard.test.ts permanently stubbed getProjectName() to 'test-project' for the entire Bun worker process, causing tests in other files to receive the wrong value. Removed the unnecessary mock (session-init tests don't assert on project name), added bunfig.toml smol=true for worker isolation, and added a regression test. Generated by Claude Code Vibe coded by ousamabenyounes Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
7
bunfig.toml
Normal file
7
bunfig.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[test]
|
||||||
|
# Force each test file into its own worker process.
|
||||||
|
# Prevents mock.module() calls (which are permanent within a worker)
|
||||||
|
# from leaking across test files in parallel runs.
|
||||||
|
# Note: smol=true increases test startup time by spawning one Bun process per file.
|
||||||
|
# See: https://github.com/thedotmack/claude-mem/issues/1299
|
||||||
|
smol = true
|
||||||
@@ -29,10 +29,6 @@ mock.module('../../src/shared/worker-utils.js', () => ({
|
|||||||
getWorkerPort: () => 37777,
|
getWorkerPort: () => 37777,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
mock.module('../../src/utils/project-name.js', () => ({
|
|
||||||
getProjectName: () => 'test-project',
|
|
||||||
}));
|
|
||||||
|
|
||||||
mock.module('../../src/utils/project-filter.js', () => ({
|
mock.module('../../src/utils/project-filter.js', () => ({
|
||||||
isProjectExcluded: () => false,
|
isProjectExcluded: () => false,
|
||||||
}));
|
}));
|
||||||
|
|||||||
28
tests/utils/project-name-isolation.test.ts
Normal file
28
tests/utils/project-name-isolation.test.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* Regression test for mock.module() worker pollution (#1299)
|
||||||
|
*
|
||||||
|
* context-reinjection-guard.test.ts used to call mock.module('../../src/utils/project-name.js', ...)
|
||||||
|
* at the top level, which permanently stubbed getProjectName to return 'test-project'
|
||||||
|
* for every subsequent import in the same Bun worker process.
|
||||||
|
*
|
||||||
|
* Without bunfig.toml [test] smol=true, this test would fail when Bun scheduled
|
||||||
|
* it in the same worker as context-reinjection-guard.test.ts, because the module
|
||||||
|
* was mocked before these tests ran and getProjectName() returned 'test-project'
|
||||||
|
* instead of the real extracted basename.
|
||||||
|
*/
|
||||||
|
import { describe, it, expect } from 'bun:test';
|
||||||
|
import { getProjectName } from '../../src/utils/project-name.js';
|
||||||
|
|
||||||
|
describe('getProjectName mock isolation (#1299)', () => {
|
||||||
|
it('returns real basename, not the leaked test-project mock', () => {
|
||||||
|
expect(getProjectName('/real/path/to/my-project')).toBe('my-project');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns unknown-project for empty string (real implementation)', () => {
|
||||||
|
expect(getProjectName('')).toBe('unknown-project');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns real basename from nested path', () => {
|
||||||
|
expect(getProjectName('/home/user/code/awesome-app')).toBe('awesome-app');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user