(06f15bf) Stop comments overwriting each other, and bump to 0.1.1
Comment filenames were stamped to the second, so two comments added in the same second produced the same name and fs::write truncated the first. Agents post in bursts, so this was routine data loss: five comments added back to back left one file. Stamp microseconds instead, and create the file with create_new rather than fs::write, so a name that already exists is taken as a collision and the next zero-padded suffix is used instead of overwriting. The suffix sorts after the bare stem, so read_comments still orders comments the way they were written. The collision branch cannot be reached from the CLI, since two processes will not share a microsecond, so it has a unit test of its own. Patch bump: existing second-resolution comment files still read and still sort ahead of new ones written in the same second, so no migration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
54569b2c85
commit
8563218ab5
@@ -212,3 +212,41 @@ fn comment_falls_back_to_git_user_when_owner_omitted() {
|
||||
let content = fs::read_to_string(files[0].path()).unwrap();
|
||||
assert!(content.contains("**Author**"));
|
||||
}
|
||||
|
||||
/// Second-resolution filenames meant the second of two quick comments
|
||||
/// truncated the first.
|
||||
#[test]
|
||||
fn comments_added_back_to_back_are_both_kept() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
let uuid = create_ticket(&worklane, "backlog", "Rapid Fire");
|
||||
|
||||
for body in ["first comment", "second comment", "third comment"] {
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(&temp.path())
|
||||
.arg("comment")
|
||||
.args([&uuid, body])
|
||||
.assert()
|
||||
.success();
|
||||
}
|
||||
|
||||
let comments_dir = worklane.join("comments").join(&uuid);
|
||||
let files: Vec<_> = fs::read_dir(&comments_dir)
|
||||
.unwrap()
|
||||
.filter_map(|e| e.ok())
|
||||
.collect();
|
||||
assert_eq!(files.len(), 3, "a comment was overwritten");
|
||||
|
||||
// And show has to render them in the order they were added
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path()).arg("show").arg(&uuid);
|
||||
let assert = cmd.assert().success();
|
||||
let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
|
||||
|
||||
let first = stdout.find("first comment").expect("first comment missing");
|
||||
let second = stdout.find("second comment").expect("second comment missing");
|
||||
let third = stdout.find("third comment").expect("third comment missing");
|
||||
assert!(first < second && second < third, "comments out of order");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user