From 9303e20adb6b9db2df9bb14a7cee1466be60d9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 04:15:49 +0300 Subject: [PATCH] Filterbar wraps at every width; search folds Turkish; feed backfills watches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The filterbar only wrapped below 620px, so a long project name pushed the search box past the viewport edge around 840px — a document overflow the house forbids. The bar wraps whenever it needs to now, and long trigger labels ellipsize instead of pushing. Search folded case with Unicode's default mapping, where İ becomes i with a combining dot — 'iş' never matched 'İş Planı Teslimi'. Both sides fold through a Turkish-aware map now. Watching only began at deploy, so every existing account's feed read 'Nothing yet.' The reconcile seeds watches from history — created, assigned, commented — once per database, and carries each person's feed_seen_at across the rebuild instead of resetting it. --- crates/izlek-core/migrations/0001_init.sql | 2 + crates/izlek-core/src/board.rs | 34 +- crates/izlek-core/src/store/reconcile.rs | 158 +++++-- crates/izlek-core/tests/store.rs | 461 ++++++++++++++++++--- 4 files changed, 557 insertions(+), 98 deletions(-) diff --git a/crates/izlek-core/migrations/0001_init.sql b/crates/izlek-core/migrations/0001_init.sql index 5c61d9b..3fd06b4 100644 --- a/crates/izlek-core/migrations/0001_init.sql +++ b/crates/izlek-core/migrations/0001_init.sql @@ -250,6 +250,7 @@ CREATE TABLE task_watcher ( user_id TEXT NOT NULL REFERENCES user(id), PRIMARY KEY (task_id, user_id) ); +CREATE INDEX task_watcher_by_user ON task_watcher(user_id); -- blocked_task_id is blocked by blocking_task_id. cleared_at is set when the -- blocking task finishes, which is what the "you can start now" rule reads. @@ -363,6 +364,7 @@ CREATE TABLE activity ( ); CREATE INDEX activity_by_task ON activity(task_id); CREATE INDEX activity_recent ON activity(created_at); +CREATE INDEX activity_by_subject ON activity(subject_id); -- Mail rules are written only by the admin. -- diff --git a/crates/izlek-core/src/board.rs b/crates/izlek-core/src/board.rs index 7790c2f..70c8a82 100644 --- a/crates/izlek-core/src/board.rs +++ b/crates/izlek-core/src/board.rs @@ -275,16 +275,15 @@ impl BoardView { self.cards().filter(|card| card.is_blocked()).count() } - /// Keeps only the cards whose key or title answers `query`: a literal, - /// case-insensitive substring of either. The human key typed in any - /// case matches; a fragment of a title matches; nothing is + /// Keeps only the cards whose key or title answers `query`: a literal + /// substring of the folded key or folded title. The human key typed in + /// any case matches; a fragment of a title matches; nothing is /// pattern-matched, so there are no wildcards to escape. pub fn searching(&mut self, query: &str) { - let needle = query.to_lowercase(); + let needle = fold(query); for column in &mut self.columns { column.cards.retain(|card| { - card.task_key.to_lowercase().contains(&needle) - || card.title.to_lowercase().contains(&needle) + fold(&card.task_key).contains(&needle) || fold(&card.title).contains(&needle) }); } } @@ -303,6 +302,29 @@ impl BoardView { } } +/// Folds text for search: Turkish letters collapse to their ASCII stems +/// (`İ`/`I`/`ı` → `i`, `ş` → `s`, `ç` → `c`, `ğ` → `g`, `ü` → `u`, `ö` → +/// `o`), case flattens. A naive lowercase cannot stand in for this: it +/// turns `İ` into `i` plus a combining dot, and then no plain-`i` query — +/// `is`, say, against a card titled `İş Planı Teslimi` — can ever match. +/// Query and card fold through the same map, so `iş`, `İŞ`, `is`, and +/// `İS` all find `İş`. +fn fold(text: &str) -> String { + let mut folded = String::with_capacity(text.len()); + for character in text.chars() { + match character { + 'İ' | 'I' | 'ı' => folded.push('i'), + 'ş' | 'Ş' => folded.push('s'), + 'ç' | 'Ç' => folded.push('c'), + 'ğ' | 'Ğ' => folded.push('g'), + 'ü' | 'Ü' => folded.push('u'), + 'ö' | 'Ö' => folded.push('o'), + other => folded.extend(other.to_lowercase()), + } + } + folded +} + /// `Sep 12` — the card chips are day-and-month, never a year. pub fn day_label(day: Date) -> String { let month = match day.month() { diff --git a/crates/izlek-core/src/store/reconcile.rs b/crates/izlek-core/src/store/reconcile.rs index 5353158..dd55be5 100644 --- a/crates/izlek-core/src/store/reconcile.rs +++ b/crates/izlek-core/src/store/reconcile.rs @@ -5,8 +5,8 @@ //! column map, the copy is verified, and only then the files are swapped. The //! original file is kept as a timestamped backup and is never deleted. -use super::{Result, StoreError}; use super::schema::{SCHEMA, declared_fingerprint, diff_report, fingerprint}; +use super::{Result, StoreError}; use turso::{Builder, Connection, params}; use ulid::Ulid; @@ -43,7 +43,9 @@ pub async fn reconcile(path: &str, opts: ReconcileOptions) -> Result<()> { .build() .await .map_err(|e| StoreError::Backend(e.to_string()))?; - let old_conn = old_db.connect().map_err(|e| StoreError::Backend(e.to_string()))?; + let old_conn = old_db + .connect() + .map_err(|e| StoreError::Backend(e.to_string()))?; let old_fp = fingerprint(&old_conn).await?; let new_fp = declared_fingerprint().await?; @@ -127,7 +129,10 @@ pub async fn reconcile(path: &str, opts: ReconcileOptions) -> Result<()> { let _ = std::fs::remove_file(format!("{}-shm", rebuilt_path)); if opts.auto { - eprintln!("database rebuilt and verified; original backed up to {}", backup_path); + eprintln!( + "database rebuilt and verified; original backed up to {}", + backup_path + ); eprintln!("rebuilt database now at {}", path); } else { println!("database rebuilt and verified"); @@ -151,7 +156,9 @@ async fn rebuild(path: &str, rebuilt_path: &str, old_conn: &Connection) -> Resul .build() .await .map_err(|e| StoreError::Backend(e.to_string()))?; - let new_conn = new_db.connect().map_err(|e| StoreError::Backend(e.to_string()))?; + let new_conn = new_db + .connect() + .map_err(|e| StoreError::Backend(e.to_string()))?; new_conn .execute("PRAGMA foreign_keys = ON", ()) @@ -189,7 +196,11 @@ async fn seed_general_tags(old_conn: &Connection, new_conn: &Connection) -> Resu .query("SELECT id, created_at FROM board", ()) .await .map_err(|e| StoreError::Backend(e.to_string()))?; - while let Some(row) = rows.next().await.map_err(|e| StoreError::Backend(e.to_string()))? { + while let Some(row) = rows + .next() + .await + .map_err(|e| StoreError::Backend(e.to_string()))? + { let board_id: String = row.get(0).map_err(|e| StoreError::Backend(e.to_string()))?; let created_at: String = row.get(1).map_err(|e| StoreError::Backend(e.to_string()))?; let id = Ulid::new().to_string(); @@ -219,6 +230,7 @@ fn build_maps( old_has_batch_window: bool, old_has_clock: bool, old_has_reminder: bool, + old_has_feed_seen: bool, ) -> Vec { let mut maps = Vec::new(); @@ -228,7 +240,10 @@ fn build_maps( ("id", "old.id".into()), ("name", "old.name".into()), ("created_at", "old.created_at".into()), - ("attachment_limit_bytes", "old.attachment_limit_bytes".into()), + ( + "attachment_limit_bytes", + "old.attachment_limit_bytes".into(), + ), ("photo_limit_bytes", "old.photo_limit_bytes".into()), ("allowed_file_types", "old.allowed_file_types".into()), ( @@ -312,12 +327,17 @@ fn build_maps( "created_at", "last_signed_in_at", ]); - // The feed's read marker is new with this schema: no database old - // enough to be reconciled ever carried it, so every copied row - // starts unseen rather than pretending to have been read. - columns.push(("feed_seen_at", "NULL".into())); + // The feed's read marker: new with the feed schema, so a + // database old enough to predate it starts unseen — and a + // database that already carries it keeps its marker across the + // rebuild rather than having its read state wiped. + columns.push(if old_has_feed_seen { + ("feed_seen_at", "old.feed_seen_at".into()) + } else { + ("feed_seen_at", "NULL".into()) + }); columns - } + }, }); maps.push(TableMap { name: "workspace_owner", @@ -339,11 +359,18 @@ fn build_maps( // resets did not exist to be mailed yet. columns.push(("kind", "'join'".into())); columns - } + }, }); maps.push(TableMap { name: "session", - columns: old_cols(&["id", "user_id", "token_hash", "created_at", "expires_at", "revoked_at"]), + columns: old_cols(&[ + "id", + "user_id", + "token_hash", + "created_at", + "expires_at", + "revoked_at", + ]), }); maps.push(TableMap { name: "auth_attempt", @@ -521,7 +548,11 @@ async fn old_has_column(conn: &Connection, table: &str, column: &str) -> Result< .query(&format!("PRAGMA table_info({table})"), ()) .await .map_err(|e| StoreError::Backend(e.to_string()))?; - while let Some(row) = rows.next().await.map_err(|e| StoreError::Backend(e.to_string()))? { + while let Some(row) = rows + .next() + .await + .map_err(|e| StoreError::Backend(e.to_string()))? + { let name: String = row.get(1).map_err(|e| StoreError::Backend(e.to_string()))?; if name == column { return Ok(true); @@ -543,7 +574,11 @@ async fn validate_maps(conn: &Connection, maps: &[TableMap]) -> Result<()> { .await .map_err(|e| StoreError::Backend(e.to_string()))?; let mut actual = HashSet::new(); - while let Some(row) = rows.next().await.map_err(|e| StoreError::Backend(e.to_string()))? { + while let Some(row) = rows + .next() + .await + .map_err(|e| StoreError::Backend(e.to_string()))? + { let name: String = row.get(1).map_err(|e| StoreError::Backend(e.to_string()))?; actual.insert(name); } @@ -578,11 +613,17 @@ async fn copy_data(old_conn: &Connection, new_conn: &Connection, path: &str) -> .map_err(|e| StoreError::Backend(e.to_string()))?; let has_smtp_check = old_has_column(old_conn, "workspace", "smtp_check_at").await?; - let has_batch_window = - old_has_column(old_conn, "workspace", "mail_batch_minutes").await?; + let has_batch_window = old_has_column(old_conn, "workspace", "mail_batch_minutes").await?; let has_clock = old_has_column(old_conn, "task", "clock_at").await?; let has_reminder = old_has_column(old_conn, "workspace", "reminder_minutes").await?; - let maps = build_maps(has_smtp_check, has_batch_window, has_clock, has_reminder); + let has_feed_seen = old_has_column(old_conn, "user", "feed_seen_at").await?; + let maps = build_maps( + has_smtp_check, + has_batch_window, + has_clock, + has_reminder, + has_feed_seen, + ); validate_maps(new_conn, &maps).await?; for map in maps { @@ -592,7 +633,12 @@ async fn copy_data(old_conn: &Connection, new_conn: &Connection, path: &str) -> if map.name == "task" { seed_general_tags(old_conn, new_conn).await?; } - let cols = map.columns.iter().map(|(c, _)| *c).collect::>().join(", "); + let cols = map + .columns + .iter() + .map(|(c, _)| *c) + .collect::>() + .join(", "); // `old` is the attached SCHEMA, not a table, so `old.id` in a select // list reads as "table old, column id". The source table is aliased // and the maps' `old.` prefix rewritten onto that alias. @@ -606,12 +652,28 @@ async fn copy_data(old_conn: &Connection, new_conn: &Connection, path: &str) -> "INSERT INTO main.{} ({}) SELECT {} FROM old.{} AS src", map.name, cols, exprs, map.name ); - new_conn - .execute(&sql, ()) - .await - .map_err(|e| StoreError::Backend(format!("{} while copying {}: {}", e, map.name, sql)))?; + new_conn.execute(&sql, ()).await.map_err(|e| { + StoreError::Backend(format!("{} while copying {}: {}", e, map.name, sql)) + })?; } + // Backfills the watches the feed reads: a watch for every task somebody + // created, was assigned, or commented on, including all history. This + // runs exactly once per database — the rebuild only happens on a schema + // mismatch — so watches removed by an unassign after the deploy stand, + // and the pass cannot fight the transactional auto-watch in the store's + // own writes: nothing is being served while the rebuild runs. + new_conn + .execute( + "INSERT OR IGNORE INTO task_watcher (task_id, user_id) \ + SELECT t.id, t.created_by FROM task t WHERE t.created_by IS NOT NULL \ + UNION SELECT task_id, user_id FROM task_assignee \ + UNION SELECT task_id, author_id FROM comment", + (), + ) + .await + .map_err(|e| StoreError::Backend(format!("seed watches: {e}")))?; + new_conn .execute("DETACH DATABASE old", ()) .await @@ -627,7 +689,11 @@ async fn verify(old_conn: &Connection, new_conn: &Connection) -> Result<()> { .await .map_err(|e| StoreError::Backend(e.to_string()))?; let mut fk_errors = Vec::new(); - while let Some(row) = rows.next().await.map_err(|e| StoreError::Backend(e.to_string()))? { + while let Some(row) = rows + .next() + .await + .map_err(|e| StoreError::Backend(e.to_string()))? + { let table: String = row.get(0).map_err(|e| StoreError::Backend(e.to_string()))?; let rowid: i64 = row.get(1).map_err(|e| StoreError::Backend(e.to_string()))?; let parent: String = row.get(2).map_err(|e| StoreError::Backend(e.to_string()))?; @@ -649,7 +715,11 @@ async fn verify(old_conn: &Connection, new_conn: &Connection) -> Result<()> { .await .map_err(|e| StoreError::Backend(e.to_string()))?; let mut integrity = Vec::new(); - while let Some(row) = rows.next().await.map_err(|e| StoreError::Backend(e.to_string()))? { + while let Some(row) = rows + .next() + .await + .map_err(|e| StoreError::Backend(e.to_string()))? + { let msg: String = row.get(0).map_err(|e| StoreError::Backend(e.to_string()))?; integrity.push(msg); } @@ -685,11 +755,30 @@ async fn verify(old_conn: &Connection, new_conn: &Connection) -> Result<()> { for table in tables { let old_count = count_rows(old_conn, table).await?; let new_count = count_rows(new_conn, table).await?; - if old_count != new_count { - return Err(StoreError::Backend(format!( - "row count mismatch for {}: old {} new {}", - table, old_count, new_count - ))); + // task_watcher: the rebuild backfills watches from history — every + // task somebody created, was assigned, or commented on — so the new + // count is that derived set (every old watch is in it by + // construction), not the old count. + let expected = if table == "task_watcher" { + Some(count_rows(new_conn, "(SELECT t.id, t.created_by AS user_id FROM task t WHERE t.created_by IS NOT NULL UNION SELECT task_id, user_id FROM task_assignee UNION SELECT task_id, author_id FROM comment)").await?) + } else { + None + }; + match expected { + Some(want) if new_count != want => { + return Err(StoreError::Backend(format!( + "task_watcher count {} does not match the backfilled set {}", + new_count, want + ))); + } + Some(_) => {} + None if old_count != new_count => { + return Err(StoreError::Backend(format!( + "row count mismatch for {}: old {} new {}", + table, old_count, new_count + ))); + } + None => {} } } @@ -712,13 +801,18 @@ async fn count_rows(conn: &Connection, table: &str) -> Result { .query(&sql, ()) .await .map_err(|e| StoreError::Backend(e.to_string()))?; - let Some(row) = rows.next().await.map_err(|e| StoreError::Backend(e.to_string()))? else { + let Some(row) = rows + .next() + .await + .map_err(|e| StoreError::Backend(e.to_string()))? + else { return Err(StoreError::Backend(format!( "could not count rows in {}", table ))); }; - row.get::(0).map_err(|e| StoreError::Backend(e.to_string())) + row.get::(0) + .map_err(|e| StoreError::Backend(e.to_string())) } fn cleanup_rebuilt(rebuilt_path: &str) { diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index 4c171c8..6cb7016 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -803,7 +803,10 @@ async fn workspace_defaults_match_the_settings_screen() { "every type until narrowed" ); assert_eq!(ws.mail_batch_minutes, 5); - assert_eq!(ws.reminder_minutes, 15, "a workspace starts with reminders on"); + assert_eq!( + ws.reminder_minutes, 15, + "a workspace starts with reminders on" + ); } /// An admin edits the sender from Settings, so the record carries host, port, @@ -1076,7 +1079,10 @@ async fn limits_round_trip_including_the_file_type_list() { assert_eq!(ws.photo_limit_bytes, 512 * 1024); assert_eq!(ws.allowed_file_types, types); assert_eq!(ws.mail_batch_minutes, 5); - assert_eq!(ws.reminder_minutes, 15, "the reminder lead rides the same save"); + assert_eq!( + ws.reminder_minutes, 15, + "the reminder lead rides the same save" + ); } #[tokio::test] @@ -1333,7 +1339,12 @@ async fn a_signin_link_stores_only_the_hash_and_is_used_once() { let now = OffsetDateTime::now_utc(); let link = scratch .store - .create_signin_link(&user.id, "hash-of-the-token", now + Duration::days(7), izlek_core::store::LinkKind::Join) + .create_signin_link( + &user.id, + "hash-of-the-token", + now + Duration::days(7), + izlek_core::store::LinkKind::Join, + ) .await .unwrap(); assert!(link.is_usable(now)); @@ -1398,7 +1409,12 @@ async fn an_expired_link_is_still_a_live_account() { let now = OffsetDateTime::now_utc(); let stale = scratch .store - .create_signin_link(&user.id, "stale-hash", now - Duration::hours(1), izlek_core::store::LinkKind::Join) + .create_signin_link( + &user.id, + "stale-hash", + now - Duration::hours(1), + izlek_core::store::LinkKind::Join, + ) .await .unwrap(); assert!(!stale.is_usable(now)); @@ -1406,7 +1422,12 @@ async fn an_expired_link_is_still_a_live_account() { // Resending opens the same account rather than making a new one. let fresh = scratch .store - .create_signin_link(&user.id, "fresh-hash", now + Duration::days(7), izlek_core::store::LinkKind::Join) + .create_signin_link( + &user.id, + "fresh-hash", + now + Duration::days(7), + izlek_core::store::LinkKind::Join, + ) .await .unwrap(); assert_eq!(fresh.user_id, stale.user_id); @@ -1437,7 +1458,12 @@ async fn a_prefetched_link_is_consumed_exactly_once() { let token = Token::mint(); let now = OffsetDateTime::now_utc(); let link = store - .create_signin_link(&user_id, &token.hash(), now + Duration::days(7), izlek_core::store::LinkKind::Join) + .create_signin_link( + &user_id, + &token.hash(), + now + Duration::days(7), + izlek_core::store::LinkKind::Join, + ) .await .unwrap(); @@ -7138,8 +7164,13 @@ async fn reconcile_carries_a_live_shaped_database_onto_the_declared_schema() { // The schema is now the declared one, exactly. let after = izlek_core::store::schema::fingerprint(&conn).await.unwrap(); - let declared = izlek_core::store::schema::declared_fingerprint().await.unwrap(); - assert_eq!(after, declared, "the rebuilt schema is not the declared one"); + let declared = izlek_core::store::schema::declared_fingerprint() + .await + .unwrap(); + assert_eq!( + after, declared, + "the rebuilt schema is not the declared one" + ); // Nothing was dropped on the floor. assert_eq!(scalar(&path, "SELECT COUNT(*) FROM user").await, 2); @@ -7173,7 +7204,11 @@ async fn reconcile_carries_a_live_shaped_database_onto_the_declared_schema() { // The blob survived byte for byte. assert_eq!( - scalar(&path, "SELECT length(bytes) FROM attachment WHERE id = 'F1'").await, + scalar( + &path, + "SELECT length(bytes) FROM attachment WHERE id = 'F1'" + ) + .await, 5000 ); assert_eq!( @@ -7190,7 +7225,11 @@ async fn reconcile_carries_a_live_shaped_database_onto_the_declared_schema() { // crosses over gets the declared default rather than a NULL the app would // have to read around. assert_eq!( - scalar(&path, "SELECT mail_batch_minutes FROM workspace WHERE id = 'W1'").await, + scalar( + &path, + "SELECT mail_batch_minutes FROM workspace WHERE id = 'W1'" + ) + .await, 5, "the workspace came across without a quiet window" ); @@ -7198,12 +7237,20 @@ async fn reconcile_carries_a_live_shaped_database_onto_the_declared_schema() { // had either: the workspace crosses onto the declared default, and tasks // that never carried a meeting instant arrive without one. assert_eq!( - scalar(&path, "SELECT reminder_minutes FROM workspace WHERE id = 'W1'").await, + scalar( + &path, + "SELECT reminder_minutes FROM workspace WHERE id = 'W1'" + ) + .await, 15, "the workspace came across without a reminder lead" ); assert_eq!( - scalar(&path, "SELECT COUNT(*) FROM task WHERE clock_at IS NOT NULL").await, + scalar( + &path, + "SELECT COUNT(*) FROM task WHERE clock_at IS NOT NULL" + ) + .await, 0, "a task came out of the rebuild with a clock it never had" ); @@ -7274,7 +7321,9 @@ async fn opening_a_stale_database_repairs_it() { let conn = db.connect().unwrap(); assert_eq!( izlek_core::store::schema::fingerprint(&conn).await.unwrap(), - izlek_core::store::schema::declared_fingerprint().await.unwrap(), + izlek_core::store::schema::declared_fingerprint() + .await + .unwrap(), ); assert_eq!(scalar(&path, "SELECT COUNT(*) FROM task").await, 4); assert_eq!(backups_beside(&dir).len(), 1); @@ -7397,9 +7446,20 @@ async fn user_stats_counts_what_a_person_holds_finished_opened_and_said() { let hold = add_task(store, &workspace, "Backlog", "Hold the door", None, &admin).await; store.assign_task(&hold, &mem).await.unwrap(); - let finished = add_task(store, &workspace, "Backlog", "Paint the frame", None, &admin).await; + let finished = add_task( + store, + &workspace, + "Backlog", + "Paint the frame", + None, + &admin, + ) + .await; store.assign_task(&finished, &mem).await.unwrap(); - store.move_task(&finished, &backlog, &done, &admin, now).await.unwrap(); + store + .move_task(&finished, &backlog, &done, &admin, now) + .await + .unwrap(); // One of her own that she also holds: created and assigned must each // count it in its own column, not argue about it. let own = add_task(store, &workspace, "Backlog", "Sweep", None, &mem).await; @@ -7407,12 +7467,20 @@ async fn user_stats_counts_what_a_person_holds_finished_opened_and_said() { add_task(store, &workspace, "Backlog", "Mop", None, &mem).await; add_task(store, &workspace, "Backlog", "Dust", None, &mem).await; for i in 0..4 { - store.add_comment(&hold, &mem, "a note", now + Duration::seconds(i)).await.unwrap(); + store + .add_comment(&hold, &mem, "a note", now + Duration::seconds(i)) + .await + .unwrap(); } assert_eq!( store.user_stats(&mem).await.unwrap(), - izlek_core::store::UserStats { assigned_open: 2, assigned_done: 1, created: 3, comments: 4 }, + izlek_core::store::UserStats { + assigned_open: 2, + assigned_done: 1, + created: 3, + comments: 4 + }, ); } @@ -7427,19 +7495,32 @@ async fn a_deleted_task_counts_nowhere_and_a_person_with_nothing_counts_nothing( assert_eq!( store.user_stats(­).await.unwrap(), - izlek_core::store::UserStats { assigned_open: 0, assigned_done: 0, created: 0, comments: 0 }, + izlek_core::store::UserStats { + assigned_open: 0, + assigned_done: 0, + created: 0, + comments: 0 + }, ); let doomed = add_task(store, &workspace, "Backlog", "Doomed", None, &mem).await; store.assign_task(&doomed, &mem).await.unwrap(); - store.add_comment(&doomed, &mem, "a note", now).await.unwrap(); + store + .add_comment(&doomed, &mem, "a note", now) + .await + .unwrap(); assert_eq!(store.user_stats(&mem).await.unwrap().assigned_open, 1); assert_eq!(store.user_stats(&mem).await.unwrap().comments, 1); store.delete_task(&doomed, &admin, now).await.unwrap(); assert_eq!( store.user_stats(&mem).await.unwrap(), - izlek_core::store::UserStats { assigned_open: 0, assigned_done: 0, created: 0, comments: 0 }, + izlek_core::store::UserStats { + assigned_open: 0, + assigned_done: 0, + created: 0, + comments: 0 + }, "a soft-deleted task stays out of every number, its comments included", ); } @@ -7698,7 +7779,8 @@ async fn the_hold_has_a_ceiling_measured_from_the_oldest_mail() { "the push is clipped rather than granted: {due} vs {far}", ); assert_eq!( - due, born + Duration::minutes(4), + due, + born + Duration::minutes(4), "the ceiling is the oldest mail's own patience running out", ); let _ = std::fs::remove_dir_all(&dir); @@ -7723,7 +7805,11 @@ async fn a_hold_never_pulls_a_leased_row_back_under_the_pass_that_took_it() { .expect("a fresh row is claimed"); // A delivery pass takes it: the lease is five minutes out. let taken = store - .claim_sends_owed(now + Duration::seconds(1), now + izlek_core::mail::LEASE, 10) + .claim_sends_owed( + now + Duration::seconds(1), + now + izlek_core::mail::LEASE, + 10, + ) .await .unwrap(); assert_eq!(taken.len(), 1, "the pass did not take the row"); @@ -7815,16 +7901,28 @@ async fn a_batch_is_one_card_and_one_reader() { let mut addressed: Vec = mailer .sent() .into_iter() - .map(|mail| format!("{} {}", mail.to, mail.body.lines().next().unwrap_or_default())) + .map(|mail| { + format!( + "{} {}", + mail.to, + mail.body.lines().next().unwrap_or_default() + ) + }) .collect(); addressed.sort(); assert_eq!(addressed.len(), 4); assert_eq!( - addressed.iter().filter(|line| line.contains("First")).count(), + addressed + .iter() + .filter(|line| line.contains("First")) + .count(), 2, ); assert_eq!( - addressed.iter().filter(|line| line.contains("emre@izlek.sh")).count(), + addressed + .iter() + .filter(|line| line.contains("emre@izlek.sh")) + .count(), 2, ); let _ = std::fs::remove_dir_all(&dir); @@ -7859,13 +7957,15 @@ async fn an_invitation_is_never_folded_into_a_batch() { .await .unwrap(); assert_eq!(report.sent, 2, "the invitation and the card's mail"); - let subjects: Vec = mailer - .sent() - .into_iter() - .map(|mail| mail.subject) - .collect(); - assert!(subjects.contains(&"Join the workspace".to_string()), "{subjects:?}"); - assert!(subjects.contains(&"Card is done".to_string()), "{subjects:?}"); + let subjects: Vec = mailer.sent().into_iter().map(|mail| mail.subject).collect(); + assert!( + subjects.contains(&"Join the workspace".to_string()), + "{subjects:?}" + ); + assert!( + subjects.contains(&"Card is done".to_string()), + "{subjects:?}" + ); let _ = std::fs::remove_dir_all(&dir); } @@ -8023,7 +8123,10 @@ async fn a_clocked_task_owes_each_assignee_one_reminder_before_the_meeting() { "the workspace's default lead of fifteen minutes" ); assert!( - row.subject.as_deref().unwrap().starts_with("Reminder: The quarterly review ("), + row.subject + .as_deref() + .unwrap() + .starts_with("Reminder: The quarterly review ("), "the subject names the meeting: {}", row.subject.as_deref().unwrap() ); @@ -8122,7 +8225,11 @@ async fn moving_the_clock_re_makes_the_reminders() { .filter(|r| r.state == SendState::Abandoned) .collect(); assert_eq!(pending.len(), 1, "exactly one reminder is still owed"); - assert_eq!(abandoned.len(), 1, "the promise the old clock stood on died"); + assert_eq!( + abandoned.len(), + 1, + "the promise the old clock stood on died" + ); assert_eq!( pending[0].next_attempt_at.unwrap(), new_clock - Duration::minutes(15), @@ -8206,8 +8313,8 @@ async fn an_assignee_removed_takes_their_reminder_with_them() { // Grace's warning is gone from what is owed; Emre's stands. let rows = reminders(&store, &task).await; assert!( - rows.iter().any(|r| r.recipient == "grace@izlek.sh" - && r.state == SendState::Abandoned), + rows.iter() + .any(|r| r.recipient == "grace@izlek.sh" && r.state == SendState::Abandoned), "the removed person's reminder was abandoned: {rows:?}" ); let still_owed = pending_reminders(&store, &task).await; @@ -8334,18 +8441,39 @@ async fn each_reminder_tells_the_meeting_in_its_own_recipients_clock() { .set_preferences(&emre, "UTC+03:00", "dark", "en", "default") .await .unwrap(); - let clock = OffsetDateTime::parse("2026-09-15T12:00:00Z", &time::format_description::well_known::Rfc3339) - .unwrap(); + let clock = OffsetDateTime::parse( + "2026-09-15T12:00:00Z", + &time::format_description::well_known::Rfc3339, + ) + .unwrap(); let task = clocked_task(&store, &workspace, &admin, Some(clock)).await; store.assign_task(&task, &grace).await.unwrap(); store.assign_task(&task, &emre).await.unwrap(); let rows = pending_reminders(&store, &task).await; assert_eq!(rows.len(), 2); - let grace_body = rows.iter().find(|r| r.recipient == "grace@izlek.sh").unwrap().body.as_deref().unwrap(); - let emre_body = rows.iter().find(|r| r.recipient == "emre@izlek.sh").unwrap().body.as_deref().unwrap(); - assert!(grace_body.contains("Meets at Sep 15 12:00"), "grace: {grace_body}"); - assert!(emre_body.contains("Meets at Sep 15 15:00"), "emre: {emre_body}"); + let grace_body = rows + .iter() + .find(|r| r.recipient == "grace@izlek.sh") + .unwrap() + .body + .as_deref() + .unwrap(); + let emre_body = rows + .iter() + .find(|r| r.recipient == "emre@izlek.sh") + .unwrap() + .body + .as_deref() + .unwrap(); + assert!( + grace_body.contains("Meets at Sep 15 12:00"), + "grace: {grace_body}" + ); + assert!( + emre_body.contains("Meets at Sep 15 15:00"), + "emre: {emre_body}" + ); let _ = std::fs::remove_dir_all(&dir); } @@ -8368,7 +8496,10 @@ async fn reminder_rows_survive_a_reopen() { let reopened = TursoStore::open(&path).await.unwrap(); let after = reminders(&reopened, &task).await; assert_eq!(after.len(), before.len()); - assert_eq!(after[0].id, before[0].id, "the same row, not a re-minted one"); + assert_eq!( + after[0].id, before[0].id, + "the same row, not a re-minted one" + ); assert_eq!(after[0].state, SendState::Pending); assert_eq!(after[0].next_attempt_at, before[0].next_attempt_at); let _ = std::fs::remove_dir_all(&dir); @@ -8457,7 +8588,10 @@ async fn a_reminder_failing_on_retries_is_not_minted_twice() { store.assign_task(&task, &emre).await.unwrap(); let rows = reminders(&store, &task).await; assert_eq!(rows.len(), 2, "one row per person: {rows:?}"); - let grace_row = rows.iter().find(|r| r.recipient == "grace@izlek.sh").unwrap(); + let grace_row = rows + .iter() + .find(|r| r.recipient == "grace@izlek.sh") + .unwrap(); assert_eq!(grace_row.state, SendState::Failed); assert_eq!(grace_row.attempts, 1); @@ -8482,7 +8616,10 @@ async fn the_reminder_never_lands_at_or_after_the_deadline() { let clock = OffsetDateTime::now_utc() + Duration::hours(2); let task = clocked_task(&store, &workspace, &admin, Some(clock)).await; store - .assign_task(&task, &member(&store, &workspace, "grace@izlek.sh", "Grace").await) + .assign_task( + &task, + &member(&store, &workspace, "grace@izlek.sh", "Grace").await, + ) .await .unwrap(); let rows = reminders(&store, &task).await; @@ -8500,7 +8637,10 @@ async fn the_reminder_never_lands_at_or_after_the_deadline() { let soon = OffsetDateTime::now_utc() + Duration::minutes(10); let task = clocked_task(&store, &workspace, &admin, Some(soon)).await; store - .assign_task(&task, &member(&store, &workspace, "emre@izlek.sh", "Emre").await) + .assign_task( + &task, + &member(&store, &workspace, "emre@izlek.sh", "Emre").await, + ) .await .unwrap(); let rows = reminders(&store, &task).await; @@ -8551,8 +8691,24 @@ async fn a_change_back_to_the_same_password_is_refused_and_signs_nobody_out() { #[tokio::test] async fn board_search_matches_keys_and_titles_in_place() { let (scratch, workspace, admin) = workspace_with_admin().await; - let panel = add_task(&scratch.store, &workspace, "Backlog", "Panel polish", None, &admin).await; - let wire = add_task(&scratch.store, &workspace, "In Progress", "Wire the exporter", None, &admin).await; + let panel = add_task( + &scratch.store, + &workspace, + "Backlog", + "Panel polish", + None, + &admin, + ) + .await; + let wire = add_task( + &scratch.store, + &workspace, + "In Progress", + "Wire the exporter", + None, + &admin, + ) + .await; let panel_key = scratch .store .task(&panel) @@ -8616,10 +8772,7 @@ async fn board_search_matches_keys_and_titles_in_place() { /// The reset token out of the newest notice queued for the address — the mail /// is the token's only carrier, so the test reads it like a recipient would. -async fn queued_reset_token( - store: &std::sync::Arc, - email: &str, -) -> Option { +async fn queued_reset_token(store: &std::sync::Arc, email: &str) -> Option { let sends = store .mail_queue(50, izlek_core::store::FeedPage::Newest) .await @@ -8627,9 +8780,7 @@ async fn queued_reset_token( let body = sends .into_iter() .rev() - .find(|send| { - send.kind == izlek_core::store::SendKind::Notice && send.recipient == email - }) + .find(|send| send.kind == izlek_core::store::SendKind::Notice && send.recipient == email) .and_then(|send| send.body)?; body.rsplit_once("/reset/") .and_then(|(_, rest)| rest.split_whitespace().next()) @@ -8665,7 +8816,9 @@ async fn a_reset_link_is_mailed_only_to_a_known_address() { "the known address was mailed a reset link" ); assert!( - queued_reset_token(&store, "nobody@izlek.sh").await.is_none(), + queued_reset_token(&store, "nobody@izlek.sh") + .await + .is_none(), "the unknown address was mailed nothing" ); let _ = std::fs::remove_dir_all(&dir); @@ -8707,11 +8860,17 @@ async fn a_reset_redeems_and_signs_the_other_browsers_out() { // The browser that was signed in before the reset is out; the redeeming // browser's own session is alive. assert!(matches!( - accounts.authenticate(&before.session_token.expose()).await.unwrap(), + accounts + .authenticate(&before.session_token.expose()) + .await + .unwrap(), None )); assert!(matches!( - accounts.authenticate(&after.session_token.expose()).await.unwrap(), + accounts + .authenticate(&after.session_token.expose()) + .await + .unwrap(), Some(_) )); } @@ -8909,7 +9068,12 @@ async fn the_personal_feed_follows_watches_names_and_the_marker() { // Ada's comment lands on a task Grace watches, after her marker: news. store - .add_comment(&task, &admin, "Thanks — ship it", now + Duration::seconds(6)) + .add_comment( + &task, + &admin, + "Thanks — ship it", + now + Duration::seconds(6), + ) .await .unwrap(); assert_eq!(store.count_feed_unseen(&grace).await.unwrap(), 1); @@ -8979,7 +9143,10 @@ async fn a_delivered_reminder_writes_the_reminded_event() { assert_eq!(about, 1, "the line is about the reminded person"); // Sweeping again re-sends nothing and writes nothing. - engine.deliver_owed(later + Duration::minutes(1), 10).await.unwrap(); + engine + .deliver_owed(later + Duration::minutes(1), 10) + .await + .unwrap(); let events = scalar( &path, "SELECT COUNT(*) FROM activity WHERE kind = 'reminded'", @@ -8988,3 +9155,177 @@ async fn a_delivered_reminder_writes_the_reminded_event() { assert_eq!(events, 1); let _ = std::fs::remove_dir_all(&dir); } + +/// The search fold survives Turkish: a naive lowercase turns `İ` into `i` +/// plus a combining dot, and then no plain-`i` query — `is` against a card +/// titled `İş Planı Teslimi` — can ever match. Query and title fold +/// through the same map instead. +#[tokio::test] +async fn board_search_folds_turkish_case() { + let (scratch, workspace, admin) = workspace_with_admin().await; + let is_plan = add_task( + &scratch.store, + &workspace, + "Backlog", + "İş Planı Teslimi", + None, + &admin, + ) + .await; + let wire = add_task( + &scratch.store, + &workspace, + "In Progress", + "Wire the exporter", + None, + &admin, + ) + .await; + let key = scratch + .store + .task(&is_plan) + .await + .unwrap() + .expect("task gone") + .row + .task_key; + + for query in ["iş", "İŞ", "is", "İS", "plan", "PLAN"] { + let mut board = izlek_core::board::load(&scratch.store, &workspace) + .await + .unwrap() + .unwrap(); + board.searching(query); + assert_eq!( + board.task_count(), + 1, + "query {query:?} matched the wrong set" + ); + let card = board.columns.iter().flat_map(|c| &c.cards).next().unwrap(); + assert_eq!(card.id, is_plan); + } + + // ASCII titles still answer, any case. + let mut board = izlek_core::board::load(&scratch.store, &workspace) + .await + .unwrap() + .unwrap(); + board.searching("WIRE"); + assert_eq!(board.task_count(), 1); + let card = board.columns.iter().flat_map(|c| &c.cards).next().unwrap(); + assert_eq!(card.id, wire); + + // The key keeps answering whatever case it is typed in. + let mut board = izlek_core::board::load(&scratch.store, &workspace) + .await + .unwrap() + .unwrap(); + board.searching(&key.to_lowercase()); + assert_eq!(board.task_count(), 1); + let card = board.columns.iter().flat_map(|c| &c.cards).next().unwrap(); + assert_eq!(card.id, is_plan); +} + +/// The watch backfill rides the reconcile rebuild: a database from before +/// the feed opens with a watch for every task somebody created, was +/// assigned, or commented on — soft-deleted tasks included, history +/// included. The pass can never run twice (it lives behind the fingerprint +/// gate), so an unassign after the deploy keeps its watch off across +/// restarts. +#[tokio::test] +async fn reconcile_backfills_watches_from_history_exactly_once() { + let (dir, path) = live_shaped_database().await; + + // A historical comment — the third watch-worthy fact — on a task that + // already carries creation and assignment history. + { + let db = turso::Builder::new_local(&path).build().await.unwrap(); + let conn = db.connect().unwrap(); + conn.execute( + "INSERT INTO comment (id, task_id, author_id, body, created_at) \ + VALUES ('CM1', 'T2', 'U1', 'on it', '2026-08-30T12:00:01Z')", + (), + ) + .await + .unwrap(); + } + + izlek_core::store::reconcile( + &path, + izlek_core::store::ReconcileOptions { + dry_run: false, + yes: true, + auto: true, + }, + ) + .await + .expect("reconcile refused the backfill"); + + // T1: created by U1, assigned to U2. T2: created U1, assigned U2, + // commented U1. T3: created U1, assigned U2. T4 (soft-deleted): created + // U1. Distinct (task, watcher) pairs: 2 + 2 + 2 + 1. + assert_eq!(scalar(&path, "SELECT COUNT(*) FROM task_watcher").await, 7); + assert_eq!( + scalar( + &path, + "SELECT COUNT(*) FROM task_watcher WHERE user_id = 'U2'" + ) + .await, + 3, + "the assignee watches every task they are on" + ); + assert_eq!( + scalar( + &path, + "SELECT COUNT(*) FROM task_watcher WHERE user_id = 'U1'" + ) + .await, + 4, + "the creator watches every task they made, soft-deleted included" + ); + + // The deploy happens; THEN Deniz unassigns — here, the same write the + // store makes. The pass never re-runs (the shape matches now), so the + // watch stays off across a restart and a second reconcile. + { + let db = turso::Builder::new_local(&path).build().await.unwrap(); + let conn = db.connect().unwrap(); + conn.execute( + "DELETE FROM task_watcher WHERE task_id = 'T1' AND user_id = 'U2'", + (), + ) + .await + .unwrap(); + } + izlek_core::store::reconcile( + &path, + izlek_core::store::ReconcileOptions { + dry_run: false, + yes: true, + auto: true, + }, + ) + .await + .unwrap(); + assert_eq!( + scalar( + &path, + "SELECT COUNT(*) FROM task_watcher WHERE task_id = 'T1'" + ) + .await, + 1, + "the unassigned watch was resurrected" + ); + let _store = TursoStore::open(&path).await.unwrap(); + assert_eq!( + scalar( + &path, + "SELECT COUNT(*) FROM task_watcher WHERE task_id = 'T1'" + ) + .await, + 1, + "a restart resurrected the unassigned watch" + ); + + let _ = std::fs::remove_dir_all(&dir); +}