test(preflight): skip real-bind tests in restricted environments (#544)#1988
test(preflight): skip real-bind tests in restricted environments (#544)#1988ColinM-sys wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
…st bind (NVIDIA#544) Fixes NVIDIA#544. The existing tests in preflight.test.ts that exercise the real Node net.createServer() probe assumed localhost bind was always permitted. In constrained CI/sandbox environments (seccomp, gVisor, some container runtimes), binding even to port 0 on 127.0.0.1 fails with EPERM/EACCES — making the suite flaky and environment-dependent. The production `probePortAvailability` already handles EPERM/EACCES correctly (returns ok:true with a "probe skipped" warning, not a false conflict). What was missing was test resilience. Add a one-shot `canBindLocalhost()` detector (memoised) that attempts a port-0 bind at test time. The four real-net tests now: 1. If bind is permitted: exercise the real probe as before. 2. If bind is denied: assert that the probe returned ok:true with an inconclusive/skipped warning — which is the documented graceful- degradation behavior — and exit without trying to manufacture a port conflict we cannot actually create. Mocked-probe tests (probeImpl injection) are unchanged and continue to provide full coverage of the happy path, EADDRINUSE path, and EPERM/EACCES path regardless of environment. All 36 preflight tests pass locally. Signed-off-by: ColinM-sys <cmcdonough@50words.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdded a cached Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Summary
Harden the four real-net probe tests in `src/lib/preflight.test.ts` against environments that deny localhost `bind()` (seccomp, gVisor, some container runtimes).
Fixes #544.
Background
The production code (`probePortAvailability`) already handles `EPERM`/`EACCES` correctly — it returns `{ ok: true, warning: ... }` rather than a false port conflict (see `src/lib/preflight.ts:469-475`). The gap was in the tests: the real-bind cases assumed localhost bind permission was always available, which is flaky in restricted CI / sandbox environments.
Change
Added a memoised `canBindLocalhost()` helper that probes port-0 once. The four real-bind tests now:
Mocked-probe tests (via `probeImpl` injection) are unchanged — they already cover the happy / `EADDRINUSE` / `EPERM` paths independent of environment.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit