fix(onboard): cancel onboarding when exit is typed at numbered menus#4581
Conversation
Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a generic selectFromNumberedMenuOrExit helper that treats "exit" as cancellation, parses 1-based numeric choices with 0-based indexing into options, and falls back to a provided default. Integrates the helper into three onboarding prompts and adds comprehensive tests. ChangesNumbered Menu Selection Helper Consolidation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
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 docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
PR Review AdvisorFindings: 0 needs attention, 1 worth checking, 0 nice ideas Review findings🛠️ Needs attention
🔎 Worth checking
🌱 Nice ideas
Since last review detailsCurrent findings:
This is an automated advisory review. A human maintainer must make the final merge decision. |
E2E Advisor RecommendationRequired E2E: Dispatch hint: Auto-dispatched E2E: Full advisor summaryE2E Recommendation AdvisorBase: Required E2E
Optional E2E
New E2E recommendations
Dispatch hint
|
E2E Scenario Advisor RecommendationRequired scenario E2E: Dispatch required scenario E2E:
Full scenario advisor summaryE2E Scenario AdvisorBase: Required scenario E2E
Optional scenario E2E
Relevant changed files
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/onboard/prompt-helpers.ts`:
- Around line 40-41: The current return uses a || fallback which treats valid
falsy option values as missing; in the block that computes idx from
rawChoice/defaultIdx (variables rawChoice, defaultIdx, options, idx), replace
the falsy-check fallback with an explicit bounds check: if idx is within
0..options.length-1 return options[idx], otherwise return options[defaultIdx -
1]. Ensure you compute idx as Number.parseInt(rawChoice || String(defaultIdx),
10) - 1 and use the explicit index range check rather than the || operator.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 4c3321c8-579e-4821-8aa5-fb2c0f652d12
📒 Files selected for processing (3)
src/lib/onboard.tssrc/lib/onboard/prompt-helpers.test.tssrc/lib/onboard/prompt-helpers.ts
Selective E2E Results — ✅ All requested jobs passedRun: 26717140181
|
Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
cjagwani
left a comment
There was a problem hiding this comment.
Approving. Clean helper extraction — the three menu sites now honor the documented exit/quit contract instead of silently advancing on a parse-NaN.
Test coverage is exemplary: 9 cases covering casing variants (EXIT/Quit/whitespace), non-navigation words, sparse arrays, and the falsy-option edge case where 1 mustn't silently swap to the bracketed default. cloud-onboard-e2e, macos-e2e, test-e2e-sandbox, and test-e2e-gateway-isolation all passed.
Selective E2E Results — ✅ All requested jobs passedRun: 26774993624
|
Summary
The inference provider menu, NIM model menu, and non-TTY policy tier menu all dispatched the reply through
parseInt(rawChoice || String(default), 10) - 1with no navigation check first. Typingexitat any of them parses toNaN, falls through to the bracketed default, and the wizard silently advances as if the operator had pressed Enter. Other prompts in the same flow honour the documentedexit/quitcancellation contract viagetNavigationChoice+exitOnboardFromPrompt.This PR extracts a single
selectFromNumberedMenuhelper insrc/lib/onboard/prompt-helpers.tsthat wraps the navigation check around theparseInt-with-default selection, and routes the three menu sites through it.onboard.tsshrinks by three lines on net.Related Issue
Fixes #4514.
Changes
src/lib/onboard/prompt-helpers.ts: addselectFromNumberedMenu<T>(rawChoice, defaultIdx, options)— runsgetNavigationChoice→exitOnboardFromPrompt()onexit/quit, otherwise returns the parsed-index option (falling back to the bracketed default).src/lib/onboard.ts: replace the inlineparseIntselection at the inference provider menu, the NIM model menu, and the non-TTY policy tier menu withselectFromNumberedMenu. The provider menu now honours theexit/quitcontract advertised by the wizard.src/lib/onboard/prompt-helpers.test.ts: nine new cases pinning bare-Enter → default, valid number → option, out-of-range → default, every casing / whitespace variant ofexit/quit/EXIT/Quit/" exit "→process.exit(1)with theExiting onboarding.banner, and non-navigation words → numeric path.Type of Change
Verification
npm run typecheck:clipassesnpm run build:clipassesnpx vitest run --project cli src/lib/onboard/prompt-helpers.test.ts test/onboard-selection.test.ts— 87 / 87 passnpm run docsbuilds without warnings (doc changes only)Signed-off-by: Tinson Lai tinsonl@nvidia.com
Summary by CodeRabbit
Refactor
Tests