(dca0b61) Add priority as a ticket field
Priority lived in tags, as p1 to p3, which ls could neither sort nor filter on, nothing validated, and a typo like P1 passed silently. ls sorted by title only, so a backlog of any size gave no ordering signal. Levels are 1 to 5 with 1 most urgent, matching what the tags meant. Omitting the flag leaves the field _Not set_, like Due and Owner: there is no implicit middle level, because a priority nobody chose is worse than none. clap rejects anything outside the range before a ticket is written. Priority parses to three states rather than two. A stored value outside the range is Invalid, kept distinct from Unset, so a typo cannot read as "no priority": it shows as ? and sorts just ahead of the unset tail. ls sorts on priority and falls back to the old title sort, and --priority filters, composing with the status filter in both the grouped and the filtered listing. TicketItem becomes a struct, since a sixth tuple field was past reading. Migrated the 31 tickets already carrying p1 to p3 tags: the level moves to the field and the tag is dropped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b7781a830c
commit
ddbd45e332
@@ -216,3 +216,61 @@ fn ls_survives_a_malformed_created_at() {
|
||||
// Unparseable, so the timestamp column is dropped rather than printed raw
|
||||
assert!(!stdout.contains("日本語"));
|
||||
}
|
||||
|
||||
fn create_ticket_with_priority(worklane_dir: &std::path::PathBuf, title: &str, priority: &str) {
|
||||
let slug: String = title.to_lowercase().replace(' ', "-");
|
||||
let body = format!(
|
||||
"# {}\n\n## Metadata\n\n- **ID**: 00000000-0000-0000-0000-00000000000{}\n\
|
||||
- **Priority**: {}\n- **Tags**: test\n- **Due**: _Not set_\n\
|
||||
- **Owner**: alice\n- **Status**: backlog\n",
|
||||
title,
|
||||
slug.len() % 10,
|
||||
priority
|
||||
);
|
||||
let filename = format!("0000000{}-0000-0000-0000-000000000001_{}.md", slug.len() % 10, slug);
|
||||
fs::write(worklane_dir.join("backlog").join(filename), body).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_sorts_by_priority_then_title() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
create_ticket_with_priority(&worklane, "Zebra urgent", "1");
|
||||
create_ticket_with_priority(&worklane, "Apple later", "4");
|
||||
create_ticket_with_priority(&worklane, "Middle one", "2");
|
||||
create_ticket(&worklane, "backlog", "No priority at all", "alice", "_Not set_");
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path()).arg("ls").arg("backlog");
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
|
||||
let at = |needle: &str| stdout.find(needle).unwrap_or_else(|| panic!("{needle} missing"));
|
||||
assert!(at("Zebra urgent") < at("Middle one"), "priority 1 must lead");
|
||||
assert!(at("Middle one") < at("Apple later"), "2 before 4");
|
||||
// Unset sorts last even though its title would come first alphabetically
|
||||
assert!(at("Apple later") < at("No priority at all"), "unset must trail");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_filters_by_priority_and_composes_with_status() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
create_ticket_with_priority(&worklane, "Urgent one", "1");
|
||||
create_ticket_with_priority(&worklane, "Lower one", "3");
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path())
|
||||
.args(["ls", "backlog", "--priority", "1"]);
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert!(stdout.contains("Urgent one"));
|
||||
assert!(!stdout.contains("Lower one"), "filter let a level 3 through");
|
||||
|
||||
// Same filter without a status, through the grouped listing
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path()).args(["ls", "--priority", "3"]);
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert!(stdout.contains("Lower one"));
|
||||
assert!(!stdout.contains("Urgent one"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user