Skip to content

test(server): relax flaky startServer port-retry integration assertion#942

Closed
tomsen-ai wants to merge 1 commit into
MoonshotAI:mainfrom
tomsen-ai:fix/flaky-start-test-port-retry
Closed

test(server): relax flaky startServer port-retry integration assertion#942
tomsen-ai wants to merge 1 commit into
MoonshotAI:mainfrom
tomsen-ai:fix/flaky-start-test-port-retry

Conversation

@tomsen-ai

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

Copy link
Copy Markdown

Related Issue

Resolve #937

Problem

See #937 for the full report.

packages/server/test/start.test.ts had a flaky assertion that assumed startServer would always bind to exactly port + 1 when port was occupied. Under vitest's concurrent workers, another test could grab port + 1 in the window between allocation and binding, causing startServer to advance to port + 2 or higher and the strict equality check to fail.

What changed

  • Relaxed the integration assertion to verify the server bound to a port >= port + 1 instead of requiring exactly port + 1.
  • Added a check that the lock file records the actual bound port, preserving the invariant that status/kill/ps will work.
  • Renamed the test title from "retries on port+1" to "retries to a higher port" to match the looser assertion.

The exact +1 / +2 / ... retry strategy is still pinned by the existing unit tests for listenWithPortRetry, which use a fake gateway and do not depend on real port allocation.

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
@changeset-bot

changeset-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f62030d

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

@tomsen-ai

Copy link
Copy Markdown
Author

Closing as a duplicate of #941@tt-a1i already opened a PR for the same fix with additional lint cleanups. I'll leave review feedback there instead.

@tomsen-ai tomsen-ai closed this Jun 20, 2026
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): flaky startServer port-retry assertion under concurrent test runs

1 participant