(8556048) Take a relation off with relate --clear, and bump to 0.32.0
`relate` only added. A `--blocked-by` pointed at the wrong ticket was on that ticket forever, refusing every move it made until the target was done or `-f` was passed again, and a target that was deleted did not clean up either: the board carried a dead edge that nothing could clear and every later read of the ticket paid for. `--clear <kind> <target>` takes one off. It is on `relate` rather than on `set` for the reason `RELATIONS` is out of `section_args`: a relation names a target that has to be resolved first, so one writer owns both directions, the way `chown` owns setting an owner and clearing one. It names the target and not just the kind, because a ticket can hold several relations of one kind and emptying all of them is not what anybody is asking for. That is also why it is not spelled the way `set --clear` is, which names a field and empties it whole. Both spellings of the kind are taken, `blocked-by` from the flag and `blocked by` from the label: both are in front of the reader, the flag being what recorded the relation and the label what `show` prints and the file stores, so refusing the printed form would trap anyone clearing a row they had just read. `RelationKind::flag` is a match rather than a `replace` on the label, so the flag, the `--clear` value and the completion list cannot drift. `find_relation` searches the ticket's own edges by id prefix before it searches the board, and that order is the feature rather than an optimisation: no search of the board reaches a target whose ticket is gone, so the stored-target tier is the only thing that can clear a dangling edge, which is the case most likely to need clearing. Two stored targets under one prefix name the candidates instead of guessing, as an ambiguous ticket search already does. An edge the ticket does not hold reports no change, and a target naming nothing at all is an error. The two are different facts: the first is the state the caller asked for, and the second is a typo that a no-op would swallow. The resolver's own reason is carried through, so an ambiguous search says it is ambiguous rather than being reported as nothing found. Recording and clearing the same relation in one call is refused, and the check runs on what was *asked* for and not on what would be written. A relation already in the file is not among the additions, so comparing against those would have let `--blocked-by X --clear blocked-by X` quietly remove it. Removals rewrite the section from what is left and additions are appended to that, in that order and in two passes: a call with no `--clear` then takes exactly the path it always took. The last edge leaves the placeholder, which is the line `append` treats as no content, so the next `relate` replaces it rather than writing underneath it. The two values are one flag, so clap cannot type them apart. `num_args = 2` is per occurrence, which makes an odd number a usage error and every chunk a full pair, and `cleared` parses the kind before the ticket is resolved. Nothing is logged, in either direction, since `relate` never has: a log recording only the destructive half would read as though the additions had never happened. `chowns_clear_is_completed_with_tickets_and_sets_is_not` found the first rule carrying `-l clear` and there are now three, on three commands, each taking something different. It is `each_clear_flag_is_completed_for_its_own_command`, scoped per command, and `relate --clear` offers the kinds rather than a board listing, since tickets where the kind goes would be candidates it refuses. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
7994d98913
commit
0f0767ac00
+55
-13
@@ -22,7 +22,7 @@ use clap::{CommandFactory, ValueEnum};
|
||||
use clap_complete::Shell;
|
||||
|
||||
use crate::install::SKILLS;
|
||||
use crate::util::Status;
|
||||
use crate::util::{RelationKind, Status};
|
||||
|
||||
/// Subcommands whose first positional is a ticket.
|
||||
///
|
||||
@@ -98,6 +98,11 @@ fn fish_dynamic() -> String {
|
||||
let ticket_commands = TICKET_COMMANDS.join(" ");
|
||||
let ticket_second_commands = TICKET_SECOND_COMMANDS.join(" ");
|
||||
let ticket_flags = flag_list(&TICKET_FLAGS);
|
||||
let relation_kinds = RelationKind::ALL
|
||||
.iter()
|
||||
.map(|kind| kind.flag())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
let campaign_commands = CAMPAIGN_COMMANDS.join(" ");
|
||||
let campaign_nested = CAMPAIGN_NESTED_COMMANDS
|
||||
.iter()
|
||||
@@ -188,6 +193,14 @@ complete -c worklane \
|
||||
complete -c worklane -n '__worklane_command_is relate' {ticket_flags} \
|
||||
-x -a '(worklane ls --ids)'
|
||||
|
||||
# `--clear` is the one flag here whose first value is not a ticket, so it is not in
|
||||
# `TICKET_FLAGS`: it takes the kind and then the target, and offering a board listing where
|
||||
# the kind goes would be offering values it refuses. The kinds come from `RelationKind`
|
||||
# rather than being spelled again. The target gets no rule at all, deliberately: fish
|
||||
# completes the value after the flag, and the case this flag exists for is a target whose
|
||||
# ticket is gone, which no listing of the board can offer.
|
||||
complete -c worklane -n '__worklane_command_is relate' -l clear -x -a '{relation_kinds}'
|
||||
|
||||
# Campaigns, from `campaign ls --ids`, in the three places one is named: `assign`'s first
|
||||
# argument, `campaign show`'s only one, and `ls --campaign`.
|
||||
complete -c worklane \
|
||||
@@ -464,22 +477,51 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// `chown --clear` takes a ticket, so it is completed like one, and only under
|
||||
/// `chown`: `set --clear` is the same flag name carrying a field.
|
||||
/// Three commands carry a `--clear` and each one takes something different: `chown`
|
||||
/// takes the ticket, `relate` takes the kind and then the target, and `set` takes a
|
||||
/// field name clap already offers. So each rule is scoped to its own command, and a
|
||||
/// bare search for `-l clear` cannot tell them apart, which is what this used to do.
|
||||
#[test]
|
||||
fn chowns_clear_is_completed_with_tickets_and_sets_is_not() {
|
||||
fn each_clear_flag_is_completed_for_its_own_command() {
|
||||
let script = fish_dynamic();
|
||||
let rule = script
|
||||
.lines()
|
||||
.find(|line| line.starts_with("complete") && line.contains("-l clear"))
|
||||
.expect("chown --clear has a rule of its own");
|
||||
assert!(rule.contains("__worklane_command_is chown"), "{rule}");
|
||||
assert!(rule.contains("worklane ls --ids"), "{rule}");
|
||||
let chown = command().find_subcommand("chown").expect("chown exists").clone();
|
||||
let cli = command();
|
||||
|
||||
let rule_for = |name: &str| {
|
||||
let scope = format!("__worklane_command_is {name}");
|
||||
script
|
||||
.lines()
|
||||
.find(|line| {
|
||||
line.starts_with("complete")
|
||||
&& line.contains("-l clear")
|
||||
&& line.contains(&scope)
|
||||
})
|
||||
.unwrap_or_else(|| panic!("no --clear rule for {name}:\n{script}"))
|
||||
};
|
||||
|
||||
let has_clear = |name: &str| {
|
||||
cli.find_subcommand(name)
|
||||
.unwrap_or_else(|| panic!("no such subcommand: {name}"))
|
||||
.get_arguments()
|
||||
.any(|arg| arg.get_long() == Some("clear"))
|
||||
};
|
||||
|
||||
// `chown --clear` names the ticket in the flag, so the flag completes tickets.
|
||||
assert!(has_clear("chown"), "`chown` has no --clear for the rule to complete");
|
||||
assert!(rule_for("chown").contains("worklane ls --ids"), "{}", rule_for("chown"));
|
||||
|
||||
// `relate --clear` takes the kind first, so it offers the kinds and not a board
|
||||
// listing: tickets there would be candidates the flag refuses. The target, the
|
||||
// second value, is deliberately left uncompleted.
|
||||
assert!(has_clear("relate"), "`relate` has no --clear for the rule to complete");
|
||||
let relate = rule_for("relate");
|
||||
for kind in RelationKind::ALL {
|
||||
assert!(relate.contains(kind.flag()), "{kind:?} is not offered: {relate}");
|
||||
}
|
||||
assert!(
|
||||
chown.get_arguments().any(|arg| arg.get_long() == Some("clear")),
|
||||
"`chown` has no --clear for the rule to complete"
|
||||
!relate.contains("worklane ls --ids"),
|
||||
"tickets offered where the kind goes: {relate}"
|
||||
);
|
||||
|
||||
assert!(
|
||||
!TICKET_FLAGS.contains(&"clear"),
|
||||
"--clear in TICKET_FLAGS would offer tickets to `set --clear`, which takes a field"
|
||||
|
||||
Reference in New Issue
Block a user