`set --tags` writes the whole field, so adding one tag to a ticket that
already carries some meant reading it first and retyping every one of
them. 30a2b34 wrote that down in the skill as the way to do it; this is
the flag that makes it unnecessary.
The merge is idempotent and ordered. A tag the ticket already carries is
reported as no change rather than added twice, which is the point of the
flag: the caller does not have to know what is there. A new one goes on
the end in the order it was given rather than sorting the field under
whoever last touched it. Values are split on commas the way the stored
field is, so `--tags "bug, tui"` names two tags and matches the two a
ticket carrying them already holds; without that the pair would land as
a single tag nothing can filter by and would not match itself on the
next call. `split_tags` is that rule, lifted out of `parse_tags` so the
argument and the field are separated by the same code.
It writes the same `Kind::Tags` entry `set --tags` writes, so `--actor`
and `--actor-from-git` come with it. Tags are logged wherever they move,
and the one command that adds to them without replacing them would
otherwise be the one tag change the log missed. The before and after are
read off the field rather than off the flag, so an append of `beta` onto
`alpha` reads as the pair and not as what the call asked for.
`non_empty` rather than the `clearable` that `set --tags` takes: that
message names `--clear`, and `append` has none, so it would send the
caller looking here for a flag that is `set`'s. A value that is only
separators reaches the handler and is refused there, in the words
`appended_items` refuses an all-blank section with. Emptying the field
stays `set --clear tags`.
`TAG_FLAGS` becomes pairs of command and flag, because `ls --tag` and
`append --tags` are spelled differently and one rule naming both options
would tell fish that each command accepts the other's. `add --tags` and
`set --tags` deliberately get no value rule and are recorded in the
test's `TAG_LIST_FLAGS` instead: they take the whole list, so the token
at the cursor is `bug,tui` and fish replaces a token entire, throwing
away what is already typed. The honesty test now walks `tag` and `tags`
both, so the next tag argument has to say which of the two it is.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
727 lines
23 KiB
Rust
727 lines
23 KiB
Rust
//! The history log: what the CLI records about a ticket besides what somebody said.
|
|
//!
|
|
//! One file rather than a few tests in each command's suite: the rules are about the log
|
|
//! and not about `mv` or `chown`, and the interesting cases are the ones where two
|
|
//! commands have to agree — every mechanical entry has the same shape, and every refusal
|
|
//! writes nothing.
|
|
|
|
use assert_cmd::Command;
|
|
use assert_fs::TempDir;
|
|
use assert_fs::fixture::{PathChild, PathCreateDir};
|
|
use std::fs;
|
|
use std::path::{Path, PathBuf};
|
|
use std::process::Output;
|
|
|
|
const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane");
|
|
const UUID: &str = "475534a3-8a0d-45cb-9a97-39c251dd8e39";
|
|
|
|
fn setup_worklane(temp: &TempDir) -> PathBuf {
|
|
let worklane = temp.child(".worklane");
|
|
worklane.create_dir_all().unwrap();
|
|
|
|
for dir in ["backlog", "committed", "reviewing", "done"] {
|
|
worklane.child(dir).create_dir_all().unwrap();
|
|
}
|
|
|
|
worklane.path().to_path_buf()
|
|
}
|
|
|
|
/// A ticket with every field an entry can record a change to.
|
|
fn create_ticket(worklane: &Path, status: &str) -> String {
|
|
let filename = format!("{}_a-ticket.md", UUID);
|
|
fs::write(
|
|
worklane.join(status).join(&filename),
|
|
format!(
|
|
"# A ticket\n\
|
|
\n\
|
|
## Description\n\
|
|
Something to do.\n\
|
|
\n\
|
|
## Acceptance Criteria\n\
|
|
- [ ] Crit one\n\
|
|
- [ ] Crit two\n\
|
|
\n\
|
|
## Implementation Plan\n\
|
|
1. Step one\n\
|
|
\n\
|
|
## Metadata\n\
|
|
\n\
|
|
- **ID**: {}\n\
|
|
- **Priority**: 3\n\
|
|
- **Tags**: alpha\n\
|
|
- **Due**: 2026-09-01\n\
|
|
- **Owner**: alice\n\
|
|
- **Status**: {}\n",
|
|
UUID, status
|
|
),
|
|
)
|
|
.unwrap();
|
|
filename
|
|
}
|
|
|
|
/// Run with the actor named, so every author assertion is about the log and not about
|
|
/// the git user of whoever runs the suite.
|
|
fn run(temp: &TempDir, args: &[&str]) -> Output {
|
|
Command::cargo_bin(BIN_NAME)
|
|
.unwrap()
|
|
.current_dir(temp.path())
|
|
.env("WORKLANE_ACTOR", "claude")
|
|
.args(args)
|
|
.assert()
|
|
.get_output()
|
|
.clone()
|
|
}
|
|
|
|
/// Run as an agent acting for the person: the variable still names the agent, the git
|
|
/// config names the human, and the flag is what tells the two apart.
|
|
fn run_for_the_human(temp: &TempDir, args: &[&str]) -> Output {
|
|
Command::cargo_bin(BIN_NAME)
|
|
.unwrap()
|
|
.current_dir(temp.path())
|
|
.env("WORKLANE_ACTOR", "claude")
|
|
.env("GIT_CONFIG_GLOBAL", git_config_naming(temp, "Ansho Rei"))
|
|
.env("GIT_CONFIG_NOSYSTEM", "1")
|
|
.args(args)
|
|
.assert()
|
|
.get_output()
|
|
.clone()
|
|
}
|
|
|
|
/// A git config file holding nothing but a `user.name`, for the tests that need the
|
|
/// fallback to answer something known instead of whatever the machine is configured with.
|
|
fn git_config_naming(temp: &TempDir, name: &str) -> PathBuf {
|
|
let path = temp.path().join("gitconfig");
|
|
fs::write(&path, format!("[user]\n\tname = {}\n", name)).unwrap();
|
|
path
|
|
}
|
|
|
|
/// Every entry on the ticket, name and content, in the order the log sorts them.
|
|
fn entries(worklane: &Path) -> Vec<(String, String)> {
|
|
let dir = worklane.join("history").join(UUID);
|
|
if !dir.exists() {
|
|
return vec![];
|
|
}
|
|
|
|
let mut found: Vec<(String, String)> = fs::read_dir(&dir)
|
|
.unwrap()
|
|
.filter_map(|entry| entry.ok())
|
|
.map(|entry| {
|
|
(
|
|
entry.file_name().into_string().unwrap(),
|
|
fs::read_to_string(entry.path()).unwrap(),
|
|
)
|
|
})
|
|
.collect();
|
|
found.sort_by(|a, b| a.0.cmp(&b.0));
|
|
found
|
|
}
|
|
|
|
/// The one entry a call wrote, with its kind checked off the filename.
|
|
fn only_entry(worklane: &Path, kind: &str) -> String {
|
|
let found = entries(worklane);
|
|
assert_eq!(found.len(), 1, "expected one entry, got {found:?}");
|
|
assert!(found[0].0.ends_with(&format!("_{kind}.md")), "was {}", found[0].0);
|
|
found[0].1.clone()
|
|
}
|
|
|
|
#[test]
|
|
fn mv_writes_a_status_entry() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
run(&temp, &["mv", UUID, "--status", "committed"]);
|
|
|
|
let entry = only_entry(&worklane, "status");
|
|
assert!(entry.starts_with("**Status**\nbacklog → committed\n"), "{entry:?}");
|
|
assert!(entry.contains("**Author**: claude"), "{entry:?}");
|
|
}
|
|
|
|
/// One file, one event, its explanation: `--reason` rides in the status entry that
|
|
/// records the transition it explains, as a field after **Time**, and `show` renders it
|
|
/// indented under the row rather than as a paragraph of its own.
|
|
#[test]
|
|
fn the_reason_travels_with_its_transition() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "reviewing");
|
|
|
|
run(
|
|
&temp,
|
|
&[
|
|
"mv",
|
|
UUID,
|
|
"--status",
|
|
"backlog",
|
|
"-f",
|
|
"--reason",
|
|
"sent back: the first plan was wrong",
|
|
],
|
|
);
|
|
|
|
let entry = only_entry(&worklane, "status");
|
|
assert!(entry.starts_with("**Status**\nreviewing → backlog\n"), "{entry:?}");
|
|
assert!(
|
|
entry.ends_with("**Reason**: sent back: the first plan was wrong\n"),
|
|
"{entry:?}"
|
|
);
|
|
|
|
let out = run(&temp, &["show", UUID]);
|
|
let stdout = String::from_utf8(out.stdout).unwrap();
|
|
|
|
let moved = stdout.find("reviewing → backlog").expect("the move is missing");
|
|
let reason = stdout
|
|
.find("\n sent back: the first plan was wrong")
|
|
.expect("the reason is missing");
|
|
// Attached means the very next line: nothing, not even a blank line, between.
|
|
assert!(
|
|
!stdout[moved..reason].contains('\n'),
|
|
"the reason is detached from its row:\n{stdout}"
|
|
);
|
|
}
|
|
|
|
/// The unusual moves are exactly the ones that need a why, so a refused one must not
|
|
/// log one either: the entry is written after the edit, and there was no edit.
|
|
#[test]
|
|
fn a_refused_move_writes_no_reason_either() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "reviewing");
|
|
|
|
let out = run(
|
|
&temp,
|
|
&[
|
|
"mv",
|
|
UUID,
|
|
"--status",
|
|
"backlog",
|
|
"--reason",
|
|
"this move never happened",
|
|
],
|
|
);
|
|
assert_eq!(out.status.code(), Some(1));
|
|
assert_eq!(entries(&worklane), vec![], "a refused move logged its reason");
|
|
}
|
|
|
|
/// Same for the move that changes nothing.
|
|
#[test]
|
|
fn a_no_op_move_writes_no_reason_either() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "committed");
|
|
|
|
let out = run(
|
|
&temp,
|
|
&[
|
|
"mv",
|
|
UUID,
|
|
"--status",
|
|
"committed",
|
|
"--reason",
|
|
"nothing moved",
|
|
],
|
|
);
|
|
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
|
assert_eq!(entries(&worklane), vec![], "a no-op move logged its reason");
|
|
}
|
|
|
|
#[test]
|
|
fn chown_writes_an_owner_entry() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
run(&temp, &["chown", "bob", UUID]);
|
|
|
|
let entry = only_entry(&worklane, "owner");
|
|
assert!(entry.starts_with("**Owner**\nalice → bob\n"), "{entry:?}");
|
|
}
|
|
|
|
/// Clearing is the same field going somewhere, so it is logged, and the value it goes to
|
|
/// is the sentinel the ticket now holds rather than a word this log invented.
|
|
#[test]
|
|
fn clearing_the_owner_writes_an_owner_entry() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
run(&temp, &["chown", "--clear", UUID]);
|
|
|
|
let entry = only_entry(&worklane, "owner");
|
|
assert!(entry.starts_with("**Owner**\nalice → _Not set_\n"), "{entry:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn set_tags_writes_a_tags_entry() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
run(&temp, &["set", UUID, "--tags", "beta", "--tags", "gamma"]);
|
|
|
|
let entry = only_entry(&worklane, "tags");
|
|
assert!(entry.starts_with("**Tags**\nalpha → beta, gamma\n"), "{entry:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn clearing_the_tags_writes_a_tags_entry() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
run(&temp, &["set", UUID, "--clear", "tags"]);
|
|
|
|
let entry = only_entry(&worklane, "tags");
|
|
assert!(entry.starts_with("**Tags**\nalpha → _None_\n"), "{entry:?}");
|
|
}
|
|
|
|
/// Tags are logged wherever they change, so the command that adds to them logs the same
|
|
/// entry the one that replaces them does. The values come off the field rather than off
|
|
/// the flag, so the entry records where the field went and not what the call added: an
|
|
/// append of `beta` onto `alpha` reads as the pair, not as `beta`.
|
|
#[test]
|
|
fn appending_a_tag_writes_a_tags_entry() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
run(&temp, &["append", UUID, "--tags", "beta"]);
|
|
|
|
let entry = only_entry(&worklane, "tags");
|
|
assert!(entry.starts_with("**Tags**\nalpha → alpha, beta\n"), "{entry:?}");
|
|
}
|
|
|
|
/// The sections are not logged, and appending to one is not a tag change: an append that
|
|
/// touches no tag writes nothing, so the log does not fill with the edits it deliberately
|
|
/// leaves out.
|
|
#[test]
|
|
fn appending_to_a_section_writes_nothing() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
run(&temp, &["append", UUID, "--acceptance", "One more criterion"]);
|
|
|
|
assert_eq!(entries(&worklane), vec![]);
|
|
}
|
|
|
|
/// The entry names the campaign the way a reader knows it, the codename, not the uuid
|
|
/// the field actually holds. A ticket never assigned starts from the sentinel an unset
|
|
/// field reads as everywhere else.
|
|
#[test]
|
|
fn assign_writes_a_campaign_entry_naming_the_codename() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
run(
|
|
&temp,
|
|
&[
|
|
"campaign",
|
|
"add",
|
|
"--title",
|
|
"First public release",
|
|
"--codename",
|
|
"v1",
|
|
],
|
|
);
|
|
|
|
run(&temp, &["assign", "v1", UUID]);
|
|
|
|
let entry = only_entry(&worklane, "campaign");
|
|
assert!(entry.starts_with("**Campaign**\n_Not set_ → v1\n"), "{entry:?}");
|
|
}
|
|
|
|
/// A campaign filed without a codename is recorded by its title, the name `show` and
|
|
/// `campaign ls` fall back to.
|
|
#[test]
|
|
fn a_campaign_without_a_codename_is_recorded_by_its_title() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
run(&temp, &["campaign", "add", "--title", "First public release"]);
|
|
|
|
run(&temp, &["assign", "First public", UUID]);
|
|
|
|
let entry = only_entry(&worklane, "campaign");
|
|
assert!(
|
|
entry.starts_with("**Campaign**\n_Not set_ → First public release\n"),
|
|
"{entry:?}"
|
|
);
|
|
}
|
|
|
|
/// A ticket leaving one campaign for another records both ends, which is the move the
|
|
/// log exists to answer for: the field is rewritten, so nothing else remembers where the
|
|
/// ticket was.
|
|
#[test]
|
|
fn moving_between_campaigns_records_both_names() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
run(
|
|
&temp,
|
|
&[
|
|
"campaign",
|
|
"add",
|
|
"--title",
|
|
"First release",
|
|
"--codename",
|
|
"v1",
|
|
],
|
|
);
|
|
run(
|
|
&temp,
|
|
&[
|
|
"campaign",
|
|
"add",
|
|
"--title",
|
|
"Second release",
|
|
"--codename",
|
|
"beaver",
|
|
],
|
|
);
|
|
|
|
run(&temp, &["assign", "v1", UUID]);
|
|
run(&temp, &["assign", "beaver", UUID]);
|
|
|
|
let found = entries(&worklane);
|
|
assert_eq!(found.len(), 2, "{found:?}");
|
|
assert!(found[1].1.starts_with("**Campaign**\nv1 → beaver\n"), "{:?}", found[1].1);
|
|
}
|
|
|
|
/// Assigning the campaign a ticket already names is reported as no change, and a log of
|
|
/// no change would be a log of nothing happening.
|
|
#[test]
|
|
fn a_no_op_assign_writes_nothing() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
run(
|
|
&temp,
|
|
&[
|
|
"campaign",
|
|
"add",
|
|
"--title",
|
|
"First release",
|
|
"--codename",
|
|
"v1",
|
|
],
|
|
);
|
|
|
|
run(&temp, &["assign", "v1", UUID]);
|
|
let out = run(&temp, &["assign", "v1", UUID]);
|
|
|
|
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
|
|
assert_eq!(
|
|
entries(&worklane).len(),
|
|
1,
|
|
"a no-op assign logged a change it did not make"
|
|
);
|
|
}
|
|
|
|
/// The fields that change often enough that a log of them is noise. `set` writing one of
|
|
/// them is not an entry, and neither is a criterion being ticked.
|
|
#[test]
|
|
fn the_edits_that_are_not_logged_write_nothing() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
for args in [
|
|
vec!["set", UUID, "--title", "A better title"],
|
|
vec!["set", UUID, "--due", "2026-10-01"],
|
|
vec!["set", UUID, "--priority", "1"],
|
|
vec!["set", UUID, "--description", "Rewritten."],
|
|
vec!["set", UUID, "--plan", "One step"],
|
|
vec!["check", UUID, "1"],
|
|
vec!["uncheck", UUID, "1"],
|
|
vec!["append", UUID, "--description", "One more paragraph."],
|
|
vec!["comment", UUID, "-", "--"],
|
|
] {
|
|
let out = run(&temp, &args);
|
|
assert!(
|
|
out.status.success(),
|
|
"{args:?}: {:?}",
|
|
String::from_utf8_lossy(&out.stderr)
|
|
);
|
|
}
|
|
|
|
// The comment is the exception: it is an entry, and the only one this run wrote.
|
|
let found = entries(&worklane);
|
|
assert_eq!(found.len(), 1, "{found:?}");
|
|
assert!(found[0].0.ends_with("_comment.md"), "was {}", found[0].0);
|
|
}
|
|
|
|
/// An edit reported as no change writes no entry: the field is already what the call
|
|
/// asked for, and a log of that would be a log of nothing happening.
|
|
#[test]
|
|
fn a_no_op_edit_writes_nothing() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
for args in [
|
|
vec!["mv", UUID, "--status", "backlog"],
|
|
vec!["chown", "alice", UUID],
|
|
vec!["set", UUID, "--tags", "alpha"],
|
|
vec!["append", UUID, "--tags", "alpha"],
|
|
] {
|
|
let out = run(&temp, &args);
|
|
assert!(
|
|
out.status.success(),
|
|
"{args:?}: {:?}",
|
|
String::from_utf8_lossy(&out.stderr)
|
|
);
|
|
assert_eq!(entries(&worklane), vec![], "{args:?} logged a change it did not make");
|
|
}
|
|
}
|
|
|
|
/// A refused move is not a move. The entry is written after the edit for exactly this.
|
|
#[test]
|
|
fn a_refused_move_writes_nothing() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "reviewing");
|
|
|
|
let backward = run(&temp, &["mv", UUID, "--status", "backlog"]);
|
|
assert_eq!(backward.status.code(), Some(1));
|
|
|
|
let skipped = run(&temp, &["mv", UUID, "--status", "backlog", "-f"]);
|
|
assert!(skipped.status.success(), "{:?}", String::from_utf8_lossy(&skipped.stderr));
|
|
|
|
// The forced one moved, so it is logged; the refused one is not.
|
|
let found = entries(&worklane);
|
|
assert_eq!(found.len(), 1, "{found:?}");
|
|
assert!(found[0].1.contains("reviewing → backlog"), "{:?}", found[0].1);
|
|
}
|
|
|
|
/// A failed edit logs nothing, whatever the failure. This ticket has no Owner field, so
|
|
/// `chown` refuses it after resolving it and before writing anything.
|
|
#[test]
|
|
fn a_failed_edit_writes_nothing() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
fs::write(
|
|
worklane.join("backlog").join(format!("{}_bare.md", UUID)),
|
|
format!("# Bare\n\n## Metadata\n\n- **ID**: {}\n- **Status**: backlog\n", UUID),
|
|
)
|
|
.unwrap();
|
|
|
|
let out = run(&temp, &["chown", "bob", UUID]);
|
|
assert_eq!(out.status.code(), Some(1));
|
|
assert_eq!(entries(&worklane), vec![], "a refused chown was logged");
|
|
}
|
|
|
|
/// One sequence, oldest first, with a comment rendered as it always was and a field
|
|
/// change as one line.
|
|
#[test]
|
|
fn show_prints_the_comments_and_the_changes_in_one_sequence() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
run(&temp, &["comment", UUID, "Picked this up."]);
|
|
run(&temp, &["mv", UUID, "--status", "committed"]);
|
|
run(&temp, &["chown", "bob", UUID]);
|
|
|
|
let out = run(&temp, &["show", UUID]);
|
|
let stdout = String::from_utf8(out.stdout).unwrap();
|
|
|
|
assert!(stdout.contains("HISTORY"), "{stdout}");
|
|
let said = stdout.find("Picked this up.").expect("the comment is missing");
|
|
let moved = stdout.find("backlog → committed").expect("the move is missing");
|
|
let owned = stdout.find("alice → bob").expect("the chown is missing");
|
|
assert!(said < moved && moved < owned, "out of order:\n{stdout}");
|
|
|
|
for line in ["status backlog → committed", "owner alice → bob"] {
|
|
assert!(stdout.contains(line), "{line:?} not in:\n{stdout}");
|
|
}
|
|
assert!(stdout.contains("From claude ("), "{stdout}");
|
|
}
|
|
|
|
/// A ticket nothing has happened to says so, where it used to say there were no comments.
|
|
#[test]
|
|
fn show_says_so_when_there_is_no_history() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
let out = run(&temp, &["show", UUID]);
|
|
assert!(
|
|
String::from_utf8(out.stdout)
|
|
.unwrap()
|
|
.contains("No history yet.")
|
|
);
|
|
}
|
|
|
|
/// A board written by an older version: the directory is adopted on the first access,
|
|
/// the entries in it are read as the comments they are, and nothing is rewritten.
|
|
#[test]
|
|
fn an_old_comments_directory_is_adopted() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
let legacy = worklane.join("comments").join(UUID);
|
|
fs::create_dir_all(&legacy).unwrap();
|
|
let name = "20260820_143012_123456.md";
|
|
let content =
|
|
"**Comment**\nSaid long ago.\n\n**Author**: Ansho Rei\n**Time**: 2026-08-20 14:30:12\n";
|
|
fs::write(legacy.join(name), content).unwrap();
|
|
|
|
let out = run(&temp, &["show", UUID]);
|
|
let stdout = String::from_utf8(out.stdout).unwrap();
|
|
assert!(stdout.contains("Said long ago."), "{stdout}");
|
|
assert!(stdout.contains("From Ansho Rei ("), "{stdout}");
|
|
|
|
assert!(!worklane.join("comments").exists(), "the old directory survived");
|
|
let moved = worklane.join("history").join(UUID).join(name);
|
|
assert_eq!(fs::read_to_string(&moved).unwrap(), content, "the entry was rewritten");
|
|
|
|
// And a new entry lands beside it, in the order it was written.
|
|
run(&temp, &["mv", UUID, "--status", "committed"]);
|
|
let found = entries(&worklane);
|
|
assert_eq!(found.len(), 2, "{found:?}");
|
|
assert_eq!(found[0].0, name);
|
|
assert!(found[1].0.ends_with("_status.md"), "was {}", found[1].0);
|
|
}
|
|
|
|
/// The flag is spelled the same on every command that writes an entry, and it overrides
|
|
/// the variable on each of them.
|
|
#[test]
|
|
fn the_actor_flag_names_the_writer_on_every_command_that_writes_one() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
run(
|
|
&temp,
|
|
&[
|
|
"campaign",
|
|
"add",
|
|
"--title",
|
|
"First release",
|
|
"--codename",
|
|
"v1",
|
|
],
|
|
);
|
|
|
|
run(&temp, &["comment", UUID, "By hand.", "--actor", "opencode"]);
|
|
run(&temp, &["mv", UUID, "--status", "committed", "--actor", "opencode"]);
|
|
run(&temp, &["chown", "bob", UUID, "--actor", "opencode"]);
|
|
run(&temp, &["set", UUID, "--tags", "beta", "--actor", "opencode"]);
|
|
run(&temp, &["append", UUID, "--tags", "gamma", "--actor", "opencode"]);
|
|
run(&temp, &["assign", "v1", UUID, "--actor", "opencode"]);
|
|
|
|
let found = entries(&worklane);
|
|
assert_eq!(found.len(), 6, "{found:?}");
|
|
for (name, content) in found {
|
|
assert!(content.contains("**Author**: opencode"), "{name}: {content:?}");
|
|
}
|
|
}
|
|
|
|
/// The lift is spelled the same on every command that writes an entry, and it raises
|
|
/// the git user over the variable on each of them.
|
|
#[test]
|
|
fn actor_from_git_names_the_git_user_on_every_command_that_writes_one() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
run(
|
|
&temp,
|
|
&[
|
|
"campaign",
|
|
"add",
|
|
"--title",
|
|
"First release",
|
|
"--codename",
|
|
"v1",
|
|
],
|
|
);
|
|
|
|
run_for_the_human(&temp, &["comment", UUID, "By hand.", "--actor-from-git"]);
|
|
run_for_the_human(&temp, &["mv", UUID, "--status", "committed", "--actor-from-git"]);
|
|
run_for_the_human(&temp, &["chown", "bob", UUID, "--actor-from-git"]);
|
|
run_for_the_human(&temp, &["set", UUID, "--tags", "beta", "--actor-from-git"]);
|
|
run_for_the_human(&temp, &["append", UUID, "--tags", "gamma", "--actor-from-git"]);
|
|
run_for_the_human(&temp, &["assign", "v1", UUID, "--actor-from-git"]);
|
|
|
|
let found = entries(&worklane);
|
|
assert_eq!(found.len(), 6, "{found:?}");
|
|
for (name, content) in found {
|
|
assert!(content.contains("**Author**: Ansho Rei"), "{name}: {content:?}");
|
|
}
|
|
}
|
|
|
|
/// Both flags answer the same question — who is the entry attributed to — so a call
|
|
/// carrying both is a usage error at parse time rather than a last-wins answer. Refused
|
|
/// before any ticket is resolved, so nothing reaches the log.
|
|
#[test]
|
|
fn actor_and_actor_from_git_are_refused_together() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
create_ticket(&worklane, "backlog");
|
|
|
|
let calls: [&[&str]; 6] = [
|
|
&[
|
|
"comment",
|
|
UUID,
|
|
"Body.",
|
|
"--actor",
|
|
"opencode",
|
|
"--actor-from-git",
|
|
],
|
|
&[
|
|
"mv",
|
|
UUID,
|
|
"--status",
|
|
"committed",
|
|
"--actor",
|
|
"opencode",
|
|
"--actor-from-git",
|
|
],
|
|
&[
|
|
"chown",
|
|
"bob",
|
|
UUID,
|
|
"--actor",
|
|
"opencode",
|
|
"--actor-from-git",
|
|
],
|
|
&[
|
|
"set",
|
|
UUID,
|
|
"--tags",
|
|
"beta",
|
|
"--actor",
|
|
"opencode",
|
|
"--actor-from-git",
|
|
],
|
|
&[
|
|
"append",
|
|
UUID,
|
|
"--tags",
|
|
"beta",
|
|
"--actor",
|
|
"opencode",
|
|
"--actor-from-git",
|
|
],
|
|
&[
|
|
"assign",
|
|
"v1",
|
|
UUID,
|
|
"--actor",
|
|
"opencode",
|
|
"--actor-from-git",
|
|
],
|
|
];
|
|
|
|
for call in calls {
|
|
let output = run(&temp, call);
|
|
assert_eq!(output.status.code(), Some(2), "{call:?} was not a usage error");
|
|
}
|
|
|
|
assert!(
|
|
!worklane.join("history").join(UUID).exists(),
|
|
"an entry was written despite the usage error"
|
|
);
|
|
}
|