tui: mark friends invite-stale after an F8 prekey rotation
All checks were successful
ci / test (pull_request) Successful in 21m19s
ci / sdk (pull_request) Successful in 2m7s

F8 replaces the Noise static prekey and the ML-KEM key together and clears
every stored ratchet, but nothing recorded the cut: a friend on the roster
still held an invite with the old prekey, the next inbound frame could not be
decrypted, our own outbound re-bootstrapped an epoch they did not have, and the
send looked delivered. The only fix -- ask them to paste the new invite -- was
never said.

- `rotate_prekey` snapshots the roster into `$ONIONWIRE_HOME/invite-stale`
  (derived local state; no store schema change, no wire field, no new crate).
  `Node::invite_stale(pk)` / `invite_stale_friends()` answer the question, and
  an install that never rotated has no file and nothing marked.
- `Node::send` and `Node::send_once` fail closed with `invite stale` for a
  pre-rotation friend instead of silently re-bootstrapping past the cut.
- The roster gains its own `invite stale` word and colour token (violet; `stale`
  keeps meaning "the last dial did not answer"), and the alert row above the
  panes carries `invite stale -- F2 to share your new invite, they F3-paste it`,
  recomputed every draw so F3-pasting an invite for that friend clears it.
- `add_friend_payload` removes the pubkey from the set, which is the test the
  card asks for; docs/TUI.md documents the marker.

This makes the existing hard cut legible. It does not add in-band revocation or
a soft rotation; the threat model's hard-cut wording stays as it is.
This commit is contained in:
rust-dev 2026-10-22 23:38:30 -04:00
commit 9b53632859
No known key found for this signature in database
4 changed files with 436 additions and 20 deletions

View file

@ -108,7 +108,13 @@ the composer types the letter.
`loc `; offline friends must F3-paste the new invite.
- **F8.** Type `ROTATE`. Prekey is the Noise static **and** the ratchet bootstrap
seed. Every friend must F3-paste the new invite. Status:
`prekey rotated · friends must F3-paste your new invite`.
`prekey rotated · friends must F3-paste your new invite`. The cut is recorded
locally (`$ONIONWIRE_HOME/invite-stale`), so every friend who was on the roster
shows `invite stale` on their row, in violet, and the alert row above the panes
reads `invite stale — F2 to share your new invite, they F3-paste it`. Sends to
that friend fail closed with `invite stale` instead of looking delivered. The
marker is not the dial marker: `stale` keeps meaning "the last dial did not
answer". F3-pasting an invite for that friend clears it.
## Wallet (`F6`)

View file

