Every argument naming a campaign or a tag fell through to nothing: `campaign show <TAB>`, `assign <TAB>`, `ls --campaign <TAB>` and `ls --tag <TAB>`. Neither value had a listing a completion could parse. `campaign ls --ids` is the same flag and the same two fields as `ls --ids`, since it answers the same question about a different object. It skips the member counting the decorated listing does, because `members()` reads every ticket on the board and the caller is a shell on a keypress, and it prints nothing on an empty board where the decorated listing prints a sentence. Tags get a command rather than a mode on `ls`. `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. `worklane tags` prints the tag, a tab and the count, alphabetical and case sensitive like the filter, so `bug` and `Bug` list separately and land next to each other. assets/PLAN.md used to tell the agent to count the vocabulary with a `show` per ticket; it now points here. The fish half gains `__worklane_nested_arg_of`, which matches a parent and a child, because `campaign show <TAB>` and `chown alice <TAB>` sit at the same token count and the two counting helpers cannot tell them apart. It also gains `__worklane_command_is`, which fixes a leak the campaign and tag rules would have joined. A bare `complete -c worklane -l tag` does not only complete that option's values, it tells fish the whole tool accepts `--tag`: `worklane init --<TAB>` offered `--blocked-by`, `--regression-of`, `--relates-to` and three others. `relate`'s three were already leaking that way, so all of them are scoped now rather than leaving a correctly scoped twin beside a wrong one. `__fish_seen_subcommand_from ls` is not the scope to use, since `campaign ls` is an `ls` fish has seen. The honesty tests grow to five lists and one walker, `every_argument`, since they differ only in the id they look for. Each asserts how many arguments it found, so a walker that stopped finding them fails rather than passing every assertion by never running it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
645 lines
22 KiB
Rust
645 lines
22 KiB
Rust
use assert_cmd::Command;
|
|
use assert_fs::TempDir;
|
|
use assert_fs::fixture::{PathChild, PathCreateDir};
|
|
use std::fs;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane");
|
|
|
|
/// Two campaigns, so a filter has something to exclude, and three tickets: one in each
|
|
/// campaign and one in neither.
|
|
const CAMP_A: &str = "aa11bb22-33cc-4dd4-8ee5-ff6677889900";
|
|
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";
|
|
|
|
fn setup_worklane(temp: &TempDir) -> PathBuf {
|
|
let worklane = temp.child(".worklane");
|
|
worklane.create_dir_all().unwrap();
|
|
|
|
for dir in ["backlog", "committed", "reviewing", "done", "campaigns"] {
|
|
worklane.child(dir).create_dir_all().unwrap();
|
|
}
|
|
|
|
worklane.path().to_path_buf()
|
|
}
|
|
|
|
fn slug(title: &str) -> String {
|
|
title
|
|
.to_lowercase()
|
|
.chars()
|
|
.filter(|c| c.is_alphanumeric() || *c == ' ' || *c == '-' || *c == '_')
|
|
.map(|c| if c == ' ' { '-' } else { c })
|
|
.collect()
|
|
}
|
|
|
|
/// A ticket with a ticked criterion, a section the tool knows nothing about and a
|
|
/// metadata field it has never heard of, so every test can check that an assignment
|
|
/// leaves all three exactly as they were.
|
|
///
|
|
/// Deliberately carries no Campaign field: no ticket written before campaigns existed
|
|
/// has one, and `add` still does not write one, so the insertion path is what every
|
|
/// assignment goes through.
|
|
fn create_ticket(worklane: &Path, status: &str, title: &str, uuid: &str) -> PathBuf {
|
|
let path = worklane
|
|
.join(status)
|
|
.join(format!("{}_{}.md", uuid, slug(title)));
|
|
|
|
fs::write(
|
|
&path,
|
|
format!(
|
|
"# {title}\n\
|
|
\n\
|
|
## Description\n\
|
|
Prose that mentions **Campaign**: not a field, in the body.\n\
|
|
\n\
|
|
## Acceptance Criteria\n\
|
|
- [x] Crit one\n\
|
|
\n\
|
|
## Implementation Plan\n\
|
|
1. Step one\n\
|
|
\n\
|
|
## Notes\n\
|
|
A handwritten note the tool knows nothing about.\n\
|
|
\n\
|
|
## Metadata\n\
|
|
\n\
|
|
- **ID**: {uuid}\n\
|
|
- **Priority**: 3\n\
|
|
- **Tags**: alpha\n\
|
|
- **Due**: _Not set_\n\
|
|
- **Handled By Team**: ops\n\
|
|
- **Owner**: alice\n\
|
|
- **Created At**: 2026-08-21 02:10:17\n\
|
|
- **Status**: {status}\n"
|
|
),
|
|
)
|
|
.unwrap();
|
|
|
|
path
|
|
}
|
|
|
|
fn create_campaign(worklane: &Path, title: &str, uuid: &str) -> PathBuf {
|
|
let path = worklane
|
|
.join("campaigns")
|
|
.join(format!("{}_{}.md", uuid, slug(title)));
|
|
|
|
fs::write(
|
|
&path,
|
|
format!(
|
|
"# {title}\n\
|
|
\n\
|
|
## Description\n\
|
|
What has to ship together.\n\
|
|
\n\
|
|
## Metadata\n\
|
|
\n\
|
|
- **ID**: {uuid}\n\
|
|
- **Owner**: alice\n\
|
|
- **Created At**: 2026-08-21 02:10:17\n"
|
|
),
|
|
)
|
|
.unwrap();
|
|
|
|
path
|
|
}
|
|
|
|
fn board(temp: &TempDir) -> PathBuf {
|
|
let worklane = setup_worklane(temp);
|
|
create_campaign(&worklane, "v1 release", CAMP_A);
|
|
create_campaign(&worklane, "v2 release", CAMP_B);
|
|
create_ticket(&worklane, "backlog", "The member", MEMBER);
|
|
create_ticket(&worklane, "done", "The other member", OTHER);
|
|
create_ticket(&worklane, "backlog", "The loner", LONER);
|
|
worklane
|
|
}
|
|
|
|
fn run(temp: &TempDir, args: &[&str]) -> std::process::Output {
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(temp.path()).args(args);
|
|
cmd.assert().get_output().clone()
|
|
}
|
|
|
|
fn stdout(out: &std::process::Output) -> String {
|
|
String::from_utf8_lossy(&out.stdout).to_string()
|
|
}
|
|
|
|
fn stderr(out: &std::process::Output) -> String {
|
|
String::from_utf8_lossy(&out.stderr).to_string()
|
|
}
|
|
|
|
fn find(worklane: &Path, uuid: &str) -> PathBuf {
|
|
for status in ["backlog", "committed", "reviewing", "done"] {
|
|
for entry in fs::read_dir(worklane.join(status))
|
|
.unwrap()
|
|
.filter_map(|e| e.ok())
|
|
{
|
|
if entry.file_name().to_string_lossy().starts_with(uuid) {
|
|
return entry.path();
|
|
}
|
|
}
|
|
}
|
|
|
|
panic!("no file for ticket {uuid}");
|
|
}
|
|
|
|
fn ticket(worklane: &Path, uuid: &str) -> String {
|
|
fs::read_to_string(find(worklane, uuid)).unwrap()
|
|
}
|
|
|
|
fn campaigns(worklane: &Path) -> Vec<String> {
|
|
let mut names: Vec<String> = fs::read_dir(worklane.join("campaigns"))
|
|
.unwrap()
|
|
.filter_map(|e| e.ok())
|
|
.map(|e| e.file_name().to_string_lossy().to_string())
|
|
.collect();
|
|
names.sort();
|
|
names
|
|
}
|
|
|
|
// ------------------------------------------------------------------ filing one --
|
|
|
|
#[test]
|
|
fn campaign_add_writes_a_uuid_title_description_and_metadata() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let out = run(
|
|
&temp,
|
|
&[
|
|
"campaign",
|
|
"add",
|
|
"--title",
|
|
"v1 release",
|
|
"--description",
|
|
"Everything that ships together.",
|
|
"--owner",
|
|
"alice",
|
|
],
|
|
);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
let names = campaigns(&worklane);
|
|
assert_eq!(names.len(), 1, "{names:?}");
|
|
let name = &names[0];
|
|
assert!(name.ends_with("_v1-release.md"), "{name}");
|
|
|
|
let content = fs::read_to_string(worklane.join("campaigns").join(name)).unwrap();
|
|
assert!(content.starts_with("# v1 release\n"), "{content}");
|
|
assert!(content.contains("Everything that ships together."), "{content}");
|
|
assert!(content.contains("- **Owner**: alice"), "{content}");
|
|
assert!(content.contains("- **Created At**: 20"), "{content}");
|
|
|
|
// The uuid in the file is the one in the filename, since that is what `assign`
|
|
// stores and what every lookup compares against.
|
|
let uuid = name.split('_').next().unwrap();
|
|
assert!(content.contains(&format!("- **ID**: {uuid}")), "{content}");
|
|
}
|
|
|
|
/// A campaign has no status, so its file carries none. A Status field would be a second
|
|
/// place for a state that is derived, and the two would disagree the moment a member
|
|
/// moved.
|
|
#[test]
|
|
fn a_campaign_carries_no_status_and_no_criteria() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
run(&temp, &["campaign", "add", "--title", "v1 release"]);
|
|
|
|
let name = campaigns(&worklane).remove(0);
|
|
let content = fs::read_to_string(worklane.join("campaigns").join(name)).unwrap();
|
|
|
|
assert!(!content.contains("**Status**"), "{content}");
|
|
assert!(!content.contains("Acceptance Criteria"), "{content}");
|
|
assert!(!content.contains("Implementation Plan"), "{content}");
|
|
}
|
|
|
|
#[test]
|
|
fn nothing_is_created_without_a_title() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
let out = run(&temp, &["campaign", "add", "--description", "No title here."]);
|
|
|
|
assert_eq!(out.status.code(), Some(2), "{}", stderr(&out));
|
|
assert!(campaigns(&worklane).is_empty(), "{:?}", campaigns(&worklane));
|
|
}
|
|
|
|
#[test]
|
|
fn init_creates_the_campaigns_directory() {
|
|
let temp = TempDir::new().unwrap();
|
|
|
|
let out = run(&temp, &["init"]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
assert!(temp.child(".worklane").child("campaigns").path().is_dir());
|
|
}
|
|
|
|
/// A board made before campaigns existed has no such directory, and a `worklane init`
|
|
/// over a live board to get one would be a strange thing to have to do.
|
|
#[test]
|
|
fn the_campaigns_directory_is_created_for_a_board_that_predates_it() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = temp.child(".worklane");
|
|
worklane.create_dir_all().unwrap();
|
|
for dir in ["backlog", "committed", "reviewing", "done"] {
|
|
worklane.child(dir).create_dir_all().unwrap();
|
|
}
|
|
assert!(!worklane.child("campaigns").path().exists());
|
|
|
|
let out = run(&temp, &["campaign", "add", "--title", "v1 release"]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
assert_eq!(campaigns(worklane.path()).len(), 1);
|
|
}
|
|
|
|
// -------------------------------------------------------------------- assigning --
|
|
|
|
#[test]
|
|
fn assign_writes_the_campaign_field_in_the_metadata_section() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
|
|
let out = run(&temp, &["assign", "v1 release", MEMBER]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
let content = ticket(&worklane, MEMBER);
|
|
assert!(content.contains(&format!("- **Campaign**: {CAMP_A}")), "{content}");
|
|
|
|
// Scoped to the section: the description quotes the marker, and the field has to
|
|
// land under the heading rather than over the prose.
|
|
let metadata = content.split("## Metadata").nth(1).unwrap();
|
|
assert!(metadata.contains(&format!("- **Campaign**: {CAMP_A}")), "{content}");
|
|
assert!(
|
|
content.contains("Prose that mentions **Campaign**: not a field, in the body."),
|
|
"the description was rewritten: {content}"
|
|
);
|
|
}
|
|
|
|
/// The field goes in its place among the others rather than at the end, so Status stays
|
|
/// last, which is where every file already keeps it.
|
|
#[test]
|
|
fn the_field_is_inserted_before_status() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
|
|
let content = ticket(&worklane, MEMBER);
|
|
let campaign_at = content.find("- **Campaign**:").unwrap();
|
|
let status_at = content.find("- **Status**:").unwrap();
|
|
assert!(campaign_at < status_at, "{content}");
|
|
}
|
|
|
|
/// All three tiers, since a campaign is addressed the way a ticket is: a uuid prefix, a
|
|
/// title substring, and a substring reaching the middle of the filename.
|
|
#[test]
|
|
fn a_campaign_resolves_by_uuid_prefix_title_or_filename() {
|
|
for search in ["aa11", "v1 release", "4dd4"] {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
|
|
let out = run(&temp, &["assign", search, MEMBER]);
|
|
assert!(out.status.success(), "{search}: {}", stderr(&out));
|
|
assert!(
|
|
ticket(&worklane, MEMBER).contains(&format!("- **Campaign**: {CAMP_A}")),
|
|
"{search}: {}",
|
|
ticket(&worklane, MEMBER)
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_ticket_names_at_most_one_campaign() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
let out = run(&temp, &["assign", "v2 release", MEMBER]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
let content = ticket(&worklane, MEMBER);
|
|
assert_eq!(
|
|
content.matches("- **Campaign**:").count(),
|
|
1,
|
|
"reassigning added a second field: {content}"
|
|
);
|
|
assert!(content.contains(&format!("- **Campaign**: {CAMP_B}")), "{content}");
|
|
assert!(!content.contains(CAMP_A), "{content}");
|
|
}
|
|
|
|
#[test]
|
|
fn assigning_the_campaign_already_named_writes_nothing() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
let before = ticket(&worklane, MEMBER);
|
|
|
|
let out = run(&temp, &["assign", "v1 release", MEMBER]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
assert!(stdout(&out).contains("already in campaign"), "{}", stdout(&out));
|
|
assert_eq!(ticket(&worklane, MEMBER), before);
|
|
}
|
|
|
|
/// The campaign is resolved before the ticket is touched, so a call naming a good
|
|
/// ticket and a campaign that does not exist writes nothing at all.
|
|
#[test]
|
|
fn an_unknown_campaign_leaves_the_ticket_alone() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
let before = ticket(&worklane, MEMBER);
|
|
|
|
let out = run(&temp, &["assign", "v9 release", MEMBER]);
|
|
|
|
assert!(!out.status.success());
|
|
assert!(stderr(&out).contains("No campaign found matching"), "{}", stderr(&out));
|
|
assert_eq!(ticket(&worklane, MEMBER), before);
|
|
}
|
|
|
|
#[test]
|
|
fn content_the_tool_does_not_know_survives_an_assignment() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
|
|
let content = ticket(&worklane, MEMBER);
|
|
assert!(content.contains("## Notes"), "{content}");
|
|
assert!(
|
|
content.contains("A handwritten note the tool knows nothing about."),
|
|
"{content}"
|
|
);
|
|
assert!(content.contains("- **Handled By Team**: ops"), "{content}");
|
|
// And the ticked criterion is still ticked.
|
|
assert!(content.contains("- [x] Crit one"), "{content}");
|
|
}
|
|
|
|
/// One field, one writer. `assign` owns Campaign the way `chown` owns Owner.
|
|
#[test]
|
|
fn neither_add_nor_set_offers_a_campaign_flag() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
|
|
let added = run(&temp, &["add", "--title", "New one", "--campaign", "v1 release"]);
|
|
assert_eq!(added.status.code(), Some(2), "{}", stderr(&added));
|
|
|
|
let set = run(&temp, &["set", MEMBER, "--campaign", "v1 release"]);
|
|
assert_eq!(set.status.code(), Some(2), "{}", stderr(&set));
|
|
|
|
// The stored shape, not the bare marker: the fixture description quotes the marker
|
|
// on purpose, so an unscoped match here would pass whatever the commands did.
|
|
assert!(!ticket(&worklane, MEMBER).contains("- **Campaign**:"));
|
|
}
|
|
|
|
// --------------------------------------------------------------------- reading --
|
|
|
|
#[test]
|
|
fn campaign_ls_lists_campaigns_with_their_member_counts() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
run(&temp, &["assign", "v1 release", OTHER]);
|
|
|
|
let out = run(&temp, &["campaign", "ls"]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
let listing = stdout(&out);
|
|
// One of the two members is in done, so the campaign is open and half finished.
|
|
assert!(listing.contains("v1 release | 1/2 done [open]"), "{listing}");
|
|
// Nothing has been filed against the other one.
|
|
assert!(listing.contains("v2 release | no members"), "{listing}");
|
|
}
|
|
|
|
/// The machine-readable listing, the same two fields and the same shape as `ls --ids`.
|
|
#[test]
|
|
fn campaign_ls_ids_prints_the_id_and_the_title_tab_separated() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
|
|
let out = run(&temp, &["campaign", "ls", "--ids"]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
let listing = stdout(&out);
|
|
assert_eq!(
|
|
listing.lines().collect::<Vec<_>>(),
|
|
vec![
|
|
format!("{}\tv1 release", &CAMP_A[..7]),
|
|
format!("{}\tv2 release", &CAMP_B[..7]),
|
|
]
|
|
);
|
|
|
|
// Nothing decorated: no heading, no member count, no escape.
|
|
assert!(!listing.contains("Campaigns:"), "{listing}");
|
|
assert!(!listing.contains("done"), "{listing}");
|
|
assert!(!listing.contains('\u{1b}'), "{listing}");
|
|
}
|
|
|
|
/// A completion offers nothing rather than a sentence, so the empty case that prints
|
|
/// prose for a reader has to stay out of the parsed path.
|
|
#[test]
|
|
fn campaign_ls_ids_says_nothing_on_a_board_with_no_campaigns() {
|
|
let temp = TempDir::new().unwrap();
|
|
setup_worklane(&temp);
|
|
|
|
let out = run(&temp, &["campaign", "ls", "--ids"]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
assert_eq!(stdout(&out), "");
|
|
|
|
// The decorated listing still explains itself.
|
|
assert!(stdout(&run(&temp, &["campaign", "ls"])).contains("No campaigns yet"));
|
|
}
|
|
|
|
/// A campaign is done when it holds members and every one of them is done. An empty one
|
|
/// is neither, which is why it reads `no members` rather than `0/0 done`.
|
|
#[test]
|
|
fn a_campaign_whose_every_member_is_done_reads_done() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", OTHER]);
|
|
|
|
let listing = stdout(&run(&temp, &["campaign", "ls"]));
|
|
assert!(listing.contains("v1 release | 1/1 done [done]"), "{listing}");
|
|
}
|
|
|
|
#[test]
|
|
fn campaign_show_prints_the_body_and_the_members_grouped_by_status() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
run(&temp, &["assign", "v1 release", OTHER]);
|
|
|
|
let out = run(&temp, &["campaign", "show", "aa11"]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
let shown = stdout(&out);
|
|
assert!(shown.contains("v1 release"), "{shown}");
|
|
assert!(shown.contains("What has to ship together."), "{shown}");
|
|
assert!(shown.contains("1/2 done"), "{shown}");
|
|
assert!(shown.contains("[BACKLOG]"), "{shown}");
|
|
assert!(shown.contains("The member"), "{shown}");
|
|
// Done members are shown here, unlike in `ls`: what is finished against what is
|
|
// left is the whole question a campaign asks.
|
|
assert!(shown.contains("[DONE]"), "{shown}");
|
|
assert!(shown.contains("The other member"), "{shown}");
|
|
// And a ticket in no campaign is not a member of this one.
|
|
assert!(!shown.contains("The loner"), "{shown}");
|
|
}
|
|
|
|
#[test]
|
|
fn ls_campaign_lists_only_that_campaigns_members() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
run(&temp, &["assign", "v2 release", LONER]);
|
|
|
|
let out = run(&temp, &["ls", "--campaign", "v1 release"]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
let listing = stdout(&out);
|
|
assert!(listing.contains("The member"), "{listing}");
|
|
assert!(!listing.contains("The loner"), "{listing}");
|
|
assert!(listing.contains("[BACKLOG] 1 ticket"), "{listing}");
|
|
}
|
|
|
|
#[test]
|
|
fn ls_campaign_refuses_a_campaign_that_does_not_exist() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
let out = run(&temp, &["ls", "--campaign", "v9 release"]);
|
|
|
|
assert!(!out.status.success());
|
|
assert!(stderr(&out).contains("No campaign found matching"), "{}", stderr(&out));
|
|
}
|
|
|
|
/// The stored value is a full uuid, so a campaign that has been deleted has to be
|
|
/// reported as gone rather than shown raw, the way a dangling relation target is.
|
|
#[test]
|
|
fn a_campaign_that_no_longer_exists_reads_as_missing() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
fs::remove_file(
|
|
worklane
|
|
.join("campaigns")
|
|
.join(format!("{CAMP_A}_v1-release.md")),
|
|
)
|
|
.unwrap();
|
|
|
|
let out = run(&temp, &["show", MEMBER]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
|
|
let shown = stdout(&out);
|
|
assert!(shown.contains("_missing_"), "{shown}");
|
|
// The short id survives, since it is the only thing left to go looking for.
|
|
assert!(shown.contains("(aa11bb2)"), "{shown}");
|
|
assert!(!shown.contains(CAMP_A), "the bare uuid was shown: {shown}");
|
|
}
|
|
|
|
/// The title is shown rather than the uuid the file stores: thirty-six characters of
|
|
/// hex in a metadata table say nothing about which campaign it is.
|
|
#[test]
|
|
fn a_ticket_shows_the_campaign_title_not_its_uuid() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
run(&temp, &["assign", "v1 release", MEMBER]);
|
|
|
|
let shown = stdout(&run(&temp, &["show", MEMBER]));
|
|
assert!(shown.contains("(aa11bb2) v1 release"), "{shown}");
|
|
assert!(!shown.contains(CAMP_A), "{shown}");
|
|
}
|
|
|
|
// -------------------------------------------------------------- not a ticket --
|
|
|
|
/// A campaign is in no status directory, so `mv` has nothing to move. It says so rather
|
|
/// than reporting a ticket it could not find, which would send the caller hunting for a
|
|
/// typo in a name that is perfectly correct.
|
|
#[test]
|
|
fn mv_refuses_a_campaign() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = board(&temp);
|
|
|
|
let out = run(&temp, &["mv", "v1 release", "--status", "committed"]);
|
|
|
|
assert!(!out.status.success());
|
|
let message = stderr(&out);
|
|
assert!(message.contains("is a campaign, not a ticket"), "{message}");
|
|
assert!(message.contains("no status directory"), "{message}");
|
|
|
|
// And it stayed where it was: nothing was moved into a status directory.
|
|
assert!(
|
|
worklane
|
|
.join("campaigns")
|
|
.join(format!("{CAMP_A}_v1-release.md"))
|
|
.exists()
|
|
);
|
|
for status in ["backlog", "committed", "reviewing", "done"] {
|
|
let moved = fs::read_dir(worklane.join(status))
|
|
.unwrap()
|
|
.filter_map(|e| e.ok())
|
|
.any(|e| e.file_name().to_string_lossy().starts_with(CAMP_A));
|
|
assert!(!moved, "a campaign reached the {status} directory");
|
|
}
|
|
}
|
|
|
|
/// Every command that takes a ticket gives the same explanation, because the refusal is
|
|
/// in resolution rather than in `mv`.
|
|
#[test]
|
|
fn a_campaign_is_refused_wherever_a_ticket_is_expected() {
|
|
for args in [
|
|
vec!["show", "v1 release"],
|
|
vec!["comment", "v1 release", "A note."],
|
|
vec!["chown", "bob", "v1 release"],
|
|
] {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
let out = run(&temp, &args);
|
|
assert!(!out.status.success(), "{args:?}");
|
|
assert!(
|
|
stderr(&out).contains("is a campaign, not a ticket"),
|
|
"{args:?}: {}",
|
|
stderr(&out)
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A search that names neither still says nothing was found, rather than complaining
|
|
/// about a directory the caller never mentioned.
|
|
#[test]
|
|
fn a_search_that_names_nothing_still_reports_no_ticket() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
let out = run(&temp, &["show", "nothing at all"]);
|
|
|
|
assert!(!out.status.success());
|
|
assert!(stderr(&out).contains("No ticket found matching"), "{}", stderr(&out));
|
|
}
|
|
|
|
/// A campaign resolves by the same tiers a ticket does, so it can be ambiguous the same
|
|
/// way, and the listing has to name campaigns rather than tickets.
|
|
#[test]
|
|
fn an_ambiguous_campaign_lists_the_candidates() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = board(&temp);
|
|
|
|
let out = run(&temp, &["campaign", "show", "release"]);
|
|
|
|
assert!(!out.status.success());
|
|
let message = stderr(&out);
|
|
assert!(message.contains("Multiple campaigns found matching"), "{message}");
|
|
assert!(message.contains("v1 release"), "{message}");
|
|
assert!(message.contains("v2 release"), "{message}");
|
|
}
|