(87862df) Attribute an entry to WORKLANE_ACTOR, not to the git user, and bump to 0.28.0
Every comment the CLI wrote was attributed to the git user, so a board several agents write to read as a list of things one human had done. resolve_actor is now the single source: flag, then WORKLANE_ACTOR, then get_git_user(), then unknown. comment --owner is renamed to --actor with no alias, since it names the writer of the entry and not the ticket's assignee, which is chown's. add --owner and campaign add --owner still default to the git user. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
c2ee165108
commit
a1bdb5df49
+132
-12
@@ -41,6 +41,24 @@ fn create_ticket(worklane_dir: &Path, status: &str, title: &str) -> String {
|
||||
uuid
|
||||
}
|
||||
|
||||
/// The one comment on a ticket, which every author test writes exactly one of.
|
||||
fn only_comment(worklane_dir: &Path, uuid: &str) -> String {
|
||||
let files: Vec<_> = fs::read_dir(worklane_dir.join("comments").join(uuid))
|
||||
.unwrap()
|
||||
.filter_map(|e| e.ok())
|
||||
.collect();
|
||||
assert_eq!(files.len(), 1, "expected one comment");
|
||||
fs::read_to_string(files[0].path()).unwrap()
|
||||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comment_creates_file_with_valid_ticket_uuid() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
@@ -162,32 +180,134 @@ fn comment_creates_comments_directory() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comment_uses_owner_flag_when_provided() {
|
||||
fn comment_uses_actor_flag_when_provided() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
let uuid = create_ticket(&worklane, "backlog", "Owner Test");
|
||||
let uuid = create_ticket(&worklane, "backlog", "Actor Test");
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(temp.path())
|
||||
.arg("comment")
|
||||
.args([&uuid, "Test comment with owner"])
|
||||
.arg("-o")
|
||||
.arg("TestUser")
|
||||
.args([&uuid, "Test comment with actor"])
|
||||
.args(["--actor", "TestUser"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let comments_dir = worklane.join("comments").join(&uuid);
|
||||
let files: Vec<_> = fs::read_dir(&comments_dir)
|
||||
assert!(only_comment(&worklane, &uuid).contains("**Author**: TestUser"));
|
||||
}
|
||||
|
||||
/// The flag it was, which named the ticket's assignee and not the writer of the entry.
|
||||
/// Renamed without an alias, so the old spelling is a usage error rather than something
|
||||
/// that half works.
|
||||
#[test]
|
||||
fn the_owner_flag_is_gone() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let uuid = create_ticket(&worklane, "backlog", "Gone Test");
|
||||
|
||||
for flag in ["--owner", "-o"] {
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(temp.path())
|
||||
.arg("comment")
|
||||
.args([&uuid, "A body"])
|
||||
.args([flag, "TestUser"])
|
||||
.assert()
|
||||
.failure();
|
||||
}
|
||||
|
||||
assert!(
|
||||
!worklane.join("comments").join(&uuid).exists(),
|
||||
"a comment was written despite the usage error"
|
||||
);
|
||||
}
|
||||
|
||||
/// The variable is the case an agent runs in: set once by its configuration and
|
||||
/// inherited by every call, where a flag can be forgotten on the fortieth one.
|
||||
#[test]
|
||||
fn comment_takes_the_author_from_the_actor_variable() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let uuid = create_ticket(&worklane, "backlog", "Variable Test");
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.filter_map(|e| e.ok())
|
||||
.collect();
|
||||
let content = fs::read_to_string(files[0].path()).unwrap();
|
||||
assert!(content.contains("**Author**: TestUser"));
|
||||
.current_dir(temp.path())
|
||||
.env("WORKLANE_ACTOR", "claude")
|
||||
.arg("comment")
|
||||
.args([&uuid, "Written by an agent"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
assert!(only_comment(&worklane, &uuid).contains("**Author**: claude"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comment_falls_back_to_git_user_when_owner_omitted() {
|
||||
fn the_actor_flag_overrides_the_variable() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let uuid = create_ticket(&worklane, "backlog", "Override Test");
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(temp.path())
|
||||
.env("WORKLANE_ACTOR", "claude")
|
||||
.arg("comment")
|
||||
.args([&uuid, "Written by the other one"])
|
||||
.args(["--actor", "opencode"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
assert!(only_comment(&worklane, &uuid).contains("**Author**: opencode"));
|
||||
}
|
||||
|
||||
/// An empty variable counts as unset, the convention `NO_COLOR` follows, so a wrapper
|
||||
/// script can clear an inherited one and get the git user back.
|
||||
#[test]
|
||||
fn an_empty_actor_variable_falls_through_to_the_git_user() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let uuid = create_ticket(&worklane, "backlog", "Empty Variable Test");
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(temp.path())
|
||||
.env("WORKLANE_ACTOR", "")
|
||||
.env("GIT_CONFIG_GLOBAL", git_config_naming(&temp, "Configured User"))
|
||||
.env("GIT_CONFIG_NOSYSTEM", "1")
|
||||
.arg("comment")
|
||||
.args([&uuid, "Written by a person"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
assert!(only_comment(&worklane, &uuid).contains("**Author**: Configured User"));
|
||||
}
|
||||
|
||||
/// The last resort. Reached with a git that has no `user.name`, which is why the config
|
||||
/// files are redirected: the machine running the suite has one.
|
||||
#[test]
|
||||
fn the_author_is_unknown_when_nothing_names_one() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let uuid = create_ticket(&worklane, "backlog", "Unknown Test");
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(temp.path())
|
||||
.env_remove("WORKLANE_ACTOR")
|
||||
.env("GIT_CONFIG_GLOBAL", temp.path().join("no-such-gitconfig"))
|
||||
.env("GIT_CONFIG_NOSYSTEM", "1")
|
||||
.arg("comment")
|
||||
.args([&uuid, "Written by nobody in particular"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
assert!(only_comment(&worklane, &uuid).contains("**Author**: unknown"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comment_falls_back_to_git_user_when_actor_omitted() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user