fix: use sudo -n for lsof retry in preflight to avoid password prompt#1227
fix: use sudo -n for lsof retry in preflight to avoid password prompt#1227
Conversation
The port-availability check in checkPortAvailable retries with sudo lsof to detect root-owned listeners. Without -n (non-interactive), sudo blocks on a Password: prompt, stalling non-interactive installs (curl | bash, --non-interactive, NEMOCLAW_NON_INTERACTIVE=1, CI). Switch to sudo -n so it fails immediately when passwordless sudo is unavailable, falling through to the TCP bind probe instead of hanging.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA single line modification in the port availability check function updates the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
ericksoa
left a comment
There was a problem hiding this comment.
No regression risk. The -n flag prevents a surprise password prompt during preflight — if sudo needs a password, it fails silently into the existing ignoreError: true fallback path.
Convert bin/lib/preflight.js (357 lines) to src/lib/preflight.ts with full type definitions for all opts objects and return types. The old file becomes a thin re-export shim so existing consumers are unaffected. Changes: - Typed interfaces: PortProbeResult, MemoryInfo, SwapResult, and all opts types (CheckPortOpts, GetMemoryInfoOpts, EnsureSwapOpts) - Extract parseLsofLines helper to reduce duplication in checkPortAvailable - Incorporate #1227 fix: sudo -> sudo -n (non-interactive) for lsof retry - Co-locate tests: test/preflight.test.js -> src/lib/preflight.test.ts converted to expect-style with type narrowing - Add real net probe tests (EADDRINUSE detection on occupied ports) - Fix co-located test imports to go through dist/ for coverage attribution - Add targeted dashboard and validation branch tests for ratchet 612 CLI tests pass. Coverage ratchet passes. No user-facing behavior changes. Relates to #924 (shell consolidation). Supersedes #1227. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary - Convert `bin/lib/preflight.js` (357 lines) to `src/lib/preflight.ts` with full type definitions - Typed interfaces for all opts objects and return types: `PortProbeResult`, `MemoryInfo`, `SwapResult`, `CheckPortOpts`, `GetMemoryInfoOpts`, `EnsureSwapOpts` - Extract `parseLsofLines` helper to reduce duplication in `checkPortAvailable` - Incorporate #1227 fix: `sudo` → `sudo -n` (non-interactive) for lsof retry - `bin/lib/preflight.js` becomes a thin re-export shim — existing consumers unaffected - Co-locate tests: `test/preflight.test.js` → `src/lib/preflight.test.ts` - Add real net probe tests (EADDRINUSE detection on occupied ports) - Fix all co-located test imports to use `dist/` paths for coverage attribution - Add targeted dashboard/validation branch tests to maintain ratchet Stacked on #1240. Not touched by any #924 blocker PR. ## Test plan - [x] 612 CLI tests pass (601 existing + 11 new) - [x] `tsc -p tsconfig.src.json` compiles cleanly - [x] `tsc -p tsconfig.cli.json` type-checks cleanly - [x] `tsc -p jsconfig.json` type-checks cleanly (the pre-push check that caught the union issue) - [x] Coverage ratchet passes Relates to #924 (shell consolidation). Supersedes #1227. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…#1227) ## Problem The port-availability preflight check in `checkPortAvailable` retries with `sudo lsof` to detect root-owned listeners when unprivileged `lsof` returns empty output. Without `-n` (non-interactive mode), `sudo` blocks on a `Password:` prompt, stalling non-interactive installs: - `curl -fsSL https://www.nvidia.com/nemoclaw.sh | bash` - `nemoclaw onboard --non-interactive` - `NEMOCLAW_NON_INTERACTIVE=1` - CI pipelines ## Fix Use `sudo -n` so it fails immediately when passwordless sudo is unavailable, falling through to the TCP bind probe instead of hanging. This is the only `sudo` call in the codebase that should degrade gracefully — the other `sudo` calls (swap creation) intentionally require elevated privileges to succeed.
…NVIDIA#1227) ## Problem The port-availability preflight check in `checkPortAvailable` retries with `sudo lsof` to detect root-owned listeners when unprivileged `lsof` returns empty output. Without `-n` (non-interactive mode), `sudo` blocks on a `Password:` prompt, stalling non-interactive installs: - `curl -fsSL https://www.nvidia.com/nemoclaw.sh | bash` - `nemoclaw onboard --non-interactive` - `NEMOCLAW_NON_INTERACTIVE=1` - CI pipelines ## Fix Use `sudo -n` so it fails immediately when passwordless sudo is unavailable, falling through to the TCP bind probe instead of hanging. This is the only `sudo` call in the codebase that should degrade gracefully — the other `sudo` calls (swap creation) intentionally require elevated privileges to succeed.
…NVIDIA#1227) ## Problem The port-availability preflight check in `checkPortAvailable` retries with `sudo lsof` to detect root-owned listeners when unprivileged `lsof` returns empty output. Without `-n` (non-interactive mode), `sudo` blocks on a `Password:` prompt, stalling non-interactive installs: - `curl -fsSL https://www.nvidia.com/nemoclaw.sh | bash` - `nemoclaw onboard --non-interactive` - `NEMOCLAW_NON_INTERACTIVE=1` - CI pipelines ## Fix Use `sudo -n` so it fails immediately when passwordless sudo is unavailable, falling through to the TCP bind probe instead of hanging. This is the only `sudo` call in the codebase that should degrade gracefully — the other `sudo` calls (swap creation) intentionally require elevated privileges to succeed.
Problem
The port-availability preflight check in
checkPortAvailableretries withsudo lsofto detect root-owned listeners when unprivilegedlsofreturns empty output. Without-n(non-interactive mode),sudoblocks on aPassword:prompt, stalling non-interactive installs:curl -fsSL https://www.nvidia.com/nemoclaw.sh | bashnemoclaw onboard --non-interactiveNEMOCLAW_NON_INTERACTIVE=1Fix
Use
sudo -nso it fails immediately when passwordless sudo is unavailable, falling through to the TCP bind probe instead of hanging.This is the only
sudocall in the codebase that should degrade gracefully — the othersudocalls (swap creation) intentionally require elevated privileges to succeed.Summary by CodeRabbit