test(daemon): drive the whole CLI suite against a daemon, and fix what it caught

SOULSEEK_E2E_MODE=daemon makes the existing e2e harness serve every session
from a daemon instead of the command's own login, so the same 83 tests assert
the same records and exit codes both ways. CI runs the suite twice.

Two defects it found:

serve judged whether anything was shared from this run's configuration
rather than from the session, so routed to a daemon it would start with
nothing to serve and report success.

The TUI showed an empty conversation when attached, because the daemon's
message history was never asked for. It is now a SessionApi method, empty
locally, which puts the difference behind the seam.

main.rs is now a thin entry point over the library rather than a second copy
of every module, so the program compiles once instead of twice.
This commit is contained in:
Michel de Graaf
2026-07-27 10:58:27 +02:00
parent 834fbcd35b
commit a69f52c657
12 changed files with 663 additions and 578 deletions
+24 -2
View File
@@ -10,7 +10,7 @@ use crate::api::SessionApi;
use crate::models::AppState;
use crate::persist::{
snapshot::{Snapshot, restore_messages, restore_searches},
state::StateStore,
state::{PersistedMessage, StateStore},
};
use color_eyre::Result;
use ratatui::{
@@ -58,7 +58,29 @@ impl MainTui {
/// (rejoined on the server), and downloads — incomplete ones are
/// re-enqueued so they resume automatically.
fn restore_persisted_state(&mut self) {
let Some(store) = &self.store else { return };
// Whatever the session has been collecting comes first: attached to a
// daemon this is the conversation so far, including everything that
// arrived while nothing was showing it. Locally it is empty and the
// snapshot below is the whole record.
let history: Vec<PersistedMessage> = self
.client
.message_history()
.into_iter()
.map(|message| PersistedMessage {
peer: message.peer,
outgoing: message.outgoing,
text: message.text,
at: chrono::DateTime::from_timestamp(message.at, 0)
.unwrap_or_default()
.into(),
})
.collect();
restore_messages(&mut self.state, &history);
let Some(store) = &self.store else {
self.saved_snapshot = Snapshot::capture(&self.state);
return;
};
restore_searches(&mut self.state, &store.load_search_queries());
restore_messages(&mut self.state, &store.load_messages());