Layout only, no behaviour and no wording. 161 hunks across 22 files, 98 of them rustfmt joining a call or a message onto the one line it fits on. The config it formats to, and how its four numbers were arrived at, is the commit before this one. Separate so that it is reviewable by not being read: nothing here is a decision, and every decision is next door. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1057 lines
32 KiB
Rust
1057 lines
32 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 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);
|
|
}
|