Compare commits

...

2 Commits

Author SHA1 Message Date
jif-oai
d9ce960795 fix tests 2025-11-28 14:20:46 +00:00
jif-oai
56c456ca83 fix: flaky tests 2025-11-28 13:03:25 +00:00
2 changed files with 22 additions and 12 deletions

View File

@@ -61,7 +61,7 @@ pub struct McpProcess {
process: Child,
stdin: ChildStdin,
stdout: BufReader<ChildStdout>,
pending_user_messages: VecDeque<JSONRPCNotification>,
pending_notifications: VecDeque<JSONRPCNotification>,
}
impl McpProcess {
@@ -132,7 +132,7 @@ impl McpProcess {
process,
stdin,
stdout,
pending_user_messages: VecDeque::new(),
pending_notifications: VecDeque::new(),
})
}
@@ -495,6 +495,14 @@ impl McpProcess {
Ok(request_id)
}
/// Clear any queued notifications.
///
/// Tests can call this between turns when they want to guarantee that the
/// next read_* call sees only events from the new turn.
pub fn clear_pending_notifications(&mut self) {
self.pending_notifications.clear();
}
pub async fn send_response(
&mut self,
id: RequestId,
@@ -546,7 +554,7 @@ impl McpProcess {
match message {
JSONRPCMessage::Notification(notification) => {
eprintln!("notification: {notification:?}");
self.enqueue_user_message(notification);
self.enqueue_notification(notification);
}
JSONRPCMessage::Request(jsonrpc_request) => {
return jsonrpc_request.try_into().with_context(
@@ -574,7 +582,7 @@ impl McpProcess {
match message {
JSONRPCMessage::Notification(notification) => {
eprintln!("notification: {notification:?}");
self.enqueue_user_message(notification);
self.enqueue_notification(notification);
}
JSONRPCMessage::Request(_) => {
anyhow::bail!("unexpected JSONRPCMessage::Request: {message:?}");
@@ -600,7 +608,7 @@ impl McpProcess {
match message {
JSONRPCMessage::Notification(notification) => {
eprintln!("notification: {notification:?}");
self.enqueue_user_message(notification);
self.enqueue_notification(notification);
}
JSONRPCMessage::Request(_) => {
anyhow::bail!("unexpected JSONRPCMessage::Request: {message:?}");
@@ -634,7 +642,7 @@ impl McpProcess {
if notification.method == method {
return Ok(notification);
}
self.enqueue_user_message(notification);
self.enqueue_notification(notification);
}
JSONRPCMessage::Request(_) => {
anyhow::bail!("unexpected JSONRPCMessage::Request: {message:?}");
@@ -651,18 +659,16 @@ impl McpProcess {
fn take_pending_notification_by_method(&mut self, method: &str) -> Option<JSONRPCNotification> {
if let Some(pos) = self
.pending_user_messages
.pending_notifications
.iter()
.position(|notification| notification.method == method)
{
return self.pending_user_messages.remove(pos);
return self.pending_notifications.remove(pos);
}
None
}
fn enqueue_user_message(&mut self, notification: JSONRPCNotification) {
if notification.method == "codex/event/user_message" {
self.pending_user_messages.push_back(notification);
}
fn enqueue_notification(&mut self, notification: JSONRPCNotification) {
self.pending_notifications.push_back(notification);
}
}

View File

@@ -553,6 +553,10 @@ async fn turn_start_updates_sandbox_and_cwd_between_turns_v2() -> Result<()> {
)
.await??;
// Drop any leftover notifications from the first turn before we wait for
// events from the second turn.
mcp.clear_pending_notifications();
// second turn with workspace-write and second_cwd, ensure exec begins in second_cwd
let second_turn = mcp
.send_turn_start_request(TurnStartParams {