(7f772a7) Repair a Status field that lags its directory on mv, and bump to 0.32.6
This commit is contained in:
@@ -1145,6 +1145,94 @@ fn mv_does_not_restamp_a_no_op_move() {
|
||||
assert_eq!(ticket_at(&worklane, "committed", &filename), before);
|
||||
}
|
||||
|
||||
/// A ticket whose file sits in one status directory while its Status field says another
|
||||
/// is a hand-moved file or a partial restore. Moving it to the status it already sits in
|
||||
/// is the repair: the field is rewritten to agree with the directory and reported as a
|
||||
/// correction rather than refused as a no-op.
|
||||
#[test]
|
||||
fn mv_repairs_a_lagging_status_field_instead_of_refusing() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let filename = stamped_ticket(&worklane, "done");
|
||||
let drifted = ticket_at(&worklane, "done", &filename)
|
||||
.replace("- **Status**: done", "- **Status**: backlog");
|
||||
fs::write(worklane.join("done").join(&filename), &drifted).unwrap();
|
||||
|
||||
let out = move_ticket(&temp, "cccc3333", "done", false);
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
assert!(out.status.success(), "{stderr}");
|
||||
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(stdout.contains("Corrected Status field"), "{stdout}");
|
||||
assert!(stdout.contains("backlog"), "{stdout}");
|
||||
|
||||
// Not a move: nothing was relocated and only the field changed, byte for byte.
|
||||
assert!(worklane.join("done").join(&filename).exists());
|
||||
assert_eq!(md_files(&worklane.join("backlog")), Vec::<String>::new());
|
||||
assert_eq!(
|
||||
ticket_at(&worklane, "done", &filename),
|
||||
drifted.replace("- **Status**: backlog", "- **Status**: done")
|
||||
);
|
||||
}
|
||||
|
||||
/// The repair corrects bookkeeping rather than moving work, so it stamps nothing and
|
||||
/// logs nothing: an entry shaped like a transition would record a journey the ticket
|
||||
/// never took.
|
||||
#[test]
|
||||
fn a_repair_writes_no_stamp_and_no_history_entry() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let filename = stamped_ticket(&worklane, "backlog");
|
||||
|
||||
// A real move first, so the ticket carries the stamp and the log entry that a
|
||||
// repair has to leave alone.
|
||||
let out = move_ticket(&temp, "cccc3333", "committed", false);
|
||||
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
||||
let history = worklane
|
||||
.join("history")
|
||||
.join("cccc3333cccc3333cccc3333cccc3333cccc");
|
||||
assert_eq!(md_files(&history).len(), 1);
|
||||
|
||||
let content = ticket_at(&worklane, "committed", &filename);
|
||||
assert!(content.contains("Committed On"), "{content}");
|
||||
let drifted = content.replace("- **Status**: committed", "- **Status**: done");
|
||||
fs::write(worklane.join("committed").join(&filename), &drifted).unwrap();
|
||||
|
||||
let out = move_ticket(&temp, "cccc3333", "committed", false);
|
||||
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
||||
|
||||
let repaired = ticket_at(&worklane, "committed", &filename);
|
||||
assert!(repaired.contains("Committed On"), "{repaired}");
|
||||
assert!(!repaired.contains("Submitted On"), "{repaired}");
|
||||
assert_eq!(md_files(&history).len(), 1, "the repair logged an entry");
|
||||
}
|
||||
|
||||
/// The mirror drift, a field ahead of its directory from a crash mid-move, repairs the
|
||||
/// same way when the caller keeps the ticket where it sits rather than moving it on to
|
||||
/// where the field claims.
|
||||
#[test]
|
||||
fn mv_repairs_a_field_ahead_of_its_directory_too() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let filename = stamped_ticket(&worklane, "backlog");
|
||||
let drifted = ticket_at(&worklane, "backlog", &filename)
|
||||
.replace("- **Status**: backlog", "- **Status**: done");
|
||||
fs::write(worklane.join("backlog").join(&filename), &drifted).unwrap();
|
||||
|
||||
let out = move_ticket(&temp, "cccc3333", "backlog", false);
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
assert!(out.status.success(), "{stderr}");
|
||||
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(stdout.contains("Corrected Status field"), "{stdout}");
|
||||
assert!(worklane.join("backlog").join(&filename).exists());
|
||||
assert!(
|
||||
ticket_at(&worklane, "backlog", &filename).contains("- **Status**: backlog"),
|
||||
"{}",
|
||||
ticket_at(&worklane, "backlog", &filename)
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- discarded --
|
||||
|
||||
/// Discarding is not a stage of work, so it is reachable from wherever the ticket
|
||||
|
||||
Reference in New Issue
Block a user