Skip to content

refactor(dash-tui): share one append/backspace handler across text-input fields - #848

Merged
jussielo-amd merged 2 commits into
ROCm:mainfrom
jussielo-amd:worktree-dash-tui-apply-char-key
Nov 3, 2026
Merged

jussielo-amd merged 2 commits into
ROCm:mainfrom
jussielo-amd:worktree-dash-tui-apply-char-key

Conversation

@jussielo-amd

Copy link
Copy Markdown
Collaborator

Why

Eight dash-TUI modules each hand-rolled the same "a Char appends, Backspace pops one char" match arms for their String buffers, fourteen buffers in all: four in bench_run, three in serve_wizard, two in install_manager, and one each in logs_view, command_screen, model_picker, runtime_manager and onboarding. The next text field would have been a ninth copy. Fixes #770.

What changes

ui/widgets.rs gains apply_char_key and apply_char_key_filtered, and every text field above now goes through them. The filtered form takes a predicate for the fields that refuse some characters (the serve wizard's digits-only port, the onboarding pin value's control-character filter); Backspace is never filtered. Both return true for any Char or Backspace key, whether or not the buffer changed, so a caller keeps its own side effects exact: bench_run clears its message and model_picker resets its cursor on any edit key, as before. The field-routed forms (bench_run, install_manager, serve_wizard) now pick the focused buffer once instead of repeating the field match for typing and for backspace. The helper is documented in the shared components lists in AGENTS.md and docs/architecture.md.

There is no user-visible change. Every converted handler behaves as it did, including the quirks worth knowing about: the onboarding pin value ignores characters until a pin mode is chosen but still accepts Backspace, and Ctrl/Alt-modified characters are still appended as text everywhere, because the helper takes a KeyCode and cannot see modifiers.

Scope

  • folder_browser.rs, which the issue lists, is not converted: its Backspace means "go to the parent directory" and it has no text buffer.
  • The Chat tab's input in app/actions.rs is deliberately left alone. Its keys are first mapped to a KeyAction by a pure, separately tested table and applied in the same file, so there is no duplicated match arm to collapse; the AGENTS.md entry names it as the exception.
  • No scenario in tests/e2e-cucumber/features/ is added because this is a purely internal refactor: nothing the CLI prints, returns or creates changes, and no runtime selection is affected.

Verification

  • cargo test -p rocm-dash-tui passes with 977 library tests (960 before the change). cargo clippy -p rocm-dash-tui --all-targets -- -D warnings and cargo fmt --check are clean, and the repository's pre-push hooks (fmt, clippy, cargo test, commit signature checks) passed locally.

  • The new tests were shown to fail when their target is broken. Ten single-branch breakages of the converted handlers each turn a test red: swapping the Concurrency and Out buffers, clearing the bench message or resetting the picker cursor on non-edit keys, pointing the serve wizard's Host at the model buffer, dropping Backspace from the command, logs, runtime-import and serve-wizard handlers, letting a non-text install field edit the channel, and dropping the onboarding control-character filter. The helper's own tests also fail under dropping the pop, ignoring the filter, and not reporting Backspace as consumed.

  • Not verified: the dash TUI was not driven by hand in a terminal, and cargo xtask coverage, scripts/smoke_local.py and the GPU lanes were not run locally.

  • 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. (Not applicable: refactor, no bug fixed.)

  • 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 or subsystem.)

  • 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 — per AGENTS.md §3. (Not applicable: no user-facing message is added or changed.)

…put fields

Eight dash-TUI modules each hand-rolled the same Char-pushes/Backspace-pops
match arms for their String buffers. Add apply_char_key and a predicate
variant to ui/widgets.rs and route those fields through them, so the next
text field reuses it instead of adding another copy.

The helper reports whether the key was a text-edit key (not whether the
buffer changed), which keeps the existing side effects exact: bench_run
clears its message and model_picker resets its cursor on any edit key, the
serve wizard Port still swallows non-digits, and the onboarding pin value
still ignores chars until a pin mode is chosen while Backspace stays ungated.

No user-visible behaviour change. Adds characterization tests for those
preserved quirks and documents the helper in AGENTS.md.

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
…e helper in architecture.md

