mirror of
https://github.com/openai/codex.git
synced 2026-04-24 22:54:54 +00:00
V3
This commit is contained in:
@@ -108,6 +108,8 @@ struct PatchInFlight {
|
||||
working_dir: PathBuf,
|
||||
}
|
||||
|
||||
const MAX_COMPLETED_UNDO_TURNS: usize = 1;
|
||||
|
||||
#[derive(Default)]
|
||||
struct PatchUndoHistory {
|
||||
trackers: HashMap<String, PatchInFlight>,
|
||||
@@ -129,6 +131,7 @@ impl PatchUndoHistory {
|
||||
let completed = self.take_active_turn()?;
|
||||
let count = completed.len();
|
||||
self.completed_turns.push(completed);
|
||||
self.prune_completed_turns();
|
||||
Some(count)
|
||||
}
|
||||
|
||||
@@ -179,6 +182,12 @@ impl PatchUndoHistory {
|
||||
}
|
||||
}
|
||||
|
||||
fn prune_completed_turns(&mut self) {
|
||||
while self.completed_turns.len() > MAX_COMPLETED_UNDO_TURNS {
|
||||
self.completed_turns.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
fn begin_undo(&mut self) -> Option<Arc<[AppliedPatchDiff]>> {
|
||||
if self.undo_in_progress.is_some() {
|
||||
return None;
|
||||
@@ -198,6 +207,7 @@ impl PatchUndoHistory {
|
||||
&& !success
|
||||
{
|
||||
self.completed_turns.push(turn);
|
||||
self.prune_completed_turns();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,29 @@ fn upgrade_event_payload_for_tests(mut payload: serde_json::Value) -> serde_json
|
||||
payload
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn patch_undo_history_is_bounded() {
|
||||
fn make_diff(label: &str) -> Arc<[AppliedPatchDiff]> {
|
||||
Arc::from(vec![AppliedPatchDiff {
|
||||
diff: format!("diff --git a/{label} b/{label}"),
|
||||
working_dir: PathBuf::from("/repo"),
|
||||
}])
|
||||
}
|
||||
|
||||
let mut history = PatchUndoHistory::new();
|
||||
history.completed_turns.push(make_diff("first"));
|
||||
history.prune_completed_turns();
|
||||
assert_eq!(history.completed_turns.len(), 1);
|
||||
|
||||
history.completed_turns.push(make_diff("second"));
|
||||
history.prune_completed_turns();
|
||||
assert_eq!(history.completed_turns.len(), 1);
|
||||
assert_eq!(
|
||||
history.completed_turns[0][0].diff,
|
||||
"diff --git a/second b/second"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn final_answer_without_newline_is_flushed_immediately() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual();
|
||||
|
||||
Reference in New Issue
Block a user