Avoid panicking when edit agent emits an empty old_text tag (#30030)
Release Notes: - Fixed a panic that could sometimes occur when the agent applies edits. Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
09d3ff9dbe
commit
c92b2e31e1
1 changed files with 42 additions and 0 deletions
|
@ -269,6 +269,12 @@ impl EditAgent {
|
||||||
let EditParserEvent::OldText(old_text_query) = edit_event? else {
|
let EditParserEvent::OldText(old_text_query) = edit_event? else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Skip edits with an empty old text.
|
||||||
|
if old_text_query.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let old_text_query = SharedString::from(old_text_query);
|
let old_text_query = SharedString::from(old_text_query);
|
||||||
|
|
||||||
let (edits_tx, edits_rx) = mpsc::unbounded();
|
let (edits_tx, edits_rx) = mpsc::unbounded();
|
||||||
|
@ -742,6 +748,42 @@ mod tests {
|
||||||
use unindent::Unindent;
|
use unindent::Unindent;
|
||||||
use util::test::{generate_marked_text, marked_text_ranges};
|
use util::test::{generate_marked_text, marked_text_ranges};
|
||||||
|
|
||||||
|
#[gpui::test(iterations = 100)]
|
||||||
|
async fn test_empty_old_text(cx: &mut TestAppContext, mut rng: StdRng) {
|
||||||
|
let agent = init_test(cx).await;
|
||||||
|
let buffer = cx.new(|cx| {
|
||||||
|
Buffer::local(
|
||||||
|
indoc! {"
|
||||||
|
abc
|
||||||
|
def
|
||||||
|
ghi
|
||||||
|
"},
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
let raw_edits = simulate_llm_output(
|
||||||
|
indoc! {"
|
||||||
|
<old_text></old_text>
|
||||||
|
<new_text>jkl</new_text>
|
||||||
|
<old_text>def</old_text>
|
||||||
|
<new_text>DEF</new_text>
|
||||||
|
"},
|
||||||
|
&mut rng,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
let (apply, _events) =
|
||||||
|
agent.apply_edit_chunks(buffer.clone(), raw_edits, &mut cx.to_async());
|
||||||
|
apply.await.unwrap();
|
||||||
|
pretty_assertions::assert_eq!(
|
||||||
|
buffer.read_with(cx, |buffer, _| buffer.snapshot().text()),
|
||||||
|
indoc! {"
|
||||||
|
abc
|
||||||
|
DEF
|
||||||
|
ghi
|
||||||
|
"}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test(iterations = 100)]
|
#[gpui::test(iterations = 100)]
|
||||||
async fn test_indentation(cx: &mut TestAppContext, mut rng: StdRng) {
|
async fn test_indentation(cx: &mut TestAppContext, mut rng: StdRng) {
|
||||||
let agent = init_test(cx).await;
|
let agent = init_test(cx).await;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue