Make the Guardian deadline cancellation helper crate-private (#45493)

## What changed

Restrict `run_before_review_deadline_with_cancel` and its re-export to `codex-guardian-reviewer`. Move its timeout, abort, and successful-completion tests from core into the reviewer's deadline module, and remove the standalone `run_before_review_deadline` tests from core.

GitOrigin-RevId: dd9f1ed571a40a4bd66b08c88f3ee2be071f4870
This commit is contained in:
felixxia-oai authored and copyberry committed 2026-09-14 18:57:52 +00:00
1 parent 43da136850
commit d3812ddbb3
5 files changed
+75 -105

No files matched your search

@@ -100,8 +100,6 @@ use super::prompt::build_guardian_prompt_items_with_parent_turn;
use super::review::guardian_review_session_config;
pub(crate) use super::reviewer_config::build_guardian_review_session_config;
use codex_guardian_reviewer::run_before_review_deadline;
#[cfg(test)]
use codex_guardian_reviewer::run_before_review_deadline_with_cancel;
use codex_guardian_reviewer::wait_for_guardian_review;
const GUARDIAN_MAX_IMAGE_ITEM_TOKENS: i64 = 10_000;
@@ -775,107 +775,6 @@ async fn guardian_review_session_config_preserves_explicit_empty_catalog_templat
);
}
#[tokio::test(flavor = "current_thread")]
async fn run_before_review_deadline_times_out_before_future_completes() {
let outcome = run_before_review_deadline(
tokio::time::Instant::now() + Duration::from_millis(10),
/*external_cancel*/ None,
async {
tokio::time::sleep(Duration::from_millis(50)).await;
},
)
.await;
assert!(matches!(
outcome,
Err(GuardianReviewSessionOutcome::TimedOut)
));
}
#[tokio::test(flavor = "current_thread")]
async fn run_before_review_deadline_aborts_when_cancelled() {
let cancel_token = CancellationToken::new();
let canceller = cancel_token.clone();
drop(tokio::spawn(async move {
tokio::time::sleep(Duration::from_millis(10)).await;
canceller.cancel();
}));
let outcome = run_before_review_deadline(
tokio::time::Instant::now() + Duration::from_secs(1),
Some(&cancel_token),
std::future::pending::<()>(),
)
.await;
assert!(matches!(
outcome,
Err(GuardianReviewSessionOutcome::Aborted)
));
}
#[tokio::test(flavor = "current_thread")]
async fn run_before_review_deadline_with_cancel_cancels_token_on_timeout() {
let cancel_token = CancellationToken::new();
let outcome = run_before_review_deadline_with_cancel(
tokio::time::Instant::now() + Duration::from_millis(10),
/*external_cancel*/ None,
&cancel_token,
async {
tokio::time::sleep(Duration::from_millis(50)).await;
},
)
.await;
assert!(matches!(
outcome,
Err(GuardianReviewSessionOutcome::TimedOut)
));
assert!(cancel_token.is_cancelled());
}
#[tokio::test(flavor = "current_thread")]
async fn run_before_review_deadline_with_cancel_cancels_token_on_abort() {
let external_cancel = CancellationToken::new();
let external_canceller = external_cancel.clone();
let cancel_token = CancellationToken::new();
drop(tokio::spawn(async move {
tokio::time::sleep(Duration::from_millis(10)).await;
external_canceller.cancel();
}));
let outcome = run_before_review_deadline_with_cancel(
tokio::time::Instant::now() + Duration::from_secs(1),
Some(&external_cancel),
&cancel_token,
std::future::pending::<()>(),
)
.await;
assert!(matches!(
outcome,
Err(GuardianReviewSessionOutcome::Aborted)
));
assert!(cancel_token.is_cancelled());
}
#[tokio::test(flavor = "current_thread")]
async fn run_before_review_deadline_with_cancel_preserves_token_on_success() {
let cancel_token = CancellationToken::new();
let outcome = run_before_review_deadline_with_cancel(
tokio::time::Instant::now() + Duration::from_secs(1),
/*external_cancel*/ None,
&cancel_token,
async { 42usize },
)
.await;
assert_eq!(outcome.unwrap(), 42);
assert!(!cancel_token.is_cancelled());
}
#[test]
fn had_prior_review_context_tracks_prompt_mode() {
assert!(!had_prior_review_context(&GuardianPromptMode::Full));