(a1a5d69) Add tags to a ticket with append --tags, keeping the ones it carries, and bump to 0.32.18
`set --tags` writes the whole field, so adding one tag to a ticket that
already carries some meant reading it first and retyping every one of
them. 30a2b34 wrote that down in the skill as the way to do it; this is
the flag that makes it unnecessary.
The merge is idempotent and ordered. A tag the ticket already carries is
reported as no change rather than added twice, which is the point of the
flag: the caller does not have to know what is there. A new one goes on
the end in the order it was given rather than sorting the field under
whoever last touched it. Values are split on commas the way the stored
field is, so `--tags "bug, tui"` names two tags and matches the two a
ticket carrying them already holds; without that the pair would land as
a single tag nothing can filter by and would not match itself on the
next call. `split_tags` is that rule, lifted out of `parse_tags` so the
argument and the field are separated by the same code.
It writes the same `Kind::Tags` entry `set --tags` writes, so `--actor`
and `--actor-from-git` come with it. Tags are logged wherever they move,
and the one command that adds to them without replacing them would
otherwise be the one tag change the log missed. The before and after are
read off the field rather than off the flag, so an append of `beta` onto
`alpha` reads as the pair and not as what the call asked for.
`non_empty` rather than the `clearable` that `set --tags` takes: that
message names `--clear`, and `append` has none, so it would send the
caller looking here for a flag that is `set`'s. A value that is only
separators reaches the handler and is refused there, in the words
`appended_items` refuses an all-blank section with. Emptying the field
stays `set --clear tags`.
`TAG_FLAGS` becomes pairs of command and flag, because `ls --tag` and
`append --tags` are spelled differently and one rule naming both options
would tell fish that each command accepts the other's. `add --tags` and
`set --tags` deliberately get no value rule and are recorded in the
test's `TAG_LIST_FLAGS` instead: they take the whole list, so the token
at the cursor is `bug,tui` and fish replaces a token entire, throwing
away what is already typed. The honesty test now walks `tag` and `tags`
both, so the next tag argument has to say which of the two it is.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b4534eb86d
commit
7470255a22
@@ -676,6 +676,140 @@ fn append_requires_at_least_one_section() {
|
||||
assert_eq!(run(&temp, &["append", UUID]).status.code(), Some(2));
|
||||
}
|
||||
|
||||
/// The reason the flag exists: `set --tags` writes the whole field, so adding one tag to
|
||||
/// a ticket that already carries some meant knowing and retyping every one of them.
|
||||
#[test]
|
||||
fn append_adds_a_tag_and_keeps_the_ones_already_there() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["append", UUID, "--tags", "beta"]);
|
||||
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
||||
|
||||
let content = ticket(&worklane);
|
||||
assert!(content.contains("- **Tags**: alpha, beta"), "{content}");
|
||||
// The sections and the other fields are as untouched as they are by any other append
|
||||
assert!(content.contains("- [x] Crit one\n- [ ] Crit two\n"), "{content}");
|
||||
assert!(content.contains("- **Priority**: 3"), "{content}");
|
||||
}
|
||||
|
||||
/// Idempotent on purpose: the caller of an append does not have to know what is there
|
||||
/// already, so naming a tag the ticket carries is reported as no change and writes
|
||||
/// nothing, the way an unchanged field is everywhere else.
|
||||
#[test]
|
||||
fn append_ignores_a_tag_the_ticket_already_carries() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
let before = ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["append", UUID, "--tags", "alpha"]);
|
||||
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
||||
assert!(
|
||||
String::from_utf8_lossy(&out.stdout).contains("No changes to"),
|
||||
"{:?}",
|
||||
String::from_utf8_lossy(&out.stdout)
|
||||
);
|
||||
assert_eq!(ticket(&worklane), before);
|
||||
|
||||
// And the one already there is not added a second time beside a new one
|
||||
run(&temp, &["append", UUID, "--tags", "alpha", "--tags", "beta"]);
|
||||
assert!(
|
||||
ticket(&worklane).contains("- **Tags**: alpha, beta"),
|
||||
"{}",
|
||||
ticket(&worklane)
|
||||
);
|
||||
}
|
||||
|
||||
/// Two spellings for the same call, because the stored field is comma separated too and
|
||||
/// `set --tags` takes that form on this very field: refusing it on the counterpart would
|
||||
/// be a trap. New tags land in the order they were given, after the ones already there.
|
||||
#[test]
|
||||
fn append_takes_several_tags_by_repeated_flag_or_by_comma() {
|
||||
for args in [
|
||||
vec!["append", UUID, "--tags", "bug", "--tags", "tui"],
|
||||
vec!["append", UUID, "--tags", "bug, tui"],
|
||||
vec!["append", UUID, "-g", "bug,tui"],
|
||||
] {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &args);
|
||||
assert!(
|
||||
out.status.success(),
|
||||
"{args:?}: {:?}",
|
||||
String::from_utf8_lossy(&out.stderr)
|
||||
);
|
||||
assert!(ticket(&worklane).contains("- **Tags**: alpha, bug, tui"), "{args:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A value that names no tag is refused rather than written, the way an all-blank section
|
||||
/// value is: `--tags ","` adds nothing, and writing the field back unchanged would report
|
||||
/// an append that never happened. Emptying the field is `set --clear tags`.
|
||||
#[test]
|
||||
fn append_refuses_a_tags_value_that_names_nothing() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
let before = ticket(&worklane);
|
||||
|
||||
// Empty at the parser, before the ticket is even resolved
|
||||
let empty = run(&temp, &["append", UUID, "--tags", ""]);
|
||||
assert_eq!(empty.status.code(), Some(2));
|
||||
assert!(
|
||||
String::from_utf8_lossy(&empty.stderr).contains("value cannot be empty"),
|
||||
"{:?}",
|
||||
String::from_utf8_lossy(&empty.stderr)
|
||||
);
|
||||
// The message must not name a `--clear` this command does not have
|
||||
assert!(
|
||||
!String::from_utf8_lossy(&empty.stderr).contains("use --clear"),
|
||||
"{:?}",
|
||||
String::from_utf8_lossy(&empty.stderr)
|
||||
);
|
||||
|
||||
// Separators only, which the parser cannot see is empty
|
||||
let blank = run(&temp, &["append", UUID, "--tags", ", ,"]);
|
||||
assert_eq!(blank.status.code(), Some(1));
|
||||
assert!(
|
||||
String::from_utf8_lossy(&blank.stderr).contains("Nothing to append to the tags"),
|
||||
"{:?}",
|
||||
String::from_utf8_lossy(&blank.stderr)
|
||||
);
|
||||
|
||||
assert_eq!(ticket(&worklane), before);
|
||||
}
|
||||
|
||||
/// A ticket with no tags starts the list rather than appending to the sentinel.
|
||||
#[test]
|
||||
fn append_writes_the_first_tag_over_the_unset_sentinel() {
|
||||
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", "Untagged"])
|
||||
.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, "--tags", "bug"]);
|
||||
|
||||
let content = ticket(&worklane);
|
||||
assert!(content.contains("- **Tags**: bug"), "{content}");
|
||||
assert!(!content.contains("_None_"), "{content}");
|
||||
}
|
||||
|
||||
/// Owner belongs to chown and status to mv, so neither command offers them.
|
||||
#[test]
|
||||
fn neither_command_can_write_owner_or_status() {
|
||||
|
||||
+45
-3
@@ -275,6 +275,36 @@ fn clearing_the_tags_writes_a_tags_entry() {
|
||||
assert!(entry.starts_with("**Tags**\nalpha → _None_\n"), "{entry:?}");
|
||||
}
|
||||
|
||||
/// Tags are logged wherever they change, so the command that adds to them logs the same
|
||||
/// entry the one that replaces them does. The values come off the field rather than off
|
||||
/// the flag, so the entry records where the field went and not what the call added: an
|
||||
/// append of `beta` onto `alpha` reads as the pair, not as `beta`.
|
||||
#[test]
|
||||
fn appending_a_tag_writes_a_tags_entry() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane, "backlog");
|
||||
|
||||
run(&temp, &["append", UUID, "--tags", "beta"]);
|
||||
|
||||
let entry = only_entry(&worklane, "tags");
|
||||
assert!(entry.starts_with("**Tags**\nalpha → alpha, beta\n"), "{entry:?}");
|
||||
}
|
||||
|
||||
/// The sections are not logged, and appending to one is not a tag change: an append that
|
||||
/// touches no tag writes nothing, so the log does not fill with the edits it deliberately
|
||||
/// leaves out.
|
||||
#[test]
|
||||
fn appending_to_a_section_writes_nothing() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane, "backlog");
|
||||
|
||||
run(&temp, &["append", UUID, "--acceptance", "One more criterion"]);
|
||||
|
||||
assert_eq!(entries(&worklane), vec![]);
|
||||
}
|
||||
|
||||
/// The entry names the campaign the way a reader knows it, the codename, not the uuid
|
||||
/// the field actually holds. A ticket never assigned starts from the sentinel an unset
|
||||
/// field reads as everywhere else.
|
||||
@@ -433,6 +463,7 @@ fn a_no_op_edit_writes_nothing() {
|
||||
vec!["mv", UUID, "--status", "backlog"],
|
||||
vec!["chown", "alice", UUID],
|
||||
vec!["set", UUID, "--tags", "alpha"],
|
||||
vec!["append", UUID, "--tags", "alpha"],
|
||||
] {
|
||||
let out = run(&temp, &args);
|
||||
assert!(
|
||||
@@ -577,10 +608,11 @@ fn the_actor_flag_names_the_writer_on_every_command_that_writes_one() {
|
||||
run(&temp, &["mv", UUID, "--status", "committed", "--actor", "opencode"]);
|
||||
run(&temp, &["chown", "bob", UUID, "--actor", "opencode"]);
|
||||
run(&temp, &["set", UUID, "--tags", "beta", "--actor", "opencode"]);
|
||||
run(&temp, &["append", UUID, "--tags", "gamma", "--actor", "opencode"]);
|
||||
run(&temp, &["assign", "v1", UUID, "--actor", "opencode"]);
|
||||
|
||||
let found = entries(&worklane);
|
||||
assert_eq!(found.len(), 5, "{found:?}");
|
||||
assert_eq!(found.len(), 6, "{found:?}");
|
||||
for (name, content) in found {
|
||||
assert!(content.contains("**Author**: opencode"), "{name}: {content:?}");
|
||||
}
|
||||
@@ -609,10 +641,11 @@ fn actor_from_git_names_the_git_user_on_every_command_that_writes_one() {
|
||||
run_for_the_human(&temp, &["mv", UUID, "--status", "committed", "--actor-from-git"]);
|
||||
run_for_the_human(&temp, &["chown", "bob", UUID, "--actor-from-git"]);
|
||||
run_for_the_human(&temp, &["set", UUID, "--tags", "beta", "--actor-from-git"]);
|
||||
run_for_the_human(&temp, &["append", UUID, "--tags", "gamma", "--actor-from-git"]);
|
||||
run_for_the_human(&temp, &["assign", "v1", UUID, "--actor-from-git"]);
|
||||
|
||||
let found = entries(&worklane);
|
||||
assert_eq!(found.len(), 5, "{found:?}");
|
||||
assert_eq!(found.len(), 6, "{found:?}");
|
||||
for (name, content) in found {
|
||||
assert!(content.contains("**Author**: Ansho Rei"), "{name}: {content:?}");
|
||||
}
|
||||
@@ -627,7 +660,7 @@ fn actor_and_actor_from_git_are_refused_together() {
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane, "backlog");
|
||||
|
||||
let calls: [&[&str]; 5] = [
|
||||
let calls: [&[&str]; 6] = [
|
||||
&[
|
||||
"comment",
|
||||
UUID,
|
||||
@@ -662,6 +695,15 @@ fn actor_and_actor_from_git_are_refused_together() {
|
||||
"opencode",
|
||||
"--actor-from-git",
|
||||
],
|
||||
&[
|
||||
"append",
|
||||
UUID,
|
||||
"--tags",
|
||||
"beta",
|
||||
"--actor",
|
||||
"opencode",
|
||||
"--actor-from-git",
|
||||
],
|
||||
&[
|
||||
"assign",
|
||||
"v1",
|
||||
|
||||
Reference in New Issue
Block a user