Edit a campaign's description, and bump to 0.27.0

`campaign set` reached the title and the codename, so the description a
campaign was filed with was the description it kept: fixing a typo in the
one field nothing could edit meant a hand edit of the file, or refiling the
campaign and reassigning every member.

Both halves arrive together, which is why d637288 left this out rather than
adding the flag. `campaign set --description` replaces the section and
`campaign append --description` adds a paragraph to it, because a `set` with
no `append` is the half that is easy to reach for and wrong: replacing a
description to add a sentence is how the rest of it gets lost.

`append` is a campaign's own subcommand rather than the top-level one, which
resolves a ticket. `resolve_in`'s tiers are the same over both directories,
so one positional naming either object could resolve in each with nothing
but a flag to say which was meant, and it would make a liar of the
explanation `resolve_ticket` gives a ticket search that names a campaign.

The section is the `DESCRIPTION` entry and the surgery is
`set_section_body`, `append_section_body` and `Section::normalise`, not a
copy scoped to campaigns. `SECTION_ORDER` needs no campaign variant: a
campaign holds one section where a ticket holds four, and the followers a
campaign does not have are simply not in the file, so its description
anchors against `## Metadata`, where `campaign_body` writes it.

Still no `--clear`, and that is now a decision rather than a deferral: a
campaign's description has no cleared form, so an empty `--description ""`
is a paragraph break here as it is everywhere else, and the refusal for an
all-blank value says there is nowhere to go back to instead of naming a flag
that does not exist. `replaced_items` and `appended_items` hold that check
once for both objects, with the way out as the caller's argument.

