`relate` is the only writer of the section, the way `chown` is the only writer of Owner: a relation names a target that has to be resolved to a uuid first, so `set` and `append` are deliberately kept out of it. One flag per kind, so an unknown kind is a usage error rather than a line refused on the way back out. One direction is stored and the inverse is derived by a scan. `blocked by` goes on the gated ticket, whose move `mv` now refuses while the target is not done, naming every open blocker; `-f` bypasses it beside the backward and skipping moves. A target that is not on the board warns and allows the move. The rendered block is built outside `content_trim` and passed in, since half of it comes from other tickets. The section is created on demand rather than by `add`, so a ticket written before it existed gains it without being regenerated. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
881 lines
26 KiB
Rust
881 lines
26 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());
|
|
}
|
|
|
|
#[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()
|
|
.failure();
|
|
|
|
let stderr = get_stderr(&mut cmd);
|
|
assert!(stderr.contains("Invalid target status"));
|
|
}
|
|
|
|
#[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());
|
|
}
|