(a6023e2) Stamp the time a ticket entered its status, and bump to 0.17.1

mv writes Committed On, Submitted On or Completed On for the status it
enters, so the board answers how long a ticket has been where it is
without guessing from file mtimes.

The three are mutually exclusive: entering stamps, leaving removes and
re-entering restamps, so a backward move under -f leaves no stale
Completed On behind. These fields are current state, like Status itself;
the trail of how the ticket got there belongs to the history log.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-08-22 20:31:53 +02:00
co-authored by Claude Opus 5
parent 373ba519b3
commit 139c9b012f
9 changed files with 454 additions and 8 deletions
+170
View File
@@ -888,3 +888,173 @@ fn mv_ignores_the_kinds_that_are_not_blockers() {
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
assert!(worklane.join("committed").join(&filename).exists());
}
/// The value of a metadata field, or nothing when the ticket does not carry it.
fn field(content: &str, name: &str) -> Option<String> {
let prefix = format!("- **{}**: ", name);
content
.lines()
.find_map(|line| line.strip_prefix(prefix.as_str()))
.map(str::to_string)
}
/// `%Y-%m-%d %H:%M:%S`, checked by shape. A test cannot pin the clock, so what it can
/// assert is that the stamp carries the same format `Created At` does.
fn is_timestamp(value: &str) -> bool {
value.len() == 19
&& value.chars().enumerate().all(|(index, c)| match index {
4 | 7 => c == '-',
10 => c == ' ',
13 | 16 => c == ':',
_ => c.is_ascii_digit(),
})
}
fn stamped_ticket(worklane: &Path, status: &str) -> String {
create_ticket(
worklane,
status,
"Stamped Task",
"Carries the stamps.",
"cccc3333cccc3333cccc3333cccc3333cccc",
"alice",
"_Not set_",
"test",
)
}
fn ticket_at(worklane: &Path, status: &str, filename: &str) -> String {
fs::read_to_string(worklane.join(status).join(filename)).unwrap()
}
/// One field per status, written with the time of the move, and only the current one:
/// the stamps are where the ticket is now, not the trail of how it got there.
#[test]
fn mv_stamps_the_field_of_the_status_it_enters() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = stamped_ticket(&worklane, "backlog");
for (status, stamp, cleared) in [
("committed", "Committed On", "Submitted On"),
("reviewing", "Submitted On", "Committed On"),
("done", "Completed On", "Submitted On"),
] {
let out = move_ticket(&temp, "cccc3333", status, false);
assert!(out.status.success(), "{:?}", out);
let content = ticket_at(&worklane, status, &filename);
let value = field(&content, stamp)
.unwrap_or_else(|| panic!("no {stamp} after moving to {status}: {content}"));
assert!(is_timestamp(&value), "{stamp} reads '{value}'");
assert_eq!(field(&content, cleared), None, "{content}");
}
}
/// Backlog has no stamp of its own, so a ticket forced back to it carries none at all
/// rather than a Completed On for work that has been undone.
#[test]
fn mv_removes_the_stamp_of_the_status_it_leaves() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = stamped_ticket(&worklane, "backlog");
move_ticket(&temp, "cccc3333", "done", true);
let done = ticket_at(&worklane, "done", &filename);
assert!(field(&done, "Completed On").is_some(), "{done}");
move_ticket(&temp, "cccc3333", "backlog", true);
let content = ticket_at(&worklane, "backlog", &filename);
for stamp in ["Committed On", "Submitted On", "Completed On"] {
assert_eq!(field(&content, stamp), None, "{content}");
}
}
/// Re-entry is the time of the move that brought the ticket back, not the first one.
#[test]
fn mv_restamps_a_status_the_ticket_is_re_entering() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = stamped_ticket(&worklane, "committed");
// Hand-written so the earlier value is old enough to tell from the move's own time,
// which two moves in the same second would not be.
let path = worklane.join("committed").join(&filename);
let seeded = fs::read_to_string(&path)
.unwrap()
.replace("- **Status**:", "- **Committed On**: 2020-01-01 00:00:00\n- **Status**:");
fs::write(&path, seeded).unwrap();
move_ticket(&temp, "cccc3333", "backlog", true);
move_ticket(&temp, "cccc3333", "committed", false);
let content = ticket_at(&worklane, "committed", &filename);
let value = field(&content, "Committed On").expect(&content);
assert!(is_timestamp(&value), "{value}");
assert_ne!(value, "2020-01-01 00:00:00");
assert_eq!(content.matches("**Committed On**:").count(), 1, "{content}");
}
/// The fixture predates the fields, as every ticket on a real board does, so the line
/// is inserted rather than rewritten. Against METADATA_ORDER, which keeps Status last.
#[test]
fn mv_inserts_the_stamp_before_the_status_field() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = stamped_ticket(&worklane, "backlog");
move_ticket(&temp, "cccc3333", "committed", false);
let content = ticket_at(&worklane, "committed", &filename);
let value = field(&content, "Committed On").expect(&content);
assert!(
content.contains(&format!(
"- **Owner**: alice\n- **Committed On**: {}\n- **Status**: committed\n",
value
)),
"{content}"
);
assert!(content.ends_with("- **Status**: committed\n"), "{content}");
}
/// Behind the refusals, all of them: a move that does not happen leaves the file exactly
/// as it was, stamp included.
#[test]
fn mv_writes_no_stamp_when_the_move_is_refused() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let backward = stamped_ticket(&worklane, "committed");
let before = ticket_at(&worklane, "committed", &backward);
let out = move_ticket(&temp, "cccc3333", "backlog", false);
assert!(!out.status.success());
assert_eq!(ticket_at(&worklane, "committed", &backward), before);
// The blocked ticket takes the other refusal, which sits after the no-op return.
let blocked = create_gated_pair(&worklane, &temp, "backlog");
let before = ticket_at(&worklane, "backlog", &blocked);
let out = move_ticket(&temp, "aaaa1111", "committed", false);
assert!(!out.status.success());
assert_eq!(ticket_at(&worklane, "backlog", &blocked), before);
}
/// A move to the status the ticket is already in returns before anything is written, so
/// it does not restamp either.
#[test]
fn mv_does_not_restamp_a_no_op_move() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = stamped_ticket(&worklane, "committed");
let before = ticket_at(&worklane, "committed", &filename);
let out = move_ticket(&temp, "cccc3333", "committed", false);
assert!(out.status.success());
assert_eq!(ticket_at(&worklane, "committed", &filename), before);
}