Files
codex/codex-rs/guardian-context/src/reviews_tests.rs
T
felixxia-oai 0b9b5ecff3 Centralize bounded Guardian review evidence in guardian-context (#43595)
## What changed

Move prior-review rendering and developer-message construction into `codex_guardian_context`, and route async scorer evidence through a dedicated `PreviousReviews` context section.

Validate a maximum of eight review fragments and a per-fragment byte budget equivalent to 1,000 approximate tokens. Reject oversized evidence without rewriting or dropping records, and fail closed when validation fails. Preserve authorization-version filtering and the existing developer-role delivery. Keep review contents out of debug output.

## Testing

Add coverage for count and UTF-8 byte-size boundaries, preservation of accepted fragments, async-only section delivery, and omission of review contents from debug output.

GitOrigin-RevId: 05e9f53a6405f490b2424b2491a834cd90ab24f0
2026-09-07 21:20:31 +00:00

35 lines
1.1 KiB
Rust

//! Constructor boundaries preserve valid evidence and reject oversize sections.
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn previous_reviews_checks_count_and_size_without_rewriting_fragments() {
let max_bytes = TruncationPolicy::Tokens(MAX_REVIEW_FRAGMENT_TOKENS).byte_budget();
let fragment = "é".repeat(max_bytes / 2);
let fragments = vec![fragment.clone(); MAX_PREVIOUS_REVIEWS];
let reviews = PreviousReviews::try_from_fragments(fragments.clone()).unwrap();
let ResponseItem::Message { content, .. } = reviews.into_message() else {
panic!("expected a review message");
};
assert_eq!(
&content[1..],
fragments
.into_iter()
.map(|text| ContentItem::InputText { text })
.collect::<Vec<_>>()
.as_slice()
);
for invalid in [
vec!["review".to_owned(); MAX_PREVIOUS_REVIEWS + 1],
vec![format!("{fragment}a")],
] {
assert_eq!(
PreviousReviews::try_from_fragments(invalid),
Err(SectionError::EvidenceLimitExceeded {
section: "previous_reviews",
})
);
}
}