mirror of
https://github.com/openai/codex.git
synced 2026-05-18 10:12:59 +00:00
78 lines
3.0 KiB
Rust
78 lines
3.0 KiB
Rust
use std::future::Future;
|
|
|
|
use anyhow::Result;
|
|
mod analytics_server;
|
|
mod auth_fixtures;
|
|
mod config;
|
|
mod mcp_process;
|
|
mod mock_model_server;
|
|
mod models_cache;
|
|
mod responses;
|
|
mod rollout;
|
|
|
|
pub use analytics_server::start_analytics_events_server;
|
|
pub use auth_fixtures::ChatGptAuthFixture;
|
|
pub use auth_fixtures::ChatGptIdTokenClaims;
|
|
pub use auth_fixtures::encode_id_token;
|
|
pub use auth_fixtures::write_chatgpt_auth;
|
|
use codex_app_server_protocol::JSONRPCResponse;
|
|
pub use config::write_mock_responses_config_toml;
|
|
pub use config::write_mock_responses_config_toml_with_chatgpt_base_url;
|
|
pub use core_test_support::PathBufExt;
|
|
pub use core_test_support::format_with_current_shell;
|
|
pub use core_test_support::format_with_current_shell_display;
|
|
pub use core_test_support::format_with_current_shell_display_non_login;
|
|
pub use core_test_support::format_with_current_shell_non_login;
|
|
pub use core_test_support::test_absolute_path;
|
|
pub use core_test_support::test_path_buf_with_windows;
|
|
pub use core_test_support::test_tmp_path;
|
|
pub use core_test_support::test_tmp_path_buf;
|
|
pub use mcp_process::DEFAULT_CLIENT_NAME;
|
|
pub use mcp_process::DISABLE_PLUGIN_STARTUP_TASKS_ARG;
|
|
pub use mcp_process::McpProcess;
|
|
pub use mock_model_server::create_mock_responses_server_repeating_assistant;
|
|
pub use mock_model_server::create_mock_responses_server_sequence;
|
|
pub use mock_model_server::create_mock_responses_server_sequence_unchecked;
|
|
pub use models_cache::write_models_cache;
|
|
pub use models_cache::write_models_cache_with_models;
|
|
pub use responses::create_apply_patch_sse_response;
|
|
pub use responses::create_exec_command_sse_response;
|
|
pub use responses::create_final_assistant_message_sse_response;
|
|
pub use responses::create_request_permissions_sse_response;
|
|
pub use responses::create_request_user_input_sse_response;
|
|
pub use responses::create_shell_command_sse_response;
|
|
pub use rollout::create_fake_rollout;
|
|
pub use rollout::create_fake_rollout_with_source;
|
|
pub use rollout::create_fake_rollout_with_text_elements;
|
|
pub use rollout::create_fake_rollout_with_token_usage;
|
|
pub use rollout::rollout_path;
|
|
use serde::de::DeserializeOwned;
|
|
|
|
pub fn run_current_thread_test_with_stack<F>(name: &str, future: F) -> Result<()>
|
|
where
|
|
F: Future<Output = Result<()>> + Send + 'static,
|
|
{
|
|
const TEST_STACK_SIZE_BYTES: usize = 4 * 1024 * 1024;
|
|
|
|
let handle = std::thread::Builder::new()
|
|
.name(name.to_string())
|
|
.stack_size(TEST_STACK_SIZE_BYTES)
|
|
.spawn(move || -> Result<()> {
|
|
let runtime = tokio::runtime::Builder::new_current_thread()
|
|
.enable_all()
|
|
.build()?;
|
|
runtime.block_on(Box::pin(future))
|
|
})?;
|
|
|
|
match handle.join() {
|
|
Ok(result) => result,
|
|
Err(_) => Err(anyhow::anyhow!("{name} thread panicked")),
|
|
}
|
|
}
|
|
|
|
pub fn to_response<T: DeserializeOwned>(response: JSONRPCResponse) -> anyhow::Result<T> {
|
|
let value = serde_json::to_value(response.result)?;
|
|
let codex_response = serde_json::from_value(value)?;
|
|
Ok(codex_response)
|
|
}
|