(6f44d16) Drop the unreachable duplicate-title check in add, and bump to 0.17.2

The branch tested a path built from a uuid generated three lines above
it, so it could not fire, and its message claimed a ticket with the
title already existed. Duplicate titles are supported on purpose.

What replaces it is the write's own failure, named with the ticket and
the path the way the other writes in the tree name them, and a test that
pins the message against an unwritable backlog directory.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-08-22 23:24:18 +02:00
co-authored by Claude Opus 5
parent 139c9b012f
commit fc71f9f4a4
4 changed files with 53 additions and 7 deletions
Generated
+1 -1
View File
@@ -1503,7 +1503,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.17.1"
version = "0.17.2"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.17.1"
version = "0.17.2"
edition = "2024"
[dependencies]
+15 -5
View File
@@ -256,10 +256,6 @@ pub fn cmd_add(args: &AddArgs, start: &Path) -> Result<()> {
let filename = format!("{}_{}.md", id, slug);
let filepath = backlog_dir.join(&filename);
if filepath.exists() {
return Err(anyhow!("A ticket with this title already exists."));
}
// Joined with a single newline, so an empty value is how a caller spells a
// paragraph break and an all-blank description is no description at all.
let description = trim_blank_ends(description);
@@ -327,7 +323,21 @@ pub fn cmd_add(args: &AddArgs, start: &Path) -> Result<()> {
);
body.push('\n');
fs::write(&filepath, body)?;
// No existence check ahead of this. The name carries a uuid generated a few lines
// up, so a collision is not something that happens, and the branch that used to
// guard the write claimed the *title* was taken, which is the opposite of what the
// format allows: duplicate titles are supported and `add_allows_duplicate_titles`
// pins it. `cmd_campaign_add` deliberately does not carry it either. What is left is
// the write's own failure, named with the ticket and the path the way the other
// writes in the tree name them.
fs::write(&filepath, body).map_err(|e| {
anyhow!(
"Could not write ticket '{}' at {}: {}",
title,
filepath.display(),
e
)
})?;
println!("Created ticket: {}", filename);
Ok(())
+36
View File
@@ -561,3 +561,39 @@ fn read_only_ticket(dir: &Path) -> String {
fs::read_to_string(file.path()).unwrap()
}
fn chmod(path: &Path, mode: u32) {
use std::os::unix::fs::PermissionsExt;
let mut perms = fs::metadata(path).unwrap().permissions();
perms.set_mode(mode);
fs::set_permissions(path, perms).unwrap();
}
/// A duplicate title is not a failure, so the only thing left to refuse is the write
/// itself, and it is named with the ticket and the path rather than raised as a bare io
/// error. The branch this replaces could not fire at all: the filename carries a fresh
/// uuid, and its message claimed the title was taken.
#[test]
fn add_names_the_ticket_and_the_path_when_the_write_fails() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let backlog = worklane.join("backlog");
chmod(&backlog, 0o555);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
let assert = cmd
.current_dir(temp.path())
.args(["add", "--title", "Unwritable"])
.assert()
.failure();
let stderr = String::from_utf8(assert.get_output().stderr.clone()).unwrap();
assert!(stderr.contains("Unwritable"), "{stderr}");
assert!(stderr.contains("unwritable.md"), "{stderr}");
assert!(!stderr.contains("already exists"), "{stderr}");
chmod(&backlog, 0o755);
assert_eq!(fs::read_dir(&backlog).unwrap().count(), 0);
}