inject cleanup

This commit is contained in:
Roy Han
2026-03-12 17:29:52 -07:00
parent 145135bf40
commit d8caacebc2
3 changed files with 69 additions and 142 deletions
+69
View File
@@ -3795,6 +3795,75 @@ async fn task_finish_emits_turn_item_lifecycle_for_leftover_pending_user_input()
));
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn task_finish_emits_prompt_queued_metadata_for_injected_user_input_when_feature_enabled() {
let (mut sess, tc, rx) = make_session_and_context_with_rx().await;
Arc::get_mut(&mut sess)
.expect("session should be uniquely owned in this test")
.features
.enable(crate::features::Feature::UserMessageTypeMetadata)
.expect("feature flag should be enabled for this test");
let input = vec![UserInput::Text {
text: "hello".to_string(),
text_elements: Vec::new(),
}];
sess.spawn_task(
Arc::clone(&tc),
input,
NeverEndingTask {
kind: TaskKind::Regular,
listen_to_cancellation_token: false,
},
)
.await;
while rx.try_recv().is_ok() {}
sess.inject_response_items(vec![ResponseInputItem::Message {
role: "user".to_string(),
content: vec![ContentItem::InputText {
text: "late queued pending input".to_string(),
}],
}])
.await
.expect("inject pending input into active turn");
sess.on_task_finished(Arc::clone(&tc), None).await;
let first = tokio::time::timeout(std::time::Duration::from_secs(2), rx.recv())
.await
.expect("expected raw response item event")
.expect("channel open");
assert!(matches!(first.msg, EventMsg::RawResponseItem(_)));
let second = tokio::time::timeout(std::time::Duration::from_secs(2), rx.recv())
.await
.expect("expected item started event")
.expect("channel open");
assert!(matches!(
second.msg,
EventMsg::ItemStarted(ItemStartedEvent {
item: TurnItem::UserMessage(UserMessageItem { metadata: Some(metadata), .. }),
..
}) if metadata.user_message_type
== Some(codex_protocol::items::UserMessageType::PromptQueued)
));
let third = tokio::time::timeout(std::time::Duration::from_secs(2), rx.recv())
.await
.expect("expected item completed event")
.expect("channel open");
assert!(matches!(
third.msg,
EventMsg::ItemCompleted(ItemCompletedEvent {
item: TurnItem::UserMessage(UserMessageItem { metadata: Some(metadata), .. }),
..
}) if metadata.user_message_type
== Some(codex_protocol::items::UserMessageType::PromptQueued)
));
}
#[tokio::test]
async fn steer_input_requires_active_turn() {
let (sess, _tc, _rx) = make_session_and_context_with_rx().await;
-11
View File
@@ -88,17 +88,6 @@ impl CodexThread {
self.codex.steer_input(input, expected_turn_id).await
}
/// Use sparingly: inject response input into the active turn.
///
/// Returns the input unchanged when there is no active turn.
#[doc(hidden)]
pub async fn inject_response_items(
&self,
input: Vec<ResponseInputItem>,
) -> Result<(), Vec<ResponseInputItem>> {
self.codex.inject_response_items(input).await
}
pub async fn set_app_server_client_name(
&self,
app_server_client_name: Option<String>,