`cargo clippy --all-targets` was reporting 96 warnings, 14 of them in the binary. It is now clean from a cold cache, and the 211 tests still pass. `clippy --fix` took the mechanical ones: needless borrows, `map_or` that is `is_some_and`, `push_str` of a single character, manual `split_once`, and `&PathBuf` parameters in the test fixtures. It also moved the `handlers.rs` test module to the end of the file, which is what `items_after_test_module` was pointing at. Three by hand. `cmd_add` took nine parameters threaded from `main`, and now takes `AddArgs`, which is how `set`, `append` and `check` already pass theirs; the handler destructures it so the body reads as before, and `add --help` is unchanged. The collapsed `if` in `content_trim` needed reindenting, since `--fix` left its body at the old depth. And the two `split_once` rewrites read as `.split_once(..).map(|(_, value)| value)` rather than clippy's `.map(|x| x.1)`. The two eight-argument `create_ticket` test fixtures keep an `allow(too_many_arguments)` carrying the reason: the lint is right that twenty-five positional call sites read as a wall of strings, but replacing them with a named-field struct is a refactor and not a warning sweep. a34a316 tracks it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
418 lines
13 KiB
Rust
418 lines
13 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");
|
|
const UUID: &str = "475534a3-8a0d-45cb-9a97-39c251dd8e39";
|
|
|
|
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()
|
|
}
|
|
|
|
/// A fully populated ticket, with one criterion already ticked and a section the tool
|
|
/// knows nothing about, so every test can check both survive.
|
|
fn create_ticket(worklane: &Path) -> String {
|
|
let filename = format!("{}_original-title.md", UUID);
|
|
fs::write(
|
|
worklane.join("backlog").join(&filename),
|
|
format!(
|
|
"# Original title\n\
|
|
\n\
|
|
## Description\n\
|
|
First paragraph.\n\
|
|
\n\
|
|
Second paragraph.\n\
|
|
\n\
|
|
## Acceptance Criteria\n\
|
|
- [x] Crit one\n\
|
|
- [ ] Crit two\n\
|
|
\n\
|
|
## Implementation Plan\n\
|
|
1. Step one\n\
|
|
2. Step two\n\
|
|
\n\
|
|
## Notes\n\
|
|
A handwritten note the tool knows nothing about.\n\
|
|
\n\
|
|
## Metadata\n\
|
|
\n\
|
|
- **ID**: {}\n\
|
|
- **Priority**: 3\n\
|
|
- **Tags**: alpha\n\
|
|
- **Due**: 2026-09-01\n\
|
|
- **Owner**: alice\n\
|
|
- **Created At**: 2026-08-21 02:10:17\n\
|
|
- **Status**: backlog\n",
|
|
UUID
|
|
),
|
|
)
|
|
.unwrap();
|
|
filename
|
|
}
|
|
|
|
fn run(temp: &TempDir, args: &[&str]) -> std::process::Output {
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path()).args(args);
|
|
cmd.assert().get_output().clone()
|
|
}
|
|
|
|
fn ticket(worklane: &Path) -> String {
|
|
let entry = fs::read_dir(worklane.join("backlog"))
|
|
.unwrap()
|
|
.filter_map(|e| e.ok())
|
|
.find(|e| e.file_name().to_string_lossy().ends_with(".md"))
|
|
.expect("no ticket file");
|
|
fs::read_to_string(entry.path()).unwrap()
|
|
}
|
|
|
|
fn stray_files(worklane: &Path) -> 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()
|
|
}
|
|
|
|
#[test]
|
|
fn set_replaces_each_field_it_is_given() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
let out = run(
|
|
&temp,
|
|
&[
|
|
"set", UUID,
|
|
"--description", "Only paragraph.",
|
|
"--acceptance", "New crit",
|
|
"--plan", "New step",
|
|
"--tags", "beta,gamma",
|
|
"--due", "2026-12-31",
|
|
"--priority", "1",
|
|
],
|
|
);
|
|
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
|
|
|
let content = ticket(&worklane);
|
|
assert!(content.contains("## Description\nOnly paragraph.\n"), "{content}");
|
|
assert!(content.contains("## Acceptance Criteria\n- [ ] New crit\n"), "{content}");
|
|
assert!(content.contains("## Implementation Plan\n1. New step\n"), "{content}");
|
|
assert!(content.contains("- **Tags**: beta,gamma"), "{content}");
|
|
assert!(content.contains("- **Due**: 2026-12-31"), "{content}");
|
|
assert!(content.contains("- **Priority**: 1"), "{content}");
|
|
|
|
// The fields it was not given are untouched
|
|
assert!(content.contains("- **Owner**: alice"), "{content}");
|
|
assert!(content.contains("- **Status**: backlog"), "{content}");
|
|
}
|
|
|
|
/// The criterion is ticked in the fixture, so an unrelated edit must leave it ticked.
|
|
#[test]
|
|
fn set_leaves_a_ticked_criterion_and_an_unknown_section_alone() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
run(&temp, &["set", UUID, "--due", "2026-12-31"]);
|
|
|
|
let content = ticket(&worklane);
|
|
assert!(content.contains("- [x] Crit one"), "the tick was lost: {content}");
|
|
assert!(
|
|
content.contains("## Notes\nA handwritten note the tool knows nothing about.\n"),
|
|
"the unknown section was lost: {content}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn set_renames_the_file_for_a_new_title_and_keeps_the_uuid() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
run(&temp, &["set", UUID, "--title", "A brand new title"]);
|
|
|
|
let names: Vec<String> = fs::read_dir(worklane.join("backlog"))
|
|
.unwrap()
|
|
.filter_map(|e| e.ok())
|
|
.map(|e| e.file_name().into_string().unwrap())
|
|
.collect();
|
|
assert_eq!(names, vec![format!("{}_a-brand-new-title.md", UUID)]);
|
|
assert!(ticket(&worklane).starts_with("# A brand new title\n"));
|
|
|
|
// And the renamed ticket is still reachable, by the new title and by the uuid
|
|
for search in ["brand new", "475534a3"] {
|
|
let out = run(&temp, &["show", search]);
|
|
assert!(out.status.success(), "{search} did not resolve");
|
|
assert!(String::from_utf8_lossy(&out.stdout).contains("A brand new title"));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn set_reports_no_change_and_leaves_the_file_alone() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
let before = ticket(&worklane);
|
|
|
|
let out = run(&temp, &["set", UUID, "--due", "2026-09-01", "--priority", "3"]);
|
|
assert!(out.status.success());
|
|
assert!(
|
|
String::from_utf8_lossy(&out.stdout).contains("No changes"),
|
|
"{:?}",
|
|
String::from_utf8_lossy(&out.stdout)
|
|
);
|
|
assert_eq!(ticket(&worklane), before, "the file was rewritten anyway");
|
|
}
|
|
|
|
/// Only the field that actually differs is claimed, so the report cannot overstate.
|
|
#[test]
|
|
fn set_reports_only_the_fields_that_changed() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
let out = run(&temp, &["set", UUID, "--due", "2026-09-01", "--priority", "5"]);
|
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
|
|
|
assert!(stdout.contains("priority"), "{stdout:?}");
|
|
assert!(!stdout.contains("due"), "{stdout:?}");
|
|
}
|
|
|
|
/// An empty scalar looks like a way to clear a field, and clearing is not supported.
|
|
#[test]
|
|
fn set_refuses_an_empty_scalar_as_a_usage_error() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
let before = ticket(&worklane);
|
|
|
|
for flag in ["--title", "--due", "--tags"] {
|
|
let out = run(&temp, &["set", UUID, flag, ""]);
|
|
assert_eq!(out.status.code(), Some(2), "{flag} was accepted");
|
|
assert!(
|
|
String::from_utf8_lossy(&out.stderr).contains("clearing a field is not supported"),
|
|
"{flag}: {:?}",
|
|
String::from_utf8_lossy(&out.stderr)
|
|
);
|
|
}
|
|
|
|
assert_eq!(ticket(&worklane), before);
|
|
}
|
|
|
|
/// An empty value is a paragraph break for a section, so an all-blank one is a
|
|
/// clearing attempt rather than a break.
|
|
#[test]
|
|
fn set_refuses_to_clear_a_section() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
let before = ticket(&worklane);
|
|
|
|
let out = run(&temp, &["set", UUID, "--description", ""]);
|
|
assert_eq!(out.status.code(), Some(1));
|
|
assert!(
|
|
String::from_utf8_lossy(&out.stderr).contains("clearing is not supported"),
|
|
"{:?}",
|
|
String::from_utf8_lossy(&out.stderr)
|
|
);
|
|
assert_eq!(ticket(&worklane), before);
|
|
}
|
|
|
|
/// A bare `set <ticket>` would otherwise be a silent no-op.
|
|
#[test]
|
|
fn set_requires_at_least_one_field() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
let out = run(&temp, &["set", UUID]);
|
|
assert_eq!(out.status.code(), Some(2));
|
|
}
|
|
|
|
/// Interior blanks are paragraph breaks, per 4c516e6, so they have to reach the file.
|
|
#[test]
|
|
fn set_keeps_a_paragraph_break_in_a_replaced_description() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
run(
|
|
&temp,
|
|
&["set", UUID, "-d", "One.", "-d", "", "-d", "Two."],
|
|
);
|
|
|
|
assert!(
|
|
ticket(&worklane).contains("## Description\nOne.\n\nTwo.\n\n## Acceptance"),
|
|
"{}",
|
|
ticket(&worklane)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn set_accepts_prose_that_begins_with_a_hyphen() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
let out = run(
|
|
&temp,
|
|
&["set", UUID, "-a", "--print should be supported", "-t", "-t is the title flag"],
|
|
);
|
|
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
|
|
|
let content = ticket(&worklane);
|
|
assert!(content.contains("- [ ] --print should be supported"), "{content}");
|
|
assert!(content.starts_with("# -t is the title flag\n"), "{content}");
|
|
}
|
|
|
|
#[test]
|
|
fn set_leaves_nothing_behind() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
run(&temp, &["set", UUID, "--due", "2026-12-31"]);
|
|
assert_eq!(stray_files(&worklane), Vec::<String>::new());
|
|
}
|
|
|
|
#[test]
|
|
fn append_adds_a_paragraph_items_and_numbered_steps() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
let out = run(
|
|
&temp,
|
|
&[
|
|
"append", UUID,
|
|
"-d", "A third paragraph.",
|
|
"-a", "Crit three",
|
|
"-a", "Crit four",
|
|
"-p", "Step three",
|
|
],
|
|
);
|
|
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
|
|
|
let content = ticket(&worklane);
|
|
assert!(
|
|
content.contains("Second paragraph.\n\nA third paragraph.\n"),
|
|
"no paragraph break: {content}"
|
|
);
|
|
assert!(
|
|
content.contains("- [x] Crit one\n- [ ] Crit two\n- [ ] Crit three\n- [ ] Crit four\n"),
|
|
"{content}"
|
|
);
|
|
// Numbered on from the last step, and the steps above are untouched
|
|
assert!(
|
|
content.contains("1. Step one\n2. Step two\n3. Step three\n"),
|
|
"{content}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn append_replaces_an_empty_section_rather_than_following_its_placeholder() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let mut add = Command::cargo_bin(BIN_NAME).unwrap();
|
|
add.current_dir(temp.path())
|
|
.args(["add", "--title", "Bare ticket"])
|
|
.assert()
|
|
.success();
|
|
|
|
let uuid = fs::read_dir(worklane.join("backlog"))
|
|
.unwrap()
|
|
.filter_map(|e| e.ok())
|
|
.map(|e| e.file_name().into_string().unwrap())
|
|
.next()
|
|
.map(|name| name.split('_').next().unwrap().to_string())
|
|
.unwrap();
|
|
|
|
run(
|
|
&temp,
|
|
&["append", &uuid, "-d", "A description arrives late.", "-a", "First crit", "-p", "First step"],
|
|
);
|
|
|
|
let content = ticket(&worklane);
|
|
assert!(!content.contains("_No description provided._"), "{content}");
|
|
assert!(!content.contains("_No acceptance criteria provided._"), "{content}");
|
|
assert!(!content.contains("_No implementation plan provided._"), "{content}");
|
|
assert!(content.contains("## Description\nA description arrives late.\n"), "{content}");
|
|
assert!(content.contains("## Implementation Plan\n1. First step\n"), "{content}");
|
|
}
|
|
|
|
#[test]
|
|
fn append_leaves_a_ticked_criterion_and_an_unknown_section_alone() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
run(&temp, &["append", UUID, "-a", "Crit three"]);
|
|
|
|
let content = ticket(&worklane);
|
|
assert!(content.contains("- [x] Crit one"), "{content}");
|
|
assert!(
|
|
content.contains("## Notes\nA handwritten note the tool knows nothing about.\n"),
|
|
"{content}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn append_refuses_when_every_value_is_blank() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
let before = ticket(&worklane);
|
|
|
|
let out = run(&temp, &["append", UUID, "-a", " "]);
|
|
assert_eq!(out.status.code(), Some(1));
|
|
assert!(
|
|
String::from_utf8_lossy(&out.stderr).contains("Nothing to append"),
|
|
"{:?}",
|
|
String::from_utf8_lossy(&out.stderr)
|
|
);
|
|
assert_eq!(ticket(&worklane), before);
|
|
}
|
|
|
|
#[test]
|
|
fn append_requires_at_least_one_section() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
assert_eq!(run(&temp, &["append", UUID]).status.code(), Some(2));
|
|
}
|
|
|
|
/// Owner belongs to chown and status to mv, so neither command offers them.
|
|
#[test]
|
|
fn neither_command_can_write_owner_or_status() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
for args in [
|
|
vec!["set", UUID, "--owner", "bob"],
|
|
vec!["set", UUID, "--status", "committed"],
|
|
vec!["append", UUID, "--owner", "bob"],
|
|
] {
|
|
let out = run(&temp, &args);
|
|
assert_eq!(out.status.code(), Some(2), "{args:?} was accepted");
|
|
}
|
|
|
|
let content = ticket(&worklane);
|
|
assert!(content.contains("- **Owner**: alice"));
|
|
assert!(content.contains("- **Status**: backlog"));
|
|
}
|