mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Consolidate Rust unit tests under dedicated test modules (#56247)
## What changed Move inline crate tests into `lib_tests.rs` and nest related test suites under each crate's `tests` module. Update imports, subprocess test filters, logging targets, and snapshot names to match the new module paths. Keep test helpers accessible where needed and preserve the schema writer's exact test name used by release tooling. GitOrigin-RevId: de55eaae66dce4941abb33dd0b2f170093daa8f9
This commit is contained in:
committed by
copyberry
parent
22db5847c8
commit
c227654800
@@ -1574,87 +1574,5 @@ fn analytics_rpc_transport(transport: &AppServerTransport) -> AppServerRpcTransp
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "stderr_logging_tests.rs"]
|
||||
mod stderr_logging_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::LogFormat;
|
||||
use super::ShutdownAction;
|
||||
use super::ShutdownSignal;
|
||||
use super::ShutdownState;
|
||||
#[cfg(debug_assertions)]
|
||||
use super::loader_overrides_with_test_user_config_file;
|
||||
use super::turn_admission::TurnAdmission;
|
||||
#[cfg(debug_assertions)]
|
||||
use codex_config::LoaderOverrides;
|
||||
#[cfg(debug_assertions)]
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn shutdown_waits_for_admitted_requests_but_force_remains_available() {
|
||||
let admission = TurnAdmission::default();
|
||||
let active = admission.subscribe_active();
|
||||
let in_flight = admission.admit().expect("request admitted");
|
||||
let mut shutdown = ShutdownState::default();
|
||||
let connection_count = 1;
|
||||
let running_turn_count = 0;
|
||||
shutdown.on_signal(
|
||||
ShutdownSignal::Forceable,
|
||||
connection_count,
|
||||
running_turn_count,
|
||||
&admission,
|
||||
);
|
||||
assert!(matches!(
|
||||
shutdown.update(running_turn_count, *active.borrow(), connection_count),
|
||||
ShutdownAction::Noop
|
||||
));
|
||||
shutdown.on_signal(
|
||||
ShutdownSignal::Forceable,
|
||||
connection_count,
|
||||
running_turn_count,
|
||||
&admission,
|
||||
);
|
||||
assert!(shutdown.forced());
|
||||
assert!(matches!(
|
||||
shutdown.update(running_turn_count, *active.borrow(), connection_count),
|
||||
ShutdownAction::Finish
|
||||
));
|
||||
drop(in_flight);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn log_format_from_env_value_matches_json_values_case_insensitively() {
|
||||
assert_eq!(LogFormat::from_env_value(Some("json")), LogFormat::Json);
|
||||
assert_eq!(LogFormat::from_env_value(Some("JSON")), LogFormat::Json);
|
||||
assert_eq!(LogFormat::from_env_value(Some(" Json ")), LogFormat::Json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn log_format_from_env_value_defaults_for_non_json_values() {
|
||||
assert_eq!(
|
||||
LogFormat::from_env_value(/*value*/ None),
|
||||
LogFormat::Default
|
||||
);
|
||||
assert_eq!(LogFormat::from_env_value(Some("")), LogFormat::Default);
|
||||
assert_eq!(LogFormat::from_env_value(Some("text")), LogFormat::Default);
|
||||
assert_eq!(LogFormat::from_env_value(Some("jsonl")), LogFormat::Default);
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
#[test]
|
||||
fn debug_test_user_config_file_overrides_loader_path() {
|
||||
let path = std::env::temp_dir().join("codex-app-server-test-config.toml");
|
||||
let loader_overrides = loader_overrides_with_test_user_config_file(
|
||||
LoaderOverrides::default(),
|
||||
Some(path.clone()),
|
||||
)
|
||||
.expect("test config path should be valid");
|
||||
|
||||
assert_eq!(
|
||||
loader_overrides.user_config_path,
|
||||
Some(AbsolutePathBuf::from_absolute_path(path).expect("absolute test path"))
|
||||
);
|
||||
}
|
||||
}
|
||||
#[path = "lib_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#![cfg(test)]
|
||||
|
||||
//! Unit tests for the crate and its related test suites.
|
||||
|
||||
use super::LogFormat;
|
||||
use super::ShutdownAction;
|
||||
use super::ShutdownSignal;
|
||||
use super::ShutdownState;
|
||||
#[cfg(debug_assertions)]
|
||||
use super::loader_overrides_with_test_user_config_file;
|
||||
use super::turn_admission::TurnAdmission;
|
||||
#[cfg(debug_assertions)]
|
||||
use codex_config::LoaderOverrides;
|
||||
#[cfg(debug_assertions)]
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn shutdown_waits_for_admitted_requests_but_force_remains_available() {
|
||||
let admission = TurnAdmission::default();
|
||||
let active = admission.subscribe_active();
|
||||
let in_flight = admission.admit().expect("request admitted");
|
||||
let mut shutdown = ShutdownState::default();
|
||||
let connection_count = 1;
|
||||
let running_turn_count = 0;
|
||||
shutdown.on_signal(
|
||||
ShutdownSignal::Forceable,
|
||||
connection_count,
|
||||
running_turn_count,
|
||||
&admission,
|
||||
);
|
||||
assert!(matches!(
|
||||
shutdown.update(running_turn_count, *active.borrow(), connection_count),
|
||||
ShutdownAction::Noop
|
||||
));
|
||||
shutdown.on_signal(
|
||||
ShutdownSignal::Forceable,
|
||||
connection_count,
|
||||
running_turn_count,
|
||||
&admission,
|
||||
);
|
||||
assert!(shutdown.forced());
|
||||
assert!(matches!(
|
||||
shutdown.update(running_turn_count, *active.borrow(), connection_count),
|
||||
ShutdownAction::Finish
|
||||
));
|
||||
drop(in_flight);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn log_format_from_env_value_matches_json_values_case_insensitively() {
|
||||
assert_eq!(LogFormat::from_env_value(Some("json")), LogFormat::Json);
|
||||
assert_eq!(LogFormat::from_env_value(Some("JSON")), LogFormat::Json);
|
||||
assert_eq!(LogFormat::from_env_value(Some(" Json ")), LogFormat::Json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn log_format_from_env_value_defaults_for_non_json_values() {
|
||||
assert_eq!(
|
||||
LogFormat::from_env_value(/*value*/ None),
|
||||
LogFormat::Default
|
||||
);
|
||||
assert_eq!(LogFormat::from_env_value(Some("")), LogFormat::Default);
|
||||
assert_eq!(LogFormat::from_env_value(Some("text")), LogFormat::Default);
|
||||
assert_eq!(LogFormat::from_env_value(Some("jsonl")), LogFormat::Default);
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
#[test]
|
||||
fn debug_test_user_config_file_overrides_loader_path() {
|
||||
let path = std::env::temp_dir().join("codex-app-server-test-config.toml");
|
||||
let loader_overrides =
|
||||
loader_overrides_with_test_user_config_file(LoaderOverrides::default(), Some(path.clone()))
|
||||
.expect("test config path should be valid");
|
||||
|
||||
assert_eq!(
|
||||
loader_overrides.user_config_path,
|
||||
Some(AbsolutePathBuf::from_absolute_path(path).expect("absolute test path"))
|
||||
);
|
||||
}
|
||||
|
||||
#[path = "stderr_logging_tests.rs"]
|
||||
mod stderr_logging_tests;
|
||||
@@ -36,7 +36,7 @@ async fn sqlite_transaction_completes_with_undrained_stderr(format: LogFormat) -
|
||||
let fmt = tracing_subscriber::fmt::layer()
|
||||
.with_writer(Mutex::new(writer))
|
||||
.with_span_events(stderr_span_events());
|
||||
let filter = EnvFilter::new("off,codex_app_server::stderr_logging_tests=info");
|
||||
let filter = EnvFilter::new("off,codex_app_server::tests::stderr_logging_tests=info");
|
||||
let fmt: StderrLogLayer = match format {
|
||||
LogFormat::Json => fmt.json().with_filter(filter).boxed(),
|
||||
LogFormat::Default => fmt.with_filter(filter).boxed(),
|
||||
|
||||
Reference in New Issue
Block a user