Skip to content

Commit 617d52b

Browse files
committed
fix test
1 parent 1100af4 commit 617d52b

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

codex-rs/app-server/tests/suite/v2/turn_start.rs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ use app_test_support::create_mock_chat_completions_server;
55
use app_test_support::create_mock_chat_completions_server_unchecked;
66
use app_test_support::create_shell_sse_response;
77
use app_test_support::to_response;
8+
use codex_app_server_protocol::CommandExecutionStatus;
9+
use codex_app_server_protocol::ItemStartedNotification;
810
use codex_app_server_protocol::JSONRPCNotification;
911
use codex_app_server_protocol::JSONRPCResponse;
1012
use codex_app_server_protocol::ParsedCommand;
1113
use codex_app_server_protocol::RequestId;
1214
use codex_app_server_protocol::ServerRequest;
15+
use codex_app_server_protocol::ThreadItem;
1316
use codex_app_server_protocol::ThreadStartParams;
1417
use codex_app_server_protocol::ThreadStartResponse;
1518
use codex_app_server_protocol::TurnStartParams;
@@ -18,8 +21,6 @@ use codex_app_server_protocol::TurnStartedNotification;
1821
use codex_app_server_protocol::UserInput as V2UserInput;
1922
use codex_core::protocol_config_types::ReasoningEffort;
2023
use codex_core::protocol_config_types::ReasoningSummary;
21-
use codex_protocol::protocol::Event;
22-
use codex_protocol::protocol::EventMsg;
2324
use core_test_support::skip_if_no_network;
2425
use pretty_assertions::assert_eq;
2526
use std::path::Path;
@@ -261,11 +262,11 @@ async fn turn_start_exec_approval_toggle_v2() -> Result<()> {
261262
let ServerRequest::CommandExecutionRequestApproval { request_id, params } = server_req else {
262263
panic!("expected CommandExecutionRequestApproval request");
263264
};
264-
assert_eq!(params.request.call_id, "call1");
265+
assert_eq!(params.item_id, "call1");
265266
assert_eq!(
266-
params.request.parsed_cmd,
267+
params.metadata.parsed_cmd,
267268
vec![ParsedCommand::Unknown {
268-
cmd: "python3 -c 'print(42)'".to_string()
269+
cmd: "python3 -c 'print(42)'".to_string(),
269270
}]
270271
);
271272

@@ -314,8 +315,6 @@ async fn turn_start_exec_approval_toggle_v2() -> Result<()> {
314315

315316
#[tokio::test]
316317
async fn turn_start_updates_sandbox_and_cwd_between_turns_v2() -> Result<()> {
317-
// When returning Result from a test, pass an Ok(()) to the skip macro
318-
// so the early return type matches. The no-arg form returns unit.
319318
skip_if_no_network!(Ok(()));
320319

321320
let tmp = TempDir::new()?;
@@ -424,29 +423,35 @@ async fn turn_start_updates_sandbox_and_cwd_between_turns_v2() -> Result<()> {
424423
)
425424
.await??;
426425

427-
let exec_begin_notification = timeout(
428-
DEFAULT_READ_TIMEOUT,
429-
mcp.read_stream_until_notification_message("codex/event/exec_command_begin"),
430-
)
426+
let command_exec_item = timeout(DEFAULT_READ_TIMEOUT, async {
427+
loop {
428+
let item_started_notification = mcp
429+
.read_stream_until_notification_message("item/started")
430+
.await?;
431+
let params = item_started_notification
432+
.params
433+
.clone()
434+
.expect("item/started params");
435+
let item_started: ItemStartedNotification =
436+
serde_json::from_value(params).expect("deserialize item/started notification");
437+
if matches!(item_started.item, ThreadItem::CommandExecution { .. }) {
438+
return Ok::<ThreadItem, anyhow::Error>(item_started.item);
439+
}
440+
}
441+
})
431442
.await??;
432-
let params = exec_begin_notification
433-
.params
434-
.clone()
435-
.expect("exec_command_begin params");
436-
let event: Event = serde_json::from_value(params).expect("deserialize exec begin event");
437-
let exec_begin = match event.msg {
438-
EventMsg::ExecCommandBegin(exec_begin) => exec_begin,
439-
other => panic!("expected ExecCommandBegin event, got {other:?}"),
443+
let ThreadItem::CommandExecution {
444+
cwd,
445+
command,
446+
status,
447+
..
448+
} = command_exec_item
449+
else {
450+
unreachable!("loop ensures we break on command execution items");
440451
};
441-
assert_eq!(exec_begin.cwd, second_cwd);
442-
assert_eq!(
443-
exec_begin.command,
444-
vec![
445-
"bash".to_string(),
446-
"-lc".to_string(),
447-
"echo second turn".to_string()
448-
]
449-
);
452+
assert_eq!(cwd, second_cwd);
453+
assert_eq!(command, "bash -lc echo second turn");
454+
assert_eq!(status, CommandExecutionStatus::InProgress);
450455

451456
timeout(
452457
DEFAULT_READ_TIMEOUT,

0 commit comments

Comments
 (0)