Skip to content

Commit 9f2e265

Browse files
authored
fix: address PR37 review feedback — zero line counts and verification enum YAML (#41)
- diff_parser: add regression assertions for @@ -0,0 +1,N @@ and @@ -N,N +0,0 @@ so zero line counts are preserved (Bugbot/CRITICAL). Add TDD test test_parse_new_file_multi_line_zero_old_lines. Main already uses parse_optional_capture without a zero filter; tests would fail if re-introduced. - config: add tests that deserialize verification_model_role and verification_consensus_mode from YAML (flat keys into config.verification). Assert weak/majority and primary/all; use config.verification.* after VerificationConfig flatten refactor. Made-with: Cursor
1 parent e39c31a commit 9f2e265

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

src/config.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,6 +2113,40 @@ temperature: 0.3
21132113
);
21142114
}
21152115

2116+
#[test]
2117+
fn test_config_deserialize_verification_enum_fields_from_yaml() {
2118+
// Regression (PR37): flattened verification_model_role / verification_consensus_mode
2119+
// must deserialize from YAML. serde_yaml can have issues with enums in flattened
2120+
// structs; this test locks in that config.verification (flatten) works.
2121+
let yaml = r#"
2122+
model: claude-sonnet-4-6
2123+
verification_model_role: weak
2124+
verification_consensus_mode: majority
2125+
"#;
2126+
let config: Config = serde_yaml::from_str(yaml).unwrap();
2127+
assert_eq!(config.verification.model_role, ModelRole::Weak);
2128+
assert_eq!(
2129+
config.verification.consensus_mode,
2130+
VerificationConsensusMode::Majority
2131+
);
2132+
}
2133+
2134+
#[test]
2135+
fn test_config_deserialize_verification_enum_primary_and_all() {
2136+
// TDD: prove enum variants deserialize from YAML (primary, all).
2137+
let yaml = r#"
2138+
model: claude-sonnet-4-6
2139+
verification_model_role: primary
2140+
verification_consensus_mode: all
2141+
"#;
2142+
let config: Config = serde_yaml::from_str(yaml).unwrap();
2143+
assert_eq!(config.verification.model_role, ModelRole::Primary);
2144+
assert_eq!(
2145+
config.verification.consensus_mode,
2146+
VerificationConsensusMode::All
2147+
);
2148+
}
2149+
21162150
#[test]
21172151
fn test_default_frontier_role_models_match_requested_pair() {
21182152
let config = Config::default();

src/core/diff_parser.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,10 @@ index 83db48f..0000000\n\
556556
assert_eq!(diffs.len(), 1);
557557
assert!(diffs[0].is_deleted);
558558
assert!(!diffs[0].is_new);
559-
assert_eq!(diffs[0].hunks[0].old_lines, 1);
560-
assert_eq!(diffs[0].hunks[0].new_lines, 0);
559+
// Regression (PR37): @@ -1,1 +0,0 @@ must preserve old_lines=1, new_lines=0
560+
let hunk = &diffs[0].hunks[0];
561+
assert_eq!(hunk.old_lines, 1, "deleted-file hunk must have old_lines=1");
562+
assert_eq!(hunk.new_lines, 0, "deleted-file hunk must have new_lines=0");
561563
}
562564

563565
#[test]
@@ -575,8 +577,33 @@ index 0000000..f735c20\n\
575577
assert_eq!(diffs.len(), 1);
576578
assert!(diffs[0].is_new);
577579
assert!(!diffs[0].is_deleted);
578-
assert_eq!(diffs[0].hunks[0].old_lines, 0);
579-
assert_eq!(diffs[0].hunks[0].new_lines, 1);
580+
// Regression (PR37): @@ -0,0 +1,1 @@ must preserve old_lines=0, new_lines=1
581+
let hunk = &diffs[0].hunks[0];
582+
assert_eq!(hunk.old_lines, 0, "new-file hunk must have old_lines=0");
583+
assert_eq!(hunk.new_lines, 1, "new-file hunk must have new_lines=1");
584+
}
585+
586+
#[test]
587+
fn test_parse_new_file_multi_line_zero_old_lines() {
588+
// TDD: @@ -0,0 +1,5 @@ must yield old_lines=0, new_lines=5
589+
let diff_text = "\
590+
diff --git a/new.txt b/new.txt\n\
591+
new file mode 100644\n\
592+
index 0000000..abc1234\n\
593+
--- /dev/null\n\
594+
+++ b/new.txt\n\
595+
@@ -0,0 +1,5 @@\n\
596+
+line1\n\
597+
+line2\n\
598+
+line3\n\
599+
+line4\n\
600+
+line5\n";
601+
let diffs = DiffParser::parse_unified_diff(diff_text).unwrap();
602+
assert_eq!(diffs.len(), 1);
603+
let hunk = &diffs[0].hunks[0];
604+
assert_eq!(hunk.old_lines, 0, "zero old_lines must be preserved");
605+
assert_eq!(hunk.new_lines, 5, "new_lines=5 must be preserved");
606+
assert_eq!(hunk.changes.len(), 5, "all 5 added lines must be parsed");
580607
}
581608

582609
#[test]

0 commit comments

Comments
 (0)