@ -65,6 +65,47 @@ pub const SHUTDOWN_FLUSH_TIMEOUT: Duration = Duration::from_secs(10);
/// immediately, and a live one answers in milliseconds.
const DAEMON_PROBE_BUDGET: Duration = Duration::from_secs(3);
/// Local record of the friends who were on the roster when the prekey last
/// rotated (F8). Not a store column and not a wire field: derived state under
/// `$ONIONWIRE_HOME`, so an install that never pressed F8 has no file and every
/// friend reads as current. The header carries the rotation timestamp; the body
/// is one 64-char hex identity pubkey per line.
const INVITE_STALE_FILE: &str = "invite-stale";
const INVITE_STALE_HEADER: &str = "onionwire-invite-stale-v1";
/// What a send to a pre-rotation friend answers. The roster marker and the
/// alert-row hint carry the instruction; the error only has to name the cause.
pub const INVITE_STALE_REASON: &str = "invite stale";
/// Lowercase hex, the on-disk form for a pubkey line.
fn hex_line(bytes: &[u8]) -> String {
bytes.iter().map(|b| format!("{b:02x}")).collect()
}
/// One hex line back to 32 bytes; anything else is skipped (the file is a cache
/// of a set, not a trusted input).
fn hex_pubkey(line: &str) -> Option<Vec<u8>> {
let line = line.trim();
if line.len() != 64 || !line.is_ascii() {
return None;
}
let mut out = Vec::with_capacity(32);
for chunk in line.as_bytes().chunks(2) {
let hi = (chunk[0] as char).to_digit(16)?;
let lo = (chunk[1] as char).to_digit(16)?;
out.push((hi * 16 + lo) as u8);
}
Some(out)
}
/// Write `bytes` beside `path` and rename over it, so a crash cannot leave a
/// half-written set that reads as "some friends are stale, some are not".
fn write_atomic(path: &Path, bytes: &[u8]) -> Result<(), String> {
let tmp = path.with_extension("tmp");
std::fs::write(&tmp, bytes).map_err(|e| format!("{}: {e}", tmp.display()))?;
std::fs::rename(&tmp, path).map_err(|e| format!("{}: {e}", path.display()))
}
struct HsHandle {
svc: Arc<RunningOnionService>,
rend: tokio::task::JoinHandle<()>,
@ -512,6 +553,9 @@ impl Node {
// state is unusable. Drop it; the next frame rebuilds a fresh state.
store.clear_ratchet(&p.pubkey).map_err(|e| e.to_string())?;
}
// An invite we just accepted is current by definition, so a friend F8
// had marked as holding the old one is no longer marked.
self.clear_invite_stale(&p.pubkey)?;
Ok(())
}
@ -1737,6 +1781,11 @@ impl Node {
}
async fn send_once(&self, friend_pk: &[u8], plaintext: &[u8]) -> Result<(), String> {
// One-shot frames (file, pay, tip, profile) have no outbox to retry
// them, so a pre-rotation invite must not look delivered either.
if self.invite_stale(friend_pk) {
return Err(INVITE_STALE_REASON.into());
}
self.ensure_running()?;
let (onion, prekey, kem) = {
let f = self.friend(friend_pk)?;
@ -1847,7 +1896,7 @@ impl Node {
let sk = StaticSecret::random_from_rng(OsRng);
let pk = X25519Public::from(&sk).to_bytes();
let kem_kp = crate::kem::generate();
{
let friends = {
let store = self.store.lock().map_err(|e| e.to_string())?;
// `replace_identity_keys` rewrites the prekey columns too; the
// identity values passed back are the ones already stored.
@ -1857,18 +1906,111 @@ impl Node {
store
.set_kem_keys(&kem_kp.seed[..], &kem_kp.pk)
.map_err(|e| e.to_string())?;
for f in store.list_friends().map_err(|e| e.to_string())? {
store.clear_ratchet(&f.pubkey).map_err(|e| e.to_string())?;
let friends: Vec<Vec<u8>> = store
.list_friends()
.map_err(|e| e.to_string())?
.into_iter()
.map(|f| f.pubkey)
.collect();
for f in &friends {
store.clear_ratchet(f).map_err(|e| e.to_string())?;
}
}
friends
};
k.prekey_sk = sk.to_bytes();
k.prekey_pk = pk;
k.kem_seed = *kem_kp.seed;
k.kem_pk = kem_kp.pk;
*self.keys.lock().map_err(|e| e.to_string())? = k;
// Every friend on the roster holds an invite with the prekey we just
// replaced; their next inbound frame cannot be decrypted and our own
// outbound re-bootstraps an epoch they do not have. Record the cut so
// the roster can say so instead of a send looking delivered.
self.record_invite_stale(unix_now(), &friends)
.map_err(|e| format!("prekey rotated, but the invite-stale marker failed: {e}"))?;
Ok(pk)
}
/// Friends whose recorded invite predates the current prekey (F8).
///
/// The set lives in `home/invite-stale` — derived local state, not a store
/// column and not a wire field. An install that never rotated has no file
/// and therefore an empty set. A missing or unreadable file reads as
/// "nothing stale": the marker is advisory, and a damaged file must not
/// make the roster accuse every friend.
pub fn invite_stale_friends(&self) -> Vec<Vec<u8>> {
let Ok(text) = std::fs::read_to_string(self.invite_stale_file()) else {
return Vec::new();
};
let mut lines = text.lines();
if !lines
.next()
.is_some_and(|l| l.split_whitespace().next() == Some(INVITE_STALE_HEADER))
{
return Vec::new();
}
lines.filter_map(hex_pubkey).collect()
}
/// Does this friend still hold an invite with the pre-rotation prekey?
pub fn invite_stale(&self, friend_pk: &[u8]) -> bool {
self.invite_stale_friends().iter().any(|p| p == friend_pk)
}
fn invite_stale_file(&self) -> PathBuf {
self.home.join(INVITE_STALE_FILE)
}
/// Write the roster snapshot taken by `rotate_prekey`. `rotated_at` is kept
/// in the header for a future reader; the set itself is the state.
fn record_invite_stale(&self, rotated_at: i64, friends: &[Vec<u8>]) -> Result<(), String> {
let mut text = format!("{INVITE_STALE_HEADER} {rotated_at}\n");
for pk in friends {
text.push_str(&hex_line(pk));
text.push('\n');
}
write_atomic(&self.invite_stale_file(), text.as_bytes())
}
/// A re-pasted invite is the exchange that closes the cut, so it takes the
/// pubkey out of the set.
fn clear_invite_stale(&self, friend_pk: &[u8]) -> Result<(), String> {
let path = self.invite_stale_file();
let Ok(text) = std::fs::read_to_string(&path) else {
return Ok(());
};
let mut lines = text.lines();
let Some(header) = lines.next() else {
return Ok(());
};
if header.split_whitespace().next() != Some(INVITE_STALE_HEADER) {
return Ok(());
}
let target = hex_line(friend_pk);
let mut changed = false;
let kept: Vec<&str> = lines
.map(str::trim)
.filter(|l| !l.is_empty())
.filter(|l| {
if l.eq_ignore_ascii_case(&target) {
changed = true;
false
} else {
true
}
})
.collect();
if !changed {
return Ok(());
}
let mut out = format!("{header}\n");
for l in kept {
out.push_str(l);
out.push('\n');
}
write_atomic(&path, out.as_bytes())
}
/// One-shot file to a friend. Fail closed; no outbox, no resume.
/// Chunks are paced (`file::CHUNK_PACE`) with bounded per-chunk retry so
/// a 1 MiB transfer fits the receiver's rendezvous token bucket.
@ -1906,6 +2048,12 @@ impl Node {
/// here, before the first attempt, and the frame is what the outbox retries.
/// Local history keeps the plaintext (the store is encrypted at rest).
pub async fn send(&self, friend_pk: &[u8], plaintext: &[u8]) -> Result<OutboxStatus, String> {
// A pre-rotation invite is a hard cut, not a reachability problem: the
// frame would encode and look delivered while the peer cannot decrypt
// it. Fail closed with the cause instead of silently re-bootstrapping.
if self.invite_stale(friend_pk) {
return Err(INVITE_STALE_REASON.into());
}
self.ensure_running()?;
let keys = self.keys()?;
let frame = {
@ -3558,6 +3706,79 @@ pub(crate) mod tests {
);
}
/// F8 is a hard cut that leaves every friend holding an invite with the old
/// prekey. The roster has to say so instead of letting the next send look
/// delivered and then fail to decrypt on the far side.
#[tokio::test]
async fn rotating_the_prekey_marks_existing_friends_invite_stale() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("bob"), Arc::new(NoDial));
let peer = Keys::generate();
let fresh = Keys::generate();
{
let store = node.store.lock().unwrap();
befriend(&store, &peer.identity_pk, &peer.prekey_pk, "peer.onion");
store
.save_ratchet(&peer.identity_pk, b"epoch-bound-to-the-old-prekey")
.expect("seed ratchet state");
}
assert!(
!node.invite_stale(&peer.identity_pk),
"nothing is invite-stale before a rotation"
);
node.rotate_prekey().expect("rotate prekey");
assert!(
node.invite_stale(&peer.identity_pk),
"a friend on the roster when the prekey rotated holds the old invite"
);
{
let store = node.store.lock().unwrap();
befriend(&store, &fresh.identity_pk, &fresh.prekey_pk, "fresh.onion");
}
assert!(
!node.invite_stale(&fresh.identity_pk),
"a friend added after the rotation is not marked"
);
let err = node
.send(&peer.identity_pk, b"hello")
.await
.expect_err("a stale invite must fail closed, not queue");
assert!(
err.contains("invite stale"),
"the send must name the cause, got {err:?}"
);
}
/// A re-pasted invite for that friend is the exchange that fixes the cut, so
/// it is also what takes the marker off the roster.
#[tokio::test]
async fn pasting_a_new_invite_clears_the_invite_stale_marker() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("bob"), Arc::new(NoDial));
let peer = Keys::generate();
{
let store = node.store.lock().unwrap();
befriend(&store, &peer.identity_pk, &peer.prekey_pk, "peer.onion");
}
node.rotate_prekey().expect("rotate prekey");
assert!(node.invite_stale(&peer.identity_pk), "precondition");
node.add_friend_payload(&crate::qr::QrPayload {
pubkey: peer.identity_pk.to_vec(),
onion: "peer.onion".into(),
signed_prekey: peer.prekey_pk.to_vec(),
kem_pk: None,
})
.expect("accept invite");
assert!(
!node.invite_stale(&peer.identity_pk),
"a freshly accepted invite clears the marker"
);
}
/// An outbound tip must be recorded as a *tip*. The receipt row is the
/// recipient's view of a receipt frame; for money the user just spent the
/// wallet history wants the tip they paid. `ingest_tip` already stores

View file

@ -29,6 +29,9 @@ const C_TEXT: Color = Color::Rgb(196, 214, 176);
const C_DIM: Color = Color::Rgb(98, 110, 92);
const C_ALERT: Color = Color::Rgb(220, 80, 70);
const C_STALE: Color = Color::Rgb(210, 180, 80);
/// F8: the friend holds an invite with the pre-rotation prekey. Violet, not the
/// dial-stale amber — a stale invite is an exchange problem, not a dead peer.
const C_INVITE_STALE: Color = Color::Rgb(178, 128, 216);
const C_HL_BG: Color = Color::Rgb(48, 42, 28);
const C_BORDER: Color = Color::Rgb(72, 84, 64);
@ -403,6 +406,8 @@ pub struct TokenStyles {
pub alert: Style,
/// Stale data (unconfirmed, timed out).
pub stale: Style,
/// F8: the friend's copy of our invite predates the current prekey.
pub invite_stale: Style,
/// Border / chrome lines.
pub border: Style,
/// Highlight block (selected list row).
@ -438,6 +443,11 @@ pub fn tokens_for(mode: ColorMode) -> TokenStyles {
accent,
alert: rgb(C_ALERT, Color::Red),
stale: rgb(C_STALE, Color::Yellow),
invite_stale: match mode {
ColorMode::None => Style::default().add_modifier(Modifier::BOLD),
ColorMode::Ansi16 => Style::default().fg(Color::Magenta),
ColorMode::Rgb => Style::default().fg(C_INVITE_STALE),
},
border: rgb(C_BORDER, Color::DarkGray),
highlight,
}
@ -464,6 +474,10 @@ fn style_stale() -> Style {
tokens_for(color_mode()).stale
}
fn style_invite_stale() -> Style {
tokens_for(color_mode()).invite_stale
}
fn style_border() -> Style {
tokens_for(color_mode()).border
}
@ -493,6 +507,13 @@ pub fn fingerprint_mismatch_banner() -> &'static str {
"fingerprint mismatch"
}
/// The one-line hint for a friend whose invite predates our current prekey
/// (F8). Rendered in the same alert row as `fingerprint_mismatch_banner`, so the
/// user reads it where every other fail-closed sentence appears. Fits 80.
pub fn invite_stale_banner() -> &'static str {
"invite stale — F2 to share your new invite, they F3-paste it"
}
pub fn rotate_screen_text() -> &'static str {
"Rotate onion address?\n\
Your identity key stays the same.\n\
@ -1236,6 +1257,9 @@ struct App {
rt: tokio::runtime::Handle,
screen: Screen,
friends: Vec<Friend>,
/// Pubkeys whose invite predates our current prekey (F8), straight from
/// `Node::invite_stale_friends`. Refreshed with the roster, read on draw.
invite_stale: Vec<Vec<u8>>,
selected: usize,
me_fp: String,
me_onion: String,
@ -1823,6 +1847,7 @@ 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()?;
let invite_stale = node.invite_stale_friends();
// 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
@ -1847,6 +1872,7 @@ impl App {
rt,
screen,
friends,
invite_stale,
selected: 0,
alert: None,
status_note: None,
@ -2436,6 +2462,10 @@ impl App {
fn confirm_rotate_prekey(&mut self) -> Result<(), String> {
match self.node.rotate_prekey() {
Ok(_) => {
// Every friend on the roster just became "invite stale"; the
// markers have to be on the roster before the share screen
// opens, not after the next friend-list refresh.
self.reload_friends()?;
self.status_note =
Some("prekey rotated · friends must F3-paste your new invite".into());
self.open_share()
@ -3141,6 +3171,7 @@ impl App {
fn reload_friends(&mut self) -> Result<(), String> {
self.friends = self.node.list_friends()?;
self.invite_stale = self.node.invite_stale_friends();
if self.friends.is_empty() {
self.selected = 0;
} else {
@ -3409,7 +3440,12 @@ impl App {
fn draw_main(&self, f: &mut Frame) {
let phase = Some(TorPhase::of(self.node.tor_state()));
let (chat_lines, summary, chat_style) = self.chat_view(phase);
let rows: Vec<FriendRow> = self.friends.iter().map(friend_row).collect();
let invite_set = &self.invite_stale;
let rows: Vec<FriendRow> = self
.friends
.iter()
.map(|f| friend_row(f, invite_set.iter().any(|pk| pk == &f.pubkey)))
.collect();
let chat_name = self.friends.get(self.selected).map(|friend| {
friend
.petname
@ -3420,10 +3456,20 @@ impl App {
// The outbox is the source of truth while anything is outstanding; the
// transient note still covers "sending", "sent file x", "invoice sent".
let mut note = summary.note().or_else(|| self.status_note.clone());
// F8's cut is a standing fact about the selected friend, not a transient
// error: with nothing else failing, the alert row carries the sentence
// that turns it into an action. It clears with the marker (a re-pasted
// invite), so it is recomputed every draw rather than set once.
let invite_hint = self
.friends
.get(self.selected)
.filter(|f| self.invite_stale.iter().any(|pk| pk == &f.pubkey))
.map(|_| invite_stale_banner());
let alert = self.alert.as_deref().or(invite_hint);
// The alert row above the panes is the error channel. When it already
// carries the same sentence, drop it from the footer: one statement of a
// failure, in the place the eye goes for errors.
if note.as_deref() == self.alert.as_deref() {
if note.as_deref() == alert {
note = None;
}
let view = MainView {
@ -3438,7 +3484,7 @@ impl App {
chat_name: chat_name.as_deref(),
chat_scroll: self.chat_scroll,
composer: &self.composer,
alert: self.alert.as_deref(),
alert,
note: note.as_deref(),
};
draw_main_chrome(f, &view);
@ -3470,12 +3516,20 @@ impl App {
}
}
/// One roster row: the label, the fingerprint, and the word `stale` when the
/// last dial did not answer. Colour is what the row is (text vs stale), never a
/// decoration — the word carries the state on a monochrome terminal.
/// One roster row: the label, the fingerprint, and the state word — `stale`
/// when the last dial did not answer, `invite stale` when F8 replaced the prekey
/// the friend still holds. Colour is what the row is (text / dial stale / invite
/// stale), never a decoration — the word carries the state on a monochrome
/// terminal.
pub fn roster_line(row: &FriendRow, inner_width: u16) -> Line<'static> {
let text = roster_row_text(row, inner_width);
let style = if row.stale { style_stale() } else { style_text() };
let style = if row.invite_stale {
style_invite_stale()
} else if row.stale {
style_stale()
} else {
style_text()
};
Line::from(Span::raw(text).style(style))
}
@ -3750,6 +3804,9 @@ pub struct FriendRow {
pub fingerprint: String,
/// Last dial to this peer's onion did not answer.
pub stale: bool,
/// The friend's recorded invite predates our current prekey (F8): their
/// next inbound frame cannot be decrypted until they paste the new invite.
pub invite_stale: bool,
/// Friend row has an ML-KEM key (v2 invite). `false` means sessions to
/// this friend are the classical `onionwire-v1` transport, and the roster
/// says so in words — no pretending it is hybrid.
@ -3757,12 +3814,14 @@ pub struct FriendRow {
}
/// The roster row for one friend, fitted to the pane's inner width in cells.
pub fn friend_row(friend: &Friend) -> FriendRow {
/// `invite_stale` is `Node::invite_stale`'s answer for this pubkey.
pub fn friend_row(friend: &Friend, invite_stale: bool) -> FriendRow {
let raw = friend.petname.as_deref().unwrap_or(&friend.fingerprint);
FriendRow {
label: sanitize::display_text(raw.as_bytes()).to_string(),
fingerprint: friend.fingerprint.clone(),
stale: !friend.last_connect_ok,
invite_stale,
pq: friend.kem_pk.is_some(),
}
}
@ -5557,10 +5616,14 @@ fn truncate_fp(fp: &str) -> String {
fn roster_row_text(row: &FriendRow, inner_width: u16) -> String {
let budget = (inner_width as usize).saturating_sub(2);
let stale_s = if row.stale { " stale" } else { "" };
// F8's cut is not a failed dial: its own word, beside `stale` when both are
// true (the invite is old *and* the last dial timed out).
let invite_s = if row.invite_stale { " invite stale" } else { "" };
// A legacy v1 friend has no PQ transport; say the word rather than let the
// roster imply protection it does not have.
let pq_s = if row.pq { "" } else { " classical" };
let avail = budget.saturating_sub(cell_width(stale_s) + cell_width(pq_s));
let avail =
budget.saturating_sub(cell_width(stale_s) + cell_width(invite_s) + cell_width(pq_s));
// The name is what the reader is looking for. The fingerprint only
// disambiguates two friends with the same petname, so it gets what is left
// and is dropped entirely when the pane is too narrow to show a usable
@ -5576,7 +5639,7 @@ fn roster_row_text(row: &FriendRow, inner_width: u16) -> String {
} else {
(fit_cells(&row.label, avail), String::new())
};
fit_cells(&format!("{shown}{fp_part}{pq_s}{stale_s}"), budget)
fit_cells(&format!("{shown}{fp_part}{pq_s}{invite_s}{stale_s}"), budget)
}
fn to_hex(bytes: &[u8]) -> String {

View file

@ -16,11 +16,11 @@ use onionwire::outbox::{OutboxEntry, OutboxStatus};
use onionwire::qr;
use onionwire::tui::{
ChatRowStyle, FriendRow, MainView, Pane, TorPhase, backup_screen_text, banner_for_width,
cell_width, chat_no_friends_lines, chat_with_delivery, compact_banner, draw_main_chrome,
draw_share, draw_text_overlay, fingerprint_mismatch_banner, help_overlay_text,
main_footer_hints, onion_glyph, quit_screen_text, restore_screen_text, rotate_screen_text,
roster_line, status_footer, who_overlay_text, wipe_screen_text, wordmark_banner, ProfileEditor,
WipeKind,
cell_width, chat_no_friends_lines, chat_with_delivery, color_mode, compact_banner,
draw_main_chrome, draw_share, draw_text_overlay, fingerprint_mismatch_banner,
help_overlay_text, invite_stale_banner, main_footer_hints, onion_glyph, quit_screen_text,
restore_screen_text, rotate_screen_text, roster_line, status_footer, tokens_for,
who_overlay_text, wipe_screen_text, wordmark_banner, ProfileEditor, WipeKind,
};
use onionwire::{FriendProfile, Message};
use ratatui::Frame;
@ -91,12 +91,14 @@ fn friend_rows() -> Vec<FriendRow> {
label: "alice".into(),
fingerprint: "aaaaaaaaaaaaaaaa".into(),
stale: false,
invite_stale: false,
pq: true,
},
FriendRow {
label: "bob-the-stale-peer".into(),
fingerprint: "bbbbbbbbbbbbbbbb".into(),
stale: true,
invite_stale: false,
pq: true,
},
]
@ -108,6 +110,7 @@ fn a_legacy_friend_row_says_classical_in_the_roster() {
label: "alice".into(),
fingerprint: "aaaaaaaaaaaaaaaa".into(),
stale: false,
invite_stale: false,
pq: true,
};
let legacy = FriendRow {
@ -131,6 +134,129 @@ fn a_legacy_friend_row_says_classical_in_the_roster() {
);
}
/// F8 invalidates every friend's stored copy of our invite. That is a different
/// fact from "the last dial did not answer": the roster needs its own word, its
/// own colour token, and it must not borrow `stale` for it.
#[test]
fn an_invite_stale_friend_is_marked_apart_from_a_dial_stale_one() {
let row = FriendRow {
label: "alice".into(),
fingerprint: "aaaaaaaaaaaaaaaa".into(),
stale: false,
invite_stale: false,
pq: true,
};
let invite = FriendRow {
invite_stale: true,
..row.clone()
};
let dial = FriendRow {
stale: true,
..row.clone()
};
let text = |r: &FriendRow| -> String {
roster_line(r, 40)
.spans
.iter()
.map(|s| s.content.clone())
.collect()
};
let invite_text = text(&invite);
assert!(
invite_text.contains("invite stale"),
"a pre-rotation friend must say so in words: {invite_text:?}"
);
let dial_text = text(&dial);
assert!(
!dial_text.contains("invite stale"),
"a failed dial keeps the old marker and only that: {dial_text:?}"
);
assert!(dial_text.contains("stale"), "{dial_text:?}");
let invite_style = roster_line(&invite, 40).spans[0].style;
let tokens = tokens_for(color_mode());
assert_eq!(
invite_style, tokens.invite_stale,
"invite staleness owns a colour token, not the dial-stale one"
);
assert_ne!(tokens.invite_stale, tokens.stale);
}
/// The hint has to render in the same place as the fingerprint mismatch banner
/// (the fail-closed alert row above the panes) and fit 80 columns.
#[test]
fn the_invite_stale_hint_renders_above_the_panes_at_80_columns() {
let hint = invite_stale_banner();
assert!(
cell_width(hint) <= 80,
"the hint must fit 80 columns: {hint:?} is {}",
cell_width(hint)
);
assert!(hint.contains("invite stale"), "{hint:?}");
assert!(
hint.contains("F2") && hint.contains("F3"),
"the hint must point at sharing and re-pasting an invite: {hint:?}"
);
let friends = vec![
FriendRow {
label: "alice".into(),
fingerprint: "aaaaaaaaaaaaaaaa".into(),
stale: false,
invite_stale: true,
pq: true,
},
FriendRow {
label: "bob".into(),
fingerprint: "bbbbbbbbbbbbbbbb".into(),
stale: false,
invite_stale: false,
pq: true,
},
];
let chat = vec!["hi".to_string()];
let draw = |w: u16, h: u16| {
draw_frame(w, h, |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Ready),
friends: &friends,
selected: 1,
focus: Pane::Chat,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: Some(hint),
note: None,
},
)
})
};
// 80x24 is the audit size every rendered row must survive.
let narrow = draw(80, 24);
let narrow_screen = screen_of(&narrow, 80, 24);
for line in narrow_screen.lines().filter(|l| l.contains("invite")) {
println!("80-col line ({} cells): {line:?}", cell_width(line));
}
assert!(
narrow_screen.lines().nth(1).unwrap_or_default().contains("invite stale"),
"the hint belongs in the alert row: {narrow_screen}"
);
let wide = draw(120, 40);
let wide_screen = screen_of(&wide, 120, 40);
assert!(
wide_screen.contains("alice invite stale"),
"the row itself must carry the marker: {wide_screen}"
);
}
fn out_msg(id: i64, body: &str) -> Message {
Message {
id,