Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ddd0addf6 | ||
|
|
cbc20848f6 | ||
|
|
eae411ab50 | ||
|
|
95426e87be | ||
|
|
72dbdec2ec |
@@ -22,7 +22,8 @@
|
||||
- Filenames: `<uuid_v4>_<slug>.md`
|
||||
- The slug is the title through `slug()`: lowercased, alphanumerics plus `-` and `_` kept, spaces turned into dashes. `Ticket 06` lands as `<uuid>_ticket-06.md`. Derive fixture filenames through `slug()`, never by hand
|
||||
- Metadata fields parsed by `parse_ticket_field()`: `ID`, `Priority`, `Tags`, `Due`, `Owner`, `Created At`, `Committed On`, `Submitted On`, `Completed On`, `Campaign`, `Status`. The last four are the ones no ticket is born with: `add` writes none of them, so they are inserted on demand, against `METADATA_ORDER`, which is also what keeps `Status` last
|
||||
- The three stamps are `mv`'s, written by `set_status_stamp` from `Status::stamp_field`, and they are mutually exclusive: entering a status writes its field, leaving removes it, re-entering restamps. So a ticket carries at most one, the one for the status it is sitting in, and a backward move under `-f` leaves no stale `Completed On` behind. They are current state, like `Status` itself; the trail of how the ticket got there is d4ce964's job and must not be grown here. `backlog` has no stamp, `Created At` already answers for it
|
||||
- The three stamps are `mv`'s, written by `set_status_stamp` from `Status::stamp_field`, and they **accumulate**: entering a status writes its field, re-entering restamps, and arriving anywhere removes the fields of every status *after* the target. One arrival rule keyed off `Status::ALL`, not a case per move, which is why a backward move truncates the journey at the target (`done` back to `reviewing` drops `Completed On`, anything back to `backlog` drops all three) and a forward skip under `-f` stamps only where it lands rather than fabricating the stages it jumped. A ticket that walks the whole flow ends with `Created At`, `Committed On`, `Submitted On` and `Completed On` side by side, so presence means *got this far and has not been sent back past it*, not *is here now* — `Status` is what says where it is. Still not d4ce964's history log: these answer how far and when, once per stage, and every change along the way is the log's. `backlog` has no stamp, `Created At` already answers for it
|
||||
- **Each status column is ordered by its own entry stamp, through `by_status_order`.** Priority is the clock in the backlog and that column keeps priority then title; past it the question changes, so committed sorts by `Committed On` ascending, reviewing by `Submitted On` ascending, and done by `Completed On` descending. Said once: the head of every column is what the reader acts on next. An unstamped ticket sinks below every stamped one in its column, because a missing time is unknown rather than ancient and unknown must not claim the head of a queue; equal stamps and both-unstamped fall through to `by_priority_then_title`. One function keyed on the `Status`, taken by both `cmd_ls` branches, `list_ids`, `columns_of` and `campaign::members`, which is why those loops walk `Status::ALL` rather than `status_dirs()`. The stamps are read in `collect_ticket_items`' existing pass, the rule `criteria` and `tags` already hold, and compared as strings: `%Y-%m-%d %H:%M:%S` is lexicographic in chronological order, the property `Due` already relies on, so nothing parses a date at sort time
|
||||
- Format: `**Field Name**: value`
|
||||
- Ticket structure: `# Title` → `## Description` → `## Acceptance Criteria` → `## Implementation Plan` → `## Metadata`
|
||||
- A **campaign** file carries `ID`, `Codename`, `Owner` and `Created At`, in that order, and no `Status`. `Codename` sits directly under the ID because that is what it is, a second way to say which campaign this is; it is written by `campaign add --codename` alone and is `_Not set_` when the flag was not given. It is not in `METADATA_ORDER`, which is the anchor list for the *upsert* on a ticket, and nothing upserts a campaign
|
||||
@@ -93,7 +94,7 @@ and this file is for what someone changing worklane's own code needs.
|
||||
- **Position is counted, not inferred.** The four `__worklane_*` predicates all read `$tokens[2]` and the token count rather than using `__fish_seen_subcommand_from`, because `campaign ls` and `campaign show` are also an `ls` and a `show` that fish has seen, and because matching against the ticket list would run worklane again inside the condition. `first_arg_of` and `second_arg_of` count a top-level command's arguments, `nested_arg_of` matches a parent and a child so `campaign show <TAB>` can be told from `chown alice <TAB>`, which sit at the same token count, and `command_is` asks only which command this is, at any position in it
|
||||
- **Every rule carrying `-l` needs a `__worklane_command_is`, and `every_rule_naming_an_option_is_scoped_to_a_command` is what enforces it.** A bare `complete -c worklane -l tag` does not just complete that option's values, it tells fish the whole tool accepts `--tag`: `worklane init --<TAB>` offered six options that only `relate` and `ls` have. Fixed in 55ee6e3. `__fish_seen_subcommand_from ls` is not the scope to use, for the nesting reason above
|
||||
- **The five completion lists are kept honest by tests** that walk the clap definition and fail on an argument left out of them. `TICKET_COMMANDS` and `TICKET_SECOND_COMMANDS` by position, `TICKET_FLAGS`, `CAMPAIGN_COMMANDS`, `CAMPAIGN_NESTED_COMMANDS`, `CAMPAIGN_FLAGS` and `TAG_FLAGS` likewise. The walk is one function, `every_argument`, since the tests differ only in the id they look for. Each also asserts *how many* it found, so a walker that stopped finding arguments fails rather than passing every assertion by never running them
|
||||
- **A campaign is named in three shapes and a tag in one**, which is why the lists are not one list: a campaign is `assign`'s first positional, `campaign show`'s only argument and `ls --campaign`'s value, and each needs a different fish rule. A tag is only ever an option value, and its values come from a different command
|
||||
- **A campaign is named in three shapes and a tag in one**, which is why the lists are not one list: a campaign is `assign`'s first positional, the first argument of `campaign show` and `campaign set`, and `ls --campaign`'s value, and each needs a different fish rule. A tag is only ever an option value, and its values come from a different command
|
||||
- **`ls --ids` is the machine-readable listing**, and one of the three outputs in the tree meant to be parsed: the short id, a tab, the title, unstyled. Two fields because fish reads what follows a tab as the description and a script reads `cut -f1`. It includes done, which the decorated listing leaves out, because a completion has to be able to name a finished ticket, and it skips a missing status directory rather than refusing, because an error printed over a shell prompt is worse than no candidates. The filters still apply, and an unknown `--campaign` is still refused
|
||||
- **`campaign ls --ids` is the same flag and the same two fields for the other object**, and it deliberately skips the member counting the decorated listing does: `members()` reads every ticket on the board, and the caller here is a shell filling in candidates on a keypress. It also prints nothing on an empty board, where the decorated listing prints a sentence, because a sentence offered as a candidate is worse than no candidates
|
||||
- **`worklane tags` is the third, and it is a command rather than a mode on `ls`.** Two reasons: `ls --tag <tag>` answers what carries a tag and cannot answer what tags exist, which is the question a grooming sweep starts from, and a `--tags` beside a `--tag` is one letter from a filter that means something else. Alphabetical and case sensitive, matching the filter, so `bug` and `Bug` list separately and land next to each other, which is where a near-duplicate is spotted. Every status, done included: a tag that has fallen out of use is still part of what the vocabulary has been. `assets/PLAN.md` used to tell the agent to count tags with a `show` per ticket, and now points here
|
||||
@@ -178,6 +179,11 @@ 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
|
||||
- **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 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
|
||||
- The campaigns directory is created by `init` and **on demand** by `campaign add`, since every board made before campaigns existed has none and a `worklane init` over a live board to get one would be a strange thing to have to do
|
||||
|
||||
@@ -297,6 +303,13 @@ and this file is for what someone changing worklane's own code needs.
|
||||
- `detail_body` closes a line only where the text says, so a part that does not end on a newline runs on into the next one. The seam between text and rows is wherever the body put it rather than wherever a part happened to end
|
||||
- **The relations block is the only coloured part of the overlay body, and that is a decision, not an oversight.** The headings, the plan numbers, the criteria marks, the bold runs and the grey unset values are all painted by `show` and all flat on the board. The block earned its colour because it is where a reader compares several references at once, and because it was already data rather than prose: it arrives as rows for the status mark, so styling it cost nothing extra. Colouring the rest means giving every painted run in `content_parts` the `Cell` treatment, which is a much larger change with no reader's question behind it, and it is its own ticket. Do not paint one more section here without taking that on: two coloured sections and five plain ones reads as a bug, where one clearly does not
|
||||
|
||||
### Finding the Board
|
||||
- **`find_worklane_dir` classifies the entry before it follows it.** `exists()` follows a link, so a `.worklane` that was a dangling symlink answered the same as no `.worklane` at all: the walk carried on up the tree and the first board above the project became the one every write landed in, silently. `classify` reads `symlink_metadata` first and answers one of four, `Absent`, `Board`, `Dangling` or `NotADirectory`, and **`Absent` is the only one the walk carries on from**. A `.worklane` that is there but unusable is this project's board and is reported, not handed upward
|
||||
- Anything other than `NotFound` from `symlink_metadata` is an error rather than an `Absent`. Reading a filesystem that could not answer as nothing-there is how the walk-past worked in the first place
|
||||
- The dangling failure **names the target and says the boards repo may not be cloned**, and deliberately does not say to run `worklane init`. Once the boards live outside the project a dangling link is an ordinary state, what you have before the boards repo is cloned and after a board directory is renamed, so "no board found, run init" points at the wrong problem
|
||||
- **A link that resolves is indistinguishable from a real directory, and what comes back is the link rather than its target.** `.worklane/backlog/*.md` has to read the same either way and nothing downstream learns whether the board is local, which is the property the shared-boards layout rests on
|
||||
- A regular file at that path is an error as well. It is a plausible future pointer form, and reading it as one is that change's decision to make; stepping over it and writing to a board above is the one answer that is wrong today
|
||||
|
||||
### Monitoring Several Boards
|
||||
- `worklane tui <path>...` takes any number of paths, each resolved through `find_worklane_dir` the way the working directory is: the first `.worklane` at or above it. No path is the working directory, so a bare `worklane` and `worklane tui` are unchanged
|
||||
- The failure **names the path** that had no board, since with several arguments "No .worklane directory found" does not say which one was wrong. Only when a path was given: a bare `worklane` has no path to name and keeps the message every other command gives, which is what its integration test asserts
|
||||
@@ -304,7 +317,7 @@ and this file is for what someone changing worklane's own code needs.
|
||||
- **`Tab` owns the selection**, `column`, `card` and `offsets`, not `Board`. Sharing them across projects would point the selection at whatever unrelated ticket sat at the same place in the tab you switched to. `Board::current()` is the tab in view, and `show_done` stays on the board because it is a preference about the flow rather than about a project
|
||||
- The tabs are fixed for the run: a project cannot be added or dropped without restarting, so `Board::new` builds the tab list once and `reload` only refills each tab's columns. `reload` clamps **every** tab, and `select_tab` clamps again on arrival, because done may have been hidden while another tab was in view
|
||||
- The merge tab goes **first** and is where the view opens: it is the reason to monitor several boards at once. It is materialised in `reload`, from the cards already read, rather than computed per draw — the same reason the criteria count is filled in `collect_ticket_items`
|
||||
- The merge is **sorted**, through `by_priority_then_title` in `util.rs`, not concatenated. An overview whose order depended on the order of the arguments would bury one project's p1 under another's p5. That comparator is exported for this and is the one `collect_ticket_items` uses, so the two orders cannot drift
|
||||
- The merge is **sorted**, through `by_priority_then_title` in `util.rs`, not concatenated. An overview whose order depended on the order of the arguments would bury one project's p1 under another's p5. It keeps priority then title where every other column takes `by_status_order`: the merge spans statuses, so no single entry stamp governs it
|
||||
- `Card` wraps a `TicketItem` with the project it came from, `Some` only on the merge tab. Decided at reload rather than passed down to `card_lines` as a "which tab is this" flag. `TicketItem` is therefore `Clone`: the merge holds a second copy rather than re-reading every tree
|
||||
- **The project follows the id, on the card and on the overlay border.** Across boards the id is not an address: two projects can hold the same title, and seven characters do not say where they live. `project_label` takes what the row has left after the mark and the id and ends in an ellipsis, and it is measured before the due date, so on the merge the project wins the narrow column and the date is what `corner_line` drops
|
||||
- `tab` and `shift+tab` cycle rather than clamp, unlike the cards and columns: a row of tabs is a ring, and there is no end of a list to run off. Both were free of every other binding — the columns took `hjkl` and the arrows
|
||||
|
||||
Generated
+1
-1
@@ -1503,7 +1503,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.20.0"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.20.0"
|
||||
version = "0.23.1"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -19,6 +19,7 @@ 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 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 |
|
||||
|
||||
+5
-1
@@ -160,6 +160,7 @@ 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 assign v1 1b78a24
|
||||
```
|
||||
|
||||
@@ -181,7 +182,10 @@ tui is usable on a narrow terminal" is a campaign. "The tui tickets" is a tag.
|
||||
board draws on every card in it and the shortest thing that addresses it at the command
|
||||
line, and a campaign filed without one is drawn by its short id, which says nothing. A
|
||||
campaign already on the board that has no codename is worth pointing out for the same
|
||||
reason a near-duplicate tag is.
|
||||
reason a near-duplicate tag is, and `campaign set` is how it gets one without refiling.
|
||||
- **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.
|
||||
|
||||
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.
|
||||
|
||||
+10
-1
@@ -211,6 +211,7 @@ 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 assign v1 1b78a24 # put a ticket in it
|
||||
worklane ls --campaign v1 # only that campaign's tickets
|
||||
```
|
||||
@@ -219,7 +220,15 @@ worklane ls --campaign v1 # only that campaign's tickets
|
||||
draws on every card in the campaign, because a uuid does not fit there and a title is a
|
||||
sentence, and it is the shortest thing that addresses the campaign at the command line.
|
||||
Optional: a campaign without one is drawn and listed by its short id instead, which
|
||||
resolves but says nothing.
|
||||
resolves but says nothing. `campaign set <campaign> --codename <word>` gives one to a
|
||||
campaign that is already filed, which is what every campaign filed before the field
|
||||
existed needs. **Replacing a codename it already has needs `--force`**: that word is how
|
||||
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.
|
||||
|
||||
`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
|
||||
|
||||
+12
-9
@@ -201,20 +201,23 @@ pub fn resolved_for(content: &str, worklane_dir: &Path, colored: bool) -> Result
|
||||
pub fn members(worklane_dir: &Path, uuid: &str) -> Result<Vec<(&'static str, Vec<TicketItem>)>> {
|
||||
let mut grouped = Vec::new();
|
||||
|
||||
for status in status_dirs() {
|
||||
let status_path = worklane_dir.join(status);
|
||||
// Over `Status::ALL` rather than the names, so each group can be put in its own
|
||||
// column's order: a campaign's committed list answers what has waited longest for
|
||||
// the same reason the board's column does.
|
||||
for status in Status::ALL {
|
||||
let status_path = worklane_dir.join(status.as_str());
|
||||
let items = match status_path.exists() {
|
||||
true => collect_ticket_items(&status_path)?,
|
||||
false => Vec::new(),
|
||||
};
|
||||
|
||||
grouped.push((
|
||||
status,
|
||||
items
|
||||
.into_iter()
|
||||
.filter(|item| item.campaign.as_deref() == Some(uuid))
|
||||
.collect(),
|
||||
));
|
||||
let mut members: Vec<TicketItem> = items
|
||||
.into_iter()
|
||||
.filter(|item| item.campaign.as_deref() == Some(uuid))
|
||||
.collect();
|
||||
members.sort_by(|a, b| by_status_order(status, a, b));
|
||||
|
||||
grouped.push((status.as_str(), members));
|
||||
}
|
||||
|
||||
Ok(grouped)
|
||||
|
||||
+68
-2
@@ -286,13 +286,24 @@ pub enum Command {
|
||||
/// What a campaign can be asked for.
|
||||
///
|
||||
/// No `mv`: a campaign has no status to move it to, its state is derived from its
|
||||
/// members. No `set` or `append` either, which is a gap rather than a decision, since
|
||||
/// nothing yet edits a campaign after it is filed.
|
||||
/// 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.
|
||||
#[derive(clap::Subcommand)]
|
||||
pub enum CampaignCommand {
|
||||
/// File a new campaign
|
||||
Add(CampaignAddArgs),
|
||||
|
||||
/// 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.
|
||||
Set(CampaignSetArgs),
|
||||
|
||||
/// List campaigns with their member counts
|
||||
Ls {
|
||||
/// Print one campaign per line as its id and title, tab separated, for a script
|
||||
@@ -313,6 +324,61 @@ 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`].
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// `--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.
|
||||
///
|
||||
/// 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`].
|
||||
#[derive(clap::Args)]
|
||||
#[command(group(
|
||||
clap::ArgGroup::new("campaign_set_fields")
|
||||
.required(true)
|
||||
.multiple(true)
|
||||
.args(["title", "codename"])
|
||||
))]
|
||||
pub struct CampaignSetArgs {
|
||||
/// Campaign UUID, title, filename or codename
|
||||
pub campaign: String,
|
||||
|
||||
/// Replace the campaign title, renaming the file to match
|
||||
#[arg(short, long, allow_hyphen_values = PROSE, value_parser = non_empty)]
|
||||
pub title: Option<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
|
||||
/// it was written. Replacing one a campaign already has needs `--force`
|
||||
#[arg(short, long, value_parser = codename)]
|
||||
pub codename: Option<String>,
|
||||
|
||||
/// Replace a codename the campaign already has
|
||||
///
|
||||
/// Without it, `--codename` on a campaign that already has one is refused and nothing
|
||||
/// is written. The codename is how a campaign is referred to once it has one, on every
|
||||
/// card in it and at the command line, so changing it is a decision rather than a
|
||||
/// correction. Setting the codename a campaign already carries is a no-op either way,
|
||||
/// not a refusal: there is nothing to overwrite
|
||||
#[arg(short, long)]
|
||||
pub force: bool,
|
||||
}
|
||||
|
||||
/// What a campaign holds: a title, a description and an owner.
|
||||
///
|
||||
/// Deliberately narrower than [`AddArgs`]. There are no acceptance criteria, because a
|
||||
|
||||
+6
-6
@@ -50,11 +50,11 @@ pub const CAMPAIGN_COMMANDS: [&str; 1] = ["assign"];
|
||||
|
||||
/// Nested subcommands whose first argument is a campaign, as `parent child`.
|
||||
///
|
||||
/// `campaign show` is the only one, and it is why the fish half needs a third position
|
||||
/// helper: its 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); 1] = [("campaign", "show")];
|
||||
/// `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")];
|
||||
|
||||
/// Options whose value is a campaign.
|
||||
pub const CAMPAIGN_FLAGS: [&str; 1] = ["campaign"];
|
||||
@@ -348,7 +348,7 @@ mod tests {
|
||||
|
||||
// A guard on the walker itself: if it stopped finding arguments, every assertion
|
||||
// above would pass by never running.
|
||||
assert_eq!(seen, 3, "expected assign, campaign show and ls --campaign");
|
||||
assert_eq!(seen, 4, "expected assign, campaign show, campaign set and ls --campaign");
|
||||
}
|
||||
|
||||
/// Tags have their own list because their values come from `worklane tags` rather than
|
||||
|
||||
+173
-35
@@ -7,7 +7,8 @@ use std::path::Path;
|
||||
|
||||
use crate::campaign::*;
|
||||
use crate::command::{
|
||||
AddArgs, AppendArgs, CampaignAddArgs, CheckArgs, ChownArgs, LsArgs, RelateArgs, SetArgs,
|
||||
AddArgs, AppendArgs, CampaignAddArgs, CampaignSetArgs, CheckArgs, ChownArgs, LsArgs,
|
||||
RelateArgs, SetArgs,
|
||||
};
|
||||
use crate::install;
|
||||
use crate::util::*;
|
||||
@@ -62,8 +63,10 @@ pub fn cmd_ls(args: &LsArgs, worklane_dir: &Path) -> Result<()> {
|
||||
}
|
||||
|
||||
if let Some(status) = args.status {
|
||||
let status = status.as_str();
|
||||
let status_path = worklane_dir.join(status);
|
||||
// The `Status` is kept alongside its name: the directory is joined from the
|
||||
// name, and the order the column prints in is keyed on the status itself.
|
||||
let name = status.as_str();
|
||||
let status_path = worklane_dir.join(name);
|
||||
if !status_path.exists() {
|
||||
// The status itself is clap's to reject now, so reaching here means the
|
||||
// board is missing a directory it should have rather than that the name was
|
||||
@@ -71,19 +74,20 @@ pub fn cmd_ls(args: &LsArgs, worklane_dir: &Path) -> Result<()> {
|
||||
// alone.
|
||||
return Err(anyhow!(
|
||||
"No '{}' directory in {}. Every board has all four; creating it is enough.",
|
||||
status,
|
||||
name,
|
||||
worklane_dir.display()
|
||||
));
|
||||
}
|
||||
|
||||
let items = filtered(collect_ticket_items(&status_path)?, priority_filter, uuid, tag);
|
||||
let mut items = filtered(collect_ticket_items(&status_path)?, priority_filter, uuid, tag);
|
||||
items.sort_by(|a, b| by_status_order(status, a, b));
|
||||
|
||||
if items.is_empty() {
|
||||
println!("No tickets in '{}' status.", status);
|
||||
println!("No tickets in '{}' status.", name);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
println!("Tickets in '{}' status:\n", status);
|
||||
println!("Tickets in '{}' status:\n", name);
|
||||
display_ticket_items(&items);
|
||||
} else {
|
||||
// List all statuses with their ticket counts
|
||||
@@ -100,23 +104,27 @@ pub fn cmd_ls(args: &LsArgs, worklane_dir: &Path) -> Result<()> {
|
||||
println!(" [{}] {} {}", status.to_uppercase(), count, label);
|
||||
}
|
||||
|
||||
// Show all tickets except done grouped by status
|
||||
for status in &statuses {
|
||||
if *status == DONE {
|
||||
// Show all tickets except done grouped by status. Over `Status::ALL` rather
|
||||
// than the names, because each column is ordered by its own entry stamp and the
|
||||
// comparator is keyed on the status, not on the directory it was read from.
|
||||
for status in Status::ALL {
|
||||
if status.as_str() == DONE {
|
||||
continue;
|
||||
}
|
||||
let status_path = worklane_dir.join(status);
|
||||
let status_path = worklane_dir.join(status.as_str());
|
||||
if !status_path.exists() || !fs::metadata(&status_path)?.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let items = match collect_ticket_items(&status_path) {
|
||||
let mut items = match collect_ticket_items(&status_path) {
|
||||
Ok(items) => filtered(items, priority_filter, uuid, tag),
|
||||
Err(_) => continue,
|
||||
};
|
||||
items.sort_by(|a, b| by_status_order(status, a, b));
|
||||
if items.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let status_header = color_text(&format!("[{}]", status.to_uppercase()), Color::Orange);
|
||||
let status_header =
|
||||
color_text(&format!("[{}]", status.as_str().to_uppercase()), Color::Orange);
|
||||
println!("\n{}", status_header);
|
||||
display_ticket_items(&items);
|
||||
}
|
||||
@@ -149,16 +157,20 @@ fn list_ids(
|
||||
worklane_dir: &Path,
|
||||
) -> Result<()> {
|
||||
let statuses = match status {
|
||||
Some(status) => vec![status.as_str()],
|
||||
None => status_dirs(),
|
||||
Some(status) => vec![status],
|
||||
None => Status::ALL.to_vec(),
|
||||
};
|
||||
|
||||
for status in statuses {
|
||||
let status_path = worklane_dir.join(status);
|
||||
let status_path = worklane_dir.join(status.as_str());
|
||||
if !status_path.exists() {
|
||||
continue;
|
||||
}
|
||||
for item in filtered(collect_ticket_items(&status_path)?, level, campaign, tag) {
|
||||
// The same order the listing prints, so a completion and the board agree on
|
||||
// which ticket is at the head of a column.
|
||||
let mut items = filtered(collect_ticket_items(&status_path)?, level, campaign, tag);
|
||||
items.sort_by(|a, b| by_status_order(status, a, b));
|
||||
for item in items {
|
||||
println!("{}\t{}", item.id, item.title);
|
||||
}
|
||||
}
|
||||
@@ -442,10 +454,19 @@ pub fn cmd_show(search: &str, worklane_dir: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// What is being written, for the messages a failure carries.
|
||||
///
|
||||
/// A `&str` naming the thing rather than two copies of the write path: a campaign file is
|
||||
/// a ticket file in every way that matters here, `<uuid>_<slug>.md` in a directory, and the
|
||||
/// only difference is the word a failure has to use. Every message below puts it
|
||||
/// mid-sentence so there is no capital to case.
|
||||
const TICKET: &str = "ticket";
|
||||
const CAMPAIGN: &str = "campaign";
|
||||
|
||||
/// Write `content` over `path`, without ever leaving half a file behind.
|
||||
///
|
||||
/// Staged in a temp file and renamed into place, because `fs::write` truncates before
|
||||
/// it writes and a partial write would corrupt the ticket. The temp sits under
|
||||
/// it writes and a partial write would corrupt the file. The temp sits under
|
||||
/// `.worklane/` rather than beside the ticket, so a leftover from a hard kill is
|
||||
/// invisible to ticket lookup and to the listing instead of showing up as a stray
|
||||
/// untitled ticket.
|
||||
@@ -454,6 +475,7 @@ fn write_then_replace(
|
||||
path: &Path,
|
||||
filename: &str,
|
||||
content: &str,
|
||||
kind: &str,
|
||||
title: &str,
|
||||
) -> Result<()> {
|
||||
let temp = worklane_dir.join(format!(".wl-{}.tmp", filename));
|
||||
@@ -461,7 +483,8 @@ fn write_then_replace(
|
||||
if let Err(e) = fs::write(&temp, content) {
|
||||
let _ = fs::remove_file(&temp);
|
||||
return Err(anyhow!(
|
||||
"Could not stage the update for ticket '{}' at {}: {}",
|
||||
"Could not stage the update for {} '{}' at {}: {}",
|
||||
kind,
|
||||
title,
|
||||
temp.display(),
|
||||
e
|
||||
@@ -470,21 +493,29 @@ fn write_then_replace(
|
||||
|
||||
if let Err(e) = fs::rename(&temp, path) {
|
||||
let _ = fs::remove_file(&temp);
|
||||
return Err(anyhow!("Could not write ticket '{}' at {}: {}", title, path.display(), e));
|
||||
return Err(anyhow!(
|
||||
"Could not write {} '{}' at {}: {}",
|
||||
kind,
|
||||
title,
|
||||
path.display(),
|
||||
e
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The ticket file in `dir` carrying `uuid`.
|
||||
/// The file in `dir` carrying `uuid`, ticket or campaign.
|
||||
///
|
||||
/// Matched on the uuid, not the title. Titles are not unique, `add` allows duplicates
|
||||
/// on purpose, so a title scan could land on a different ticket than the one that was
|
||||
/// resolved: `mv <uuid-of-second>` moved the first ticket sharing its title.
|
||||
fn find_ticket_file(dir: &Path, uuid: &str, title: &str) -> Result<String> {
|
||||
/// resolved: `mv <uuid-of-second>` moved the first ticket sharing its title. The same holds
|
||||
/// for a campaign, whose file is named the same way.
|
||||
fn find_entry_file(dir: &Path, kind: &str, uuid: &str, title: &str) -> Result<String> {
|
||||
if uuid.trim().is_empty() || is_unknown_value(uuid) {
|
||||
return Err(anyhow!(
|
||||
"Ticket '{}' has no ID field, so its file cannot be located",
|
||||
"Could not locate the file for {} '{}': it has no ID field",
|
||||
kind,
|
||||
title
|
||||
));
|
||||
}
|
||||
@@ -507,7 +538,8 @@ fn find_ticket_file(dir: &Path, uuid: &str, title: &str) -> Result<String> {
|
||||
}
|
||||
|
||||
Err(anyhow!(
|
||||
"Could not find the file for ticket '{}' in {}",
|
||||
"Could not find the file for {} '{}' in {}",
|
||||
kind,
|
||||
title,
|
||||
dir.display()
|
||||
))
|
||||
@@ -537,7 +569,7 @@ fn move_ticket_file(
|
||||
let source = from.join(filename);
|
||||
let dest = to.join(filename);
|
||||
|
||||
write_then_replace(worklane_dir, &source, filename, content, title)?;
|
||||
write_then_replace(worklane_dir, &source, filename, content, TICKET, title)?;
|
||||
|
||||
// The content is correct and in one place by now, so a failure here leaves the
|
||||
// ticket where it started rather than half moved.
|
||||
@@ -660,7 +692,7 @@ pub fn cmd_mv(ticket_id: &str, target: Status, force: bool, start: &Path) -> Res
|
||||
)?;
|
||||
|
||||
let found_filename =
|
||||
find_ticket_file(¤t_path, &parse_ticket_field(&resolved, "ID"), &title)?;
|
||||
find_entry_file(¤t_path, TICKET, &parse_ticket_field(&resolved, "ID"), &title)?;
|
||||
|
||||
move_ticket_file(
|
||||
&worklane_dir,
|
||||
@@ -756,21 +788,56 @@ fn save_ticket(
|
||||
new_title: Option<&String>,
|
||||
content: &str,
|
||||
) -> Result<()> {
|
||||
let status_path = worklane_dir.join(status);
|
||||
let filename = find_ticket_file(&status_path, uuid, title)?;
|
||||
let path = status_path.join(&filename);
|
||||
let dir = worklane_dir.join(status);
|
||||
save_entry(worklane_dir, &dir, TICKET, uuid, title, new_title, content)
|
||||
}
|
||||
|
||||
write_then_replace(worklane_dir, &path, &filename, content, title)?;
|
||||
/// The same for a campaign, whose directory is `campaigns/` and which sits in no status.
|
||||
///
|
||||
/// A named wrapper rather than a `save_entry` at the call site, so the campaign handler
|
||||
/// reads the way the ticket handlers do and neither has to know which directory the other
|
||||
/// writes to.
|
||||
fn save_campaign(
|
||||
worklane_dir: &Path,
|
||||
uuid: &str,
|
||||
title: &str,
|
||||
new_title: Option<&String>,
|
||||
content: &str,
|
||||
) -> Result<()> {
|
||||
let dir = campaigns_dir(worklane_dir);
|
||||
save_entry(worklane_dir, &dir, CAMPAIGN, uuid, title, new_title, content)
|
||||
}
|
||||
|
||||
// The uuid is kept, so the new name cannot collide with another ticket, and an
|
||||
/// Write a file back where it was, renaming it when the title changed.
|
||||
///
|
||||
/// One body for tickets and campaigns. Both are `<uuid>_<slug>.md` in a directory, both are
|
||||
/// written through `write_then_replace` so a failure leaves no half file, and both rename
|
||||
/// only after the write has landed: renaming first and writing second is what leaves a file
|
||||
/// under a name that does not match what is in it.
|
||||
fn save_entry(
|
||||
worklane_dir: &Path,
|
||||
dir: &Path,
|
||||
kind: &str,
|
||||
uuid: &str,
|
||||
title: &str,
|
||||
new_title: Option<&String>,
|
||||
content: &str,
|
||||
) -> Result<()> {
|
||||
let filename = find_entry_file(dir, kind, uuid, title)?;
|
||||
let path = dir.join(&filename);
|
||||
|
||||
write_then_replace(worklane_dir, &path, &filename, content, kind, title)?;
|
||||
|
||||
// The uuid is kept, so the new name cannot collide with another entry, and an
|
||||
// unchanged slug means there is nothing to rename.
|
||||
if let Some(new_title) = new_title {
|
||||
let renamed = format!("{}_{}.md", uuid, slug(new_title));
|
||||
if renamed != filename {
|
||||
let destination = status_path.join(&renamed);
|
||||
let destination = dir.join(&renamed);
|
||||
fs::rename(&path, &destination).map_err(|e| {
|
||||
anyhow!(
|
||||
"Ticket '{}' was updated but could not be renamed to {}: {}",
|
||||
"Could not rename {} '{}' to {} after updating it: {}",
|
||||
kind,
|
||||
title,
|
||||
destination.display(),
|
||||
e
|
||||
@@ -1065,7 +1132,7 @@ pub fn cmd_campaign_add(args: &CampaignAddArgs, start: &Path) -> Result<()> {
|
||||
&Local::now().format(TIMESTAMP_FORMAT).to_string(),
|
||||
);
|
||||
|
||||
write_then_replace(&worklane_dir, &path, &filename, &body, title)?;
|
||||
write_then_replace(&worklane_dir, &path, &filename, &body, CAMPAIGN, title)?;
|
||||
|
||||
println!("Created campaign: {}", filename);
|
||||
Ok(())
|
||||
@@ -1172,6 +1239,77 @@ pub fn cmd_tags(worklane_dir: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Replace fields on a campaign that is already filed.
|
||||
///
|
||||
/// `cmd_set` for a campaign, and built out of the same parts: `set_title` for the heading,
|
||||
/// `set_metadata_field` for the field, `apply` for whether an edit changed anything, and
|
||||
/// `report` for what it says afterwards. Nothing about writing a field lives twice, which is
|
||||
/// the shape `cmd_chown` already took.
|
||||
///
|
||||
/// The **codename is inserted when the campaign has no such line**, rather than refused.
|
||||
/// `set_metadata_field` refuses a field that is not there, which is right for the fields
|
||||
/// `add` writes; every campaign filed before the field existed has none, and those are
|
||||
/// exactly the campaigns this command is for. So it goes through
|
||||
/// `set_or_insert_metadata_field`, the upsert `assign` already uses for the Campaign field
|
||||
/// on a ticket, for the same reason.
|
||||
///
|
||||
/// **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 changing it out from under that is the same mistake
|
||||
/// overwriting an edited skill document would be. So it is refused, and the refusal names
|
||||
/// both words and the flag, the way `install-skill` names `--force` rather than leaving it
|
||||
/// to be found.
|
||||
///
|
||||
/// Checked before any edit is applied, like `SetArgs::contested`, so a call that also
|
||||
/// carries `--title` writes neither field rather than half of what was asked for.
|
||||
///
|
||||
/// 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.
|
||||
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)?;
|
||||
let title = campaign.title.clone();
|
||||
|
||||
let overwrite = match (&args.codename, &campaign.codename) {
|
||||
(Some(wanted), Some(held)) if wanted != held => Some((held, wanted)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((held, wanted)) = overwrite.filter(|_| !args.force) {
|
||||
return Err(anyhow!(
|
||||
"Campaign '{}' is already codenamed '{}', so nothing was written. \
|
||||
Pass --force to replace it with '{}'",
|
||||
title,
|
||||
held,
|
||||
wanted
|
||||
));
|
||||
}
|
||||
|
||||
let mut content = campaign.content.clone();
|
||||
let mut changed: Vec<&str> = Vec::new();
|
||||
|
||||
if let Some(new_title) = &args.title {
|
||||
let next = set_title(&content, new_title)?;
|
||||
apply(&mut content, &mut changed, "title", 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);
|
||||
}
|
||||
|
||||
if changed.is_empty() {
|
||||
report(&[], &title, "Updated");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let renamed = changed.contains(&"title").then_some(()).and(args.title.as_ref());
|
||||
save_campaign(&worklane_dir, &campaign.uuid, &title, renamed, &content)?;
|
||||
|
||||
report(&changed, args.title.as_ref().unwrap_or(&title), "Updated");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Show a campaign, then its members grouped by status.
|
||||
///
|
||||
/// Every status is shown, done included, unlike `ls`, which leaves done out of its
|
||||
|
||||
@@ -71,6 +71,7 @@ fn main() -> Result<()> {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
cmd_campaign_ls(&worklane_dir, ids)
|
||||
}
|
||||
CampaignCommand::Set(args) => cmd_campaign_set(&args, &start),
|
||||
CampaignCommand::Show { campaign } => {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
cmd_campaign_show(&campaign, &worklane_dir)
|
||||
|
||||
+97
-3
@@ -1157,12 +1157,14 @@ fn span_of(cell: Cell) -> Span<'static> {
|
||||
fn columns_of(worklane_dir: &Path) -> (Vec<Column>, CampaignIndex) {
|
||||
let campaigns = CampaignIndex::load(worklane_dir).unwrap_or_default();
|
||||
|
||||
let mut columns: Vec<Column> = status_dirs()
|
||||
// Over `Status::ALL` rather than the names: each column is ordered by its own entry
|
||||
// stamp, so the build needs the status itself and not just the directory to read.
|
||||
let mut columns: Vec<Column> = Status::ALL
|
||||
.into_iter()
|
||||
.map(|status| {
|
||||
// An absent or unreadable directory is an empty column, not a missing one:
|
||||
// the four statuses are the shape of the board.
|
||||
let cards = collect_ticket_items(worklane_dir.join(status))
|
||||
let mut cards: Vec<Card> = collect_ticket_items(worklane_dir.join(status.as_str()))
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|ticket| Card {
|
||||
@@ -1172,7 +1174,8 @@ fn columns_of(worklane_dir: &Path) -> (Vec<Column>, CampaignIndex) {
|
||||
blocked: false,
|
||||
})
|
||||
.collect();
|
||||
Column { status, cards }
|
||||
cards.sort_by(|a, b| by_status_order(status, &a.ticket, &b.ticket));
|
||||
Column { status: status.as_str(), cards }
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -4530,6 +4533,97 @@ mod tests {
|
||||
assert!(top.contains("backlog (1)"), "{top}");
|
||||
}
|
||||
|
||||
/// The titles of one column, top to bottom, which is the order the reader acts on.
|
||||
fn column_titles(board: &Board, at: usize) -> Vec<String> {
|
||||
board.current().columns[at]
|
||||
.cards
|
||||
.iter()
|
||||
.map(|card| card.ticket.title.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Each column is ordered by its own entry stamp, not by priority: committed is the
|
||||
/// longest wait first, done is what just landed first. Every ticket here is a p2, so
|
||||
/// the stamp is doing all of the work.
|
||||
#[test]
|
||||
fn a_column_is_ordered_by_the_stamp_the_ticket_entered_it_with() {
|
||||
let dir = board_dir();
|
||||
let stamp = |field: &str, at: &str| format!("- **{field}**: 2026-08-0{at} 09:00:00\n");
|
||||
|
||||
write_ticket(
|
||||
&dir,
|
||||
"committed",
|
||||
"11111111-0000-4000-8000-000000000000",
|
||||
"Waited",
|
||||
&stamp("Committed On", "1"),
|
||||
);
|
||||
write_ticket(
|
||||
&dir,
|
||||
"committed",
|
||||
"22222222-0000-4000-8000-000000000000",
|
||||
"Fresh",
|
||||
&stamp("Committed On", "3"),
|
||||
);
|
||||
write_ticket(
|
||||
&dir,
|
||||
"done",
|
||||
"33333333-0000-4000-8000-000000000000",
|
||||
"Older",
|
||||
&stamp("Completed On", "1"),
|
||||
);
|
||||
write_ticket(
|
||||
&dir,
|
||||
"done",
|
||||
"44444444-0000-4000-8000-000000000000",
|
||||
"Newer",
|
||||
&stamp("Completed On", "3"),
|
||||
);
|
||||
|
||||
let board = boards(&[("only", &dir)]);
|
||||
|
||||
assert_eq!(column_titles(&board, 1), ["Waited", "Fresh"]);
|
||||
assert_eq!(column_titles(&board, 3), ["Newer", "Older"]);
|
||||
}
|
||||
|
||||
/// The merge spans statuses, so no single stamp governs it and it keeps priority then
|
||||
/// title. Pinned on done, where the column order and the merge order disagree: the
|
||||
/// board would put the newest first and the merge puts the p1 first.
|
||||
#[test]
|
||||
fn the_merge_keeps_priority_then_title_where_a_column_would_use_the_stamp() {
|
||||
let (first, second) = (board_dir(), board_dir());
|
||||
let card = |dir: &Path, uuid: &str, title: &str, level: u8, day: u8| {
|
||||
let path = write_ticket(dir, "done", uuid, title, "");
|
||||
let body = std::fs::read_to_string(&path)
|
||||
.unwrap()
|
||||
.replace("- **Priority**: 2", &format!("- **Priority**: {level}"))
|
||||
.replace(
|
||||
"- **Status**: done\n",
|
||||
&format!("- **Completed On**: 2026-08-0{day} 09:00:00\n- **Status**: done\n"),
|
||||
);
|
||||
std::fs::write(&path, body).unwrap();
|
||||
};
|
||||
|
||||
// Both on one board, so that board's own column can be read for the other
|
||||
// order. The urgent one finished first, so stamp and priority disagree.
|
||||
card(&first, "11111111-0000-4000-8000-000000000000", "Urgent", 1, 1);
|
||||
card(&first, "22222222-0000-4000-8000-000000000000", "Later", 5, 3);
|
||||
// A second board, which is what makes the merge tab exist at all.
|
||||
card(&second, "33333333-0000-4000-8000-000000000000", "Other", 3, 2);
|
||||
|
||||
let mut board = boards(&[("alpha", &first), ("beta", &second)]);
|
||||
|
||||
assert_eq!(
|
||||
column_titles(&board, 3),
|
||||
["Urgent", "Other", "Later"],
|
||||
"the merge sorted by stamp"
|
||||
);
|
||||
|
||||
// The board the cards came from orders that column by the stamp, so the two
|
||||
// really are two orders rather than one that happens to agree.
|
||||
board.select_tab(1, SCREEN);
|
||||
assert_eq!(column_titles(&board, 3), ["Later", "Urgent"]);
|
||||
}
|
||||
|
||||
/// A tab per project, plus the merge, and the merge is where the view opens: it is
|
||||
/// the reason to monitor several boards at once.
|
||||
#[test]
|
||||
|
||||
+507
-31
@@ -254,13 +254,87 @@ pub fn color_text(text: &str, color: Color) -> String {
|
||||
paint(text, color, should_use_colors())
|
||||
}
|
||||
|
||||
/// What sits at a candidate `.worklane` path.
|
||||
///
|
||||
/// The distinction the walk turns on is between nothing there and something
|
||||
/// unusable there. `exists()` follows a link, so a dangling one answered the same
|
||||
/// as an empty parent and the walk carried on upward until it met a board above
|
||||
/// the project, which then became the board every write went to. Silently. With
|
||||
/// the boards kept outside the project a dangling link is an ordinary state
|
||||
/// rather than a corrupted tree: it is what you have before the boards repo is
|
||||
/// cloned, and after a board directory is renamed.
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum Candidate {
|
||||
/// Nothing at that path, which is the one answer the walk carries on from.
|
||||
Absent,
|
||||
/// A directory, or a link that resolves to one.
|
||||
Board,
|
||||
/// A link that resolves to nothing, carrying the target it names.
|
||||
Dangling(std::path::PathBuf),
|
||||
/// There, and not a directory: a regular file, or a link to one.
|
||||
NotADirectory,
|
||||
}
|
||||
|
||||
/// Which of the four a `.worklane` path is.
|
||||
///
|
||||
/// `symlink_metadata` first, so the answer is about the entry itself and absence
|
||||
/// cannot be confused with a target that is gone. Only then is the link followed,
|
||||
/// which is what makes a resolvable one indistinguishable from a real directory.
|
||||
fn classify(path: &Path) -> Result<Candidate> {
|
||||
let entry = match fs::symlink_metadata(path) {
|
||||
Ok(entry) => entry,
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(Candidate::Absent),
|
||||
// Anything other than absence is a filesystem that could not answer, and
|
||||
// reading that as absence is how the walk-past worked in the first place.
|
||||
Err(error) => return Err(anyhow!("Could not read {}: {error}", path.display())),
|
||||
};
|
||||
|
||||
if !entry.is_symlink() {
|
||||
return Ok(match entry.is_dir() {
|
||||
true => Candidate::Board,
|
||||
false => Candidate::NotADirectory,
|
||||
});
|
||||
}
|
||||
|
||||
// Read whether or not it resolves: the target is the only part of the failure
|
||||
// that says what to go and fix.
|
||||
let target = fs::read_link(path).unwrap_or_else(|_| path.to_path_buf());
|
||||
|
||||
Ok(match fs::metadata(path) {
|
||||
Ok(resolved) if resolved.is_dir() => Candidate::Board,
|
||||
Ok(_) => Candidate::NotADirectory,
|
||||
Err(_) => Candidate::Dangling(target),
|
||||
})
|
||||
}
|
||||
|
||||
/// The first `.worklane` at or above `start`.
|
||||
///
|
||||
/// The symlink stays unresolved in what is returned, so a board reached through a
|
||||
/// link is the same path to everything downstream as one sitting in the project.
|
||||
pub fn find_worklane_dir(start: &Path) -> Result<std::path::PathBuf> {
|
||||
let mut current = start.canonicalize()?;
|
||||
|
||||
loop {
|
||||
let worklane_dir = current.join(".worklane");
|
||||
if worklane_dir.exists() {
|
||||
return Ok(worklane_dir);
|
||||
match classify(&worklane_dir)? {
|
||||
Candidate::Board => return Ok(worklane_dir),
|
||||
// The only answer that hands the search upward. A `.worklane` that is
|
||||
// there but unusable is this project's board and is reported here,
|
||||
// rather than quietly becoming a write to whatever sits above it.
|
||||
Candidate::Absent => {}
|
||||
Candidate::Dangling(target) => {
|
||||
return Err(anyhow!(
|
||||
"{} is a symlink to {}, which does not exist. The boards repo may not be cloned on this machine.",
|
||||
worklane_dir.display(),
|
||||
target.display()
|
||||
));
|
||||
}
|
||||
Candidate::NotADirectory => {
|
||||
return Err(anyhow!(
|
||||
"{} is not a directory. A board is a directory of ticket files.",
|
||||
worklane_dir.display()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if !current.pop() {
|
||||
@@ -1261,8 +1335,16 @@ pub fn parse_tags(content: &str) -> Vec<String> {
|
||||
/// stamps follow `Created At`, since they answer the same question it does about a
|
||||
/// later moment, and they are in flow order for a reader who sees one after another
|
||||
/// across a board.
|
||||
const METADATA_ORDER: [&str; 11] = [
|
||||
///
|
||||
/// `Codename` is a *campaign's* field and sits here for the same reason Campaign does: this
|
||||
/// is the one list that decides where an inserted field lands, and a campaign filed before
|
||||
/// the field existed is precisely the file `campaign set --codename` has to insert into.
|
||||
/// Directly after ID, because that is where `campaign_body` writes it, so a campaign given
|
||||
/// a codename later ends up with the same file as one filed with it. Nothing ever upserts
|
||||
/// it on a ticket, so its place in a ticket's order costs nothing.
|
||||
const METADATA_ORDER: [&str; 12] = [
|
||||
"ID",
|
||||
CODENAME_FIELD,
|
||||
"Priority",
|
||||
"Tags",
|
||||
"Due",
|
||||
@@ -1356,28 +1438,38 @@ pub const COMMITTED_ON_FIELD: &str = "Committed On";
|
||||
pub const SUBMITTED_ON_FIELD: &str = "Submitted On";
|
||||
pub const COMPLETED_ON_FIELD: &str = "Completed On";
|
||||
|
||||
/// Stamp the field of the status being entered and drop the other two.
|
||||
/// Stamp the field of the status being entered and drop the ones after it.
|
||||
///
|
||||
/// A stamp is present exactly while the ticket sits in its status, so the three are
|
||||
/// mutually exclusive: entering writes one, leaving removes it, and re-entering
|
||||
/// restamps rather than keeping the first value. That is what keeps a ticket moved
|
||||
/// backward under `-f` from carrying a `Completed On` for work it has undone, and it is
|
||||
/// the line between these fields and d4ce964's history log. Metadata carries current
|
||||
/// state, which is why `Status` is a field at all; the trail of how the ticket got here
|
||||
/// belongs to the log, and a stamp left behind would be a second copy of that job.
|
||||
/// The stamps accumulate down the flow rather than being mutually exclusive, so a
|
||||
/// ticket that has walked the whole way carries `Created At`, `Committed On`,
|
||||
/// `Submitted On` and `Completed On` side by side and the journey behind it is legible.
|
||||
/// Presence therefore means the ticket got that far and has not been sent back past it,
|
||||
/// not that it is sitting there now; `Status` is what says where it is.
|
||||
///
|
||||
/// One arrival rule covers both directions. A backward move truncates the journey at
|
||||
/// the target, so `done` back to `reviewing` drops `Completed On` and keeps the two
|
||||
/// before it, and anything back to `backlog` drops all three. A forward skip under `-f`
|
||||
/// has nothing after it to clear, so `backlog` straight to `done` stamps `Completed On`
|
||||
/// alone and leaves the stages it jumped over unwritten rather than fabricated.
|
||||
/// Re-entering restamps rather than keeping the earlier value.
|
||||
///
|
||||
/// This is still not d4ce964's history log. These fields answer how far and when, once
|
||||
/// per stage; every status change, every owner and every tag along the way is the log's
|
||||
/// job and must not be grown here. `backlog` has no stamp, `Created At` answers for it.
|
||||
///
|
||||
/// The time comes in as a string rather than being read here, so the caller stamps the
|
||||
/// same moment it reports and a test can pin the value.
|
||||
pub fn set_status_stamp(content: &str, target: Status, now: &str, title: &str) -> Result<String> {
|
||||
let mut content = content.to_string();
|
||||
|
||||
// Every status but the target, so a skipping move under `-f` clears the stamps of
|
||||
// the stages it jumped over as well as the one it left.
|
||||
for status in Status::ALL {
|
||||
if status == target {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Every status after the target, off the flow order `Status::ALL` already holds
|
||||
// rather than a case per move, so arrival alone decides what is cleared and a
|
||||
// backward move and a skip are the same rule.
|
||||
for status in Status::ALL
|
||||
.iter()
|
||||
.skip_while(|status| **status != target)
|
||||
.skip(1)
|
||||
{
|
||||
let Some(field) = status.stamp_field() else {
|
||||
continue;
|
||||
};
|
||||
@@ -2488,8 +2580,8 @@ pub enum Status {
|
||||
}
|
||||
|
||||
impl Status {
|
||||
/// Every status, in flow order. The one list, which [`status_dirs`] and `mv` both
|
||||
/// read rather than spelling the four names again.
|
||||
/// Every status, in flow order. The one list, which [`status_dirs`], `mv` and every
|
||||
/// caller of [`by_status_order`] read rather than spelling the four names again.
|
||||
pub const ALL: [Status; 4] = [
|
||||
Status::Backlog,
|
||||
Status::Committed,
|
||||
@@ -2645,6 +2737,48 @@ pub struct TicketItem {
|
||||
/// The file this came from. The listing ignores it; the TUI opens it for the
|
||||
/// detail view rather than resolving the ticket a second time.
|
||||
pub path: std::path::PathBuf,
|
||||
/// The time `mv` stamped on entering committed, or `None` for a ticket that has
|
||||
/// never got that far.
|
||||
///
|
||||
/// Read here for the reason `criteria` is, and it is what its column is ordered by:
|
||||
/// a comparator that read the file would re-read every ticket on every comparison,
|
||||
/// where this pass reads each one once.
|
||||
pub committed_on: Option<String>,
|
||||
/// The same for reviewing.
|
||||
pub submitted_on: Option<String>,
|
||||
/// The same for done.
|
||||
pub completed_on: Option<String>,
|
||||
}
|
||||
|
||||
impl TicketItem {
|
||||
/// The stamp the ticket entered a status with, which is what that column sorts on.
|
||||
///
|
||||
/// A slot per status rather than a lookup by field name, so a fifth status carrying
|
||||
/// a stamp is a compile error here the way it is in [`Status::stamp_field`].
|
||||
/// Backlog has none: nothing stamps it, and `Created At` is not an entry time, so
|
||||
/// every ticket in that column answers `None` and the whole order is the fallback.
|
||||
fn entry_stamp(&self, status: Status) -> Option<&str> {
|
||||
match status {
|
||||
Status::Backlog => None,
|
||||
Status::Committed => self.committed_on.as_deref(),
|
||||
Status::Reviewing => self.submitted_on.as_deref(),
|
||||
Status::Done => self.completed_on.as_deref(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The stamp a ticket carries for a status, or `None` for one it has not reached.
|
||||
///
|
||||
/// The field name comes off [`Status::stamp_field`], so what is read here cannot drift
|
||||
/// from what `mv` writes. An absent field reads as `_Not set_` like every other, and a
|
||||
/// stamp is machine-written so that spelling never appears as a value; both count as no
|
||||
/// stamp rather than as a time.
|
||||
fn parse_stamp(content: &str, status: Status) -> Option<String> {
|
||||
let value = parse_ticket_field(content, status.stamp_field()?);
|
||||
match is_unknown_value(&value) {
|
||||
true => None,
|
||||
false => Some(value),
|
||||
}
|
||||
}
|
||||
|
||||
/// The date part of a due value, for a view with only a corner to spend on it.
|
||||
@@ -2806,6 +2940,9 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
|
||||
uuid: parse_ticket_field(&content, "ID"),
|
||||
blockers,
|
||||
path: e.path(),
|
||||
committed_on: parse_stamp(&content, Status::Committed),
|
||||
submitted_on: parse_stamp(&content, Status::Reviewing),
|
||||
completed_on: parse_stamp(&content, Status::Done),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
@@ -2814,11 +2951,13 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
/// The order a status column is read in: priority first, title as the tiebreak.
|
||||
/// The order the backlog is read in, and the tiebreak every other column falls back to:
|
||||
/// priority first, title second.
|
||||
///
|
||||
/// Named and exported because the board's All tab merges several boards' columns into
|
||||
/// one and has to land in the order the listing uses. A merge sorted a second way
|
||||
/// would put a p1 below a p5 depending on which project it came from.
|
||||
/// one and has to land in one order. A merge sorted a second way would put a p1 below a
|
||||
/// p5 depending on which project it came from, and the merge spans statuses, so no
|
||||
/// single stamp governs it.
|
||||
pub fn by_priority_then_title(a: &TicketItem, b: &TicketItem) -> std::cmp::Ordering {
|
||||
a.priority
|
||||
.rank()
|
||||
@@ -2826,6 +2965,39 @@ pub fn by_priority_then_title(a: &TicketItem, b: &TicketItem) -> std::cmp::Order
|
||||
.then_with(|| a.title.to_lowercase().cmp(&b.title.to_lowercase()))
|
||||
}
|
||||
|
||||
/// The order one status column is read in, keyed on the status.
|
||||
///
|
||||
/// Priority is the clock in the backlog, and that column keeps exactly the order it has
|
||||
/// always printed. Past the backlog the question changes: committed asks what has waited
|
||||
/// longest, reviewing what was handed over first, done what just landed. The head of
|
||||
/// every column is therefore what the reader acts on next, which is ascending by entry
|
||||
/// stamp in committed and reviewing and descending in done, the way a changelog reads.
|
||||
///
|
||||
/// A ticket with no stamp sinks below every stamped one in its column. A missing time is
|
||||
/// unknown, not ancient, and unknown must not claim the head of a queue ahead of a wait
|
||||
/// somebody can point at. Reading absence as the epoch would come free from the string
|
||||
/// comparison and put every legacy ticket first on data nothing verified.
|
||||
///
|
||||
/// The comparison is a string comparison. The stamp format is `%Y-%m-%d %H:%M:%S`, where
|
||||
/// lexicographic order is chronological order, the same property `Due` already relies
|
||||
/// on, so there is no date parsing at sort time. Equal stamps happen, `mv` writes whole
|
||||
/// seconds, and they fall through to priority and title like everything else.
|
||||
pub fn by_status_order(status: Status, a: &TicketItem, b: &TicketItem) -> std::cmp::Ordering {
|
||||
let by_stamp = match (a.entry_stamp(status), b.entry_stamp(status)) {
|
||||
(Some(left), Some(right)) => match status {
|
||||
Status::Done => right.cmp(left),
|
||||
_ => left.cmp(right),
|
||||
},
|
||||
(Some(_), None) => std::cmp::Ordering::Less,
|
||||
(None, Some(_)) => std::cmp::Ordering::Greater,
|
||||
// Both unstamped, which is every ticket in the backlog: the fallback is the
|
||||
// whole order there rather than a tiebreak.
|
||||
(None, None) => std::cmp::Ordering::Equal,
|
||||
};
|
||||
|
||||
by_stamp.then_with(|| by_priority_then_title(a, b))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -3395,10 +3567,10 @@ mod tests {
|
||||
assert!(error.to_string().contains("Campaign"), "{error}");
|
||||
}
|
||||
|
||||
/// The one stamp the target status carries, and nothing of the others: the fields
|
||||
/// are current state, not a record of every stage the ticket has been through.
|
||||
/// The stamp of the status being entered, added to what the ticket already carries:
|
||||
/// the fields accumulate down the flow, so the stages behind it stay readable.
|
||||
#[test]
|
||||
fn entering_a_status_stamps_its_field_and_clears_the_rest() {
|
||||
fn entering_a_status_stamps_its_field_and_keeps_the_ones_before_it() {
|
||||
let content = with_metadata(
|
||||
"- **ID**: abc\n- **Committed On**: 2026-08-01 09:00:00\n- **Status**: committed\n",
|
||||
);
|
||||
@@ -3407,25 +3579,64 @@ mod tests {
|
||||
set_status_stamp(&content, Status::Reviewing, "2026-08-22 10:11:12", "T").unwrap();
|
||||
|
||||
assert!(updated.contains("- **Submitted On**: 2026-08-22 10:11:12"), "{updated}");
|
||||
assert!(!updated.contains("**Committed On**"), "{updated}");
|
||||
assert!(updated.contains("- **Committed On**: 2026-08-01 09:00:00"), "{updated}");
|
||||
}
|
||||
|
||||
/// Backlog has no stamp of its own, so a backward move under `-f` leaves the ticket
|
||||
/// carrying none rather than a Completed On for work it has undone.
|
||||
/// Arrival truncates the journey at the target, so the stage the ticket has been
|
||||
/// sent back out of is dropped and the ones it still got through are not.
|
||||
#[test]
|
||||
fn arriving_removes_the_stamps_of_the_statuses_after_the_target() {
|
||||
let content = with_metadata(
|
||||
"- **ID**: abc\n\
|
||||
- **Committed On**: 2026-08-01 09:00:00\n\
|
||||
- **Submitted On**: 2026-08-02 09:00:00\n\
|
||||
- **Completed On**: 2026-08-03 09:00:00\n\
|
||||
- **Status**: done\n",
|
||||
);
|
||||
|
||||
let updated =
|
||||
set_status_stamp(&content, Status::Reviewing, "2026-08-22 10:11:12", "T").unwrap();
|
||||
|
||||
assert!(!updated.contains("**Completed On**"), "{updated}");
|
||||
assert!(updated.contains("- **Committed On**: 2026-08-01 09:00:00"), "{updated}");
|
||||
assert!(updated.contains("- **Submitted On**: 2026-08-22 10:11:12"), "{updated}");
|
||||
}
|
||||
|
||||
/// Backlog has no stamp of its own and every status follows it, so a ticket forced
|
||||
/// all the way back carries none of the three rather than a trail it has undone.
|
||||
#[test]
|
||||
fn moving_back_to_backlog_leaves_no_stamp_behind() {
|
||||
let content = with_metadata(
|
||||
"- **ID**: abc\n- **Completed On**: 2026-08-01 09:00:00\n- **Status**: done\n",
|
||||
"- **ID**: abc\n\
|
||||
- **Committed On**: 2026-08-01 09:00:00\n\
|
||||
- **Submitted On**: 2026-08-02 09:00:00\n\
|
||||
- **Completed On**: 2026-08-03 09:00:00\n\
|
||||
- **Status**: done\n",
|
||||
);
|
||||
|
||||
let updated =
|
||||
set_status_stamp(&content, Status::Backlog, "2026-08-22 10:11:12", "T").unwrap();
|
||||
|
||||
assert!(!updated.contains("**Completed On**"), "{updated}");
|
||||
for field in [COMMITTED_ON_FIELD, SUBMITTED_ON_FIELD, COMPLETED_ON_FIELD] {
|
||||
assert!(!updated.contains(&format!("**{}**", field)), "{updated}");
|
||||
}
|
||||
assert!(!updated.contains("2026-08-22 10:11:12"), "{updated}");
|
||||
assert!(updated.contains("- **ID**: abc\n- **Status**: done\n"), "{updated}");
|
||||
}
|
||||
|
||||
/// A skip stamps the target and nothing else. The stages it jumped over are left
|
||||
/// unwritten rather than given a time the ticket never spent there.
|
||||
#[test]
|
||||
fn a_forward_skip_stamps_only_the_status_it_lands_in() {
|
||||
let content = with_metadata("- **ID**: abc\n- **Status**: backlog\n");
|
||||
|
||||
let updated = set_status_stamp(&content, Status::Done, "2026-08-22 10:11:12", "T").unwrap();
|
||||
|
||||
assert!(updated.contains("- **Completed On**: 2026-08-22 10:11:12"), "{updated}");
|
||||
assert!(!updated.contains("**Committed On**"), "{updated}");
|
||||
assert!(!updated.contains("**Submitted On**"), "{updated}");
|
||||
}
|
||||
|
||||
/// Re-entry is the time of the move that brought it back, not the first one.
|
||||
#[test]
|
||||
fn re_entering_a_status_restamps_rather_than_keeping_the_earlier_value() {
|
||||
@@ -3464,6 +3675,170 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// A listed ticket with only the fields the column order reads: its title, its
|
||||
/// priority and the stamp for the status being sorted.
|
||||
fn listed(title: &str, level: u8, status: Status, stamp: Option<&str>) -> TicketItem {
|
||||
let stamp = stamp.map(|value| value.to_string());
|
||||
|
||||
TicketItem {
|
||||
title: title.to_string(),
|
||||
owner: NOT_SET.to_string(),
|
||||
due: NOT_SET.to_string(),
|
||||
id: "0000000".to_string(),
|
||||
created: String::new(),
|
||||
priority: Priority::Level(level),
|
||||
criteria: None,
|
||||
campaign: None,
|
||||
tags: Vec::new(),
|
||||
uuid: NOT_SET.to_string(),
|
||||
blockers: Vec::new(),
|
||||
path: std::path::PathBuf::new(),
|
||||
committed_on: match status {
|
||||
Status::Committed => stamp.clone(),
|
||||
_ => None,
|
||||
},
|
||||
submitted_on: match status {
|
||||
Status::Reviewing => stamp.clone(),
|
||||
_ => None,
|
||||
},
|
||||
completed_on: match status {
|
||||
Status::Done => stamp,
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Sorted the way the column is read, titles out, so a case reads as the order it
|
||||
/// asserts rather than as a pair of comparisons.
|
||||
fn ordered(status: Status, mut items: Vec<TicketItem>) -> Vec<String> {
|
||||
items.sort_by(|a, b| by_status_order(status, a, b));
|
||||
items.into_iter().map(|item| item.title).collect()
|
||||
}
|
||||
|
||||
/// The backlog is the one column priority still governs, and it prints exactly what
|
||||
/// it always has: the stamps a ticket carries from an earlier trip through the flow
|
||||
/// do not reach it, because backlog has no stamp of its own to sort on.
|
||||
#[test]
|
||||
fn the_backlog_keeps_priority_then_title() {
|
||||
let items = vec![
|
||||
listed("zebra", 5, Status::Backlog, None),
|
||||
listed("alpha", 1, Status::Backlog, None),
|
||||
listed("beta", 1, Status::Backlog, None),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(Status::Backlog, items), ["alpha", "beta", "zebra"]);
|
||||
}
|
||||
|
||||
/// Committed and reviewing are queues: the head is what has waited longest, which is
|
||||
/// where the reader picks next from.
|
||||
#[test]
|
||||
fn committed_and_reviewing_list_the_oldest_stamp_first() {
|
||||
for status in [Status::Committed, Status::Reviewing] {
|
||||
let items = vec![
|
||||
listed("newest", 1, status, Some("2026-08-03 09:00:00")),
|
||||
listed("oldest", 5, status, Some("2026-08-01 09:00:00")),
|
||||
listed("middle", 1, status, Some("2026-08-02 09:00:00")),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(status, items), ["oldest", "middle", "newest"], "{status:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Done reads like a changelog: what just landed is at the top, and priority no
|
||||
/// longer decides anything about finished work.
|
||||
#[test]
|
||||
fn done_lists_the_newest_stamp_first() {
|
||||
let items = vec![
|
||||
listed("first", 1, Status::Done, Some("2026-08-01 09:00:00")),
|
||||
listed("last", 5, Status::Done, Some("2026-08-03 09:00:00")),
|
||||
listed("middle", 1, Status::Done, Some("2026-08-02 09:00:00")),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(Status::Done, items), ["last", "middle", "first"]);
|
||||
}
|
||||
|
||||
/// A missing stamp is unknown, not ancient. Reading absence as the epoch would come
|
||||
/// free from the string comparison and hand the head of the queue to every legacy
|
||||
/// ticket, so it sinks instead, in both directions.
|
||||
#[test]
|
||||
fn a_ticket_with_no_stamp_sorts_below_every_stamped_one() {
|
||||
for status in [Status::Committed, Status::Reviewing, Status::Done] {
|
||||
let items = vec![
|
||||
listed("unstamped", 1, status, None),
|
||||
listed("stamped", 5, status, Some("2026-08-01 09:00:00")),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(status, items), ["stamped", "unstamped"], "{status:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// `mv` writes whole seconds, so two moves in the same second is a real tie rather
|
||||
/// than a hypothetical one, and it falls through to the order the backlog uses.
|
||||
#[test]
|
||||
fn equal_stamps_fall_back_to_priority_then_title() {
|
||||
let same = Some("2026-08-01 09:00:00");
|
||||
let items = vec![
|
||||
listed("zebra", 1, Status::Committed, same),
|
||||
listed("beta", 3, Status::Committed, same),
|
||||
listed("alpha", 3, Status::Committed, same),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(Status::Committed, items), ["zebra", "alpha", "beta"]);
|
||||
}
|
||||
|
||||
/// Two unstamped tickets in one column are ordered among themselves the way the
|
||||
/// backlog is, rather than left in whatever order the directory handed them back.
|
||||
#[test]
|
||||
fn unstamped_tickets_are_ordered_among_themselves_by_priority_then_title() {
|
||||
let items = vec![
|
||||
listed("zebra", 1, Status::Done, None),
|
||||
listed("beta", 3, Status::Done, None),
|
||||
listed("alpha", 3, Status::Done, None),
|
||||
];
|
||||
|
||||
assert_eq!(ordered(Status::Done, items), ["zebra", "alpha", "beta"]);
|
||||
}
|
||||
|
||||
/// The stamps come off the pass that builds the listing, not off a second read at
|
||||
/// 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();
|
||||
|
||||
fs::write(
|
||||
dir.join("aaaa_walked.md"),
|
||||
"# Walked\n\n## Metadata\n\n\
|
||||
- **ID**: aaaa\n\
|
||||
- **Committed On**: 2026-08-01 09:00:00\n\
|
||||
- **Submitted On**: 2026-08-02 09:00:00\n\
|
||||
- **Completed On**: 2026-08-03 09:00:00\n\
|
||||
- **Status**: done\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
dir.join("bbbb_fresh.md"),
|
||||
"# Fresh\n\n## Metadata\n\n- **ID**: bbbb\n- **Status**: backlog\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let items = collect_ticket_items(&dir).unwrap();
|
||||
|
||||
let walked = items.iter().find(|item| item.title == "Walked").unwrap();
|
||||
assert_eq!(walked.committed_on.as_deref(), Some("2026-08-01 09:00:00"));
|
||||
assert_eq!(walked.submitted_on.as_deref(), Some("2026-08-02 09:00:00"));
|
||||
assert_eq!(walked.completed_on.as_deref(), Some("2026-08-03 09:00:00"));
|
||||
|
||||
// Absent reads as no stamp rather than as the `_Not set_` every other field
|
||||
// falls back to, so the order sinks it instead of comparing that text.
|
||||
let fresh = items.iter().find(|item| item.title == "Fresh").unwrap();
|
||||
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
|
||||
/// quoting a field marker is prose, and rewriting it would corrupt the ticket text
|
||||
/// while leaving the real field in place.
|
||||
@@ -4476,4 +4851,105 @@ mod tests {
|
||||
"{rendered:?}"
|
||||
);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- finding the board --
|
||||
|
||||
/// A project directory under a temp root.
|
||||
///
|
||||
/// The root is canonicalized because `find_worklane_dir` canonicalizes its
|
||||
/// start: on a system whose temp path runs through a link, the two spellings
|
||||
/// of the same directory would not compare equal.
|
||||
fn project_in(root: &tempfile::TempDir) -> std::path::PathBuf {
|
||||
let dir = root.path().canonicalize().unwrap().join("project");
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
dir
|
||||
}
|
||||
|
||||
/// The failure names the target, since the link is not the thing to fix, and it
|
||||
/// does not say to run `init`: that answer belongs to an empty tree, and giving
|
||||
/// it here points at the wrong problem.
|
||||
#[test]
|
||||
fn a_dangling_board_link_is_reported_with_its_target() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let project = project_in(&root);
|
||||
let target = project.parent().unwrap().join("boards/2fed877-the-board");
|
||||
std::os::unix::fs::symlink(&target, project.join(".worklane")).unwrap();
|
||||
|
||||
let error = find_worklane_dir(&project).unwrap_err().to_string();
|
||||
assert!(error.contains(&target.display().to_string()), "{error}");
|
||||
assert!(error.contains("boards repo"), "{error}");
|
||||
assert!(!error.contains("worklane init"), "{error}");
|
||||
}
|
||||
|
||||
/// The bug this was written for: `exists()` follows the link, so a dangling one
|
||||
/// answered false, the walk carried on up the tree, and the board above the
|
||||
/// project became the board every write landed in.
|
||||
#[test]
|
||||
fn a_dangling_board_link_does_not_reach_the_board_above_it() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let project = project_in(&root);
|
||||
let above = project.parent().unwrap().join(".worklane");
|
||||
fs::create_dir_all(&above).unwrap();
|
||||
let link = project.join(".worklane");
|
||||
std::os::unix::fs::symlink(project.parent().unwrap().join("gone"), &link).unwrap();
|
||||
|
||||
let error = find_worklane_dir(&project).unwrap_err().to_string();
|
||||
assert!(error.contains(&link.display().to_string()), "{error}");
|
||||
|
||||
// And the walk really would have reached it, so the assertion above is
|
||||
// about where the walk stopped rather than about an empty tree.
|
||||
assert_eq!(find_worklane_dir(project.parent().unwrap()).unwrap(), above);
|
||||
}
|
||||
|
||||
/// Nothing at that path is still the one answer the walk carries on from.
|
||||
#[test]
|
||||
fn no_worklane_at_all_lets_the_walk_carry_on_upward() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let project = project_in(&root);
|
||||
let above = project.parent().unwrap().join(".worklane");
|
||||
fs::create_dir_all(&above).unwrap();
|
||||
|
||||
assert_eq!(find_worklane_dir(&project).unwrap(), above);
|
||||
}
|
||||
|
||||
/// A link that resolves is the board, and what comes back is the link rather
|
||||
/// than its target: `.worklane/backlog` has to read the same either way.
|
||||
#[test]
|
||||
fn a_link_to_a_board_resolves_the_way_a_directory_does() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let project = project_in(&root);
|
||||
let board = project.parent().unwrap().join("boards/2fed877-the-board");
|
||||
fs::create_dir_all(&board).unwrap();
|
||||
let link = project.join(".worklane");
|
||||
std::os::unix::fs::symlink(&board, &link).unwrap();
|
||||
|
||||
assert_eq!(find_worklane_dir(&project).unwrap(), link);
|
||||
}
|
||||
|
||||
/// A regular file is reported rather than stepped over, and a board above it
|
||||
/// does not make it the walk's problem to solve.
|
||||
#[test]
|
||||
fn a_regular_file_where_the_board_goes_is_an_error() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let project = project_in(&root);
|
||||
fs::write(project.join(".worklane"), "board = \"2fed877\"\n").unwrap();
|
||||
fs::create_dir_all(project.parent().unwrap().join(".worklane")).unwrap();
|
||||
|
||||
let error = find_worklane_dir(&project).unwrap_err().to_string();
|
||||
assert!(error.contains("not a directory"), "{error}");
|
||||
}
|
||||
|
||||
/// A link that resolves to a file, which the follow catches and the entry check
|
||||
/// on its own cannot: the entry is a symlink and the target is not a directory.
|
||||
#[test]
|
||||
fn a_link_to_a_file_is_not_a_board_either() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let project = project_in(&root);
|
||||
let file = project.parent().unwrap().join("pointer.toml");
|
||||
fs::write(&file, "board = \"2fed877\"\n").unwrap();
|
||||
std::os::unix::fs::symlink(&file, project.join(".worklane")).unwrap();
|
||||
|
||||
let error = find_worklane_dir(&project).unwrap_err().to_string();
|
||||
assert!(error.contains("not a directory"), "{error}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,3 +597,30 @@ fn add_names_the_ticket_and_the_path_when_the_write_fails() {
|
||||
chmod(&backlog, 0o755);
|
||||
assert_eq!(fs::read_dir(&backlog).unwrap().count(), 0);
|
||||
}
|
||||
|
||||
/// The board above the project is real and empty, and stays empty: a dangling
|
||||
/// `.worklane` link used to read as no board here, and the walk then wrote the
|
||||
/// ticket into whatever board sat above it.
|
||||
#[test]
|
||||
fn add_writes_nothing_when_the_board_link_does_not_resolve() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let above = setup_worklane(&temp);
|
||||
|
||||
let project = temp.child("project");
|
||||
project.create_dir_all().unwrap();
|
||||
let target = temp.path().join("boards/2fed877-the-board");
|
||||
std::os::unix::fs::symlink(&target, project.path().join(".worklane")).unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
let assert = cmd
|
||||
.current_dir(project.path())
|
||||
.args(["add", "--title", "Should not land"])
|
||||
.assert()
|
||||
.failure();
|
||||
|
||||
let stderr = String::from_utf8(assert.get_output().stderr.clone()).unwrap();
|
||||
assert!(stderr.contains(&target.display().to_string()), "{stderr}");
|
||||
assert!(stderr.contains("boards repo"), "{stderr}");
|
||||
|
||||
assert_eq!(fs::read_dir(above.join("backlog")).unwrap().count(), 0);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ const CAMP_B: &str = "bb22cc33-44dd-4ee5-8ff6-001122334455";
|
||||
const MEMBER: &str = "641e3d5c-1b0e-4d2f-9a7e-3c8b5f0a2d61";
|
||||
const OTHER: &str = "b1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d";
|
||||
const LONER: &str = "f1f2f3f4-5a6b-4c7d-8e9f-0a1b2c3d4e5f";
|
||||
/// A second done member, for the one test that needs two in one column to see an order.
|
||||
const LATE: &str = "a9a8a7a6-5b4c-4d3e-8f2a-1b0c9d8e7f60";
|
||||
|
||||
fn setup_worklane(temp: &TempDir) -> PathBuf {
|
||||
let worklane = temp.child(".worklane");
|
||||
@@ -144,6 +146,21 @@ fn find(worklane: &Path, uuid: &str) -> PathBuf {
|
||||
panic!("no file for ticket {uuid}");
|
||||
}
|
||||
|
||||
/// A campaign's content by uuid, found rather than named, since `campaign set --title`
|
||||
/// renames the file and a test that named it would be asserting the old name.
|
||||
fn campaign_file(worklane: &Path, uuid: &str) -> String {
|
||||
for entry in fs::read_dir(worklane.join("campaigns"))
|
||||
.unwrap()
|
||||
.filter_map(|e| e.ok())
|
||||
{
|
||||
if entry.file_name().to_string_lossy().starts_with(uuid) {
|
||||
return fs::read_to_string(entry.path()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
panic!("no file for campaign {uuid}");
|
||||
}
|
||||
|
||||
fn ticket(worklane: &Path, uuid: &str) -> String {
|
||||
fs::read_to_string(find(worklane, uuid)).unwrap()
|
||||
}
|
||||
@@ -492,6 +509,37 @@ fn campaign_show_prints_the_body_and_the_members_grouped_by_status() {
|
||||
assert!(!shown.contains("The loner"), "{shown}");
|
||||
}
|
||||
|
||||
/// The members of a status are listed in that status's own order, not in the board-wide
|
||||
/// one: a campaign's done list answers what just landed, for the same reason the board's
|
||||
/// column does. Every fixture is a p3, so the stamp is doing all of the work.
|
||||
#[test]
|
||||
fn campaign_show_lists_each_status_in_its_own_order() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
let stamp = |uuid: &str, day: &str| {
|
||||
let path = find(&worklane, uuid);
|
||||
let body = fs::read_to_string(&path).unwrap().replace(
|
||||
"- **Status**: done\n",
|
||||
&format!("- **Completed On**: 2026-08-0{day} 09:00:00\n- **Status**: done\n"),
|
||||
);
|
||||
fs::write(&path, body).unwrap();
|
||||
};
|
||||
|
||||
// A second done member, finished after the one the fixture writes.
|
||||
create_ticket(&worklane, "done", "The late member", LATE);
|
||||
stamp(OTHER, "1");
|
||||
stamp(LATE, "3");
|
||||
|
||||
run(&temp, &["assign", "v1 release", OTHER]);
|
||||
run(&temp, &["assign", "v1 release", LATE]);
|
||||
|
||||
let shown = stdout(&run(&temp, &["campaign", "show", "aa11"]));
|
||||
let at = |needle: &str| shown.find(needle).unwrap_or_else(|| panic!("{needle}: {shown}"));
|
||||
|
||||
assert!(at("The late member") < at("The other member"), "{shown}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_campaign_lists_only_that_campaigns_members() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
@@ -856,3 +904,362 @@ fn a_ticket_search_is_unaffected_by_the_codename_tier() {
|
||||
assert!(stdout(&out).contains("The member"), "{}", stdout(&out));
|
||||
let _ = worklane;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- campaign set --
|
||||
|
||||
/// The point of the command: a campaign already on the board can be given a codename,
|
||||
/// which `campaign add --codename` cannot do because `add` files a new one.
|
||||
#[test]
|
||||
fn campaign_set_gives_a_filed_campaign_a_codename() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
let out = run(&temp, &["campaign", "set", "v1 release", "--codename", "beaver"]);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(stdout(&out).contains("Updated codename"), "{}", stdout(&out));
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.contains("- **Codename**: beaver"), "{content}");
|
||||
}
|
||||
|
||||
/// `create_campaign` writes no Codename line at all, which is every campaign filed before
|
||||
/// the field existed, so the insertion path is the one this command is actually for.
|
||||
/// It lands under the ID, where `campaign add` writes it, so a campaign given a codename
|
||||
/// later is the same file as one filed with it.
|
||||
#[test]
|
||||
fn the_codename_is_inserted_under_the_id_when_the_line_is_absent() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
assert!(
|
||||
!campaign_file(&worklane, CAMP_A).contains("Codename"),
|
||||
"the fixture changed"
|
||||
);
|
||||
|
||||
run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
let id = content.find("- **ID**:").expect("no id");
|
||||
let codename = content.find("- **Codename**:").expect("no codename");
|
||||
let owner = content.find("- **Owner**:").expect("no owner");
|
||||
assert!(id < codename && codename < owner, "{content}");
|
||||
}
|
||||
|
||||
/// One parser, so a codename is one thing however it was written. The board draws it as a
|
||||
/// label with a mark and no quoting, and that does not depend on which command wrote it.
|
||||
#[test]
|
||||
fn campaign_set_validates_the_codename_the_way_add_does() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
for value in ["two words", ""] {
|
||||
let out = run(&temp, &["campaign", "set", "v1 release", "--codename", value]);
|
||||
assert_eq!(out.status.code(), Some(2), "{value:?}: {}", stderr(&out));
|
||||
assert!(
|
||||
!campaign_file(&worklane, CAMP_A).contains("Codename"),
|
||||
"{value:?} was written"
|
||||
);
|
||||
}
|
||||
|
||||
// And the message is the one `campaign add` gives, since the parser is the same.
|
||||
let out = run(&temp, &["campaign", "set", "v1 release", "--codename", "two words"]);
|
||||
assert!(stderr(&out).contains("single word"), "{}", stderr(&out));
|
||||
}
|
||||
|
||||
/// A bare `campaign set <campaign>` is a usage error rather than a silent no-op, exactly
|
||||
/// as it is for `set`.
|
||||
#[test]
|
||||
fn campaign_set_with_no_field_is_a_usage_error() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
let out = run(&temp, &["campaign", "set", "v1 release"]);
|
||||
assert_eq!(out.status.code(), Some(2), "{}", stderr(&out));
|
||||
assert!(
|
||||
!campaign_file(&worklane, CAMP_A).contains("Codename"),
|
||||
"something was written"
|
||||
);
|
||||
}
|
||||
|
||||
/// Replacing the title renames the file, keeping the uuid, the way `set --title` does. That
|
||||
/// is the reason this is a `set` rather than a flag on something narrower.
|
||||
#[test]
|
||||
fn campaign_set_renames_the_file_with_the_title() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
// A member first, so the rename has something to break.
|
||||
run(&temp, &["assign", "v1 release", MEMBER]);
|
||||
|
||||
let out = run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"set",
|
||||
"v1 release",
|
||||
"--title",
|
||||
"First public release",
|
||||
],
|
||||
);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
|
||||
let names = campaigns(&worklane);
|
||||
assert!(
|
||||
names.contains(&format!("{CAMP_A}_first-public-release.md")),
|
||||
"not renamed: {names:?}"
|
||||
);
|
||||
assert!(
|
||||
!names.contains(&format!("{CAMP_A}_v1-release.md")),
|
||||
"the old file is still there: {names:?}"
|
||||
);
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.starts_with("# First public release\n"), "{content}");
|
||||
// The uuid is kept, so membership survives the rename: it is stored on the member as
|
||||
// the uuid, and nothing has to be rewritten when the campaign is renamed.
|
||||
assert!(content.contains(&format!("- **ID**: {CAMP_A}")), "{content}");
|
||||
let out = run(&temp, &["ls", "--campaign", "First public release"]);
|
||||
assert!(
|
||||
stdout(&out).contains("The member"),
|
||||
"membership was lost: {}",
|
||||
stdout(&out)
|
||||
);
|
||||
}
|
||||
|
||||
/// Both fields in one call, since the group is `multiple`.
|
||||
#[test]
|
||||
fn campaign_set_takes_the_title_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",
|
||||
"-c",
|
||||
"v1",
|
||||
],
|
||||
);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(stdout(&out).contains("title, codename"), "{}", stdout(&out));
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.starts_with("# First public release\n"), "{content}");
|
||||
assert!(content.contains("- **Codename**: v1"), "{content}");
|
||||
}
|
||||
|
||||
/// The whole-file comparison `set` and `chown` use, so writing what is already there
|
||||
/// writes nothing and says so.
|
||||
#[test]
|
||||
fn setting_the_codename_a_campaign_already_has_writes_nothing() {
|
||||
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", "-c", "v1"]);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
/// A codename set here resolves the campaign afterwards, which is the whole point of the
|
||||
/// field being typable: the tier is in the shared resolver, not in `campaign add`.
|
||||
#[test]
|
||||
fn a_codename_set_afterwards_resolves_the_campaign() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
run(&temp, &["campaign", "set", "v1 release", "-c", "beaver"]);
|
||||
|
||||
let out = run(&temp, &["assign", "beaver", MEMBER]);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(
|
||||
ticket(&worklane, MEMBER).contains(&format!("- **Campaign**: {CAMP_A}")),
|
||||
"{}",
|
||||
ticket(&worklane, MEMBER)
|
||||
);
|
||||
}
|
||||
|
||||
/// Nothing else in the file moves. A campaign carries prose and an owner this command
|
||||
/// cannot reach, and a hand-written section has to survive an edit to a field.
|
||||
#[test]
|
||||
fn content_the_command_cannot_reach_survives_a_set() {
|
||||
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("## Metadata", "## Notes\nA handwritten note.\n\n## Metadata"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
|
||||
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.contains("A handwritten note."), "{content}");
|
||||
assert!(content.contains("What has to ship together."), "{content}");
|
||||
assert!(content.contains("- **Owner**: alice"), "{content}");
|
||||
assert!(!content.contains("**Status**"), "a status was invented: {content}");
|
||||
}
|
||||
|
||||
/// A campaign that does not resolve leaves everything alone, the answer `assign` already
|
||||
/// gives an unknown campaign.
|
||||
#[test]
|
||||
fn an_unknown_campaign_is_refused_and_nothing_is_written() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
|
||||
let out = run(&temp, &["campaign", "set", "nothing-by-that-name", "-c", "v1"]);
|
||||
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
|
||||
assert!(stderr(&out).contains("No campaign found"), "{}", stderr(&out));
|
||||
assert!(
|
||||
!campaign_file(&worklane, CAMP_A).contains("Codename"),
|
||||
"something was written"
|
||||
);
|
||||
assert!(
|
||||
!campaign_file(&worklane, CAMP_B).contains("Codename"),
|
||||
"something was 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.
|
||||
#[test]
|
||||
fn campaign_set_offers_no_description_and_no_owner() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
let out = run(&temp, &["campaign", "set", "--help"]);
|
||||
let help = stdout(&out);
|
||||
|
||||
assert!(help.contains("--codename"), "{help}");
|
||||
assert!(help.contains("--title"), "{help}");
|
||||
assert!(!help.contains("--description"), "{help}");
|
||||
assert!(!help.contains("--owner"), "{help}");
|
||||
assert!(!help.contains("--clear"), "{help}");
|
||||
}
|
||||
|
||||
/// A codename is how a campaign is referred to once it has one: on every card in it and at
|
||||
/// the command line. Replacing that silently is the mistake `install-skill --force` exists
|
||||
/// to prevent, so it is refused and the refusal names the flag.
|
||||
#[test]
|
||||
fn an_existing_codename_is_not_replaced_without_force() {
|
||||
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", "-c", "beaver"]);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
|
||||
let said = stderr(&out);
|
||||
// Both words and the flag, so the message says what is there, what was asked for and
|
||||
// how to get it.
|
||||
assert!(said.contains("already codenamed 'v1'"), "{said}");
|
||||
assert!(said.contains("'beaver'"), "{said}");
|
||||
assert!(said.contains("--force"), "{said}");
|
||||
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the file was written anyway");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_replaces_an_existing_codename() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
|
||||
|
||||
let out = run(&temp, &["campaign", "set", "v1", "-c", "beaver", "--force"]);
|
||||
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
let content = campaign_file(&worklane, CAMP_A);
|
||||
assert!(content.contains("- **Codename**: beaver"), "{content}");
|
||||
// The line is replaced, not added beside the old one. Asserted on the field rather
|
||||
// than on the word, since the campaign's title is "v1 release" and holds it too.
|
||||
assert!(!content.contains("- **Codename**: v1"), "the old line survived: {content}");
|
||||
assert_eq!(content.matches("**Codename**").count(), 1, "two codenames: {content}");
|
||||
}
|
||||
|
||||
/// The guard is about overwriting a *different* word. A campaign with no codename has
|
||||
/// nothing to overwrite, so `--force` is not the price of the first one.
|
||||
#[test]
|
||||
fn the_first_codename_needs_no_force() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
assert!(
|
||||
!campaign_file(&worklane, CAMP_A).contains("Codename"),
|
||||
"the fixture changed"
|
||||
);
|
||||
|
||||
let out = run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
|
||||
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(campaign_file(&worklane, CAMP_A).contains("- **Codename**: v1"));
|
||||
}
|
||||
|
||||
/// And setting the one it already has stays a no-op rather than becoming a refusal: there
|
||||
/// is nothing to overwrite, which is the same answer `install-skill` gives an identical
|
||||
/// document.
|
||||
#[test]
|
||||
fn setting_the_same_codename_again_is_a_no_op_not_a_refusal() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
|
||||
|
||||
let out = run(&temp, &["campaign", "set", "v1", "-c", "v1"]);
|
||||
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(stdout(&out).contains("No changes"), "{}", stdout(&out));
|
||||
assert!(campaign_file(&worklane, CAMP_A).contains("- **Codename**: v1"));
|
||||
}
|
||||
|
||||
/// Refused before any edit is applied, like `SetArgs::contested`, so a call carrying both
|
||||
/// fields writes neither rather than half of what was asked for.
|
||||
#[test]
|
||||
fn a_refused_codename_takes_the_title_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",
|
||||
"-t",
|
||||
"Renamed anyway",
|
||||
"-c",
|
||||
"beaver",
|
||||
],
|
||||
);
|
||||
|
||||
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
|
||||
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the title went through");
|
||||
let names = campaigns(&worklane);
|
||||
assert!(
|
||||
!names.iter().any(|name| name.contains("renamed-anyway")),
|
||||
"renamed: {names:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The title needs no guard, since a campaign always has one and replacing it is what the
|
||||
/// flag is for. `--force` is the codename's alone.
|
||||
#[test]
|
||||
fn the_title_is_replaced_without_force() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = board(&temp);
|
||||
run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
|
||||
|
||||
let out = run(&temp, &["campaign", "set", "v1", "--title", "First public release"]);
|
||||
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
assert!(campaign_file(&worklane, CAMP_A).starts_with("# First public release\n"));
|
||||
}
|
||||
|
||||
+199
-3
@@ -677,9 +677,9 @@ fn ls_names_the_four_statuses_when_given_another() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The listing reads the fields it prints and nothing else, so the stamps `mv` writes
|
||||
/// do not reach it. Pinned against a ticket carrying one, since a listing that started
|
||||
/// showing them would change the output every board and completion script parses.
|
||||
/// The listing reads the stamps to order the column by them, and prints none of them.
|
||||
/// Pinned against a ticket carrying one, since a listing that started showing them would
|
||||
/// change the output every board and completion script parses.
|
||||
#[test]
|
||||
fn ls_output_is_unchanged_by_a_status_stamp() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
@@ -707,3 +707,199 @@ fn ls_output_is_unchanged_by_a_status_stamp() {
|
||||
assert_eq!(after, before);
|
||||
assert!(!after.contains("Committed On"), "{after}");
|
||||
}
|
||||
|
||||
/// A ticket in a status with the entry stamp that status is ordered by, or none.
|
||||
///
|
||||
/// The field is derived from the status rather than passed, so a case says which column
|
||||
/// it is about and cannot name the wrong stamp for it.
|
||||
fn create_stamped_ticket(
|
||||
worklane_dir: &std::path::Path,
|
||||
status: &str,
|
||||
title: &str,
|
||||
uuid: &str,
|
||||
priority: &str,
|
||||
stamp: Option<&str>,
|
||||
) {
|
||||
let field = match status {
|
||||
"committed" => "Committed On",
|
||||
"reviewing" => "Submitted On",
|
||||
"done" => "Completed On",
|
||||
other => panic!("{other} has no entry stamp"),
|
||||
};
|
||||
let line = match stamp {
|
||||
Some(value) => format!("- **{field}**: {value}\n"),
|
||||
None => String::new(),
|
||||
};
|
||||
let body = format!(
|
||||
"# {title}\n\n## Metadata\n\n- **ID**: {uuid}\n- **Priority**: {priority}\n\
|
||||
- **Tags**: test\n- **Due**: _Not set_\n- **Owner**: alice\n{line}\
|
||||
- **Status**: {status}\n"
|
||||
);
|
||||
fs::write(
|
||||
worklane_dir
|
||||
.join(status)
|
||||
.join(format!("{uuid}_{}.md", slug(title))),
|
||||
body,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn positions(stdout: &str, titles: [&str; 3]) -> Vec<usize> {
|
||||
titles
|
||||
.iter()
|
||||
.map(|title| {
|
||||
stdout
|
||||
.find(title)
|
||||
.unwrap_or_else(|| panic!("{title} missing from {stdout}"))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Committed and reviewing are queues, and the head is what has waited longest: that is
|
||||
/// what the reader picks next from. Priority no longer decides it, which is why the
|
||||
/// oldest here is the least urgent of the three.
|
||||
#[test]
|
||||
fn ls_orders_committed_and_reviewing_by_the_oldest_entry_stamp() {
|
||||
for status in ["committed", "reviewing"] {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
let at = |n: u8| format!("aaaa000{n}-0000-0000-0000-000000000001");
|
||||
create_stamped_ticket(
|
||||
&worklane,
|
||||
status,
|
||||
"Newest",
|
||||
&at(1),
|
||||
"1",
|
||||
Some("2026-08-03 09:00:00"),
|
||||
);
|
||||
create_stamped_ticket(
|
||||
&worklane,
|
||||
status,
|
||||
"Oldest",
|
||||
&at(2),
|
||||
"5",
|
||||
Some("2026-08-01 09:00:00"),
|
||||
);
|
||||
create_stamped_ticket(
|
||||
&worklane,
|
||||
status,
|
||||
"Middle",
|
||||
&at(3),
|
||||
"1",
|
||||
Some("2026-08-02 09:00:00"),
|
||||
);
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(temp.path()).args(["ls", status]);
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
|
||||
let seen = positions(&stdout, ["Oldest", "Middle", "Newest"]);
|
||||
assert!(seen[0] < seen[1] && seen[1] < seen[2], "{status}: {stdout}");
|
||||
|
||||
// The overview lists the same columns, so it has to agree with the narrowed
|
||||
// listing rather than falling back to priority for the same tickets.
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(temp.path()).arg("ls");
|
||||
let overview = get_stdout(&mut cmd);
|
||||
|
||||
let seen = positions(&overview, ["Oldest", "Middle", "Newest"]);
|
||||
assert!(seen[0] < seen[1] && seen[1] < seen[2], "{status} overview: {overview}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Done reads like a changelog: what just landed is at the top. The p1 that finished
|
||||
/// first is at the bottom, which is the whole point of the column not being priority.
|
||||
#[test]
|
||||
fn ls_orders_done_by_the_newest_entry_stamp() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
let at = |n: u8| format!("bbbb000{n}-0000-0000-0000-000000000001");
|
||||
create_stamped_ticket(&worklane, "done", "First", &at(1), "1", Some("2026-08-01 09:00:00"));
|
||||
create_stamped_ticket(&worklane, "done", "Last", &at(2), "5", Some("2026-08-03 09:00:00"));
|
||||
create_stamped_ticket(&worklane, "done", "Middle", &at(3), "1", Some("2026-08-02 09:00:00"));
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(temp.path()).args(["ls", "done"]);
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
|
||||
let seen = positions(&stdout, ["Last", "Middle", "First"]);
|
||||
assert!(seen[0] < seen[1] && seen[1] < seen[2], "{stdout}");
|
||||
}
|
||||
|
||||
/// A missing stamp is unknown, not ancient, so it sinks below every stamped ticket
|
||||
/// rather than claiming the head of the queue. Every ticket on a board older than the
|
||||
/// stamps is one of these.
|
||||
#[test]
|
||||
fn ls_sinks_an_unstamped_ticket_below_the_stamped_ones() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
let at = |n: u8| format!("cccc000{n}-0000-0000-0000-000000000001");
|
||||
create_stamped_ticket(&worklane, "committed", "Unstamped", &at(1), "1", None);
|
||||
create_stamped_ticket(
|
||||
&worklane,
|
||||
"committed",
|
||||
"Waited",
|
||||
&at(2),
|
||||
"5",
|
||||
Some("2026-08-01 09:00:00"),
|
||||
);
|
||||
create_stamped_ticket(
|
||||
&worklane,
|
||||
"committed",
|
||||
"Fresh",
|
||||
&at(3),
|
||||
"5",
|
||||
Some("2026-08-09 09:00:00"),
|
||||
);
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(temp.path()).args(["ls", "committed"]);
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
|
||||
let seen = positions(&stdout, ["Waited", "Fresh", "Unstamped"]);
|
||||
assert!(seen[0] < seen[1] && seen[1] < seen[2], "{stdout}");
|
||||
}
|
||||
|
||||
/// The two listings are one order. A completion offering candidates in a different
|
||||
/// order than the board prints them would make the head of a column mean two things.
|
||||
#[test]
|
||||
fn ls_ids_prints_the_same_order_the_listing_does() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
let at = |n: u8| format!("dddd000{n}-0000-0000-0000-000000000001");
|
||||
create_stamped_ticket(
|
||||
&worklane,
|
||||
"reviewing",
|
||||
"Newest",
|
||||
&at(1),
|
||||
"1",
|
||||
Some("2026-08-03 09:00:00"),
|
||||
);
|
||||
create_stamped_ticket(
|
||||
&worklane,
|
||||
"reviewing",
|
||||
"Oldest",
|
||||
&at(2),
|
||||
"5",
|
||||
Some("2026-08-01 09:00:00"),
|
||||
);
|
||||
create_stamped_ticket(&worklane, "reviewing", "Unstamped", &at(3), "1", None);
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(temp.path()).args(["ls", "reviewing", "--ids"]);
|
||||
let ids = get_stdout(&mut cmd);
|
||||
|
||||
let titles: Vec<&str> = ids.lines().filter_map(|line| line.split('\t').nth(1)).collect();
|
||||
assert_eq!(titles, ["Oldest", "Newest", "Unstamped"], "{ids:?}");
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(temp.path()).args(["ls", "reviewing"]);
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
|
||||
let seen = positions(&stdout, ["Oldest", "Newest", "Unstamped"]);
|
||||
assert!(seen[0] < seen[1] && seen[1] < seen[2], "{stdout}");
|
||||
}
|
||||
|
||||
+103
-13
@@ -923,35 +923,89 @@ fn ticket_at(worklane: &Path, status: &str, filename: &str) -> String {
|
||||
fs::read_to_string(worklane.join(status).join(filename)).unwrap()
|
||||
}
|
||||
|
||||
/// One field per status, written with the time of the move, and only the current one:
|
||||
/// the stamps are where the ticket is now, not the trail of how it got there.
|
||||
/// One field per status, written with the time of the move and added to the ones
|
||||
/// already there: walking the flow leaves the whole journey on the ticket.
|
||||
#[test]
|
||||
fn mv_stamps_the_field_of_the_status_it_enters() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let filename = stamped_ticket(&worklane, "backlog");
|
||||
|
||||
for (status, stamp, cleared) in [
|
||||
("committed", "Committed On", "Submitted On"),
|
||||
("reviewing", "Submitted On", "Committed On"),
|
||||
("done", "Completed On", "Submitted On"),
|
||||
// The fixture predates Created At as well as the stamps, and the four reading as
|
||||
// one block is the point, so it is seeded rather than asserted around.
|
||||
let path = worklane.join("backlog").join(&filename);
|
||||
let seeded = fs::read_to_string(&path)
|
||||
.unwrap()
|
||||
.replace("- **Status**:", "- **Created At**: 2026-08-01 09:00:00\n- **Status**:");
|
||||
fs::write(&path, seeded).unwrap();
|
||||
|
||||
let mut carried: Vec<&str> = Vec::new();
|
||||
|
||||
for (status, stamp) in [
|
||||
("committed", "Committed On"),
|
||||
("reviewing", "Submitted On"),
|
||||
("done", "Completed On"),
|
||||
] {
|
||||
let out = move_ticket(&temp, "cccc3333", status, false);
|
||||
assert!(out.status.success(), "{:?}", out);
|
||||
carried.push(stamp);
|
||||
|
||||
let content = ticket_at(&worklane, status, &filename);
|
||||
let value = field(&content, stamp)
|
||||
.unwrap_or_else(|| panic!("no {stamp} after moving to {status}: {content}"));
|
||||
|
||||
assert!(is_timestamp(&value), "{stamp} reads '{value}'");
|
||||
assert_eq!(field(&content, cleared), None, "{content}");
|
||||
for stamp in &carried {
|
||||
let value = field(&content, stamp)
|
||||
.unwrap_or_else(|| panic!("no {stamp} after moving to {status}: {content}"));
|
||||
assert!(is_timestamp(&value), "{stamp} reads '{value}'");
|
||||
}
|
||||
}
|
||||
|
||||
// The four side by side and in flow order, which is what a reader asking when this
|
||||
// was filed, picked up, handed over and finished gets one answer each from.
|
||||
let content = ticket_at(&worklane, "done", &filename);
|
||||
let block: Vec<&str> = content
|
||||
.lines()
|
||||
.filter_map(|line| line.strip_prefix("- **"))
|
||||
.filter_map(|line| line.split("**:").next())
|
||||
.skip_while(|name| *name != "Created At")
|
||||
.collect();
|
||||
|
||||
assert_eq!(
|
||||
block,
|
||||
[
|
||||
"Created At",
|
||||
"Committed On",
|
||||
"Submitted On",
|
||||
"Completed On",
|
||||
"Status"
|
||||
],
|
||||
"{content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Backlog has no stamp of its own, so a ticket forced back to it carries none at all
|
||||
/// rather than a Completed On for work that has been undone.
|
||||
/// Arrival clears what comes after it and nothing before, so a ticket sent back out of
|
||||
/// done keeps the stages it did get through.
|
||||
#[test]
|
||||
fn mv_removes_the_stamp_of_the_status_it_leaves() {
|
||||
fn mv_removes_the_stamps_of_the_statuses_after_the_one_it_enters() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let filename = stamped_ticket(&worklane, "backlog");
|
||||
|
||||
for status in ["committed", "reviewing", "done"] {
|
||||
move_ticket(&temp, "cccc3333", status, false);
|
||||
}
|
||||
|
||||
move_ticket(&temp, "cccc3333", "reviewing", true);
|
||||
|
||||
let content = ticket_at(&worklane, "reviewing", &filename);
|
||||
assert_eq!(field(&content, "Completed On"), None, "{content}");
|
||||
assert!(field(&content, "Committed On").is_some(), "{content}");
|
||||
assert!(field(&content, "Submitted On").is_some(), "{content}");
|
||||
}
|
||||
|
||||
/// Backlog has no stamp of its own and every status follows it, so a ticket forced back
|
||||
/// to it carries none at all rather than a Completed On for work that has been undone.
|
||||
#[test]
|
||||
fn mv_back_to_backlog_removes_all_three_stamps() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let filename = stamped_ticket(&worklane, "backlog");
|
||||
@@ -968,6 +1022,42 @@ fn mv_removes_the_stamp_of_the_status_it_leaves() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A skip stamps where it lands and leaves the stages it jumped unwritten: an absent
|
||||
/// field says the ticket never got that far, and inventing one would say it did.
|
||||
#[test]
|
||||
fn mv_skipping_forward_stamps_only_the_target() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let filename = stamped_ticket(&worklane, "backlog");
|
||||
|
||||
move_ticket(&temp, "cccc3333", "done", true);
|
||||
|
||||
let content = ticket_at(&worklane, "done", &filename);
|
||||
assert!(field(&content, "Completed On").is_some(), "{content}");
|
||||
assert_eq!(field(&content, "Committed On"), None, "{content}");
|
||||
assert_eq!(field(&content, "Submitted On"), None, "{content}");
|
||||
}
|
||||
|
||||
/// The three are `mv`'s alone. Nothing that edits a ticket by hand offers a way to
|
||||
/// write one or take one away, so a stamp is always the record of a real move. Pinned
|
||||
/// so the omission stays a decision rather than becoming an oversight somebody fills in.
|
||||
#[test]
|
||||
fn no_other_command_can_write_or_clear_a_stamp() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
for command in ["add", "set", "append", "chown"] {
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(temp.path()).args([command, "--help"]);
|
||||
let out = cmd.assert().get_output().clone();
|
||||
let help = String::from_utf8_lossy(&out.stdout).to_lowercase();
|
||||
|
||||
for flag in ["committed-on", "submitted-on", "completed-on", "stamp"] {
|
||||
assert!(!help.contains(flag), "{command} --help names {flag}: {help}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Re-entry is the time of the move that brought the ticket back, not the first one.
|
||||
#[test]
|
||||
fn mv_restamps_a_status_the_ticket_is_re_entering() {
|
||||
|
||||
Reference in New Issue
Block a user