a6023e2 made the three stamps mutually exclusive: entering a status wrote its field and leaving removed it, so a finished ticket carried exactly one of the three and the journey behind it was invisible. A reader asking when this was filed, when it was picked up, when it went out for review and when it finished got one answer and three absences, and nothing could tell that committed had ever happened. So the removal rule is replaced by an accumulation rule. `mv` stamps the target's field on entry, re-entering restamps, and arriving anywhere removes the fields of every status *after* the target. That is one arrival rule off the flow order `Status::ALL` already holds, not a case per move, and it is also what a forward skip under `-f` wants: backlog straight to done stamps `Completed On` alone and leaves the stages it jumped unwritten rather than fabricated. A backward move truncates the journey at the target, so done back to reviewing drops `Completed On` and keeps the two before it, and anything back to backlog drops all three. Presence therefore changes meaning. A field no longer says the ticket sits in that status now, it says the ticket got that far and has not been sent back past it. `Status` is what says where it is. This is still not d4ce964's history log. These answer how far and when, once per stage; every status change, every owner and every tag along the way is the log's job. The placement a6023e2 chose already holds: the three sit directly after `Created At` in `METADATA_ORDER`, so a ticket that has walked the whole flow reads as one block of four timestamps in flow order ahead of Campaign and Status. Nothing but `mv` writes them, pinned by a test over `add`, `set`, `append` and `chown`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1147 lines
36 KiB
Rust
1147 lines
36 KiB
Rust
use assert_cmd::Command;
|
|
use assert_fs::TempDir;
|
|
use assert_fs::fixture::{PathChild, PathCreateDir};
|
|
use std::fs;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane");
|
|
|
|
fn setup_worklane(temp: &TempDir) -> PathBuf {
|
|
let worklane = temp.child(".worklane");
|
|
worklane.create_dir_all().unwrap();
|
|
|
|
for dir in ["backlog", "committed", "reviewing", "done"] {
|
|
worklane.child(dir).create_dir_all().unwrap();
|
|
}
|
|
|
|
worklane.path().to_path_buf()
|
|
}
|
|
|
|
/// Every metadata field a ticket has, positionally. The lint is right that the call
|
|
/// site reads as a wall of strings, and the fix is a struct with named fields, but
|
|
/// that is a change to thirteen call sites in this file alone and belongs in its own
|
|
/// commit rather than in a warning sweep.
|
|
#[allow(clippy::too_many_arguments)]
|
|
fn create_ticket(
|
|
worklane_dir: &Path,
|
|
status: &str,
|
|
title: &str,
|
|
description: &str,
|
|
id: &str,
|
|
owner: &str,
|
|
due: &str,
|
|
tags: &str,
|
|
) -> String {
|
|
let slug = title
|
|
.to_lowercase()
|
|
.chars()
|
|
.filter(|c| c.is_alphanumeric() || *c == ' ' || *c == '-' || *c == '_')
|
|
.map(|c| if c == ' ' { '-' } else { c })
|
|
.collect::<String>();
|
|
let filename = format!("{}_{}.md", id, slug);
|
|
let ticket_body = format!(
|
|
"# {}\n\
|
|
\n\
|
|
## Description\n\
|
|
{}\n\
|
|
\n\
|
|
## Acceptance Criteria\n\
|
|
- [ ] test\n\
|
|
\n\
|
|
## Implementation Plan\n\
|
|
- test\n\
|
|
\n\
|
|
## Metadata\n\
|
|
\n\
|
|
- **ID**: {}\n\
|
|
- **Tags**: {}\n\
|
|
- **Due**: {}\n\
|
|
- **Owner**: {}\n\
|
|
- **Status**: {}\n\
|
|
",
|
|
title, description, id, tags, due, owner, status
|
|
);
|
|
let path = worklane_dir.join(status).join(&filename);
|
|
fs::write(&path, ticket_body).unwrap();
|
|
filename
|
|
}
|
|
|
|
fn get_stdout(cmd: &mut Command) -> String {
|
|
let assert = cmd.assert();
|
|
String::from_utf8(assert.get_output().stdout.clone()).unwrap()
|
|
}
|
|
|
|
fn get_stderr(cmd: &mut Command) -> String {
|
|
let assert = cmd.assert();
|
|
String::from_utf8(assert.get_output().stderr.clone()).unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn mv_forwards_from_backlog_to_committed() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let id = "abc123def456789012345678901234567890";
|
|
let filename = create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"Task One",
|
|
"Move this ticket.",
|
|
id,
|
|
"alice",
|
|
"2026-12-31",
|
|
"test",
|
|
);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("committed");
|
|
|
|
let assert = cmd.assert();
|
|
let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
|
|
assert.success();
|
|
|
|
assert!(stdout.contains("Task One"));
|
|
assert!(stdout.contains("backlog"));
|
|
assert!(stdout.contains("committed"));
|
|
|
|
// Verify file moved
|
|
assert!(!worklane.join("backlog").join(&filename).exists());
|
|
assert!(worklane.join("committed").join(&filename).exists());
|
|
|
|
// Verify status updated
|
|
let content = fs::read_to_string(worklane.join("committed").join(&filename)).unwrap();
|
|
assert!(content.contains("- **Status**: committed"));
|
|
|
|
// No stray blank line inserted after the rewritten field
|
|
assert!(content.ends_with("- **Status**: committed\n"));
|
|
}
|
|
|
|
#[test]
|
|
fn mv_blocks_backward_move() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let id = "abc123def456789012345678901234567890";
|
|
create_ticket(
|
|
&worklane,
|
|
"committed",
|
|
"Committed Task",
|
|
"Should stay committed.",
|
|
id,
|
|
"bob",
|
|
"2026-11-15",
|
|
"test",
|
|
);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("backlog")
|
|
.assert()
|
|
.failure();
|
|
|
|
let stderr = get_stderr(&mut cmd);
|
|
assert!(stderr.contains("Cannot move backward"));
|
|
}
|
|
|
|
#[test]
|
|
fn mv_allows_backward_move_with_force() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let id = "abc123def456789012345678901234567890";
|
|
let filename = create_ticket(
|
|
&worklane,
|
|
"committed",
|
|
"Backward Move",
|
|
"Force backward.",
|
|
id,
|
|
"charlie",
|
|
"2026-10-01",
|
|
"test",
|
|
);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("backlog")
|
|
.arg("-f");
|
|
|
|
let assert = cmd.assert();
|
|
let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
|
|
assert.success();
|
|
|
|
assert!(stdout.contains("Backward Move"));
|
|
assert!(stdout.contains("backlog"));
|
|
assert!(worklane.join("backlog").join(&filename).exists());
|
|
}
|
|
|
|
#[test]
|
|
fn mv_blocks_nonsequential_forward_move() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let id = "abc123def456789012345678901234567890";
|
|
create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"Jump Task",
|
|
"Should not skip.",
|
|
id,
|
|
"dave",
|
|
"2026-09-01",
|
|
"test",
|
|
);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("done")
|
|
.assert()
|
|
.failure();
|
|
|
|
let stderr = get_stderr(&mut cmd);
|
|
assert!(stderr.contains("one stage forward"));
|
|
}
|
|
|
|
#[test]
|
|
fn mv_allows_skipping_stages_with_force() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let id = "abc123def456789012345678901234567890";
|
|
let filename = create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"Skip Task",
|
|
"Force jump.",
|
|
id,
|
|
"eve",
|
|
"2026-08-01",
|
|
"test",
|
|
);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("done")
|
|
.arg("-f")
|
|
.assert()
|
|
.success();
|
|
|
|
assert!(worklane.join("done").join(&filename).exists());
|
|
let content = fs::read_to_string(worklane.join("done").join(&filename)).unwrap();
|
|
assert!(content.contains("- **Status**: done"));
|
|
}
|
|
|
|
#[test]
|
|
fn mv_ignores_already_in_same_status() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let id = "abc123def456789012345678901234567890";
|
|
let filename = create_ticket(
|
|
&worklane,
|
|
"reviewing",
|
|
"Same Status",
|
|
"Already there.",
|
|
id,
|
|
"frank",
|
|
"2026-07-01",
|
|
"test",
|
|
);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("reviewing")
|
|
.assert()
|
|
.success();
|
|
|
|
let stdout = get_stdout(&mut cmd);
|
|
assert!(stdout.contains("already in"));
|
|
assert!(worklane.join("reviewing").join(&filename).exists());
|
|
}
|
|
|
|
/// A status is a value enum, so an unknown one is clap's to refuse: exit 2, the four
|
|
/// named, and the ticket untouched. The same bargain `--due` and `--priority` take, and
|
|
/// the reason `cmd_mv` no longer checks.
|
|
#[test]
|
|
fn mv_rejects_invalid_status() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let id = "abc123def456789012345678901234567890";
|
|
let filename = create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"Invalid Target",
|
|
"Bad status.",
|
|
id,
|
|
"grace",
|
|
"2026-06-01",
|
|
"test",
|
|
);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("invalid")
|
|
.assert()
|
|
.code(2);
|
|
|
|
let stderr = get_stderr(&mut cmd);
|
|
assert!(stderr.contains("invalid value 'invalid'"), "{stderr}");
|
|
for status in ["backlog", "committed", "reviewing", "done"] {
|
|
assert!(stderr.contains(status), "{status} is not offered: {stderr}");
|
|
}
|
|
assert!(
|
|
worklane.join("backlog").join(&filename).exists(),
|
|
"the ticket moved anyway"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn mv_uses_ticket_id_for_resolution() {
|
|
let temp = TempDir::new().unwrap();
|
|
let wl = setup_worklane(&temp);
|
|
|
|
let id = "abc123def456789012345678901234567890";
|
|
let filename = create_ticket(
|
|
&wl,
|
|
"backlog",
|
|
"ID Resolution",
|
|
"Use ID to find.",
|
|
id,
|
|
"hank",
|
|
"2026-05-01",
|
|
"test",
|
|
);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("committed");
|
|
|
|
let assert = cmd.assert();
|
|
let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
|
|
assert.success();
|
|
|
|
assert!(stdout.contains("ID Resolution"));
|
|
assert!(wl.join("committed").join(&filename).exists());
|
|
}
|
|
|
|
#[test]
|
|
fn mv_keeps_status_in_sync_across_consecutive_moves() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let id = "abc123def456789012345678901234567890";
|
|
let filename = create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"Two Hop",
|
|
"Moved twice.",
|
|
id,
|
|
"ida",
|
|
"2026-04-01",
|
|
"test",
|
|
);
|
|
|
|
for target in ["committed", "reviewing"] {
|
|
Command::cargo_bin(BIN_NAME)
|
|
.unwrap()
|
|
.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg(target)
|
|
.assert()
|
|
.success();
|
|
}
|
|
|
|
assert!(worklane.join("reviewing").join(&filename).exists());
|
|
|
|
// The second move must update the field too, not silently skip it
|
|
let content = fs::read_to_string(worklane.join("reviewing").join(&filename)).unwrap();
|
|
assert!(content.contains("- **Status**: reviewing"));
|
|
assert!(!content.contains("-Status"));
|
|
assert!(!content.contains("committed"));
|
|
}
|
|
|
|
#[test]
|
|
fn mv_repairs_legacy_status_field() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let filename = "abc123def456789012345678901234567890_legacy.md";
|
|
let path = worklane.join("committed").join(filename);
|
|
fs::write(
|
|
&path,
|
|
"# Legacy Ticket\n\
|
|
\n\
|
|
## Metadata\n\
|
|
\n\
|
|
- **ID**: abc123def456789012345678901234567890\n\
|
|
- **-Status**: committed\n",
|
|
)
|
|
.unwrap();
|
|
|
|
Command::cargo_bin(BIN_NAME)
|
|
.unwrap()
|
|
.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("reviewing")
|
|
.assert()
|
|
.success();
|
|
|
|
let content = fs::read_to_string(worklane.join("reviewing").join(filename)).unwrap();
|
|
assert!(content.contains("- **Status**: reviewing"));
|
|
assert!(!content.contains("-Status"));
|
|
}
|
|
|
|
#[test]
|
|
fn mv_fails_when_status_field_is_missing() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let filename = "abc123def456789012345678901234567890_no-status.md";
|
|
let path = worklane.join("backlog").join(filename);
|
|
fs::write(&path, "# No Status\n\n## Metadata\n\n- **Owner**: jack\n").unwrap();
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.arg("mv")
|
|
.arg("abc123def4567")
|
|
.arg("--status")
|
|
.arg("committed")
|
|
.assert()
|
|
.failure();
|
|
|
|
let stderr = get_stderr(&mut cmd);
|
|
assert!(stderr.contains("No Status"));
|
|
assert!(stderr.contains("has no Status field"));
|
|
|
|
// The ticket must not be half-moved
|
|
assert!(worklane.join("backlog").join(filename).exists());
|
|
assert!(!worklane.join("committed").join(filename).exists());
|
|
}
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
fn chmod(path: &std::path::Path, mode: u32) {
|
|
let mut perms = fs::metadata(path).unwrap().permissions();
|
|
perms.set_mode(mode);
|
|
fs::set_permissions(path, perms).unwrap();
|
|
}
|
|
|
|
fn md_files(dir: &std::path::Path) -> Vec<String> {
|
|
match fs::read_dir(dir) {
|
|
Ok(entries) => entries
|
|
.filter_map(|e| e.ok())
|
|
.map(|e| e.file_name().into_string().unwrap())
|
|
.filter(|name| name.ends_with(".md"))
|
|
.collect(),
|
|
Err(_) => vec![],
|
|
}
|
|
}
|
|
|
|
/// Nothing is staged in a status directory, so nothing can be left behind that the
|
|
/// listing would read as a ticket.
|
|
fn stray_files(worklane: &std::path::Path) -> Vec<String> {
|
|
let mut stray: Vec<String> = fs::read_dir(worklane)
|
|
.unwrap()
|
|
.filter_map(|e| e.ok())
|
|
.map(|e| e.file_name().into_string().unwrap())
|
|
.filter(|name| {
|
|
!["backlog", "committed", "reviewing", "done", "comments"].contains(&name.as_str())
|
|
})
|
|
.collect();
|
|
|
|
for dir in ["backlog", "committed", "reviewing", "done"] {
|
|
stray.extend(
|
|
fs::read_dir(worklane.join(dir))
|
|
.into_iter()
|
|
.flatten()
|
|
.filter_map(|e| e.ok())
|
|
.map(|e| e.file_name().into_string().unwrap())
|
|
.filter(|name| !name.ends_with(".md")),
|
|
);
|
|
}
|
|
|
|
stray
|
|
}
|
|
|
|
/// The bug this fixes. The old order renamed first and wrote second, so a write
|
|
/// that failed left the ticket in its new directory still claiming the old status.
|
|
/// A read-only ticket file is the cheapest way to make the write fail.
|
|
#[test]
|
|
fn mv_never_leaves_stale_content_in_the_target_directory() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let filename = create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"Read Only",
|
|
"A description.",
|
|
"abc123def456789012345678901234567890",
|
|
"alice",
|
|
"2026-12-31",
|
|
"test",
|
|
);
|
|
|
|
let source = worklane.join("backlog").join(&filename);
|
|
chmod(&source, 0o444);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.args(["mv", "abc123def4567", "--status", "committed"])
|
|
.assert()
|
|
.success();
|
|
|
|
// Wherever it ended up, its Status must agree with the directory it is in
|
|
let moved = worklane.join("committed").join(&filename);
|
|
assert!(moved.exists(), "ticket did not move");
|
|
let content = fs::read_to_string(&moved).unwrap();
|
|
assert!(content.contains("- **Status**: committed"), "stale status: {content:?}");
|
|
assert!(!content.contains("- **Status**: backlog"), "{content:?}");
|
|
|
|
assert_eq!(md_files(&worklane.join("backlog")).len(), 0);
|
|
assert_eq!(stray_files(&worklane), Vec::<String>::new());
|
|
}
|
|
|
|
/// The other criterion: one directory or the other, never both. An unwritable
|
|
/// target directory fails the move at the last step, which is the step that would
|
|
/// have to be reordered to break this.
|
|
#[test]
|
|
fn mv_leaves_the_ticket_in_one_place_when_the_move_fails() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let filename = create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"Blocked Move",
|
|
"A description.",
|
|
"abc123def456789012345678901234567890",
|
|
"alice",
|
|
"2026-12-31",
|
|
"test",
|
|
);
|
|
|
|
let target = worklane.join("committed");
|
|
chmod(&target, 0o555);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
let assert = cmd
|
|
.current_dir(temp.path())
|
|
.args(["mv", "abc123def4567", "--status", "committed"])
|
|
.assert()
|
|
.failure();
|
|
|
|
let stderr = String::from_utf8(assert.get_output().stderr.clone()).unwrap();
|
|
// Named, not a bare io error
|
|
assert!(stderr.contains("Blocked Move"), "{stderr}");
|
|
|
|
assert_eq!(
|
|
md_files(&worklane.join("backlog")),
|
|
vec![filename.clone()],
|
|
"the ticket left its own directory"
|
|
);
|
|
assert_eq!(md_files(&target).len(), 0, "the ticket is in both places");
|
|
assert_eq!(stray_files(&worklane), Vec::<String>::new());
|
|
|
|
// The documented worst case: still in its old directory, carrying a Status one
|
|
// move ahead because the content was written before the move was attempted.
|
|
let left = fs::read_to_string(worklane.join("backlog").join(&filename)).unwrap();
|
|
assert!(left.contains("- **Status**: committed"), "{left:?}");
|
|
|
|
// And the state is recoverable, because the directory is what decides the
|
|
// current status, so a retry moves it rather than refusing.
|
|
chmod(&target, 0o755);
|
|
|
|
let mut retry = Command::cargo_bin(BIN_NAME).unwrap();
|
|
retry
|
|
.current_dir(temp.path())
|
|
.args(["mv", "abc123def4567", "--status", "committed"])
|
|
.assert()
|
|
.success();
|
|
|
|
assert_eq!(md_files(&target), vec![filename]);
|
|
assert_eq!(md_files(&worklane.join("backlog")).len(), 0);
|
|
}
|
|
|
|
#[test]
|
|
fn mv_leaves_nothing_behind_on_success() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"Clean Move",
|
|
"A description.",
|
|
"abc123def456789012345678901234567890",
|
|
"alice",
|
|
"2026-12-31",
|
|
"test",
|
|
);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.args(["mv", "abc123def4567", "--status", "committed"])
|
|
.assert()
|
|
.success();
|
|
|
|
assert_eq!(stray_files(&worklane), Vec::<String>::new());
|
|
}
|
|
|
|
/// Duplicate titles are allowed, so the file cannot be located by title. It used to be,
|
|
/// and `mv <uuid-of-second>` moved the first ticket that shared its title.
|
|
#[test]
|
|
fn mv_moves_the_resolved_ticket_when_two_share_a_title() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
for uuid in [
|
|
"11111111-aaaa-bbbb-cccc-dddddddddddd",
|
|
"22222222-aaaa-bbbb-cccc-dddddddddddd",
|
|
] {
|
|
fs::write(
|
|
worklane.join("backlog").join(format!("{}_foo.md", uuid)),
|
|
format!("# Foo\n\n## Metadata\n\n- **ID**: {}\n- **Status**: backlog\n", uuid),
|
|
)
|
|
.unwrap();
|
|
}
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.args(["mv", "22222222", "--status", "committed"])
|
|
.assert()
|
|
.success();
|
|
|
|
assert_eq!(
|
|
md_files(&worklane.join("committed")),
|
|
vec!["22222222-aaaa-bbbb-cccc-dddddddddddd_foo.md".to_string()],
|
|
"the wrong ticket moved"
|
|
);
|
|
assert_eq!(
|
|
md_files(&worklane.join("backlog")),
|
|
vec!["11111111-aaaa-bbbb-cccc-dddddddddddd_foo.md".to_string()]
|
|
);
|
|
}
|
|
|
|
// --------------------------------------------------------------- blocked by --
|
|
|
|
/// A ticket waiting on another, and a second one for it to wait on. Returns the
|
|
/// filename of the gated ticket, whose relations the moves are then checked against.
|
|
fn create_gated_pair(worklane: &std::path::Path, temp: &TempDir, status: &str) -> String {
|
|
let filename = create_ticket(
|
|
worklane,
|
|
status,
|
|
"Gated Task",
|
|
"Waits on the blocker.",
|
|
"aaaa1111aaaa1111aaaa1111aaaa1111aaaa",
|
|
"alice",
|
|
"_Not set_",
|
|
"test",
|
|
);
|
|
create_ticket(
|
|
worklane,
|
|
"backlog",
|
|
"The Blocker",
|
|
"Nothing waits on this.",
|
|
"bbbb2222bbbb2222bbbb2222bbbb2222bbbb",
|
|
"bob",
|
|
"_Not set_",
|
|
"test",
|
|
);
|
|
|
|
// Through the command, so the fixture cannot store a relation in a shape the tool
|
|
// does not actually write.
|
|
Command::cargo_bin(BIN_NAME)
|
|
.unwrap()
|
|
.current_dir(temp.path())
|
|
.args(["relate", "aaaa1111", "--blocked-by", "bbbb2222"])
|
|
.assert()
|
|
.success();
|
|
|
|
filename
|
|
}
|
|
|
|
fn move_ticket(temp: &TempDir, ticket: &str, status: &str, force: bool) -> std::process::Output {
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.args(["mv", ticket, "--status", status]);
|
|
if force {
|
|
cmd.arg("-f");
|
|
}
|
|
|
|
cmd.assert().get_output().clone()
|
|
}
|
|
|
|
/// Refused, and nothing written: not the rename, not the Status field, not a stray
|
|
/// temp file. The blocker is named with its status, since that is what has to change.
|
|
#[test]
|
|
fn mv_refuses_a_move_while_a_blocker_is_open() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = create_gated_pair(&worklane, &temp, "backlog");
|
|
let before = fs::read_to_string(worklane.join("backlog").join(&filename)).unwrap();
|
|
|
|
let out = move_ticket(&temp, "aaaa1111", "committed", false);
|
|
assert!(!out.status.success());
|
|
|
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
|
assert!(stderr.contains("blocked by"), "{stderr}");
|
|
assert!(stderr.contains("The Blocker"), "{stderr}");
|
|
assert!(stderr.contains("backlog"), "{stderr}");
|
|
assert!(stderr.contains("--force"), "{stderr}");
|
|
|
|
assert!(worklane.join("backlog").join(&filename).exists());
|
|
assert_eq!(md_files(&worklane.join("committed")).len(), 0);
|
|
assert_eq!(
|
|
fs::read_to_string(worklane.join("backlog").join(&filename)).unwrap(),
|
|
before,
|
|
"a refused move rewrote the ticket"
|
|
);
|
|
assert_eq!(stray_files(&worklane), Vec::<String>::new());
|
|
}
|
|
|
|
/// Every open blocker, not the first: clearing the one the message happened to name
|
|
/// would leave the ticket blocked and the reader surprised.
|
|
#[test]
|
|
fn mv_names_every_open_blocker() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_gated_pair(&worklane, &temp, "backlog");
|
|
create_ticket(
|
|
&worklane,
|
|
"reviewing",
|
|
"The Second Blocker",
|
|
"Also not done.",
|
|
"cccc3333cccc3333cccc3333cccc3333cccc",
|
|
"bob",
|
|
"_Not set_",
|
|
"test",
|
|
);
|
|
|
|
Command::cargo_bin(BIN_NAME)
|
|
.unwrap()
|
|
.current_dir(temp.path())
|
|
.args(["relate", "aaaa1111", "--blocked-by", "cccc3333"])
|
|
.assert()
|
|
.success();
|
|
|
|
let out = move_ticket(&temp, "aaaa1111", "committed", false);
|
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
|
assert!(stderr.contains("The Blocker"), "{stderr}");
|
|
assert!(stderr.contains("The Second Blocker"), "{stderr}");
|
|
}
|
|
|
|
/// `-f` is where the deliberate overrides live, beside the backward and skipping moves.
|
|
#[test]
|
|
fn mv_moves_a_blocked_ticket_with_force() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = create_gated_pair(&worklane, &temp, "backlog");
|
|
|
|
let out = move_ticket(&temp, "aaaa1111", "committed", true);
|
|
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
|
assert!(worklane.join("committed").join(&filename).exists());
|
|
}
|
|
|
|
#[test]
|
|
fn mv_allows_the_move_once_the_blocker_is_done() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = create_gated_pair(&worklane, &temp, "backlog");
|
|
|
|
for status in ["committed", "reviewing", "done"] {
|
|
assert!(
|
|
move_ticket(&temp, "bbbb2222", status, false).status.success(),
|
|
"the blocker itself could not be moved to {status}"
|
|
);
|
|
}
|
|
|
|
let out = move_ticket(&temp, "aaaa1111", "committed", false);
|
|
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
|
assert!(worklane.join("committed").join(&filename).exists());
|
|
}
|
|
|
|
/// Every move, not only the one into committed. An open blocker is a reason not to
|
|
/// finish as much as a reason not to start.
|
|
#[test]
|
|
fn mv_checks_the_blockers_on_every_move() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = create_gated_pair(&worklane, &temp, "reviewing");
|
|
|
|
let out = move_ticket(&temp, "aaaa1111", "done", false);
|
|
assert!(!out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
|
assert!(worklane.join("reviewing").join(&filename).exists());
|
|
}
|
|
|
|
/// A move to the status the ticket is already in is not a move, so it is reported the
|
|
/// way it always was rather than refused.
|
|
#[test]
|
|
fn mv_does_not_check_the_blockers_on_a_no_op() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_gated_pair(&worklane, &temp, "backlog");
|
|
|
|
let out = move_ticket(&temp, "aaaa1111", "backlog", false);
|
|
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
|
assert!(String::from_utf8_lossy(&out.stdout).contains("already in"));
|
|
}
|
|
|
|
/// A dangling target is a bookkeeping fault, not a dependency. Refusing there would
|
|
/// wedge the ticket with no way out but `--force`.
|
|
#[test]
|
|
fn mv_warns_and_allows_when_a_blocker_is_not_on_the_board() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = create_gated_pair(&worklane, &temp, "backlog");
|
|
fs::remove_file(
|
|
worklane
|
|
.join("backlog")
|
|
.join("bbbb2222bbbb2222bbbb2222bbbb2222bbbb_the-blocker.md"),
|
|
)
|
|
.unwrap();
|
|
|
|
let out = move_ticket(&temp, "aaaa1111", "committed", false);
|
|
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
|
assert!(
|
|
String::from_utf8_lossy(&out.stderr).contains("not on the board"),
|
|
"{}",
|
|
String::from_utf8_lossy(&out.stderr)
|
|
);
|
|
assert!(worklane.join("committed").join(&filename).exists());
|
|
}
|
|
|
|
/// Only `blocked by` gates a move. The other two kinds are reference data.
|
|
#[test]
|
|
fn mv_ignores_the_kinds_that_are_not_blockers() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"Related Task",
|
|
"Points at an open ticket.",
|
|
"aaaa1111aaaa1111aaaa1111aaaa1111aaaa",
|
|
"alice",
|
|
"_Not set_",
|
|
"test",
|
|
);
|
|
create_ticket(
|
|
&worklane,
|
|
"backlog",
|
|
"The Other",
|
|
"Still open.",
|
|
"bbbb2222bbbb2222bbbb2222bbbb2222bbbb",
|
|
"bob",
|
|
"_Not set_",
|
|
"test",
|
|
);
|
|
|
|
Command::cargo_bin(BIN_NAME)
|
|
.unwrap()
|
|
.current_dir(temp.path())
|
|
.args([
|
|
"relate",
|
|
"aaaa1111",
|
|
"--regression-of",
|
|
"bbbb2222",
|
|
"--relates-to",
|
|
"bbbb2222",
|
|
])
|
|
.assert()
|
|
.success();
|
|
|
|
let out = move_ticket(&temp, "aaaa1111", "committed", false);
|
|
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 added to the ones
|
|
/// already there: walking the flow leaves the whole journey on the ticket.
|
|
#[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");
|
|
|
|
// The fixture predates Created At as well as the stamps, and the four reading as
|
|
// one block is the point, so it is seeded rather than asserted around.
|
|
let path = worklane.join("backlog").join(&filename);
|
|
let seeded = fs::read_to_string(&path)
|
|
.unwrap()
|
|
.replace("- **Status**:", "- **Created At**: 2026-08-01 09:00:00\n- **Status**:");
|
|
fs::write(&path, seeded).unwrap();
|
|
|
|
let mut carried: Vec<&str> = Vec::new();
|
|
|
|
for (status, stamp) in [
|
|
("committed", "Committed On"),
|
|
("reviewing", "Submitted On"),
|
|
("done", "Completed On"),
|
|
] {
|
|
let out = move_ticket(&temp, "cccc3333", status, false);
|
|
assert!(out.status.success(), "{:?}", out);
|
|
carried.push(stamp);
|
|
|
|
let content = ticket_at(&worklane, status, &filename);
|
|
|
|
for stamp in &carried {
|
|
let value = field(&content, stamp)
|
|
.unwrap_or_else(|| panic!("no {stamp} after moving to {status}: {content}"));
|
|
assert!(is_timestamp(&value), "{stamp} reads '{value}'");
|
|
}
|
|
}
|
|
|
|
// The four side by side and in flow order, which is what a reader asking when this
|
|
// was filed, picked up, handed over and finished gets one answer each from.
|
|
let content = ticket_at(&worklane, "done", &filename);
|
|
let block: Vec<&str> = content
|
|
.lines()
|
|
.filter_map(|line| line.strip_prefix("- **"))
|
|
.filter_map(|line| line.split("**:").next())
|
|
.skip_while(|name| *name != "Created At")
|
|
.collect();
|
|
|
|
assert_eq!(
|
|
block,
|
|
[
|
|
"Created At",
|
|
"Committed On",
|
|
"Submitted On",
|
|
"Completed On",
|
|
"Status"
|
|
],
|
|
"{content}"
|
|
);
|
|
}
|
|
|
|
/// Arrival clears what comes after it and nothing before, so a ticket sent back out of
|
|
/// done keeps the stages it did get through.
|
|
#[test]
|
|
fn mv_removes_the_stamps_of_the_statuses_after_the_one_it_enters() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = stamped_ticket(&worklane, "backlog");
|
|
|
|
for status in ["committed", "reviewing", "done"] {
|
|
move_ticket(&temp, "cccc3333", status, false);
|
|
}
|
|
|
|
move_ticket(&temp, "cccc3333", "reviewing", true);
|
|
|
|
let content = ticket_at(&worklane, "reviewing", &filename);
|
|
assert_eq!(field(&content, "Completed On"), None, "{content}");
|
|
assert!(field(&content, "Committed On").is_some(), "{content}");
|
|
assert!(field(&content, "Submitted On").is_some(), "{content}");
|
|
}
|
|
|
|
/// Backlog has no stamp of its own and every status follows it, 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_back_to_backlog_removes_all_three_stamps() {
|
|
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}");
|
|
}
|
|
}
|
|
|
|
/// A skip stamps where it lands and leaves the stages it jumped unwritten: an absent
|
|
/// field says the ticket never got that far, and inventing one would say it did.
|
|
#[test]
|
|
fn mv_skipping_forward_stamps_only_the_target() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = stamped_ticket(&worklane, "backlog");
|
|
|
|
move_ticket(&temp, "cccc3333", "done", true);
|
|
|
|
let content = ticket_at(&worklane, "done", &filename);
|
|
assert!(field(&content, "Completed On").is_some(), "{content}");
|
|
assert_eq!(field(&content, "Committed On"), None, "{content}");
|
|
assert_eq!(field(&content, "Submitted On"), None, "{content}");
|
|
}
|
|
|
|
/// The three are `mv`'s alone. Nothing that edits a ticket by hand offers a way to
|
|
/// write one or take one away, so a stamp is always the record of a real move. Pinned
|
|
/// so the omission stays a decision rather than becoming an oversight somebody fills in.
|
|
#[test]
|
|
fn no_other_command_can_write_or_clear_a_stamp() {
|
|
let temp = TempDir::new().unwrap();
|
|
setup_worklane(&temp);
|
|
|
|
for command in ["add", "set", "append", "chown"] {
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path()).args([command, "--help"]);
|
|
let out = cmd.assert().get_output().clone();
|
|
let help = String::from_utf8_lossy(&out.stdout).to_lowercase();
|
|
|
|
for flag in ["committed-on", "submitted-on", "completed-on", "stamp"] {
|
|
assert!(!help.contains(flag), "{command} --help names {flag}: {help}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 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);
|
|
}
|