cmd_mv spliced the metadata line by byte offset and wrote the field name as **-Status**, because the format string re-added the "- " prefix that the preceding slice already carried. parse_ticket_field could never read Status back, and the next move failed to find "- **Status**" so it silently skipped the rewrite, leaving the ticket in one status directory while its metadata claimed another. Replace the splicing with set_status_field, a line based rewrite that keeps every other line verbatim, inserts no stray newline, and errors when the Metadata section has no Status field. It also accepts the **-Status** spelling so tickets damaged by the old code are repaired as they move. The content is now computed before the rename, so a ticket without a Status field is never half-moved. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
434 lines
11 KiB
Rust
434 lines
11 KiB
Rust
use assert_cmd::Command;
|
|
use assert_fs::TempDir;
|
|
use assert_fs::fixture::{PathChild, PathCreateDir};
|
|
use std::fs;
|
|
use std::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()
|
|
}
|
|
|
|
fn create_ticket(
|
|
worklane_dir: &PathBuf,
|
|
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());
|
|
}
|