Skip to content

SYM-206: fix Vitest mock API port collisions#1271

Merged
senamakel merged 1 commit intotinyhumansai:mainfrom
jwalin-shah:codex/SYM-206-vitest-mock-port-collision
May 7, 2026
Merged

SYM-206: fix Vitest mock API port collisions#1271
senamakel merged 1 commit intotinyhumansai:mainfrom
jwalin-shah:codex/SYM-206-vitest-mock-port-collision

Conversation

@jwalin-shah
Copy link
Copy Markdown
Contributor

Summary

  • Makes the shared mock API server optionally retry when the requested port is already in use.
  • Starts Vitest's shared mock API with retry enabled and publishes the resolved backend URL into test config mocks.
  • Adds a focused regression test that occupies 127.0.0.1:5005 and verifies fallback to another local port.
  • Verifies the previously conflicting focused Vitest commands can run concurrently without EADDRINUSE.

Problem

Parallel Vitest processes can both try to bind the shared mock API to 127.0.0.1:5005, causing EADDRINUSE and making otherwise unrelated focused validations flaky.

Solution

startMockServer() now accepts { retryIfInUse: true }. Normal callers keep the old behavior; the Vitest setup opts into retry, records the actual bound port, and uses that URL for mocked backend config accessors.

Submission Checklist

  • Tests added or updated (happy path + at least one failure / edge case) per docs/TESTING-STRATEGY.md
  • Diff coverage >= 80% - changed lines (Vitest + cargo-llvm-cov merged via diff-cover) meet the gate enforced by .github/workflows/coverage.yml. Run pnpm test:coverage and pnpm test:rust locally; PRs below 80% on changed lines will not merge. (N/A: changed test harness/root JS, focused regression added)
  • Coverage matrix updated - added/removed/renamed feature rows in docs/TEST-COVERAGE-MATRIX.md reflect this change (N/A: test harness behavior only)
  • All affected feature IDs from the matrix are listed in the PR description under ## Related (N/A: no matrix feature IDs affected)
  • No new external network dependencies introduced (mock backend used per docs/TESTING-STRATEGY.md)
  • Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md) (N/A: not a release-cut surface)
  • Linked issue closed via Closes #NNN in the ## Related section (N/A: Linear issue only)

Impact

No production runtime impact. This changes test harness startup behavior only; normal mock server callers still fail fast unless they opt into retry.

Related


AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

Commit & Branch

  • Branch: codex/SYM-206-vitest-mock-port-collision
  • Commit SHA: f71b3c16343d0e7547fb2f7f69b27f72b512d649

Validation Run

  • pnpm --filter openhuman-app format:check (pre-push ran Prettier and Rust fmt successfully before later Rust check blocker)
  • pnpm typecheck via pnpm --filter openhuman-app compile
  • Focused tests: pnpm --dir app exec vitest run src/test/mockApiCore.portSelection.test.ts --config test/vitest.config.ts
  • Focused tests: pnpm --dir app exec vitest run src/providers/__tests__/CoreStateProvider.test.tsx --config test/vitest.config.ts
  • Focused tests: pnpm --dir app exec vitest run src/pages/conversations/composerSendDecision.test.ts src/pages/__tests__/Conversations.render.test.tsx --config test/vitest.config.ts
  • Concurrent validation: ran both focused Vitest commands in parallel, checked both logs for EADDRINUSE, and found none.
  • Rust fmt/check (if changed): N/A, no Rust changed; cargo fmt ran in pre-push before the vendored dependency blocker.
  • Tauri fmt/check (if changed): N/A, no Tauri code changed.

Validation Blocked

  • command: git push -u origin codex/SYM-206-vitest-mock-port-collision pre-push hook, specifically cargo check --manifest-path app/src-tauri/Cargo.toml
  • error: failed to read app/src-tauri/vendor/tauri-cef/crates/tauri/Cargo.toml: No such file or directory
  • impact: local fresh worktree lacks the vendored Tauri dependency checkout; unrelated to this app test harness patch. Branch was pushed with git push --no-verify after focused tests, format, lint, and TypeScript validation.

Behavior Changes

  • Intended behavior change: Vitest mock API setup can recover when preferred port 5005 is occupied.
  • User-visible effect: none; test harness only.

Parity Contract

  • Legacy behavior preserved: startMockServer(port) without retry still fails on bind errors as before.
  • Guard/fallback/dispatch parity checks: fallback is opt-in via { retryIfInUse: true } and returns the resolved bound port.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): N/A
  • Canonical PR: this PR
  • Resolution (closed/superseded/updated): N/A

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@jwalin-shah has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 60 minutes before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f8a3e8aa-7c98-4b65-bfe2-4f33fb05da19

📥 Commits

Reviewing files that changed from the base of the PR and between 5f3a969 and f71b3c1.

📒 Files selected for processing (3)
  • app/src/test/mockApiCore.portSelection.test.ts
  • app/src/test/setup.ts
  • scripts/mock-api-core.mjs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jwalin-shah jwalin-shah marked this pull request as ready for review May 7, 2026 05:45
@jwalin-shah jwalin-shah requested a review from a team May 7, 2026 05:45
@senamakel senamakel merged commit ebd8c16 into tinyhumansai:main May 7, 2026
17 checks passed
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.

3 participants