fix: prefer valid position for comment line fallback

This commit is contained in:
2026-04-08 23:37:20 +08:00
parent d00e6bcb2c
commit eb7dd1125d
2 changed files with 69 additions and 1 deletions
+53
View File
@@ -249,3 +249,56 @@ fn normalize_does_not_merge_unrelated_comments_on_same_file() {
assert_eq!(doc.threads[1].root_comment.id, 11);
assert_eq!(doc.threads[1].replies.len(), 0);
}
#[test]
fn normalize_uses_non_zero_position_when_line_is_missing() {
let bundle = PullBundleDto {
pull: PullDto {
number: 101,
title: "T".into(),
state: "open".into(),
body: None,
user: UserDto {
login: "alice".into(),
},
base: PullBranchDto {
ref_name: "main".into(),
},
head: PullBranchDto {
ref_name: "feature/z".into(),
},
created_at: "2026-04-08T10:00:00Z".into(),
updated_at: "2026-04-08T10:00:00Z".into(),
merged_at: None,
additions: None,
deletions: None,
changed_files: None,
},
reviews: vec![],
comments: vec![ReviewCommentDto {
id: 1001,
body: "position based comment".into(),
created_at: "2026-04-08T12:00:00Z".into(),
updated_at: None,
user: UserDto {
login: "bob".into(),
},
path: Some("src/main.rs".into()),
line: None,
pull_request_review_id: Some(1),
in_reply_to: None,
original_position: Some(42),
position: Some(41),
commit_id: Some("abc123".into()),
original_commit_id: Some("abc123".into()),
diff_hunk: None,
}],
commits: vec![],
files: vec![],
};
let doc = normalize_bundle("org/repo", bundle);
assert_eq!(doc.threads.len(), 1);
assert_eq!(doc.threads[0].root_comment.path.as_deref(), Some("src/main.rs"));
assert_eq!(doc.threads[0].root_comment.line, Some(41));
}