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>
746 lines
24 KiB
Rust
746 lines
24 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 is still a usage error, and the message now points at the flag that
|
|
/// does clear a field, so the two do not contradict each other.
|
|
///
|
|
/// `--title` is the exception, and says only that the value cannot be empty: a title has
|
|
/// no unset state to return to, so there is nothing to point at.
|
|
#[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, expected) in [
|
|
("--title", "value cannot be empty"),
|
|
("--due", "use --clear"),
|
|
("--tags", "use --clear"),
|
|
] {
|
|
let out = run(&temp, &["set", UUID, flag, ""]);
|
|
assert_eq!(out.status.code(), Some(2), "{flag} was accepted");
|
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
|
assert!(stderr.contains(expected), "{flag}: {stderr:?}");
|
|
assert!(
|
|
!stderr.contains("not supported"),
|
|
"{flag} still says clearing is unsupported: {stderr:?}"
|
|
);
|
|
}
|
|
|
|
assert_eq!(ticket(&worklane), before);
|
|
}
|
|
|
|
/// An empty value is a paragraph break for a section, so it cannot also mean empty the
|
|
/// section. The error names the flag that does, per section.
|
|
#[test]
|
|
fn set_refuses_an_empty_section_and_names_the_clear_for_it() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
let before = ticket(&worklane);
|
|
|
|
for (flag, expected) in [
|
|
("--description", "--clear description"),
|
|
("--acceptance", "--clear acceptance"),
|
|
("--plan", "--clear plan"),
|
|
] {
|
|
let out = run(&temp, &["set", UUID, flag, ""]);
|
|
assert_eq!(out.status.code(), Some(1), "{flag} was accepted");
|
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
|
assert!(stderr.contains(expected), "{flag}: {stderr:?}");
|
|
}
|
|
|
|
assert_eq!(ticket(&worklane), before);
|
|
}
|
|
|
|
/// Every field `--clear` reaches, in one call, back to what a ticket is born with.
|
|
#[test]
|
|
fn clear_returns_every_field_it_reaches_to_unset() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
let out = run(
|
|
&temp,
|
|
&[
|
|
"set",
|
|
UUID,
|
|
"--clear",
|
|
"due",
|
|
"--clear",
|
|
"tags",
|
|
"--clear",
|
|
"priority",
|
|
"--clear",
|
|
"description",
|
|
"--clear",
|
|
"acceptance",
|
|
"--clear",
|
|
"plan",
|
|
],
|
|
);
|
|
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
|
|
|
let content = ticket(&worklane);
|
|
assert!(content.contains("- **Due**: _Not set_"), "{content}");
|
|
assert!(content.contains("- **Tags**: _None_"), "{content}");
|
|
assert!(content.contains("- **Priority**: _Not set_"), "{content}");
|
|
assert!(
|
|
content.contains("## Description\n_No description provided._\n"),
|
|
"{content}"
|
|
);
|
|
assert!(
|
|
content.contains("## Acceptance Criteria\n_No acceptance criteria provided._\n"),
|
|
"{content}"
|
|
);
|
|
assert!(
|
|
content.contains("## Implementation Plan\n_No implementation plan provided._\n"),
|
|
"{content}"
|
|
);
|
|
|
|
// The placeholder goes in bare, not dressed as an item of the section it replaces.
|
|
assert!(!content.contains("- [ ] _No"), "{content}");
|
|
assert!(!content.contains("1. _No"), "{content}");
|
|
|
|
// What --clear cannot reach is untouched, the handwritten section included.
|
|
assert!(content.starts_with("# Original title\n"), "{content}");
|
|
assert!(content.contains("- **Owner**: alice"), "{content}");
|
|
assert!(content.contains("- **Status**: backlog"), "{content}");
|
|
assert!(
|
|
content.contains("## Notes\nA handwritten note the tool knows nothing about.\n"),
|
|
"{content}"
|
|
);
|
|
}
|
|
|
|
/// A cleared ticket and one that was never given the field have to read the same, or
|
|
/// clearing would be its own third state.
|
|
#[test]
|
|
fn a_cleared_ticket_reads_like_one_filed_without_the_fields() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
run(&temp, &["add", "--title", "Bare"]);
|
|
run(
|
|
&temp,
|
|
&[
|
|
"add",
|
|
"--title",
|
|
"Full",
|
|
"--description",
|
|
"A body.",
|
|
"--acceptance",
|
|
"One criterion",
|
|
"--plan",
|
|
"One step",
|
|
"--tags",
|
|
"alpha,beta",
|
|
"--due",
|
|
"2026-09-01",
|
|
"--priority",
|
|
"2",
|
|
],
|
|
);
|
|
|
|
let full = added(&worklane, "full");
|
|
let out = run(
|
|
&temp,
|
|
&[
|
|
"set",
|
|
&full.0,
|
|
"--clear",
|
|
"due",
|
|
"--clear",
|
|
"tags",
|
|
"--clear",
|
|
"priority",
|
|
"--clear",
|
|
"description",
|
|
"--clear",
|
|
"acceptance",
|
|
"--clear",
|
|
"plan",
|
|
],
|
|
);
|
|
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
|
|
|
let cleared = comparable(&fs::read_to_string(&full.1).unwrap());
|
|
let bare = comparable(&fs::read_to_string(&added(&worklane, "bare").1).unwrap());
|
|
assert_eq!(cleared, bare);
|
|
}
|
|
|
|
/// The uuid and the file of the one ticket whose slug matches, as `add` wrote it.
|
|
fn added(worklane: &Path, slug: &str) -> (String, PathBuf) {
|
|
let entry = fs::read_dir(worklane.join("backlog"))
|
|
.unwrap()
|
|
.filter_map(|e| e.ok())
|
|
.find(|e| e.file_name().to_string_lossy().ends_with(&format!("_{slug}.md")))
|
|
.unwrap_or_else(|| panic!("no ticket slugged {slug}"));
|
|
let name = entry.file_name().into_string().unwrap();
|
|
let uuid = name.split('_').next().unwrap().to_string();
|
|
(uuid, entry.path())
|
|
}
|
|
|
|
/// A ticket without the three lines that are different by definition: its title, its
|
|
/// uuid and the moment it was filed.
|
|
fn comparable(content: &str) -> String {
|
|
content
|
|
.lines()
|
|
.filter(|line| {
|
|
!line.starts_with("# ")
|
|
&& !line.contains("**ID**:")
|
|
&& !line.contains("**Created At**:")
|
|
})
|
|
.collect::<Vec<_>>()
|
|
.join("\n")
|
|
}
|
|
|
|
/// Nothing to take away is not a rewrite, per the same whole-file comparison a
|
|
/// replacement uses.
|
|
#[test]
|
|
fn clearing_a_field_that_is_already_unset_is_no_change() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
run(&temp, &["set", UUID, "--clear", "due", "--clear", "tags"]);
|
|
let before = ticket(&worklane);
|
|
|
|
let out = run(&temp, &["set", UUID, "--clear", "due", "--clear", "tags"]);
|
|
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");
|
|
}
|
|
|
|
/// Replaced and emptied are reported in those words, since a caller doing both in one
|
|
/// call cannot tell which happened to which field otherwise.
|
|
#[test]
|
|
fn clear_is_reported_apart_from_a_replacement() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
let out = run(&temp, &["set", UUID, "--priority", "1", "--clear", "due"]);
|
|
assert!(out.status.success());
|
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
|
assert!(stdout.contains("Updated priority on 'Original title'"), "{stdout:?}");
|
|
assert!(stdout.contains("Cleared due on 'Original title'"), "{stdout:?}");
|
|
}
|
|
|
|
/// Replacing and clearing one field in a single call is a contradiction, and answering
|
|
/// it by whichever was applied last would be a silent answer.
|
|
#[test]
|
|
fn clearing_and_replacing_the_same_field_is_refused() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
let before = ticket(&worklane);
|
|
|
|
for (flag, value, field) in [
|
|
("--due", "2026-12-31", "due"),
|
|
("--tags", "beta", "tags"),
|
|
("--priority", "1", "priority"),
|
|
("--acceptance", "A criterion", "acceptance"),
|
|
] {
|
|
let out = run(&temp, &["set", UUID, flag, value, "--clear", field]);
|
|
assert_eq!(out.status.code(), Some(1), "{flag} with --clear {field} was accepted");
|
|
assert!(
|
|
String::from_utf8_lossy(&out.stderr).contains("contradict each other"),
|
|
"{:?}",
|
|
String::from_utf8_lossy(&out.stderr)
|
|
);
|
|
}
|
|
|
|
assert_eq!(ticket(&worklane), before);
|
|
}
|
|
|
|
/// The fields no writer of `set` can reach are not reachable through `--clear` either,
|
|
/// and an unknown one is a usage error listing what is.
|
|
#[test]
|
|
fn clear_refuses_a_field_it_does_not_own() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
let before = ticket(&worklane);
|
|
|
|
for field in [
|
|
"owner",
|
|
"title",
|
|
"status",
|
|
"campaign",
|
|
"relations",
|
|
"nonsense",
|
|
] {
|
|
let out = run(&temp, &["set", UUID, "--clear", field]);
|
|
assert_eq!(out.status.code(), Some(2), "--clear {field} was accepted");
|
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
|
assert!(stderr.contains("possible values"), "{field}: {stderr:?}");
|
|
}
|
|
|
|
assert_eq!(ticket(&worklane), before);
|
|
}
|
|
|
|
/// `--clear` on its own satisfies the at-least-one-field rule, since it is a field
|
|
/// being written like any other.
|
|
#[test]
|
|
fn clear_alone_is_enough_of_a_field() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane);
|
|
|
|
let out = run(&temp, &["set", UUID, "--clear", "due"]);
|
|
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
|
assert!(ticket(&worklane).contains("- **Due**: _Not set_"));
|
|
}
|
|
|
|
/// 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"));
|
|
}
|
|
|
|
/// The same parser `add` uses, from one definition. Grooming a board sets dates through
|
|
/// `set`, so validating only the command that files a ticket would leave the path that
|
|
/// is actually used wide open.
|
|
#[test]
|
|
fn set_refuses_a_due_date_that_is_not_a_real_iso_date() {
|
|
for value in ["next friday", "2026-02-30", "2026-8-9"] {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = create_ticket(&worklane);
|
|
let before = fs::read_to_string(worklane.join("backlog").join(&filename)).unwrap();
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
let out = cmd
|
|
.current_dir(temp.path())
|
|
.args(["set", UUID])
|
|
.args(["--due", value])
|
|
.assert()
|
|
.failure()
|
|
.get_output()
|
|
.clone();
|
|
|
|
assert_eq!(out.status.code(), Some(2), "{value:?} was not a usage error");
|
|
assert_eq!(
|
|
fs::read_to_string(worklane.join("backlog").join(&filename)).unwrap(),
|
|
before,
|
|
"{value:?} changed the ticket anyway"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn set_stores_a_valid_due_date_unchanged() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
let filename = create_ticket(&worklane);
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path())
|
|
.args(["set", UUID])
|
|
.args(["--due", "2026-12-31"])
|
|
.assert()
|
|
.success();
|
|
|
|
let content = fs::read_to_string(worklane.join("backlog").join(&filename)).unwrap();
|
|
assert!(content.contains("- **Due**: 2026-12-31"), "{content}");
|
|
}
|