tests/tui_spec: remove the NO_COLOR env race behind the flaky suite #164
2 changed files with 1316 additions and 20 deletions
Merge branch 'main' into onionwire/t_75caf868-onionwire-tui-tests-no_color-env-race-ma
commit
0149e105b0
1079
docs/tui-wallet-ux-review.md
Normal file
1079
docs/tui-wallet-ux-review.md
Normal file
File diff suppressed because it is too large
Load diff
257
src/tui.rs
257
src/tui.rs
|
|
@ -1389,14 +1389,16 @@ fn function_key_for(screen: &Screen, code: KeyCode) -> Option<FunctionKey> {
|
|||
impl App {
|
||||
fn new(node: Arc<Node>, rt: tokio::runtime::Handle) -> Result<Self, String> {
|
||||
let friends = node.list_friends()?;
|
||||
// First run is the create flow, not an empty list to pick from; an
|
||||
// install that already has wallets starts on the list, so a restart
|
||||
// lands on the wallets it remembers. A catalogue that cannot be read is
|
||||
// the screen's own error state (the create row still works there).
|
||||
// A fresh install has no wallet to pick and nothing to warn about yet,
|
||||
// so it starts on the main view. The spend-authority warning is not
|
||||
// weakened by this: every path where a user commits to creating or
|
||||
// restoring a wallet (`/wallet create`, F6 `c`, the list's create row)
|
||||
// still routes into `WalletSetup::CreateWarn`. An install that already
|
||||
// has wallets starts on the list, so a restart lands on the wallets it
|
||||
// remembers. A catalogue that cannot be read is the screen's own error
|
||||
// state (the create row still works there).
|
||||
let screen = match node.list_wallets() {
|
||||
Ok(rows) if rows.is_empty() => Screen::WalletSetup(WalletSetup::CreateWarn {
|
||||
typed: String::new(),
|
||||
}),
|
||||
Ok(rows) if rows.is_empty() => Screen::Main,
|
||||
Ok(rows) => Screen::WalletSelect {
|
||||
state: WalletSelectState::from_rows(wallet_rows(rows)),
|
||||
},
|
||||
|
|
@ -2028,8 +2030,31 @@ impl App {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// What `F6` says on an install it cannot name a receive address for. It
|
||||
/// points at this screen's own create/import keys, which exist today, rather
|
||||
/// than at the in-TUI setup screen (a sibling card's work that may not have
|
||||
/// landed yet): the note has to be true on every install that renders it.
|
||||
const WALLET_SETUP_NOTE: &str =
|
||||
"no wallet configured · c create or i import, or set ONIONWIRE_WALLET_RPC";
|
||||
|
||||
fn open_wallet(&mut self) -> Result<(), String> {
|
||||
let addr = self.rt.block_on(self.node.wallet_receive_address())?;
|
||||
// An install with no wallet is a normal state on this screen, not a
|
||||
// fatal one: `F9` already degrades the same call to an empty address.
|
||||
// Propagating the `Err` here ran out of `App::run` and out of `main`, so
|
||||
// pressing `F6` killed the process.
|
||||
let addr = match self.rt.block_on(self.node.wallet_receive_address()) {
|
||||
Ok(addr) => addr,
|
||||
Err(_) => {
|
||||
self.status_note = Some(if self.node.wallet_status().configured {
|
||||
// Configured but the call failed: the endpoint is what is
|
||||
// wrong, not the absence of a wallet.
|
||||
wallet::NOT_CONNECTED_MSG.to_string()
|
||||
} else {
|
||||
Self::WALLET_SETUP_NOTE.to_string()
|
||||
});
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
let balance = self.rt.block_on(self.node.wallet_balance());
|
||||
let transfers = self.rt.block_on(self.node.wallet_recent_transfers(8)).unwrap_or_default();
|
||||
self.screen = Screen::Wallet {
|
||||
|
|
@ -5673,18 +5698,90 @@ mod wallet_store_tests {
|
|||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
/// Nothing remembered means there is no list to choose from: the first run
|
||||
/// goes straight to the existing creation flow.
|
||||
fn key(code: KeyCode) -> KeyEvent {
|
||||
KeyEvent::new(code, KeyModifiers::NONE)
|
||||
}
|
||||
|
||||
/// The frame the real `App::draw` path puts on a terminal of this size.
|
||||
fn frame_on(app: &App, width: u16, height: u16) -> String {
|
||||
let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(width, height))
|
||||
.expect("test terminal");
|
||||
term.draw(|f| app.draw(f)).expect("draw");
|
||||
let buf = term.backend().buffer().clone();
|
||||
let mut drawn = String::new();
|
||||
for y in 0..buf.area.height {
|
||||
for x in 0..buf.area.width {
|
||||
drawn.push_str(buf[(x, y)].symbol());
|
||||
}
|
||||
drawn.push('\n');
|
||||
}
|
||||
drawn
|
||||
}
|
||||
|
||||
/// The first frame on the standard 80x24 terminal.
|
||||
fn first_frame(app: &App) -> String {
|
||||
frame_on(app, 80, 24)
|
||||
}
|
||||
|
||||
/// Whitespace-collapsed copy of some drawn text, so a sentence the renderer
|
||||
/// wrapped across lines still reads as the one string that produced it.
|
||||
fn flattened(text: &str) -> String {
|
||||
text.split_whitespace().collect::<Vec<_>>().join(" ")
|
||||
}
|
||||
|
||||
/// Nothing remembered means nothing to warn about: a first run opens on the
|
||||
/// main view, not on the create flow's spend-authority warning. Asserting
|
||||
/// the screen alone would pass with the warning merely drawn behind Main, so
|
||||
/// the second half reads the first frame the app actually renders.
|
||||
#[test]
|
||||
fn an_install_with_no_wallet_starts_on_the_create_flow() {
|
||||
fn a_fresh_install_starts_on_main_not_the_spend_warning() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (app, _rt) = app(&dir.path().join("home"), &[]);
|
||||
assert!(
|
||||
matches!(app.screen, Screen::Main),
|
||||
"a first run must start on the main view"
|
||||
);
|
||||
|
||||
let frame = first_frame(&app);
|
||||
assert!(
|
||||
!flattened(&frame).contains(&flattened(wallet::SPEND_AUTHORITY_WARNING)),
|
||||
"the spend-authority warning must not be on the first frame:\n{frame}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Moving the entry point did not weaken the warning: `/wallet create` on a
|
||||
/// fresh install still lands on `CreateWarn`, and the frame really carries
|
||||
/// the spend-authority copy.
|
||||
#[test]
|
||||
fn the_create_flow_is_still_reachable_and_still_warns() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (mut app, _rt) = app(&dir.path().join("home"), &[]);
|
||||
assert!(matches!(app.screen, Screen::Main));
|
||||
|
||||
for c in "/wallet create".chars() {
|
||||
app.handle_key(key(KeyCode::Char(c))).expect("typed key");
|
||||
}
|
||||
app.handle_key(key(KeyCode::Enter)).expect("enter");
|
||||
|
||||
assert!(
|
||||
matches!(
|
||||
app.screen,
|
||||
Screen::WalletSetup(WalletSetup::CreateWarn { .. })
|
||||
),
|
||||
"a first run must start on the create flow"
|
||||
"the create command must still warn before anything is created"
|
||||
);
|
||||
// The overlay is taller than its body and scrolls to its tail, so the
|
||||
// 80x24 frame carries only the warning's closing words; the whole
|
||||
// sentence needs a frame wide enough to hold it on one row.
|
||||
let narrow = first_frame(&app);
|
||||
assert!(
|
||||
flattened(&narrow).contains("trust."),
|
||||
"the create flow must warn on the standard frame:\n{narrow}"
|
||||
);
|
||||
let wide = frame_on(&app, 200, 60);
|
||||
assert!(
|
||||
flattened(&wide).contains(&flattened(wallet::SPEND_AUTHORITY_WARNING)),
|
||||
"the spend-authority warning must be drawn on the create flow:\n{wide}"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -5777,7 +5874,10 @@ mod wallet_store_tests {
|
|||
let dir = tempfile::tempdir().unwrap();
|
||||
let home = dir.path().join("home");
|
||||
let (mut app, _rt) = app(&home, &[]);
|
||||
assert!(matches!(app.screen, Screen::WalletSetup(_)));
|
||||
assert!(
|
||||
matches!(app.screen, Screen::Main),
|
||||
"a fresh install starts on the main view"
|
||||
);
|
||||
assert!(
|
||||
app.node.list_wallets().expect("list wallets").is_empty(),
|
||||
"nothing to list yet"
|
||||
|
|
@ -5803,6 +5903,123 @@ mod wallet_store_tests {
|
|||
);
|
||||
assert_eq!(app.status_note.as_deref(), Some("opened wallet fresh"));
|
||||
}
|
||||
|
||||
fn key(code: KeyCode) -> KeyEvent {
|
||||
KeyEvent::new(code, KeyModifiers::NONE)
|
||||
}
|
||||
|
||||
/// What the real render path puts on an 80x24 terminal — `App::draw`, not a
|
||||
/// stand-in widget.
|
||||
fn frame_text(app: &App) -> String {
|
||||
let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(80, 24))
|
||||
.expect("test terminal");
|
||||
term.draw(|f| app.draw(f)).expect("draw");
|
||||
let buf = term.backend().buffer().clone();
|
||||
let mut out = String::new();
|
||||
for y in 0..buf.area.height {
|
||||
for x in 0..buf.area.width {
|
||||
out.push_str(buf[(x, y)].symbol());
|
||||
}
|
||||
out.push('\n');
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// `F6` on an install with no wallet is a normal state, not a fatal one: the
|
||||
/// address call fails there by design. Propagating that `Err` ran out of
|
||||
/// `App::run` and out of `main`, so pressing the key killed the process.
|
||||
#[test]
|
||||
fn f6_on_a_bare_install_opens_the_wallet_screen_instead_of_exiting() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (mut app, _rt) = app(&dir.path().join("home"), &[]);
|
||||
// A first run opens on the create flow; the key in the bug report is
|
||||
// pressed from the main view (`Esc` leaves the create prompt, and is
|
||||
// harmless once a fresh install starts on `Main` itself).
|
||||
app.handle_key(key(KeyCode::Esc))
|
||||
.expect("leave the create flow");
|
||||
assert!(matches!(app.screen, Screen::Main));
|
||||
|
||||
app.handle_key(key(KeyCode::F(6)))
|
||||
.expect("F6 must not fail on an install with no wallet");
|
||||
|
||||
let Screen::Wallet { receive_addr, .. } = &app.screen else {
|
||||
panic!("F6 must open the wallet screen");
|
||||
};
|
||||
assert!(
|
||||
receive_addr.is_empty(),
|
||||
"the field must be empty, not the error text: {receive_addr:?}"
|
||||
);
|
||||
assert!(
|
||||
app.status_note
|
||||
.as_deref()
|
||||
.is_some_and(|n| n.contains("no wallet configured")),
|
||||
"the screen must name the way forward: {:?}",
|
||||
app.status_note
|
||||
);
|
||||
}
|
||||
|
||||
/// The frame the user actually gets. The node's error string never reaches
|
||||
/// it, and the note is rendered on the status line of the main view — which
|
||||
/// is where this screen's footer lives.
|
||||
///
|
||||
/// Not asserted here: the wallet screen's own body (`address` / `balance` /
|
||||
/// `recent transfers`). `draw_wallet` renders that paragraph into a
|
||||
/// `Constraint::Length(2)` slot whose borders consume both rows, so the body
|
||||
/// is clipped away on every install, empty or not — a pre-existing defect
|
||||
/// filed as its own card, outside this change's scope.
|
||||
#[test]
|
||||
fn f6_on_a_bare_install_never_draws_the_error_and_states_the_way_forward() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (mut app, _rt) = app(&dir.path().join("home"), &[]);
|
||||
app.handle_key(key(KeyCode::Esc))
|
||||
.expect("leave the create flow");
|
||||
app.handle_key(key(KeyCode::F(6))).expect("F6");
|
||||
|
||||
let wallet_frame = frame_text(&app);
|
||||
assert!(
|
||||
wallet_frame.contains("wallet") && wallet_frame.contains("Esc back"),
|
||||
"the F6 screen must be what is on screen: {wallet_frame}"
|
||||
);
|
||||
assert!(
|
||||
!wallet_frame.contains("no receive address"),
|
||||
"the node's error must not reach the screen: {wallet_frame}"
|
||||
);
|
||||
|
||||
app.handle_key(key(KeyCode::Esc)).expect("back to main");
|
||||
assert!(matches!(app.screen, Screen::Main));
|
||||
let main_frame = frame_text(&app);
|
||||
assert!(
|
||||
main_frame.contains("no wallet configured"),
|
||||
"the note must be rendered, not only stored: {main_frame}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The control: when the node can name an address, `F6` fills the screen
|
||||
/// with it exactly as before — no note, no empty field.
|
||||
#[test]
|
||||
fn f6_on_an_install_with_a_wallet_still_fills_the_receive_address() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (mut app, _rt) = app(&dir.path().join("home"), &[("onionwire", "lance")]);
|
||||
// Same documented mainnet standard address `tests/wallet.rs` uses.
|
||||
let addr = "4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYTRj5UzqtReoS44qo9mtmXCqY45DJ852K5Jv2684Rge";
|
||||
app.node
|
||||
.set_self_profile("", "", addr)
|
||||
.expect("set profile");
|
||||
app.handle_key(key(KeyCode::Esc)).expect("leave the list");
|
||||
assert!(matches!(app.screen, Screen::Main));
|
||||
|
||||
app.handle_key(key(KeyCode::F(6))).expect("F6");
|
||||
|
||||
let Screen::Wallet { receive_addr, .. } = &app.screen else {
|
||||
panic!("F6 must open the wallet screen");
|
||||
};
|
||||
assert_eq!(receive_addr, addr);
|
||||
assert!(
|
||||
app.status_note.is_none(),
|
||||
"an address is no reason to warn: {:?}",
|
||||
app.status_note
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The optional seed-offset step sits between the pasted seed and the wallet-file
|
||||
|
|
@ -6004,19 +6221,19 @@ mod wallet_offset_tests {
|
|||
"a prefix is not the word"
|
||||
);
|
||||
|
||||
// The fourth letter is the one that proceeds: it opens the wallet, and
|
||||
// this install has none, so the open is what fails. Nothing before the
|
||||
// The fourth letter is the one that proceeds: it opens the wallet. This
|
||||
// install has none, so the screen opens address-less — the open itself
|
||||
// must not fail (the same degradation `F6` needs). Nothing before the
|
||||
// full word gets that far.
|
||||
assert!(
|
||||
app.status_note.is_none(),
|
||||
"a prefix must not run any import side effect"
|
||||
);
|
||||
let err = app
|
||||
.handle_key(key(KeyCode::Char('n')))
|
||||
.expect_err("SEEN must attempt to open the wallet");
|
||||
app.handle_key(key(KeyCode::Char('n')))
|
||||
.expect("SEEN must open the wallet screen");
|
||||
assert!(
|
||||
err.contains("receive address") || err.to_ascii_lowercase().contains("not configured"),
|
||||
"expected the open to fail on the missing wallet, got {err}"
|
||||
matches!(app.screen, Screen::Wallet { .. }),
|
||||
"only the full word proceeds"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue