Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3592584747 | ||
|
|
5dc087d49e | ||
|
|
07c783410c |
@@ -45,6 +45,10 @@ and this file is for what someone changing worklane's own code needs.
|
||||
- Tests use `assert_cmd` and `assert_fs` for CLI testing
|
||||
- `setup_worklane()` creates temp `.worklane/` with all four status folders pre-created, plus `campaigns/` in `cmd_campaign.rs`, which is also where the on-demand creation is tested from a board without it
|
||||
- `create_ticket()` writes fully-formed markdown files directly (no `--` separator for positional args in test commands)
|
||||
- **Every unit-test fixture directory goes through `util::Fixture`, and nothing calls `remove_dir_all` at the end of a test.** `Fixture::new(prefix)` makes a uuid-named directory under the system temp dir and its `Drop` removes it, which is the only shape that also runs when an assertion fails — a trailing line does not, and a failing test is exactly when a fixture is most likely to be stranded. That was b74dc5a: `/tmp` reached 18363 of these and filled the disk, failing a link step and then a `git add` with "No space left on device", an error naming neither the tests nor what they left behind
|
||||
- **`Fixture` derefs to `Path` and also implements `AsRef<Path>`**, because the two reach different call sites: a parameter typed `&Path` is a coercion site and one bound by `impl AsRef<Path>` is not. `Fixture::child(name)` points the fixture at a directory inside itself while still removing the parent, which is the tree `project_tree` needs. The prefix earns its place on the one path that is ever left behind, which is why this is a small guard rather than `assert_fs::TempDir` — that names its directories `.tmpXXXXXX`, which says nothing about whose they are
|
||||
- **`WORKLANE_KEEP_FIXTURES=1 cargo test` keeps the fixtures and prints each path.** Opt-in rather than kept-automatically-on-failure, because the assertions here carry the state they are about: a failing board test prints the rendered rows. The flag is read once when a fixture is made rather than at drop time, so the answer cannot change mid-test, and `Fixture::swept()` turns it off for the three tests that are about the guard itself and must not be failed by a reader's environment
|
||||
- **Verify a claim about leaked fixtures against a clean temp dir, not against `/tmp`.** `TMPDIR=/tmp/scratch cargo test` then count what is left in it: `/tmp` still holds the historical leak, so counting there measures the past rather than the change
|
||||
- In `tui.rs`, `write_member_card` is `write_tagged_card` plus a Campaign field and `write_campaign` puts a campaign on disk, creating the campaigns directory as it goes — `board_dir()` deliberately does not, so every test that does not write one is also the test that a board with no campaigns draws. `picker_rows` cuts the picker's list out of the frame by its own geometry, for the reason `overlay_title_row` exists: a card carries the same campaign label, so a search over every row finds the board rather than the list
|
||||
- **`cargo clippy --all-targets` is clean. Keep it clean**, and do not silence a lint that is pointing at something real. The only two `allow`s in the tree sit on the `create_ticket` fixtures in `cmd_mv.rs` and `cmd_show.rs`, each carrying the reason and what would replace it
|
||||
- **`cargo fmt --check` is clean too, and `rustfmt.toml` is what makes that affordable.** rustfmt is the formatter here, run it. The config is four stable width settings and nothing else:
|
||||
@@ -121,6 +125,7 @@ and this file is for what someone changing worklane's own code needs.
|
||||
- Appending to a numbered section continues from the count of steps already there and does not renumber what is above it, so a handwritten line in the section survives exactly as written
|
||||
- Appending to an empty section replaces the placeholder rather than following it, or the ticket would read `_No description provided._` above its description
|
||||
- An empty value is a paragraph break for the three sections and a usage error for the scalars, via `non_empty` and `clearable` in `command.rs`. Neither spells clearing, and both errors name the flag that does
|
||||
- **A call whose values are *every one* blank is refused, by `replaced_items` for `set` and `appended_items` for `append`.** The check is the section's rather than the object's, so `campaign set --description` shares it. What differs is the way out, which is why `replaced_items` takes it as an argument: a ticket's section is emptied with `--clear <field>` and a campaign's description cannot be emptied at all, so a single hard-coded tail would name a flag that does not exist on one of the two
|
||||
|
||||
### Clearing a Field
|
||||
- **`set --clear <field>` is the one way to take a value away, and it is a flag with the field as its value.** Not a per-field `--clear-due`, which is a flag per field to keep in step with the field it undoes, and not an empty value, which is already a paragraph break for a section and would make an accidentally empty variable a silent delete. Repeatable, so one call empties as many fields as it likes
|
||||
@@ -181,9 +186,14 @@ and this file is for what someone changing worklane's own code needs.
|
||||
- `campaign ls` scans the status directories **once per campaign** to count members. That is a scan per row rather than one walk reused, and it is deliberate: the map-from-uuid version is worth writing when a board has enough campaigns to notice
|
||||
- **The TUI got a card label and a frame, not a campaign tab.** 61879a4 decided it. A tab would have had to answer what its columns are, and a campaign groups *across* the flow rather than within one status, so the honest answer is the four statuses filtered — which is a filter on the board it already has rather than a fifth tab. So: a label on the card, a frame above the columns while one is selected, and `c` for the picker. The cost the earlier decision balked at, a campaigns read per reload, is paid once per project in `columns_of` and is what names the label; see The Board View
|
||||
- **A campaign is named by its codename on the board, and by its short id when it has none.** The uuid does not fit on a card and the title is a sentence, which is the gap `Codename` fills. `campaign_label` builds it in one place, as a `Cell`, so the CLI paints it and the board makes a span of it; the mark is `CAMPAIGN_MARK`, `~`, beside `#` for a tag
|
||||
- **`campaign set` is the only writer of a filed campaign's fields, and it carries the two scalars.** d637288 decided it: a `set` rather than a flag on something narrower, because the file has more than one editable thing and the moment somebody wants to fix a typo in a title there would be a second command to design. `--title`, which renames the file the way `set --title` does, and `--codename`. `campaign add` writing a field at creation is not a second writer, exactly as `add --title` and `set --title` coexist
|
||||
- **`campaign set` and `campaign append` are the only writers of a filed campaign's fields.** d637288 decided the command: a `set` rather than a flag on something narrower, because the file has more than one editable thing and the moment somebody wants to fix a typo in a title there would be a second command to design. `set` carries `--title`, which renames the file the way `set --title` does, `--description` and `--codename`; `append` carries `--description` alone. `campaign add` writing a field at creation is not a second writer, exactly as `add --title` and `set --title` coexist
|
||||
- **Replacing a codename the campaign already has needs `--force`.** Once a campaign has one it is referred to by it: it is on every card in the campaign, it is what resolves the campaign at the command line, and it is in somebody's shell history. Changing it silently is the mistake `install-skill --force` exists to prevent, so it is refused and the refusal names both words and the flag rather than leaving it to be found. Checked before any edit is applied, like `SetArgs::contested`, so a call also carrying `--title` writes neither field. Setting the codename a campaign already carries stays a **no-op, not a refusal** — `--force` is about overwriting a *different* word, which is the same division `install::Outcome` draws between `Unchanged` and `Refused`. `--force` guards the codename alone: a campaign always has a title, so guarding that would mean the flag was always required
|
||||
- **No `campaign set --description`, and that is the line, not an oversight.** `set` and `append` are a pair for a prose section: a way to replace a description with no way to add a paragraph is half of it. The two scalars have no append form at all, which is the same line `append` already draws for a ticket. `campaign_set_offers_no_description_and_no_owner` pins it. No `--owner` either, because nothing writes a campaign's Owner today and giving `set` one would settle by accident whether `chown` grows a campaign; and no `--clear`, because a wrong codename is replaced rather than emptied and `Clearable` is `SetArgs`'s, its variants being a ticket's fields
|
||||
- **The description arrived as a pair, `set --description` and `campaign append`, 32e98ab.** Never one without the other: for a prose section `set` replaces and `append` adds, and a way to replace a description with no way to add a paragraph is the half that is easy to reach for and wrong, since replacing a description to add a sentence to it is how the rest of it gets lost. The two scalars have no append form at all, which is the same line `append` already draws for a ticket, and `campaign_append_offers_only_the_description` pins that. Neither flag takes `--force`: a description is prose written to be revised, the same reason `tags set --annotation` has none
|
||||
- **`append` is a campaign's own subcommand, not the top-level `append`.** That one resolves a ticket, and one positional naming either object is the ambiguity `resolve_in` makes real: its tiers are the same over both directories, so a search can resolve in each and nothing but a flag could say which was meant. It would also make a liar of `resolve_ticket`, which explains a ticket search that *names* a campaign. Under `campaign` the object is settled by the command, as it is for `set`, `show` and `ls`
|
||||
- **Still no `--owner` and still no `--clear`.** No `--owner`, because nothing writes a campaign's Owner today and giving `set` one would settle by accident whether `chown` grows a campaign. No `--clear`, which 32e98ab settled rather than deferred: a codename is replaced rather than emptied, and emptying the description of a container six tickets are filed against is not a thing anybody has asked for, so the only spellings left would be `Clearable` on a campaign, whose variants are a ticket's fields, or a second enum with one variant in it. `campaign_set_offers_no_owner_and_no_clear` pins both
|
||||
- **An empty `--description ""` is a paragraph break here too, and the refusal for an all-blank value names no flag.** Every prose argument in the tool reads a blank value that way, `add`, `set` and `tags --annotation` alike, so a campaign reading it as *empty the section* would be the one exception. With no `--clear` to point at, the refusal says a campaign's description has no cleared form instead of naming a flag that does not exist. `replaced_items` is where the check lives, shared with `set`, and the way out is the caller's argument for exactly that reason
|
||||
- **`SECTION_ORDER` needs no campaign variant, and that is what the one-section file proves.** A campaign holds Description and Metadata where a ticket holds four sections and Metadata. Every consumer of the list looks for the headings that follow, *filtered by what is actually in the file*, so a campaign's description anchors against `## Metadata` — which is where `campaign_body` writes it. `the_description_is_edited_in_place_in_a_file_with_one_section` pins that no section a campaign does not have gets inserted to anchor against
|
||||
- **A campaign whose Description heading is gone is refused, not given the section back.** No `ensure_section` on this path: every campaign the tool has ever filed carries the heading, so an insertion here would be reachable only from a hand-edited file, which is the opposite of the Relations case, where `add` writes nothing and the insertion is the only path there is. The refusal therefore names the section and **not** the object — "There is no description section to write to" — because both a ticket and a campaign reach `replace_section_body` now. `write_then_replace` still carries the noun, where the message is about a file
|
||||
- **The codename is written through `set_or_insert_metadata_field`, not `set_metadata_field`.** Every campaign filed before the field existed has no such line, and those are exactly the campaigns the command is for, which is the same reasoning that puts `assign` on the upsert. **`Codename` is therefore in `METADATA_ORDER`, directly after ID**, so an inserted one lands where `campaign_body` writes it and a campaign given a codename later is the same file as one filed with it. Nothing upserts it on a ticket, so its place in a ticket's order costs nothing
|
||||
- **One write path for tickets and campaigns.** `save_entry` is the body, `save_ticket` and `save_campaign` are the named wrappers, and `write_then_replace` and `find_entry_file` take the noun as a `&str` so a failure says "campaign" where it is one. A campaign file is a ticket file in every way that matters here, `<uuid>_<slug>.md` in a directory, and the rename happens only after the write has landed. Every message puts the noun mid-sentence so there is no capital to case
|
||||
- `campaign_body()` builds the file from `DESCRIPTION` and `METADATA_HEADING` rather than its own string literals, so the two file formats cannot drift apart on the spelling of a heading. A campaign has no acceptance criteria (its definition of done is derived), no implementation plan and no Status
|
||||
|
||||
Generated
+1
-1
@@ -1503,7 +1503,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.26.3"
|
||||
version = "0.27.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.26.3"
|
||||
version = "0.27.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -19,7 +19,8 @@ Worklane is a local Kanban flow for agentic software development.
|
||||
| `worklane uncheck <ticket> [criteria...]` | Unticks acceptance criteria, addressed the same way |
|
||||
| `worklane comment <ticket> <body>` | Adds a comment to a ticket by UUID or title |
|
||||
| `worklane 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, and `--codename`. At least one required. The only way to change a campaign after it is filed, and the way a campaign filed before codenames existed gets one. 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. No `--description`: replacing prose without an `append` to add a paragraph is half a pair |
|
||||
| `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 |
|
||||
| `worklane campaign ls` | Lists the campaigns as their short id, their codename, their title and how many members are done. `--ids` prints one per line as the id, a tab and the title, unstyled, for a script or a completion |
|
||||
| `worklane campaign show <campaign>` | Shows a campaign and its members grouped by status, done included, since what is finished against what is left is the question a campaign asks |
|
||||
| `worklane assign <campaign> <ticket>` | Puts a ticket in a campaign, the only command that writes the Campaign field. Campaign first and ticket second, after `chown`. A ticket is in at most one, so assigning one that already belongs somewhere moves it |
|
||||
|
||||
+10
-5
@@ -122,7 +122,7 @@ question asked by tag.
|
||||
## Annotating a tag
|
||||
|
||||
```
|
||||
worklane tags # every tag carried, with counts
|
||||
worklane tags # every tag, its count and what it means
|
||||
worklane tags add kitchen --annotation "..." # declare one, and say what it means
|
||||
worklane tags set kitchen --annotation "..." # change what it means
|
||||
```
|
||||
@@ -132,10 +132,15 @@ annotation under it. It is what a person opens to find out what the board means
|
||||
and it is what an agent reads before choosing one.
|
||||
|
||||
**Declaring a tag tags nothing, and tagging a ticket declares nothing.** The two lists are
|
||||
separate on purpose: `worklane tags` counts what the tickets carry, `tags.md` records what
|
||||
separate on purpose: the counts come from what the tickets carry, `tags.md` records what
|
||||
the board agreed on, and the difference between them is the thing worth looking at. A tag
|
||||
carried by tickets but never declared is a word somebody invented in a hurry.
|
||||
|
||||
`worklane tags` reports both, as the tag, a tab, the count, and a tab and the annotation's
|
||||
opening line for a tag that is declared. So the two cases worth finding read off the
|
||||
listing: a tag at a count of zero is declared and nobody has reached for it, and a tag with
|
||||
no annotation column at all is carried and was never declared.
|
||||
|
||||
### What an annotation has to say
|
||||
|
||||
The definition is the easy half and does the least work. What stops drift is the boundary
|
||||
@@ -177,9 +182,9 @@ ones two people quietly disagree about.
|
||||
not. Each names the other, so the refusal tells you which you wanted.
|
||||
- A tag cannot contain a comma, because a comma is what separates one tag from the next in
|
||||
the Tags field. Surrounding spaces are trimmed.
|
||||
- `worklane tags` counts tickets, so a tag you have declared and never applied does not
|
||||
appear in it. That is not a fault; it is the file and the board disagreeing, which is
|
||||
the state that tells you the vocabulary has not landed yet.
|
||||
- A tag you have declared and never applied lists at a count of zero. That is not a fault;
|
||||
it is the file and the board disagreeing, which is the state that tells you the
|
||||
vocabulary has not landed yet.
|
||||
- Nothing removes a declaration. There is no `tags rm`, so a tag declared in error stays
|
||||
in the file with whatever its annotation says. Say it is retired in the annotation.
|
||||
|
||||
|
||||
+8
-1
@@ -168,7 +168,8 @@ fields; a goal is a campaign.
|
||||
worklane campaign ls
|
||||
worklane campaign show v1
|
||||
worklane campaign add --title "..." --codename v1 --description "..."
|
||||
worklane campaign set v1 --title "..." # or --codename, on one already filed
|
||||
worklane campaign set v1 --title "..." # or --description or --codename, on one already filed
|
||||
worklane campaign append v1 -d "..." # add a paragraph to the description
|
||||
worklane assign v1 1b78a24
|
||||
```
|
||||
|
||||
@@ -194,6 +195,12 @@ tui is usable on a narrow terminal" is a campaign. "The tui tickets" is a tag.
|
||||
- **Do not propose renaming a codename a campaign already has.** It is what the campaign is
|
||||
called on every card in it and at the command line, so changing it is churn dressed as
|
||||
grooming. `campaign set` refuses it without `--force` for that reason.
|
||||
- **A campaign's description is editable, so a wrong one is a fix rather than a refiling.**
|
||||
A container whose description no longer describes what its members are for is worth
|
||||
pointing out: it is the line every one of those tickets was filed against. `campaign set
|
||||
--description` replaces it and `campaign append --description` adds to it, so neither
|
||||
needs the campaign refiled and its members reassigned. Adding to it is the usual answer;
|
||||
replacing prose to add a sentence to it is how the rest of it gets lost.
|
||||
|
||||
Proposing a campaign means naming the goal, the members, and what is deliberately left
|
||||
out of it. The last part is what makes it a goal rather than a pile.
|
||||
|
||||
+12
-4
@@ -211,7 +211,8 @@ worklane campaign add --title "First public release" --codename v1 \
|
||||
worklane campaign ls # every campaign, its codename, how far it has got
|
||||
worklane campaign ls --ids # id and title, tab separated, like ls --ids
|
||||
worklane campaign show v1 # its body, then its members by status
|
||||
worklane campaign set v1 --title "..." # replace the title or the codename
|
||||
worklane campaign set v1 --title "..." # replace the title, description or codename
|
||||
worklane campaign append v1 -d "..." # add a paragraph to the description
|
||||
worklane assign v1 1b78a24 # put a ticket in it
|
||||
worklane ls --campaign v1 # only that campaign's tickets
|
||||
```
|
||||
@@ -226,9 +227,16 @@ existed needs. **Replacing a codename it already has needs `--force`**: that wor
|
||||
the campaign is referred to on the board and at the command line, so changing it is a
|
||||
decision rather than a correction. Setting the one it already has is a no-op either way.
|
||||
|
||||
`campaign set` is the only way to change a campaign after it is filed, and it reaches the
|
||||
title and the codename only. There is no way to edit a campaign's description or its owner
|
||||
yet.
|
||||
`campaign set` and `campaign append` are the only ways to change a campaign after it is
|
||||
filed. `set` replaces the title, the description or the codename; `append` adds a paragraph
|
||||
to the description, which is what to use when the description is right and only incomplete,
|
||||
since replacing prose to add a sentence to it is how the rest of it gets lost. An empty
|
||||
`--description ""` between two values is a paragraph break, exactly as it is for a ticket,
|
||||
and a call whose every value is blank is refused: a campaign's description cannot be
|
||||
emptied. There is still no way to change a campaign's owner.
|
||||
|
||||
`append` here is `campaign append` and not the top-level `append`, which takes a ticket. The
|
||||
two objects are addressed the same way, so the command is what says which one is meant.
|
||||
|
||||
`assign` takes the **campaign first and the ticket second**, like `chown`, and is the
|
||||
only writer of the field. `add` has no `--campaign` and neither has `set`, so membership
|
||||
|
||||
+63
-16
@@ -358,10 +358,18 @@ pub enum Command {
|
||||
/// No `mv`: a campaign has no status to move it to, its state is derived from its
|
||||
/// members.
|
||||
///
|
||||
/// No `append`, and therefore no `set --description`: `set` and `append` are a pair for a
|
||||
/// prose section, and a way to replace a description with no way to add a paragraph to one
|
||||
/// is half of it. That pair is its own ticket. `set` here carries the two scalars, which
|
||||
/// have no append form at all, the same line `append` already draws for a ticket.
|
||||
/// `set` and `append` arrive together, 32e98ab, because for a prose section they are a
|
||||
/// pair: a way to replace a description with no way to add a paragraph to one is the half
|
||||
/// that is easy to reach for and wrong, since replacing a description to add a sentence is
|
||||
/// how the rest of it gets lost. The two scalars have no append form at all, which is the
|
||||
/// same line `append` already draws for a ticket.
|
||||
///
|
||||
/// **`append` is a campaign's own subcommand and not the top-level `append`.** That one
|
||||
/// resolves a ticket, and its positional would then name either object: `resolve_in`'s tiers
|
||||
/// are the same over both directories, so a search can resolve in each and nothing but a
|
||||
/// flag could say which was meant. It would also make a liar of `resolve_ticket`, which
|
||||
/// explains a ticket search that names a campaign. Under `campaign` the object is settled by
|
||||
/// the command, the way it is for `set`, `show` and `ls`.
|
||||
#[derive(clap::Subcommand)]
|
||||
pub enum CampaignCommand {
|
||||
/// File a new campaign
|
||||
@@ -369,11 +377,19 @@ pub enum CampaignCommand {
|
||||
|
||||
/// Replace fields on an existing campaign
|
||||
///
|
||||
/// The only way to change a campaign after it is filed. `campaign add --codename` writes
|
||||
/// the field at creation the way `add --title` does for a ticket; this is what replaces
|
||||
/// it, so every campaign filed before the field existed can still be given one.
|
||||
/// The only way to change a campaign's title or codename after it is filed.
|
||||
/// `campaign add --codename` writes the field at creation the way `add --title` does for
|
||||
/// a ticket; this is what replaces it, so every campaign filed before the field existed
|
||||
/// can still be given one.
|
||||
Set(CampaignSetArgs),
|
||||
|
||||
/// Add a paragraph to a campaign's description
|
||||
///
|
||||
/// The other half of `campaign set --description`, and the half that keeps what is
|
||||
/// already written: a description is the sentence a whole campaign's members are filed
|
||||
/// against, so adding a line to it must not mean retyping it.
|
||||
Append(CampaignAppendArgs),
|
||||
|
||||
/// List campaigns with their member counts
|
||||
Ls {
|
||||
/// Print one campaign per line as its id and title, tab separated, for a script
|
||||
@@ -394,25 +410,30 @@ pub enum CampaignCommand {
|
||||
},
|
||||
}
|
||||
|
||||
/// What can be replaced on a campaign that is already filed: its title and its codename.
|
||||
///
|
||||
/// The two scalars, and deliberately not the description. See [`CampaignCommand`].
|
||||
/// What can be replaced on a campaign that is already filed: everything it holds but its
|
||||
/// owner.
|
||||
///
|
||||
/// No `--owner`: nothing writes a campaign's Owner today, and giving `set` one would settle
|
||||
/// by accident whether `chown` grows a campaign or `set` keeps the field, which is the
|
||||
/// one-field-one-writer question and not this command's to answer.
|
||||
///
|
||||
/// No `--clear`: nothing has asked to empty a codename, a wrong one is replaced rather than
|
||||
/// emptied, and the vocabulary is a real question — `Clearable` is `SetArgs`'s and its
|
||||
/// variants are a ticket's fields, so reusing it here would put a ticket's enum on a
|
||||
/// campaign and inventing a second one is a decision worth making on purpose.
|
||||
/// No `--clear`, which is 32e98ab's decision and not a deferral. A codename is replaced
|
||||
/// rather than emptied, and a campaign's one prose section has no cleared form worth
|
||||
/// reaching: emptying the description of a container six tickets are filed against is not a
|
||||
/// thing anybody has asked for, and the only ways to spell it would be to put [`Clearable`]
|
||||
/// on a campaign, whose variants are a ticket's fields, or to invent a second enum with one
|
||||
/// variant in it. So an empty `--description ""` stays a paragraph break here exactly as it
|
||||
/// is everywhere else, and the refusal for an all-blank value says there is nowhere to go
|
||||
/// back to rather than naming a flag that does not exist.
|
||||
///
|
||||
/// `--force` guards the codename and nothing else. A campaign that already has one is
|
||||
/// referred to by it: it is on every card in the campaign, it is what resolves it at the
|
||||
/// command line, and it is very likely in somebody's shell history. Replacing that silently
|
||||
/// is the same mistake overwriting an edited skill document would be, which is what
|
||||
/// `install-skill --force` exists for. A title needs no guard, since a campaign always has
|
||||
/// one and replacing it is the whole point of the flag.
|
||||
/// one and replacing it is the whole point of the flag. Neither does a description: it is
|
||||
/// prose written to be revised, the same reason `tags set --annotation` has no guard, and a
|
||||
/// guard in front of the command's whole purpose is worse than no command.
|
||||
///
|
||||
/// The group makes at least one field mandatory, so a bare `worklane campaign set <c>` is a
|
||||
/// usage error rather than a silent no-op, exactly as it is for [`SetArgs`].
|
||||
@@ -421,7 +442,7 @@ pub enum CampaignCommand {
|
||||
clap::ArgGroup::new("campaign_set_fields")
|
||||
.required(true)
|
||||
.multiple(true)
|
||||
.args(["title", "codename"])
|
||||
.args(["title", "description", "codename"])
|
||||
))]
|
||||
pub struct CampaignSetArgs {
|
||||
/// Campaign UUID, title, filename or codename
|
||||
@@ -431,6 +452,13 @@ pub struct CampaignSetArgs {
|
||||
#[arg(short, long, allow_hyphen_values = PROSE, value_parser = non_empty)]
|
||||
pub title: Option<String>,
|
||||
|
||||
/// Replace the description. Repeat the flag for more lines, empty for a paragraph break
|
||||
///
|
||||
/// The whole section, so a paragraph added to it is `campaign append --description`
|
||||
/// rather than the description retyped
|
||||
#[arg(short, long, allow_hyphen_values = PROSE)]
|
||||
pub description: Vec<String>,
|
||||
|
||||
/// Replace the codename, a single word to call the campaign by
|
||||
///
|
||||
/// The same parser `campaign add --codename` takes, so a codename is one thing however
|
||||
@@ -449,6 +477,25 @@ pub struct CampaignSetArgs {
|
||||
pub force: bool,
|
||||
}
|
||||
|
||||
/// What can be added to a campaign that is already filed: a paragraph of its description.
|
||||
///
|
||||
/// One field, so it is `required` rather than a group of one, which is the longer way to say
|
||||
/// the same thing and the shape [`TagSetArgs`] already takes. A bare
|
||||
/// `worklane campaign append <c>` is therefore a usage error rather than a silent no-op.
|
||||
///
|
||||
/// No `--title` and no `--codename`, because appending to a scalar has no meaning. That is
|
||||
/// the line `append` already draws for a ticket, where the title is absent for the same
|
||||
/// reason.
|
||||
#[derive(clap::Args)]
|
||||
pub struct CampaignAppendArgs {
|
||||
/// Campaign UUID, title, filename or codename
|
||||
pub campaign: String,
|
||||
|
||||
/// Add a paragraph to the description. Repeat the flag for more lines within it
|
||||
#[arg(short, long, required = true, allow_hyphen_values = PROSE)]
|
||||
pub description: Vec<String>,
|
||||
}
|
||||
|
||||
/// What a campaign holds: a title, a description and an owner.
|
||||
///
|
||||
/// Deliberately narrower than [`AddArgs`]. There are no acceptance criteria, because a
|
||||
|
||||
+51
-10
@@ -50,11 +50,16 @@ pub const CAMPAIGN_COMMANDS: [&str; 1] = ["assign"];
|
||||
|
||||
/// Nested subcommands whose first argument is a campaign, as `parent child`.
|
||||
///
|
||||
/// `campaign show` and `campaign set`, and they are why the fish half needs a third
|
||||
/// position helper: their argument is the *third* token, where `__worklane_first_arg_of`
|
||||
/// reads the second and `__worklane_second_arg_of` counts a top-level command's arguments.
|
||||
/// Neither can tell `campaign show <TAB>` from `chown alice <TAB>` by position.
|
||||
pub const CAMPAIGN_NESTED_COMMANDS: [(&str, &str); 2] = [("campaign", "show"), ("campaign", "set")];
|
||||
/// `campaign show`, `campaign set` and `campaign append`, and they are why the fish half
|
||||
/// needs a third position helper: their argument is the *third* token, where
|
||||
/// `__worklane_first_arg_of` reads the second and `__worklane_second_arg_of` counts a
|
||||
/// top-level command's arguments. Neither can tell `campaign show <TAB>` from
|
||||
/// `chown alice <TAB>` by position.
|
||||
pub const CAMPAIGN_NESTED_COMMANDS: [(&str, &str); 3] = [
|
||||
("campaign", "show"),
|
||||
("campaign", "set"),
|
||||
("campaign", "append"),
|
||||
];
|
||||
|
||||
/// Options whose value is a campaign.
|
||||
pub const CAMPAIGN_FLAGS: [&str; 1] = ["campaign"];
|
||||
@@ -192,14 +197,21 @@ complete -c worklane -n '__worklane_command_is ls' {campaign_flags} \
|
||||
-x -a '(worklane campaign ls --ids)'
|
||||
|
||||
# Tags come from `worklane tags` rather than from a listing of objects, since a tag has no
|
||||
# id. The count after the tab lands as fish's description, which is what makes the list
|
||||
# worth reading: it says which spelling the board actually uses.
|
||||
complete -c worklane -n '__worklane_command_is ls' {tag_flags} -x -a '(worklane tags)'
|
||||
# id. Three fields now, the tag, its count and its annotation, and fish takes everything
|
||||
# after the *first* tab as one description, so the count is dropped here rather than landing
|
||||
# in the middle of the prose. `cut` and not `string replace` because the columns are what is
|
||||
# being picked, and `cut -f1` is how a script reads this listing anyway.
|
||||
#
|
||||
# What is left is the annotation, and a tag the board carries but has never declared has
|
||||
# none: it is offered with no description at all, which is the near-duplicate the file was
|
||||
# added to catch. The count used to be the description and said the same thing more weakly.
|
||||
complete -c worklane -n '__worklane_command_is ls' {tag_flags} \
|
||||
-x -a '(worklane tags | cut -f1,3)'
|
||||
|
||||
# And `tags set` names one that is already declared, so it reads the same listing. `tags
|
||||
# add` has no rule on purpose: it takes a tag the board does not have, so the candidates
|
||||
# here are the values it refuses.
|
||||
complete -c worklane -n '{tag_nested}' -a '(worklane tags)'
|
||||
complete -c worklane -n '{tag_nested}' -a '(worklane tags | cut -f1,3)'
|
||||
|
||||
# `chown --clear` names the ticket in the flag too, since with no user to give there is
|
||||
# no second positional to put it in. Scoped to `chown`, unlike the rule above: `set`
|
||||
@@ -367,7 +379,10 @@ mod tests {
|
||||
|
||||
// A guard on the walker itself: if it stopped finding arguments, every assertion
|
||||
// above would pass by never running.
|
||||
assert_eq!(seen, 4, "expected assign, campaign show, campaign set and ls --campaign");
|
||||
assert_eq!(
|
||||
seen, 5,
|
||||
"expected assign, campaign show, campaign set, campaign append and ls --campaign"
|
||||
);
|
||||
}
|
||||
|
||||
/// Commands whose tag positional names a tag that does not exist yet.
|
||||
@@ -514,6 +529,32 @@ mod tests {
|
||||
assert!(script.contains("__worklane_first_arg_of assign"), "{script}");
|
||||
}
|
||||
|
||||
/// Every rule that reads the tag listing drops the count, because `worklane tags` prints
|
||||
/// three fields and fish takes everything after the first tab as the description. Left
|
||||
/// whole, a tag would be described as its count, a tab and its annotation.
|
||||
///
|
||||
/// Pinned per rule rather than once over the script: a rule added later that reads
|
||||
/// `worklane tags` raw is the bug this catches, and it would not show up in a single
|
||||
/// `contains`.
|
||||
#[test]
|
||||
fn every_tag_rule_takes_the_annotation_as_its_description() {
|
||||
let script = fish_dynamic();
|
||||
|
||||
let reading: Vec<&str> = script
|
||||
.lines()
|
||||
.filter(|line| line.contains("(worklane tags"))
|
||||
.collect();
|
||||
|
||||
assert_eq!(
|
||||
reading.len(),
|
||||
2,
|
||||
"expected the ls --tag rule and the tags set one: {reading:?}"
|
||||
);
|
||||
for line in reading {
|
||||
assert!(line.contains("(worklane tags | cut -f1,3)"), "{line}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The one status positional and the one shell positional, which clap does not emit
|
||||
/// possible values for. Read off the enums, so a fifth status would appear here on
|
||||
/// its own.
|
||||
|
||||
+127
-30
@@ -7,8 +7,8 @@ use std::path::Path;
|
||||
|
||||
use crate::campaign::*;
|
||||
use crate::command::{
|
||||
AddArgs, AppendArgs, CampaignAddArgs, CampaignSetArgs, CheckArgs, ChownArgs, LsArgs,
|
||||
RelateArgs, SetArgs, TagAddArgs, TagSetArgs,
|
||||
AddArgs, AppendArgs, CampaignAddArgs, CampaignAppendArgs, CampaignSetArgs, CheckArgs,
|
||||
ChownArgs, LsArgs, RelateArgs, SetArgs, TagAddArgs, TagSetArgs,
|
||||
};
|
||||
use crate::install;
|
||||
use crate::tag::{TAGS_FILE, TagIndex, tags_path};
|
||||
@@ -784,6 +784,42 @@ fn section_args<'a>(
|
||||
]
|
||||
}
|
||||
|
||||
/// The lines a caller's values amount to, or the refusal an all-blank call earns.
|
||||
///
|
||||
/// An empty value is a paragraph break, so a call whose values are *every one* blank asked
|
||||
/// for nothing, and writing an empty section is not what it meant. Shared by `set` and
|
||||
/// `campaign set` because the rule is the section's rather than the object's.
|
||||
///
|
||||
/// `instead` is the way out, and it is the caller's because the callers differ: a ticket's
|
||||
/// section is emptied with `--clear <field>`, and a campaign's description has no cleared
|
||||
/// form at all, per [`CampaignSetArgs`].
|
||||
fn replaced_items(section: &Section, values: &[String], instead: &str) -> Result<Vec<String>> {
|
||||
let items = section.normalise(values);
|
||||
if items.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"An empty value is a paragraph break, not a way to empty the {}: {}",
|
||||
section.label,
|
||||
instead
|
||||
));
|
||||
}
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
/// The same for `append`, which has no way out to name: appending nothing was never a way
|
||||
/// to empty anything, so the message says only that there was nothing to add.
|
||||
fn appended_items(section: &Section, values: &[String]) -> Result<Vec<String>> {
|
||||
let items = section.normalise(values);
|
||||
if items.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"Nothing to append to the {}: every value given was blank",
|
||||
section.label
|
||||
));
|
||||
}
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
/// Write the ticket back, renaming the file when a new title changes its slug.
|
||||
///
|
||||
/// The content goes down first and the rename second, the same order and for the same
|
||||
@@ -917,14 +953,8 @@ pub fn cmd_set(args: &SetArgs, start: &Path) -> Result<()> {
|
||||
continue;
|
||||
}
|
||||
|
||||
let items = section.normalise(values);
|
||||
if items.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"An empty value is a paragraph break, not a way to empty the {}: use --clear {}",
|
||||
section.label,
|
||||
section.clear.map_or("", Clearable::name)
|
||||
));
|
||||
}
|
||||
let clear = format!("use --clear {}", section.clear.map_or("", Clearable::name));
|
||||
let items = replaced_items(section, values, &clear)?;
|
||||
|
||||
let next = set_section_body(&content, section, &items)?;
|
||||
apply(&mut content, &mut changed, section.label, next);
|
||||
@@ -1031,13 +1061,7 @@ pub fn cmd_append(args: &AppendArgs, start: &Path) -> Result<()> {
|
||||
continue;
|
||||
}
|
||||
|
||||
let items = section.normalise(values);
|
||||
if items.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"Nothing to append to the {}: every value given was blank",
|
||||
section.label
|
||||
));
|
||||
}
|
||||
let items = appended_items(section, values)?;
|
||||
|
||||
content = append_section_body(&content, section, &items)?;
|
||||
changed.push(section.label);
|
||||
@@ -1217,27 +1241,52 @@ pub fn cmd_campaign_ls(worklane_dir: &Path, ids: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Every tag on the board, with how many tickets carry it.
|
||||
/// Every tag on the board: the ones the tickets carry, the ones the file declares, and
|
||||
/// what each declared one means.
|
||||
///
|
||||
/// The vocabulary itself, which nothing else could answer: `ls --tag` filters by a tag
|
||||
/// already known, and the decorated listing does not print tags at all. A grooming sweep
|
||||
/// starts by asking what the vocabulary *is*, and `assets/PLAN.md` used to have to say
|
||||
/// that the question could only be answered by reading the tickets.
|
||||
///
|
||||
/// **The union of the two vocabularies, not either one.** Since `tags.md` exists there are
|
||||
/// two: the tags the file declares and the tags the tickets carry. A declared tag nothing
|
||||
/// carries lists at zero rather than being dropped, and a carried tag nothing declares
|
||||
/// still lists. Those two cases are the whole reason to declare tags at all, so this is
|
||||
/// the command that has to show them apart.
|
||||
///
|
||||
/// **Alphabetical, and case sensitive.** `--tag` matches a whole value case sensitively,
|
||||
/// so `bug` and `Bug` are two tags and listing them as one would hide the reason a filter
|
||||
/// came back short. Sorting puts them next to each other, which is where a near-duplicate
|
||||
/// is spotted.
|
||||
///
|
||||
/// Machine-readable, the second output in the tree that is: the tag, a tab, the count.
|
||||
/// Fish reads what follows the tab as a description, a script takes `cut -f1`, and neither
|
||||
/// wants an escape sequence. Every status, done included, for the reason `ls --ids`
|
||||
/// includes it: a tag retired months ago is still part of the answer to what the
|
||||
/// vocabulary has been.
|
||||
/// Machine-readable, the second output in the tree that is: the tag, a tab, the count, and
|
||||
/// a tab and the annotation's opening line for a tag the file declares. Fish reads what
|
||||
/// follows the first tab as a description, a script takes `cut -f1`, and neither wants an
|
||||
/// escape sequence.
|
||||
///
|
||||
/// **A carried but undeclared tag is marked by the absence of the third field**, which is
|
||||
/// where the shape comes from. Anything appended to the tag itself would have a completion
|
||||
/// offer a tag that does not exist, and anything added to the count would stop the second
|
||||
/// field being a number. Absence costs neither, and it buys the one property a marker
|
||||
/// could not: a board with no `tags.md` has every tag undeclared, so it prints two fields
|
||||
/// a line, which is byte for byte what this printed before the file existed. The shipped
|
||||
/// fish completion of an older version is still reading that.
|
||||
///
|
||||
/// Every status, done included, for the reason `ls --ids` includes it: a tag retired months
|
||||
/// ago is still part of the answer to what the vocabulary has been.
|
||||
pub fn cmd_tags(worklane_dir: &Path) -> Result<()> {
|
||||
// Through the same `load` `tags add` uses, so a file that is there and cannot be read
|
||||
// is an error here too. The listing is the one tag command that could go on without the
|
||||
// file, and reporting a vocabulary while silently treating a broken file as no file is
|
||||
// the wrong half of the answer.
|
||||
let index = TagIndex::load(worklane_dir)?;
|
||||
|
||||
// BTreeMap rather than a sort afterwards: the order is the point, and the counting
|
||||
// wants a map anyway.
|
||||
let mut counts: BTreeMap<String, usize> = BTreeMap::new();
|
||||
// wants a map anyway. Seeded from the vocabulary rather than merged into afterwards,
|
||||
// which is what puts a declared tag nothing carries in at zero.
|
||||
let mut counts: BTreeMap<String, usize> =
|
||||
index.names().map(|tag| (tag.to_string(), 0)).collect();
|
||||
|
||||
for status in status_dirs() {
|
||||
let status_path = worklane_dir.join(status);
|
||||
@@ -1253,7 +1302,10 @@ pub fn cmd_tags(worklane_dir: &Path) -> Result<()> {
|
||||
}
|
||||
|
||||
for (tag, count) in counts {
|
||||
println!("{}\t{}", tag, count);
|
||||
match index.summary(&tag) {
|
||||
Some(summary) => println!("{tag}\t{count}\t{summary}"),
|
||||
None => println!("{tag}\t{count}"),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -1381,6 +1433,18 @@ pub fn cmd_tag_set(args: &TagSetArgs, start: &Path) -> Result<()> {
|
||||
/// No-op detection compares the whole file, the way `set` and `chown` do, so setting a
|
||||
/// codename a campaign already carries writes nothing. That is a no-op and not a refusal:
|
||||
/// `--force` is about overwriting a *different* word, and there is nothing to overwrite.
|
||||
///
|
||||
/// **The description goes through `set_section_body` and the `DESCRIPTION` entry**, the
|
||||
/// section table `cmd_set` and `campaign_body` already read, so what a campaign's one prose
|
||||
/// section *is* stays decided in one place. A second definition scoped to campaigns would
|
||||
/// drift on the spelling of the heading, which is the drift `campaign_body` was written
|
||||
/// against.
|
||||
///
|
||||
/// A campaign whose Description heading is gone is refused by that call rather than given
|
||||
/// the section back through `ensure_section`. Every campaign the tool has ever filed carries
|
||||
/// the heading, so an insertion path here would be reachable only from a hand-edited file:
|
||||
/// that is the opposite of the Relations case, where `add` writes nothing and the insertion
|
||||
/// is the only path there is.
|
||||
pub fn cmd_campaign_set(args: &CampaignSetArgs, start: &Path) -> Result<()> {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
let campaign = resolve_campaign(&args.campaign, &worklane_dir)?;
|
||||
@@ -1408,6 +1472,16 @@ pub fn cmd_campaign_set(args: &CampaignSetArgs, start: &Path) -> Result<()> {
|
||||
apply(&mut content, &mut changed, "title", next);
|
||||
}
|
||||
|
||||
if !args.description.is_empty() {
|
||||
let items = replaced_items(
|
||||
&DESCRIPTION,
|
||||
&args.description,
|
||||
"a campaign's description has no cleared form",
|
||||
)?;
|
||||
let next = set_section_body(&content, &DESCRIPTION, &items)?;
|
||||
apply(&mut content, &mut changed, DESCRIPTION.label, next);
|
||||
}
|
||||
|
||||
if let Some(codename) = &args.codename {
|
||||
let next = set_or_insert_metadata_field(&content, CODENAME_FIELD, codename, &title)?;
|
||||
apply(&mut content, &mut changed, "codename", next);
|
||||
@@ -1425,6 +1499,32 @@ pub fn cmd_campaign_set(args: &CampaignSetArgs, start: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add a paragraph to a campaign's description.
|
||||
///
|
||||
/// The other half of `campaign set --description`, and `cmd_append` for a campaign: the same
|
||||
/// `append_section_body` and the same `DESCRIPTION` entry, so a paragraph lands under a
|
||||
/// campaign's description the way it lands under a ticket's, blank line and all. A campaign
|
||||
/// filed with no description holds the placeholder, and that is replaced rather than
|
||||
/// followed, which is `append_section_body`'s rule and not a case handled here.
|
||||
///
|
||||
/// No whole-file comparison, unlike `set`: every value blank is refused above, so there is
|
||||
/// nothing left that appends nothing. `cmd_append` says it the same way.
|
||||
///
|
||||
/// One section, so there is no loop and no list to report: what changed is the description
|
||||
/// or the call failed.
|
||||
pub fn cmd_campaign_append(args: &CampaignAppendArgs, start: &Path) -> Result<()> {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
let campaign = resolve_campaign(&args.campaign, &worklane_dir)?;
|
||||
|
||||
let items = appended_items(&DESCRIPTION, &args.description)?;
|
||||
let content = append_section_body(&campaign.content, &DESCRIPTION, &items)?;
|
||||
|
||||
save_campaign(&worklane_dir, &campaign.uuid, &campaign.title, None, &content)?;
|
||||
|
||||
report(&[DESCRIPTION.label], &campaign.title, "Appended to");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Show a campaign, then its members grouped by status.
|
||||
///
|
||||
/// Every status is shown, done included, unlike `ls`, which leaves done out of its
|
||||
@@ -1766,8 +1866,7 @@ mod tests {
|
||||
/// will not share a microsecond, but it is the whole point of the guard.
|
||||
#[test]
|
||||
fn a_colliding_stem_takes_the_next_name_and_keeps_the_first() {
|
||||
let dir = std::env::temp_dir().join(format!("worklane-test-{}", uuid::Uuid::new_v4()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
let dir = Fixture::new("worklane-test");
|
||||
|
||||
let first = write_new_comment(&dir, "20260820_143012_123456", "first").unwrap();
|
||||
let second = write_new_comment(&dir, "20260820_143012_123456", "second").unwrap();
|
||||
@@ -1786,7 +1885,5 @@ mod tests {
|
||||
let mut names = vec![second.clone(), third.clone(), first.clone()];
|
||||
names.sort();
|
||||
assert_eq!(names, vec![first, second, third]);
|
||||
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ fn main() -> Result<()> {
|
||||
cmd_campaign_ls(&worklane_dir, ids)
|
||||
}
|
||||
CampaignCommand::Set(args) => cmd_campaign_set(&args, &start),
|
||||
CampaignCommand::Append(args) => cmd_campaign_append(&args, &start),
|
||||
CampaignCommand::Show { campaign } => {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
cmd_campaign_show(&campaign, &worklane_dir)
|
||||
|
||||
+39
@@ -153,6 +153,45 @@ impl TagIndex {
|
||||
self.tags.contains_key(tag)
|
||||
}
|
||||
|
||||
/// Every tag the file declares, alphabetical, whatever the board carries.
|
||||
///
|
||||
/// The half of the listing the status directories cannot answer. A tag declared and
|
||||
/// never applied is carried by no ticket, so counting alone drops it, and that tag is
|
||||
/// most of the reason the file exists: a word the board agreed on and nobody has
|
||||
/// reached for yet is exactly what a grooming sweep wants to see.
|
||||
pub fn names(&self) -> impl Iterator<Item = &str> {
|
||||
self.tags.keys().map(String::as_str)
|
||||
}
|
||||
|
||||
/// The opening line of what a tag means, or `None` for a tag the file does not declare.
|
||||
///
|
||||
/// The cut to one line lives here rather than on the parse, the way
|
||||
/// [`CampaignRow::summary`] takes one line off a description the read carries whole:
|
||||
/// the annotation is prose with paragraphs in it, and which view wants how much of it
|
||||
/// is the view's business.
|
||||
///
|
||||
/// **`None` is what marks a carried but undeclared tag**, since `cmd_tags` prints no
|
||||
/// third field for it. Nothing is appended to the tag itself and nothing is added to
|
||||
/// the count, so `cut -f1` still yields the tag values and a board with no file at all
|
||||
/// lists what it listed before the file existed.
|
||||
///
|
||||
/// A declared tag with nothing said about it answers [`NO_ANNOTATION`] rather than an
|
||||
/// empty string, because an empty third field is a trailing tab and nothing else: it
|
||||
/// would be the only difference between declared and not, and it would be invisible in
|
||||
/// a terminal and in a completion alike. The placeholder is also what the file itself
|
||||
/// holds under that heading, so the field stays the section's opening line either way.
|
||||
///
|
||||
/// [`CampaignRow::summary`]: crate::tui::CampaignRow::summary
|
||||
/// [`NO_ANNOTATION`]: crate::tag::NO_ANNOTATION
|
||||
pub fn summary(&self, tag: &str) -> Option<&str> {
|
||||
let annotation = self.tags.get(tag)?;
|
||||
|
||||
Some(match annotation.lines().next() {
|
||||
Some(line) => line,
|
||||
None => NO_ANNOTATION,
|
||||
})
|
||||
}
|
||||
|
||||
/// Declare `tag`, or replace what it means.
|
||||
///
|
||||
/// One writer for both, because the file holds one section per tag either way and the
|
||||
|
||||
+24
-181
@@ -3300,10 +3300,17 @@ mod tests {
|
||||
|
||||
/// A board on disk, since everything here is about reading a real tree.
|
||||
///
|
||||
/// The directory stands in for a `.worklane`, so its parent is the temp directory
|
||||
/// and `project_name` reads the generated name off it.
|
||||
fn board_dir() -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("worklane-tui-{}", uuid::Uuid::new_v4()));
|
||||
/// The directory stands in for a `.worklane` and holds the four status directories.
|
||||
/// `board_dir()` deliberately does not create the campaigns directory beside them, so
|
||||
/// every test that does not write one is also the test that a board with no campaigns
|
||||
/// draws.
|
||||
///
|
||||
/// A [`Fixture`], so it goes when the test that made it does, whether the test passed or
|
||||
/// not. It used to be a `PathBuf` and a `remove_dir_all` at the end of the tests that
|
||||
/// remembered one, which is b74dc5a: the line does not run when an assertion fails, and
|
||||
/// most tests here never had it.
|
||||
fn board_dir() -> Fixture {
|
||||
let dir = Fixture::new("worklane-tui");
|
||||
for status in status_dirs() {
|
||||
std::fs::create_dir_all(dir.join(status)).unwrap();
|
||||
}
|
||||
@@ -4885,7 +4892,7 @@ mod tests {
|
||||
}
|
||||
|
||||
/// A board with something to find in three columns, done included.
|
||||
fn searchable() -> PathBuf {
|
||||
fn searchable() -> Fixture {
|
||||
let dir = board_dir();
|
||||
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "Alpha first", "");
|
||||
write_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "Beta second", "");
|
||||
@@ -5402,10 +5409,11 @@ mod tests {
|
||||
|
||||
/// A project tree: a directory holding a `.worklane`, which is what a path argument
|
||||
/// is resolved to.
|
||||
fn project_tree(name: &str) -> PathBuf {
|
||||
let root = std::env::temp_dir()
|
||||
.join(format!("worklane-project-{}", uuid::Uuid::new_v4()))
|
||||
.join(name);
|
||||
/// The fixture points at the project and removes the directory above it, which is what
|
||||
/// `Fixture::child` is for: the path a test hands to `projects` is the project, and the
|
||||
/// generated name that has to be swept up is its parent.
|
||||
fn project_tree(name: &str) -> Fixture {
|
||||
let root = Fixture::new("worklane-project").child(name);
|
||||
for status in status_dirs() {
|
||||
std::fs::create_dir_all(root.join(".worklane").join(status)).unwrap();
|
||||
}
|
||||
@@ -5441,7 +5449,8 @@ mod tests {
|
||||
fn several_paths_are_monitored_together() {
|
||||
let (alpha, beta) = (project_tree("alpha"), project_tree("beta"));
|
||||
|
||||
let found = projects(&[alpha, beta], &std::env::temp_dir()).unwrap();
|
||||
let found =
|
||||
projects(&[alpha.to_path_buf(), beta.to_path_buf()], &std::env::temp_dir()).unwrap();
|
||||
let names: Vec<&str> = found.iter().map(|p| p.name.as_str()).collect();
|
||||
assert_eq!(names, ["alpha", "beta"]);
|
||||
}
|
||||
@@ -5451,10 +5460,10 @@ mod tests {
|
||||
#[test]
|
||||
fn a_path_with_no_board_fails_naming_that_path() {
|
||||
let alpha = project_tree("alpha");
|
||||
let bare = std::env::temp_dir().join(format!("worklane-bare-{}", uuid::Uuid::new_v4()));
|
||||
std::fs::create_dir_all(&bare).unwrap();
|
||||
let bare = Fixture::new("worklane-bare");
|
||||
|
||||
let error = projects(&[alpha, bare.clone()], &std::env::temp_dir()).unwrap_err();
|
||||
let error = projects(&[alpha.to_path_buf(), bare.to_path_buf()], &std::env::temp_dir())
|
||||
.unwrap_err();
|
||||
let printed = format!("{error:#}");
|
||||
|
||||
assert!(
|
||||
@@ -5473,7 +5482,7 @@ mod tests {
|
||||
let deep = root.join("src");
|
||||
std::fs::create_dir_all(&deep).unwrap();
|
||||
|
||||
let found = projects(&[root, deep], &std::env::temp_dir()).unwrap();
|
||||
let found = projects(&[root.to_path_buf(), deep], &std::env::temp_dir()).unwrap();
|
||||
assert_eq!(found.len(), 1, "the same board was monitored twice");
|
||||
}
|
||||
|
||||
@@ -6013,7 +6022,7 @@ mod tests {
|
||||
/// The section goes where `relate` writes it, ahead of the metadata, rather than in
|
||||
/// `write_ticket`'s trailer: the block has to be on screen for a test to read the
|
||||
/// colour off the drawn buffer.
|
||||
fn related_board() -> PathBuf {
|
||||
fn related_board() -> Fixture {
|
||||
let dir = board_dir();
|
||||
let holder = "11111111-0000-4000-8000-000000000000";
|
||||
let target = "22222222-0000-4000-8000-000000000000";
|
||||
@@ -6387,8 +6396,6 @@ mod tests {
|
||||
let title = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
|
||||
assert!(title.contains("A long one"), "{title}");
|
||||
assert!(!title.contains("pg "), "the indicator landed on the title row:\n{title}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// At the top of a scrollable ticket, page one.
|
||||
@@ -6401,7 +6408,6 @@ mod tests {
|
||||
let row = overlay_bottom_row(&screen, SCREEN.width, SCREEN.height);
|
||||
|
||||
assert!(row.contains("pg 1/"), "{row}");
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The one the arithmetic is for: the clamp stops at the wrapped height less the
|
||||
@@ -6431,8 +6437,6 @@ mod tests {
|
||||
.to_string();
|
||||
let (page, total) = indicator.split_once('/').expect("no separator");
|
||||
assert_eq!(page, total, "the last page reads as the second to last: {indicator}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A ticket that fits spends no indicator, the way an untagged card spends no row on
|
||||
@@ -6463,8 +6467,6 @@ mod tests {
|
||||
"a ticket that fits drew an indicator:\n{}",
|
||||
screen.join("\n")
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The wrapped count and the viewport both move with the terminal, so the total has
|
||||
@@ -6489,8 +6491,6 @@ mod tests {
|
||||
let wide = total(120, 40);
|
||||
let narrow = total(60, 20);
|
||||
assert_ne!(wide, narrow, "the same total on two terminal sizes");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// An overlay too narrow for the indicator drops it whole rather than cutting it, the
|
||||
@@ -6562,8 +6562,6 @@ mod tests {
|
||||
Some(Color::Orange.into()),
|
||||
"the indicator took the title's colour"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- campaigns --
|
||||
@@ -6810,8 +6808,6 @@ mod tests {
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
assert_eq!(rows.len(), 5, "the label row is missing: {rows:?}");
|
||||
assert_eq!(rows[2], "~v1 #cli #tui", "the campaign is not on the row: {rows:?}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The mark is not `#`, because the two sit on one row and the row would otherwise
|
||||
@@ -6833,8 +6829,6 @@ mod tests {
|
||||
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
assert_eq!(rows[2], format!("~{}", short_id(V1)), "{rows:?}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A ticket in no campaign renders exactly as it did before campaigns reached the
|
||||
@@ -6848,8 +6842,6 @@ mod tests {
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
assert_eq!(rows.len(), 4, "a row was spent on nothing: {rows:?}");
|
||||
assert!(!rows.iter().any(|row| row.contains(CAMPAIGN_MARK)), "{rows:?}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A campaign the board does not hold marks nothing, the answer `mark_blocked` gives
|
||||
@@ -6863,8 +6855,6 @@ mod tests {
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
assert_eq!(rows.len(), 4, "{rows:?}");
|
||||
assert!(!rows.iter().any(|row| row.contains("_missing_")), "{rows:?}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The campaign takes the row first and the tags give way, the order a corner and a
|
||||
@@ -6882,8 +6872,6 @@ mod tests {
|
||||
|
||||
let fits = only_card_at(&dir, 25);
|
||||
assert_eq!(fits[2], "~v1 #frontend #operations", "{fits:?}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// And a campaign the row will not hold goes whole, never cut: half a codename is a
|
||||
@@ -6899,8 +6887,6 @@ mod tests {
|
||||
|
||||
let fits = only_card_at(&dir, 7);
|
||||
assert_eq!(fits[2], "~beaver", "{fits:?}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The colour groups a campaign across the cards that carry it, from the same pure
|
||||
@@ -6926,8 +6912,6 @@ mod tests {
|
||||
"the campaign does not jump out: {:?}",
|
||||
label.style
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A campaign with no codename is drawn in grey rather than in the red a uuid takes
|
||||
@@ -6959,8 +6943,6 @@ mod tests {
|
||||
"a card was labelled"
|
||||
);
|
||||
assert!(headings(&board, 100, 24).contains("backlog (1)"), "the board did not draw");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Selecting a campaign turns the four columns into that campaign's members grouped
|
||||
@@ -6984,8 +6966,6 @@ mod tests {
|
||||
assert_eq!(titles, vec!["In v1".to_string(), "Also in v1".to_string()], "{titles:?}");
|
||||
// Every column is kept, empty ones included: a campaign's shape is the flow.
|
||||
assert_eq!(board.current().columns.len(), status_dirs().len());
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The frame says which campaign the columns belong to, and how far it has got, from
|
||||
@@ -7016,8 +6996,6 @@ mod tests {
|
||||
assert!(rows[bottom].contains("[open]"), "no derived state: {:?}", rows[bottom]);
|
||||
// The way out, on the border of the thing it undoes.
|
||||
assert!(rows[bottom].contains("q board"), "no way out named: {:?}", rows[bottom]);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The standing counts done whether the column is drawn or not: hiding done is a
|
||||
@@ -7047,8 +7025,6 @@ mod tests {
|
||||
assert!(!board.show_done, "done is hidden at startup");
|
||||
let standing = board.campaign().expect("no campaign selected").standing;
|
||||
assert_eq!((standing.done, standing.total), (1, 2));
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The frame takes its three rows off the columns rather than off the footer, and
|
||||
@@ -7070,8 +7046,6 @@ mod tests {
|
||||
plain.height - Chrome::CAMPAIGN_ROWS,
|
||||
"the frame took its rows from somewhere else"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------- the frame's own prose --
|
||||
@@ -7141,8 +7115,6 @@ mod tests {
|
||||
let wanted = format!("Line {:03}", at + 1);
|
||||
assert!(drawn.contains(&wanted), "no {wanted} on the frame: {drawn:?}");
|
||||
}
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Up past the top card reaches the frame, and down comes back to the column it was
|
||||
@@ -7171,8 +7143,6 @@ mod tests {
|
||||
assert_eq!(board.current().focus, Focus::Cards, "down did not leave the frame");
|
||||
assert_eq!(board.current().column, 1, "down landed in a different column");
|
||||
assert_eq!(selected_title(&board).as_deref(), Some("Also in v1"));
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// An empty column reaches it too. A column with no card to stand on must not be a
|
||||
@@ -7194,8 +7164,6 @@ mod tests {
|
||||
|
||||
board.select_card(1, SCREEN);
|
||||
assert_eq!(board.current().column, 2, "down landed somewhere else");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The two keys the overlay reads a ticket with read the frame's description, clamped
|
||||
@@ -7222,8 +7190,6 @@ mod tests {
|
||||
|
||||
board.scroll_page(-40, SCREEN);
|
||||
assert_eq!(board.current().frame_offset, 0, "the scroll ran off the top");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// And only while it holds the selection. On the cards the keys are what they were
|
||||
@@ -7236,8 +7202,6 @@ mod tests {
|
||||
|
||||
board.scroll_page(1, SCREEN);
|
||||
assert_eq!(board.current().frame_offset, 0, "the frame scrolled from the cards");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// An open ticket keeps both keys whatever holds the selection behind it. It is the
|
||||
@@ -7272,8 +7236,6 @@ mod tests {
|
||||
|
||||
assert!(board.offset > 0, "the open ticket lost the scroll keys");
|
||||
assert_eq!(board.current().frame_offset, 0, "the frame took them from under it");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// And the frame is out of reach from under an open ticket. Up and down step through
|
||||
@@ -7290,8 +7252,6 @@ mod tests {
|
||||
board.select_card(-1, SCREEN);
|
||||
assert_eq!(board.current().focus, Focus::Cards, "the frame took the selection");
|
||||
assert!(board.detail.is_some(), "the overlay closed on an arrow key");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The frame says there is more of it than fits, in the words the overlay says it in:
|
||||
@@ -7319,8 +7279,6 @@ mod tests {
|
||||
second.contains("pg 2/"),
|
||||
"the indicator did not follow the scroll: {second:?}"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A description that fits leaves the frame selectable and the keys inert. Making the
|
||||
@@ -7344,8 +7302,6 @@ mod tests {
|
||||
!bottom.contains("pg "),
|
||||
"an indicator over a description that fits: {bottom:?}"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A campaign with no description is reachable and spends its rows on the placeholder.
|
||||
@@ -7374,8 +7330,6 @@ mod tests {
|
||||
|
||||
board.select_card(-1, SCREEN);
|
||||
assert_eq!(board.current().focus, Focus::Frame, "an empty frame was unreachable");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The footer describes the keys that work where the selection is, which on the frame
|
||||
@@ -7398,8 +7352,6 @@ mod tests {
|
||||
);
|
||||
// And the last slot still answers how to get out, which from here is `ctrl-c`.
|
||||
assert!(row.contains("ctrl-c quit"), "nothing says what quits from here:\n{row}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// No card is selected while the frame holds the selection, and none is drawn as if it
|
||||
@@ -7425,8 +7377,6 @@ mod tests {
|
||||
|
||||
board.select_card(1, SCREEN);
|
||||
assert!(a_card_is_highlighted(&board, 120, 20), "the highlight did not come back");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// `y` copies the id of what is selected in every state the selection can be in, and on
|
||||
@@ -7445,8 +7395,6 @@ mod tests {
|
||||
Some(short_id("11111111-0000-4000-8000-000000000000")),
|
||||
"back on the cards it is not the ticket's id"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Left and right do nothing on the frame. It spans the width of the board, so there is
|
||||
@@ -7462,8 +7410,6 @@ mod tests {
|
||||
board.select_column(1, SCREEN);
|
||||
assert_eq!(board.current().focus, Focus::Frame, "a column key left the frame");
|
||||
assert_eq!(board.current().column, 1, "a column key moved where down comes back to");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// `q` gives the whole board back from the frame, as it does from the columns: the
|
||||
@@ -7485,8 +7431,6 @@ mod tests {
|
||||
|
||||
let all: usize = board.current().columns.iter().map(|c| c.cards.len()).sum();
|
||||
assert_eq!(all, 4, "the whole board did not come back");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A jump lands on a card, so it takes the selection off the frame: `/` reaching a
|
||||
@@ -7510,8 +7454,6 @@ mod tests {
|
||||
"the jump left the selection on the frame"
|
||||
);
|
||||
assert_eq!(selected_title(&board).as_deref(), Some("Also in v1"));
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The offset is the tab's, beside the filter, since the filter is per tab: how far into
|
||||
@@ -7545,9 +7487,6 @@ mod tests {
|
||||
board.select_tab(-2, SCREEN);
|
||||
assert_eq!(board.current().frame_offset, at, "the tab did not keep its place");
|
||||
assert_eq!(board.current().focus, Focus::Frame, "the tab did not keep its focus");
|
||||
|
||||
std::fs::remove_dir_all(&one).ok();
|
||||
std::fs::remove_dir_all(&two).ok();
|
||||
}
|
||||
|
||||
/// Changing the filter puts the frame back at the top, the answer `refresh_detail`
|
||||
@@ -7564,8 +7503,6 @@ mod tests {
|
||||
board.select_campaign(Some(BEAVER.to_string()), SCREEN);
|
||||
assert_eq!(board.current().frame_offset, 0, "the new campaign opened partway down");
|
||||
assert_eq!(board.current().focus, Focus::Cards, "the selection stayed on the frame");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------- the frame's two heights --
|
||||
@@ -7606,8 +7543,6 @@ mod tests {
|
||||
board.toggle_focused(SCREEN);
|
||||
assert!(!board.current().expanded, "the tab did not collapse");
|
||||
assert_eq!(frame_height(&board, SCREEN), collapsed, "the rows did not come back");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// And only from the frame. `enter` on a card is the overlay's, which is what the routing
|
||||
@@ -7623,8 +7558,6 @@ mod tests {
|
||||
|
||||
board.toggle_focused(SCREEN);
|
||||
assert!(board.detail.is_none(), "enter did not close the ticket");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Half of what the frame and the columns divide, which is the screen less the tab row
|
||||
@@ -7644,8 +7577,6 @@ mod tests {
|
||||
let columns = board_area(SCREEN, board.chrome()).height;
|
||||
assert!(columns >= shared / 2, "the cards did not keep the odd row");
|
||||
assert_eq!(frame_height(&board, SCREEN) + columns + FOOTER_ROWS, SCREEN.height);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The share is bounded at both ends, and a sweep is what says so rather than one screen
|
||||
@@ -7720,8 +7651,6 @@ mod tests {
|
||||
rows[BOARD_ROW].height - 2,
|
||||
"the cards are laid out against a column of another height"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The scroll keys go on doing what they do, and the indicator repages: the step and the
|
||||
@@ -7748,8 +7677,6 @@ mod tests {
|
||||
let text = frame_text_area(SCREEN, board.chrome());
|
||||
let last = last_offset(&frame_prose(board.campaign().expect("no campaign")), text);
|
||||
assert_eq!(board.current().frame_offset, last, "the scroll ran past the description");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A description that did not fit the collapsed frame and does fit the expanded one
|
||||
@@ -7767,8 +7694,6 @@ mod tests {
|
||||
|
||||
board.scroll_page(1, SCREEN);
|
||||
assert_eq!(board.current().frame_offset, 0, "prose that fits scrolled");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A description that fits the collapsed frame expands anyway. A key that worked on one
|
||||
@@ -7787,8 +7712,6 @@ mod tests {
|
||||
frame_height(&board, SCREEN) > Chrome::CAMPAIGN_ROWS,
|
||||
"the frame did not grow"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// `q` takes the campaign filter off from an expanded frame exactly as it does from a
|
||||
@@ -7809,8 +7732,6 @@ mod tests {
|
||||
|
||||
let all: usize = board.current().columns.iter().map(|c| c.cards.len()).sum();
|
||||
assert_eq!(all, 4, "the whole board did not come back");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Up and down leave the height where it was. The reader chose a view of the campaign;
|
||||
@@ -7830,8 +7751,6 @@ mod tests {
|
||||
|
||||
board.select_card(-1, SCREEN);
|
||||
assert!(board.current().expanded, "up changed the height");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The footer says which of the two `enter` is about to do, since the key is a toggle and
|
||||
@@ -7850,8 +7769,6 @@ mod tests {
|
||||
let row = footer(&board, 120, 20);
|
||||
assert!(row.contains("enter collapse"), "enter still offered as expand:\n{row}");
|
||||
assert!(!row.contains("enter expand"), "the row names it both ways:\n{row}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Expanding and collapsing leave the reader where they were rather than at the top. The
|
||||
@@ -7877,8 +7794,6 @@ mod tests {
|
||||
|
||||
board.toggle_focused(SCREEN);
|
||||
assert!(board.current().frame_offset > 0, "collapsing went back to the top");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The height is the tab's own, beside the filter it belongs to, so switching away and
|
||||
@@ -7908,9 +7823,6 @@ mod tests {
|
||||
|
||||
board.select_tab(-2, SCREEN);
|
||||
assert!(board.current().expanded, "the tab did not keep its height");
|
||||
|
||||
std::fs::remove_dir_all(&one).ok();
|
||||
std::fs::remove_dir_all(&two).ok();
|
||||
}
|
||||
|
||||
/// And selecting another campaign opens its frame collapsed, the answer `select_campaign`
|
||||
@@ -7926,8 +7838,6 @@ mod tests {
|
||||
board.select_campaign(Some(BEAVER.to_string()), SCREEN);
|
||||
assert!(!board.current().expanded, "the new campaign opened at half the board");
|
||||
assert_eq!(frame_height(&board, SCREEN), Chrome::CAMPAIGN_ROWS);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A campaign that leaves the board takes the frame with it, focus and offset both: the
|
||||
@@ -7958,8 +7868,6 @@ mod tests {
|
||||
"the selection is on a frame nothing draws"
|
||||
);
|
||||
assert_eq!(board.current().frame_offset, 0, "the offset outlived the description");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// `q` takes off one layer at a time, in the order they were put on: the overlay, then
|
||||
@@ -7980,8 +7888,6 @@ mod tests {
|
||||
|
||||
board.dismiss(SCREEN);
|
||||
assert!(board.should_quit, "nothing left to close and it did not quit");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// And the overlay comes off before the campaign, so one press takes off one layer.
|
||||
@@ -7996,8 +7902,6 @@ mod tests {
|
||||
board.dismiss(SCREEN);
|
||||
assert!(board.detail.is_none(), "the overlay stayed open");
|
||||
assert_eq!(board.current().campaign, Some(V1.to_string()), "the filter came off too");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Selecting a campaign closes an open ticket, the answer hiding the done column
|
||||
@@ -8012,8 +7916,6 @@ mod tests {
|
||||
|
||||
board.select_campaign(Some(BEAVER.to_string()), SCREEN);
|
||||
assert!(board.detail.is_none(), "the overlay survived the filter");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The picker owns the keyboard while it is open, the rule the search prompt already
|
||||
@@ -8043,8 +7945,6 @@ mod tests {
|
||||
// reach the arm bound to `d`.
|
||||
board.picker_key(KeyEvent::new(KeyCode::Char('d'), KeyModifiers::CONTROL), SCREEN);
|
||||
assert!(!board.show_done, "ctrl-d reached the done column");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// `ctrl-c` is the one key it declines, because a terminal application always honours
|
||||
@@ -8058,8 +7958,6 @@ mod tests {
|
||||
assert!(
|
||||
!board.picker_key(KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL), SCREEN)
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The point of the list: move to a campaign, press enter, look at it.
|
||||
@@ -8076,8 +7974,6 @@ mod tests {
|
||||
board.picker_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE), SCREEN);
|
||||
assert!(board.picker.is_none(), "the picker stayed open");
|
||||
assert_eq!(board.current().campaign, Some(BEAVER.to_string()));
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Esc leaves the board exactly as it was, so opening the list is never a commitment.
|
||||
@@ -8092,8 +7988,6 @@ mod tests {
|
||||
|
||||
assert!(board.picker.is_none(), "the picker stayed open");
|
||||
assert_eq!(board.current().campaign, Some(V1.to_string()), "the filter moved");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// It opens on the campaign already selected, so `c` on a filtered board says where
|
||||
@@ -8109,8 +8003,6 @@ mod tests {
|
||||
.picker_highlight()
|
||||
.expect("the highlight is on no campaign");
|
||||
assert_eq!(highlighted.uuid, V1);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A board with no campaigns says so in words rather than opening an empty box that
|
||||
@@ -8127,8 +8019,6 @@ mod tests {
|
||||
let notice = board.notice.as_ref().expect("nothing was said");
|
||||
assert!(notice.text.contains("no campaigns"), "{:?}", notice.text);
|
||||
assert!(notice.failed, "a key that did nothing read as a key that worked");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The rows carry the three things a campaign is chosen by, and the description is the
|
||||
@@ -8150,8 +8040,6 @@ mod tests {
|
||||
// And the footer is the picker's while it is open, for the reason the prompt takes
|
||||
// it: the board's key list describes nothing that currently works.
|
||||
assert!(footer(&board, 100, 24).contains("enter view"), "the footer is the board's");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A campaign with no codename shows the id once, not twice: the row already opens
|
||||
@@ -8173,8 +8061,6 @@ mod tests {
|
||||
|
||||
assert_eq!(row.matches(short_id(V1)).count(), 1, "the id is on the row twice: {row:?}");
|
||||
assert!(!row.contains(CAMPAIGN_MARK), "a mark with nothing after it: {row:?}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A campaign filed elsewhere has to reach the board, and the digest is what decides
|
||||
@@ -8196,8 +8082,6 @@ mod tests {
|
||||
write_campaign(&dir, V1, "First public release", "beaver", "For a public tag.");
|
||||
assert!(board.tick().unwrap(), "an edited campaign moved nothing");
|
||||
assert_eq!(board.current().campaigns[0].codename.as_deref(), Some("beaver"));
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A selection whose campaign has left the board goes back to the whole board rather
|
||||
@@ -8215,8 +8099,6 @@ mod tests {
|
||||
assert_eq!(board.current().campaign, None, "the filter outlived its campaign");
|
||||
let all: usize = board.current().columns.iter().map(|c| c.cards.len()).sum();
|
||||
assert_eq!(all, 4, "the board stayed filtered to nothing");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// One flat list ordered by title put the completed campaigns among the open ones
|
||||
@@ -8242,8 +8124,6 @@ mod tests {
|
||||
|
||||
// A heading is chrome, and grey is what the guideline gives to what a reader skips.
|
||||
assert_eq!(picker_row_color(&board, open, 100, 24), Color::Grey.into());
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// `Standing::state` calls a campaign with no members neither open nor done. For the
|
||||
@@ -8276,8 +8156,6 @@ mod tests {
|
||||
row_with(&rows, short_id(BEAVER)) < row_at(&rows, COMPLETED_SECTION),
|
||||
"a campaign with no members listed as completed: {rows:?}"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The completed tail is truncated to the couple most recently filed, and the line under
|
||||
@@ -8312,8 +8190,6 @@ mod tests {
|
||||
rows[hidden]
|
||||
);
|
||||
assert_eq!(picker_row_color(&board, hidden, 100, 24), Color::Grey.into());
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// One campaign hidden is one campaign, since a line that misspells what it is counting
|
||||
@@ -8349,8 +8225,6 @@ mod tests {
|
||||
board.open_picker();
|
||||
type_picker_query(&mut board, short_id(FINISHED[3].0));
|
||||
assert_eq!(picked_ids(&board), vec![FINISHED[3].0.to_string()], "the id missed");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The summary is drawn on the row but is not what the row is chosen by: a query that
|
||||
@@ -8364,8 +8238,6 @@ mod tests {
|
||||
// Beaver's summary reads "Move the store off one disk." and its title does not.
|
||||
type_picker_query(&mut board, "disk");
|
||||
assert_eq!(picked_ids(&board), vec![FINISHED[0].0.to_string()], "the summary matched");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A search reaches the whole completed tail, untruncated, which is the point of having
|
||||
@@ -8394,8 +8266,6 @@ mod tests {
|
||||
!rows.iter().any(|row| row.contains("older completed")),
|
||||
"the query left the truncation on: {rows:?}"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// While the query is open the picker still owns the keyboard, so `q` types rather than
|
||||
@@ -8422,8 +8292,6 @@ mod tests {
|
||||
|
||||
press(&mut board, KeyCode::Esc);
|
||||
assert!(board.picker.is_none(), "the second esc left the picker open");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Enter takes the highlighted row whether a query is open or not: filtering is how the
|
||||
@@ -8444,8 +8312,6 @@ mod tests {
|
||||
press(&mut board, KeyCode::Enter);
|
||||
assert!(board.picker.is_none(), "the picker stayed open");
|
||||
assert_eq!(board.current().campaign, Some(BEAVER.to_string()));
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A query that matches nothing keeps the picker and the query open, and says so in the
|
||||
@@ -8466,8 +8332,6 @@ mod tests {
|
||||
assert!(board.picker.is_some(), "enter on a miss closed the picker");
|
||||
assert_eq!(query_of(&board).as_deref(), Some("zzz"), "the query was taken away");
|
||||
assert_eq!(board.current().campaign, None, "a miss selected something");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Section headings and the truncation line take no number: they are not campaigns, so
|
||||
@@ -8509,8 +8373,6 @@ mod tests {
|
||||
}
|
||||
back.reverse();
|
||||
assert_eq!(back, walked[..3], "the walk back is not the walk out");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The highlight follows the campaign it was on rather than the number it was at: a
|
||||
@@ -8532,8 +8394,6 @@ mod tests {
|
||||
// And back to the whole list, still on it.
|
||||
press(&mut board, KeyCode::Esc);
|
||||
assert_eq!(highlighted(&board).as_deref(), Some(V1), "clearing the query lost it");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// A query that excludes the highlighted campaign drops the highlight to the first row
|
||||
@@ -8547,8 +8407,6 @@ mod tests {
|
||||
|
||||
type_picker_query(&mut board, "polish");
|
||||
assert_eq!(highlighted(&board).as_deref(), Some(FINISHED[2].0));
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The footer is the picker's while it is open, and the query's while that is open: with
|
||||
@@ -8566,8 +8424,6 @@ mod tests {
|
||||
assert!(row.contains("/beav"), "the query is not on the row: {row:?}");
|
||||
assert!(row.contains("esc clear"), "the row does not say what esc does: {row:?}");
|
||||
assert!(!row.contains("/ search"), "the row names a key that types: {row:?}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The bare count is what the box is. A query that cuts the list down makes the total
|
||||
@@ -8586,8 +8442,6 @@ mod tests {
|
||||
|
||||
type_picker_query(&mut board, "migration");
|
||||
assert_eq!(title(&board), " campaigns (2 of 6) ");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The standing on every row is settled at reload, off the cards the reload already
|
||||
@@ -8614,8 +8468,6 @@ mod tests {
|
||||
rows.iter().any(|row| row.contains(short_id(FINISHED[3].0))),
|
||||
"a completed campaign left the section: {rows:?}"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Paired with the test above, which would pass by never asking the filesystem again:
|
||||
@@ -8646,8 +8498,6 @@ mod tests {
|
||||
let v1 = campaigns.iter().find(|row| row.uuid == V1).expect("no v1");
|
||||
assert_eq!((v1.standing.done, v1.standing.total), (1, 1), "the standing did not move");
|
||||
assert!(v1.completed(), "a campaign whose every member is done stayed open");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The highlight survives a tick, on the campaign rather than on the number: one filed
|
||||
@@ -8669,8 +8519,6 @@ mod tests {
|
||||
Some(V1),
|
||||
"the highlight held its row rather than its campaign"
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The key is named where a reader has to find it, and left out where the frame's own
|
||||
@@ -8686,8 +8534,6 @@ mod tests {
|
||||
let footer = footer(&board, 120, 24);
|
||||
assert!(footer.contains("ctrl-c quit"), "q still claims to quit: {footer:?}");
|
||||
assert!(!footer.contains("q quit"), "{footer:?}");
|
||||
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// The filter belongs to the tab, not the board: a campaign is resolved inside one
|
||||
@@ -8721,8 +8567,5 @@ mod tests {
|
||||
// And the tab it was set on kept it.
|
||||
board.select_tab(-1, SCREEN);
|
||||
assert_eq!(board.current().campaign, Some(V1.to_string()));
|
||||
|
||||
std::fs::remove_dir_all(&one).ok();
|
||||
std::fs::remove_dir_all(&two).ok();
|
||||
}
|
||||
}
|
||||
|
||||
+185
-18
@@ -1843,6 +1843,12 @@ pub fn clear_section_body(content: &str, section: &Section) -> Result<String> {
|
||||
}
|
||||
|
||||
/// The line surgery both of the above are, given a body that is already rendered.
|
||||
///
|
||||
/// The refusal names the section and not the file it is missing from, because both a ticket
|
||||
/// and a campaign reach here: `campaign set --description` writes a campaign's one prose
|
||||
/// section through this, so "Ticket has no description section" would be wrong half the
|
||||
/// time. `write_then_replace` carries the noun instead, where a message about a *file* is
|
||||
/// worth spelling.
|
||||
fn replace_section_body(
|
||||
content: &str,
|
||||
section: &Section,
|
||||
@@ -1850,7 +1856,7 @@ fn replace_section_body(
|
||||
) -> Result<String> {
|
||||
let lines: Vec<&str> = content.lines().collect();
|
||||
let body = section_body(&lines, section.heading)
|
||||
.ok_or_else(|| anyhow!("Ticket has no {} section", section.label))?;
|
||||
.ok_or_else(|| anyhow!("There is no {} section to write to", section.label))?;
|
||||
|
||||
let mut out: Vec<String> = lines[..body.start].iter().map(|l| l.to_string()).collect();
|
||||
out.extend(body_lines);
|
||||
@@ -1871,7 +1877,7 @@ fn replace_section_body(
|
||||
pub fn append_section_body(content: &str, section: &Section, items: &[String]) -> Result<String> {
|
||||
let lines: Vec<&str> = content.lines().collect();
|
||||
let body = section_body(&lines, section.heading)
|
||||
.ok_or_else(|| anyhow!("Ticket has no {} section", section.label))?;
|
||||
.ok_or_else(|| anyhow!("There is no {} section to write to", section.label))?;
|
||||
|
||||
let at = body_content_end(&lines, &body);
|
||||
let existing: Vec<&&str> = lines[body.start..at]
|
||||
@@ -3077,10 +3083,183 @@ pub fn by_status_order(status: Status, a: &TicketItem, b: &TicketItem) -> std::c
|
||||
by_stamp.then_with(|| by_priority_then_title(a, b))
|
||||
}
|
||||
|
||||
/// The environment variable that keeps a test's fixture directory on disk.
|
||||
///
|
||||
/// Opt-in rather than on-by-default-when-a-test-fails, because the assertions in this crate
|
||||
/// carry the state they are about: a failing board test prints the rendered rows, a failing
|
||||
/// listing test prints the listing. The path is what you want when you would rather poke at
|
||||
/// the files than read the message, which is the less common of the two.
|
||||
#[cfg(test)]
|
||||
pub const KEEP_FIXTURES: &str = "WORKLANE_KEEP_FIXTURES";
|
||||
|
||||
/// A fixture directory under the system temp directory that removes itself.
|
||||
///
|
||||
/// Every unit test in this crate builds its board or its status directory by hand under
|
||||
/// `std::env::temp_dir()`. The ones that remembered a `remove_dir_all` at the end of the
|
||||
/// test only cleaned up when their assertions passed, and most had no such line at all, so
|
||||
/// a full run left one directory per test behind. `/tmp` reached 18363 of them and filled
|
||||
/// the disk, which failed a link step and then a `git add` with "No space left on device" —
|
||||
/// an error that names neither the tests nor what they left behind. That is b74dc5a.
|
||||
///
|
||||
/// A `Drop` rather than a line at the end of each test, because that is the only shape that
|
||||
/// runs when an assertion fails, which is exactly when a fixture is most likely to be
|
||||
/// stranded: unwinding runs destructors, so the guard holds on the failing path without the
|
||||
/// test having to say anything.
|
||||
///
|
||||
/// `assert_fs::TempDir` is a dev-dependency already and is what the integration tests use,
|
||||
/// and it was still not the answer here. It names its directories `.tmpXXXXXX`, which says
|
||||
/// nothing about whose they are for the one case that matters — the one left on disk on
|
||||
/// purpose — and it has no opinion about naming the path when it keeps one. Wrapping it to
|
||||
/// add both is more code than this.
|
||||
///
|
||||
/// `Deref` to `Path`, so a fixture reads as the path it stands for at the call sites that
|
||||
/// already had one and nothing had to change but the type.
|
||||
#[cfg(test)]
|
||||
pub struct Fixture {
|
||||
/// What is removed: the directory this fixture created at the top.
|
||||
root: std::path::PathBuf,
|
||||
/// What the test works with, at or below the root. The two differ only for a fixture
|
||||
/// that needs a named directory inside a parent it can also throw away.
|
||||
path: std::path::PathBuf,
|
||||
/// Whether to leave the directory behind, read once here rather than at drop time.
|
||||
///
|
||||
/// At construction because the answer must not be able to change between a test
|
||||
/// starting and ending, and because it is what [`Fixture::swept`] can then turn off for
|
||||
/// the tests that are about the guard rather than about this flag.
|
||||
keep: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl Fixture {
|
||||
/// A fresh directory, named after the family of tests that asked for it.
|
||||
///
|
||||
/// The prefix earns its place on the kept path: `worklane-tui-` says which suite left it
|
||||
/// where a random name would not, and the uuid is what makes two fixtures with one
|
||||
/// prefix two directories, so no test can reach another's.
|
||||
pub fn new(prefix: &str) -> Self {
|
||||
let root = std::env::temp_dir().join(format!("{prefix}-{}", uuid::Uuid::new_v4()));
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
|
||||
Fixture {
|
||||
path: root.clone(),
|
||||
root,
|
||||
keep: std::env::var_os(KEEP_FIXTURES).is_some(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The same fixture, swept up whatever the environment says.
|
||||
///
|
||||
/// For the tests below, which assert that the directory goes: they are about the guard
|
||||
/// and not about the flag, so `WORKLANE_KEEP_FIXTURES` in a reader's environment must
|
||||
/// not be able to fail them.
|
||||
pub fn swept(mut self) -> Self {
|
||||
self.keep = false;
|
||||
self
|
||||
}
|
||||
|
||||
/// The same fixture, pointing at a directory inside it.
|
||||
///
|
||||
/// For the tree a project test needs: `<root>/<project>/.worklane`, where the path the
|
||||
/// test hands to `projects` is the project and what has to be removed is the root above
|
||||
/// it. Consuming, so one directory never has two guards and therefore never two attempts
|
||||
/// to remove it.
|
||||
pub fn child(mut self, name: &str) -> Self {
|
||||
self.path = self.root.join(name);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl AsRef<std::path::Path> for Fixture {
|
||||
fn as_ref(&self) -> &std::path::Path {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
|
||||
/// Beside `AsRef`, because the two reach different call sites: a parameter bound by
|
||||
/// `impl AsRef<Path>` is not a coercion site, and a parameter typed `&Path` is.
|
||||
#[cfg(test)]
|
||||
impl std::ops::Deref for Fixture {
|
||||
type Target = std::path::Path;
|
||||
|
||||
fn deref(&self) -> &std::path::Path {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl Drop for Fixture {
|
||||
fn drop(&mut self) {
|
||||
if self.keep {
|
||||
// Named, since a fixture kept and not findable is a fixture kept for nothing.
|
||||
eprintln!("kept fixture {}", self.root.display());
|
||||
return;
|
||||
}
|
||||
|
||||
// Best effort. A directory that will not go must not turn a passing test into a
|
||||
// failing one, and must not panic a second time out of a drop that is already
|
||||
// unwinding, which would lose the failure the test was reporting.
|
||||
std::fs::remove_dir_all(&self.root).ok();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// The guard removes the directory when it goes out of scope, which is what makes the
|
||||
/// cleanup independent of the assertions passing: unwinding runs destructors, so a
|
||||
/// failing test drops its fixture on the way out exactly as a passing one does.
|
||||
#[test]
|
||||
fn a_fixture_removes_itself_when_its_guard_goes() {
|
||||
let path = {
|
||||
let dir = Fixture::new("worklane-guard").swept();
|
||||
fs::write(dir.join("a.md"), "body").unwrap();
|
||||
assert!(dir.exists(), "the fixture was not created");
|
||||
dir.to_path_buf()
|
||||
};
|
||||
|
||||
assert!(!path.exists(), "the fixture outlived its guard: {}", path.display());
|
||||
}
|
||||
|
||||
/// And on the failing path, which is the whole point: a line at the end of a test does
|
||||
/// not run when an assertion above it does not pass.
|
||||
#[test]
|
||||
fn a_fixture_removes_itself_when_the_test_panics() {
|
||||
// The default hook would print this deliberate panic and make a green run read as a
|
||||
// red one. Swapped for the length of the call and put straight back, which is as
|
||||
// narrow as a process-wide hook can be made.
|
||||
let hook = std::panic::take_hook();
|
||||
std::panic::set_hook(Box::new(|_| {}));
|
||||
let caught = std::panic::catch_unwind(|| {
|
||||
let dir = Fixture::new("worklane-guard").swept();
|
||||
// Handed out through the payload, so the assertion below has a path to look at
|
||||
// whether or not the guard did its job.
|
||||
std::panic::panic_any(dir.to_path_buf());
|
||||
});
|
||||
std::panic::set_hook(hook);
|
||||
|
||||
let path = *caught
|
||||
.expect_err("the closure did not panic")
|
||||
.downcast::<std::path::PathBuf>()
|
||||
.expect("the panic did not carry the fixture path");
|
||||
|
||||
assert!(!path.exists(), "the fixture survived a failing test: {}", path.display());
|
||||
}
|
||||
|
||||
/// Two fixtures with one prefix are two directories, so no test can rely on one another
|
||||
/// test built — which the shared temp directory is what made possible.
|
||||
#[test]
|
||||
fn two_fixtures_with_one_prefix_are_two_directories() {
|
||||
let first = Fixture::new("worklane-guard");
|
||||
let second = Fixture::new("worklane-guard");
|
||||
assert_ne!(first.to_path_buf(), second.to_path_buf(), "one directory, two guards");
|
||||
|
||||
let kept = second.to_path_buf();
|
||||
drop(first);
|
||||
assert!(kept.exists(), "one fixture going took the other with it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_color_disables_colour_on_a_terminal() {
|
||||
assert!(!colors_wanted(true, Some("1"), Some("xterm-256color")));
|
||||
@@ -3454,8 +3633,7 @@ mod tests {
|
||||
/// in `show`, so the two cannot disagree about what a criterion is.
|
||||
#[test]
|
||||
fn collect_ticket_items_counts_the_criteria_show_would_number() {
|
||||
let dir = std::env::temp_dir().join(format!("worklane-count-{}", uuid::Uuid::new_v4()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
let dir = Fixture::new("worklane-count");
|
||||
|
||||
let write = |name: &str, body: &str| {
|
||||
fs::write(
|
||||
@@ -3480,8 +3658,6 @@ mod tests {
|
||||
counted.contains(&None),
|
||||
"a ticket with no criteria got a count: {counted:?}"
|
||||
);
|
||||
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
|
||||
/// The count is a directory listing rather than a read: nothing here parses a comment,
|
||||
@@ -3537,8 +3713,7 @@ mod tests {
|
||||
/// listing that stops on one malformed ticket is the worse failure.
|
||||
#[test]
|
||||
fn collect_ticket_items_reads_the_uuid_and_the_blockers_it_records() {
|
||||
let dir = std::env::temp_dir().join(format!("worklane-blocked-{}", uuid::Uuid::new_v4()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
let dir = Fixture::new("worklane-blocked");
|
||||
|
||||
let uuid = |tail: &str| format!("11111111-0000-4000-8000-00000000000{tail}");
|
||||
let write = |name: &str, relations: &str| {
|
||||
@@ -3563,8 +3738,6 @@ mod tests {
|
||||
assert_eq!(of("T1").blockers, vec![uuid("2")]);
|
||||
assert!(of("T2").blockers.is_empty(), "a regression was read as a blocker");
|
||||
assert!(of("T3").blockers.is_empty(), "an unreadable section was not survived");
|
||||
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
|
||||
/// Whole values, so a filter or a card cannot confuse two tags that share a prefix.
|
||||
@@ -3591,8 +3764,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn collect_ticket_items_lists_only_md_files() {
|
||||
let dir = std::env::temp_dir().join(format!("worklane-stray-{}", uuid::Uuid::new_v4()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
let dir = Fixture::new("worklane-stray");
|
||||
|
||||
fs::write(
|
||||
dir.join("11111111-0000-4000-8000-000000000001.md"),
|
||||
@@ -3608,8 +3780,6 @@ mod tests {
|
||||
let titles: Vec<&str> = items.iter().map(|item| item.title.as_str()).collect();
|
||||
|
||||
assert_eq!(titles, vec!["Real"], "{titles:?}");
|
||||
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
|
||||
/// The template ticket, and the shape every insertion test measures against.
|
||||
@@ -3927,8 +4097,7 @@ mod tests {
|
||||
/// comparison time, which is what makes an ordered column cost one read per file.
|
||||
#[test]
|
||||
fn collect_ticket_items_reads_the_stamps_the_order_sorts_on() {
|
||||
let dir = std::env::temp_dir().join(format!("worklane-stamps-{}", uuid::Uuid::new_v4()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
let dir = Fixture::new("worklane-stamps");
|
||||
|
||||
fs::write(
|
||||
dir.join("aaaa_walked.md"),
|
||||
@@ -3959,8 +4128,6 @@ mod tests {
|
||||
assert_eq!(fresh.committed_on, None);
|
||||
assert_eq!(fresh.submitted_on, None);
|
||||
assert_eq!(fresh.completed_on, None);
|
||||
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
|
||||
/// Removal is scoped to the section for the same reason the write is: a description
|
||||
|
||||
+445
-5
@@ -1129,11 +1129,13 @@ fn an_unknown_campaign_is_refused_and_nothing_is_written() {
|
||||
);
|
||||
}
|
||||
|
||||
/// No `--description`: `set` and `append` are a pair for a prose section, and a way to
|
||||
/// replace a description with no way to add a paragraph is half of it. Pinned so the
|
||||
/// omission stays a decision rather than becoming an oversight somebody fills in.
|
||||
/// `--description` arrived with `campaign append`, 32e98ab, because for a prose section the
|
||||
/// two are a pair. What is still deliberately absent is what this pins: no `--owner`, which
|
||||
/// would settle by accident whether `chown` grows a campaign, and no `--clear`, because a
|
||||
/// campaign's description has no cleared form and `Clearable`'s variants are a ticket's
|
||||
/// fields.
|
||||
#[test]
|
||||
fn campaign_set_offers_no_description_and_no_owner() {
|
||||
fn campaign_set_offers_no_owner_and_no_clear() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
@@ -1142,7 +1144,7 @@ fn campaign_set_offers_no_description_and_no_owner() {
|
||||
|
||||
assert!(help.contains("--codename"), "{help}");
|
||||
assert!(help.contains("--title"), "{help}");
|
||||
assert!(!help.contains("--description"), "{help}");
|
||||
assert!(help.contains("--description"), "{help}");
|
||||
assert!(!help.contains("--owner"), "{help}");
|
||||
assert!(!help.contains("--clear"), "{help}");
|
||||
}
|
||||
@@ -1263,3 +1265,441 @@ fn the_title_is_replaced_without_force() {
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(campaign_file(&worklane, CAMP_A).starts_with("# First public release\n"));
|
||||
}
|
||||
|
||||
// ---------------------------------------------- campaign set --description --
|
||||
|
||||
/// The point of 32e98ab: the description a campaign was filed with is no longer the one it
|
||||
/// keeps. `create_campaign` writes prose, so this is a replacement rather than a first line.
|
||||
#[test]
|
||||
fn campaign_set_replaces_the_description() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
let out = run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"set",
|
||||
"v1 release",
|
||||
"--description",
|
||||
"What the tag has to hold.",
|
||||
],
|
||||
);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(stdout(&out).contains("Updated description"), "{}", stdout(&out));
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.contains("What the tag has to hold."), "{content}");
|
||||
assert!(
|
||||
!content.contains("What has to ship together."),
|
||||
"the old description survived: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// An empty value between two others is the paragraph break, the rule every prose argument
|
||||
/// in the tool follows: `add --description`, `set --description` and `tags --annotation`.
|
||||
#[test]
|
||||
fn an_empty_value_is_a_paragraph_break_in_a_campaigns_description() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
let out = run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"set",
|
||||
"v1 release",
|
||||
"-d",
|
||||
"The tag itself.",
|
||||
"-d",
|
||||
"",
|
||||
"-d",
|
||||
"And what blocks it.",
|
||||
],
|
||||
);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.contains("The tag itself.\n\nAnd what blocks it."), "{content}");
|
||||
}
|
||||
|
||||
/// And an all-blank value is refused rather than emptying the section. The refusal names no
|
||||
/// flag, because there is none: a campaign's description has no cleared form, which is the
|
||||
/// `Clearable` question 32e98ab settled rather than deferred.
|
||||
#[test]
|
||||
fn an_all_blank_description_is_refused_and_names_no_clear_flag() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
let before = campaign_file(&worklane, CAMP_A);
|
||||
|
||||
let out = run(&temp, &["campaign", "set", "v1 release", "-d", "", "-d", " "]);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
|
||||
let said = stderr(&out);
|
||||
assert!(said.contains("An empty value is a paragraph break"), "{said}");
|
||||
assert!(said.contains("no cleared form"), "{said}");
|
||||
assert!(!said.contains("--clear"), "it named a flag that does not exist: {said}");
|
||||
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the file was written");
|
||||
}
|
||||
|
||||
/// The whole-file comparison `set`, `chown` and the codename already use, so a description
|
||||
/// replaced with the one it already holds writes nothing.
|
||||
#[test]
|
||||
fn setting_the_description_a_campaign_already_has_writes_nothing() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
let before = campaign_file(&worklane, CAMP_A);
|
||||
|
||||
let out = run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"set",
|
||||
"v1 release",
|
||||
"-d",
|
||||
"What has to ship together.",
|
||||
],
|
||||
);
|
||||
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(stdout(&out).contains("No changes"), "{}", stdout(&out));
|
||||
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the file was rewritten");
|
||||
}
|
||||
|
||||
/// Three fields in one call, since the group is `multiple` and the description is in it.
|
||||
#[test]
|
||||
fn campaign_set_takes_the_title_the_description_and_the_codename_together() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
let out = run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"set",
|
||||
"v1 release",
|
||||
"-t",
|
||||
"First public release",
|
||||
"-d",
|
||||
"What the tag has to hold.",
|
||||
"-c",
|
||||
"v1",
|
||||
],
|
||||
);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(stdout(&out).contains("title, description, codename"), "{}", stdout(&out));
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.starts_with("# First public release\n"), "{content}");
|
||||
assert!(content.contains("What the tag has to hold."), "{content}");
|
||||
assert!(content.contains("- **Codename**: v1"), "{content}");
|
||||
}
|
||||
|
||||
/// A refused codename takes the description down with it, the way it already takes the
|
||||
/// title: checked before any edit is applied, so a call writes all of what it asked for or
|
||||
/// none of it.
|
||||
#[test]
|
||||
fn a_refused_codename_takes_the_description_down_with_it() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
|
||||
let before = campaign_file(&worklane, CAMP_A);
|
||||
|
||||
let out = run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"set",
|
||||
"v1",
|
||||
"-d",
|
||||
"Rewritten anyway.",
|
||||
"-c",
|
||||
"beaver",
|
||||
],
|
||||
);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
|
||||
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the description went through");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------- campaign append --
|
||||
|
||||
/// The other half of the pair, and the reason `set --description` is not a flag on its own:
|
||||
/// adding a line to a description must not mean retyping the rest of it.
|
||||
#[test]
|
||||
fn campaign_append_adds_a_paragraph_without_replacing_the_description() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
let out = run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"append",
|
||||
"v1 release",
|
||||
"-d",
|
||||
"And what is out of scope.",
|
||||
],
|
||||
);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(stdout(&out).contains("Appended to description"), "{}", stdout(&out));
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
// The paragraph lands after the one that was there, with the blank line between them
|
||||
// that makes it a paragraph rather than a run-on.
|
||||
assert!(
|
||||
content.contains("What has to ship together.\n\nAnd what is out of scope.\n"),
|
||||
"{content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Several values in one call are lines *within* the paragraph, not several paragraphs. The
|
||||
/// same reading `append --description` gives a ticket, since it is the same section entry.
|
||||
#[test]
|
||||
fn the_values_of_one_append_are_lines_within_the_paragraph() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"append",
|
||||
"v1 release",
|
||||
"-d",
|
||||
"Out of scope:",
|
||||
"-d",
|
||||
"the installer.",
|
||||
],
|
||||
);
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.contains("Out of scope:\nthe installer.\n"), "{content}");
|
||||
}
|
||||
|
||||
/// A campaign filed with no description holds the placeholder, and appending replaces it
|
||||
/// rather than following it: the alternative reads `_No description provided._` above the
|
||||
/// description. `append_section_body`'s rule, so nothing here handles the case.
|
||||
#[test]
|
||||
fn appending_to_an_empty_description_replaces_the_placeholder() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
run(&temp, &["campaign", "add", "--title", "No prose yet"]);
|
||||
|
||||
let uuid = {
|
||||
let names = campaigns(&worklane);
|
||||
let name = names
|
||||
.iter()
|
||||
.find(|name| name.ends_with("_no-prose-yet.md"))
|
||||
.expect("the campaign was not filed");
|
||||
name.split('_').next().unwrap().to_string()
|
||||
};
|
||||
assert!(
|
||||
campaign_file(&worklane, &uuid).contains("_No description provided._"),
|
||||
"the placeholder is not what add writes any more"
|
||||
);
|
||||
|
||||
let out = run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"append",
|
||||
"No prose yet",
|
||||
"-d",
|
||||
"The first thing said.",
|
||||
],
|
||||
);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
|
||||
let content = campaign_file(&worklane, &uuid);
|
||||
assert!(content.contains("The first thing said."), "{content}");
|
||||
assert!(
|
||||
!content.contains("_No description provided._"),
|
||||
"the placeholder is still above the description: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Every value blank is refused rather than writing nothing quietly, the answer `append`
|
||||
/// gives a ticket, in the same words: appending nothing was never a way to empty anything,
|
||||
/// so there is no flag to name.
|
||||
#[test]
|
||||
fn an_all_blank_append_is_refused() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
let before = campaign_file(&worklane, CAMP_A);
|
||||
|
||||
let out = run(&temp, &["campaign", "append", "v1 release", "-d", " "]);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
|
||||
assert!(stderr(&out).contains("Nothing to append"), "{}", stderr(&out));
|
||||
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the file was written");
|
||||
}
|
||||
|
||||
/// A bare `campaign append <campaign>` is a usage error rather than a silent no-op, the way
|
||||
/// a bare `campaign set` is. `--description` is `required` rather than a group of one.
|
||||
#[test]
|
||||
fn campaign_append_with_no_description_is_a_usage_error() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
let before = campaign_file(&worklane, CAMP_A);
|
||||
|
||||
let out = run(&temp, &["campaign", "append", "v1 release"]);
|
||||
|
||||
assert_eq!(out.status.code(), Some(2), "{}", stderr(&out));
|
||||
assert_eq!(campaign_file(&worklane, CAMP_A), before, "something was written");
|
||||
}
|
||||
|
||||
/// Appending to a scalar has no meaning, which is the line `append` already draws for a
|
||||
/// ticket: no `--title` there and none here, and no `--codename` either.
|
||||
#[test]
|
||||
fn campaign_append_offers_only_the_description() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
let out = run(&temp, &["campaign", "append", "--help"]);
|
||||
let help = stdout(&out);
|
||||
|
||||
assert!(help.contains("--description"), "{help}");
|
||||
assert!(!help.contains("--title"), "{help}");
|
||||
assert!(!help.contains("--codename"), "{help}");
|
||||
assert!(!help.contains("--force"), "{help}");
|
||||
}
|
||||
|
||||
/// A campaign is addressed here by the same tiers everything else takes, codename included,
|
||||
/// because it goes through `resolve_campaign` rather than a lookup of its own.
|
||||
#[test]
|
||||
fn campaign_append_resolves_the_campaign_by_its_codename() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
run(&temp, &["campaign", "set", "v1 release", "-c", "beaver"]);
|
||||
|
||||
let out = run(&temp, &["campaign", "append", "beaver", "-d", "One more thing."]);
|
||||
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(
|
||||
campaign_file(&worklane, CAMP_A).contains("One more thing."),
|
||||
"{}",
|
||||
campaign_file(&worklane, CAMP_A)
|
||||
);
|
||||
}
|
||||
|
||||
/// An unknown campaign leaves every campaign alone, the answer `campaign set` and `assign`
|
||||
/// already give.
|
||||
#[test]
|
||||
fn campaign_append_refuses_an_unknown_campaign() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
let before = campaign_file(&worklane, CAMP_A);
|
||||
|
||||
let out = run(&temp, &["campaign", "append", "nothing-by-that-name", "-d", "Text."]);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
|
||||
assert!(stderr(&out).contains("No campaign found"), "{}", stderr(&out));
|
||||
assert_eq!(campaign_file(&worklane, CAMP_A), before, "something was written");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ the shared machinery --
|
||||
|
||||
/// A campaign has one section where a ticket has four, and the section table in `util.rs` is
|
||||
/// what both go through. So the surgery has to land against `## Metadata`, which is the only
|
||||
/// heading that follows a campaign's description, and leave everything outside the body
|
||||
/// alone: a handwritten section, the owner, and the codename in its place.
|
||||
#[test]
|
||||
fn the_description_is_edited_in_place_in_a_file_with_one_section() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
|
||||
|
||||
let path = worklane
|
||||
.join("campaigns")
|
||||
.join(format!("{}_{}.md", CAMP_A, slug("v1 release")));
|
||||
let original = fs::read_to_string(&path).unwrap();
|
||||
fs::write(
|
||||
&path,
|
||||
original.replace("## Metadata", "## Notes\nA handwritten note.\n\n## Metadata"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
run(&temp, &["campaign", "set", "v1", "-d", "Replaced."]);
|
||||
run(&temp, &["campaign", "append", "v1", "-d", "Added."]);
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.contains("## Description\nReplaced.\n\nAdded.\n"), "{content}");
|
||||
// Nothing outside the body moved: the section that follows it, the handwritten one
|
||||
// between them, and the fields under it.
|
||||
assert!(content.contains("## Notes\nA handwritten note."), "{content}");
|
||||
assert!(content.contains("- **Codename**: v1"), "{content}");
|
||||
assert!(content.contains("- **Owner**: alice"), "{content}");
|
||||
assert!(!content.contains("**Status**"), "a status was invented: {content}");
|
||||
// And no section a campaign does not have was inserted to anchor against.
|
||||
assert!(!content.contains("## Acceptance Criteria"), "{content}");
|
||||
assert!(!content.contains("## Implementation Plan"), "{content}");
|
||||
}
|
||||
|
||||
/// The heading is the one in the section table, so `campaign set --description` reaches the
|
||||
/// section `campaign_body` wrote and `campaign show` prints. A second spelling scoped to
|
||||
/// campaigns is what this would catch.
|
||||
#[test]
|
||||
fn the_description_a_campaign_is_filed_with_is_the_one_set_replaces() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"add",
|
||||
"--title",
|
||||
"Filed with prose",
|
||||
"--description",
|
||||
"As filed.",
|
||||
],
|
||||
);
|
||||
run(&temp, &["campaign", "set", "Filed with prose", "-d", "As replaced."]);
|
||||
|
||||
let out = run(&temp, &["campaign", "show", "Filed with prose"]);
|
||||
let shown = stdout(&out);
|
||||
assert!(shown.contains("As replaced."), "{shown}");
|
||||
assert!(!shown.contains("As filed."), "{shown}");
|
||||
// One Description heading in the file, not a second one written beside it.
|
||||
let names = campaigns(&worklane);
|
||||
let name = names
|
||||
.iter()
|
||||
.find(|name| name.ends_with("_filed-with-prose.md"))
|
||||
.expect("not filed");
|
||||
let content = fs::read_to_string(worklane.join("campaigns").join(name)).unwrap();
|
||||
assert_eq!(content.matches("## Description").count(), 1, "{content}");
|
||||
}
|
||||
|
||||
/// A campaign file with no Description heading is refused rather than given one back. Every
|
||||
/// campaign the tool files carries the heading, so an insertion path here would be reachable
|
||||
/// only from a hand-edited file, which is the opposite of the Relations case. The message
|
||||
/// names the section and not the object, because both a ticket and a campaign reach it.
|
||||
#[test]
|
||||
fn a_campaign_with_no_description_section_is_refused() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
let path = worklane
|
||||
.join("campaigns")
|
||||
.join(format!("{}_{}.md", CAMP_A, slug("v1 release")));
|
||||
let original = fs::read_to_string(&path).unwrap();
|
||||
fs::write(
|
||||
&path,
|
||||
original.replace("## Description\nWhat has to ship together.\n\n", ""),
|
||||
)
|
||||
.unwrap();
|
||||
let before = fs::read_to_string(&path).unwrap();
|
||||
|
||||
for args in [
|
||||
["campaign", "set", "v1 release", "-d", "Text."],
|
||||
["campaign", "append", "v1 release", "-d", "Text."],
|
||||
] {
|
||||
let out = run(&temp, &args);
|
||||
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
|
||||
let said = stderr(&out);
|
||||
assert!(said.contains("no description section"), "{said}");
|
||||
assert!(!said.contains("Ticket"), "a campaign was called a ticket: {said}");
|
||||
assert_eq!(fs::read_to_string(&path).unwrap(), before, "the file was written");
|
||||
}
|
||||
}
|
||||
|
||||
+109
-11
@@ -5,10 +5,11 @@
|
||||
//! under test are the ones that question needs: every status counted, case kept apart,
|
||||
//! alphabetical order, and an output a shell can parse.
|
||||
//!
|
||||
//! `tags add` is the other half of the same question. The listing reports the vocabulary
|
||||
//! the tickets *carry*; the file reports the one the board *intends*, and the tests below
|
||||
//! are mostly about the two being allowed to disagree without either one damaging the
|
||||
//! other.
|
||||
//! `tags add` is the other half of the same question. The file reports the vocabulary the
|
||||
//! board *intends* and the tickets carry the one it *has*, and the tests below are mostly
|
||||
//! about the two being allowed to disagree without either one damaging the other. The
|
||||
//! listing reports both and marks which is which, so the tests for the output shape are
|
||||
//! about the marking: which field it lands in, and what a board with no file still prints.
|
||||
|
||||
use assert_cmd::Command;
|
||||
use assert_fs::TempDir;
|
||||
@@ -380,19 +381,113 @@ fn a_vocabulary_that_cannot_be_read_is_refused_rather_than_replaced() {
|
||||
assert!(stray.is_empty(), "a temp file was left in .worklane");
|
||||
}
|
||||
|
||||
/// The vocabulary does not touch the listing, which counts tickets. The two disagreeing is
|
||||
/// the normal state and the thing the file is for.
|
||||
/// The listing is the union of the two vocabularies, and the two disagreeing is the normal
|
||||
/// state rather than a fault: a declaration tags no ticket, and tagging a ticket declares
|
||||
/// nothing.
|
||||
///
|
||||
/// Both halves of the disagreement in one assertion, since neither is legible without the
|
||||
/// other. `chore` is declared and carried by nothing, so it lists at zero with what it
|
||||
/// means; `bug` is carried and declared by nothing, so it lists with a count and no third
|
||||
/// field at all.
|
||||
#[test]
|
||||
fn a_declared_tag_is_not_a_carried_one() {
|
||||
fn the_listing_is_the_union_of_the_declared_and_the_carried() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane, "backlog", "11111111", "bug");
|
||||
|
||||
run(&temp, &["tags", "add", "chore", "-a", "Housekeeping."]);
|
||||
|
||||
// `chore` is declared and carried by nothing, `bug` is carried and declared by nothing,
|
||||
// and the listing still answers only the second question. Reporting both is 9564ac9.
|
||||
assert_eq!(tags(&temp), vec!["bug\t1"]);
|
||||
assert_eq!(tags(&temp), vec!["bug\t1", "chore\t0\tHousekeeping."]);
|
||||
}
|
||||
|
||||
/// The third field is the annotation's *opening* line. An annotation is prose with
|
||||
/// paragraphs in it, and a second line in this output would be read as a second tag.
|
||||
#[test]
|
||||
fn the_annotation_is_cut_to_its_opening_line() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
run(
|
||||
&temp,
|
||||
&[
|
||||
"tags",
|
||||
"add",
|
||||
"bug",
|
||||
"-a",
|
||||
"What it is.",
|
||||
"-a",
|
||||
"",
|
||||
"-a",
|
||||
"When to use it.",
|
||||
],
|
||||
);
|
||||
|
||||
assert_eq!(tags(&temp), vec!["bug\t0\tWhat it is."]);
|
||||
}
|
||||
|
||||
/// A tag declared with nothing said about it still carries a third field, and it is the
|
||||
/// placeholder the file itself holds under that heading.
|
||||
///
|
||||
/// The subtle case, and the reason the field is not simply left empty: an empty third field
|
||||
/// is a trailing tab, so the only difference between a declared tag and an undeclared one
|
||||
/// would be invisible in a terminal and in a completion alike.
|
||||
#[test]
|
||||
fn a_tag_declared_without_an_annotation_is_still_marked_as_declared() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane, "backlog", "11111111", "carried");
|
||||
|
||||
run(&temp, &["tags", "add", "declared"]);
|
||||
|
||||
assert_eq!(tags(&temp), vec!["carried\t1", "declared\t0\t_No annotation provided._"]);
|
||||
}
|
||||
|
||||
/// `cut -f1` over the listing yields exactly the tag values, undeclared ones included.
|
||||
///
|
||||
/// The constraint the whole output shape is built around: whatever marks a carried but
|
||||
/// undeclared tag must stay out of the first field, or a completion offers a tag that does
|
||||
/// not exist and `ls --tag` comes back empty for it.
|
||||
#[test]
|
||||
fn the_first_field_is_the_bare_tag_whether_it_is_declared_or_not() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane, "backlog", "11111111", "carried,both");
|
||||
run(&temp, &["tags", "add", "both", "-a", "Carried and declared."]);
|
||||
run(&temp, &["tags", "add", "declared", "-a", "Declared only."]);
|
||||
|
||||
let first: Vec<String> = tags(&temp)
|
||||
.iter()
|
||||
.map(|line| line.split('\t').next().unwrap().to_string())
|
||||
.collect();
|
||||
assert_eq!(first, vec!["both", "carried", "declared"]);
|
||||
|
||||
// And each of them is a value `--tag` can match, which is what the first field is for.
|
||||
for tag in ["both", "carried"] {
|
||||
let out = run(&temp, &["ls", "--tag", tag, "--ids"]);
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&out.stdout).lines().count(),
|
||||
1,
|
||||
"--tag {tag} matched nothing"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A board with no vocabulary lists what it listed before the file existed, byte for byte.
|
||||
///
|
||||
/// Every tag on such a board is carried and undeclared, so the absence of the third field
|
||||
/// is what keeps the old output shape: a marker in it would have changed every line of
|
||||
/// every board that predates the file, and the shipped fish completion of an older version
|
||||
/// is still reading this.
|
||||
#[test]
|
||||
fn a_board_with_no_vocabulary_lists_what_it_listed_before_the_file_existed() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
create_ticket(&worklane, "backlog", "11111111", "bug, cli");
|
||||
create_ticket(&worklane, "done", "22222222", "bug");
|
||||
assert!(!temp.path().join(".worklane").join("tags.md").exists());
|
||||
|
||||
let out = run(&temp, &["tags"]);
|
||||
assert_eq!(String::from_utf8_lossy(&out.stdout), "bug\t2\ncli\t1\n");
|
||||
}
|
||||
|
||||
/// The bare form is the listing, byte for byte, because the shipped fish completion calls it
|
||||
@@ -409,7 +504,10 @@ fn the_bare_form_and_ls_are_the_same_listing() {
|
||||
|
||||
assert!(bare.status.success());
|
||||
assert_eq!(bare.stdout, group.stdout);
|
||||
assert_eq!(String::from_utf8_lossy(&bare.stdout), "bug\t1\ncli\t1\n");
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&bare.stdout),
|
||||
"bug\t1\nchore\t0\t_No annotation provided._\ncli\t1\n"
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------------------------------- changing what a tag means --
|
||||
|
||||
Reference in New Issue
Block a user