Files
codex/codex-rs/ext/guardian-reviewer/src/conversation_tests.rs
T
felixxia-oai 5fff6378d6 Share Guardian image deduplication and checkpoint restoration (#54278)
## What changed

- Add `ComposedContext::retain_new_images` and use it in Guardian review sessions and the async scorer. Compare host-prepared image references against admitted history, ignoring image detail, and skip scanning history when no images need checking.
- Restore `ConversationState` directly from a checkpoint, retaining committed history for rollback or transferring it with `take_history` for ephemeral forks.

## Testing

Extend tests for prepared-image matching across differing detail levels, image-free continuations that avoid scanning history, and checkpoint restoration and history transfer.

GitOrigin-RevId: bafeb6de9babc721182be43d0eb1a653955a0ebb
2026-10-15 12:42:15 +00:00

63 lines
2.0 KiB
Rust

//! Checks that forks use committed history and progress while the next review runs.
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn fork_keeps_committed_history_and_cursor_while_next_review_is_uncommitted() {
let mut state = ConversationState::default();
let first = TranscriptCursor {
parent_history_version: 1,
transcript_entry_count: 2,
};
state.complete_review(first);
state.commit_snapshot(vec!["first review"]);
let second = TranscriptCursor {
transcript_entry_count: 4,
..first
};
// A failed review can retain new input without completing or replacing the
// last successful checkpoint used by concurrent forks.
state.admit_transcript(second);
let fork = ConversationState::from(state.snapshot().unwrap().clone());
assert_eq!(
(
state.cursor(),
state.completed_review_count(),
fork.snapshot().unwrap().history(),
fork.cursor(),
fork.completed_review_count(),
),
(Some(second), 1, &vec!["first review"], Some(first), 1),
);
state.complete_review(second);
let fork = ConversationState::from(state.snapshot().unwrap().clone());
assert_eq!(
(
fork.snapshot().unwrap().history(),
fork.cursor(),
fork.completed_review_count(),
),
(&vec!["first review"], Some(first), 1),
);
state.commit_snapshot(vec!["first review", "second review"]);
let mut fork = ConversationState::from(state.snapshot().unwrap().clone());
let history = fork.take_history();
assert_eq!(
(history, fork.cursor(), fork.completed_review_count()),
(Some(vec!["first review", "second review"]), Some(second), 2),
);
assert!(fork.snapshot().is_none());
assert_eq!(
(
state.take_history(),
state.cursor(),
state.completed_review_count(),
),
(Some(vec!["first review", "second review"]), Some(second), 2),
);
assert!(state.snapshot().is_none());
}