(451fb83) Add a discarded status for work that will not be done, and bump to 0.31.0
The flow ended at done, so a ticket that turned out to be a duplicate or obsolete had nowhere to go: it sat in the backlog or was deleted by hand, which destroyed the record and left every relation to it dangling. Discarded is a fifth status with its own directory, keeping the invariant that the filename, the Status field and the directory agree, and keeping done meaning the work landed. Entering it is allowed from any status without -f, because discarding is not a stage of work. Discarded sits last in Status::ALL, which is what makes the rest fall out rather than needing cases: nothing follows it, so a discard clears no stamp and a ticket abandoned from reviewing keeps the journey it made, and every move out is a backward move, so un-discarding needs -f. The two dependency guards now look opposite ways. check_blockers asks what a ticket waits on and gates work moves; check_dependents asks who waits on it and gates the discard, because those plans depended on work about to be declared never-happening. Both skip targets that are themselves terminal. Status::FLOW is the four stages the board draws, so a discarded column on screen stays a136d13's ticket and done stays the last drawn column. Every tree walker keeps using Status::ALL, or a discarded ticket would be unaddressable. util::is_open replaces three spellings of "not done and not discarded", across mv, ls and the campaign standing. The board's blocked mark goes through it as well: that path was only accidentally correct, since a discarded blocker is absent from the FLOW columns, and drawing the column later would have diverged it from what mv allows. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
c03f47c52d
commit
5bf0fd1bfe
+73
-9
@@ -113,11 +113,12 @@ pub fn cmd_ls(args: &LsArgs, worklane_dir: &Path) -> Result<()> {
|
||||
println!(" [{}] {} {}", status.to_uppercase(), count, label);
|
||||
}
|
||||
|
||||
// Show all tickets except done grouped by status. Over `Status::ALL` rather
|
||||
// than the names, because each column is ordered by its own entry stamp and the
|
||||
// comparator is keyed on the status, not on the directory it was read from.
|
||||
// Show all tickets except the two terminal statuses, grouped by status. Over
|
||||
// `Status::ALL` rather than the names, because each column is ordered by its own
|
||||
// entry stamp and the comparator is keyed on the status, not on the directory it
|
||||
// was read from.
|
||||
for status in Status::ALL {
|
||||
if status.as_str() == DONE {
|
||||
if !is_open(status.as_str()) {
|
||||
continue;
|
||||
}
|
||||
let status_path = worklane_dir.join(status.as_str());
|
||||
@@ -524,7 +525,10 @@ fn check_blockers(worklane_dir: &Path, content: &str, title: &str) -> Result<()>
|
||||
|
||||
for blocker in &blockers {
|
||||
match index.get(&blocker.target) {
|
||||
Some(target) if target.status == DONE => {}
|
||||
// Discarded satisfies a block the way done does: there is nothing left to
|
||||
// wait for. Whether the dependent still makes sense was asked when the
|
||||
// blocker was discarded, which is `check_dependents`' refusal.
|
||||
Some(target) if !is_open(&target.status) => {}
|
||||
Some(target) => open.push(format!(
|
||||
" ({}) {} [{}]",
|
||||
color_text(short_id(&target.uuid), Color::Red),
|
||||
@@ -552,6 +556,49 @@ fn check_blockers(worklane_dir: &Path, content: &str, title: &str) -> Result<()>
|
||||
))
|
||||
}
|
||||
|
||||
/// Refuse discarding a ticket while open tickets are blocked by it.
|
||||
///
|
||||
/// The mirror of [`check_blockers`], asked at the other end of the edge: those tickets
|
||||
/// recorded a dependency on work that is about to be declared never-happening, so their
|
||||
/// plans need a look before the ground moves. `-f` is the caller saying they looked.
|
||||
///
|
||||
/// Tickets already done or discarded do not hold it up: a dependency that was satisfied
|
||||
/// or abandoned is nobody's plan anymore.
|
||||
fn check_dependents(worklane_dir: &Path, uuid: &str, title: &str) -> Result<()> {
|
||||
let index = RelationIndex::load(worklane_dir)?;
|
||||
|
||||
// Every open dependent, not the first, for the reason `check_blockers` names them
|
||||
// all.
|
||||
let waiting: Vec<String> = index
|
||||
.iter()
|
||||
.filter(|ticket| is_open(&ticket.status))
|
||||
.filter(|ticket| {
|
||||
ticket
|
||||
.relations
|
||||
.iter()
|
||||
.any(|relation| relation.kind == RelationKind::BlockedBy && relation.target == uuid)
|
||||
})
|
||||
.map(|ticket| {
|
||||
format!(
|
||||
" ({}) {} [{}]",
|
||||
color_text(short_id(&ticket.uuid), Color::Red),
|
||||
ticket.title,
|
||||
color_text(&ticket.status, Color::Orange),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
if waiting.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Err(anyhow!(
|
||||
"Cannot discard '{}' while open tickets are blocked by it:\n{}\nUse --force (-f) to discard it anyway.",
|
||||
color_text(title, Color::Green),
|
||||
waiting.join("\n"),
|
||||
))
|
||||
}
|
||||
|
||||
/// A status is a [`Status`] rather than a string, so an unknown one is clap's to refuse
|
||||
/// and nothing here has to check. What is left is the order of the flow, which is
|
||||
/// `Status::ALL`.
|
||||
@@ -573,7 +620,13 @@ pub fn cmd_mv(
|
||||
.unwrap();
|
||||
let target_idx = Status::ALL.iter().position(|status| *status == target).unwrap();
|
||||
|
||||
if !force && target_idx < current_idx {
|
||||
// Discarding is not a stage of work, so the walk rules below do not apply to
|
||||
// entering it: a ticket is abandoned from wherever it stands. They do apply to
|
||||
// leaving it, which with discarded last in `Status::ALL` is always a backward move,
|
||||
// so un-discarding needs `-f` with no rule of its own.
|
||||
let discarding = target == Status::Discarded;
|
||||
|
||||
if !force && !discarding && target_idx < current_idx {
|
||||
return Err(anyhow!(
|
||||
"Cannot move backward from {} to {}. Use --force (-f) to allow.",
|
||||
color_text(¤t_status, Color::Orange),
|
||||
@@ -581,7 +634,7 @@ pub fn cmd_mv(
|
||||
));
|
||||
}
|
||||
|
||||
if !force && target_idx != current_idx + 1 && target_idx != current_idx {
|
||||
if !force && !discarding && target_idx != current_idx + 1 && target_idx != current_idx {
|
||||
return Err(anyhow!(
|
||||
"Can only move one stage forward at a time. Use --force (-f) to skip stages."
|
||||
));
|
||||
@@ -597,14 +650,25 @@ pub fn cmd_mv(
|
||||
|
||||
// After the no-op above, so a ticket is never refused for a move it is not making,
|
||||
// and behind `force`, which is where the other two overrides of a rule the board
|
||||
// keeps true already live.
|
||||
// keeps true already live. The two guards look opposite ways: a ticket being worked
|
||||
// must not run ahead of what it waits on, and a ticket being abandoned owes nothing
|
||||
// to its own blockers but must not be pulled out from under the tickets waiting on
|
||||
// it.
|
||||
if !force {
|
||||
check_blockers(&worklane_dir, &resolved, &title)?;
|
||||
match discarding {
|
||||
true => check_dependents(&worklane_dir, &parse_ticket_field(&resolved, "ID"), &title)?,
|
||||
false => check_blockers(&worklane_dir, &resolved, &title)?,
|
||||
}
|
||||
}
|
||||
|
||||
let current_path = worklane_dir.join(¤t_status);
|
||||
let target_path = worklane_dir.join(target_status);
|
||||
|
||||
// A board created before a status existed has no directory for it, and the first
|
||||
// move into one is the wrong place to refuse. Idempotent for every board that has
|
||||
// it.
|
||||
fs::create_dir_all(&target_path)?;
|
||||
|
||||
// Updated before the file is even located, so a ticket without a Status field is
|
||||
// refused for that reason rather than for whatever the lookup notices first.
|
||||
let content = set_status_field(&resolved, target_status, &title)?;
|
||||
|
||||
Reference in New Issue
Block a user