Compare commits

..
4 Commits
13 changed files with 1071 additions and 215 deletions
+13 -7
View File
@@ -85,7 +85,7 @@ and this file is for what someone changing worklane's own code needs.
- Prefer explicit `match` over `unwrap_or_default()` for clarity
- Use `unwrap_or_else(|| expr)` for lazy defaults, `unwrap_or(val)` for eager defaults
- Use `anyhow!()` with context strings that include identifying info (e.g. UUID, title) not bare values
- A command whose arguments run past a handful takes a clap `Args` struct, not an inline variant with a matching parameter list: `AddArgs`, `SetArgs`, `AppendArgs`, `CheckArgs`. `add` was nine positional parameters threaded from `main` before it became `AddArgs`, and the handler destructures the struct so the body reads the same as before
- A command whose arguments run past a handful takes a clap `Args` struct, not an inline variant with a matching parameter list: `AddArgs`, `SetArgs`, `AppendArgs`, `CheckArgs`, `MvArgs`. `add` was nine positional parameters threaded from `main` before it became `AddArgs`, and the handler destructures the struct so the body reads the same as before. `mv` was the last inline variant to carry an `--actor`, and `--actor-from-git` pushed its list past the line
### CLI Arguments
- The prose arguments carry `allow_hyphen_values`, via the `PROSE` constant in `command.rs`: `add --title`, `--description`, `--acceptance`, `--plan`, and the `comment` body. Ticket text quotes flag names constantly, and without it a criterion reading `--print is supported` is parsed as a flag and the whole ticket is refused with nothing written
@@ -277,7 +277,7 @@ and this file is for what someone changing worklane's own code needs.
- **The expanded height is a share, not a second constant: half of what the frame and the columns divide.** That is the screen less the tab row and the footer, so the split is even between the two of them rather than even against rows neither gets all of. Half rather than most of it for the same reason the frame is not an overlay: the columns below are the campaign's members, and a reader inspecting the campaign has to go on seeing what it is made of. Floored, so the odd row goes to the cards. `Chrome::frame_rows` takes the height because of this, and `screen_rows` is where it is called, since that is the one place that already has an area to take a share of — which is what keeps `Chrome` itself pure and copyable from `Board::chrome` with no screen to hand
- **The share is bounded at both ends, and `COLUMN_MIN_ROWS` is why.** `Constraint::Min(COLUMN_MIN_ROWS)` would take rows back from a frame that asked for too many, silently, and the frame's own measurement would then disagree with what is drawn — the fault `Chrome` exists to prevent. So the share is capped at what leaves the columns those rows, and floored at `FRAME_ROWS`, since expanding must never shrink the frame. On a board too short to divide, `enter` gives the collapsed height back rather than a height nothing measured. `the_expanded_share_is_bounded_at_both_ends` sweeps every height from 4 to 60, tabbed and not, because one screen that happens to work says nothing about the arithmetic
- **The frame says the rest of what it has to say on its borders**, the trade the detail overlay makes with its title and its page indicator: `(id) ~codename · Name` on the top one, the standing on the bottom right, and `q board` then the page indicator on the bottom left. Every row spent here is a row of cards
- **The frame slot is shared between the two filters, not doubled.** One filter is on at a time, per `Filter`, so a tag frame is the campaign frame with its three slots filled differently: `#tag` in `tag_color` on the top border where the campaign's identity goes, how many tickets carry it on the bottom right where the standing goes, and the annotation in the prose rows. `FrameContent` is what the two are told apart into, and **`frame_content` is the one place they are told apart at all** — the borders, the colour, `q board`, the page indicator, the scroll and the focus are all the campaign frame's, and a second `match` on the filter below that is how the two frames come to behave differently in a way nobody decided
- **The frame slot is shared between the filters, not doubled.** One filter is on at a time, per `Filter`, so a tag frame is the campaign frame with its three slots filled differently: `#tag` in `tag_color` on the top border where the campaign's identity goes, how many tickets carry it on the bottom right where the standing goes, and the annotation in the prose rows. `FrameContent` is what they are told apart into, and **`frame_content` is the one place they are told apart at all** — the borders, the colour, `q board`, the page indicator, the scroll and the focus are all the campaign frame's, and a second `match` on the filter below that is how the frames come to behave differently in a way nobody decided
- **A tag frame draws the annotation, which is the payoff for declaring a tag.** Whoever is browsing a tag is deciding whether the next ticket belongs in it, and the sentence saying when the tag is appropriate is then on the screen at that moment rather than in `tags.md`, which they would have to know to open. An undeclared tag draws `NO_ANNOTATION` in grey, which is also the frame saying the word was never agreed on — the vocabulary file's own placeholder rather than the description section's, so the frame and the file say the same thing about the same tag. A tag declared with nothing said about it draws the same, since here the two have the same nothing to show; the picker's sections are where the difference is actionable
- **A tag has no id, so `y` on its frame copies the word.** A tag *is* its name, matched whole by `ls --tag`, so there are no seven characters to shorten and the `#` the border draws is not part of it — `--tag "#bug"` matches nothing. The footer says `y copy tag` there for the same reason: naming it an id would send the reader looking for a short id on a border that prints a word
- **The count on a tag frame is every column's, drawn or not**, the rule the standing holds. With the filter on, those columns *are* the tickets carrying the tag, so it counts what is below it without counting it a second way. The noun is spelled out and pluralised, because a bare number on a border says nothing about what was counted, and there is no derived state beside it: a tag is a word and not a piece of work, so there is no `[open]` to be in
@@ -296,7 +296,12 @@ and this file is for what someone changing worklane's own code needs.
- **The picker's rows are `Tab::campaigns`, not a copy taken when it opened**, so a campaign filed elsewhere appears in an open picker on the next tick. It opens on the campaign already selected, so `c` on a filtered board says where you are as well as offering somewhere to go, and a board with no campaigns gets a `Notice` rather than an empty box that has to be dismissed to learn it was empty
- **`t` opens the same picker over the tags instead, and taking a tag filters every column to the cards carrying it.** Every tag the board declares or carries, matched whole and case sensitively the way `ls --tag` matches — the box completes the filter, so offering what the filter would refuse is the one bug it must not have. It opens on the tag already applied, the courtesy `c` pays a campaign-filtered board, and a board carrying no tag gets the same `Notice` a board with no campaigns gets
- **A picker row draws a real codename only.** The row opens with the short id, so the card's `~<id>` fallback would print it twice and say nothing the second time
- **One picker serves both lists, and `PickerRow::key` is what keeps it one.** A second picker would have been a second keyboard, query and highlight to keep in step with the first; instead `PickerKind` decides only which list is built and what the answer filters, and everything between the keypress and the filter runs once against the key — a campaign is keyed by its uuid and a tag by itself, both strings the tab can be filtered by. Picking either clears the other without either setter remembering to, because `select_filter` replaces one `Filter`: one field, which is the same reason the frame slot is shared
- **One picker serves both lists, and `PickerRow::key` is what keeps it one.** A second picker would have been a second keyboard, query and highlight to keep in step with the first; instead `PickerKind` decides only which list is built, and everything between the keypress and the filter runs once against the key — which since the pile arrived is a `PickerKey` enum rather than a bare string, because one of the answers filters on an *absence* and carries no string to hand back. `take_picked` reads the kind off the answer rather than off which list was open. Picking any of them clears the others without either setter remembering to, because `select_filter` replaces one `Filter`: one field, which is the same reason the frame slot is shared
- **The campaign picker opens with a row for the tickets in no campaign**, above both sections and never truncated: the pile is the one question about a board of campaigns that no single campaign answers, and on a board whose completed tail is being kept back it would be pushed off the box if it listed among them. It draws its count where a campaign row draws its standing, so picking an empty pile is seen coming; under a query it answers "no campaign" and "none" and hides like any other row. **It selects `Filter::NoCampaign`, its own variant** — `retain_campaign` compares the field to the uuid it is given, so the absence case is a different predicate beside it (`retain_no_campaign`) and not a different value in it, and a magic uuid meaning none is exactly the thing that later matches a real one. A dangling uuid is *set* wrongly and stays out of the view, as it draws `_missing_` on its card rather than nothing at all
- **The pile crosses boards where a campaign cannot, so it is pickable on the merge tab.** An unset field means the same thing in every `.worklane`, the property that lets a tag filter travel there; the count adds across boards, taken at reload off the unfiltered columns like the standings are (`Tab::no_campaign`), never per draw and never off the filtered columns, which would answer zero about themselves
- **The opening highlight still lands on the first campaign, not on the pile.** Campaigns are what this list opens for; the row sits above the list without claiming it — one step up reaches it, it holds the highlight whenever it was the row selected, and only when every campaign is hidden does it take the opening one
- **The frame speaks for the pile in its own words, because the frame question stays `is_whole()`.** Exempting one variant from either half of that rule would be a state where the selection rests on a frame that is not drawn — the one thing `Focus` exists to make unrepresentable. So the title is grey `no campaign` (no id to shorten and no mark, which keeps `~` meaning a campaign and `#` a tag), the standing corner takes the count, and the prose is one grey sentence the board owns, since no file holds words for an absence
- **`y` has nothing to copy from the pile's frame** — no id to shorten and no word a command line takes, `ls --campaign` being unable to say none — so the footer leaves the key out rather than naming it into a notice, and pressing it anyway still answers "nothing to copy"
- **The picker draws two sections, open campaigns above completed, and truncates the completed tail.** One flat list by title put the finished campaigns among the open ones forever, and the tail only grows, so on a board that has run for a while the campaigns worth picking were pushed towards the bottom of the box and eventually off it. Open keeps the index's order, which is by title; completed is by `Created At` newest first, because what a reader recognises about a finished campaign is that it was finished recently. `COMPLETED_SHOWN` of them survive, behind a grey line naming how many older ones are being kept back — rows that are simply gone read as a board that never held them. An unstamped campaign sinks below every stamped one, the rule `by_status_order` holds for a column
- **The tag sections are declared above undeclared, and truncate neither.** The same two-section shape with the opposite reason for the second: a completed campaign is finished with, so its tail is kept back before it pushes the pickable campaigns off the box, while an undeclared tag — a word somebody typed onto a ticket that the board never agreed on — is the row a reader most wants to see. A declared tag no ticket carries stays a row too: `tags.md` is what the board intends, and the vocabulary the listing reports is the one the picker offers. `campaign` and `campaigns` would have sat one under the other here, in different sections, the day the second was invented
- **`picker_list` is the one place that decides what a picker row is**, and `Picker::row` counts *drawn* rows. The sections reorder the campaigns and add rows of their own, so `Tab::campaigns` and the drawn list agree about no number past the first heading, and a row number that meant one thing to the draw and another to a keypress is how a highlight comes to name a campaign nobody chose. The list is derived on every draw and every keypress and never held, which is what keeps a campaign filed elsewhere reaching an open picker on the next tick
@@ -306,7 +311,7 @@ and this file is for what someone changing worklane's own code needs.
- **`/` in the picker is the key it already is on the board**, and `picker_key` can take it because printable keys used to fall through `_ => {}`. Typing filters case insensitively against the short id, the codename and the title — the three things the row draws and the three a campaign is chosen by. Not the summary: a query that matched prose would answer `disk` with every campaign whose description mentions one. A tag answers by itself or by its annotation, which is a reader who cannot remember the word finding it by what it was for — case insensitive here though `--tag` is not, because matching a tag is the filter and searching for one is a reader typing. **An empty query matches everything**, the opposite of `first_match`'s answer and right for the opposite reason: a jump with nothing typed has nowhere to go, while a filter with nothing typed is not filtering, and pressing `/` must not empty the list
- **A query turns the truncation off**, which is the point of having one: the campaign a reader is searching for is exactly the one the truncation hid
- **The query is a layer, and `esc` takes it off before it takes the picker off**, the order `dismiss` closes the board's own layers in. So the list is whole again after that press, not still filtered with nothing on screen saying why. Movement and `enter` stay live under an open query, because a filtered list nothing can move in is a list nothing can be chosen from; every *printable* key goes into the buffer, so `q` types and so does `j`
- **The highlight follows its row, not its row number.** `place_picker` takes a key — a uuid or a tag, whichever list is open — the same string `Tab::filter` holds for either filter: typing, clearing the query and a tick that finishes a campaign all reshape the list, and a number kept across that names whichever campaign now sits at it. One the list no longer holds drops the highlight to the first row that does, which is where an incremental filter puts it. `reload` reads the highlighted key before the lists are rebuilt and puts it back after
- **The highlight follows its row, not its row number.** `place_picker` takes a key — whichever answer `PickerRow::key` hands back, the same shape `Tab::filter` holds for any of them: typing, clearing the query and a tick that finishes a campaign all reshape the list, and a number kept across that names whichever campaign now sits at it. One the list no longer holds drops the highlight to the first row that does, which is where an incremental filter puts it. `reload` reads the highlighted key before the lists are rebuilt and puts it back after
- **A miss is a row in the box, `no match` in brightred**, where the search prompt puts its own, and `enter` on it leaves the picker and the query exactly as they are so the query can be corrected in place. An empty box says nothing about why it is empty
- **The picker's footer becomes its query**, the trade `draw_search` makes: with every printable key going into a buffer, a list of keys describes nothing that works. `/ search` is named only on the closed query, and the open one names what `esc` does to *it* rather than what it does to the picker
- **The title says both counts while a query is open**, `campaigns (2 of 6)`. The bare total is what the box is, but over a list a query has cut down it is a lie about what is on screen
@@ -410,8 +415,9 @@ and this file is for what someone changing worklane's own code needs.
### Who Wrote an Entry
- **Identity is supplied, not detected.** Every option that needs no cooperation fails: a harness variable such as `CLAUDECODE` names the tool rather than the instance and breaks across versions, walking the parent process is platform specific and also only names the harness, and a terminal check separates interactive from not, which a human piping output is too. So the actor is `WORKLANE_ACTOR`, set once per session, with `--actor` as the per-call override
- **Precedence: flag, then `WORKLANE_ACTOR`, then `get_git_user()`, then `unknown`.** `resolve_actor` is the only caller of `get_git_user` for an entry's author, and every entry the CLI writes goes through it. The two halves are separate pure functions, `session_actor` and `entry_actor`, tested without touching the process environment for the reason `colors_wanted` is split that way
- **The session half is cached in a `OnceLock`, the way `should_use_colors` is:** neither the variable nor the git user can change mid-run, and the fallback costs a `git config` subprocess. `session_actor` takes the git user as a closure so that subprocess is not run when the variable already answered
- **Precedence: flag, then `WORKLANE_ACTOR`, then `get_git_user()`, then `unknown`.** With `--actor-from-git` and no explicit value the git user is lifted *above* the variable rather than added beneath it — the flag says attribute this to the human, and a machine with no git user configured reads `unknown` instead of quietly attributing back to the agent. An explicit `--actor` wins outright either way. `resolve_actor` is the only caller of `get_git_user` for an entry's author, and every entry the CLI writes goes through it. The halves are separate pure functions, `session_actor` (the variable alone now) and `entry_actor`, tested without touching the process environment for the reason `colors_wanted` is split that way
- **The variable half is cached in a `OnceLock` and the git user in another**, the way `should_use_colors` is: neither input can change mid-run, and the git user costs a subprocess. Two caches rather than one is the whole point: baking the git user into the session's answer would make `--actor-from-git` read whatever the run's *first* call produced, since with the variable set that call never fetched git at all. `entry_actor` takes the git user as a closure so the subprocess is not run when something ahead of it already answered
- **The two flags are refused together at parse time**, clap `conflicts_with`: both answer who the entry is attributed to, and last-wins would be a silent answer to a contradictory call. `every_actor_command_takes_actor_from_git` walks the clap definition so the pair travels together onto any command that grows an `--actor`
- An **empty `WORKLANE_ACTOR` counts as unset**, the convention `colors_wanted` follows for `NO_COLOR`, so a wrapper script can clear an inherited one. Whitespace counts the same, since a shell quoting a missing value writes one
- **The actor is free text, checked against nothing**, like the `chown` user: there is no registry of actors, and the same reason `ls --tag` refuses to validate a tag
- **It was `comment --owner`, renamed with no alias.** Owner is the ticket's assignee and has one writer, `chown`; this names the writer of the entry, which is a different field. Pre-1.0, and two names for one thing is what splitting `set` and `chown` avoided. `the_owner_flag_is_gone` pins the refusal, since an alias kept "for now" is what makes the wrong name permanent
@@ -431,7 +437,7 @@ and this file is for what someone changing worklane's own code needs.
- **The stamp leads the filename and the kind follows it**, so the lexicographic sort in `read_history` stays chronological however many kinds there are. The collision suffix goes last, after the kind, and is a number, so it matches no slug and the counter skips it
- **A mechanical entry renders as one line and a comment as it always did.** A field change is one fact, and a paragraph for it would bury the comments it sits between. The labels are padded to `Kind::LABEL_WIDTH`, `campaign` being the longest of the four, so the bodies line up under each other
- **A campaign entry records `Campaign::name`, the codename or failing that the title, never the uuid the field holds.** Settled when the entry is written, not left to the renderer: a log is a record, and resolving at read time would let an entry change meaning when a campaign is renamed. A `before` uuid the board no longer has reads `_missing_`, the way the Campaign field itself renders a dangling one, and a ticket never assigned starts from `_Not set_` (f774a33)
- **`--actor` is on every command that writes an entry**, spelled from one `ACTOR_HELP` in `command.rs`: a flag documented differently on each command reads as four flags. On `chown` it sits beside `user`, which is the ticket's new assignee — the two are different questions and that command answers both
- **`--actor` is on every command that writes an entry**, spelled from one `ACTOR_HELP` in `command.rs`: a flag documented differently on each command reads as four flags. `--actor-from-git` rides beside it from its own one string, the same way. On `chown` it sits beside `user`, which is the ticket's new assignee — the two are different questions and that command answers both
- **`set --actor` reaches only the entry `--tags` writes**, since tags are the one field of that command's that is logged. Documented on the flag rather than left for a reader to notice from the absence of entries
### Shipping the Agent Assets
Generated
+1 -1
View File
@@ -1503,7 +1503,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.32.6"
version = "0.32.9"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.32.6"
version = "0.32.9"
edition = "2024"
[dependencies]
+2 -2
View File
@@ -17,7 +17,7 @@ Worklane is a local Kanban flow for agentic software development.
| `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 chown --clear <ticket>` returns the field to unset, taking the ticket in the flag since there is no user to give, and not to the git user `add` falls back to. Records an `owner` entry in the ticket's history, with the owner before and after; `--actor` names who made the change, which is not the same as the user argument |
| `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. The author is `--actor`, or `WORKLANE_ACTOR`, or the git user, in that order |
| `worklane comment <ticket> <body>` | Adds a comment to a ticket by UUID or title. The author is `--actor`, or `WORKLANE_ACTOR`, or the git user, in that order; `--actor-from-git` lifts the git user over `WORKLANE_ACTOR`, for acting on the person's behalf without knowing how they spell themselves, and is refused beside `--actor` |
| `worklane campaign add` | Files a campaign in `.worklane/campaigns/` with `--title`, `--description`, `--codename` and `--owner`. A campaign has no status: its state is derived, open until every member is done. `--codename` is one word to call it by, `v1` or `beaver`, which is what the board draws on every card in it and what every command that takes a campaign will also resolve it by |
| `worklane campaign set <campaign>` | Replaces `--title`, which renames the file keeping the uuid, `--description` and `--codename`. At least one required. The way a campaign filed before codenames existed gets one, and the way a description filed with a typo in it gets fixed. Replacing a codename the campaign already has needs `--force`, since that is the word it is referred to by everywhere; setting the one it already has is a no-op either way. A description needs no `--force`: it is prose written to be revised. No `--clear` and no `--owner` |
| `worklane campaign append <campaign>` | Adds a paragraph to a campaign's description with `--description`, which is required. The other half of `campaign set --description`, so adding a line to a description does not mean retyping the rest of it. Repeat the flag for more lines within the one paragraph. Its own subcommand rather than the top-level `append`, which resolves a ticket |
@@ -33,7 +33,7 @@ Worklane is a local Kanban flow for agentic software development.
| Variable | Effect |
|----------|--------|
| `WORKLANE_ACTOR` | Who every entry the CLI writes is attributed to: a comment, and the `status`, `owner` and `tags` entries `mv`, `chown` and `set --tags` record. Set it once, in the environment an agent runs in, and every call it makes is attributed to it instead of to the git user of whoever's machine it is on. `--actor` overrides it per call, an empty value counts as unset, and with neither supplied the author is the git user and then `unknown`. Free text, checked against nothing |
| `WORKLANE_ACTOR` | Who every entry the CLI writes is attributed to: a comment, and the `status`, `owner` and `tags` entries `mv`, `chown` and `set --tags` record. Set it once, in the environment an agent runs in, and every call it makes is attributed to it instead of to the git user of whoever's machine it is on. `--actor` overrides it per call and `--actor-from-git` lifts the git user over it per call (the two flags are refused together), an empty value counts as unset, and with neither supplied the author is the git user and then `unknown`. Free text, checked against nothing |
| `NO_COLOR` | Set and non-empty turns colour off, whatever the value, per no-color.org. Colour is also off when output is not a terminal, and when `TERM` is `dumb` or empty |
| `XDG_CONFIG_HOME` | Where `install-tool` looks for opencode's config root, `$XDG_CONFIG_HOME/opencode`, defaulting to `~/.config`. `install-skill` does not follow it: `~/.claude` is not an XDG path |
+10 -2
View File
@@ -374,12 +374,20 @@ Code, and the environment opencode is started with for opencode, since it passes
environment to the tools it runs.
**Reach for `--actor` only when the entry is somebody else's action**: the person asked
you to move a ticket, or to put words on the board as their comment, so name them on the
flag — the move was theirs and the words are theirs, and an entry carrying your name
you to move a ticket, or to put words on the board as their comment, so name them on
the flag — the move was theirs and the words are theirs, and an entry carrying your name
reads later as though you decided both. Otherwise leave it off, unless your instructions
say to use it. It is spelled the same on every command that writes an entry: `comment`,
`mv`, `chown`, `set` and `assign`.
Acting for the person without knowing how they spell themselves? `--actor-from-git`
attributes the entry to the detected git user instead of `WORKLANE_ACTOR`, so their name
is never needed. It cannot be combined with `--actor`, and a machine with no git user
configured has nobody to name: the entry reads `unknown` rather than falling back to your
variable.
```
worklane mv 1b78a24 --status done --actor "Ansho Rei"
```
worklane mv 1b78a24 --status done --actor "Ansho Rei"
```
+87 -20
View File
@@ -199,6 +199,13 @@ fn annotation_line(raw: &str) -> Result<String, String> {
/// command reads as five flags.
const ACTOR_HELP: &str = "Who the entry is attributed to, overriding WORKLANE_ACTOR and the git user. Free text, checked against nothing";
/// What `--actor-from-git` says on every command that writes a history entry.
///
/// The counterpart to [`ACTOR_HELP`]: where that one names somebody specific, this one
/// says attribute it to the human whose checkout this is, without knowing how they spell
/// themselves.
const ACTOR_FROM_GIT_HELP: &str = "Attribute the entry to the detected git user instead of WORKLANE_ACTOR, for acting on the person's behalf. Cannot be combined with --actor";
/// Arguments that carry prose, and therefore have to accept a value starting with
/// a hyphen.
///
@@ -229,26 +236,7 @@ pub enum Command {
},
/// Move a ticket to a different status
Mv {
/// Ticket UUID or title
ticket: String,
/// Target status
#[arg(short, long)]
status: Status,
/// Force move (allows backward or non-sequential moves)
#[arg(short, long)]
force: bool,
#[arg(long, help = ACTOR_HELP)]
actor: Option<String>,
/// Why the ticket moved, recorded in the history entry beside the transition
/// it explains. Prose, so it takes a leading hyphen
#[arg(long, allow_hyphen_values = PROSE)]
reason: Option<String>,
},
Mv(MvArgs),
/// Replace fields on an existing ticket
Set(SetArgs),
@@ -298,6 +286,9 @@ pub enum Command {
/// is `chown`'s. It was `--owner`, which said the wrong one of the two.
#[arg(long, help = ACTOR_HELP)]
actor: Option<String>,
#[arg(long, conflicts_with = "actor", help = ACTOR_FROM_GIT_HELP)]
actor_from_git: bool,
},
/// Group tickets that have to be finished together
@@ -323,6 +314,9 @@ pub enum Command {
#[arg(long, help = ACTOR_HELP)]
actor: Option<String>,
#[arg(long, conflicts_with = "actor", help = ACTOR_FROM_GIT_HELP)]
actor_from_git: bool,
},
/// The tag vocabulary: what the board carries, and what each tag means
@@ -700,6 +694,33 @@ pub struct AddArgs {
pub priority: Option<u8>,
}
/// `mv` grew past a handful of parameters when `--actor-from-git` arrived, so it is a
/// struct like `set` and `append` rather than an inline variant.
#[derive(clap::Args)]
pub struct MvArgs {
/// Ticket UUID or title
pub ticket: String,
/// Target status
#[arg(short, long)]
pub status: Status,
/// Force move (allows backward or non-sequential moves)
#[arg(short, long)]
pub force: bool,
#[arg(long, help = ACTOR_HELP)]
pub actor: Option<String>,
#[arg(long, conflicts_with = "actor", help = ACTOR_FROM_GIT_HELP)]
pub actor_from_git: bool,
/// Why the ticket moved, recorded in the history entry beside the transition
/// it explains. Prose, so it takes a leading hyphen
#[arg(long, allow_hyphen_values = PROSE)]
pub reason: Option<String>,
}
/// `set` replaces a field outright. Owner is deliberately absent: `chown` owns that
/// field, and status is `mv`'s, so no field has two writers.
///
@@ -764,6 +785,9 @@ pub struct SetArgs {
/// command's that is logged
#[arg(long, help = ACTOR_HELP)]
pub actor: Option<String>,
#[arg(long, conflicts_with = "actor", help = ACTOR_FROM_GIT_HELP)]
pub actor_from_git: bool,
}
impl SetArgs {
@@ -814,6 +838,9 @@ pub struct ChownArgs {
/// change. Both are on this command because it writes both.
#[arg(long, help = ACTOR_HELP)]
pub actor: Option<String>,
#[arg(long, conflicts_with = "actor", help = ACTOR_FROM_GIT_HELP)]
pub actor_from_git: bool,
}
impl ChownArgs {
@@ -1015,4 +1042,44 @@ mod tests {
for two minor versions."
);
}
/// `--actor` and `--actor-from-git` are one pair that has to travel together: every
/// command that takes one takes the other, documented by the same string, because
/// the second is the first's spelling for "the human whose checkout this is".
///
/// A walker rather than five named commands, so a sixth entry-writing command fails
/// this on its own `--actor` instead of being forgotten here too.
#[test]
fn every_actor_command_takes_actor_from_git() {
let cli = Cli::command();
let mut seen = 0;
for sub in cli.get_subcommands() {
if sub.get_name() == "help" {
continue;
}
if !sub.get_arguments().any(|arg| arg.get_id().as_str() == "actor") {
continue;
}
seen += 1;
let from_git = sub
.get_arguments()
.find(|arg| arg.get_id().as_str() == "actor_from_git")
.unwrap_or_else(|| {
panic!("`{}` takes --actor but not --actor-from-git", sub.get_name())
});
assert_eq!(
from_git.get_help().map(|help| help.to_string()),
Some(ACTOR_FROM_GIT_HELP.to_string()),
"`{}` documents --actor-from-git differently",
sub.get_name()
);
}
// A guard on the walker itself: if it stopped finding commands, every assertion
// above would pass by never running.
assert_eq!(seen, 5, "expected comment, mv, chown, set and assign to carry --actor");
}
}
+6 -6
View File
@@ -11,10 +11,10 @@
//! costs one `worklane ls --ids` per keypress, which measured at 2.5ms in release on a
//! board of seventy-five tickets, comfortably below anything a person notices.
//!
//! The four statuses are half clap's: `Status` is a `ValueEnum`, so it emits them for
//! `mv --status`, but the fish generator does not emit possible values for a *positional*
//! and `ls <status>` gets nothing. Same for `completions <shell>`. So the block below
//! lists those two, from the enums rather than by hand.
//! Status values are half clap's: `Status` is a `ValueEnum`, so clap emits every one
//! of them for `mv --status`, but the fish generator does not emit possible values for
//! a *positional* and `ls <status>` gets nothing. Same for `completions <shell>`. So
//! the block below lists those two, from the enums rather than by hand.
use std::io;
@@ -231,7 +231,7 @@ complete -c worklane -n '{tag_nested}' -a '(worklane tags | cut -f1,3)'
# has a `--clear` of its own that takes a field name, and clap already offers those.
complete -c worklane -n '__worklane_command_is chown' -l clear -x -a '(worklane ls --ids)'
# clap emits the four for `mv --status`, which is an option, but the fish generator
# clap emits the statuses for `mv --status`, which is an option, but the fish generator
# emits nothing for the possible values of a positional. So the one place a status is
# positional needs them listed, and the same goes for the shell below.
complete -c worklane -n '__worklane_first_arg_of ls' -a '{statuses}' -d status
@@ -616,7 +616,7 @@ mod tests {
}
}
/// The four for `mv --status` are clap's, which is half of why `Status` is a
/// The statuses for `mv --status` are clap's, which is half of why `Status` is a
/// `ValueEnum`. If clap ever stops emitting them, the fish half has to carry them
/// too, and this is what says so.
#[test]
+28 -27
View File
@@ -8,7 +8,7 @@ use std::path::Path;
use crate::campaign::*;
use crate::command::{
AddArgs, AppendArgs, CampaignAddArgs, CampaignAppendArgs, CampaignSetArgs, CheckArgs,
ChownArgs, LsArgs, RelateArgs, SetArgs, TagAddArgs, TagSetArgs,
ChownArgs, LsArgs, MvArgs, RelateArgs, SetArgs, TagAddArgs, TagSetArgs,
};
use crate::history::{Kind, change, format_history, read_history, write_entry};
use crate::install;
@@ -378,12 +378,8 @@ pub fn cmd_show(search: &str, worklane_dir: &Path) -> Result<()> {
/// What is being written, for the messages a failure carries.
///
/// A `&str` naming the thing rather than two copies of the write path: a campaign file is
/// a ticket file in every way that matters here, `<uuid>_<slug>.md` in a directory, and the
/// only difference is the word a failure has to use. Every message below puts it
/// mid-sentence so there is no capital to case.
const TICKET: &str = "ticket";
const CAMPAIGN: &str = "campaign";
/// `TICKET` and `CAMPAIGN` live in util.rs beside the writers that now carry the noun
/// too; only the tag is spelled here, being a file no ticket command writes.
const TAG: &str = "tag";
/// Write `content` over `path`, without ever leaving half a file behind.
@@ -602,14 +598,15 @@ fn check_dependents(worklane_dir: &Path, uuid: &str, title: &str) -> Result<()>
/// A status is a [`Status`] rather than a string, so an unknown one is clap's to refuse
/// and nothing here has to check. What is left is the order of the flow, which is
/// `Status::ALL`.
pub fn cmd_mv(
ticket_id: &str,
target: Status,
force: bool,
actor: &Option<String>,
reason: &Option<String>,
start: &Path,
) -> Result<()> {
pub fn cmd_mv(args: &MvArgs, start: &Path) -> Result<()> {
let MvArgs {
ticket: ticket_id,
status: target,
force,
actor,
actor_from_git,
reason,
} = args;
let target_status = target.as_str();
// A reason is one fact on one line, which is how the renderer draws it, so a
@@ -628,13 +625,13 @@ pub fn cmd_mv(
.iter()
.position(|status| status.as_str() == current_status)
.unwrap();
let target_idx = Status::ALL.iter().position(|status| *status == target).unwrap();
let target_idx = Status::ALL.iter().position(|status| *status == *target).unwrap();
// Discarding is not a stage of work, so the walk rules below do not apply to
// entering it: a ticket is abandoned from wherever it stands. They do apply to
// leaving it, which with discarded last in `Status::ALL` is always a backward move,
// so un-discarding needs `-f` with no rule of its own.
let discarding = target == Status::Discarded;
let discarding = *target == Status::Discarded;
if !force && !discarding && target_idx < current_idx {
return Err(anyhow!(
@@ -721,7 +718,7 @@ pub fn cmd_mv(
// crash-safe write the Status field does.
let content = set_status_stamp(
&content,
target,
*target,
&Local::now().format(TIMESTAMP_FORMAT).to_string(),
&title,
)?;
@@ -746,7 +743,7 @@ pub fn cmd_mv(
&parse_ticket_field(&resolved, "ID"),
Kind::Status,
&change(&current_status, target_status),
&resolve_actor(actor.as_deref()),
&resolve_actor(actor.as_deref(), *actor_from_git),
&reason,
)?;
@@ -764,6 +761,7 @@ pub fn cmd_comment(
ticket_id: &str,
body: &str,
actor: &Option<String>,
actor_from_git: bool,
start: &Path,
) -> Result<()> {
if body.is_empty() {
@@ -783,7 +781,7 @@ pub fn cmd_comment(
&ticket_uuid,
Kind::Comment,
body,
&resolve_actor(actor.as_deref()),
&resolve_actor(actor.as_deref(), actor_from_git),
"",
)?;
@@ -967,7 +965,7 @@ pub fn cmd_set(args: &SetArgs, start: &Path) -> Result<()> {
let mut cleared: Vec<&str> = Vec::new();
if let Some(new_title) = &args.title {
let next = set_title(&content, new_title)?;
let next = set_title(&content, new_title, TICKET)?;
apply(&mut content, &mut changed, "title", next);
}
@@ -1032,7 +1030,7 @@ pub fn cmd_set(args: &SetArgs, start: &Path) -> Result<()> {
&parse_ticket_field(&original, "Tags"),
&parse_ticket_field(&content, "Tags"),
),
&resolve_actor(args.actor.as_deref()),
&resolve_actor(args.actor.as_deref(), args.actor_from_git),
"",
)?;
}
@@ -1091,7 +1089,7 @@ pub fn cmd_chown(args: &ChownArgs, start: &Path) -> Result<()> {
&parse_ticket_field(&original, "Owner"),
&parse_ticket_field(&content, "Owner"),
),
&resolve_actor(args.actor.as_deref()),
&resolve_actor(args.actor.as_deref(), args.actor_from_git),
"",
)?;
@@ -1674,7 +1672,7 @@ pub fn cmd_campaign_set(args: &CampaignSetArgs, start: &Path) -> Result<()> {
let mut changed: Vec<&str> = Vec::new();
if let Some(new_title) = &args.title {
let next = set_title(&content, new_title)?;
let next = set_title(&content, new_title, CAMPAIGN)?;
apply(&mut content, &mut changed, "title", next);
}
@@ -1689,7 +1687,8 @@ pub fn cmd_campaign_set(args: &CampaignSetArgs, start: &Path) -> Result<()> {
}
if let Some(codename) = &args.codename {
let next = set_or_insert_metadata_field(&content, CODENAME_FIELD, codename, &title)?;
let next =
set_or_insert_metadata_field(&content, CODENAME_FIELD, codename, CAMPAIGN, &title)?;
apply(&mut content, &mut changed, "codename", next);
}
@@ -1775,6 +1774,7 @@ pub fn cmd_assign(
campaign_search: &str,
ticket_id: &str,
actor: &Option<String>,
actor_from_git: bool,
start: &Path,
) -> Result<()> {
let worklane_dir = find_worklane_dir(start)?;
@@ -1782,7 +1782,8 @@ pub fn cmd_assign(
let (status, title, original) = resolve_ticket(ticket_id, &worklane_dir)?;
let uuid = parse_ticket_field(&original, "ID");
let content = set_or_insert_metadata_field(&original, CAMPAIGN_FIELD, &campaign.uuid, &title)?;
let content =
set_or_insert_metadata_field(&original, CAMPAIGN_FIELD, &campaign.uuid, TICKET, &title)?;
if content == original {
println!(
@@ -1812,7 +1813,7 @@ pub fn cmd_assign(
&uuid,
Kind::Campaign,
&change(&before, campaign.name()),
&resolve_actor(actor.as_deref()),
&resolve_actor(actor.as_deref(), actor_from_git),
"",
)?;
+13 -13
View File
@@ -57,22 +57,19 @@ fn main() -> Result<()> {
let worklane_dir = find_worklane_dir(&start)?;
cmd_show(&id, &worklane_dir)
}
Some(Command::Mv {
ticket,
status,
force,
actor,
reason,
}) => cmd_mv(&ticket, status, force, &actor, &reason, &start),
Some(Command::Mv(args)) => cmd_mv(&args, &start),
Some(Command::Set(args)) => cmd_set(&args, &start),
Some(Command::Append(args)) => cmd_append(&args, &start),
Some(Command::Relate(args)) => cmd_relate(&args, &start),
Some(Command::Chown(args)) => cmd_chown(&args, &start),
Some(Command::Check(args)) => cmd_check(&args, true, &start),
Some(Command::Uncheck(args)) => cmd_check(&args, false, &start),
Some(Command::Comment { ticket, body, actor }) => {
cmd_comment(&ticket, &body, &actor, &start)
}
Some(Command::Comment {
ticket,
body,
actor,
actor_from_git,
}) => cmd_comment(&ticket, &body, &actor, actor_from_git, &start),
Some(Command::Campaign { command }) => match command {
CampaignCommand::Add(args) => cmd_campaign_add(&args, &start),
CampaignCommand::Ls { ids } => {
@@ -86,9 +83,12 @@ fn main() -> Result<()> {
cmd_campaign_show(&campaign, &worklane_dir)
}
},
Some(Command::Assign { campaign, ticket, actor }) => {
cmd_assign(&campaign, &ticket, &actor, &start)
}
Some(Command::Assign {
campaign,
ticket,
actor,
actor_from_git,
}) => cmd_assign(&campaign, &ticket, &actor, actor_from_git, &start),
// The bare form and `ls` are one arm: `worklane tags` was the listing before the
// group existed and the fish completion still calls it that way, so the two
// spellings cannot be allowed to drift into two behaviours.
+582 -79
View File
@@ -159,7 +159,8 @@ pub enum Focus {
Frame,
}
/// What a tab's columns are cut down to: one campaign, one tag, or the whole board.
/// What a tab's columns are cut down to: one campaign, one tag, no campaign at all, or the
/// whole board.
///
/// A type rather than two `Option<String>` fields and a rule that only one may be set. The
/// board has one frame slot above the columns and it names what the columns are showing, so
@@ -174,6 +175,13 @@ pub enum Focus {
/// whole and case sensitively, and the same word means the same thing on every board. That
/// is why the merge tab can carry a tag filter where it could not carry another project's
/// campaign.
///
/// The absence of a campaign is its own variant rather than a value inside [`Filter::Campaign`]:
/// [`retain_campaign`] compares the field to the uuid it is given, so the tickets in no
/// campaign are a different predicate over the field and not a different value in it — and a
/// magic uuid meaning none is exactly the kind of thing that later matches a real one. Being
/// keyed on nothing is also why it crosses boards where a campaign cannot, the property a
/// tag filter already has on the merge tab.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub enum Filter {
/// Every card the tab holds, which is where a tab opens.
@@ -181,15 +189,18 @@ pub enum Filter {
Whole,
Campaign(String),
Tag(String),
/// Only the cards whose Campaign field is unset: the pile no campaign gathers.
NoCampaign,
}
impl Filter {
/// The campaign this filters to, or nothing for a tag filter or none.
/// The campaign this filters to, or nothing for any other filter.
///
/// What the campaign frame draws itself from, and what tells a filter that resolves
/// against the campaigns directory from one that resolves against nothing. The frame,
/// the focus and the geometry ask [`Filter::is_whole`] instead: either filter draws a
/// frame, so either can hold the selection above the columns.
/// What tells a filter that resolves against the campaigns directory from one that
/// resolves against nothing. The no-campaign filter answers nothing here too, being a
/// predicate over the field rather than a value in it; the frame, the focus and the
/// geometry ask [`Filter::is_whole`] instead: every filter draws a frame, so any can
/// hold the selection above the columns.
pub fn campaign(&self) -> Option<&str> {
match self {
Filter::Campaign(uuid) => Some(uuid),
@@ -312,6 +323,10 @@ pub struct Column {
pub cards: Vec<Card>,
}
/// What one reload builds for one tab: its columns, what it can be filtered by, and how
/// many tickets on it name no campaign.
type Reloaded = (Vec<Column>, Vec<CampaignRow>, Vec<TagRow>, usize);
/// A campaign as the board holds it: what the picker lists and what the frame draws.
///
/// Read at reload from the one pass over the campaigns directory, the same pass that names
@@ -446,7 +461,18 @@ pub struct Tab {
/// tab's `bug` is one row standing for every board's, and filtering to it cuts all of
/// them at once.
pub tags: Vec<TagRow>,
/// What the columns are cut down to: one campaign, one tag, or the whole board.
/// How many tickets on this tab name no campaign, drawn or not.
///
/// Counted at reload off the columns before either filter is applied to them, for the
/// reason the standings are: how many tickets are in no campaign is not a question about
/// what the tab is currently showing, and a count taken off the filtered columns would
/// answer zero about itself. The picker's first row draws it and the frame repeats it.
///
/// On the merge tab it is every board's, summed — an unset field means the same thing in
/// every `.worklane`, which is why this filter crosses boards where a campaign cannot.
pub no_campaign: usize,
/// What the columns are cut down to: one campaign, one tag, no campaign, or the whole
/// board.
///
/// Per tab rather than on the `Board`, the way the selection is. A campaign belongs to
/// one `.worklane`, so a filter carried across to another project's tab would empty it
@@ -486,6 +512,7 @@ impl Tab {
offsets: Vec::new(),
campaigns: Vec::new(),
tags: Vec::new(),
no_campaign: 0,
filter: Filter::default(),
focus: Focus::default(),
expanded: false,
@@ -715,8 +742,8 @@ pub struct Picker {
/// On the picker rather than on the board, for the reason the row and the query are:
/// "a picker is open" and "what it is choosing between" cannot disagree, and closing it
/// leaves nothing to reset. Everything about moving, querying and scrolling is the same
/// either way; this decides only what `picker_list` builds and what `take_picked` does
/// with the answer.
/// either way; this decides only what `picker_list` builds, the answer carrying its own
/// kind back to `take_picked`.
pub kind: PickerKind,
/// Which *drawn* row the highlight is on, headings and the truncation line included,
/// so it and `offset` are counted in the same units and `picker_list` is the one place
@@ -763,31 +790,68 @@ const COMPLETED_SHOWN: usize = 2;
/// is. Nothing here is held on the `Picker`: the rows are derived on every draw and every
/// keypress, which is what lets a campaign filed elsewhere reach an open picker on the next
/// tick instead of being missing from a copy taken when it opened.
#[derive(Debug)]
enum PickerRow<'a> {
/// A section heading, naming what the rows under it are.
Heading(&'static str),
Campaign(&'a CampaignRow),
Tag(&'a TagRow),
/// The tickets whose Campaign field is unset, with how many they are.
NoCampaign(usize),
/// How many older completed campaigns the truncation is keeping back.
Hidden(usize),
/// The query matched nothing, said in the box rather than left as an empty one.
Missed,
}
/// What taking a picker row selects, kept across a rebuild of the list.
///
/// A campaign is keyed by its uuid and a tag by itself — both strings the tab can be
/// filtered by, which is what [`PickerRow::key`] handed back when those were the only two
/// rows. The third answer names nothing on any file: the no-campaign row filters on the
/// *absence* of a value, so it is its own variant here rather than an empty string standing
/// in for one, and `take_picked` reads the kind off the key instead of off which list was
/// open.
///
/// Owned rather than borrowed, because the highlight has to outlive the rows it was read
/// from: `reload` takes it before the lists are rebuilt and puts it back after.
#[derive(Clone, Debug, PartialEq, Eq)]
enum PickerKey {
Campaign(String),
Tag(String),
NoCampaign,
}
impl PickerKey {
/// What a test would call this answer, so a highlight can be named without reaching
/// for a row number the sections have already moved.
#[cfg(test)]
fn name(&self) -> &str {
match self {
PickerKey::Campaign(uuid) => uuid,
PickerKey::Tag(name) => name,
PickerKey::NoCampaign => NO_CAMPAIGN_ROW,
}
}
}
/// What the no-campaign row and its frame are called, everywhere they are drawn.
const NO_CAMPAIGN_ROW: &str = "no campaign";
impl PickerRow<'_> {
/// What taking this row would filter the board to, or nothing for a row of chrome.
///
/// One accessor for both kinds, which is what lets everything between the keypress and
/// the filter — the step over selectable rows, the highlight kept across a rebuild, the
/// value `enter` takes — be written once. A campaign is keyed by its uuid and a tag by
/// itself, and both are a string the tab can be filtered by.
/// value `enter` takes — be written once.
///
/// `None` is also the test of whether a row can be highlighted at all, so a heading or
/// the truncation line is stepped over rather than landed on.
fn key(&self) -> Option<&str> {
fn key(&self) -> Option<PickerKey> {
match self {
PickerRow::Campaign(campaign) => Some(&campaign.uuid),
PickerRow::Tag(tag) => Some(&tag.name),
PickerRow::Campaign(campaign) => Some(PickerKey::Campaign(campaign.uuid.clone())),
PickerRow::Tag(tag) => Some(PickerKey::Tag(tag.name.clone())),
PickerRow::NoCampaign(_) => Some(PickerKey::NoCampaign),
_ => None,
}
}
@@ -830,7 +894,7 @@ fn picker_list<'a>(tab: &'a Tab, picker: &Picker) -> Vec<PickerRow<'a>> {
rows
}
/// The campaign rows: open above completed, the completed tail truncated.
/// The campaign rows: the tickets in no campaign above open above completed.
fn campaign_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec<PickerRow<'a>> {
let (mut completed, open): (Vec<&CampaignRow>, Vec<&CampaignRow>) = tab
.campaigns
@@ -845,6 +909,13 @@ fn campaign_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec<PickerRow<'a>> {
}
let mut rows: Vec<PickerRow> = Vec::new();
// First and never truncated, so it is reachable without scrolling on a board whose
// completed tail would otherwise push it down: the pile is the one question about a
// board of campaigns that no single campaign answers. Not under either heading — it
// is not a campaign, and a section naming what its rows are would be lying about it.
if no_campaign_matches(query) {
rows.push(PickerRow::NoCampaign(tab.no_campaign));
}
if !open.is_empty() {
rows.push(PickerRow::Heading(OPEN_SECTION));
rows.extend(open.into_iter().map(PickerRow::Campaign));
@@ -914,6 +985,22 @@ fn picker_matches(campaign: &CampaignRow, query: &str) -> bool {
|| campaign.title.to_lowercase().contains(&query)
}
/// Whether the no-campaign row answers the query: the words a reader would type for it.
///
/// "no campaign" is what the row says, and "none" is the shorter way to ask for the same
/// thing; both are matched as substrings, so a query still being typed narrows the same way
/// it does over the campaigns. The row carries no id, no codename and no title — there is
/// nothing else on it to be found by, which is the rule `picker_matches` holds: a row is
/// found by what it draws.
fn no_campaign_matches(query: &str) -> bool {
let query = query.trim().to_lowercase();
if query.is_empty() {
return true;
}
NO_CAMPAIGN_ROW.to_lowercase().contains(&query) || "none".contains(&query)
}
/// Whether a tag answers the query: the tag itself, or what it is annotated to mean.
///
/// The two things the row draws, which is the rule `picker_matches` follows for a campaign.
@@ -1094,6 +1181,7 @@ impl Board {
let mut per_columns: Vec<Vec<Column>> = Vec::new();
let mut per_campaigns: Vec<Vec<CampaignRow>> = Vec::new();
let mut per_tags: Vec<Vec<TagRow>> = Vec::new();
let mut per_no_campaign: Vec<usize> = Vec::new();
for project in &self.projects {
let (columns, campaigns, tags) = columns_of(&project.dir);
// The project is named on a row only where it has to be. On a single board
@@ -1110,6 +1198,8 @@ impl Board {
// Counted off the same unfiltered columns, and for the same reason: how many
// tickets carry a tag is not a question about what the tab is showing.
per_tags.push(tag_rows(&tags, &columns));
// And this one beside them: how many tickets name no campaign at all.
per_no_campaign.push(no_campaign_count(&columns));
per_columns.push(columns);
}
@@ -1118,17 +1208,18 @@ impl Board {
// survive the rebuild, the way `Tab::campaign` is a uuid and not an index.
let highlighted = self.picked();
let mut built: Vec<(Vec<Column>, Vec<CampaignRow>, Vec<TagRow>)> = Vec::new();
let mut built: Vec<Reloaded> = Vec::new();
if merged {
// Every board's campaigns under the merge, each carrying the project it was
// filed in: on that tab an id says which campaign but not which board holds it.
// The tags merge by name instead, since the same word is the same tag on every
// board.
// board. The unset field adds across boards, being keyed on nothing.
let campaigns = per_campaigns.iter().flatten().cloned().collect();
built.push((
merge(&per_columns, &self.projects),
campaigns,
merged_tag_rows(&per_tags),
per_no_campaign.iter().sum(),
));
}
built.extend(
@@ -1136,12 +1227,16 @@ impl Board {
.into_iter()
.zip(per_campaigns)
.zip(per_tags)
.map(|((columns, campaigns), tags)| (columns, campaigns, tags)),
.zip(per_no_campaign)
.map(|(((columns, campaigns), tags), no_campaign)| {
(columns, campaigns, tags, no_campaign)
}),
);
for (tab, (columns, campaigns, tags)) in self.tabs.iter_mut().zip(built) {
for (tab, (columns, campaigns, tags, no_campaign)) in self.tabs.iter_mut().zip(built) {
tab.campaigns = campaigns;
tab.tags = tags;
tab.no_campaign = no_campaign;
// A selection whose campaign has left the board goes back to the whole board
// rather than filtering it to nothing: the frame would have nothing to name and
// every column would be empty, which reads as a board that has lost its
@@ -1168,8 +1263,15 @@ impl Board {
tab.expanded = false;
tab.frame_offset = 0;
}
tab.columns =
retain_tag(retain_campaign(columns, tab.filter.campaign()), tab.filter.tag());
// The campaign filter and its opposite are two predicates over the one field,
// which is why they are decided in the same breath here rather than by a flag
// somewhere on the filter.
let columns = match &tab.filter {
Filter::Campaign(uuid) => retain_campaign(columns, uuid),
Filter::NoCampaign => retain_no_campaign(columns),
Filter::Whole | Filter::Tag(_) => columns,
};
tab.columns = retain_tag(columns, tab.filter.tag());
// One scroll position per column, kept by index. A tick that adds or removes
// columns is not a thing statuses do, but the resize keeps the two in step
// regardless; `resize` both pads and truncates.
@@ -1182,7 +1284,7 @@ impl Board {
// And put back, on the campaign rather than on the number: one filed or finished
// elsewhere splits the list differently, so the row that held it has moved.
if self.picker.is_some() {
self.place_picker(highlighted.as_deref());
self.place_picker(highlighted.as_ref());
}
// The selected ticket may have moved or gone, so the open detail follows it.
@@ -1417,10 +1519,20 @@ impl Board {
pub fn open_picker(&mut self, kind: PickerKind, screen: Size) {
let tab = self.current();
let (empty, held) = match kind {
PickerKind::Campaign => {
(tab.campaigns.is_empty(), tab.filter.campaign().map(str::to_string))
}
PickerKind::Tag => (tab.tags.is_empty(), tab.filter.tag().map(str::to_string)),
PickerKind::Campaign => (
tab.campaigns.is_empty(),
// Either campaign answer holds its row: a filter to one campaign opens on
// it, and a filter to no campaign opens on that row.
match &tab.filter {
Filter::Campaign(uuid) => Some(PickerKey::Campaign(uuid.clone())),
Filter::NoCampaign => Some(PickerKey::NoCampaign),
Filter::Whole | Filter::Tag(_) => None,
},
),
PickerKind::Tag => (
tab.tags.is_empty(),
tab.filter.tag().map(|tag| PickerKey::Tag(tag.to_string())),
),
};
if empty {
@@ -1433,14 +1545,15 @@ impl Board {
}
self.picker = Some(Picker { kind, ..Picker::default() });
self.place_picker(held.as_deref());
self.place_picker(held.as_ref());
// The list is taller than the box on a board with many tags, so the highlight has
// to be brought into it rather than left at an offset the last picker had.
self.align_picker(screen);
}
/// What the highlight is on, as the string that would filter the board: a campaign's
/// uuid or a tag. Nothing when the picker is closed or the highlight is on chrome.
/// What the highlight is on, as the answer taking it would filter the board to: a
/// campaign, a tag, or no campaign. Nothing when the picker is closed or the highlight
/// is on chrome.
///
/// Through the drawn list rather than by indexing the tab's own list, because that is
/// what the row number counts: the sections reorder the rows and add rows of their own,
@@ -1449,31 +1562,39 @@ impl Board {
/// Owned rather than borrowed, unlike the campaign row it used to hand back. Every
/// caller wanted the key and cloned it, and a borrow of the board is exactly what a
/// caller about to mutate the board cannot hold.
fn picked(&self) -> Option<String> {
fn picked(&self) -> Option<PickerKey> {
let picker = self.picker.as_ref()?;
picker_list(self.current(), picker)
.get(picker.row)?
.key()
.map(str::to_string)
picker_list(self.current(), picker).get(picker.row)?.key()
}
/// Put the highlight on `uuid`, or on the first row that can be taken.
/// Put the highlight on `key`, or on the first row that can be taken.
///
/// By uuid rather than by keeping the number, the answer `Tab::campaign` gives for the
/// By key rather than by keeping the number, the answer `Tab::campaign` gives for the
/// filter: a query typed into or a tick that finishes a campaign reshapes the list, and
/// a number kept across that names whichever campaign now sits at it. A campaign the
/// list no longer holds leaves nothing to hold on to, so the highlight goes to the top
/// of what is there — which is where an incremental filter puts it anyway.
/// a number kept across that names whichever campaign now sits at it. A row the list no
/// longer holds leaves nothing to hold on to, so the highlight goes to the top of what
/// is there — which is where an incremental filter puts it anyway.
///
/// The top is deliberately not where it starts: the fallback skips the no-campaign row
/// and lands on the first campaign, which is what this picker has always opened on and
/// still the common thing asked of it. The no-campaign row sits above the list without
/// claiming it — reachable in one step up, and holding the highlight whenever it was the
/// row selected. Only when every campaign is hidden — a query matching the pile alone —
/// does it take the opening highlight.
///
/// A list of nothing but chrome puts it on row zero, where `take_picked` finds no
/// campaign and does nothing.
fn place_picker(&mut self, key: Option<&str>) {
fn place_picker(&mut self, key: Option<&PickerKey>) {
let Some(picker) = &self.picker else { return };
let rows = picker_list(self.current(), picker);
let held = key.and_then(|key| rows.iter().position(|row| row.key() == Some(key)));
let held = key.and_then(|key| rows.iter().position(|row| row.key().as_ref() == Some(key)));
let at = held
.or_else(|| {
rows.iter()
.position(|row| row.key().is_some_and(|key| key != PickerKey::NoCampaign))
})
.or_else(|| rows.iter().position(|row| row.key().is_some()))
.unwrap_or(0);
@@ -1561,7 +1682,7 @@ impl Board {
};
edit(&mut picker.query);
self.place_picker(held.as_deref());
self.place_picker(held.as_ref());
self.align_picker(screen);
}
@@ -1619,29 +1740,27 @@ impl Board {
picker.offset = aligned_offset(picker.offset, start, start + 1, height, count);
}
/// Take the highlighted campaign and close the picker.
/// Take the highlighted row and close the picker.
///
/// A highlight on nothing takeable — the `no match` row, or a list of chrome — leaves
/// the picker and the query exactly as they are, so the query can be corrected in place.
/// That is what the search prompt does with a miss, and for the same reason: doing
/// nothing visible is what makes a reader retype a query that was already right.
fn take_picked(&mut self, screen: Size) {
let Some(picker) = &self.picker else { return };
let kind = picker.kind;
let Some(key) = self.picked() else {
return;
};
self.picker = None;
// The key is a uuid or a tag depending on which list was open, which is the one
// thing about a picker that its kind decides rather than its rows.
self.select_filter(
match kind {
PickerKind::Campaign => Filter::Campaign(key),
PickerKind::Tag => Filter::Tag(key),
},
screen,
);
// The key carries which list it came from: a campaign row keys a campaign and a tag
// row keys a tag, so the kind is read off the answer rather than asked of a picker
// that has just been put away.
let filter = match key {
PickerKey::Campaign(uuid) => Filter::Campaign(uuid),
PickerKey::Tag(name) => Filter::Tag(name),
PickerKey::NoCampaign => Filter::NoCampaign,
};
self.select_filter(filter, screen);
}
/// Cut the tab in view down to one campaign or one tag, or back to the whole board.
@@ -1833,11 +1952,16 @@ impl Board {
/// command that takes a campaign resolves. A tag has no id to shorten: it *is* its name,
/// which is what `ls --tag` matches whole and case sensitively, so the whole word goes
/// on the clipboard and the hash the border draws does not — `--tag` would not match it.
///
/// The no-campaign frame has neither: no id to shorten, and no word a command line takes,
/// since `ls --campaign` cannot say none — that spelling is its own ticket. `y` on this
/// frame answers "nothing to copy", and the footer leaves it unnamed rather than naming
/// a key into a notice.
fn frame_id(&self) -> Option<String> {
let tab = self.current();
match &tab.filter {
Filter::Whole => None,
Filter::Whole | Filter::NoCampaign => None,
Filter::Campaign(_) => tab
.selected_campaign()
.map(|campaign| short_id(&campaign.uuid).to_string()),
@@ -2396,11 +2520,7 @@ fn standings_of(columns: &[Column]) -> HashMap<&str, Standing> {
/// the answer is one column per status and the question is how many are in each. Filtered here,
/// where the columns are built, so nothing downstream has to ask whether a campaign is
/// selected — the board simply holds fewer cards.
fn retain_campaign(mut columns: Vec<Column>, campaign: Option<&str>) -> Vec<Column> {
let Some(uuid) = campaign else {
return columns;
};
fn retain_campaign(mut columns: Vec<Column>, uuid: &str) -> Vec<Column> {
for column in columns.iter_mut() {
column
.cards
@@ -2410,6 +2530,39 @@ fn retain_campaign(mut columns: Vec<Column>, campaign: Option<&str>) -> Vec<Colu
columns
}
/// The opposite predicate over the same field: only the tickets that name no campaign.
///
/// A different question from [`retain_campaign`] and not a different value in it — comparing
/// against a uuid that means none would be one rename or one reused id away from matching a
/// real campaign. The field's absence is the whole test: a ticket whose Campaign names a uuid
/// no campaign carries is *set* wrongly, not unset, and stays out of this view the way it
/// draws `_missing_` on its own card rather than nothing at all.
///
/// Every column kept, empty ones included, for the reason `retain_campaign` keeps them. The
/// count beside this filter is [`Tab::no_campaign`], taken off the unfiltered columns; what
/// this answers is which cards survive it.
fn retain_no_campaign(mut columns: Vec<Column>) -> Vec<Column> {
for column in columns.iter_mut() {
column.cards.retain(|card| card.ticket.campaign.is_none());
}
columns
}
/// How many tickets name no campaign, counted off one board's columns.
fn no_campaign_count(columns: &[Column]) -> usize {
columns
.iter()
.map(|column| {
column
.cards
.iter()
.filter(|card| card.ticket.campaign.is_none())
.count()
})
.sum()
}
/// The label for the campaign a ticket names, or nothing when it names none.
///
/// Nothing, too, for a uuid the index does not hold. `campaign_cells` renders that case as
@@ -2708,11 +2861,17 @@ struct FrameContent {
/// What the tab's filter has to say for itself, or nothing when it is showing the whole
/// board.
///
/// **The one place the two filters are told apart above the columns.** Everything the draw
/// **The one place the filters are told apart above the columns.** Everything the draw
/// does with this is the same either way — the borders, the colour, the way out, the page
/// indicator and the scroll are all the campaign frame's, and a tag fills its slots rather
/// than inventing a second shape. A second `match` on the filter anywhere below here is how
/// the two frames come to behave differently in a way nobody decided.
/// the frames come to behave differently in a way nobody decided.
///
/// The no-campaign filter fills the same slots in its own words rather than being left
/// frameless: `is_whole()` is what decides both that a frame is drawn and that
/// [`Focus::Frame`] can hold the selection, and exempting one variant from either half would
/// be a state where the selection rests on a frame that is not drawn — the one thing
/// [`Focus`] exists to make unrepresentable.
///
/// Nothing, too, for a filter that resolves to no row: `reload` clears both of those, so
/// this is the answer to a draw that arrives before it rather than a state the board holds.
@@ -2729,6 +2888,11 @@ fn frame_content(tab: &Tab, width: u16) -> Option<FrameContent> {
standing: count_spans(tag.count),
prose: tag_prose(tag),
}),
Filter::NoCampaign => Some(FrameContent {
title: no_campaign_title(width),
standing: count_spans(tab.no_campaign),
prose: no_campaign_prose(),
}),
}
}
@@ -2911,6 +3075,19 @@ fn tag_prose(tag: &TagRow) -> Text<'static> {
}
}
/// What the no-campaign view is, as its frame says it.
///
/// The title names the filter and this says what the columns under it are, which a tag's
/// annotation and a campaign's description answer for their own frames. No file holds words
/// for an absence, so the sentence is the board's own — grey like the title, being the same
/// fact about the same unset field rather than prose anyone wrote.
fn no_campaign_prose() -> Text<'static> {
Text::from(Line::from(Span::styled(
"Tickets that name no campaign.",
Style::default().fg(Color::Grey.into()),
)))
}
/// The tag frame's title: `#tag`, in the colour a card draws it in, cut to the border.
///
/// The hash is what a card and `labels_line` already put in front of a tag, and it earns its
@@ -2991,6 +3168,29 @@ fn campaign_title(campaign: &CampaignRow, frame_width: u16) -> Vec<Span<'static>
]
}
/// The no-campaign frame's title: the words, and nothing else.
///
/// No id — there is no thing on the board to address — and no mark, which keeps `~` meaning
/// a campaign and `#` meaning a tag. Grey, because this view is the Campaign field's unset
/// state drawn out, and grey is what the palette gives `_Not set_`: the border around it says
/// where the reader is, the words say what they are looking at. Cut by hand like
/// [`tag_title`] and [`campaign_title`], since ratatui truncates a block title at whatever
/// cell it reaches.
fn no_campaign_title(frame_width: u16) -> Vec<Span<'static>> {
let room = frame_width.saturating_sub(2) as usize;
let whole = format!(" {NO_CAMPAIGN_ROW} ");
let text = match whole.chars().count() <= room {
true => whole,
false => match room.checked_sub(3).filter(|keep| *keep > 0) {
Some(keep) => format!(" {} ", with_ellipsis(NO_CAMPAIGN_ROW, keep)),
None => String::new(),
},
};
vec![Span::styled(text, Style::default().fg(Color::Grey.into()))]
}
fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) {
// Only the drawn columns are measured, so hiding done gives its width back to the
// three that are left rather than leaving a gap where it was.
@@ -3599,10 +3799,13 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
};
// What `y` copies where the selection is. A tag is its own id, so naming it one would
// send the reader looking for seven characters on a border that prints a word.
// send the reader looking for seven characters on a border that prints a word. Nothing
// on the no-campaign frame, which has neither — the key is left out of its footer
// rather than named into a notice.
let copied = match board.current().filter {
Filter::Tag(_) => "copy tag",
_ => "copy id",
Filter::Tag(_) => Some("copy tag"),
Filter::NoCampaign => None,
Filter::Whole | Filter::Campaign(_) => Some("copy id"),
};
let mut hints: Vec<(&str, &str)> = Vec::new();
@@ -3631,13 +3834,17 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
("y", "copy id"),
("↵/q", "close"),
]),
(false, Focus::Frame) => hints.extend([
("↓", "board"),
("↵", height),
("pgup/pgdn", "scroll"),
("/", "search"),
("y", copied),
]),
(false, Focus::Frame) => {
hints.extend([
("↓", "board"),
("↵", height),
("pgup/pgdn", "scroll"),
("/", "search"),
]);
if let Some(copied) = copied {
hints.push(("y", copied));
}
}
(false, Focus::Cards) => {
hints.extend([("←→", "column"), ("↑↓", "card"), ("/", "search")]);
hints.extend_from_slice(filter);
@@ -3874,6 +4081,7 @@ fn picker_row_line(row: &PickerRow, selected: bool, width: u16) -> Line<'static>
match row {
PickerRow::Campaign(campaign) => picker_line(campaign, selected, width),
PickerRow::Tag(tag) => tag_picker_line(tag, selected, width),
PickerRow::NoCampaign(count) => no_campaign_line(*count, selected),
PickerRow::Heading(name) => {
Line::from(Span::styled((*name).to_string(), grey.add_modifier(Modifier::BOLD)))
}
@@ -3947,6 +4155,30 @@ fn tag_picker_line(tag: &TagRow, selected: bool, width: u16) -> Line<'static> {
Line::from(spans)
}
/// The no-campaign row: `no campaign 12`.
///
/// Words where a campaign carries an id, because that is what the filter is: not a thing on
/// the board but the absence of one, with nothing to mark and nothing to shorten. Grey, for
/// the same reason the frame's title is — the Campaign field of everything this view holds is
/// unset, and grey is what the palette gives `_Not set_`.
///
/// The count is what the row is chosen on as much as its name, the trade `tag_picker_line`
/// makes: it says what picking this will give, including zero, so an empty board is seen
/// coming before the reader presses anything.
fn no_campaign_line(count: usize, selected: bool) -> Line<'static> {
let emphasis = match selected {
true => Modifier::REVERSED,
false => Modifier::empty(),
};
let grey = Style::default().fg(Color::Grey.into()).add_modifier(emphasis);
Line::from(vec![
Span::styled(NO_CAMPAIGN_ROW.to_string(), grey),
Span::raw(" "),
Span::styled(count.to_string(), grey),
])
}
/// One picker row: `(1b78a24) ~beaver What the campaign is for`.
///
/// The highlight is `REVERSED`, the way a selected card is, so the row reads the same
@@ -8352,7 +8584,7 @@ approach";
/// The uuid the highlight is on, so a test can name it without reaching for a row
/// number the sections have already moved.
fn highlighted(board: &Board) -> Option<String> {
board.picked()
board.picked().map(|key| key.name().to_string())
}
/// Which drawn row is exactly this heading, since a heading is the whole of its row.
@@ -10383,7 +10615,12 @@ approach";
board.select_filter(Filter::Campaign(V1.to_string()), SCREEN);
board.open_picker(PickerKind::Campaign, SCREEN);
assert_eq!(board.picked().as_deref(), Some(V1), "the highlight is on no campaign");
let held = board.picked();
assert_eq!(
held.as_ref().map(PickerKey::name),
Some(V1),
"the highlight is on no campaign"
);
}
/// A board with no campaigns says so in words rather than opening an empty box that
@@ -10716,15 +10953,18 @@ approach";
}
/// Section headings and the truncation line take no number: they are not campaigns, so
/// a highlight resting on one would give enter nothing to do.
/// a highlight resting on one would give enter nothing to do. The no-campaign row is not
/// chrome, though — it takes the highlight when the walk reaches it, but never the
/// opening one.
#[test]
fn the_highlight_moves_over_campaigns_and_never_onto_the_chrome() {
let dir = board_dir();
let mut board = tail_board(&dir);
board.open_picker(PickerKind::Campaign, SCREEN);
// It opens on the first campaign, not on the heading above it.
assert_eq!(board.picker.as_ref().expect("no picker").row, 1);
// It opens on the first campaign, not on the no-campaign row or the heading between
// them: campaigns are what this list opens for.
assert_eq!(board.picker.as_ref().expect("no picker").row, 2);
// Down until it stops, which is the last campaign and not the truncation line under
// it. Four campaigns are drawn: two open, and the two the truncation kept.
@@ -10742,7 +10982,8 @@ approach";
assert_eq!(walked[3], FINISHED[2].0, "the walk stopped short: {walked:?}");
// And back up is the same walk in reverse, over the second heading rather than onto
// it, ending on the first campaign rather than the first row.
// it — ending one further than it began, on the row above the list rather than on
// its heading.
let mut back = Vec::new();
loop {
let before = board.picker.as_ref().expect("no picker").row;
@@ -10753,7 +10994,8 @@ approach";
back.push(highlighted(&board).expect("the highlight landed on chrome"));
}
back.reverse();
assert_eq!(back, walked[..3], "the walk back is not the walk out");
assert_eq!(back[1..], walked[..3], "the walk back is not the walk out");
assert_eq!(back[0], NO_CAMPAIGN_ROW, "the walk back stopped short of the pile");
}
/// The highlight follows the campaign it was on rather than the number it was at: a
@@ -10953,4 +11195,265 @@ approach";
board.select_tab(-1, SCREEN);
assert_eq!(board.current().filter.campaign(), Some(V1));
}
// --------------------------------------------------- the no-campaign filter --
/// A board like [`campaign_board`] but with a loose ticket and the finished tail behind
/// it, which is what would push the pile down if it were listed among the sections
/// instead of above them.
fn tailed_campaign_board(dir: &Path) -> Board {
write_ticket(dir, "backlog", "66666666-0000-4000-8000-000000000000", "In neither", "");
tail_board(dir)
}
/// The opposite question to picking a campaign: what is on this board that nobody
/// grouped into anything. Every column kept, empty ones included, the rule
/// `retain_campaign` holds.
#[test]
fn picking_no_campaign_filters_every_column_to_the_unset_field() {
let dir = board_dir();
let mut board = campaign_board(&dir);
board.visibility = Visibility::Both;
board.select_filter(Filter::NoCampaign, SCREEN);
let headings = headings(&board, 120, 20);
assert!(headings.contains("backlog (1)"), "{headings}");
assert!(headings.contains("committed (0)"), "{headings}");
assert!(headings.contains("done (0)"), "{headings}");
}
/// A Campaign field naming a uuid no campaign carries is *set* wrongly, not unset: the
/// view answers what the field says, and the field does not say nothing here.
#[test]
fn a_dangling_campaign_uuid_is_set_and_not_unset() {
let dir = board_dir();
write_ticket(
&dir,
"backlog",
"11111111-0000-4000-8000-000000000000",
"Dangling",
&campaign_field("99999999-0000-4000-8000-000000000000"),
);
write_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "Free", "");
let mut board = one_board(&dir);
board.select_filter(Filter::NoCampaign, SCREEN);
let held: Vec<String> = board.current().columns[0]
.cards
.iter()
.map(|card| card.ticket.title.clone())
.collect();
assert_eq!(held, vec!["Free"], "the dangling uuid read as unset");
}
/// First, above both sections, and never truncated: on a board whose completed tail is
/// being kept back the pile is still row zero, reachable without scrolling — which is
/// the whole reason it is not a member of either list.
#[test]
fn the_picker_draws_the_pile_above_the_sections_and_never_truncates_it() {
let dir = board_dir();
let mut board = tailed_campaign_board(&dir);
board.open_picker(PickerKind::Campaign, SCREEN);
let rows = picker_rows(&board, 100, 24);
let open = row_at(&rows, OPEN_SECTION);
// The count sits where a campaign row's standing sits, saying what picking this
// will give before it is pressed.
assert!(rows[0].starts_with(NO_CAMPAIGN_ROW), "the pile was not first: {rows:?}");
assert!(rows[0].contains(" 1"), "the count is not on the row: {:?}", rows[0]);
assert!(open > 0, "the sections did not follow it: {rows:?}");
}
/// A word a reader would type for it finds it; a query naming a campaign hides it like
/// any other row; and a query matching nothing at all says so rather than leaving the
/// pile up as a consolation row.
#[test]
fn a_query_finds_the_pile_and_hides_it_like_any_other_row() {
let dir = board_dir();
let mut board = tailed_campaign_board(&dir);
board.open_picker(PickerKind::Campaign, SCREEN);
// By the shorter word, which hides every campaign and leaves the pile holding the
// highlight, since it is the only thing left to take.
type_picker_query(&mut board, "none");
assert_eq!(
highlighted(&board).as_deref(),
Some(NO_CAMPAIGN_ROW),
"the query missed the pile"
);
// A query naming a campaign hides it like any other row.
board.picker = None;
board.open_picker(PickerKind::Campaign, SCREEN);
type_picker_query(&mut board, "BEAV");
assert!(
!picker_rows(&board, 100, 24)[0].contains(NO_CAMPAIGN_ROW),
"the pile survived"
);
assert_eq!(picked_ids(&board), vec![BEAVER.to_string()]);
// And nothing matched at all.
board.picker = None;
board.open_picker(PickerKind::Campaign, SCREEN);
type_picker_query(&mut board, "zzz");
assert_eq!(highlighted(&board), None, "the miss took a row");
assert!(picker_rows(&board, 100, 24)[0].contains("no match"));
}
/// Taking the pile from under a query filters to it, which is how the row is found.
#[test]
fn taking_the_pile_under_a_query_filters_to_it() {
let dir = board_dir();
let mut board = tailed_campaign_board(&dir);
board.open_picker(PickerKind::Campaign, SCREEN);
type_picker_query(&mut board, "none");
press(&mut board, KeyCode::Enter);
assert!(board.picker.is_none(), "the picker stayed open");
assert_eq!(board.current().filter, Filter::NoCampaign);
}
/// Reopening the picker while the pile is selected opens on its row, the courtesy `c`
/// pays a filtered board: it says where you are as well as offering somewhere to go.
#[test]
fn reopening_the_picker_while_the_pile_is_selected_opens_on_its_row() {
let dir = board_dir();
let mut board = campaign_board(&dir);
board.select_filter(Filter::NoCampaign, SCREEN);
board.open_picker(PickerKind::Campaign, SCREEN);
assert_eq!(
highlighted(&board).as_deref(),
Some(NO_CAMPAIGN_ROW),
"the highlight is elsewhere"
);
// And taking it again changes nothing: the filter is what was asked for.
press(&mut board, KeyCode::Enter);
assert!(board.picker.is_none());
assert_eq!(board.current().filter, Filter::NoCampaign);
}
/// `q` takes the filter off, as it does a campaign or tag filter, because every filter
/// draws the frame whose border names it.
#[test]
fn q_gives_the_whole_board_back_from_the_no_campaign_filter() {
let dir = board_dir();
let mut board = campaign_board(&dir);
board.select_filter(Filter::NoCampaign, SCREEN);
board.dismiss(SCREEN);
assert!(board.current().filter.is_whole(), "the filter survived q");
assert_eq!(board.current().focus, Focus::Cards, "the focus outlived the frame");
assert!(!board.should_quit, "q quit out from under the filter");
}
/// The frame speaks in its own words: what the view is on the top border, how many on
/// the bottom right, and one grey sentence between them.
#[test]
fn the_no_campaign_frame_says_what_it_is_and_how_many() {
let dir = board_dir();
let mut board = campaign_board(&dir);
board.select_filter(Filter::NoCampaign, SCREEN);
let rows = frame_lines(&board, 120, 20);
let prose = &rows[1..rows.len() - 1];
assert!(rows[0].contains(NO_CAMPAIGN_ROW), "{:?}", rows[0]);
assert!(rows[rows.len() - 1].contains("1 ticket"), "{:?}", rows[rows.len() - 1]);
assert!(
prose
.iter()
.any(|row| row.contains("Tickets that name no campaign.")),
"{prose:?}"
);
}
/// The frame question stays `is_whole()` — every filter draws one — so the selection can
/// go up onto this frame the way it goes onto any other, and there is no state where it
/// rests on a frame that is not drawn.
#[test]
fn the_selection_reaches_the_no_campaign_frame_because_one_is_drawn() {
let dir = board_dir();
let mut board = campaign_board(&dir);
board.select_filter(Filter::NoCampaign, SCREEN);
board.select_card(-1, SCREEN);
assert_eq!(board.current().focus, Focus::Frame, "up did not reach the frame");
let rows = frame_lines(&board, 120, 20);
assert!(rows[0].contains(NO_CAMPAIGN_ROW), "the frame was not drawn: {rows:?}");
}
/// An unset field means the same thing on every board, so the pile is pickable on the
/// merge tab where one campaign is not: the count adds across boards and the filter cuts
/// all of them at once.
#[test]
fn the_pile_can_be_picked_on_the_merge_tab_where_a_campaign_cannot() {
let one = board_dir();
let two = board_dir();
write_campaign(&one, V1, "First public release", "v1", "For a public tag.");
write_ticket(
&one,
"backlog",
"11111111-0000-4000-8000-000000000000",
"In v1",
&campaign_field(V1),
);
write_ticket(&one, "backlog", "22222222-0000-4000-8000-000000000000", "Loose", "");
write_ticket(&two, "backlog", "44444444-0000-4000-8000-000000000000", "Adrift", "");
let mut board = boards(&[("one", &one), ("two", &two)]);
// The merged pile is two: one loose ticket per board.
board.open_picker(PickerKind::Campaign, SCREEN);
let rows = picker_list(board.current(), board.picker.as_ref().expect("no picker"));
assert!(
matches!(rows.first(), Some(PickerRow::NoCampaign(2))),
"the merged count is not the sum: {rows:?}"
);
type_picker_query(&mut board, "none");
press(&mut board, KeyCode::Enter);
let headings = headings(&board, 120, 20);
assert!(headings.contains("backlog (2)"), "{headings}");
let held: Vec<String> = board.current().columns[0]
.cards
.iter()
.map(|card| card.ticket.title.clone())
.collect();
assert_eq!(held, vec!["Adrift", "Loose"], "the merge was not cut across boards");
// And a campaign filter could not have done that: it belongs to the tab, keyed on a
// uuid from one board.
board.select_tab(1, SCREEN);
assert!(board.current().filter.is_whole(), "the filter crossed to a project");
}
/// The frame has neither an id nor a word a command line takes, so `y` is left out of
/// its footer rather than named into a notice — and pressing it anyway still says so,
/// never an empty string over the reader's clipboard.
#[test]
fn y_has_nothing_to_copy_from_the_no_campaign_frame() {
let dir = board_dir();
let mut board = campaign_board(&dir);
board.select_filter(Filter::NoCampaign, SCREEN);
board.select_card(-1, SCREEN);
assert_eq!(board.copy_text(), None);
let row = footer(&board, 120, 20);
assert!(!row.contains("copy"), "the footer names a key into a notice: {row:?}");
let mut taken = None;
board.copy_selected_id(recorder(&mut taken));
assert_eq!(taken, None, "something reached the clipboard");
let notice = board.notice.as_ref().expect("nothing was said");
assert_eq!(notice.text, "nothing to copy");
}
}
+162 -57
View File
@@ -449,52 +449,78 @@ pub const ACTOR_ENV: &str = "WORKLANE_ACTOR";
/// The author written when nothing names one.
pub const UNKNOWN_ACTOR: &str = "unknown";
/// The actor for the whole run: the variable, then the git user.
/// The actor for the whole run, from the variable alone.
///
/// Split out from the caching wrapper for the reason `colors_wanted` is: a threaded test
/// binary cannot mutate the process environment to reach one branch at a time.
///
/// An empty `WORKLANE_ACTOR` counts as unset, the convention `colors_wanted` follows for
/// `NO_COLOR`, so a wrapper script can clear an inherited one. `git_user` is a closure
/// rather than a value because the fallback costs a subprocess and the variable usually
/// answers first.
fn session_actor(env: Option<&str>, git_user: impl FnOnce() -> Option<String>) -> Option<String> {
match env.map(str::trim).filter(|value| !value.is_empty()) {
Some(value) => Some(value.to_string()),
None => git_user(),
}
/// `NO_COLOR`, so a wrapper script can clear an inherited one. This is the half the
/// [`resolve_actor`] cache holds; the git user lives in a cache of its own, because with
/// `--actor-from-git` it has to be fetched even though the variable answered.
fn session_actor(env: Option<&str>) -> Option<String> {
env.map(str::trim)
.filter(|value| !value.is_empty())
.map(str::to_string)
}
/// The actor for one entry: the flag wins, otherwise the session's, otherwise unknown.
/// The actor for one entry, from what named one.
///
/// Free text, validated against nothing, the way the `chown` user is: there is no
/// registry of actors to check a name against.
fn entry_actor(flag: Option<&str>, session: Option<&str>) -> String {
[flag, session]
.into_iter()
.flatten()
.map(str::trim)
.find(|value| !value.is_empty())
.unwrap_or(UNKNOWN_ACTOR)
.to_string()
///
/// The chain depends on the flag. An explicit `--actor` wins outright either way. With
/// `from_git`, the git user is lifted above the session rather than added beneath it:
/// the flag says attribute this to the human, and a machine with no git user configured
/// has nobody to name, which reads [`UNKNOWN_ACTOR`] rather than quietly attributing
/// back to the agent. Without it, today's chain: the variable, then the git user.
///
/// `git_user` is a closure in both branches so the subprocess it costs is not run when
/// something ahead of it already answered.
fn entry_actor(
flag: Option<&str>,
from_git: bool,
session: Option<&str>,
git_user: impl FnOnce() -> Option<String>,
) -> String {
if let Some(name) = flag.map(str::trim).filter(|value| !value.is_empty()) {
return name.to_string();
}
if from_git {
return git_user().unwrap_or_else(|| UNKNOWN_ACTOR.to_string());
}
if let Some(name) = session.map(str::trim).filter(|value| !value.is_empty()) {
return name.to_string();
}
git_user().unwrap_or_else(|| UNKNOWN_ACTOR.to_string())
}
/// Who to attribute an entry to, from the flag the call carried.
/// Who to attribute an entry to, from the flags the call carried.
///
/// Precedence: flag, then `WORKLANE_ACTOR`, then the git user, then `unknown`. Every
/// entry the CLI writes goes through here, so a board several agents write to says which
/// of them wrote what instead of attributing all of it to one human.
pub fn resolve_actor(flag: Option<&str>) -> String {
// The session half is decided once, the way should_use_colors is: neither input can
// change mid-run, and the git user costs a subprocess.
static SESSION: OnceLock<Option<String>> = OnceLock::new();
/// Precedence: flag, then — unless `from_git` lifted it — `WORKLANE_ACTOR`, then the git
/// user, then `unknown`. Every entry the CLI writes goes through here, so a board
/// several agents write to says which of them wrote what instead of attributing all of
/// it to one human.
pub fn resolve_actor(flag: Option<&str>, from_git: bool) -> String {
// Each half is decided once, the way should_use_colors is: neither input can change
// mid-run, and the git user costs a subprocess. They are two caches rather than one,
// because baking the git user into the session's answer would leave `--actor-from-git`
// reading whatever the run's *first* call produced — with the variable set, that call
// never fetched git at all.
static VARIABLE: OnceLock<Option<String>> = OnceLock::new();
static GIT_USER: OnceLock<Option<String>> = OnceLock::new();
let session = SESSION.get_or_init(|| {
let session = VARIABLE.get_or_init(|| {
let env = std::env::var(ACTOR_ENV).ok();
session_actor(env.as_deref(), get_git_user)
session_actor(env.as_deref())
});
entry_actor(flag, session.as_deref())
entry_actor(flag, from_git, session.as_deref(), || {
GIT_USER.get_or_init(get_git_user).clone()
})
}
/// One file a search matched, and where it was found.
pub struct Found {
@@ -1514,6 +1540,17 @@ const METADATA_ORDER: [&str; 13] = [
"Status",
];
/// What is being written, for the messages a failure carries.
///
/// A `&str` naming the thing rather than two copies of every message that names its
/// object: a campaign file is a ticket file in every way that matters here,
/// `<uuid>_<slug>.md` in a directory, and the only difference is the word a failure has
/// to use. Every message below puts it mid-sentence so there is no capital to case.
/// Lived in the handlers until the writers here started carrying the noun too; both
/// sides read these through one definition so the words cannot drift apart.
pub const TICKET: &str = "ticket";
pub const CAMPAIGN: &str = "campaign";
/// Rewrite a metadata field, adding the line when the file has no such field yet.
///
/// [`set_metadata_field`] refuses a field that is not already there, which is right for
@@ -1526,6 +1563,7 @@ pub fn set_or_insert_metadata_field(
content: &str,
field: &str,
value: &str,
noun: &str,
title: &str,
) -> Result<String> {
let prefix = format!("**{}**:", field);
@@ -1534,7 +1572,7 @@ pub fn set_or_insert_metadata_field(
metadata_field_body(line).starts_with(&prefix)
}) {
Some(updated) => Ok(updated),
None => insert_metadata_field(content, field, value, title),
None => insert_metadata_field(content, field, value, noun, title),
}
}
@@ -1543,14 +1581,26 @@ pub fn set_or_insert_metadata_field(
/// A file with no Metadata section is an error rather than an insertion. There is no
/// format to guess at there, and per 641e3d5 such a file has no fields at all, so
/// writing one above the prose would be inventing a shape nothing else reads.
fn insert_metadata_field(content: &str, field: &str, value: &str, title: &str) -> Result<String> {
///
/// The noun travels with the call rather than being spelled here, because both a ticket
/// and a campaign reach this: `campaign set --codename` inserts into a campaign, and
/// "Ticket 'v1 release' has no Metadata section" would be wrong about the one file it
/// names.
fn insert_metadata_field(
content: &str,
field: &str,
value: &str,
noun: &str,
title: &str,
) -> Result<String> {
let lines: Vec<&str> = content.lines().collect();
let heading = lines
.iter()
.position(|line| is_metadata_heading(line))
.ok_or_else(|| {
anyhow!(
"Ticket '{}' has no Metadata section, so its {} field cannot be written",
"There is no Metadata section on {} '{}', so its {} field cannot be written",
noun,
title,
field
)
@@ -1640,7 +1690,7 @@ pub fn set_status_stamp(content: &str, target: Status, now: &str, title: &str) -
match target.stamp_field() {
// Inserted on demand, the way Campaign is: every ticket written before these
// fields existed carries none of them.
Some(field) => set_or_insert_metadata_field(&content, field, now, title),
Some(field) => set_or_insert_metadata_field(&content, field, now, TICKET, title),
None => Ok(content),
}
}
@@ -1648,7 +1698,10 @@ pub fn set_status_stamp(content: &str, target: Status, now: &str, title: &str) -
/// Rewrite the title heading, the first `# ` line in the file.
///
/// `## ` headings do not match: the second character has to be a space.
pub fn set_title(content: &str, title: &str) -> Result<String> {
///
/// The noun travels with the call for the same reason [`insert_metadata_field`] carries
/// one: `campaign set --title` rewrites a campaign's heading too.
pub fn set_title(content: &str, title: &str, noun: &str) -> Result<String> {
let mut updated = String::with_capacity(content.len());
let mut found = false;
@@ -1664,7 +1717,7 @@ pub fn set_title(content: &str, title: &str) -> Result<String> {
}
if !found {
return Err(anyhow!("Ticket '{}' has no title heading", title));
return Err(anyhow!("There is no title heading on {} '{}'", noun, title));
}
Ok(updated)
@@ -3651,48 +3704,99 @@ mod tests {
/// closure returns a name that must not appear.
#[test]
fn the_variable_names_the_actor() {
let session = session_actor(Some("claude"), || Some("Ansho Rei".to_string()));
assert_eq!(entry_actor(None, session.as_deref()), "claude");
let session = session_actor(Some("claude"));
let git_user = || Some("Ansho Rei".to_string());
assert_eq!(entry_actor(None, false, session.as_deref(), git_user), "claude");
}
#[test]
fn the_flag_overrides_the_variable() {
let session = session_actor(Some("claude"), || None);
assert_eq!(entry_actor(Some("opencode"), session.as_deref()), "opencode");
let session = session_actor(Some("claude"));
assert_eq!(
entry_actor(Some("opencode"), false, session.as_deref(), || None),
"opencode"
);
}
/// With neither supplied the author is still the git user.
#[test]
fn the_git_user_is_the_fallback() {
let session = session_actor(None, || Some("Ansho Rei".to_string()));
assert_eq!(entry_actor(None, session.as_deref()), "Ansho Rei");
let git_user = || Some("Ansho Rei".to_string());
assert_eq!(
entry_actor(None, false, session_actor(None).as_deref(), git_user),
"Ansho Rei"
);
}
/// An empty variable counts as unset, the way `NO_COLOR` does, so a wrapper script
/// can clear an inherited one and get the git user back.
/// can clear an inherited one and get the git user back. Whitespace is the same
/// case: a shell that quotes a missing value writes one.
#[test]
fn an_empty_variable_reads_as_unset() {
let session = session_actor(Some(""), || Some("Ansho Rei".to_string()));
assert_eq!(entry_actor(None, session.as_deref()), "Ansho Rei");
// Whitespace is the same case: a shell that quotes a missing value writes one
let session = session_actor(Some(" "), || Some("Ansho Rei".to_string()));
assert_eq!(entry_actor(None, session.as_deref()), "Ansho Rei");
let git_user = || Some("Ansho Rei".to_string());
for raw in ["", " "] {
let session = session_actor(Some(raw));
assert_eq!(entry_actor(None, false, session.as_deref(), git_user), "Ansho Rei");
}
}
/// And with nothing at all, including a git that has no user configured.
#[test]
fn nothing_at_all_is_unknown() {
let session = session_actor(None, || None);
assert_eq!(entry_actor(None, session.as_deref()), UNKNOWN_ACTOR);
let session = session_actor(None);
assert_eq!(entry_actor(None, false, session.as_deref(), || None), UNKNOWN_ACTOR);
// An empty flag falls through rather than writing a blank author
assert_eq!(entry_actor(Some(""), None), UNKNOWN_ACTOR);
assert_eq!(entry_actor(Some(""), false, None, || None), UNKNOWN_ACTOR);
}
/// Free text, validated against nothing, the way the `chown` user is.
#[test]
fn an_actor_is_free_text() {
let session = session_actor(Some("claude-code, session 3 (opus)"), || None);
assert_eq!(entry_actor(None, session.as_deref()), "claude-code, session 3 (opus)");
let session = session_actor(Some("claude-code, session 3 (opus)"));
assert_eq!(
entry_actor(None, false, session.as_deref(), || None),
"claude-code, session 3 (opus)"
);
}
/// The flag is the caller acting for the person whose checkout this is: the git user
/// is lifted above the variable rather than added beneath it.
#[test]
fn from_git_lifts_the_git_user_over_the_variable() {
let session = session_actor(Some("claude"));
let git_user = || Some("Ansho Rei".to_string());
assert_eq!(entry_actor(None, true, session.as_deref(), git_user), "Ansho Rei");
}
/// An explicit `--actor` still wins outright beside the lift: it names somebody
/// specific, which is the stronger statement of the two.
#[test]
fn the_flag_wins_over_from_git_too() {
let session = session_actor(Some("claude"));
let git_user = || Some("Ansho Rei".to_string());
assert_eq!(
entry_actor(Some("opencode"), true, session.as_deref(), git_user),
"opencode"
);
}
/// The lift is not a fallback: asked to name the human and finding none configured,
/// the entry reads unknown instead of quietly attributing back to the agent.
#[test]
fn from_git_with_no_git_user_is_unknown_not_the_variable() {
let session = session_actor(Some("claude"));
assert_eq!(entry_actor(None, true, session.as_deref(), || None), UNKNOWN_ACTOR);
}
/// An empty variable still counts as unset with the lift on, which here means the
/// git user answers as usual.
#[test]
fn from_git_leaves_the_empty_variable_unset() {
let git_user = || Some("Ansho Rei".to_string());
assert_eq!(
entry_actor(None, true, session_actor(Some("")).as_deref(), git_user),
"Ansho Rei"
);
}
#[test]
@@ -4207,7 +4311,7 @@ mod tests {
let content = with_metadata("- **ID**: abc\n- **Owner**: alice\n- **Status**: backlog\n");
let updated =
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "c-uuid", "T").unwrap();
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "c-uuid", TICKET, "T").unwrap();
// Against METADATA_ORDER, so Status stays last where every file keeps it.
assert!(
@@ -4224,7 +4328,7 @@ mod tests {
let content = with_metadata("- **ID**: abc\n- **Owner**: alice\n\n## Notes\nAfter.\n");
let updated =
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "c-uuid", "T").unwrap();
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "c-uuid", TICKET, "T").unwrap();
assert!(
updated.contains("- **Owner**: alice\n- **Campaign**: c-uuid\n\n## Notes\nAfter.\n"),
@@ -4240,7 +4344,7 @@ mod tests {
with_metadata("- **ID**: abc\n- **Campaign**: first\n- **Status**: backlog\n");
let updated =
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "second", "T").unwrap();
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "second", TICKET, "T").unwrap();
assert_eq!(updated.matches("**Campaign**:").count(), 1, "{updated}");
assert!(updated.contains("- **Campaign**: second"), "{updated}");
@@ -4253,7 +4357,8 @@ mod tests {
let content = "# T\n\n## Description\n- **Campaign**: not a field\n\n\
## Metadata\n\n- **ID**: abc\n- **Status**: backlog\n";
let updated = set_or_insert_metadata_field(content, CAMPAIGN_FIELD, "c-uuid", "T").unwrap();
let updated =
set_or_insert_metadata_field(content, CAMPAIGN_FIELD, "c-uuid", TICKET, "T").unwrap();
assert!(updated.contains("- **Campaign**: not a field"), "{updated}");
assert!(
@@ -4268,7 +4373,7 @@ mod tests {
fn a_file_with_no_metadata_section_is_an_error_rather_than_an_insertion() {
let content = "# T\n\n## Description\nBody.\n";
let error = set_or_insert_metadata_field(content, CAMPAIGN_FIELD, "c-uuid", "T")
let error = set_or_insert_metadata_field(content, CAMPAIGN_FIELD, "c-uuid", TICKET, "T")
.expect_err("a file with no Metadata section gained a field");
assert!(error.to_string().contains("no Metadata section"), "{error}");
+46
View File
@@ -262,6 +262,52 @@ fn the_actor_flag_overrides_the_variable() {
assert!(only_comment(&worklane, &uuid).contains("**Author**: opencode"));
}
/// The flag for acting on the person's behalf: their name is what the machine already
/// knows, so the entry does not have to wait for the agent to know it too.
#[test]
fn the_actor_from_git_flag_names_the_git_user_over_the_variable() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid = create_ticket(&worklane, "backlog", "From Git Test");
Command::cargo_bin(BIN_NAME)
.unwrap()
.current_dir(temp.path())
.env("WORKLANE_ACTOR", "claude")
.env("GIT_CONFIG_GLOBAL", git_config_naming(&temp, "Configured User"))
.env("GIT_CONFIG_NOSYSTEM", "1")
.arg("comment")
.args([&uuid, "Written for the person"])
.arg("--actor-from-git")
.assert()
.success();
assert!(only_comment(&worklane, &uuid).contains("**Author**: Configured User"));
}
/// The lift is not a fallback: with no git user configured there is nobody to name, and
/// the entry reads unknown rather than quietly attributing back to the agent.
#[test]
fn from_git_with_no_git_user_is_unknown_even_with_the_variable() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid = create_ticket(&worklane, "backlog", "No Git User Test");
Command::cargo_bin(BIN_NAME)
.unwrap()
.current_dir(temp.path())
.env("WORKLANE_ACTOR", "claude")
.env("GIT_CONFIG_GLOBAL", temp.path().join("no-such-gitconfig"))
.env("GIT_CONFIG_NOSYSTEM", "1")
.arg("comment")
.args([&uuid, "Written with nobody to name"])
.arg("--actor-from-git")
.assert()
.success();
assert!(only_comment(&worklane, &uuid).contains("**Author**: unknown"));
}
/// An empty variable counts as unset, the convention `NO_COLOR` follows, so a wrapper
/// script can clear an inherited one and get the git user back.
#[test]
+120
View File
@@ -72,6 +72,29 @@ fn run(temp: &TempDir, args: &[&str]) -> Output {
.clone()
}
/// Run as an agent acting for the person: the variable still names the agent, the git
/// config names the human, and the flag is what tells the two apart.
fn run_for_the_human(temp: &TempDir, args: &[&str]) -> Output {
Command::cargo_bin(BIN_NAME)
.unwrap()
.current_dir(temp.path())
.env("WORKLANE_ACTOR", "claude")
.env("GIT_CONFIG_GLOBAL", git_config_naming(temp, "Ansho Rei"))
.env("GIT_CONFIG_NOSYSTEM", "1")
.args(args)
.assert()
.get_output()
.clone()
}
/// A git config file holding nothing but a `user.name`, for the tests that need the
/// fallback to answer something known instead of whatever the machine is configured with.
fn git_config_naming(temp: &TempDir, name: &str) -> PathBuf {
let path = temp.path().join("gitconfig");
fs::write(&path, format!("[user]\n\tname = {}\n", name)).unwrap();
path
}
/// Every entry on the ticket, name and content, in the order the log sorts them.
fn entries(worklane: &Path) -> Vec<(String, String)> {
let dir = worklane.join("history").join(UUID);
@@ -562,3 +585,100 @@ fn the_actor_flag_names_the_writer_on_every_command_that_writes_one() {
assert!(content.contains("**Author**: opencode"), "{name}: {content:?}");
}
}
/// The lift is spelled the same on every command that writes an entry, and it raises
/// the git user over the variable on each of them.
#[test]
fn actor_from_git_names_the_git_user_on_every_command_that_writes_one() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
create_ticket(&worklane, "backlog");
run(
&temp,
&[
"campaign",
"add",
"--title",
"First release",
"--codename",
"v1",
],
);
run_for_the_human(&temp, &["comment", UUID, "By hand.", "--actor-from-git"]);
run_for_the_human(&temp, &["mv", UUID, "--status", "committed", "--actor-from-git"]);
run_for_the_human(&temp, &["chown", "bob", UUID, "--actor-from-git"]);
run_for_the_human(&temp, &["set", UUID, "--tags", "beta", "--actor-from-git"]);
run_for_the_human(&temp, &["assign", "v1", UUID, "--actor-from-git"]);
let found = entries(&worklane);
assert_eq!(found.len(), 5, "{found:?}");
for (name, content) in found {
assert!(content.contains("**Author**: Ansho Rei"), "{name}: {content:?}");
}
}
/// Both flags answer the same question — who is the entry attributed to — so a call
/// carrying both is a usage error at parse time rather than a last-wins answer. Refused
/// before any ticket is resolved, so nothing reaches the log.
#[test]
fn actor_and_actor_from_git_are_refused_together() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
create_ticket(&worklane, "backlog");
let calls: [&[&str]; 5] = [
&[
"comment",
UUID,
"Body.",
"--actor",
"opencode",
"--actor-from-git",
],
&[
"mv",
UUID,
"--status",
"committed",
"--actor",
"opencode",
"--actor-from-git",
],
&[
"chown",
"bob",
UUID,
"--actor",
"opencode",
"--actor-from-git",
],
&[
"set",
UUID,
"--tags",
"beta",
"--actor",
"opencode",
"--actor-from-git",
],
&[
"assign",
"v1",
UUID,
"--actor",
"opencode",
"--actor-from-git",
],
];
for call in calls {
let output = run(&temp, call);
assert_eq!(output.status.code(), Some(2), "{call:?} was not a usage error");
}
assert!(
!worklane.join("history").join(UUID).exists(),
"an entry was written despite the usage error"
);
}