From 05afe95539e084f570c7828fe6a1c87cefb1fbe8 Mon Sep 17 00:00:00 2001 From: Oleksiy Syvokon Date: Wed, 28 May 2025 22:31:54 +0300 Subject: [PATCH] agent: Fix bug in creating empty files (#31626) Release Notes: - NA --- .../src/edit_agent/create_file_parser.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/assistant_tools/src/edit_agent/create_file_parser.rs b/crates/assistant_tools/src/edit_agent/create_file_parser.rs index 4f416a1fc6..07c8fac7b9 100644 --- a/crates/assistant_tools/src/edit_agent/create_file_parser.rs +++ b/crates/assistant_tools/src/edit_agent/create_file_parser.rs @@ -4,7 +4,7 @@ use std::cell::LazyCell; use util::debug_panic; const START_MARKER: LazyCell = LazyCell::new(|| Regex::new(r"\n?```\S*\n").unwrap()); -const END_MARKER: LazyCell = LazyCell::new(|| Regex::new(r"\n```\s*$").unwrap()); +const END_MARKER: LazyCell = LazyCell::new(|| Regex::new(r"(^|\n)```\s*$").unwrap()); #[derive(Debug)] pub enum CreateFileParserEvent { @@ -184,6 +184,22 @@ mod tests { ); } + #[gpui::test(iterations = 10)] + fn test_empty_file(mut rng: StdRng) { + let mut parser = CreateFileParser::new(); + assert_eq!( + parse_random_chunks( + indoc! {" + ``` + ``` + "}, + &mut parser, + &mut rng + ), + "".to_string() + ); + } + fn parse_random_chunks(input: &str, parser: &mut CreateFileParser, rng: &mut StdRng) -> String { let chunk_count = rng.gen_range(1..=cmp::min(input.len(), 50)); let mut chunk_indices = (0..input.len()).choose_multiple(rng, chunk_count);