diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs index 9ba42b4b1d..1b8e4c959d 100644 --- a/codex-rs/core/src/client.rs +++ b/codex-rs/core/src/client.rs @@ -421,9 +421,17 @@ mod tests { out } + /// Verifies that the SSE adapter emits the expected [`ResponseEvent`] for + /// a variety of `type` values from the Responses API. The test is written + /// table-driven style to keep additions for new event kinds trivial. + /// + /// Each `Case` supplies an input event, a predicate that must match the + /// *first* `ResponseEvent` produced by the adapter, and the total number + /// of events expected after appending a synthetic `response.completed` + /// marker that terminates the stream. #[tokio::test] async fn table_driven_event_kinds() { - struct Case { + struct TestCase { name: &'static str, event: serde_json::Value, expect_first: fn(&ResponseEvent) -> bool, @@ -458,13 +466,13 @@ mod tests { }); let cases = vec![ - Case { + TestCase { name: "created", event: json!({"type": "response.created", "response": {}}), expect_first: is_created, expected_len: 2, }, - Case { + TestCase { name: "output_item.done", event: json!({ "type": "response.output_item.done", @@ -479,7 +487,7 @@ mod tests { expect_first: is_output, expected_len: 2, }, - Case { + TestCase { name: "unknown", event: json!({"type": "response.new_tool_event"}), expect_first: is_completed, diff --git a/codex-rs/core/tests/test_support.rs b/codex-rs/core/tests/test_support.rs index 2b9dd0742c..5dbe637101 100644 --- a/codex-rs/core/tests/test_support.rs +++ b/codex-rs/core/tests/test_support.rs @@ -30,7 +30,6 @@ pub fn load_default_config_for_test(codex_home: &TempDir) -> Config { /// with only a `type` field results in an event with no `data:` section. This /// makes it trivial to extend the fixtures as OpenAI adds new event kinds or /// fields. -#[allow(dead_code)] pub fn load_sse_fixture(path: impl AsRef) -> String { let events: Vec = serde_json::from_reader(std::fs::File::open(path).expect("read fixture")) @@ -51,10 +50,10 @@ pub fn load_sse_fixture(path: impl AsRef) -> String { .collect() } -/// Like [`load_sse_fixture`] but substitutes the placeholder `__ID__` with the -/// provided identifier before parsing. Useful when the test needs unique -/// `response_id` values. -#[allow(dead_code)] +/// Same as [`load_sse_fixture`], but replaces the placeholder `__ID__` in the +/// fixture template with the supplied identifier before parsing. This lets a +/// single JSON template be reused by multiple tests that each need a unique +/// `response_id`. pub fn load_sse_fixture_with_id(path: impl AsRef, id: &str) -> String { let raw = std::fs::read_to_string(path).expect("read fixture template"); let replaced = raw.replace("__ID__", id);