From f7fb32ed05b1c1a3c49c7a772eb5459431979efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 01:06:12 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(core):=20a=20task=20tells=20?= =?UTF-8?q?its=20story=20newest=20first?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/izlek-core/src/store/turso_store.rs | 2 +- crates/izlek-core/tests/store.rs | 34 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/crates/izlek-core/src/store/turso_store.rs b/crates/izlek-core/src/store/turso_store.rs index f8532e8..6edabb4 100644 --- a/crates/izlek-core/src/store/turso_store.rs +++ b/crates/izlek-core/src/store/turso_store.rs @@ -3341,7 +3341,7 @@ impl DetailReads for TursoStore { "SELECT a.id, a.kind, a.detail, a.created_at, u.id, u.display_name, \ (u.photo IS NOT NULL) \ FROM activity a LEFT JOIN user u ON u.id = a.actor_id \ - WHERE a.task_id = ?1 ORDER BY a.created_at, a.rowid", + WHERE a.task_id = ?1 ORDER BY a.created_at DESC, a.rowid DESC", params![task_id], ) .await diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index 0222822..cb5ad53 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -2732,14 +2732,15 @@ async fn saving_a_task_records_only_what_changed() { assert_eq!(detail.title, "second title"); assert_eq!(detail.description, "some prose"); assert_eq!(detail.deadline_input(), "2026-09-12"); + // Newest first, as everywhere else: the deadline was the last thing set. let kinds: Vec<&ActivityKind> = detail.activity.iter().map(|e| &e.kind).collect(); assert_eq!( kinds, [ - &ActivityKind::Created, - &ActivityKind::Retitled, + &ActivityKind::DeadlineSet, &ActivityKind::Described, - &ActivityKind::DeadlineSet + &ActivityKind::Retitled, + &ActivityKind::Created ] ); } @@ -5249,3 +5250,30 @@ async fn the_engine_delivers_a_notice_that_owes_no_rule() { assert!(owed.is_empty(), "a delivered notice is no longer owed: {owed:?}"); std::fs::remove_dir_all(dir).ok(); } + +/// A task's own history reads newest first, the same way every other feed in +/// the app does — the oldest line is the last one, not the first. +#[tokio::test] +async fn a_tasks_activity_reads_newest_first() { + let (scratch, workspace, admin) = workspace_with_admin().await; + let store = &scratch.store; + let task = add_task(store, &workspace, "Backlog", "order me", None, &admin).await; + + for word in ["one", "two", "three"] { + store + .add_comment(&task, &admin, word, OffsetDateTime::now_utc()) + .await + .unwrap(); + } + + let activity = store.activity_for_task(&task).await.unwrap(); + let stamps: Vec<_> = activity.iter().map(|line| line.at).collect(); + assert!( + stamps.windows(2).all(|pair| pair[0] >= pair[1]), + "not newest first: {stamps:?}" + ); + // Creation is the oldest thing that ever happens to a task, so it is last + // now; a comment — the most recent act here — leads. + assert_eq!(activity.first().map(|line| line.kind.clone()), Some(ActivityKind::Commented), "{activity:?}"); + assert_eq!(activity.last().map(|line| line.kind.clone()), Some(ActivityKind::Created), "{activity:?}"); +}