Review of the shared text-edit helper found that several rewritten dispatch
arms had no test that fails when they are broken: Backspace on the command,
logs, runtime-import and serve-wizard screens, the Host, Concurrency and Out
buffers, the non-edit-key case that must not clear bench_run's message or
reset model_picker's cursor, and the onboarding control-char filter. Add
those, and make the install-manager non-text-field assertion check each key
on its own so a stray append and pop can no longer cancel out.

Use one catch-all dispatch style across the handlers, and add the helper to
the shared ui components list in docs/architecture.md, which mirrors the
AGENTS.md list.

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 text-editing refactor.

No open issues 🎉

What changed in this PR

Addresses #770 by centralizing append/backspace handling for fourteen text buffers across eight dash-TUI modules, preserving existing input behavior and caller-specific side effects.

Changes:

  • Adds shared text-edit helpers, including character filtering and explicit key-consumption semantics.
  • Converts existing handlers and adds regression tests for field routing, filtering, backspace, and state resets.
  • Documents helper reuse and the Chat input exception; leaves folder navigation unchanged.
File Description
docs/​architecture.md Documents shared text-edit helpers and the Chat exception.
crates/​rocm-dash-tui/​src/​ui/​widgets.rs Adds helpers and tests for editing, filtering, and key consumption.
crates/​rocm-dash-tui/​src/​ui/​serve_wizard.rs Unifies field editing while preserving digits-only port input.
crates/​rocm-dash-tui/​src/​ui/​runtime_manager.rs Uses shared editing for runtime import paths.
crates/​rocm-dash-tui/​src/​ui/​onboarding.rs Preserves pin-mode gating and control-character filtering.
crates/​rocm-dash-tui/​src/​ui/​model_picker.rs Uses shared editing while preserving cursor resets.
crates/​rocm-dash-tui/​src/​ui/​logs_view.rs Uses shared query editing and adds backspace coverage.
crates/​rocm-dash-tui/​src/​ui/​install_manager.rs Consolidates focused-field editing and tests buffer isolation.
crates/​rocm-dash-tui/​src/​ui/​command_screen.rs Uses shared command-line editing and tests backspace.
crates/​rocm-dash-tui/​src/​ui/​bench_run.rs Centralizes buffer selection and preserves message clearing.
AGENTS.md Adds text-edit helpers to shared-component guidance.

Review effort: Balanced

@jussielo-amd
jussielo-amd marked this pull request as ready for review November 3, 2026 08:56
@jussielo-amd
jussielo-amd requested a review from a team as a code owner November 3, 2026 08:56
@volen-silo

Copy link
Copy Markdown
Collaborator

I read the whole diff at 9944d28 and compared each converted handler against its previous version. I found nothing to fix: the match-arm order, the serve wizard's digits-only port, the onboarding pin gate and control-character filter, and the model picker and bench_run side effects all behave as before, and a grep finds no other hand-rolled push/pop text edits left in the dash TUI besides the documented Chat exception and folder_browser. Each converted handler has a test, plus the helper's own tests.

This looks safe to approve after final validation. That is what a read of the diff can show; it is not a CI result or a runtime check, and I did not build or run it, so the remaining checks and the maintainer's own pass still apply. This is not itself an approval.

@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 (Claude Code) · 9944d28

This automation never files a GitHub approval, so no approving review will appear here whatever the outcome — the merge decision stays with a human reviewer.

Review — no blocking findings

Full review of the whole change. Implements issue #770 (extract a shared apply_char_key append/backspace handler for dash-TUI text-input buffers) faithfully; the one listed module not converted (folder_browser.rs) is verified to genuinely have no text buffer (its Backspace navigates to the parent directory), so the deviation from the issue's file list is correct, not a gap.

Blocking

None

Non-blocking

None

