Sort the backlog by due date, then priority
The backlog was the one column priority governed alone, which sat a p1 nobody had promised above a p3 due tomorrow. It has no entry stamp, so it now takes the due date as the date `by_status_order` keys on: soonest first, undated below every dated one, and priority then title as the tiebreak, which is still the whole order among the undated ones. `TicketItem::due_key` is where a due becomes an orderable date. Only a plain `YYYY-MM-DD` counts, which is all `--due` has accepted since daa0e79, with `due_date` cutting a legacy datetime back to its date. Free text answers `None` and sinks with the unset ones rather than sorting on its spelling: a due nobody can place on a calendar is unknown, the same reading a missing stamp already gets. The comparator stays the single function keyed on `Status`, so `ls`, `ls --ids`, the board's columns and `campaign::members` move together. The All tab keeps `by_priority_then_title`: that merge spans statuses, so no single date governs it. `ls_listed_tickets_sorted_alphabetically` gave its three tickets three different due dates while asserting title order. They share one now, so the case still tests the tiebreak it names rather than the new order. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
cd7c99fe39
commit
c81838efc6
+26
-3
@@ -9175,9 +9175,9 @@ approach";
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Each column is ordered by its own entry stamp, not by priority: committed is the
|
||||
/// longest wait first, done is what just landed first. Every ticket here is a p2, so
|
||||
/// the stamp is doing all of the work.
|
||||
/// Every column past the backlog is ordered by its own entry stamp, not by priority:
|
||||
/// committed is the longest wait first, done is what just landed first. Every ticket
|
||||
/// here is a p2, so the stamp is doing all of the work.
|
||||
#[test]
|
||||
fn a_column_is_ordered_by_the_stamp_the_ticket_entered_it_with() {
|
||||
let dir = board_dir();
|
||||
@@ -9218,6 +9218,29 @@ approach";
|
||||
assert_eq!(column_titles(&board, 3), ["Newer", "Older"]);
|
||||
}
|
||||
|
||||
/// The backlog is the column with no entry stamp, so the due date is what orders it.
|
||||
/// Every ticket here is a p2, so the due is doing all of the work, and the undated
|
||||
/// one trails both dated ones rather than sitting among them.
|
||||
#[test]
|
||||
fn the_backlog_column_is_ordered_by_the_due_date() {
|
||||
let dir = board_dir();
|
||||
let card = |uuid: &str, title: &str, due: &str| {
|
||||
let path = write_ticket(&dir, "backlog", uuid, title, "");
|
||||
let body = std::fs::read_to_string(&path)
|
||||
.unwrap()
|
||||
.replace("- **Due**: 2026-12-31", &format!("- **Due**: {due}"));
|
||||
std::fs::write(&path, body).unwrap();
|
||||
};
|
||||
|
||||
card("11111111-0000-4000-8000-000000000000", "Later", "2026-09-03");
|
||||
card("22222222-0000-4000-8000-000000000000", "Undated", "_Not set_");
|
||||
card("33333333-0000-4000-8000-000000000000", "Sooner", "2026-09-01");
|
||||
|
||||
let board = boards(&[("only", &dir)]);
|
||||
|
||||
assert_eq!(column_titles(&board, 0), ["Sooner", "Later", "Undated"]);
|
||||
}
|
||||
|
||||
/// The merge spans statuses, so no single stamp governs it and it keeps priority then
|
||||
/// title. Pinned on done, where the column order and the merge order disagree: the
|
||||
/// board would put the newest first and the merge puts the p1 first.
|
||||
|
||||
+145
-25
@@ -3323,7 +3323,8 @@ impl TicketItem {
|
||||
/// A slot per status rather than a lookup by field name, so a fifth status carrying
|
||||
/// a stamp is a compile error here the way it is in [`Status::stamp_field`].
|
||||
/// Backlog has none: nothing stamps it, and `Created At` is not an entry time, so
|
||||
/// every ticket in that column answers `None` and the whole order is the fallback.
|
||||
/// every ticket in that column answers `None` and [`TicketItem::due_key`] is what
|
||||
/// orders it instead.
|
||||
fn entry_stamp(&self, status: Status) -> Option<&str> {
|
||||
match status {
|
||||
Status::Backlog => None,
|
||||
@@ -3333,6 +3334,22 @@ impl TicketItem {
|
||||
Status::Discarded => self.discarded_on.as_deref(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The date the ticket is due, or `None` for one carrying nothing orderable.
|
||||
///
|
||||
/// What the backlog is sorted on, standing in for the entry stamp the column does
|
||||
/// not have. `YYYY-MM-DD` only, so lexicographic order is chronological order and
|
||||
/// the comparison stays a string comparison like the stamps'. `--due` has refused
|
||||
/// anything else since daa0e79, and [`due_date`] cuts a datetime written before
|
||||
/// that, or by hand, back to its date.
|
||||
///
|
||||
/// Free text answers `None` rather than sorting on its spelling. A due nobody can
|
||||
/// place on a calendar is unknown, the same reading a missing stamp gets, and
|
||||
/// unknown must not claim a place in a queue ordered by time.
|
||||
fn due_key(&self) -> Option<&str> {
|
||||
let date = due_date(&self.due);
|
||||
is_ymd(date).then_some(date)
|
||||
}
|
||||
}
|
||||
|
||||
/// The stamp a ticket carries for a status, or `None` for one it has not reached.
|
||||
@@ -3538,8 +3555,7 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
/// The order the backlog is read in, and the tiebreak every other column falls back to:
|
||||
/// priority first, title second.
|
||||
/// The tiebreak every column falls back to: priority first, title second.
|
||||
///
|
||||
/// Named and exported because the board's All tab merges several boards' columns into
|
||||
/// one and has to land in one order. A merge sorted a second way would put a p1 below a
|
||||
@@ -3554,36 +3570,46 @@ pub fn by_priority_then_title(a: &TicketItem, b: &TicketItem) -> std::cmp::Order
|
||||
|
||||
/// The order one status column is read in, keyed on the status.
|
||||
///
|
||||
/// Priority is the clock in the backlog, and that column keeps exactly the order it has
|
||||
/// always printed. Past the backlog the question changes: committed asks what has waited
|
||||
/// longest, reviewing what was handed over first, done what just landed. The head of
|
||||
/// every column is therefore what the reader acts on next, which is ascending by entry
|
||||
/// stamp in committed and reviewing and descending in done and discarded, the way a
|
||||
/// changelog reads.
|
||||
/// Every column asks the same question, what the reader acts on next, and answers it
|
||||
/// with the one date it has. Committed asks what has waited longest, reviewing what was
|
||||
/// handed over first, done what just landed: ascending by entry stamp in committed and
|
||||
/// reviewing, descending in done and discarded, the way a changelog reads. The backlog
|
||||
/// carries no entry stamp, so what heads it is the date the work is wanted by, soonest
|
||||
/// first. Priority ran that column alone until then, which sat a p1 nobody had promised
|
||||
/// above a p3 due tomorrow.
|
||||
///
|
||||
/// A ticket with no stamp sinks below every stamped one in its column. A missing time is
|
||||
/// unknown, not ancient, and unknown must not claim the head of a queue ahead of a wait
|
||||
/// somebody can point at. Reading absence as the epoch would come free from the string
|
||||
/// comparison and put every legacy ticket first on data nothing verified.
|
||||
/// A ticket with no date sinks below every dated one in its column, whether that date is
|
||||
/// a stamp or a due. A missing time is unknown, not ancient, and unknown must not claim
|
||||
/// the head of a queue ahead of a deadline somebody can point at. Reading absence as the
|
||||
/// epoch would come free from the string comparison and put every legacy ticket first on
|
||||
/// data nothing verified.
|
||||
///
|
||||
/// The comparison is a string comparison. The stamp format is `%Y-%m-%d %H:%M:%S`, where
|
||||
/// lexicographic order is chronological order, the same property `Due` already relies
|
||||
/// on, so there is no date parsing at sort time. Equal stamps happen, `mv` writes whole
|
||||
/// seconds, and they fall through to priority and title like everything else.
|
||||
/// The comparison is a string comparison. The stamp format is `%Y-%m-%d %H:%M:%S` and a
|
||||
/// due is `%Y-%m-%d`, both of which order lexicographically the way they order
|
||||
/// chronologically, so there is no date parsing at sort time. Equal dates happen, `mv`
|
||||
/// writes whole seconds and a due has no time at all, and they fall through to priority
|
||||
/// and title like everything else.
|
||||
pub fn by_status_order(status: Status, a: &TicketItem, b: &TicketItem) -> std::cmp::Ordering {
|
||||
let by_stamp = match (a.entry_stamp(status), b.entry_stamp(status)) {
|
||||
// One pair, so the rules below are written once. Which date a column is keyed on is
|
||||
// the only thing that changes with the status.
|
||||
let (left, right) = match status {
|
||||
Status::Backlog => (a.due_key(), b.due_key()),
|
||||
_ => (a.entry_stamp(status), b.entry_stamp(status)),
|
||||
};
|
||||
|
||||
let by_date = match (left, right) {
|
||||
(Some(left), Some(right)) => match status {
|
||||
Status::Done | Status::Discarded => right.cmp(left),
|
||||
_ => left.cmp(right),
|
||||
},
|
||||
(Some(_), None) => std::cmp::Ordering::Less,
|
||||
(None, Some(_)) => std::cmp::Ordering::Greater,
|
||||
// Both unstamped, which is every ticket in the backlog: the fallback is the
|
||||
// whole order there rather than a tiebreak.
|
||||
// Neither carries one, which is every undated ticket in the backlog: the
|
||||
// fallback is the whole order between them rather than a tiebreak.
|
||||
(None, None) => std::cmp::Ordering::Equal,
|
||||
};
|
||||
|
||||
by_stamp.then_with(|| by_priority_then_title(a, b))
|
||||
by_date.then_with(|| by_priority_then_title(a, b))
|
||||
}
|
||||
|
||||
/// The environment variable that keeps a test's fixture directory on disk.
|
||||
@@ -4649,6 +4675,16 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// A listed ticket carrying a due value, which is what the backlog column is ordered
|
||||
/// by. Built off [`listed`] rather than beside it, so a field added to `TicketItem`
|
||||
/// is still filled in one place.
|
||||
fn due_on(title: &str, level: u8, status: Status, due: &str) -> TicketItem {
|
||||
TicketItem {
|
||||
due: due.to_string(),
|
||||
..listed(title, level, status, None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Sorted the way the column is read, titles out, so a case reads as the order it
|
||||
/// asserts rather than as a pair of comparisons.
|
||||
fn ordered(status: Status, mut items: Vec<TicketItem>) -> Vec<String> {
|
||||
@@ -4656,11 +4692,11 @@ mod tests {
|
||||
items.into_iter().map(|item| item.title).collect()
|
||||
}
|
||||
|
||||
/// The backlog is the one column priority still governs, and it prints exactly what
|
||||
/// it always has: the stamps a ticket carries from an earlier trip through the flow
|
||||
/// do not reach it, because backlog has no stamp of its own to sort on.
|
||||
/// Undated backlog tickets keep exactly the order the column always printed: the
|
||||
/// stamps a ticket carries from an earlier trip through the flow do not reach it,
|
||||
/// because backlog has no stamp of its own to sort on.
|
||||
#[test]
|
||||
fn the_backlog_keeps_priority_then_title() {
|
||||
fn undated_backlog_tickets_keep_priority_then_title() {
|
||||
let items = vec![
|
||||
listed("zebra", 5, Status::Backlog, None),
|
||||
listed("alpha", 1, Status::Backlog, None),
|
||||
@@ -4670,6 +4706,90 @@ mod tests {
|
||||
assert_eq!(ordered(Status::Backlog, items), ["alpha", "beta", "zebra"]);
|
||||
}
|
||||
|
||||
/// The due date is the backlog's clock, so the soonest deadline heads the column the
|
||||
/// way the oldest wait heads committed. Priority is deliberately inverted against the
|
||||
/// dates here: a p1 due last is still listed last.
|
||||
#[test]
|
||||
fn the_backlog_lists_the_soonest_due_date_first() {
|
||||
let items = vec![
|
||||
listed("undated", 1, Status::Backlog, None),
|
||||
due_on("last", 1, Status::Backlog, "2026-09-03"),
|
||||
due_on("first", 5, Status::Backlog, "2026-09-01"),
|
||||
due_on("middle", 3, Status::Backlog, "2026-09-02"),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(Status::Backlog, items), ["first", "middle", "last", "undated"]);
|
||||
}
|
||||
|
||||
/// A due nobody promised must not outrank one somebody did, whatever the priorities
|
||||
/// say. This is the case the column got wrong before: the p1 sat on top.
|
||||
#[test]
|
||||
fn a_dated_backlog_ticket_sorts_above_an_undated_one_of_any_priority() {
|
||||
let items = vec![
|
||||
listed("undated", 1, Status::Backlog, None),
|
||||
due_on("dated", 5, Status::Backlog, "2026-09-01"),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(Status::Backlog, items), ["dated", "undated"]);
|
||||
}
|
||||
|
||||
/// A due carries no time, so two tickets wanted on the same day is the common case
|
||||
/// rather than the rare one, and it falls through to priority and title.
|
||||
#[test]
|
||||
fn backlog_tickets_sharing_a_due_date_fall_back_to_priority_then_title() {
|
||||
let same = "2026-09-01";
|
||||
let items = vec![
|
||||
due_on("zebra", 1, Status::Backlog, same),
|
||||
due_on("beta", 3, Status::Backlog, same),
|
||||
due_on("alpha", 3, Status::Backlog, same),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(Status::Backlog, items), ["zebra", "alpha", "beta"]);
|
||||
}
|
||||
|
||||
/// `--due` has taken `YYYY-MM-DD` and nothing else since daa0e79, but a file written
|
||||
/// before that or by hand can hold a datetime or free text. The datetime sorts on the
|
||||
/// date inside it; the free text is unknown rather than a date, and sinks with the
|
||||
/// unset ones instead of sorting on its spelling.
|
||||
#[test]
|
||||
fn a_backlog_due_that_is_not_a_plain_date_sorts_on_what_can_be_read_from_it() {
|
||||
let items = vec![
|
||||
due_on("prose", 1, Status::Backlog, "next friday"),
|
||||
due_on("unset", 1, Status::Backlog, NOT_SET),
|
||||
due_on("datetime", 5, Status::Backlog, "2026-09-01 09:30:00"),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(Status::Backlog, items), ["datetime", "prose", "unset"]);
|
||||
}
|
||||
|
||||
/// The due is the backlog's clock and only the backlog's. Past it the entry stamp is
|
||||
/// the question, and a deadline set on a committed ticket does not reorder the queue
|
||||
/// of what has waited longest.
|
||||
#[test]
|
||||
fn a_due_date_does_not_reorder_a_column_past_the_backlog() {
|
||||
for status in [
|
||||
Status::Committed,
|
||||
Status::Reviewing,
|
||||
Status::Done,
|
||||
Status::Discarded,
|
||||
] {
|
||||
let soon = TicketItem {
|
||||
due: "2026-09-01".to_string(),
|
||||
..listed("soon", 1, status, Some("2026-08-02 09:00:00"))
|
||||
};
|
||||
let items = vec![
|
||||
soon,
|
||||
listed("later", 1, status, Some("2026-08-01 09:00:00")),
|
||||
];
|
||||
|
||||
let expected = match status {
|
||||
Status::Done | Status::Discarded => ["soon", "later"],
|
||||
_ => ["later", "soon"],
|
||||
};
|
||||
assert_eq!(ordered(status, items), expected, "{status:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Committed and reviewing are queues: the head is what has waited longest, which is
|
||||
/// where the reader picks next from.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user