Skip to content

fix(confirm): say when a [y/N] answer is not understood, and end the line on EOF - #982

Merged
jussielo-amd merged 6 commits into
mainfrom
worktree-issue-790-yn-prompt-feedback
Nov 9, 2026
Merged

jussielo-amd merged 6 commits into
mainfrom
worktree-issue-790-yn-prompt-feedback

Conversation

@jussielo-amd

@jussielo-amd jussielo-amd commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #790

Why

The shared [y/N] prompt declined anything other than y/yes exactly like n, so maybe at Proceed with uninstall? [y/N]: printed uninstall cancelled with 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 from read_answer in rocm_core::confirm, which rocm uninstall (and runtimes uninstall and storage removals through it), rocm fix and the SDK-overwrite prompt all share, so the fix belongs there and every caller gets it.

What changes

read_answer now also takes the output stream. y/yes approve. n, no and 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, which fix's confirm() relies on. is_affirmative_answer is replaced by parse_answer, which sorts a line into Answer::Yes, Answer::No or Answer::Unrecognized; nothing else used the old function.

The three callers pass stdout as the new argument and are otherwise unchanged. README, docs/manual-testing.md, docs/testing.md, docs/architecture.md and the shared-component paragraph in AGENTS.md describe the new behaviour.

Verification

  • Unit tests in confirm.rs cover 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, a yes and a no without a final newline, a failing feedback write, and a failing read.
  • uninstall-13, -14 and -15 drive rocm uninstall under 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.
  • Mutation check: with the newline write removed uninstall-14 and the EOF unit tests fail; with the feedback line removed uninstall-13 and its unit tests fail; with n/no classed as unrecognized uninstall-15 and two unit tests fail; with the 40-character bound removed the four cut tests fail, and with the newline write removed the test for a no without a final newline fails too.
  • Run locally on the final head (a merge of main into the branch, after the uninstall footer change fix(uninstall): correct the dry-run footer and stop answering --force with --force-dev-binaries #916 and the later main commits): 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 --offline on the changed docs, and cargo 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). One rocm-core test (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 fix and the SDK-overwrite prompt is covered only through the shared helper's unit tests; there is no scenario for either (diagnose-16 is bare-metal only and the SDK prompt needs a prepared active runtime). The pseudo-terminal scenarios were not run on Windows.

Scope

The --yes help 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 as yse then fails in the safe direction, and a loop would have to be accepted by three callers with different failure handling.

  • If this PR fixes a bug, searched tests/e2e-cucumber/expectations.toml for the fixed ticket ID and removed/narrowed any now-stale xfail rows. (No row mentions it.)
  • If this PR adds a new subcommand or subsystem, its domain implementation lives in its own file per docs/architecture.md. (Not applicable: no new subcommand.)
  • If this PR adds, renames or removes a production source file, docs/architecture.md has the matching entry. (No file added; the confirm.rs entry is updated.)
  • Every new or changed user-facing message was read against the code path that runs after it, and its test asserts the resulting state, not only the wording. (uninstall-13 to -15.)

…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@jussielo-amd
jussielo-amd marked this pull request as ready for review November 9, 2026 12:37
@jussielo-amd
jussielo-amd requested a review from a team as a code owner November 9, 2026 12:37

@juhovainio juhovainio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 no with no trailing newline.
  • rocm fix and 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()
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md Outdated
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@jussielo-amd
jussielo-amd added this pull request to the merge queue Nov 9, 2026

@nowycondro nowycondro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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" for uninstall-07..-09 contradicts 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 for diagnose-46/-47, and borne out by dash.feature's identically-tagged PTY scenarios). @requires-no-gpu is 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 same read_answer code path via confirm_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 --yes help 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 existing truncate_diagnostic_line (host_gpu/diagnostics.rs, Windows-only) and overlaps conceptually with truncate_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_answer are correctly best-effort (let _ = ...), preserving fix::consent::confirm()'s pre-existing contract that a failed cosmetic write must never turn a successful read into an error — directly exercised by a dedicated FailingWriter test.
  • 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.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 9, 2026
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>
@jussielo-amd
jussielo-amd added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit ca23a1c Nov 9, 2026
30 checks passed
@jussielo-amd
jussielo-amd deleted the worktree-issue-790-yn-prompt-feedback branch November 9, 2026 19:53
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.

[y/N] prompt: unrecognized answers get no feedback, and Ctrl-D leaves the cancel message on the prompt line

4 participants