Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88918b2f8a | ||
|
|
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
|
||||
@@ -140,6 +145,12 @@ and this file is for what someone changing worklane's own code needs.
|
||||
- The scroll offset is clamped against the *wrapped* line count, from `Paragraph::line_count`, which is why `ratatui` carries the `unstable-rendered-line-info` feature. The paragraph wraps on words, so a clamp on the raw lines would stop short of the end or scroll past it into blank space. Counting the wrapping by hand would only agree with the widget until one of the two changed
|
||||
- The clamp runs on the keypress and again in the draw. The terminal can be resized between the two, and a tick can shorten the ticket under a reader who is already at the end
|
||||
- The offset resets when the selection moves and when the modal is closed, so a ticket opens at its top. It deliberately does *not* reset on a tick: an edit elsewhere in the tree must not throw the reader back to the top of what they are reading
|
||||
- **The overlay carries a page indicator on the bottom right of its border**, `pg 2/8`, so a long ticket does not open looking exactly like a short one. `Block::title_bottom` with a right-aligned `Line`, which spends no text row, the trade the title already makes on the top border. The two cannot crowd each other: they are on opposite borders
|
||||
- **`wrapped_height` is the one measurement.** `last_offset` is it less the viewport and `page_indicator` takes the same two numbers, so the clamp and the indicator cannot disagree. A second `line_count` call, or a count of the raw lines, is a number free to drift, and an indicator that says there is more to read where the scroll refuses to move is worse than none
|
||||
- **The furthest offset is the last page by definition, not by division.** The clamp stops at the wrapped height less the viewport, which is not a page boundary, so the final screenful is partial: `offset / step + 1` reads `pg 2/3` at the bottom of a 25 row ticket in a 10 row viewport and claims there is more below
|
||||
- **The pages are counted in `scroll_step`, a screenful less the overlap line, not in whole screenfuls.** The step is what the keys take, so counting in it names only pages `pgdn` can land on. Counting by screenfuls puts a 30 row ticket in a 10 row viewport at `pg 3/3` two rows short of its end, since three presses are what it takes to get there
|
||||
- The indicator is dropped whole on an overlay too narrow for it, the rule a corner and the tags row already follow, and absent entirely when nothing scrolls, the way an untagged card spends no row on tags
|
||||
- `page_indicator` takes four numbers and returns an `Option<String>`, so every case above is pinned without a terminal. The drawn tests exist for the two things arithmetic cannot answer: which border it landed on and what colour it reached the screen in
|
||||
- **Columns scroll to keep the selected card in view.** `Board::offsets` holds one offset per column, parallel to `columns` and resized in step by `reload`, so a column you leave stays where it was. The keypress aligns the focused column via `follow_selection(screen)`, taking the screen size for the same reason `scroll_detail` does: the visible height belongs to the terminal, which only the caller measures between draws
|
||||
- Card heights are measured on `card_lines`, never assumed, on both the keypress and the draw side (`card_height`, and the `starts` vec as the cards are built). An alignment that trusted a fixed card height would drift from the renderer the first time the card changed shape
|
||||
- The draw aligns the focused column again on its own geometry, so a resize between keypress and frame cannot hide the selection, and caps every column against blank space past its last card. The stored value may go stale after a tick shrinks the column; that is fine, because what is drawn is corrected immediately and the next navigation writes the correction back
|
||||
@@ -275,6 +286,7 @@ and this file is for what someone changing worklane's own code needs.
|
||||
- Priority ramp → brightred (1), red (2), orange (3), cyan (4), grey (5). Green is deliberately absent: it means title
|
||||
- Relation kind mark → brightred `×` blocked by and blocks, cyan `→` relates to, orange `←` regression of and regressed by. A small ramp inside one column, the way the priority meter is: the mark says which kind of edge the row is, so none of these three is a colour standing in for the uuid or the title beside it. Brightred on the cross rather than red, because the id one cell to its right is red and the two would blend. It is the colour and the glyph a held-up card already carries, which is the point: one vocabulary for blocking
|
||||
- Relation status mark → grey `○` backlog, orange `◐` committed, cyan `◐` reviewing, green `●` done, grey `?` for a target the board does not hold. The second ramp in that column: the shape says how far the target has got and the colour tells the two middle stages apart, since both are half circles. **Green is here and deliberately absent from the priority ramp**, where it would sit on a whole line and read as a title; on a one-cell mark with no title behind it, it is the obvious colour for finished and nothing else wants it. Orange keeps the meaning it already has, Status, and grey keeps unset for the one row with no status to show
|
||||
- Chrome → grey. The footer's key names, a rendered `[ ]`, and the overlay's page indicator. Not a new slot: grey already means "what a reader skips", which is the other half of the unset-value meaning, and none of these is a value. The indicator in orange would read as the title it faces across the overlay, in cyan as a timestamp, and in the priority ramp's colours as a level
|
||||
- **The palette splits in two: seven colours that each mean one thing, and `TAG_COLORS`, the eight a tag may be drawn in.** A tag in red would read as a uuid, in green as a title, in grey as an unset value, so the tag slots are reserved as a list rather than picked at the call site. Do not assign a new meaning to a colour in `TAG_COLORS`, and do not draw a tag in one outside it
|
||||
- `tag_color()` is a pure function of the tag string, so the same tag is the same colour on every card, in every view and on every board, with nothing stored. Case sensitive, because `Bug` and `bug` are two different tags to the field and to every search
|
||||
- **The hash is FNV-1a written out here, not `DefaultHasher`.** std does not promise its output is stable across releases, and a board that repaints itself on a toolchain upgrade has lost the only property the mapping is for. `the_tag_mapping_is_pinned` fails on any change to it, so a repaint is a decision rather than a surprise
|
||||
|
||||
Generated
+1
-1
@@ -1494,7 +1494,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.15.2"
|
||||
version = "0.16.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.15.2"
|
||||
version = "0.16.1"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -5,7 +5,7 @@ Worklane is a local Kanban flow for agentic software development.
|
||||
## Commands
|
||||
| Command | Description |
|
||||
|---------|-------------|
|
||||
| `worklane` or `worklane tui [path...]` | Opens the board: four status columns, redrawn when the tree changes. Read only. Opens on backlog, committed and reviewing; `d` shows or hides done, whose count stays in the footer either way. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket, `/` to jump to the first ticket whose id or title matches, `y` to copy the selected ticket's short id to the clipboard, `q` to quit. Each path opens the first `.worklane` at or above it, the working directory by default. Several paths are monitored together, as a tab per project plus an `all` tab that merges them, with `tab` and `shift+tab` between them |
|
||||
| `worklane` or `worklane tui [path...]` | Opens the board: four status columns, redrawn when the tree changes. Read only. Opens on backlog, committed and reviewing; `d` shows or hides done, whose count stays in the footer either way. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket, whose border carries a page indicator while there is more of it than fits, `/` to jump to the first ticket whose id or title matches, `y` to copy the selected ticket's short id to the clipboard, `q` to quit. Each path opens the first `.worklane` at or above it, the working directory by default. Several paths are monitored together, as a tab per project plus an `all` tab that merges them, with `tab` and `shift+tab` between them |
|
||||
| `worklane init` | Creates `.worklane/` with backlog, committed, reviewing, done directories |
|
||||
| `worklane add` | Creates a ticket in backlog with `--title`, `--description`, `--acceptance`, `--plan`, `--tags`, `--due`, `--owner`, `--priority` flags. `--due` takes `YYYY-MM-DD` and refuses anything else at parse time |
|
||||
| `worklane ls [status]` | Lists tickets, sorted by priority then title. Optional positional status, and `--priority <1-5>`, `--tag <tag>` and `--campaign <campaign>`, which compose in any combination. `--tag` matches a whole value of the comma-separated Tags field, case sensitively, so `--tag bug` does not list a ticket tagged `bugfix` or one tagged `Bug` |
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
+327
-13
@@ -1643,29 +1643,87 @@ fn detail_text_area(area: Rect) -> Rect {
|
||||
detail_overlay(area).inner(Margin::new(1, 1))
|
||||
}
|
||||
|
||||
/// The furthest the detail view can scroll: the last screenful, and no further.
|
||||
/// How tall the detail body is once wrapped to `width`.
|
||||
///
|
||||
/// Measured by the widget rather than counted by hand, since it wraps on words. A clamp
|
||||
/// on the raw lines would stop short of the end on a wrapped ticket, and one that
|
||||
/// ignored the wrapping the other way would scroll past it into blank space.
|
||||
fn last_offset(detail: &Text<'static>, text: Rect) -> u16 {
|
||||
/// Measured by the widget rather than counted by hand, since it wraps on words. A count
|
||||
/// of the raw lines would stop short of the end on a wrapped ticket, and one that
|
||||
/// ignored the wrapping the other way would run past it into blank space.
|
||||
///
|
||||
/// The one place the number comes from. The scroll clamp and the page indicator are both
|
||||
/// derived from it, and two measurements are two numbers free to disagree: an indicator
|
||||
/// saying there is more to read where the scroll refuses to move is worse than no
|
||||
/// indicator at all.
|
||||
fn wrapped_height(detail: &Text<'static>, width: u16) -> u16 {
|
||||
let wrapped = Paragraph::new(detail.clone())
|
||||
.wrap(Wrap { trim: false })
|
||||
.line_count(text.width);
|
||||
.line_count(width);
|
||||
|
||||
u16::try_from(wrapped)
|
||||
.unwrap_or(u16::MAX)
|
||||
.saturating_sub(text.height)
|
||||
u16::try_from(wrapped).unwrap_or(u16::MAX)
|
||||
}
|
||||
|
||||
/// The furthest the detail view can scroll: the last screenful, and no further.
|
||||
fn last_offset(detail: &Text<'static>, text: Rect) -> u16 {
|
||||
wrapped_height(detail, text.width).saturating_sub(text.height)
|
||||
}
|
||||
|
||||
/// The step `scroll_detail` takes, a screenful less the line kept for overlap.
|
||||
///
|
||||
/// The page numbers are counted in it rather than in whole screenfuls, so the pages the
|
||||
/// indicator names are the ones the keys can actually land on. Counting by screenfuls
|
||||
/// would put a 30 line ticket in a 10 line viewport at `pg 3/3` two rows short of its
|
||||
/// end, since three presses are what it takes to get there.
|
||||
fn scroll_step(height: u16) -> u16 {
|
||||
height.saturating_sub(1).max(1)
|
||||
}
|
||||
|
||||
/// Where the reader is, as `pg 2/5`, or `None` when there is nothing to say or no room
|
||||
/// to say it in.
|
||||
///
|
||||
/// `offset` has to be clamped already and `last` is what it was clamped against, so this
|
||||
/// is arithmetic on the one wrapped measurement rather than a second look at the text.
|
||||
///
|
||||
/// **The furthest offset is the last page by definition, not by division.** The clamp
|
||||
/// stops at `last`, which is the wrapped height less the viewport and not a page
|
||||
/// boundary, so the final screenful is partial: dividing there reads `pg 2/3` at the
|
||||
/// bottom of the ticket and claims there is more to read.
|
||||
fn page_indicator(offset: u16, last: u16, height: u16, overlay_width: u16) -> Option<String> {
|
||||
// Nothing scrolls, so there are no pages to be on. A ticket that fits spends no
|
||||
// indicator, the way an untagged card spends no row on tags.
|
||||
if last == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let step = scroll_step(height);
|
||||
let total = last.div_ceil(step).saturating_add(1);
|
||||
let page = match offset >= last {
|
||||
true => total,
|
||||
false => offset / step + 1,
|
||||
};
|
||||
|
||||
let indicator = format!(" pg {page}/{total} ");
|
||||
|
||||
// Dropped whole rather than cut, the rule a card's corner follows: half a page number
|
||||
// reads as a different one. Measured against the inner width, since the two border
|
||||
// columns are not the indicator's to write on. The title cannot be crowded by this
|
||||
// however narrow the overlay gets, because the two sit on opposite borders.
|
||||
match indicator.chars().count() <= overlay_width.saturating_sub(2) as usize {
|
||||
true => Some(indicator),
|
||||
false => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
|
||||
let overlay = detail_overlay(area);
|
||||
let text = detail_text_area(area);
|
||||
|
||||
// Clamped here as well as on the keypress: the terminal may have been resized since,
|
||||
// and a ticket read to its end can grow shorter under a tick.
|
||||
let offset = offset.min(last_offset(&detail.body, detail_text_area(area)));
|
||||
// One measurement, two derivations. Clamped here as well as on the keypress: the
|
||||
// terminal may have been resized since, and a ticket read to its end can grow
|
||||
// shorter under a tick. Which is also what repages the indicator, since the wrapped
|
||||
// count and the viewport both move with the width.
|
||||
let last = wrapped_height(&detail.body, text.width).saturating_sub(text.height);
|
||||
let offset = offset.min(last);
|
||||
|
||||
let block = Block::default()
|
||||
let mut block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::Cyan.into()))
|
||||
.title(Span::styled(
|
||||
@@ -1673,6 +1731,20 @@ fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
|
||||
Style::default().fg(Color::Orange.into()),
|
||||
));
|
||||
|
||||
// On the bottom border, so it costs no text row, which is the trade the title already
|
||||
// makes on the top one. Grey because it is chrome: it says where you are in the
|
||||
// ticket rather than anything about the ticket, so it takes the colour the footer
|
||||
// keys and a rendered checkbox take, and does not compete with the orange title.
|
||||
if let Some(indicator) = page_indicator(offset, last, text.height, overlay.width) {
|
||||
block = block.title_bottom(
|
||||
Line::from(Span::styled(
|
||||
indicator,
|
||||
Style::default().fg(Color::Grey.into()),
|
||||
))
|
||||
.right_aligned(),
|
||||
);
|
||||
}
|
||||
|
||||
frame.render_widget(Clear, overlay);
|
||||
frame.render_widget(
|
||||
Paragraph::new(detail.body.clone())
|
||||
@@ -1846,6 +1918,31 @@ mod tests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The overlay's bottom border row, where the page indicator sits.
|
||||
fn overlay_bottom_row(lines: &[String], width: u16, height: u16) -> String {
|
||||
let overlay = detail_overlay(Rect::new(0, 0, width, height));
|
||||
lines[(overlay.y + overlay.height - 1) as usize]
|
||||
.chars()
|
||||
.skip(overlay.x as usize)
|
||||
.take(overlay.width as usize)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A board with one ticket long enough to scroll, opened on it.
|
||||
fn scrolling_board(dir: &Path, lines: usize) -> Board {
|
||||
write_ticket(
|
||||
dir,
|
||||
"backlog",
|
||||
"11111111-0000-4000-8000-000000000000",
|
||||
"A long one",
|
||||
&long_section(lines),
|
||||
);
|
||||
|
||||
let mut board = one_board(dir);
|
||||
board.toggle_detail();
|
||||
board
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_board_draws_the_four_statuses_as_columns_once_done_is_shown() {
|
||||
let dir = board_dir();
|
||||
@@ -4471,4 +4568,221 @@ mod tests {
|
||||
let text = &board.detail.as_ref().expect("no detail").plain();
|
||||
assert!(text.contains("A description."), "the body was lost: {text:?}");
|
||||
}
|
||||
|
||||
/// The overlay scrolls and nothing said where you were: a long ticket opened looking
|
||||
/// exactly like a short one.
|
||||
#[test]
|
||||
fn a_scrollable_ticket_shows_a_page_indicator_on_the_bottom_border() {
|
||||
let dir = board_dir();
|
||||
let board = scrolling_board(&dir, 60);
|
||||
|
||||
let screen = render(&board, SCREEN.width, SCREEN.height);
|
||||
let row = overlay_bottom_row(&screen, SCREEN.width, SCREEN.height);
|
||||
|
||||
assert!(row.contains("pg 1/"), "no indicator on the bottom border:\n{row}");
|
||||
|
||||
// On the border, not on a text row: the row it is drawn on is the one carrying
|
||||
// the corners, so no line of the ticket was spent on it.
|
||||
assert!(row.starts_with('└'), "not the bottom border row:\n{row}");
|
||||
assert!(row.ends_with('┘'), "not the bottom border row:\n{row}");
|
||||
|
||||
// Bottom right, so it is in the corner the eye goes to for a number and not
|
||||
// adrift in the middle of the border.
|
||||
let at = row.chars().position(|c| c == 'p').expect("no indicator");
|
||||
let width = row.chars().count();
|
||||
assert!(
|
||||
at > width - 12,
|
||||
"the indicator is not in the right-hand corner of a {width} cell border:\n{row}"
|
||||
);
|
||||
|
||||
// And the top border still carries the title alone.
|
||||
let title = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
|
||||
assert!(title.contains("A long one"), "{title}");
|
||||
assert!(!title.contains("pg "), "the indicator landed on the title row:\n{title}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// At the top of a scrollable ticket, page one.
|
||||
#[test]
|
||||
fn the_indicator_opens_on_page_one() {
|
||||
let dir = board_dir();
|
||||
let board = scrolling_board(&dir, 60);
|
||||
|
||||
let screen = render(&board, SCREEN.width, SCREEN.height);
|
||||
let row = overlay_bottom_row(&screen, SCREEN.width, SCREEN.height);
|
||||
|
||||
assert!(row.contains("pg 1/"), "{row}");
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The one the arithmetic is for: the clamp stops at the wrapped height less the
|
||||
/// viewport, not on a page boundary, so the last screenful is partial and dividing
|
||||
/// would claim there is more to read.
|
||||
#[test]
|
||||
fn the_furthest_scroll_reads_the_last_page() {
|
||||
let dir = board_dir();
|
||||
let mut board = scrolling_board(&dir, 60);
|
||||
|
||||
// Far past the end, so the clamp is what stops it.
|
||||
for _ in 0..40 {
|
||||
board.scroll_detail(1, SCREEN);
|
||||
}
|
||||
|
||||
let text = detail_text_area(Rect::new(0, 0, SCREEN.width, SCREEN.height));
|
||||
let last = last_offset(&board.detail.as_ref().unwrap().body, text);
|
||||
assert_eq!(board.offset, last, "the fixture did not reach the end");
|
||||
|
||||
let screen = render(&board, SCREEN.width, SCREEN.height);
|
||||
let row = overlay_bottom_row(&screen, SCREEN.width, SCREEN.height);
|
||||
|
||||
let indicator = row
|
||||
.split_whitespace()
|
||||
.find(|word| word.contains('/'))
|
||||
.unwrap_or_else(|| panic!("no indicator on:\n{row}"))
|
||||
.to_string();
|
||||
let (page, total) = indicator.split_once('/').expect("no separator");
|
||||
assert_eq!(page, total, "the last page reads as the second to last: {indicator}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A ticket that fits spends no indicator, the way an untagged card spends no row on
|
||||
/// tags.
|
||||
///
|
||||
/// On a taller screen than the other overlay tests use: `write_ticket`'s own body is
|
||||
/// twenty-odd rows and scrolls in a twenty row terminal, so the fixture has to be
|
||||
/// given a terminal it fits in for the absence to mean anything.
|
||||
#[test]
|
||||
fn a_ticket_that_fits_shows_no_indicator() {
|
||||
let (width, height) = (120, 60);
|
||||
let dir = board_dir();
|
||||
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "A short one", "");
|
||||
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let text = detail_text_area(Rect::new(0, 0, width, height));
|
||||
assert_eq!(
|
||||
last_offset(&board.detail.as_ref().unwrap().body, text),
|
||||
0,
|
||||
"the fixture scrolls, so it proves nothing"
|
||||
);
|
||||
|
||||
let screen = render(&board, width, height);
|
||||
assert!(
|
||||
!screen.join("\n").contains("pg "),
|
||||
"a ticket that fits drew an indicator:\n{}",
|
||||
screen.join("\n")
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The wrapped count and the viewport both move with the terminal, so the total has
|
||||
/// to move with them. Narrower and shorter means more pages of the same ticket.
|
||||
#[test]
|
||||
fn a_resize_repages_the_indicator() {
|
||||
let dir = board_dir();
|
||||
let board = scrolling_board(&dir, 60);
|
||||
|
||||
let total = |width: u16, height: u16| -> String {
|
||||
let screen = render(&board, width, height);
|
||||
let row = overlay_bottom_row(&screen, width, height);
|
||||
row.split_whitespace()
|
||||
.find(|word| word.contains('/'))
|
||||
.unwrap_or_else(|| panic!("no indicator at {width}x{height} on:\n{row}"))
|
||||
.split_once('/')
|
||||
.expect("no separator")
|
||||
.1
|
||||
.to_string()
|
||||
};
|
||||
|
||||
let wide = total(120, 40);
|
||||
let narrow = total(60, 20);
|
||||
assert_ne!(wide, narrow, "the same total on two terminal sizes");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// An overlay too narrow for the indicator drops it whole rather than cutting it, the
|
||||
/// rule a card's corner follows: half a page number reads as a different one.
|
||||
#[test]
|
||||
fn an_overlay_too_narrow_for_the_indicator_drops_it_whole() {
|
||||
// Six pages in a two cell overlay, so there is plenty to say and no room for it.
|
||||
assert_eq!(page_indicator(0, 50, 10, 2), None);
|
||||
assert_eq!(page_indicator(0, 50, 10, 8), None);
|
||||
|
||||
// ` pg 1/7 ` is eight characters, so it needs ten cells of overlay.
|
||||
assert_eq!(page_indicator(0, 50, 10, 10).as_deref(), Some(" pg 1/7 "));
|
||||
}
|
||||
|
||||
/// The arithmetic on its own, so the cases that need no terminal are pinned where
|
||||
/// they can be read.
|
||||
#[test]
|
||||
fn the_page_numbers_count_in_the_step_the_keys_take() {
|
||||
// A 25 line ticket in a 10 line viewport: the step is nine, so the offsets the
|
||||
// keys reach are 0, 9 and 15, the last of them clamped.
|
||||
let (last, height) = (15, 10);
|
||||
assert_eq!(page_indicator(0, last, height, 40).as_deref(), Some(" pg 1/3 "));
|
||||
assert_eq!(page_indicator(9, last, height, 40).as_deref(), Some(" pg 2/3 "));
|
||||
assert_eq!(page_indicator(15, last, height, 40).as_deref(), Some(" pg 3/3 "));
|
||||
|
||||
// Nothing to scroll, nothing to say.
|
||||
assert_eq!(page_indicator(0, 0, height, 40), None);
|
||||
|
||||
// One line over the viewport is two pages, and the second of them is one row.
|
||||
assert_eq!(page_indicator(0, 1, height, 40).as_deref(), Some(" pg 1/2 "));
|
||||
assert_eq!(page_indicator(1, 1, height, 40).as_deref(), Some(" pg 2/2 "));
|
||||
}
|
||||
|
||||
/// The colour the indicator actually reached the screen in.
|
||||
///
|
||||
/// Located on the bottom border row rather than by searching the buffer for a glyph:
|
||||
/// `p` and `g` are all over the board, and `drawn_color` would answer about whichever
|
||||
/// card holds the first one.
|
||||
fn indicator_color(
|
||||
board: &Board,
|
||||
width: u16,
|
||||
height: u16,
|
||||
) -> Option<ratatui::style::Color> {
|
||||
let mut terminal = Terminal::new(TestBackend::new(width, height)).unwrap();
|
||||
terminal.draw(|frame| draw(frame, board)).unwrap();
|
||||
let buffer = terminal.backend().buffer().clone();
|
||||
|
||||
let overlay = detail_overlay(Rect::new(0, 0, width, height));
|
||||
let row = overlay.y + overlay.height - 1;
|
||||
|
||||
(overlay.x..overlay.x + overlay.width - 1)
|
||||
.find(|x| {
|
||||
buffer[(*x, row)].symbol() == "p" && buffer[(x + 1, row)].symbol() == "g"
|
||||
})
|
||||
.map(|x| buffer[(x, row)].fg)
|
||||
}
|
||||
|
||||
/// Chrome, not a value: the guideline gives grey to what a reader skips, and the
|
||||
/// title on the opposite border keeps orange.
|
||||
#[test]
|
||||
fn the_indicator_is_drawn_as_chrome() {
|
||||
let dir = board_dir();
|
||||
let board = scrolling_board(&dir, 60);
|
||||
|
||||
assert_eq!(
|
||||
indicator_color(&board, SCREEN.width, SCREEN.height),
|
||||
Some(Color::Grey.into()),
|
||||
"the indicator was drawn in something other than the chrome colour"
|
||||
);
|
||||
|
||||
// Not the same colour as the title on the opposite border, or it would read as
|
||||
// part of the ticket's identity rather than as chrome.
|
||||
assert_ne!(
|
||||
indicator_color(&board, SCREEN.width, SCREEN.height),
|
||||
Some(Color::Orange.into()),
|
||||
"the indicator took the title's colour"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).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