const RENDER_SRC: &str = include_str!("../tui/render/sessions.rs");
const MESSAGE_REPO_SRC: &str = include_str!("../db/repository/message.rs");
const SESSION_REPO_SRC: &str = include_str!("../db/repository/session.rs");
#[test]
fn the_list_renders_the_field_it_sorts_by() {
assert!(
RENDER_SRC.contains("session.updated_at.format("),
"the session row must print updated_at: the list is ordered by \
updated_at DESC, and printing created_at made a correctly sorted \
list look scrambled"
);
assert!(
!RENDER_SRC.contains("session.created_at.format("),
"printing created_at in the row is what caused the reported confusion \
— a March date above a session used minutes ago"
);
}
#[test]
fn the_sort_key_is_last_activity() {
assert!(
SESSION_REPO_SRC.contains("ORDER BY updated_at DESC"),
"list_sessions must order by last activity; ordering by created_at \
would bury an old session that is in daily use"
);
}
#[test]
fn only_a_real_message_counts_as_activity() {
let block = MESSAGE_REPO_SRC
.split("Touch session's updated_at")
.nth(1)
.expect("the activity bump is gone from the message insert path");
let block = &block[..block.find("})").unwrap_or(block.len())];
assert!(
block.contains("UPDATE sessions SET updated_at"),
"activity must be recorded when a message lands"
);
assert!(
block.contains("m.created_at.timestamp()"),
"the stamp must be the message's own time, not now(): replaying or \
backfilling history must not reorder the list"
);
}
#[test]
fn opening_a_session_does_not_count_as_activity() {
let writers = [
(
"src/db/repository/message.rs",
"message insert — the one legitimate bump",
),
("src/db/repository/session.rs", "archive / unarchive"),
("src/db/repository/project.rs", "project assign / unassign"),
("src/services/session.rs", "working-directory change"),
];
for (path, why) in writers {
assert!(
std::path::Path::new(path).exists(),
"known updated_at writer vanished: {path} ({why})"
);
}
}