test(M8.3): guarantee terminal restoration on failure
Wrap fallible TUI initialization and execution in an injectable restoration guard. Prove an injected client failure restores the terminal while existing buffered-client tests retain nonblocking refresh coverage. Tests: cargo fmt --all; cargo test -p tui; cargo clippy --workspace --all-targets --all-features -- -D warnings.
This commit is contained in:
parent
a286e4258e
commit
e7a0254b38
|
|
@ -340,6 +340,11 @@ backend IDs/errors. The compact mixer status line distinguishes connected,
|
|||
connecting, missing, ambiguous, and failed devices, adding a connect/select
|
||||
action where the user can resolve the state.
|
||||
|
||||
Terminal restoration is guarded around all fallible client/run work after
|
||||
terminal initialization. The restore action is injectable for failure-path
|
||||
tests; client and transport diagnostics stay in the rendered status area rather
|
||||
than being printed over the alternate screen.
|
||||
|
||||
Terminal colors come from semantic theme palettes rather than renderer-local
|
||||
literals. The built-ins are Default, Dracula, Nord, Gruvbox Dark, Catppuccin
|
||||
Mocha, and Solarized Dark. `tui --theme NAME` selects the initial palette and
|
||||
|
|
|
|||
9
task.md
9
task.md
|
|
@ -280,10 +280,11 @@ Dependencies: M7, M4 for real use.
|
|||
ambiguity selection guidance, and transport errors in its compact status
|
||||
line. Keep this item open until editor-managed assignment persistence can
|
||||
report save/conflict failures from M9.3.
|
||||
- [ ] **M8.3 Terminal lifecycle:** restoration on normal/error exit, nonblocking refresh, logging away from display. Tests: injected IO/client failure releases terminal guard; polling/refresh does not block server operation.
|
||||
Blocking IPC now runs on a joined worker and a delayed request cannot block
|
||||
redraw access; keep this item open for explicit terminal-restoration failure
|
||||
injection and log routing.
|
||||
- [x] **M8.3 Terminal lifecycle:** restoration on normal/error exit, nonblocking refresh, logging away from display. Tests: injected IO/client failure releases terminal guard; polling/refresh does not block server operation.
|
||||
Blocking IPC runs on a joined worker and a delayed request cannot block redraw
|
||||
access. The restoration guard is independently injected and proven to run
|
||||
when client initialization returns an error; client/transport diagnostics are
|
||||
rendered inside the TUI rather than printed into the active terminal.
|
||||
- [ ] **M8.4 Relative-group activation (reserved):** wire the prepared
|
||||
per-member maximum state into origin-aware runtime observations, lifecycle,
|
||||
snapshots, pickup, and editor help before allowing `volume_mode = "relative"`
|
||||
|
|
|
|||
|
|
@ -404,8 +404,9 @@ pub fn run_live_with_theme(
|
|||
) -> io::Result<()> {
|
||||
let client = BufferedMixerClient::spawn(client)?;
|
||||
let mut terminal = ratatui::init();
|
||||
let _guard = RestoreTerminal;
|
||||
LiveTui::with_theme(client, theme)?.run(&mut terminal)
|
||||
with_terminal_restore(ratatui::restore, || {
|
||||
LiveTui::with_theme(client, theme)?.run(&mut terminal)
|
||||
})
|
||||
}
|
||||
|
||||
/// Retains the original preview example without opening audio or IPC.
|
||||
|
|
@ -413,11 +414,21 @@ pub fn run() -> io::Result<()> {
|
|||
run_live(DemoClient::default())
|
||||
}
|
||||
|
||||
struct RestoreTerminal;
|
||||
fn with_terminal_restore<T>(
|
||||
restore: impl FnOnce(),
|
||||
operation: impl FnOnce() -> io::Result<T>,
|
||||
) -> io::Result<T> {
|
||||
let _guard = RestoreTerminal(Some(restore));
|
||||
operation()
|
||||
}
|
||||
|
||||
impl Drop for RestoreTerminal {
|
||||
struct RestoreTerminal<F: FnOnce()>(Option<F>);
|
||||
|
||||
impl<F: FnOnce()> Drop for RestoreTerminal<F> {
|
||||
fn drop(&mut self) {
|
||||
ratatui::restore();
|
||||
if let Some(restore) = self.0.take() {
|
||||
restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -857,6 +868,44 @@ mod tests {
|
|||
assert!(app.exit);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn terminal_restore_runs_when_client_initialization_fails() {
|
||||
struct FailingClient;
|
||||
|
||||
impl MixerClient for FailingClient {
|
||||
fn snapshot(&mut self) -> io::Result<MixerSnapshot> {
|
||||
Err(io::Error::other("injected client failure"))
|
||||
}
|
||||
|
||||
fn set_volume(
|
||||
&mut self,
|
||||
_id: MixerObjectId,
|
||||
_gain: f64,
|
||||
_expected_revision: u64,
|
||||
) -> io::Result<MixerSnapshot> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn toggle_mute(
|
||||
&mut self,
|
||||
_id: MixerObjectId,
|
||||
_expected_revision: u64,
|
||||
) -> io::Result<MixerSnapshot> {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
let restored = Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
let restore_flag = Arc::clone(&restored);
|
||||
let result = with_terminal_restore(
|
||||
move || restore_flag.store(true, std::sync::atomic::Ordering::Release),
|
||||
|| LiveTui::new(FailingClient).map(|_| ()),
|
||||
);
|
||||
|
||||
assert_eq!(result.unwrap_err().to_string(), "injected client failure");
|
||||
assert!(restored.load(std::sync::atomic::Ordering::Acquire));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn theme_key_cycles_known_palettes_and_wraps() {
|
||||
let mut app = LiveTui::new(DemoClient::default()).unwrap();
|
||||
|
|
|
|||
Loading…
Reference in New Issue