(ca2a124) Add --actor-from-git beside every --actor, and bump to 0.32.8
This commit is contained in:
@@ -262,6 +262,52 @@ fn the_actor_flag_overrides_the_variable() {
|
||||
assert!(only_comment(&worklane, &uuid).contains("**Author**: opencode"));
|
||||
}
|
||||
|
||||
/// The flag for acting on the person's behalf: their name is what the machine already
|
||||
/// knows, so the entry does not have to wait for the agent to know it too.
|
||||
#[test]
|
||||
fn the_actor_from_git_flag_names_the_git_user_over_the_variable() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let uuid = create_ticket(&worklane, "backlog", "From Git Test");
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(temp.path())
|
||||
.env("WORKLANE_ACTOR", "claude")
|
||||
.env("GIT_CONFIG_GLOBAL", git_config_naming(&temp, "Configured User"))
|
||||
.env("GIT_CONFIG_NOSYSTEM", "1")
|
||||
.arg("comment")
|
||||
.args([&uuid, "Written for the person"])
|
||||
.arg("--actor-from-git")
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
assert!(only_comment(&worklane, &uuid).contains("**Author**: Configured User"));
|
||||
}
|
||||
|
||||
/// The lift is not a fallback: with no git user configured there is nobody to name, and
|
||||
/// the entry reads unknown rather than quietly attributing back to the agent.
|
||||
#[test]
|
||||
fn from_git_with_no_git_user_is_unknown_even_with_the_variable() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
let uuid = create_ticket(&worklane, "backlog", "No Git User Test");
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(temp.path())
|
||||
.env("WORKLANE_ACTOR", "claude")
|
||||
.env("GIT_CONFIG_GLOBAL", temp.path().join("no-such-gitconfig"))
|
||||
.env("GIT_CONFIG_NOSYSTEM", "1")
|
||||
.arg("comment")
|
||||
.args([&uuid, "Written with nobody to name"])
|
||||
.arg("--actor-from-git")
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
assert!(only_comment(&worklane, &uuid).contains("**Author**: unknown"));
|
||||
}
|
||||
|
||||
/// 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]
|
||||
|
||||
@@ -72,6 +72,29 @@ fn run(temp: &TempDir, args: &[&str]) -> 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);
|
||||
@@ -562,3 +585,100 @@ fn the_actor_flag_names_the_writer_on_every_command_that_writes_one() {
|
||||
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, &["assign", "v1", UUID, "--actor-from-git"]);
|
||||
|
||||
let found = entries(&worklane);
|
||||
assert_eq!(found.len(), 5, "{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]; 5] = [
|
||||
&[
|
||||
"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",
|
||||
],
|
||||
&[
|
||||
"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"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user