Decisions for the author

  • The shared helper concentrates 8 screens' text-input logic behind one function — tradeoff
    Before this change, a bug in one screen's hand-rolled push/pop match arm affected only that screen. Now a bug in apply_char_key/apply_char_key_filtered (crates/rocm-dash-tui/src/ui/widgets.rs) would affect all 8 converted screens at once. This is the standard DRY-vs-blast-radius tradeoff and looks deliberate and well-mitigated here: the helper itself has dedicated unit tests for every branch (multi-byte backspace, empty-buffer backspace, rejected-but-consumed filtered char, non-text-key rejection), and this same PR adds a targeted regression test at each of the 8 call sites. Flagging only so the tradeoff is explicit rather than implicit.
  • The convention is enforced by documentation only — non-blocking-improvement
    AGENTS.md/docs/architecture.md now tell a contributor to call apply_char_key instead of writing a tenth push/pop match arm, but nothing structurally prevents a future module from hand-rolling it again (the repo already runs other grep-style CI checks, e.g. "Stale xfail hint" and "Skill checks (skillscope)", so a similar lightweight lint is plausible if this pattern recurs). Not a defect in this PR — just an opening for the next copy to slip back in.

Positive signals

  • bench_run.rs's typing_and_backspace_edit_the_active_field_and_clear_the_message test tabs through all four fields, typing/backspacing in each and asserting the other three buffers are untouched after every edit — this would catch a field-routing transposition (e.g. Concurrency wired to Out) immediately, not just on the specific field it happens to type-check.
  • The two new onboarding.rs tests (control_chars_are_not_collected_into_the_pin_value, backspace_still_edits_pin_value_after_returning_to_no_pin_mode) target exactly the trickiest edge case in the whole diff — a control-character filter that only applies to Char and only while a pin mode is selected, with Backspace exempt from both conditions — and each asserts the resulting buffer content rather than just that the call didn't panic.
  • The second commit's own message is a model of honest self-review: it names the specific untested single-branch breakages a first pass left behind (swapped buffers, a missing non-edit-key test, a missing control-char-filter test) and closes every one of them before the PR was opened, rather than leaving that for a reviewer to find.

Deployment notes

None. Purely internal refactor — no string/message, CLI argument, or public-API surface changes; confirmed no user-facing text was touched anywhere in the diff. CI (Windows/Linux build-and-test, clippy, ratcheted coverage, E2E) is green on the reviewed commit.

What this covered

Every file in the change, read completely at commit range 6eeec620c3d4...9944d28258 3 (6eeec620c3d451a52bd8f98ef218fb9e8a0549a4...9944d282583e1203cf374661589a05d10353636e): AGENTS.md, docs/architecture.md, widgets.rs, and all 8 converted modules (bench_run.rs, command_screen.rs, install_manager.rs, logs_view.rs, model_picker.rs, onboarding.rs, runtime_manager.rs, serve_wizard.rs), split across 3 coupled-file passes plus a dedicated agent-instruction/history/prior-changes/code-comments pass, all run as independent fan-out workers. Also read folder_browser.rs and app/actions.rs in full to verify the description's two scope-exclusion claims directly against the code (both confirmed accurate). Retrieved issue #770 directly by identifier (not by following the description's implicit reference) and compared it against the change's actual scope.

Did not run cargo test/mutation testing directly (read-only review); the PR's claim that specific single-branch breakages turn each new test red was verified by static tracing of every converted match arm against the pre-PR diff, corroborated by this commit's CI showing all checks green, including "Test (affected crates)", "build-and-test" (Windows and Linux), and "Coverage (rocm-dash crates, ratcheted)". The PR description and the named ticket (#770) were read only after all findings above were reached independently from the code. Not reconciled against the PR's existing discussion thread (one comment is present on the PR; it was not read, per this method's rule that only the description and named ticket count as the change's own stated intent).


🤖 Generated with Claude Code

@jussielo-amd

Copy link
Copy Markdown
Collaborator Author

Thanks all for the reviews. I went through every review and comment on 9944d28 and none asks for a code change, so I'm not pushing anything new and the head stays as reviewed.

On the one open note, that the shared helper is enforced by documentation only: agreed, and I'd rather not add a grep-style lint for a pattern that has no known second copy yet. If a hand-rolled push/pop text edit reappears in the dash TUI, a lightweight CI check is the natural follow-up.

All checks are green on the current head and the PR is approved, so I'm adding it to the merge queue.

@jussielo-amd
jussielo-amd added this pull request to the merge queue Nov 3, 2026
Merged via the queue into ROCm:main with commit c6ab82b Nov 3, 2026
33 checks passed
@jussielo-amd
jussielo-amd deleted the worktree-dash-tui-apply-char-key branch November 3, 2026 10:00
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.

dash-TUI: extract a shared append/backspace key handler for text-input buffers

4 participants