File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -400,6 +400,14 @@ fn repair_json_candidates(candidate: &str) -> Vec<String> {
400400 candidates. push ( with_double_quotes) ;
401401 }
402402
403+ // Tab-to-space conversion: some LLMs emit tabs inside JSON (issue #28).
404+ if trimmed. contains ( '\t' ) && ( trimmed. starts_with ( '[' ) || trimmed. starts_with ( '{' ) ) {
405+ let tab_to_space = trimmed. replace ( '\t' , " " ) ;
406+ if tab_to_space != trimmed {
407+ candidates. push ( tab_to_space) ;
408+ }
409+ }
410+
403411 candidates
404412}
405413
@@ -1390,6 +1398,17 @@ let data = &input;
13901398 assert ! ( comments[ 0 ] . content. contains( "don't" ) ) ;
13911399 }
13921400
1401+ #[ test]
1402+ fn parse_json_with_tabs ( ) {
1403+ // LLM sometimes emits tabs inside JSON; repair converts tab to space (issue #28).
1404+ let input = "[{\" line\" :\t 4,\t \" issue\" :\t \" Tab-indented\" }]" ;
1405+ let file_path = PathBuf :: from ( "src/lib.rs" ) ;
1406+ let comments = parse_llm_response ( input, & file_path) . unwrap ( ) ;
1407+ assert_eq ! ( comments. len( ) , 1 ) ;
1408+ assert_eq ! ( comments[ 0 ] . line_number, 4 ) ;
1409+ assert ! ( comments[ 0 ] . content. contains( "Tab-indented" ) ) ;
1410+ }
1411+
13931412 // ── Bug: find_json_array uses mismatched brackets ──────────────────
13941413 //
13951414 // `find_json_array` uses `find('[')` (first) + `rfind(']')` (last).
Original file line number Diff line number Diff line change @@ -534,4 +534,19 @@ mod tests {
534534 + result. skipped_indices . len ( ) ;
535535 assert_eq ! ( total_accounted, 2 , "All files must be accounted for" ) ;
536536 }
537+
538+ /// #30: Adaptive compression — when total tokens exactly equals budget, strategy is Full.
539+ #[ test]
540+ fn test_adaptive_compression_exact_budget_returns_full ( ) {
541+ let diff = make_simple_diff ( "single.rs" , 200 ) ;
542+ let budget = estimate_diff_tokens ( & diff) ;
543+ let result = compress_diffs ( & [ diff] , budget, 5 ) ;
544+ assert_eq ! (
545+ result. strategy,
546+ CompressionStrategy :: Full ,
547+ "Exact budget should use Full strategy"
548+ ) ;
549+ assert_eq ! ( result. batches. len( ) , 1 ) ;
550+ assert_eq ! ( result. skipped_indices. len( ) , 0 ) ;
551+ }
537552}
You can’t perform that action at this time.
0 commit comments