Skip to content

Commit 7af9ced

Browse files
authored
fix: create separate test_support crates to eliminate #[allow(dead_code)] (openai#1667)
Because of a quirk of how implementation tests work in Rust, we had a number of `#[allow(dead_code)]` annotations that were misleading because the functions _were_ being used, just not by all integration tests in a `tests/` folder, so when compiling the test that did not use the function, clippy would complain that it was unused. This fixes things by create a "test_support" crate under the `tests/` folder that is imported as a dev dependency for the respective crate.
1 parent 2437a8d commit 7af9ced

File tree

14 files changed

+86
-45
lines changed

14 files changed

+86
-45
lines changed

codex-rs/Cargo.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codex-rs/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ openssl-sys = { version = "*", features = ["vendored"] }
6262

6363
[dev-dependencies]
6464
assert_cmd = "2"
65+
core_test_support = { path = "tests/common" }
6566
maplit = "1.0.2"
6667
predicates = "3"
6768
pretty_assertions = "1.4.1"

codex-rs/core/tests/client.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use codex_core::protocol::EventMsg;
55
use codex_core::protocol::InputItem;
66
use codex_core::protocol::Op;
77
use codex_core::protocol::SessionConfiguredEvent;
8-
mod test_support;
8+
use core_test_support::load_default_config_for_test;
9+
use core_test_support::load_sse_fixture_with_id;
10+
use core_test_support::wait_for_event;
911
use tempfile::TempDir;
10-
use test_support::load_default_config_for_test;
11-
use test_support::load_sse_fixture_with_id;
1212
use wiremock::Mock;
1313
use wiremock::MockServer;
1414
use wiremock::ResponseTemplate;
@@ -84,14 +84,13 @@ async fn includes_session_id_and_model_headers_in_request() {
8484
.unwrap();
8585

8686
let EventMsg::SessionConfigured(SessionConfiguredEvent { session_id, .. }) =
87-
test_support::wait_for_event(&codex, |ev| matches!(ev, EventMsg::SessionConfigured(_)))
88-
.await
87+
wait_for_event(&codex, |ev| matches!(ev, EventMsg::SessionConfigured(_))).await
8988
else {
9089
unreachable!()
9190
};
9291

9392
let current_session_id = Some(session_id.to_string());
94-
test_support::wait_for_event(&codex, |ev| matches!(ev, EventMsg::TaskComplete(_))).await;
93+
wait_for_event(&codex, |ev| matches!(ev, EventMsg::TaskComplete(_))).await;
9594

9695
// get request from the server
9796
let request = &server.received_requests().await.unwrap()[0];
@@ -160,7 +159,7 @@ async fn includes_base_instructions_override_in_request() {
160159
.await
161160
.unwrap();
162161

163-
test_support::wait_for_event(&codex, |ev| matches!(ev, EventMsg::TaskComplete(_))).await;
162+
wait_for_event(&codex, |ev| matches!(ev, EventMsg::TaskComplete(_))).await;
164163

165164
let request = &server.received_requests().await.unwrap()[0];
166165
let request_body = request.body_json::<serde_json::Value>().unwrap();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "core_test_support"
3+
version = { workspace = true }
4+
edition = "2024"
5+
6+
[lib]
7+
path = "lib.rs"
8+
9+
[dependencies]
10+
codex-core = { path = "../.." }
11+
serde_json = "1"
12+
tempfile = "3"
13+
tokio = { version = "1", features = ["time"] }
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#![allow(clippy::expect_used)]
22

3-
// Helpers shared by the integration tests. These are located inside the
4-
// `tests/` tree on purpose so they never become part of the public API surface
5-
// of the `codex-core` crate.
6-
73
use tempfile::TempDir;
84

95
use codex_core::config::Config;
@@ -30,7 +26,6 @@ pub fn load_default_config_for_test(codex_home: &TempDir) -> Config {
3026
/// with only a `type` field results in an event with no `data:` section. This
3127
/// makes it trivial to extend the fixtures as OpenAI adds new event kinds or
3228
/// fields.
33-
#[allow(dead_code)]
3429
pub fn load_sse_fixture(path: impl AsRef<std::path::Path>) -> String {
3530
let events: Vec<serde_json::Value> =
3631
serde_json::from_reader(std::fs::File::open(path).expect("read fixture"))
@@ -55,7 +50,6 @@ pub fn load_sse_fixture(path: impl AsRef<std::path::Path>) -> String {
5550
/// fixture template with the supplied identifier before parsing. This lets a
5651
/// single JSON template be reused by multiple tests that each need a unique
5752
/// `response_id`.
58-
#[allow(dead_code)]
5953
pub fn load_sse_fixture_with_id(path: impl AsRef<std::path::Path>, id: &str) -> String {
6054
let raw = std::fs::read_to_string(path).expect("read fixture template");
6155
let replaced = raw.replace("__ID__", id);
@@ -77,7 +71,6 @@ pub fn load_sse_fixture_with_id(path: impl AsRef<std::path::Path>, id: &str) ->
7771
.collect()
7872
}
7973

80-
#[allow(dead_code)]
8174
pub async fn wait_for_event<F>(
8275
codex: &codex_core::Codex,
8376
mut predicate: F,

codex-rs/core/tests/live_agent.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ use codex_core::protocol::ErrorEvent;
2626
use codex_core::protocol::EventMsg;
2727
use codex_core::protocol::InputItem;
2828
use codex_core::protocol::Op;
29-
mod test_support;
29+
use core_test_support::load_default_config_for_test;
3030
use tempfile::TempDir;
31-
use test_support::load_default_config_for_test;
3231
use tokio::sync::Notify;
3332
use tokio::time::timeout;
3433

codex-rs/core/tests/stream_no_completed.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ use codex_core::exec::CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR;
99
use codex_core::protocol::EventMsg;
1010
use codex_core::protocol::InputItem;
1111
use codex_core::protocol::Op;
12-
mod test_support;
12+
use core_test_support::load_default_config_for_test;
13+
use core_test_support::load_sse_fixture;
14+
use core_test_support::load_sse_fixture_with_id;
1315
use tempfile::TempDir;
14-
use test_support::load_default_config_for_test;
15-
use test_support::load_sse_fixture;
16-
use test_support::load_sse_fixture_with_id;
1716
use tokio::time::timeout;
1817
use wiremock::Mock;
1918
use wiremock::MockServer;

codex-rs/mcp-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ uuid = { version = "1", features = ["serde", "v4"] }
3737

3838
[dev-dependencies]
3939
assert_cmd = "2"
40+
mcp_test_support = { path = "tests/common" }
4041
pretty_assertions = "1.4.1"
4142
tempfile = "3"
4243
tokio-test = "0.4"

codex-rs/mcp-server/tests/codex_tool.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
mod common;
2-
31
use std::collections::HashMap;
42
use std::env;
53
use std::path::Path;
@@ -26,11 +24,11 @@ use tempfile::TempDir;
2624
use tokio::time::timeout;
2725
use wiremock::MockServer;
2826

29-
use crate::common::McpProcess;
30-
use crate::common::create_apply_patch_sse_response;
31-
use crate::common::create_final_assistant_message_sse_response;
32-
use crate::common::create_mock_chat_completions_server;
33-
use crate::common::create_shell_sse_response;
27+
use mcp_test_support::McpProcess;
28+
use mcp_test_support::create_apply_patch_sse_response;
29+
use mcp_test_support::create_final_assistant_message_sse_response;
30+
use mcp_test_support::create_mock_chat_completions_server;
31+
use mcp_test_support::create_shell_sse_response;
3432

3533
const DEFAULT_READ_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
3634

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "mcp_test_support"
3+
version = { workspace = true }
4+
edition = "2024"
5+
6+
[lib]
7+
path = "lib.rs"
8+
9+
[dependencies]
10+
anyhow = "1"
11+
assert_cmd = "2"
12+
codex-mcp-server = { path = "../.." }
13+
mcp-types = { path = "../../../mcp-types" }
14+
pretty_assertions = "1.4.1"
15+
serde_json = "1"
16+
shlex = "1.3.0"
17+
tempfile = "3"
18+
tokio = { version = "1", features = [
19+
"io-std",
20+
"macros",
21+
"process",
22+
"rt-multi-thread",
23+
] }
24+
wiremock = "0.6"

0 commit comments

Comments
 (0)