(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
@@ -199,3 +199,66 @@ fn add_file_has_uuid_prefix() {
|
||||
assert_eq!(parts[0].len(), 36);
|
||||
assert_eq!(parts[0].chars().filter(|c| c.is_ascii_hexdigit()).count(), 32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_writes_the_priority_field() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(&temp.path())
|
||||
.args(["add", "--title", "Urgent thing", "--priority", "1"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let files: Vec<_> = fs::read_dir(temp.child(".worklane").join("backlog"))
|
||||
.unwrap()
|
||||
.filter_map(|e| e.ok())
|
||||
.collect();
|
||||
let content = fs::read_to_string(files[0].path()).unwrap();
|
||||
assert!(content.contains("- **Priority**: 1"), "was {content:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_leaves_priority_unset_when_omitted() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(&temp.path())
|
||||
.args(["add", "--title", "Whenever"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let files: Vec<_> = fs::read_dir(temp.child(".worklane").join("backlog"))
|
||||
.unwrap()
|
||||
.filter_map(|e| e.ok())
|
||||
.collect();
|
||||
let content = fs::read_to_string(files[0].path()).unwrap();
|
||||
assert!(content.contains("- **Priority**: _Not set_"), "was {content:?}");
|
||||
}
|
||||
|
||||
/// Rejected at parse time, so no ticket is written at all.
|
||||
#[test]
|
||||
fn add_rejects_a_level_outside_the_range() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
// The `=` form, so a negative value reaches the validator instead of being
|
||||
// read as a flag.
|
||||
for bad in ["0", "6", "high", "-1"] {
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path())
|
||||
.args(["add", "--title", "Bad level", &format!("--priority={bad}")])
|
||||
.assert()
|
||||
.failure();
|
||||
|
||||
let stderr = String::from_utf8(cmd.assert().get_output().stderr.clone()).unwrap();
|
||||
assert!(stderr.contains("priority must be"), "for {bad}: {stderr}");
|
||||
}
|
||||
|
||||
let count = fs::read_dir(worklane.join("backlog")).unwrap().count();
|
||||
assert_eq!(count, 0, "a ticket was written despite a bad level");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user