Repository navigation
refactor(dash-tui): share one append/backspace handler across text-input fields - #848
Conversation
…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>
There was a problem hiding this comment.
🟢 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
|
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 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
left a comment
There was a problem hiding this comment.
🤖 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-rolledpush/popmatch arm affected only that screen. Now a bug inapply_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.mdnow tell a contributor to callapply_char_keyinstead of writing a tenthpush/popmatch 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'styping_and_backspace_edit_the_active_field_and_clear_the_messagetest 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.Concurrencywired toOut) immediately, not just on the specific field it happens to type-check.- The two new
onboarding.rstests (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 toCharand only while a pin mode is selected, withBackspaceexempt 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
|
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 All checks are green on the current head and the PR is approved, so I'm adding it to the merge queue. |
Why
Eight dash-TUI modules each hand-rolled the same "a
Charappends,Backspacepops one char" match arms for theirStringbuffers, fourteen buffers in all: four inbench_run, three inserve_wizard, two ininstall_manager, and one each inlogs_view,command_screen,model_picker,runtime_managerandonboarding. The next text field would have been a ninth copy. Fixes #770.What changes
ui/widgets.rsgainsapply_char_keyandapply_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);Backspaceis never filtered. Both returntruefor anyCharorBackspacekey, whether or not the buffer changed, so a caller keeps its own side effects exact:bench_runclears its message andmodel_pickerresets 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 fieldmatchfor typing and for backspace. The helper is documented in the shared components lists inAGENTS.mdanddocs/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 aKeyCodeand cannot see modifiers.Scope
folder_browser.rs, which the issue lists, is not converted: itsBackspacemeans "go to the parent directory" and it has no text buffer.app/actions.rsis deliberately left alone. Its keys are first mapped to aKeyActionby a pure, separately tested table and applied in the same file, so there is no duplicated match arm to collapse; theAGENTS.mdentry names it as the exception.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-tuipasses with 977 library tests (960 before the change).cargo clippy -p rocm-dash-tui --all-targets -- -D warningsandcargo fmt --checkare 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
ConcurrencyandOutbuffers, clearing the bench message or resetting the picker cursor on non-edit keys, pointing the serve wizard'sHostat the model buffer, droppingBackspacefrom 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 thepop, ignoring the filter, and not reportingBackspaceas consumed.Not verified: the dash TUI was not driven by hand in a terminal, and
cargo xtask coverage,scripts/smoke_local.pyand the GPU lanes were not run locally.If this PR fixes a bug, searched
tests/e2e-cucumber/expectations.tomlfor 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.)