MoonshotAI / MoonshotAI/kimi-code
test(server): replace flaky fs-watch e2e burst test with FsWatcherService unit test
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
Problem
packages/server/test/fs-watch.e2e.test.ts AC #2 ("burst > 500 changes inside 200ms window → truncated:true") is flaky under concurrent test runs.
The test creates 600 files with writeFileSync in a loop and expects chokidar to deliver more than 500 change events inside one 200ms debounce window. On slow machines or when vitest workers compete for disk IO, the 600 writes span multiple debounce windows, so no single window exceeds 500 events and truncated: true is never emitted. The assertion then fails with a timeout or expected false to be true.
Root cause
The e2e test relies on real file IO speed to simulate a burst. File IO speed is not controllable in a test environment, making the test non-deterministic.
Proposed fix
Move the truncated-burst assertion from the e2e test into a FsWatcherService unit test in packages/server/test/services.test.ts:
- Drive the watcher with a fake
FSWatcherthat emits 600 syntheticallevents. - Assert that
FsWatcherServicesets the internal truncated flag and emits anevent.fs.changedframe withtruncated: trueand the correctcountafter the debounce window expires.
This tests the exact same production logic without depending on real file IO timing.
Scope
- Remove or weaken AC #2 in
packages/server/test/fs-watch.e2e.test.ts. - Add a unit test for the truncated path in
packages/server/test/services.test.ts.
I will open a PR shortly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with packages/server/test/fs-watch.e2e.test.ts AC #2 and the FsWatcherService tests in packages/server/test/services.test.ts. Use the existing service test setup and drive a fake FSWatcher with 600 synthetic all events, then verify the debounced event.fs.changed frame has truncated: true and the correct count. Remove or weaken the flaky e2e assertion and run the affected server tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100