From 08a79b8a3df55f274e25b03531dc1444a19662bc 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 02:03:18 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A6=20feat(core):=20a=20parent=20does?= =?UTF-8?q?=20not=20finish=20before=20its=20parts=20do?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moving a task into a done column is refused while any of its subtasks is still open. A parent marked finished over unfinished work is a lie the board would then go on telling — in the column counts, in the done stamp, in every mail a status rule sends. The check reads inside the same transaction as the move, so a subtask created while the drag was in the air cannot slip under it, and it leaves nothing behind: no column change, no crossing, no line in the activity strip. `Moved::Held` sits beside `Stale`, which the board already knows how to snap a card back from. One door, not two: the detail page's status control posts to the same `/api/move_card` as a drag, and `save_task` never touches a column. There is no override. A subtask nobody will do is deleted or promoted out of its parent, both single writes that already exist; a "finish anyway" button would make the rule advisory, which is worse than not having it. The sentence carries no count — the parent's card will show one — because a number cannot survive the round trip through the address bar a browser without script makes. --- crates/izlek-core/src/board.rs | 9 ++ crates/izlek-core/src/store/turso_store.rs | 24 ++++ crates/izlek-core/tests/store.rs | 137 +++++++++++++++++++++ crates/izlek-web/src/board.rs | 1 + crates/izlek-web/src/server.rs | 10 ++ crates/izlek-web/tests/http.rs | 83 +++++++++++++ 6 files changed, 264 insertions(+) diff --git a/crates/izlek-core/src/board.rs b/crates/izlek-core/src/board.rs index ae0e03d..ffa2d4f 100644 --- a/crates/izlek-core/src/board.rs +++ b/crates/izlek-core/src/board.rs @@ -68,6 +68,15 @@ pub enum Moved { /// longer the column it is in. Nothing was written and the caller should /// re-read the board rather than overwrite a decision it never saw. Stale, + /// The card was headed for a done column with subtasks still open. A + /// parent finished while its parts are not is a lie the board would then + /// go on telling, so nothing was written. + /// + /// There is no override: a subtask nobody will do is deleted or promoted + /// out of its parent, both of which are single writes that already exist. + /// A "finish anyway" button would make this rule advisory, which is worse + /// than not having it. + Held, } /// Whoever a card can point at. The address is not here: a board card never diff --git a/crates/izlek-core/src/store/turso_store.rs b/crates/izlek-core/src/store/turso_store.rs index 19877e8..ad986e5 100644 --- a/crates/izlek-core/src/store/turso_store.rs +++ b/crates/izlek-core/src/store/turso_store.rs @@ -428,6 +428,7 @@ enum Outcome { Wrote, Stale, Missing, + Held, } fn stamp(at: OffsetDateTime) -> Result { @@ -2015,6 +2016,25 @@ impl Store for TursoStore { }; drop(rows); + // A parent does not finish before its parts do. Read inside the + // same transaction as the move: outside it, a subtask created + // while the drag was in the air would slip under the check. + if to_is_done { + let mut rows = tx + .query( + "SELECT 1 FROM task \ + WHERE parent_id = ?1 AND deleted_at IS NULL AND done_at IS NULL \ + LIMIT 1", + params![task_id], + ) + .await?; + let open_child = rows.next().await?.is_some(); + drop(rows); + if open_child { + return Ok(Outcome::Held); + } + } + // The card lands at the end of its new column. Where inside a // column a card sits is the board's sort control's business, not // the drop's. @@ -2104,6 +2124,10 @@ impl Store for TursoStore { let _ = tx.rollback().await; Ok(Moved::Stale) } + Ok(Outcome::Held) => { + let _ = tx.rollback().await; + Ok(Moved::Held) + } Ok(Outcome::Missing) => { let _ = tx.rollback().await; Err(StoreError::NotFound) diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index a063b76..f36f449 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -267,6 +267,143 @@ async fn parenting_a_task_that_is_not_there_is_not_found() { )); } +/// A parent in Backlog with one subtask, also in Backlog. Returns both ids. +async fn a_parent_and_one_subtask( + store: &TursoStore, + workspace: &str, + admin: &str, +) -> (String, String) { + let parent = add_task(store, workspace, "Backlog", "Ship the exporter", None, admin).await; + let board = store.board(workspace).await.unwrap().unwrap(); + let column_id = column_named(store, workspace, "Backlog").await; + let child = store + .create_task(NewTask { + board_id: &board.id, + column_id: &column_id, + parent_id: Some(&parent), + title: "Write the CSV writer", + description: "", + deadline: None, + created_by: admin, + }) + .await + .unwrap() + .row + .id; + (parent, child) +} + +#[tokio::test] +async fn a_parent_does_not_finish_before_its_subtasks_do() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + + let backlog = column_named(&scratch.store, &workspace, "Backlog").await; + let done = column_named(&scratch.store, &workspace, "Done").await; + let held = scratch + .store + .move_task(&parent, &backlog, &done, &admin, OffsetDateTime::now_utc()) + .await + .unwrap(); + assert!(matches!(held, Moved::Held)); + + // Nothing was written: not the column, not a crossing for a rule to read. + let detail = load_detail(&scratch.store, &workspace, &parent) + .await + .unwrap() + .unwrap(); + assert_eq!(detail.column.id, backlog); + assert!(detail.done_at.is_none()); + assert!( + !detail + .activity + .iter() + .any(|entry| matches!(entry.kind, izlek_core::detail::ActivityKind::Moved)), + "a held move leaves no trail" + ); + + // The subtask finishing is what lets the parent through. + moved_to(&scratch.store, &workspace, &child, "Backlog", "Done", &admin).await; + let recorded = scratch + .store + .move_task(&parent, &backlog, &done, &admin, OffsetDateTime::now_utc()) + .await + .unwrap(); + assert!(matches!(recorded, Moved::Recorded(_))); + assert!( + load_detail(&scratch.store, &workspace, &parent) + .await + .unwrap() + .unwrap() + .done_at + .is_some() + ); +} + +#[tokio::test] +async fn an_open_subtask_only_holds_the_done_column() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (parent, _child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + + // Every other column is a column like any other. + moved_to( + &scratch.store, + &workspace, + &parent, + "Backlog", + "In Progress", + &admin, + ) + .await; + moved_to( + &scratch.store, + &workspace, + &parent, + "In Progress", + "Review", + &admin, + ) + .await; +} + +#[tokio::test] +async fn a_subtask_finishes_on_its_own_account() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (_parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + + // The rule is about a parent's parts, not about being somebody's part. + moved_to(&scratch.store, &workspace, &child, "Backlog", "Done", &admin).await; +} + +#[tokio::test] +async fn a_deleted_subtask_stops_holding_its_parent() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + + // The escape hatch is not an override button: a subtask nobody will do is + // deleted, or promoted out of its parent. + scratch + .store + .delete_task(&child, &admin, OffsetDateTime::now_utc()) + .await + .unwrap(); + moved_to(&scratch.store, &workspace, &parent, "Backlog", "Done", &admin).await; +} + +#[tokio::test] +async fn a_promoted_subtask_stops_holding_its_parent() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + + scratch.store.set_parent(&child, None).await.unwrap(); + moved_to(&scratch.store, &workspace, &parent, "Backlog", "Done", &admin).await; +} + #[tokio::test] async fn the_first_account_owns_the_workspace() { let scratch = Scratch::open().await; diff --git a/crates/izlek-web/src/board.rs b/crates/izlek-web/src/board.rs index 2e635c6..6c0da75 100644 --- a/crates/izlek-web/src/board.rs +++ b/crates/izlek-web/src/board.rs @@ -65,6 +65,7 @@ async fn move_card_shared( } Ok(Moved::Unchanged) => Ok(None), Ok(Moved::Stale) => Ok(Some(Refusal::MovedAlready)), + Ok(Moved::Held) => Ok(Some(Refusal::SubtasksOpen)), Err(izlek_core::store::StoreError::NotFound) => Ok(Some(Refusal::NotFound)), Err(error) => { eprintln!("store error: {error}"); diff --git a/crates/izlek-web/src/server.rs b/crates/izlek-web/src/server.rs index e85b513..cdfa1b9 100644 --- a/crates/izlek-web/src/server.rs +++ b/crates/izlek-web/src/server.rs @@ -360,6 +360,11 @@ pub enum Refusal { /// The card was already moved out of the column this request thought it /// was in, by somebody else, while this person was deciding. MovedAlready, + /// A task headed for a done column while its subtasks are not done. The + /// count is deliberately not in the sentence: the parent's card already + /// carries it, and a number cannot survive the round trip through the + /// address bar that a browser without script makes. + SubtasksOpen, /// No such task — or none this account may see. Deliberately one answer for /// both. NotFound, @@ -409,6 +414,7 @@ impl Refusal { Refusal::BadDeadline => "That is not a date.".to_string(), Refusal::Cycle => "That link would put this task behind itself.".to_string(), Refusal::MovedAlready => "Somebody moved this card first.".to_string(), + Refusal::SubtasksOpen => "Subtasks are still open.".to_string(), Refusal::NotFound => "No such task.".to_string(), Refusal::NoSuchMember => "No such member.".to_string(), Refusal::Unavailable => "Something went wrong.".to_string(), @@ -438,6 +444,7 @@ impl Refusal { Refusal::BadDeadline => "Bu bir tarih değil.".to_string(), Refusal::Cycle => "Bu bağlantı görevi kendi arkasına koyar.".to_string(), Refusal::MovedAlready => "Bu kartı başka biri zaten taşıdı.".to_string(), + Refusal::SubtasksOpen => "Alt görevler hâlâ açık.".to_string(), Refusal::NotFound => "Böyle bir görev yok.".to_string(), Refusal::NoSuchMember => "Böyle bir üye yok.".to_string(), Refusal::Unavailable => "Bir şeyler ters gitti.".to_string(), @@ -512,6 +519,7 @@ impl Refusal { "bad-deadline" => Refusal::BadDeadline, "cycle" => Refusal::Cycle, "moved-already" => Refusal::MovedAlready, + "subtasks-open" => Refusal::SubtasksOpen, "not-found" => Refusal::NotFound, "no-such-member" => Refusal::NoSuchMember, "unavailable" => Refusal::Unavailable, @@ -565,6 +573,7 @@ impl Refusal { Refusal::BadDeadline => "bad-deadline", Refusal::Cycle => "cycle", Refusal::MovedAlready => "moved-already", + Refusal::SubtasksOpen => "subtasks-open", Refusal::NotFound => "not-found", Refusal::NoSuchMember => "no-such-member", Refusal::Unavailable => "unavailable", @@ -842,6 +851,7 @@ mod refusal_message_tests { Refusal::BadEmail, Refusal::Cycle, Refusal::MovedAlready, + Refusal::SubtasksOpen, Refusal::NotFound, Refusal::NoSuchMember, Refusal::Unavailable, diff --git a/crates/izlek-web/tests/http.rs b/crates/izlek-web/tests/http.rs index 6a4fd82..a24842b 100644 --- a/crates/izlek-web/tests/http.rs +++ b/crates/izlek-web/tests/http.rs @@ -1346,6 +1346,89 @@ async fn a_successful_move_never_redirects_off_site() { ); } +#[tokio::test] +async fn a_card_with_open_subtasks_is_refused_the_done_column() { + let app = App::open().await; + let admin = admin(&app).await; + let columns = columns_of(&app).await; + let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await; + let child = a_task(&app, &admin, &columns[0], "Write the CSV writer").await; + app.store.set_parent(&child, Some(&parent)).await.unwrap(); + + // The last column is the done one; both the board drag and the detail + // page's status control post here. + let done = columns.last().unwrap(); + let held = app + .post( + "/api/move_card", + Some(&admin), + &[ + ("task_id", &parent), + ("from_column_id", &columns[0]), + ("to_column_id", done), + ], + ) + .await; + assert!( + held.location + .as_deref() + .unwrap_or_default() + .contains("refusal=subtasks-open&on=move_card"), + "{:?}", + held.location + ); + + // The card did not move, so the board still shows it where it was. + let workspace_id = app.workspace_id().await; + let board = izlek_core::board::load(app.store.as_ref(), &workspace_id) + .await + .unwrap() + .unwrap(); + let held_card = board + .columns + .iter() + .flat_map(|c| &c.cards) + .find(|card| card.id == parent) + .expect("the parent left the board"); + assert_eq!(held_card.column_id, columns[0]); + assert!(!held_card.is_done()); + + // Finishing the subtask is what lets it through. + let finished = app + .post( + "/api/move_card", + Some(&admin), + &[ + ("task_id", &child), + ("from_column_id", &columns[0]), + ("to_column_id", done), + ], + ) + .await; + assert_eq!(finished.body, ""); + let through = app + .post( + "/api/move_card", + Some(&admin), + &[ + ("task_id", &parent), + ("from_column_id", &columns[0]), + ("to_column_id", done), + ], + ) + .await; + assert_eq!(through.body, ""); + assert!( + !through + .location + .as_deref() + .unwrap_or_default() + .contains("refusal="), + "{:?}", + through.location + ); +} + #[tokio::test] async fn a_drop_decided_against_a_stale_board_is_refused() { let app = App::open().await;