Repository navigation
fix(confirm): say when a [y/N] answer is not understood, and end the line on EOF - #982
Conversation
…line on EOF An answer other than y/yes was declined exactly like n, with nothing to tell the user it had not been understood, and Ctrl-D left the caller's cancel message on the prompt line because no newline was echoed. read_answer now takes the output stream: an unrecognized answer is still a no, but a line says so; and input that ended without a newline gets one before the caller prints. Enter, n and no stay silent, since Enter is the documented default. The writes are best effort so a closed stdout cannot turn a decline into an error. rocm uninstall, rocm fix and the SDK-overwrite prompt all share the helper and so all change. Covered by unit tests over each input shape, and by uninstall-07 to -09 under a pseudo-terminal, which assert the message together with the config folder being left in place. Fixes #790 Signed-off-by: Jussi Elo <jussi.elo@amd.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the shared confirmation-helper changes.
No open issues 🎉
What changed in this PR
Addresses #790 in the shared confirmation helper so uninstall, fix, and SDK-overwrite prompts explain unrecognized answers and keep subsequent output on a fresh line after EOF.
Changes:
- Distinguishes affirmative, negative, and unrecognized answers, with escaped feedback and best-effort output.
- Updates all three callers to pass the output stream.
- Adds unit tests and Linux pseudo-terminal scenarios, and documents the behavior.
| File | Description |
|---|---|
tests/e2e-cucumber/tests/e2e/uninstall_steps.rs |
Adds terminal interaction steps and cancellation assertions. |
tests/e2e-cucumber/features/uninstall.feature |
Covers unrecognized answers, EOF, and explicit refusal while preserving files. |
README.md |
Explains confirmation responses and feedback. |
docs/testing.md |
Documents new scenarios and shared-helper coverage. |
docs/manual-testing.md |
Adds manual checks for unrecognized answers and EOF. |
docs/architecture.md |
Updates the confirmation helper’s API and behavior description. |
crates/rocm-core/src/fix/consent.rs |
Passes stdout to the shared answer reader. |
crates/rocm-core/src/confirm.rs |
Implements answer classification, feedback, EOF newline handling, and unit tests. |
apps/rocm/src/uninstall_plan.rs |
Passes stdout for uninstall confirmation feedback. |
apps/rocm/src/therock/consent.rs |
Passes stdout for SDK-overwrite confirmation feedback. |
AGENTS.md |
Updates shared confirmation component guidance. |
Review effort: Balanced
juhovainio
left a comment
There was a problem hiding this comment.
Looks good. The shared read_answer now ends the prompt line on EOF and says when an answer was not understood, all three callers are updated, and the uninstall-07/08/09 scenarios assert the message together with the exit code and the config folder left in place. Unit tests cover the state matrix, and docs are updated across README, testing, manual-testing and architecture.
Non-blocking:
- The echoed answer is unbounded (see inline).
- The EOF newline also fires for piped input without a final newline (inline).
- README reflow left one overlong line, and "cancel quietly" is slightly ambiguous (inline).
- There is no unit test for a partial
nowith no trailing newline. rocm fixand the SDK-overwrite prompt are covered only by unit tests, as the PR notes.
The Linux GPU lanes are still queued; all other checks are green.
| out, | ||
| "{:?} is not yes or no; treating it as no.", | ||
| line.trim() | ||
| ); |
There was a problem hiding this comment.
The echoed answer is line.trim() with no length bound, so a long pasted line is printed in full. Optional: truncate to the first ~40 chars plus an ellipsis.
There was a problem hiding this comment.
Thanks, fixed in 467c849. The echoed answer is now cut to its first 40 characters, counted as characters so a multi-byte one is never split, with ... after the closing quote when there was more. It is still quoted with control characters escaped, and the limit is on the typed characters, so a line made of escapes stays bounded too. Four unit tests cover a long answer, an answer exactly at the limit and one over it, 2-byte and 4-byte characters, and a line of escapes, and they fail when the bound is removed.
The review body has no thread, so the missing unit test for a partial no is here. It is added in 05e6ef2 as read_answer_for_a_no_without_a_newline_declines_and_only_ends_the_prompt_line: it feeds no with no newline and expects the decline and a lone newline, and it fails when the newline write is removed.
| input.read_line(&mut line)?; | ||
| Ok(is_affirmative_answer(&line)) | ||
| if !line.ends_with('\n') { | ||
| let _ = writeln!(out); |
There was a problem hiding this comment.
This newline is also written for non-terminal input that just lacks a trailing newline (printf y |), where nothing was echoed to explain it. Harmless, but the doc says "EOF, as from Ctrl-D"; maybe say "or piped input without a final newline".
There was a problem hiding this comment.
Thanks, you are right that the doc named only Ctrl-D. 05e6ef2 now says "or piped input with no final newline such as printf no |". I kept the newline for that input and documented it: nothing echoed a line end after the prompt there either, so the cursor is still on the prompt line and the caller's next line would run into it. The test for a no without a newline pins it next to the existing one for yes, and the architecture entry for confirm.rs says the same since 335aef2.
| line saying it was not understood and is treated as no. Use `--dry-run` to only | ||
| list, and `--yes` to skip the confirmation. It does not create the folders it | ||
| reports on: with `--keep-binaries`, on a computer where ROCm CLI never ran, it | ||
| says there is nothing to remove. Outside an interactive terminal, when there is something |
There was a problem hiding this comment.
The reflow left this line well over the paragraph's wrap width; please rewrap. Also, "cancel quietly" may read as printing nothing while uninstall cancelled is still printed.
There was a problem hiding this comment.
Thanks, fixed in 8f3dbcb. The paragraph is rewrapped and "cancel quietly" is gone: it now says that Enter, n and no cancel by printing uninstall cancelled, removing nothing and exiting with code 0, which is what uninstall-07 to uninstall-09 assert, and that any other answer cancels the same way after the line saying it was not understood. It was the only place with that phrase, and the manual testing steps now also say that a long answer is shown cut to 40 characters.
…the prompt line, and say piped input does too read_answer writes a newline when the line it read did not end in one. The doc named only EOF from Ctrl-D, but piped input such as printf no | has no final newline either and the cursor is on the prompt line in both cases, so the newline is right for it too. The doc now says so, and a test pins the decline and the lone newline for a no without a newline. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
…characters The line quoted the whole trimmed answer, so a long pasted line was printed in full. It now shows at most 40 characters, counted as characters so a multi-byte one is never split, and marks a cut with an ellipsis after the closing quote. The answer is still quoted with control characters escaped, and the limit counts the typed characters, so an escaped line stays bounded too. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
…nd that a long answer is shown cut The README said Enter, n and no cancel quietly, which reads as printing nothing while uninstall cancelled is printed. It now says what happens, as the uninstall scenarios assert: that line, nothing removed, exit code 0. One overlong line left by the reflow is rewrapped. The manual testing steps also say that an answer longer than 40 characters is shown cut. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
…t and cuts a long echoed answer The confirm.rs entry named only Ctrl-D for the newline and said nothing about the length of the echoed answer. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
nowycondro
left a comment
There was a problem hiding this comment.
🤖 Automated review · review-code · head 335aef2bdc46
Outcome: needs work (one blocking finding). Implements issue #790 fully (unrecognized-answer feedback + EOF newline fix), with a thorough, well-designed test matrix (unit + 3 new PTY-driven e2e scenarios) and no CI check failing at this head.
Blocking
docs/testing.md(~line 1322): the new sentence "They run on the default mock lane" foruninstall-07..-09contradicts this same file's own stated convention for the identical tag combination. These scenarios carry only@requires-os:linux(no@requires-gpu/@requires-no-gpu), and elsewhere this file says such scenarios "run on every Linux lane (WSL2 included), GPU or not" (said explicitly fordiagnose-46/-47, and borne out bydash.feature's identically-tagged PTY scenarios).@requires-no-gpuis the tag this file uses elsewhere to actually confine a scenario to the GitHub-hosted mock lane, and these scenarios don't carry it. Suggested fix: either correct the phrasing to match the established "every Linux lane, GPU or not" convention, or, if PTY prompts genuinely can't run on the self-hosted GPU lane, say why (that would be new information not stated anywhere else in the doc).
Decisions for the author
- answered-by-intent: README's
rocm fix/runtimes uninstall/storage remove-*sections (all of which share the exact sameread_answercode path viaconfirm_uninstall/fix::consent::confirm) weren't updated with the new "not understood" message or EOF-newline behavior, which AGENTS.md's doc-sync rule would otherwise flag. The PR's own Scope section addresses this directly: "The--yeshelp text on the five prompting commands and the README lines that say(default: no)are left as they are: the default and the flags did not change, only what is printed for an answer that is neither yes nor no." Flagging so the author can confirm that's still the intended scope. - non-blocking-improvement:
echoed_answer's cut-to-N-chars-with-ellipsis logic (confirm.rs) duplicates, nearly line for line, the existingtruncate_diagnostic_line(host_gpu/diagnostics.rs, Windows-only) and overlaps conceptually withtruncate_to_chars(probe_exec.rs,pub(crate), same crate). Not a bug — correctly handles multi-byte chars and is well tested — but a shared helper would avoid a third/fourth copy of the same truncation algorithm.
Positive signals
- Both new writes in
read_answerare correctly best-effort (let _ = ...), preservingfix::consent::confirm()'s pre-existing contract that a failed cosmetic write must never turn a successful read into an error — directly exercised by a dedicatedFailingWritertest. - The new PTY e2e assertions use exact-equality checks (not substring) on the prompt/cancellation lines, which genuinely would have caught the pre-fix bugs rather than acting as a weaker proxy.
What this covered: full diff (11 files, base 17f655d…head 335aef2) read in full via independent fan-out passes (core logic + 3 callers, e2e tests, docs, AGENTS.md/code-comment adherence, git history/pattern-consistency), plus design review and the PR's own description/linked issue #790 (accurate, no scope mismatch found). CI: all 29 checks green at this head, including markdown-link and commit-signature checks.
Not a human review. This is an automated code review; please verify findings independently before acting on them.
Brings the branch up to date after the uninstall dry-run footer change landed on main. Both changes add uninstall scenarios, so the confirmation prompt scenarios of this branch are renumbered from uninstall-07 to uninstall-09 to uninstall-13 to uninstall-15, and the README and the testing guide keep main's wording with this branch's prompt sentences added. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
Closes #790
Why
The shared
[y/N]prompt declined anything other thany/yesexactly liken, somaybeatProceed with uninstall? [y/N]:printeduninstall cancelledwith nothing to say the answer had not been understood. And on Ctrl-D the terminal echoes no newline, so the caller's cancel message landed on the prompt line:Proceed with uninstall? [y/N]: uninstall cancelled. Both come fromread_answerinrocm_core::confirm, whichrocm uninstall(andruntimes uninstallandstorageremovals through it),rocm fixand the SDK-overwrite prompt all share, so the fix belongs there and every caller gets it.What changes
read_answernow also takes the output stream.y/yesapprove.n,noand an empty line decline silently, because Enter is the documented default and a deliberate no is not an error. Anything else still declines, but first prints a line such as"maybe" is not yes or no; treating it as no.(the answer is shown quoted and escaped, so control characters typed at the prompt are not echoed raw, and cut to its first 40 characters with...after the closing quote, so a long pasted line does not fill the screen). When the input ended without a newline (Ctrl-D, or piped input with no final newline), a newline is written first so the caller's own message starts on a fresh line. Both writes are best effort, so a closed stdout cannot turn a decline into an error, whichfix'sconfirm()relies on.is_affirmative_answeris replaced byparse_answer, which sorts a line intoAnswer::Yes,Answer::NoorAnswer::Unrecognized; nothing else used the old function.The three callers pass
stdoutas the new argument and are otherwise unchanged. README,docs/manual-testing.md,docs/testing.md,docs/architecture.mdand the shared-component paragraph inAGENTS.mddescribe the new behaviour.Verification
confirm.rscover each state of the matrix:y/yes/YES,n/no/Enter, an unrecognized answer, EOF on an empty read, a partial line at EOF with and without a recognizable answer, an answer holding control characters, a long answer cut at 40 characters, one exactly at the limit, multi-byte characters at the cut, a line of escapes, ayesand anowithout a final newline, a failing feedback write, and a failing read.uninstall-13,-14and-15driverocm uninstallunder a real pseudo-terminal and cover an unrecognized answer, Ctrl-D, and a plain no. Each also asserts the config folder is still there, so the "treating it as no" claim is checked against the resulting state and not only its wording. They are Linux-only like the rest of that feature and run on the default mock lane; no GPU is involved.uninstall-14and the EOF unit tests fail; with the feedback line removeduninstall-13and its unit tests fail; withn/noclassed as unrecognizeduninstall-15and two unit tests fail; with the 40-character bound removed the four cut tests fail, and with the newline write removed the test for anowithout a final newline fails too.cargo test -p rocm-core(1306 passed),cargo test -p rocm(1712 passed),cargo clippy -p rocm-core -p rocm -p e2e-cucumber --all-targets -- -D warnings,cargo fmt --check,cargo xtask check-architecture-doc,lychee --offlineon the changed docs, andcargo xtask e2e -- -n "uninstall-"(all 15 uninstall scenarios passed, fix(uninstall): correct the dry-run footer and stop answering --force with --force-dev-binaries #916's and these three, on the tree before the last main commit, which does not touch the uninstall code). Onerocm-coretest (loopback_lease_blocks_a_second_bind_until_released) failed once under load with an address-in-use error and passed on every rerun; it is in code this change does not touch. The pre-push hooks and the workspace-wide clippy ran on the earlier head.Not verified: the prompt under
rocm fixand the SDK-overwrite prompt is covered only through the shared helper's unit tests; there is no scenario for either (diagnose-16is bare-metal only and the SDK prompt needs a prepared active runtime). The pseudo-terminal scenarios were not run on Windows.Scope
The
--yeshelp text on the five prompting commands and the README lines that say(default: no)are left as they are: the default and the flags did not change, only what is printed for an answer that is neither yes nor no. Re-prompting instead of declining was considered and rejected: the documented default is no, a typo such asysethen fails in the safe direction, and a loop would have to be accepted by three callers with different failure handling.tests/e2e-cucumber/expectations.tomlfor the fixed ticket ID and removed/narrowed any now-stale xfail rows. (No row mentions it.)docs/architecture.md. (Not applicable: no new subcommand.)docs/architecture.mdhas the matching entry. (No file added; theconfirm.rsentry is updated.)uninstall-13to-15.)