mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex] Use expect in integration tests (#28441)
The workspace denies `clippy::expect_used` in production. Although `clippy.toml` allows `expect` in tests, Bazel Clippy compiles integration-test helper code in a way that does not receive that exemption, which encouraged verbose `unwrap_or_else(... panic!(...))` and equivalent `match`/`let else` forms. This allows `clippy::expect_used` once at each integration-test crate root (including aggregated suites and test-support libraries), then replaces manual panic-based Result and Option unwraps with `expect`/`expect_err`. Standalone `tests/*.rs` files remain their own crate roots. Intentional assertion and unexpected-variant panics remain unchanged, and the production `expect_used = "deny"` lint remains in place. The cleanup is mechanical and net-negative in line count.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#![allow(clippy::expect_used)]
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
@@ -53,7 +54,7 @@ impl RecordingState {
|
||||
let mut guard = self
|
||||
.stream_requests
|
||||
.lock()
|
||||
.unwrap_or_else(|err| panic!("mutex poisoned: {err}"));
|
||||
.expect("stream requests mutex should not be poisoned");
|
||||
guard.push(req);
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ impl RecordingState {
|
||||
let mut guard = self
|
||||
.stream_requests
|
||||
.lock()
|
||||
.unwrap_or_else(|err| panic!("mutex poisoned: {err}"));
|
||||
.expect("stream requests mutex should not be poisoned");
|
||||
std::mem::take(&mut *guard)
|
||||
}
|
||||
}
|
||||
@@ -172,14 +173,14 @@ impl FlakyTransport {
|
||||
fn attempts(&self) -> i64 {
|
||||
self.state
|
||||
.lock()
|
||||
.unwrap_or_else(|err| panic!("mutex poisoned: {err}"))
|
||||
.expect("flaky transport state mutex should not be poisoned")
|
||||
.attempts
|
||||
}
|
||||
|
||||
fn requests(&self) -> Vec<(RequestBody, HeaderMap, codex_client::RequestCompression)> {
|
||||
self.state
|
||||
.lock()
|
||||
.unwrap_or_else(|err| panic!("mutex poisoned: {err}"))
|
||||
.expect("flaky transport state mutex should not be poisoned")
|
||||
.requests
|
||||
.clone()
|
||||
}
|
||||
@@ -212,14 +213,14 @@ impl FailsOnceAuth {
|
||||
*self
|
||||
.attempts
|
||||
.lock()
|
||||
.unwrap_or_else(|err| panic!("mutex poisoned: {err}"))
|
||||
.expect("auth attempts mutex should not be poisoned")
|
||||
}
|
||||
|
||||
async fn apply_auth(&self, request: Request) -> Result<Request, AuthError> {
|
||||
let mut attempts = self
|
||||
.attempts
|
||||
.lock()
|
||||
.unwrap_or_else(|err| panic!("mutex poisoned: {err}"));
|
||||
.expect("auth attempts mutex should not be poisoned");
|
||||
*attempts += 1;
|
||||
|
||||
if *attempts == 1 {
|
||||
@@ -253,7 +254,7 @@ impl HttpTransport for FlakyTransport {
|
||||
let mut state = self
|
||||
.state
|
||||
.lock()
|
||||
.unwrap_or_else(|err| panic!("mutex poisoned: {err}"));
|
||||
.expect("flaky transport state mutex should not be poisoned");
|
||||
state.attempts += 1;
|
||||
state
|
||||
.requests
|
||||
@@ -486,10 +487,9 @@ async fn streaming_client_does_not_retry_auth_build_error() -> Result<()> {
|
||||
/*turn_state*/ None,
|
||||
)
|
||||
.await;
|
||||
let err = match result {
|
||||
Ok(_) => panic!("auth build errors should fail without retry"),
|
||||
Err(err) => err,
|
||||
};
|
||||
let err = result
|
||||
.err()
|
||||
.expect("auth build errors should fail without retry");
|
||||
|
||||
assert!(matches!(
|
||||
err,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#![allow(clippy::expect_used)]
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
use std::time::Duration;
|
||||
@@ -34,24 +35,22 @@ where
|
||||
Handler: FnOnce(RealtimeWsStream) -> Fut + Send + 'static,
|
||||
Fut: Future<Output = ()> + Send + 'static,
|
||||
{
|
||||
let listener = match TcpListener::bind("127.0.0.1:0").await {
|
||||
Ok(listener) => listener,
|
||||
Err(err) => panic!("failed to bind test websocket listener: {err}"),
|
||||
};
|
||||
let addr = match listener.local_addr() {
|
||||
Ok(addr) => addr.to_string(),
|
||||
Err(err) => panic!("failed to read local websocket listener address: {err}"),
|
||||
};
|
||||
let listener = TcpListener::bind("127.0.0.1:0")
|
||||
.await
|
||||
.expect("test websocket listener should bind");
|
||||
let addr = listener
|
||||
.local_addr()
|
||||
.expect("test websocket listener should have a local address")
|
||||
.to_string();
|
||||
|
||||
let server = tokio::spawn(async move {
|
||||
let (stream, _) = match listener.accept().await {
|
||||
Ok(stream) => stream,
|
||||
Err(err) => panic!("failed to accept test websocket connection: {err}"),
|
||||
};
|
||||
let ws = match accept_async(stream).await {
|
||||
Ok(ws) => ws,
|
||||
Err(err) => panic!("failed to complete websocket handshake: {err}"),
|
||||
};
|
||||
let (stream, _) = listener
|
||||
.accept()
|
||||
.await
|
||||
.expect("test websocket connection should be accepted");
|
||||
let ws = accept_async(stream)
|
||||
.await
|
||||
.expect("test websocket handshake should complete");
|
||||
handler(ws).await;
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#![allow(clippy::expect_used)]
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -78,7 +79,7 @@ fn build_responses_body(events: Vec<Value>) -> String {
|
||||
let kind = e
|
||||
.get("type")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or_else(|| panic!("fixture event missing type in SSE fixture: {e}"));
|
||||
.expect("SSE fixture event should have a type");
|
||||
if e.as_object().map(|o| o.len() == 1).unwrap_or(false) {
|
||||
body.push_str(&format!("event: {kind}\n\n"));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user