Skip to content

test(server): replace flaky fs-watch burst e2e with FsWatcherService unit test#944

Open
tomsen-ai wants to merge 2 commits into
MoonshotAI:mainfrom
tomsen-ai:test/fs-watcher-truncated-unit-test
Open

test(server): replace flaky fs-watch burst e2e with FsWatcherService unit test#944
tomsen-ai wants to merge 2 commits into
MoonshotAI:mainfrom
tomsen-ai:test/fs-watcher-truncated-unit-test

Conversation

@tomsen-ai

@tomsen-ai tomsen-ai commented Jun 20, 2026

Copy link
Copy Markdown

Related Issue

Resolve #943

Problem

packages/server/test/fs-watch.e2e.test.ts AC #2 ("burst > 500 changes inside 200ms window → truncated:true") was flaky under concurrent test runs.

The test created 600 files with writeFileSync in a loop and expected chokidar to deliver more than 500 change events inside one 200ms debounce window. On slow machines or when vitest workers competed for disk IO, the 600 writes spanned multiple debounce windows, so truncated: true was never emitted and the assertion failed.

What changed

  • Removed the flaky e2e AC fix: correct Anthropic provider inputOther token counting #2 test case from fs-watch.e2e.test.ts and renumbered the remaining ACs.
  • Added a FsWatcherService unit test in services.test.ts that drives a fake FSWatcher and asserts the truncated path:
    • more than maxChangesPerWindow synthetic events set the internal truncated flag
    • after the debounce window expires, the service emits an event.fs.changed frame with truncated: true and the correct count
  • Extended the existing FakeWatcher helper with EventEmitter so it can emit chokidar events for the unit test.

This preserves coverage of the truncated-burst logic while removing the dependency on real file IO timing.

Tests

  • pnpm --filter @moonshot-ai/server exec vitest run test/services.test.ts test/fs-watch.e2e.test.ts

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • This is a test-only fix and needs no changeset.
  • This PR needs no doc update.

The test assumed port+1 stays free between allocation and startServer binding. Under vitest concurrency another worker can grab it, causing startServer to bind to port+2 or higher.

Relax the integration assertion to check the bound port is >= port+1 and that the lock file reflects the actual bound port. The exact +1/+2 retry sequence is already covered by unit tests for listenWithPortRetry.

Closes MoonshotAI#937
…unit test

The e2e AC MoonshotAI#2 test created 600 files with writeFileSync and asserted that chokidar delivered >500 change events inside one 200ms debounce window. On slow or contended runners the 600 writes spanned multiple windows, so truncated:true was never emitted and the test failed.

Move the truncated-burst coverage to a FsWatcherService unit test that drives a fake FSWatcher, removing the dependency on real file IO timing. Remove the flaky e2e case and renumber the remaining ACs.

Closes MoonshotAI#943
@changeset-bot

changeset-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: af8ee16

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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.

test(server): replace flaky fs-watch e2e burst test with FsWatcherService unit test

1 participant