forge
Explore
Log in

Don't you dare go Hollow

A parent does not finish before its parts do

Browse files at this commit

08a79b8a3df55f274e25b03531dc1444a19662bcAhmet Kaan GümüşParent: 71160f3
  • feat
    • a parent does not finish before its parts do
Show full message
🚦 feat(core): a parent does not finish before its parts do

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.rsmodified+9 -0
@@ -68,6 +68,15 @@ pub enum Moved {
68 /// longer the column it is in. Nothing was written and the caller should68 /// longer the column it is in. Nothing was written and the caller should
69 /// re-read the board rather than overwrite a decision it never saw.69 /// re-read the board rather than overwrite a decision it never saw.
70 Stale,70 Stale,
71+ /// The card was headed for a done column with subtasks still open. A
72+ /// parent finished while its parts are not is a lie the board would then
73+ /// go on telling, so nothing was written.
74+ ///
75+ /// There is no override: a subtask nobody will do is deleted or promoted
76+ /// out of its parent, both of which are single writes that already exist.
77+ /// A "finish anyway" button would make this rule advisory, which is worse
78+ /// than not having it.
79+ Held,
71 }80 }
72 81
73 /// Whoever a card can point at. The address is not here: a board card never82 /// Whoever a card can point at. The address is not here: a board card never
crates/izlek-core/src/store/turso_store.rsmodified+24 -0
@@ -428,6 +428,7 @@ enum Outcome {
428 Wrote,428 Wrote,
429 Stale,429 Stale,
430 Missing,430 Missing,
431+ Held,
431 }432 }
432 433
433 fn stamp(at: OffsetDateTime) -> Result<String> {434 fn stamp(at: OffsetDateTime) -> Result<String> {
@@ -2015,6 +2016,25 @@ impl Store for TursoStore {
2015 };2016 };
2016 drop(rows);2017 drop(rows);
2017 2018
2019+ // A parent does not finish before its parts do. Read inside the
2020+ // same transaction as the move: outside it, a subtask created
2021+ // while the drag was in the air would slip under the check.
2022+ if to_is_done {
2023+ let mut rows = tx
2024+ .query(
2025+ "SELECT 1 FROM task \
2026+ WHERE parent_id = ?1 AND deleted_at IS NULL AND done_at IS NULL \
2027+ LIMIT 1",
2028+ params![task_id],
2029+ )
2030+ .await?;
2031+ let open_child = rows.next().await?.is_some();
2032+ drop(rows);
2033+ if open_child {
2034+ return Ok(Outcome::Held);
2035+ }
2036+ }
2037+
2018 // The card lands at the end of its new column. Where inside a2038 // The card lands at the end of its new column. Where inside a
2019 // column a card sits is the board's sort control's business, not2039 // column a card sits is the board's sort control's business, not
2020 // the drop's.2040 // the drop's.
@@ -2104,6 +2124,10 @@ impl Store for TursoStore {
2104 let _ = tx.rollback().await;2124 let _ = tx.rollback().await;
2105 Ok(Moved::Stale)2125 Ok(Moved::Stale)
2106 }2126 }
2127+ Ok(Outcome::Held) => {
2128+ let _ = tx.rollback().await;
2129+ Ok(Moved::Held)
2130+ }
2107 Ok(Outcome::Missing) => {2131 Ok(Outcome::Missing) => {
2108 let _ = tx.rollback().await;2132 let _ = tx.rollback().await;
2109 Err(StoreError::NotFound)2133 Err(StoreError::NotFound)
crates/izlek-core/tests/store.rsmodified+137 -0
@@ -267,6 +267,143 @@ async fn parenting_a_task_that_is_not_there_is_not_found() {
267 ));267 ));
268 }268 }
269 269
270+/// A parent in Backlog with one subtask, also in Backlog. Returns both ids.
271+async fn a_parent_and_one_subtask(
272+ store: &TursoStore,
273+ workspace: &str,
274+ admin: &str,
275+) -> (String, String) {
276+ let parent = add_task(store, workspace, "Backlog", "Ship the exporter", None, admin).await;
277+ let board = store.board(workspace).await.unwrap().unwrap();
278+ let column_id = column_named(store, workspace, "Backlog").await;
279+ let child = store
280+ .create_task(NewTask {
281+ board_id: &board.id,
282+ column_id: &column_id,
283+ parent_id: Some(&parent),
284+ title: "Write the CSV writer",
285+ description: "",
286+ deadline: None,
287+ created_by: admin,
288+ })
289+ .await
290+ .unwrap()
291+ .row
292+ .id;
293+ (parent, child)
294+}
295+
296+#[tokio::test]
297+async fn a_parent_does_not_finish_before_its_subtasks_do() {
298+ let scratch = Scratch::open().await;
299+ let (workspace, admin) = claim(&scratch.store).await;
300+ let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
301+
302+ let backlog = column_named(&scratch.store, &workspace, "Backlog").await;
303+ let done = column_named(&scratch.store, &workspace, "Done").await;
304+ let held = scratch
305+ .store
306+ .move_task(&parent, &backlog, &done, &admin, OffsetDateTime::now_utc())
307+ .await
308+ .unwrap();
309+ assert!(matches!(held, Moved::Held));
310+
311+ // Nothing was written: not the column, not a crossing for a rule to read.
312+ let detail = load_detail(&scratch.store, &workspace, &parent)
313+ .await
314+ .unwrap()
315+ .unwrap();
316+ assert_eq!(detail.column.id, backlog);
317+ assert!(detail.done_at.is_none());
318+ assert!(
319+ !detail
320+ .activity
321+ .iter()
322+ .any(|entry| matches!(entry.kind, izlek_core::detail::ActivityKind::Moved)),
323+ "a held move leaves no trail"
324+ );
325+
326+ // The subtask finishing is what lets the parent through.
327+ moved_to(&scratch.store, &workspace, &child, "Backlog", "Done", &admin).await;
328+ let recorded = scratch
329+ .store
330+ .move_task(&parent, &backlog, &done, &admin, OffsetDateTime::now_utc())
331+ .await
332+ .unwrap();
333+ assert!(matches!(recorded, Moved::Recorded(_)));
334+ assert!(
335+ load_detail(&scratch.store, &workspace, &parent)
336+ .await
337+ .unwrap()
338+ .unwrap()
339+ .done_at
340+ .is_some()
341+ );
342+}
343+
344+#[tokio::test]
345+async fn an_open_subtask_only_holds_the_done_column() {
346+ let scratch = Scratch::open().await;
347+ let (workspace, admin) = claim(&scratch.store).await;
348+ let (parent, _child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
349+
350+ // Every other column is a column like any other.
351+ moved_to(
352+ &scratch.store,
353+ &workspace,
354+ &parent,
355+ "Backlog",
356+ "In Progress",
357+ &admin,
358+ )
359+ .await;
360+ moved_to(
361+ &scratch.store,
362+ &workspace,
363+ &parent,
364+ "In Progress",
365+ "Review",
366+ &admin,
367+ )
368+ .await;
369+}
370+
371+#[tokio::test]
372+async fn a_subtask_finishes_on_its_own_account() {
373+ let scratch = Scratch::open().await;
374+ let (workspace, admin) = claim(&scratch.store).await;
375+ let (_parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
376+
377+ // The rule is about a parent's parts, not about being somebody's part.
378+ moved_to(&scratch.store, &workspace, &child, "Backlog", "Done", &admin).await;
379+}
380+
381+#[tokio::test]
382+async fn a_deleted_subtask_stops_holding_its_parent() {
383+ let scratch = Scratch::open().await;
384+ let (workspace, admin) = claim(&scratch.store).await;
385+ let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
386+
387+ // The escape hatch is not an override button: a subtask nobody will do is
388+ // deleted, or promoted out of its parent.
389+ scratch
390+ .store
391+ .delete_task(&child, &admin, OffsetDateTime::now_utc())
392+ .await
393+ .unwrap();
394+ moved_to(&scratch.store, &workspace, &parent, "Backlog", "Done", &admin).await;
395+}
396+
397+#[tokio::test]
398+async fn a_promoted_subtask_stops_holding_its_parent() {
399+ let scratch = Scratch::open().await;
400+ let (workspace, admin) = claim(&scratch.store).await;
401+ let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
402+
403+ scratch.store.set_parent(&child, None).await.unwrap();
404+ moved_to(&scratch.store, &workspace, &parent, "Backlog", "Done", &admin).await;
405+}
406+
270 #[tokio::test]407 #[tokio::test]
271 async fn the_first_account_owns_the_workspace() {408 async fn the_first_account_owns_the_workspace() {
272 let scratch = Scratch::open().await;409 let scratch = Scratch::open().await;
crates/izlek-web/src/board.rsmodified+1 -0
@@ -65,6 +65,7 @@ async fn move_card_shared(
65 }65 }
66 Ok(Moved::Unchanged) => Ok(None),66 Ok(Moved::Unchanged) => Ok(None),
67 Ok(Moved::Stale) => Ok(Some(Refusal::MovedAlready)),67 Ok(Moved::Stale) => Ok(Some(Refusal::MovedAlready)),
68+ Ok(Moved::Held) => Ok(Some(Refusal::SubtasksOpen)),
68 Err(izlek_core::store::StoreError::NotFound) => Ok(Some(Refusal::NotFound)),69 Err(izlek_core::store::StoreError::NotFound) => Ok(Some(Refusal::NotFound)),
69 Err(error) => {70 Err(error) => {
70 eprintln!("store error: {error}");71 eprintln!("store error: {error}");
crates/izlek-web/src/server.rsmodified+10 -0
@@ -360,6 +360,11 @@ pub enum Refusal {
360 /// The card was already moved out of the column this request thought it360 /// The card was already moved out of the column this request thought it
361 /// was in, by somebody else, while this person was deciding.361 /// was in, by somebody else, while this person was deciding.
362 MovedAlready,362 MovedAlready,
363+ /// A task headed for a done column while its subtasks are not done. The
364+ /// count is deliberately not in the sentence: the parent's card already
365+ /// carries it, and a number cannot survive the round trip through the
366+ /// address bar that a browser without script makes.
367+ SubtasksOpen,
363 /// No such task — or none this account may see. Deliberately one answer for368 /// No such task — or none this account may see. Deliberately one answer for
364 /// both.369 /// both.
365 NotFound,370 NotFound,
@@ -409,6 +414,7 @@ impl Refusal {
409 Refusal::BadDeadline => "That is not a date.".to_string(),414 Refusal::BadDeadline => "That is not a date.".to_string(),
410 Refusal::Cycle => "That link would put this task behind itself.".to_string(),415 Refusal::Cycle => "That link would put this task behind itself.".to_string(),
411 Refusal::MovedAlready => "Somebody moved this card first.".to_string(),416 Refusal::MovedAlready => "Somebody moved this card first.".to_string(),
417+ Refusal::SubtasksOpen => "Subtasks are still open.".to_string(),
412 Refusal::NotFound => "No such task.".to_string(),418 Refusal::NotFound => "No such task.".to_string(),
413 Refusal::NoSuchMember => "No such member.".to_string(),419 Refusal::NoSuchMember => "No such member.".to_string(),
414 Refusal::Unavailable => "Something went wrong.".to_string(),420 Refusal::Unavailable => "Something went wrong.".to_string(),
@@ -438,6 +444,7 @@ impl Refusal {
438 Refusal::BadDeadline => "Bu bir tarih değil.".to_string(),444 Refusal::BadDeadline => "Bu bir tarih değil.".to_string(),
439 Refusal::Cycle => "Bu bağlantı görevi kendi arkasına koyar.".to_string(),445 Refusal::Cycle => "Bu bağlantı görevi kendi arkasına koyar.".to_string(),
440 Refusal::MovedAlready => "Bu kartı başka biri zaten taşıdı.".to_string(),446 Refusal::MovedAlready => "Bu kartı başka biri zaten taşıdı.".to_string(),
447+ Refusal::SubtasksOpen => "Alt görevler hâlâ açık.".to_string(),
441 Refusal::NotFound => "Böyle bir görev yok.".to_string(),448 Refusal::NotFound => "Böyle bir görev yok.".to_string(),
442 Refusal::NoSuchMember => "Böyle bir üye yok.".to_string(),449 Refusal::NoSuchMember => "Böyle bir üye yok.".to_string(),
443 Refusal::Unavailable => "Bir şeyler ters gitti.".to_string(),450 Refusal::Unavailable => "Bir şeyler ters gitti.".to_string(),
@@ -512,6 +519,7 @@ impl Refusal {
512 "bad-deadline" => Refusal::BadDeadline,519 "bad-deadline" => Refusal::BadDeadline,
513 "cycle" => Refusal::Cycle,520 "cycle" => Refusal::Cycle,
514 "moved-already" => Refusal::MovedAlready,521 "moved-already" => Refusal::MovedAlready,
522+ "subtasks-open" => Refusal::SubtasksOpen,
515 "not-found" => Refusal::NotFound,523 "not-found" => Refusal::NotFound,
516 "no-such-member" => Refusal::NoSuchMember,524 "no-such-member" => Refusal::NoSuchMember,
517 "unavailable" => Refusal::Unavailable,525 "unavailable" => Refusal::Unavailable,
@@ -565,6 +573,7 @@ impl Refusal {
565 Refusal::BadDeadline => "bad-deadline",573 Refusal::BadDeadline => "bad-deadline",
566 Refusal::Cycle => "cycle",574 Refusal::Cycle => "cycle",
567 Refusal::MovedAlready => "moved-already",575 Refusal::MovedAlready => "moved-already",
576+ Refusal::SubtasksOpen => "subtasks-open",
568 Refusal::NotFound => "not-found",577 Refusal::NotFound => "not-found",
569 Refusal::NoSuchMember => "no-such-member",578 Refusal::NoSuchMember => "no-such-member",
570 Refusal::Unavailable => "unavailable",579 Refusal::Unavailable => "unavailable",
@@ -842,6 +851,7 @@ mod refusal_message_tests {
842 Refusal::BadEmail,851 Refusal::BadEmail,
843 Refusal::Cycle,852 Refusal::Cycle,
844 Refusal::MovedAlready,853 Refusal::MovedAlready,
854+ Refusal::SubtasksOpen,
845 Refusal::NotFound,855 Refusal::NotFound,
846 Refusal::NoSuchMember,856 Refusal::NoSuchMember,
847 Refusal::Unavailable,857 Refusal::Unavailable,
crates/izlek-web/tests/http.rsmodified+83 -0
@@ -1346,6 +1346,89 @@ async fn a_successful_move_never_redirects_off_site() {
1346 );1346 );
1347 }1347 }
1348 1348
1349+#[tokio::test]
1350+async fn a_card_with_open_subtasks_is_refused_the_done_column() {
1351+ let app = App::open().await;
1352+ let admin = admin(&app).await;
1353+ let columns = columns_of(&app).await;
1354+ let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await;
1355+ let child = a_task(&app, &admin, &columns[0], "Write the CSV writer").await;
1356+ app.store.set_parent(&child, Some(&parent)).await.unwrap();
1357+
1358+ // The last column is the done one; both the board drag and the detail
1359+ // page's status control post here.
1360+ let done = columns.last().unwrap();
1361+ let held = app
1362+ .post(
1363+ "/api/move_card",
1364+ Some(&admin),
1365+ &[
1366+ ("task_id", &parent),
1367+ ("from_column_id", &columns[0]),
1368+ ("to_column_id", done),
1369+ ],
1370+ )
1371+ .await;
1372+ assert!(
1373+ held.location
1374+ .as_deref()
1375+ .unwrap_or_default()
1376+ .contains("refusal=subtasks-open&on=move_card"),
1377+ "{:?}",
1378+ held.location
1379+ );
1380+
1381+ // The card did not move, so the board still shows it where it was.
1382+ let workspace_id = app.workspace_id().await;
1383+ let board = izlek_core::board::load(app.store.as_ref(), &workspace_id)
1384+ .await
1385+ .unwrap()
1386+ .unwrap();
1387+ let held_card = board
1388+ .columns
1389+ .iter()
1390+ .flat_map(|c| &c.cards)
1391+ .find(|card| card.id == parent)
1392+ .expect("the parent left the board");
1393+ assert_eq!(held_card.column_id, columns[0]);
1394+ assert!(!held_card.is_done());
1395+
1396+ // Finishing the subtask is what lets it through.
1397+ let finished = app
1398+ .post(
1399+ "/api/move_card",
1400+ Some(&admin),
1401+ &[
1402+ ("task_id", &child),
1403+ ("from_column_id", &columns[0]),
1404+ ("to_column_id", done),
1405+ ],
1406+ )
1407+ .await;
1408+ assert_eq!(finished.body, "");
1409+ let through = app
1410+ .post(
1411+ "/api/move_card",
1412+ Some(&admin),
1413+ &[
1414+ ("task_id", &parent),
1415+ ("from_column_id", &columns[0]),
1416+ ("to_column_id", done),
1417+ ],
1418+ )
1419+ .await;
1420+ assert_eq!(through.body, "");
1421+ assert!(
1422+ !through
1423+ .location
1424+ .as_deref()
1425+ .unwrap_or_default()
1426+ .contains("refusal="),
1427+ "{:?}",
1428+ through.location
1429+ );
1430+}
1431+
1349 #[tokio::test]1432 #[tokio::test]
1350 async fn a_drop_decided_against_a_stale_board_is_refused() {1433 async fn a_drop_decided_against_a_stale_board_is_refused() {
1351 let app = App::open().await;1434 let app = App::open().await;