fix: enable clippy on tests (#870)
https://github.com/openai/codex/pull/855 added the clippy warning to disallow `unwrap()`, but apparently we were not verifying that tests were "clippy clean" in CI, so I ended up with a lot of local errors in VS Code. This turns on the check in CI and fixes the offenders.
This commit is contained in:
@@ -194,6 +194,7 @@ fn is_valid_sed_n_arg(arg: Option<&str>) -> bool {
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use super::*;
|
||||
|
||||
fn vec_str(args: &[&str]) -> Vec<String> {
|
||||
|
||||
@@ -179,7 +179,9 @@ fn install_network_seccomp_filter_on_current_thread() -> std::result::Result<(),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests_linux {
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
|
||||
use super::*;
|
||||
use crate::exec::ExecParams;
|
||||
use crate::exec::SandboxType;
|
||||
|
||||
@@ -163,6 +163,7 @@ impl std::ops::Deref for FunctionCallOutputPayload {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -189,6 +189,7 @@ fn is_write_patch_constrained_to_writable_paths(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -20,6 +20,7 @@ pub(crate) enum UserNotification {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -19,6 +19,7 @@ use std::time::Duration;
|
||||
|
||||
use codex_core::Codex;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::error::CodexErr;
|
||||
use codex_core::protocol::EventMsg;
|
||||
use codex_core::protocol::InputItem;
|
||||
use codex_core::protocol::Op;
|
||||
@@ -32,7 +33,7 @@ fn api_key_available() -> bool {
|
||||
/// Helper that spawns a fresh Agent and sends the mandatory *ConfigureSession*
|
||||
/// submission. The caller receives the constructed [`Agent`] plus the unique
|
||||
/// submission id used for the initialization message.
|
||||
async fn spawn_codex() -> Codex {
|
||||
async fn spawn_codex() -> Result<Codex, CodexErr> {
|
||||
assert!(
|
||||
api_key_available(),
|
||||
"OPENAI_API_KEY must be set for live tests"
|
||||
@@ -53,11 +54,9 @@ async fn spawn_codex() -> Codex {
|
||||
}
|
||||
|
||||
let config = Config::load_default_config_for_test();
|
||||
let (agent, _init_id) = Codex::spawn(config, std::sync::Arc::new(Notify::new()))
|
||||
.await
|
||||
.unwrap();
|
||||
let (agent, _init_id) = Codex::spawn(config, std::sync::Arc::new(Notify::new())).await?;
|
||||
|
||||
agent
|
||||
Ok(agent)
|
||||
}
|
||||
|
||||
/// Verifies that the agent streams incremental *AgentMessage* events **before**
|
||||
@@ -66,12 +65,13 @@ async fn spawn_codex() -> Codex {
|
||||
#[ignore]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn live_streaming_and_prev_id_reset() {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
if !api_key_available() {
|
||||
eprintln!("skipping live_streaming_and_prev_id_reset – OPENAI_API_KEY not set");
|
||||
return;
|
||||
}
|
||||
|
||||
let codex = spawn_codex().await;
|
||||
let codex = spawn_codex().await.unwrap();
|
||||
|
||||
// ---------- Task 1 ----------
|
||||
codex
|
||||
@@ -140,12 +140,13 @@ async fn live_streaming_and_prev_id_reset() {
|
||||
#[ignore]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn live_shell_function_call() {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
if !api_key_available() {
|
||||
eprintln!("skipping live_shell_function_call – OPENAI_API_KEY not set");
|
||||
return;
|
||||
}
|
||||
|
||||
let codex = spawn_codex().await;
|
||||
let codex = spawn_codex().await.unwrap();
|
||||
|
||||
const MARKER: &str = "codex_live_echo_ok";
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ fn require_api_key() -> String {
|
||||
|
||||
/// Helper that spawns the binary inside a TempDir with minimal flags. Returns (Assert, TempDir).
|
||||
fn run_live(prompt: &str) -> (assert_cmd::assert::Assert, TempDir) {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::thread;
|
||||
@@ -110,6 +111,7 @@ fn run_live(prompt: &str) -> (assert_cmd::assert::Assert, TempDir) {
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn live_create_file_hello_txt() {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
if std::env::var("OPENAI_API_KEY").is_err() {
|
||||
eprintln!("skipping live_create_file_hello_txt – OPENAI_API_KEY not set");
|
||||
return;
|
||||
|
||||
@@ -48,6 +48,8 @@ data: {{\"type\":\"response.completed\",\"response\":{{\"id\":\"{}\",\"output\":
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn keeps_previous_response_id_between_tasks() {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
|
||||
// Mock server
|
||||
let server = MockServer::start().await;
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ data: {{\"type\":\"response.completed\",\"response\":{{\"id\":\"{}\",\"output\":
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn retries_on_early_close() {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
|
||||
let server = MockServer::start().await;
|
||||
|
||||
struct SeqResponder;
|
||||
|
||||
Reference in New Issue
Block a user