Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6784d80324 |
+20
-10
@@ -425,39 +425,49 @@ export const chown = tool({
|
||||
/**
|
||||
* check and uncheck differ only in the verb, so the tool is built once.
|
||||
*
|
||||
* The criterion is required here even though the CLI makes it optional: without it the
|
||||
* CLI prompts, and there is no terminal on this side of the pipe. The CLI answers a
|
||||
* The criteria are required here even though the CLI makes them optional: without any
|
||||
* the CLI prompts, and there is no terminal on this side of the pipe. The CLI answers a
|
||||
* missing criterion with the numbered list on stderr, which run() relays, so the model
|
||||
* sees the options and can retry with a number.
|
||||
*
|
||||
* One value per line, like the other list arguments, and every value goes in one call.
|
||||
* The CLI resolves them all before it writes, so a bad term costs nothing, and finishing
|
||||
* a ticket is one tool call rather than one per box.
|
||||
*/
|
||||
function checkboxTool(verb: "check" | "uncheck") {
|
||||
const past = verb === "check" ? "Checked" : "Unchecked";
|
||||
|
||||
return tool({
|
||||
description:
|
||||
`${past === "Checked" ? "Tick" : "Untick"} one acceptance criterion on a worklane ticket. ` +
|
||||
"Every other criterion keeps its state. Identify the criterion by its number as shown by show, " +
|
||||
"or by a substring of its text; a substring matching more than one is an error listing them.",
|
||||
`${past === "Checked" ? "Tick" : "Untick"} acceptance criteria on a worklane ticket. ` +
|
||||
"Every criterion not named keeps its state. Identify each one by its number as shown by show, " +
|
||||
"or by a substring of its text; a substring matching more than one is an error listing them. " +
|
||||
`Pass several, one per line, to ${verb} them in a single call, or the single word all for every ` +
|
||||
"criterion on the ticket. If any value cannot be resolved the whole call is refused and nothing " +
|
||||
"is written, so a partly wrong list never leaves the ticket half-marked.",
|
||||
args: {
|
||||
ticket: tool.schema
|
||||
.string()
|
||||
.describe("Ticket UUID prefix (4+ chars) or title substring (required)"),
|
||||
criterion: tool.schema
|
||||
criteria: tool.schema
|
||||
.string()
|
||||
.describe(
|
||||
"Criterion number as shown by show, or a substring of its text (required)",
|
||||
"Criterion numbers as shown by show, or substrings of their text, one per line. " +
|
||||
"Or the single word all for every criterion (required)",
|
||||
),
|
||||
},
|
||||
async execute(args: Record<string, any>, context: ToolContext) {
|
||||
if (!args.ticket) {
|
||||
return `Error running ${verb}: ticket is required`;
|
||||
}
|
||||
if (!args.criterion) {
|
||||
return `Error running ${verb}: criterion is required, give the number or a substring`;
|
||||
|
||||
const terms = args.criteria ? itemLines(String(args.criteria)) : [];
|
||||
if (terms.length === 0) {
|
||||
return `Error running ${verb}: criteria is required, give the numbers, substrings, or all`;
|
||||
}
|
||||
|
||||
try {
|
||||
return await run([verb, args.ticket, String(args.criterion)], context);
|
||||
return await run([verb, args.ticket, ...terms], context);
|
||||
} catch (err: any) {
|
||||
return `Error running ${verb}: ${err.message}`;
|
||||
}
|
||||
|
||||
@@ -90,11 +90,16 @@ and this file is for what someone changing worklane's own code needs.
|
||||
### Checking Off a Criterion
|
||||
- `check` and `uncheck` are separate commands, not one verb with a flag. They share `CheckArgs` and `cmd_check(args, checked)`
|
||||
- `criteria()` is scoped to the Acceptance Criteria section and counts only checkbox lines, so a checkbox written into a description is not a criterion and a handwritten line inside the section takes no number
|
||||
- `set_criterion()` splices only the character between the brackets. Rebuilding the line would normalise its indentation and whatever spacing followed the checkbox
|
||||
- The criterion argument is an index first, a substring second, so a criterion whose text is literally `2` is reachable only by substring
|
||||
- `set_criteria()` splices only the character between the brackets, and takes every line in one pass. Rebuilding the line would normalise its indentation and whatever spacing followed the checkbox
|
||||
- Each criterion term is the keyword `all` first, an index second, a substring third. So a criterion whose text is literally `2` is reachable only by substring, and one whose text merely contains "all" only by its number or a longer substring. `is_all_criteria()` and `is_index()` sit beside each other in `util.rs` for that reason
|
||||
- **The keyword wins over the text on purpose.** Ticking every box is the reason the word is typed, and a board where `all` sometimes means one criterion and sometimes means the lot would be worse than one that can be addressed another way. `all_is_the_keyword_and_not_a_substring_of_the_text` pins it against its own fixture, so the shared one keeps its three criteria and its numbering
|
||||
- **A number out of range is a bad index, not a failed substring search**, and says so. `is_index()` makes that distinction
|
||||
- Any listing of a subset must keep the real numbers, via `numbered_criteria()`. Renumbering the matches from one contradicts the advice to use the number and points at the wrong criterion
|
||||
- With the criterion omitted: prompt when stdin is a terminal, otherwise return the numbered list as an error. Never prompt unconditionally, the opencode wrapper has no tty and would block on a stdin that never closes. This is the same choice `resolve_ticket` makes for an ambiguous match, and for the same reason
|
||||
- **The criterion positional is variadic**, so `check <ticket> 1 3 "the footer"` is one call and one write. Variadic rather than a repeated flag: the terms address criteria that are already there, the way the ticket positional does, instead of carrying content the way `--acceptance` does. The prompt path is unchanged and fires on an empty list
|
||||
- **`resolve_criteria()` resolves every term before a byte is written, and one bad term refuses the whole batch.** A call that ticked the terms it understood and then failed would leave the ticket half-marked with nothing in the file to say which half was meant. It names the offending term alone rather than every failure at once, since each message carries the criteria listing and a batch of them would repeat the list per bad term
|
||||
- The chosen offsets are sorted and deduped, so the report reads in `show`'s order whatever order the terms arrived in, and a criterion named twice, or by both `all` and its own number, is marked and reported once
|
||||
- **Every named criterion gets a line, in `show`'s order, printed after the write.** A criterion already in the target state reads `Already checked 2: text` and does not count towards the write, so a batch where every box is already ticked writes nothing, which is the whole-file no-op rule the editing commands keep. The number is on the unchanged line too: without it a batch cannot be read back against `show`
|
||||
- `show` numbers the criteria as `1. [x] text`, so the index is visible where the ticket is read. The number replaces the list marker rather than joining it
|
||||
|
||||
### Relating Tickets
|
||||
|
||||
Generated
+1
-1
@@ -1494,7 +1494,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.15.2"
|
||||
version = "0.16.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.15.2"
|
||||
version = "0.16.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -15,8 +15,8 @@ Worklane is a local Kanban flow for agentic software development.
|
||||
| `worklane append <ticket>` | Adds to a section with `--description`, `--acceptance`, `--plan`. At least one required. The description gains a paragraph; list items go on the end, steps numbered on from the last |
|
||||
| `worklane relate <ticket>` | Records an edge to another ticket with `--blocked-by`, `--regression-of` or `--relates-to`, each repeatable. At least one required. Only the ticket named is written; `show` derives the other end by scanning. `mv` refuses to move a ticket blocked by one that is not done, unless `-f` |
|
||||
| `worklane chown <user> <ticket>` | Sets the Owner field, the only command that writes it. Free text, checked against nothing. User first and ticket second, after Unix `chown` |
|
||||
| `worklane check <ticket> [criterion]` | Ticks one acceptance criterion, by number as shown by `show` or by a substring. Prompts with the numbered list if omitted, or errors with it when there is no terminal |
|
||||
| `worklane uncheck <ticket> [criterion]` | Unticks one acceptance criterion, addressed the same way |
|
||||
| `worklane check <ticket> [criteria...]` | Ticks acceptance criteria, each by number as shown by `show` or by a substring. Several in one call, or `all` for every one of them. Prompts with the numbered list if none is given, or errors with it when there is no terminal |
|
||||
| `worklane uncheck <ticket> [criteria...]` | Unticks acceptance criteria, addressed the same way |
|
||||
| `worklane comment <ticket> <body>` | Adds a comment to a ticket by UUID or title |
|
||||
| `worklane install-skill [skill]` | Writes the embedded agent skills to `~/.claude/skills/<skill>/SKILL.md`, which Claude Code and opencode both read. Three ship: `worklane` teaches the CLI, `worklane-review` reviews a finished ticket against the code that claims to close it, `worklane-plan` grooms the board as a whole, its priorities, due dates, tags and campaigns. Every document unless one is named. Leaves a modified copy alone unless `--force`; `--print` writes one to stdout instead and needs the name |
|
||||
|
||||
|
||||
+4
-2
@@ -117,12 +117,14 @@ quote `--force` literally. A body of exactly `--` needs its own separator.
|
||||
## 5. Write the verdict back to the ticket
|
||||
|
||||
```
|
||||
worklane uncheck 1b78a24 2
|
||||
worklane uncheck 1b78a24 2 5
|
||||
worklane append 1b78a24 --acceptance "The footer lists only the keys that are bound"
|
||||
```
|
||||
|
||||
Untick every criterion you found unmet, one call each, by the number `show` printed. Do
|
||||
Untick every criterion you found unmet, by the numbers `show` printed, in one call. Do
|
||||
it after the comment so there is a written reason on the board before the mark changes.
|
||||
Do not reach for `all`: a review unticks what it found unmet, and unticking the lot would
|
||||
erase the implementer's claim on the criteria you agreed with.
|
||||
|
||||
**Never tick a criterion.** A tick is the implementer's claim that something is done, and
|
||||
unticking is the review disagreeing with that claim. A reviewer that also ticks makes
|
||||
|
||||
+15
-2
@@ -60,15 +60,28 @@ listing comes back empty check the spelling against a ticket you know is tagged.
|
||||
worklane mv 1b78a24 --status committed
|
||||
worklane check 1b78a24 3 # tick acceptance criterion 3
|
||||
worklane check 1b78a24 "the footer describes" # or a substring of it
|
||||
worklane check 1b78a24 1 3 "the footer" # several in one call
|
||||
worklane check 1b78a24 all # every criterion on the ticket
|
||||
worklane uncheck 1b78a24 3
|
||||
worklane comment 1b78a24 "Found the cause: the offset was never passed to the widget."
|
||||
worklane mv 1b78a24 --status reviewing
|
||||
```
|
||||
|
||||
Criteria are numbered by `show`. With the criterion omitted, `check` prompts when there
|
||||
is a terminal and otherwise fails with the numbered list, so **always pass the criterion
|
||||
Criteria are numbered by `show`. With no criterion given, `check` prompts when there
|
||||
is a terminal and otherwise fails with the numbered list, so **always pass the criteria
|
||||
when you are not sitting at a prompt**.
|
||||
|
||||
One call takes as many terms as you like, mixing numbers and substrings, and `all` stands
|
||||
for every criterion on the ticket. Use it when the work is done: it is one write instead
|
||||
of one per box. `all` is a keyword, checked before the text, so a criterion whose own
|
||||
words include "all" is reached by its number or by a longer substring.
|
||||
|
||||
**Every term is resolved before anything is written.** One term that matches nothing, or
|
||||
matches more than one criterion, refuses the whole call and names that term, so the ticket
|
||||
is never left half-marked. A criterion already in the state you asked for is reported
|
||||
unchanged rather than refused, and a call that would change nothing writes nothing. Both
|
||||
apply to `uncheck` exactly as they do to `check`.
|
||||
|
||||
## Filing a ticket
|
||||
|
||||
```
|
||||
|
||||
+11
-5
@@ -185,10 +185,10 @@ pub enum Command {
|
||||
paths: Vec<std::path::PathBuf>,
|
||||
},
|
||||
|
||||
/// Tick an acceptance criterion
|
||||
/// Tick acceptance criteria
|
||||
Check(CheckArgs),
|
||||
|
||||
/// Untick an acceptance criterion
|
||||
/// Untick acceptance criteria
|
||||
Uncheck(CheckArgs),
|
||||
|
||||
/// Add a comment to a ticket
|
||||
@@ -452,14 +452,20 @@ impl RelateArgs {
|
||||
/// because the two read as opposites at the call site and neither needs the other's
|
||||
/// name to make sense.
|
||||
///
|
||||
/// The criterion is optional: without it the criteria are listed and the index asked
|
||||
/// The criteria are optional: without any the criteria are listed and the index asked
|
||||
/// for, or, where there is no terminal to ask at, returned as an error carrying the
|
||||
/// same list.
|
||||
///
|
||||
/// Several terms in one call because finishing a ticket means ticking every box, and
|
||||
/// one invocation per box resolved the ticket and rewrote the file each time. The
|
||||
/// terms are variadic rather than a repeated flag: they address something that is
|
||||
/// already there, the way the ticket positional does, instead of carrying content the
|
||||
/// way `--acceptance` does.
|
||||
#[derive(clap::Args)]
|
||||
pub struct CheckArgs {
|
||||
/// Ticket UUID or title
|
||||
pub ticket: String,
|
||||
|
||||
/// Criterion index as shown by `show`, or a substring of its text. Prompts if omitted
|
||||
pub criterion: Option<String>,
|
||||
/// Criterion indexes as shown by `show`, substrings of their text, or `all`. Prompts if omitted
|
||||
pub criteria: Vec<String>,
|
||||
}
|
||||
|
||||
+98
-52
@@ -1153,6 +1153,66 @@ fn ask_which_criterion(criteria: &[Criterion], title: &str) -> Result<usize> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Every criterion the terms name, in the order `show` numbers them and without
|
||||
/// repeats.
|
||||
///
|
||||
/// Resolved before a byte is written, and one bad term refuses the whole batch. A call
|
||||
/// that ticked the terms it understood and then failed would leave the ticket
|
||||
/// half-marked, with nothing in the file to say which half the caller meant, and the
|
||||
/// obvious retry would be reading the ticket back to find out.
|
||||
///
|
||||
/// The offending term is named on its own rather than every failure at once: each
|
||||
/// message carries the criteria listing, so a batch of them would repeat the list per
|
||||
/// bad term and bury the first one.
|
||||
fn resolve_criteria(criteria: &[Criterion], terms: &[String], title: &str) -> Result<Vec<usize>> {
|
||||
let mut chosen: Vec<usize> = Vec::new();
|
||||
|
||||
for term in terms {
|
||||
if is_all_criteria(term) {
|
||||
chosen.extend(0..criteria.len());
|
||||
continue;
|
||||
}
|
||||
|
||||
let found = find_criteria(criteria, term);
|
||||
match found.len() {
|
||||
1 => chosen.push(found[0]),
|
||||
0 if is_index(term) => {
|
||||
return Err(anyhow!(
|
||||
"'{}' is not one of the {} criteria of '{}':\n{}",
|
||||
term.trim(),
|
||||
criteria.len(),
|
||||
title,
|
||||
criteria_list(criteria)
|
||||
));
|
||||
}
|
||||
0 => {
|
||||
return Err(anyhow!(
|
||||
"No criterion of '{}' matches '{}'. Its criteria are:\n{}",
|
||||
title,
|
||||
term,
|
||||
criteria_list(criteria)
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"'{}' matches {} criteria of '{}':\n{}\n\nUse the number instead.",
|
||||
term,
|
||||
found.len(),
|
||||
title,
|
||||
numbered_criteria(criteria, &found)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sorted so the report reads in the order `show` numbers the criteria whatever
|
||||
// order the terms arrived in, and deduped so a criterion named twice, or by both
|
||||
// `all` and its own number, is reported once.
|
||||
chosen.sort_unstable();
|
||||
chosen.dedup();
|
||||
Ok(chosen)
|
||||
}
|
||||
|
||||
pub fn cmd_check(args: &CheckArgs, checked: bool, start: &Path) -> Result<()> {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
let (status, title, content) = resolve_ticket(&args.ticket, &worklane_dir)?;
|
||||
@@ -1162,64 +1222,50 @@ pub fn cmd_check(args: &CheckArgs, checked: bool, start: &Path) -> Result<()> {
|
||||
return Err(anyhow!("Ticket '{}' has no acceptance criteria", title));
|
||||
}
|
||||
|
||||
let chosen = match &args.criterion {
|
||||
None => ask_which_criterion(&criteria, &title)?,
|
||||
Some(search) => {
|
||||
let found = find_criteria(&criteria, search);
|
||||
match found.len() {
|
||||
1 => found[0],
|
||||
0 if is_index(search) => {
|
||||
return Err(anyhow!(
|
||||
"'{}' is not one of the {} criteria of '{}':\n{}",
|
||||
search.trim(),
|
||||
criteria.len(),
|
||||
title,
|
||||
criteria_list(&criteria)
|
||||
));
|
||||
}
|
||||
0 => {
|
||||
return Err(anyhow!(
|
||||
"No criterion of '{}' matches '{}'. Its criteria are:\n{}",
|
||||
title,
|
||||
search,
|
||||
criteria_list(&criteria)
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"'{}' matches {} criteria of '{}':\n{}\n\nUse the number instead.",
|
||||
search,
|
||||
found.len(),
|
||||
title,
|
||||
numbered_criteria(&criteria, &found)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
let chosen = match args.criteria.as_slice() {
|
||||
[] => vec![ask_which_criterion(&criteria, &title)?],
|
||||
terms => resolve_criteria(&criteria, terms, &title)?,
|
||||
};
|
||||
|
||||
let criterion = &criteria[chosen];
|
||||
let verb = if checked { "checked" } else { "unchecked" };
|
||||
// Only the criteria that are not already in the target state, so a batch where
|
||||
// every box is already ticked writes nothing, the way a single one always has.
|
||||
let changing: Vec<usize> = chosen
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|offset| criteria[*offset].checked != checked)
|
||||
.collect();
|
||||
|
||||
if criterion.checked == checked {
|
||||
println!(
|
||||
"Already {}: {}",
|
||||
verb,
|
||||
color_text(&criterion.text, Color::Green)
|
||||
);
|
||||
return Ok(());
|
||||
if !changing.is_empty() {
|
||||
let lines: Vec<usize> = changing
|
||||
.iter()
|
||||
.map(|offset| criteria[*offset].line)
|
||||
.collect();
|
||||
let updated = set_criteria(&content, &lines, checked);
|
||||
let uuid = parse_ticket_field(&content, "ID");
|
||||
save_ticket(&worklane_dir, &status, &uuid, &title, None, &updated)?;
|
||||
}
|
||||
|
||||
let updated = set_criterion(&content, criterion.line, checked);
|
||||
let uuid = parse_ticket_field(&content, "ID");
|
||||
save_ticket(&worklane_dir, &status, &uuid, &title, None, &updated)?;
|
||||
// Reported after the write, one line per criterion the call named, so nothing
|
||||
// claims a mark the file does not carry.
|
||||
let verb = if checked { "checked" } else { "unchecked" };
|
||||
let past = if checked { "Checked" } else { "Unchecked" };
|
||||
|
||||
for offset in chosen {
|
||||
let criterion = &criteria[offset];
|
||||
let state = if criterion.checked == checked {
|
||||
format!("Already {}", verb)
|
||||
} else {
|
||||
past.to_string()
|
||||
};
|
||||
|
||||
println!(
|
||||
"{} {}: {}",
|
||||
state,
|
||||
offset + 1,
|
||||
color_text(&criterion.text, Color::Green)
|
||||
);
|
||||
}
|
||||
|
||||
println!(
|
||||
"{} {}: {}",
|
||||
if checked { "Checked" } else { "Unchecked" },
|
||||
chosen + 1,
|
||||
color_text(&criterion.text, Color::Green)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+20
-3
@@ -2071,6 +2071,19 @@ pub fn is_index(search: &str) -> bool {
|
||||
search.trim().parse::<usize>().is_ok()
|
||||
}
|
||||
|
||||
/// Whether `search` is the keyword standing for every criterion.
|
||||
///
|
||||
/// Checked before `find_criteria`, the way the index is checked before the substring,
|
||||
/// so a criterion whose text contains "all" is reachable only by its number or by a
|
||||
/// different substring. The keyword wins because ticking every box is the reason the
|
||||
/// word is typed, and a board where `all` sometimes means one criterion and sometimes
|
||||
/// means the lot would be worse than one that can be addressed another way.
|
||||
///
|
||||
/// Case-insensitive, like the substring match it stands beside.
|
||||
pub fn is_all_criteria(search: &str) -> bool {
|
||||
search.trim().eq_ignore_ascii_case("all")
|
||||
}
|
||||
|
||||
/// Which criterion `search` names: a one-based index as `show` prints, or a
|
||||
/// case-insensitive substring of the text.
|
||||
///
|
||||
@@ -2096,16 +2109,20 @@ pub fn find_criteria(criteria: &[Criterion], search: &str) -> Vec<usize> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Tick or untick the criterion on `line`, leaving every other byte alone.
|
||||
/// Tick or untick the criteria on `lines`, leaving every other byte alone.
|
||||
///
|
||||
/// Only the character between the brackets is spliced. Rebuilding the line would
|
||||
/// normalise its indentation and whatever spacing it carried after the checkbox.
|
||||
pub fn set_criterion(content: &str, line: usize, checked: bool) -> String {
|
||||
///
|
||||
/// Every line in one pass, so a batch is one rewrite and one save rather than one of
|
||||
/// each per criterion. `lines` is searched rather than indexed because a ticket holds
|
||||
/// a handful of criteria, and a set would only move the cost somewhere else.
|
||||
pub fn set_criteria(content: &str, lines: &[usize], checked: bool) -> String {
|
||||
let mark = if checked { 'x' } else { ' ' };
|
||||
let mut out = String::with_capacity(content.len());
|
||||
|
||||
for (index, current) in content.lines().enumerate() {
|
||||
match (index == line, current.find("- [")) {
|
||||
match (lines.contains(&index), current.find("- [")) {
|
||||
(true, Some(at)) => {
|
||||
let opens = at + "- [".len();
|
||||
out.push_str(¤t[..opens]);
|
||||
|
||||
@@ -53,6 +53,43 @@ fn create_ticket(worklane: &Path) {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// A second ticket whose criteria carry the word `all`, so the keyword's precedence
|
||||
/// can be pinned without renumbering the shared fixture.
|
||||
const ALL_UUID: &str = "6b1f9c22-0d4e-4a1b-9f37-2c85ab4d1e70";
|
||||
|
||||
fn create_all_in_text_ticket(worklane: &Path) {
|
||||
let lines = [
|
||||
"# All in the text",
|
||||
"",
|
||||
"## Acceptance Criteria",
|
||||
"- [ ] all the boxes are listed",
|
||||
"- [ ] the footer is drawn",
|
||||
"",
|
||||
"## Metadata",
|
||||
"",
|
||||
&format!("- **ID**: {}", ALL_UUID),
|
||||
"- **Status**: backlog",
|
||||
"",
|
||||
];
|
||||
|
||||
fs::write(
|
||||
worklane
|
||||
.join("backlog")
|
||||
.join(format!("{}_all-in-the-text.md", ALL_UUID)),
|
||||
lines.join("\n"),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn all_in_text_ticket(worklane: &Path) -> String {
|
||||
fs::read_to_string(
|
||||
worklane
|
||||
.join("backlog")
|
||||
.join(format!("{}_all-in-the-text.md", ALL_UUID)),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn run(temp: &TempDir, args: &[&str]) -> std::process::Output {
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(temp.path()).args(args);
|
||||
@@ -285,3 +322,239 @@ fn check_leaves_nothing_behind() {
|
||||
.collect();
|
||||
assert_eq!(strays, Vec::<String>::new());
|
||||
}
|
||||
|
||||
/// The common case the batch exists for: the work is done, every box is true.
|
||||
#[test]
|
||||
fn all_ticks_every_criterion() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["check", UUID, "all"]);
|
||||
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
||||
|
||||
let content = ticket(&worklane);
|
||||
assert!(content.contains("- [x] alpha shared\n"), "{content}");
|
||||
assert!(content.contains("- [x] beta alone\n"), "{content}");
|
||||
assert!(content.contains("- [x] gamma shared\n"), "{content}");
|
||||
|
||||
// beta was already ticked, so it is reported unchanged rather than as a new mark
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(stdout.contains("Checked 1: alpha shared"), "{stdout:?}");
|
||||
assert!(stdout.contains("Already checked 2: beta alone"), "{stdout:?}");
|
||||
assert!(stdout.contains("Checked 3: gamma shared"), "{stdout:?}");
|
||||
|
||||
// And nothing outside the section was touched
|
||||
assert!(
|
||||
content.contains("- [ ] A checkbox in the description, which is not a criterion.\n"),
|
||||
"the description checkbox was ticked: {content}"
|
||||
);
|
||||
assert!(
|
||||
content.contains(" A handwritten line inside the section.\n"),
|
||||
"the handwritten line was lost: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// An index and a substring in one call, each addressed by the existing rules.
|
||||
#[test]
|
||||
fn one_call_takes_several_mixed_terms() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["check", UUID, "3", "ALPHA"]);
|
||||
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
||||
|
||||
let content = ticket(&worklane);
|
||||
assert!(content.contains("- [x] alpha shared\n"), "{content}");
|
||||
assert!(content.contains("- [x] gamma shared\n"), "{content}");
|
||||
|
||||
// Reported in show's order whatever order the terms arrived in
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
let alpha = stdout.find("Checked 1: alpha");
|
||||
let gamma = stdout.find("Checked 3: gamma");
|
||||
assert!(
|
||||
matches!((alpha, gamma), (Some(alpha), Some(gamma)) if alpha < gamma),
|
||||
"reported out of order, or one of them is missing: {stdout:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The same criterion named twice, once by number and once by text, is one mark and
|
||||
/// one line of output.
|
||||
#[test]
|
||||
fn a_criterion_named_twice_is_reported_once() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["check", UUID, "1", "alpha", "all"]);
|
||||
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
||||
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert_eq!(
|
||||
stdout.matches("alpha shared").count(),
|
||||
1,
|
||||
"alpha was reported more than once: {stdout:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
stdout.lines().count(),
|
||||
3,
|
||||
"one line per criterion, not per term: {stdout:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Nothing to change, so nothing is written, the way a single already-ticked
|
||||
/// criterion already behaves.
|
||||
#[test]
|
||||
fn a_batch_that_would_change_nothing_writes_nothing() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
|
||||
run(&temp, &["check", UUID, "all"]);
|
||||
let before = ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["check", UUID, "all"]);
|
||||
assert!(out.status.success());
|
||||
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert_eq!(
|
||||
stdout.matches("Already checked").count(),
|
||||
3,
|
||||
"{stdout:?}"
|
||||
);
|
||||
assert_eq!(ticket(&worklane), before, "the file was rewritten anyway");
|
||||
}
|
||||
|
||||
/// One term that matches nothing refuses the whole call, so the ticket is never left
|
||||
/// half-marked.
|
||||
#[test]
|
||||
fn a_term_matching_nothing_leaves_the_batch_unwritten() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
let before = ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["check", UUID, "1", "nowhere", "3"]);
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1));
|
||||
assert!(stderr.contains("nowhere"), "the term was not named: {stderr:?}");
|
||||
assert_eq!(ticket(&worklane), before, "alpha was ticked anyway");
|
||||
}
|
||||
|
||||
/// An ambiguous term in a batch is refused the same way a lone one is, and names
|
||||
/// itself rather than whichever term happened to come first.
|
||||
#[test]
|
||||
fn an_ambiguous_term_in_a_batch_names_itself_and_writes_nothing() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
let before = ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["check", UUID, "1", "shared"]);
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1));
|
||||
assert!(stderr.contains("'shared' matches 2 criteria"), "{stderr:?}");
|
||||
assert!(stderr.contains("1. [ ] alpha shared"), "{stderr:?}");
|
||||
assert!(stderr.contains("3. [ ] gamma shared"), "{stderr:?}");
|
||||
assert_eq!(ticket(&worklane), before);
|
||||
}
|
||||
|
||||
/// An index out of range in a batch is still a bad index, not a failed text search.
|
||||
#[test]
|
||||
fn an_index_out_of_range_in_a_batch_leaves_the_file_untouched() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
let before = ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["check", UUID, "1", "9"]);
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1));
|
||||
assert!(stderr.contains("is not one of the 3 criteria"), "{stderr:?}");
|
||||
assert_eq!(ticket(&worklane), before);
|
||||
}
|
||||
|
||||
/// The decision this pins: `all` is the keyword, checked before the substring the way
|
||||
/// the index is, so it ticks every criterion and not the one whose text says "all".
|
||||
#[test]
|
||||
fn all_is_the_keyword_and_not_a_substring_of_the_text() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_all_in_text_ticket(&worklane);
|
||||
|
||||
run(&temp, &["check", ALL_UUID, "all"]);
|
||||
|
||||
let content = all_in_text_ticket(&worklane);
|
||||
assert!(content.contains("- [x] all the boxes are listed\n"), "{content}");
|
||||
assert!(
|
||||
content.contains("- [x] the footer is drawn\n"),
|
||||
"all matched its own text instead of every criterion: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// And the criterion whose text carries the word is still reachable, by its number or
|
||||
/// by a longer substring.
|
||||
#[test]
|
||||
fn a_criterion_whose_text_contains_all_is_still_reachable() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_all_in_text_ticket(&worklane);
|
||||
|
||||
run(&temp, &["check", ALL_UUID, "all the boxes"]);
|
||||
|
||||
let content = all_in_text_ticket(&worklane);
|
||||
assert!(content.contains("- [x] all the boxes are listed\n"), "{content}");
|
||||
assert!(content.contains("- [ ] the footer is drawn\n"), "{content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uncheck_takes_all() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["uncheck", UUID, "all"]);
|
||||
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
||||
|
||||
let content = ticket(&worklane);
|
||||
assert!(content.contains("- [ ] alpha shared\n"), "{content}");
|
||||
assert!(content.contains("- [ ] beta alone\n"), "{content}");
|
||||
assert!(content.contains("- [ ] gamma shared\n"), "{content}");
|
||||
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(stdout.contains("Unchecked 2: beta alone"), "{stdout:?}");
|
||||
assert!(stdout.contains("Already unchecked 1: alpha shared"), "{stdout:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uncheck_takes_several_mixed_terms() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
|
||||
run(&temp, &["check", UUID, "all"]);
|
||||
let out = run(&temp, &["uncheck", UUID, "2", "gamma"]);
|
||||
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
||||
|
||||
let content = ticket(&worklane);
|
||||
assert!(content.contains("- [x] alpha shared\n"), "{content}");
|
||||
assert!(content.contains("- [ ] beta alone\n"), "{content}");
|
||||
assert!(content.contains("- [ ] gamma shared\n"), "{content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failing_term_refuses_an_uncheck_batch_too() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane);
|
||||
let before = ticket(&worklane);
|
||||
|
||||
let out = run(&temp, &["uncheck", UUID, "2", "nowhere"]);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1));
|
||||
assert_eq!(ticket(&worklane), before, "beta was unticked anyway");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user