fix: change EventMsg enum so every variant takes a single struct (#925)
https://github.com/openai/codex/pull/922 did this for the `SessionConfigured` enum variant, and I think it is generally helpful to be able to work with the values as each enum variant as their own type, so this converts the remaining variants and updates all of the callsites. Added a simple unit test to verify that the JSON-serialized version of `Event` does not have any unexpected nesting.
This commit is contained in:
@@ -22,6 +22,8 @@ use std::time::Duration;
|
||||
use codex_core::Codex;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::error::CodexErr;
|
||||
use codex_core::protocol::AgentMessageEvent;
|
||||
use codex_core::protocol::ErrorEvent;
|
||||
use codex_core::protocol::EventMsg;
|
||||
use codex_core::protocol::InputItem;
|
||||
use codex_core::protocol::Op;
|
||||
@@ -92,9 +94,11 @@ async fn live_streaming_and_prev_id_reset() {
|
||||
.expect("agent closed");
|
||||
|
||||
match ev.msg {
|
||||
EventMsg::AgentMessage { .. } => saw_message_before_complete = true,
|
||||
EventMsg::AgentMessage(_) => saw_message_before_complete = true,
|
||||
EventMsg::TaskComplete => break,
|
||||
EventMsg::Error { message } => panic!("agent reported error in task1: {message}"),
|
||||
EventMsg::Error(ErrorEvent { message }) => {
|
||||
panic!("agent reported error in task1: {message}")
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@@ -122,11 +126,15 @@ async fn live_streaming_and_prev_id_reset() {
|
||||
.expect("agent closed");
|
||||
|
||||
match &ev.msg {
|
||||
EventMsg::AgentMessage { message } if message.contains("second turn succeeded") => {
|
||||
EventMsg::AgentMessage(AgentMessageEvent { message })
|
||||
if message.contains("second turn succeeded") =>
|
||||
{
|
||||
got_expected = true;
|
||||
}
|
||||
EventMsg::TaskComplete => break,
|
||||
EventMsg::Error { message } => panic!("agent reported error in task2: {message}"),
|
||||
EventMsg::Error(ErrorEvent { message }) => {
|
||||
panic!("agent reported error in task2: {message}")
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@@ -171,19 +179,28 @@ async fn live_shell_function_call() {
|
||||
.expect("agent closed");
|
||||
|
||||
match ev.msg {
|
||||
EventMsg::ExecCommandBegin { command, .. } => {
|
||||
EventMsg::ExecCommandBegin(codex_core::protocol::ExecCommandBeginEvent {
|
||||
command,
|
||||
call_id: _,
|
||||
cwd: _,
|
||||
}) => {
|
||||
assert_eq!(command, vec!["echo", MARKER]);
|
||||
saw_begin = true;
|
||||
}
|
||||
EventMsg::ExecCommandEnd {
|
||||
stdout, exit_code, ..
|
||||
} => {
|
||||
EventMsg::ExecCommandEnd(codex_core::protocol::ExecCommandEndEvent {
|
||||
stdout,
|
||||
exit_code,
|
||||
call_id: _,
|
||||
stderr: _,
|
||||
}) => {
|
||||
assert_eq!(exit_code, 0, "echo returned non‑zero exit code");
|
||||
assert!(stdout.contains(MARKER));
|
||||
saw_end_with_output = true;
|
||||
}
|
||||
EventMsg::TaskComplete => break,
|
||||
EventMsg::Error { message } => panic!("agent error during shell test: {message}"),
|
||||
EventMsg::Error(codex_core::protocol::ErrorEvent { message }) => {
|
||||
panic!("agent error during shell test: {message}")
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ use codex_core::Codex;
|
||||
use codex_core::ModelProviderInfo;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::exec::CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR;
|
||||
use codex_core::protocol::ErrorEvent;
|
||||
use codex_core::protocol::EventMsg;
|
||||
use codex_core::protocol::InputItem;
|
||||
use codex_core::protocol::Op;
|
||||
use serde_json::Value;
|
||||
@@ -127,7 +129,7 @@ async fn keeps_previous_response_id_between_tasks() {
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
if matches!(ev.msg, codex_core::protocol::EventMsg::TaskComplete) {
|
||||
if matches!(ev.msg, EventMsg::TaskComplete) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -149,8 +151,8 @@ async fn keeps_previous_response_id_between_tasks() {
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
match ev.msg {
|
||||
codex_core::protocol::EventMsg::TaskComplete => break,
|
||||
codex_core::protocol::EventMsg::Error { message } => {
|
||||
EventMsg::TaskComplete => break,
|
||||
EventMsg::Error(ErrorEvent { message }) => {
|
||||
panic!("unexpected error: {message}")
|
||||
}
|
||||
_ => (),
|
||||
|
||||
Reference in New Issue
Block a user