The section refusal no longer says "Ticket", since a campaign reaches it
too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-08-24 04:53:49 +02:00
co-authored by Claude Opus 5
parent 5dc087d49e
commit 3592584747
12 changed files with 652 additions and 56 deletions
+445 -5
View File
@@ -1129,11 +1129,13 @@ fn an_unknown_campaign_is_refused_and_nothing_is_written() {
);
}
/// No `--description`: `set` and `append` are a pair for a prose section, and a way to
/// replace a description with no way to add a paragraph is half of it. Pinned so the
/// omission stays a decision rather than becoming an oversight somebody fills in.
/// `--description` arrived with `campaign append`, 32e98ab, because for a prose section the
/// two are a pair. What is still deliberately absent is what this pins: no `--owner`, which
/// would settle by accident whether `chown` grows a campaign, and no `--clear`, because a
/// campaign's description has no cleared form and `Clearable`'s variants are a ticket's
/// fields.
#[test]
fn campaign_set_offers_no_description_and_no_owner() {
fn campaign_set_offers_no_owner_and_no_clear() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
@@ -1142,7 +1144,7 @@ fn campaign_set_offers_no_description_and_no_owner() {
assert!(help.contains("--codename"), "{help}");
assert!(help.contains("--title"), "{help}");
assert!(!help.contains("--description"), "{help}");
assert!(help.contains("--description"), "{help}");
assert!(!help.contains("--owner"), "{help}");
assert!(!help.contains("--clear"), "{help}");
}
@@ -1263,3 +1265,441 @@ fn the_title_is_replaced_without_force() {
assert!(out.status.success(), "{}", stderr(&out));
assert!(campaign_file(&worklane, CAMP_A).starts_with("# First public release\n"));
}
// ---------------------------------------------- campaign set --description --
/// The point of 32e98ab: the description a campaign was filed with is no longer the one it
/// keeps. `create_campaign` writes prose, so this is a replacement rather than a first line.
#[test]
fn campaign_set_replaces_the_description() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let out = run(
&temp,
&[
"campaign",
"set",
"v1 release",
"--description",
"What the tag has to hold.",
],
);
assert!(out.status.success(), "{}", stderr(&out));
assert!(stdout(&out).contains("Updated description"), "{}", stdout(&out));
let content = campaign_file(&worklane, CAMP_A);
assert!(content.contains("What the tag has to hold."), "{content}");
assert!(
!content.contains("What has to ship together."),
"the old description survived: {content}"
);
}
/// An empty value between two others is the paragraph break, the rule every prose argument
/// in the tool follows: `add --description`, `set --description` and `tags --annotation`.
#[test]
fn an_empty_value_is_a_paragraph_break_in_a_campaigns_description() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let out = run(
&temp,
&[
"campaign",
"set",
"v1 release",
"-d",
"The tag itself.",
"-d",
"",
"-d",
"And what blocks it.",
],
);
assert!(out.status.success(), "{}", stderr(&out));
let content = campaign_file(&worklane, CAMP_A);
assert!(content.contains("The tag itself.\n\nAnd what blocks it."), "{content}");
}
/// And an all-blank value is refused rather than emptying the section. The refusal names no
/// flag, because there is none: a campaign's description has no cleared form, which is the
/// `Clearable` question 32e98ab settled rather than deferred.
#[test]
fn an_all_blank_description_is_refused_and_names_no_clear_flag() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let before = campaign_file(&worklane, CAMP_A);
let out = run(&temp, &["campaign", "set", "v1 release", "-d", "", "-d", " "]);
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
let said = stderr(&out);
assert!(said.contains("An empty value is a paragraph break"), "{said}");
assert!(said.contains("no cleared form"), "{said}");
assert!(!said.contains("--clear"), "it named a flag that does not exist: {said}");
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the file was written");
}
/// The whole-file comparison `set`, `chown` and the codename already use, so a description
/// replaced with the one it already holds writes nothing.
#[test]
fn setting_the_description_a_campaign_already_has_writes_nothing() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let before = campaign_file(&worklane, CAMP_A);
let out = run(
&temp,
&[
"campaign",
"set",
"v1 release",
"-d",
"What has to ship together.",
],
);
assert!(out.status.success(), "{}", stderr(&out));
assert!(stdout(&out).contains("No changes"), "{}", stdout(&out));
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the file was rewritten");
}
/// Three fields in one call, since the group is `multiple` and the description is in it.
#[test]
fn campaign_set_takes_the_title_the_description_and_the_codename_together() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let out = run(
&temp,
&[
"campaign",
"set",
"v1 release",
"-t",
"First public release",
"-d",
"What the tag has to hold.",
"-c",
"v1",
],
);
assert!(out.status.success(), "{}", stderr(&out));
assert!(stdout(&out).contains("title, description, codename"), "{}", stdout(&out));
let content = campaign_file(&worklane, CAMP_A);
assert!(content.starts_with("# First public release\n"), "{content}");
assert!(content.contains("What the tag has to hold."), "{content}");
assert!(content.contains("- **Codename**: v1"), "{content}");
}
/// A refused codename takes the description down with it, the way it already takes the
/// title: checked before any edit is applied, so a call writes all of what it asked for or
/// none of it.
#[test]
fn a_refused_codename_takes_the_description_down_with_it() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
let before = campaign_file(&worklane, CAMP_A);
let out = run(
&temp,
&[
"campaign",
"set",
"v1",
"-d",
"Rewritten anyway.",
"-c",
"beaver",
],
);
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the description went through");
}
// ---------------------------------------------------------- campaign append --
/// The other half of the pair, and the reason `set --description` is not a flag on its own:
/// adding a line to a description must not mean retyping the rest of it.
#[test]
fn campaign_append_adds_a_paragraph_without_replacing_the_description() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let out = run(
&temp,
&[
"campaign",
"append",
"v1 release",
"-d",
"And what is out of scope.",
],
);
assert!(out.status.success(), "{}", stderr(&out));
assert!(stdout(&out).contains("Appended to description"), "{}", stdout(&out));
let content = campaign_file(&worklane, CAMP_A);
// The paragraph lands after the one that was there, with the blank line between them
// that makes it a paragraph rather than a run-on.
assert!(
content.contains("What has to ship together.\n\nAnd what is out of scope.\n"),
"{content}"
);
}
/// Several values in one call are lines *within* the paragraph, not several paragraphs. The
/// same reading `append --description` gives a ticket, since it is the same section entry.
#[test]
fn the_values_of_one_append_are_lines_within_the_paragraph() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
run(
&temp,
&[
"campaign",
"append",
"v1 release",
"-d",
"Out of scope:",
"-d",
"the installer.",
],
);
let content = campaign_file(&worklane, CAMP_A);
assert!(content.contains("Out of scope:\nthe installer.\n"), "{content}");
}
/// A campaign filed with no description holds the placeholder, and appending replaces it
/// rather than following it: the alternative reads `_No description provided._` above the
/// description. `append_section_body`'s rule, so nothing here handles the case.
#[test]
fn appending_to_an_empty_description_replaces_the_placeholder() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
run(&temp, &["campaign", "add", "--title", "No prose yet"]);
let uuid = {
let names = campaigns(&worklane);
let name = names
.iter()
.find(|name| name.ends_with("_no-prose-yet.md"))
.expect("the campaign was not filed");
name.split('_').next().unwrap().to_string()
};
assert!(
campaign_file(&worklane, &uuid).contains("_No description provided._"),
"the placeholder is not what add writes any more"
);
let out = run(
&temp,
&[
"campaign",
"append",
"No prose yet",
"-d",
"The first thing said.",
],
);
assert!(out.status.success(), "{}", stderr(&out));
let content = campaign_file(&worklane, &uuid);
assert!(content.contains("The first thing said."), "{content}");
assert!(
!content.contains("_No description provided._"),
"the placeholder is still above the description: {content}"
);
}
/// Every value blank is refused rather than writing nothing quietly, the answer `append`
/// gives a ticket, in the same words: appending nothing was never a way to empty anything,
/// so there is no flag to name.
#[test]
fn an_all_blank_append_is_refused() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let before = campaign_file(&worklane, CAMP_A);
let out = run(&temp, &["campaign", "append", "v1 release", "-d", " "]);
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
assert!(stderr(&out).contains("Nothing to append"), "{}", stderr(&out));
assert_eq!(campaign_file(&worklane, CAMP_A), before, "the file was written");
}
/// A bare `campaign append <campaign>` is a usage error rather than a silent no-op, the way
/// a bare `campaign set` is. `--description` is `required` rather than a group of one.
#[test]
fn campaign_append_with_no_description_is_a_usage_error() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let before = campaign_file(&worklane, CAMP_A);
let out = run(&temp, &["campaign", "append", "v1 release"]);
assert_eq!(out.status.code(), Some(2), "{}", stderr(&out));
assert_eq!(campaign_file(&worklane, CAMP_A), before, "something was written");
}
/// Appending to a scalar has no meaning, which is the line `append` already draws for a
/// ticket: no `--title` there and none here, and no `--codename` either.
#[test]
fn campaign_append_offers_only_the_description() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
let out = run(&temp, &["campaign", "append", "--help"]);
let help = stdout(&out);
assert!(help.contains("--description"), "{help}");
assert!(!help.contains("--title"), "{help}");
assert!(!help.contains("--codename"), "{help}");
assert!(!help.contains("--force"), "{help}");
}
/// A campaign is addressed here by the same tiers everything else takes, codename included,
/// because it goes through `resolve_campaign` rather than a lookup of its own.
#[test]
fn campaign_append_resolves_the_campaign_by_its_codename() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
run(&temp, &["campaign", "set", "v1 release", "-c", "beaver"]);
let out = run(&temp, &["campaign", "append", "beaver", "-d", "One more thing."]);
assert!(out.status.success(), "{}", stderr(&out));
assert!(
campaign_file(&worklane, CAMP_A).contains("One more thing."),
"{}",
campaign_file(&worklane, CAMP_A)
);
}
/// An unknown campaign leaves every campaign alone, the answer `campaign set` and `assign`
/// already give.
#[test]
fn campaign_append_refuses_an_unknown_campaign() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let before = campaign_file(&worklane, CAMP_A);
let out = run(&temp, &["campaign", "append", "nothing-by-that-name", "-d", "Text."]);
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
assert!(stderr(&out).contains("No campaign found"), "{}", stderr(&out));
assert_eq!(campaign_file(&worklane, CAMP_A), before, "something was written");
}
// ------------------------------------------------------ the shared machinery --
/// A campaign has one section where a ticket has four, and the section table in `util.rs` is
/// what both go through. So the surgery has to land against `## Metadata`, which is the only
/// heading that follows a campaign's description, and leave everything outside the body
/// alone: a handwritten section, the owner, and the codename in its place.
#[test]
fn the_description_is_edited_in_place_in_a_file_with_one_section() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
run(&temp, &["campaign", "set", "v1 release", "-c", "v1"]);
let path = worklane
.join("campaigns")
.join(format!("{}_{}.md", CAMP_A, slug("v1 release")));
let original = fs::read_to_string(&path).unwrap();
fs::write(
&path,
original.replace("## Metadata", "## Notes\nA handwritten note.\n\n## Metadata"),
)
.unwrap();
run(&temp, &["campaign", "set", "v1", "-d", "Replaced."]);
run(&temp, &["campaign", "append", "v1", "-d", "Added."]);
let content = campaign_file(&worklane, CAMP_A);
assert!(content.contains("## Description\nReplaced.\n\nAdded.\n"), "{content}");
// Nothing outside the body moved: the section that follows it, the handwritten one
// between them, and the fields under it.
assert!(content.contains("## Notes\nA handwritten note."), "{content}");
assert!(content.contains("- **Codename**: v1"), "{content}");
assert!(content.contains("- **Owner**: alice"), "{content}");
assert!(!content.contains("**Status**"), "a status was invented: {content}");
// And no section a campaign does not have was inserted to anchor against.
assert!(!content.contains("## Acceptance Criteria"), "{content}");
assert!(!content.contains("## Implementation Plan"), "{content}");
}
/// The heading is the one in the section table, so `campaign set --description` reaches the
/// section `campaign_body` wrote and `campaign show` prints. A second spelling scoped to
/// campaigns is what this would catch.
#[test]
fn the_description_a_campaign_is_filed_with_is_the_one_set_replaces() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
run(
&temp,
&[
"campaign",
"add",
"--title",
"Filed with prose",
"--description",
"As filed.",
],
);
run(&temp, &["campaign", "set", "Filed with prose", "-d", "As replaced."]);
let out = run(&temp, &["campaign", "show", "Filed with prose"]);
let shown = stdout(&out);
assert!(shown.contains("As replaced."), "{shown}");
assert!(!shown.contains("As filed."), "{shown}");
// One Description heading in the file, not a second one written beside it.
let names = campaigns(&worklane);
let name = names
.iter()
.find(|name| name.ends_with("_filed-with-prose.md"))
.expect("not filed");
let content = fs::read_to_string(worklane.join("campaigns").join(name)).unwrap();
assert_eq!(content.matches("## Description").count(), 1, "{content}");
}
/// A campaign file with no Description heading is refused rather than given one back. Every
/// campaign the tool files carries the heading, so an insertion path here would be reachable
/// only from a hand-edited file, which is the opposite of the Relations case. The message
/// names the section and not the object, because both a ticket and a campaign reach it.
#[test]
fn a_campaign_with_no_description_section_is_refused() {
let temp = TempDir::new().unwrap();
let worklane = board(&temp);
let path = worklane
.join("campaigns")
.join(format!("{}_{}.md", CAMP_A, slug("v1 release")));
let original = fs::read_to_string(&path).unwrap();
fs::write(
&path,
original.replace("## Description\nWhat has to ship together.\n\n", ""),
)
.unwrap();
let before = fs::read_to_string(&path).unwrap();
for args in [
["campaign", "set", "v1 release", "-d", "Text."],
["campaign", "append", "v1 release", "-d", "Text."],
] {
let out = run(&temp, &args);
assert_eq!(out.status.code(), Some(1), "{}", stderr(&out));
let said = stderr(&out);
assert!(said.contains("no description section"), "{said}");
assert!(!said.contains("Ticket"), "a campaign was called a ticket: {said}");
assert_eq!(fs::read_to_string(&path).unwrap(), before, "the file was written");
}
}