mirror of
https://github.com/openai/codex.git
synced 2026-09-11 20:36:49 +00:00
use anyhow instead of expected
This commit is contained in:
@@ -117,16 +117,17 @@ pub(crate) async fn wait_for_analytics_payload(
|
||||
}
|
||||
})
|
||||
.await?;
|
||||
Ok(serde_json::from_slice(&body).expect("analytics payload"))
|
||||
serde_json::from_slice(&body).map_err(|err| anyhow::anyhow!("invalid analytics payload: {err}"))
|
||||
}
|
||||
|
||||
pub(crate) fn thread_initialized_event(payload: &Value) -> &Value {
|
||||
payload["events"]
|
||||
pub(crate) fn thread_initialized_event(payload: &Value) -> Result<&Value> {
|
||||
let events = payload["events"]
|
||||
.as_array()
|
||||
.expect("events array")
|
||||
.ok_or_else(|| anyhow::anyhow!("analytics payload missing events array"))?;
|
||||
events
|
||||
.iter()
|
||||
.find(|event| event["event_type"] == "codex_thread_initialized")
|
||||
.expect("codex_thread_initialized event should be present")
|
||||
.ok_or_else(|| anyhow::anyhow!("codex_thread_initialized event should be present"))
|
||||
}
|
||||
|
||||
pub(crate) fn assert_basic_thread_initialized_event(
|
||||
|
||||
@@ -216,7 +216,7 @@ async fn thread_fork_tracks_thread_initialized_analytics() -> Result<()> {
|
||||
let ThreadForkResponse { thread, .. } = to_response::<ThreadForkResponse>(fork_resp)?;
|
||||
|
||||
let payload = wait_for_analytics_payload(&server, DEFAULT_READ_TIMEOUT).await?;
|
||||
let event = thread_initialized_event(&payload);
|
||||
let event = thread_initialized_event(&payload)?;
|
||||
assert_basic_thread_initialized_event(event, &thread.id, "forked");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ async fn thread_resume_tracks_thread_initialized_analytics() -> Result<()> {
|
||||
let ThreadResumeResponse { thread, .. } = to_response::<ThreadResumeResponse>(resume_resp)?;
|
||||
|
||||
let payload = wait_for_analytics_payload(&server, DEFAULT_READ_TIMEOUT).await?;
|
||||
let event = thread_initialized_event(&payload);
|
||||
let event = thread_initialized_event(&payload)?;
|
||||
assert_basic_thread_initialized_event(event, &thread.id, "resumed");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ async fn thread_start_tracks_thread_initialized_analytics() -> Result<()> {
|
||||
|
||||
let payload = wait_for_analytics_payload(&server, DEFAULT_READ_TIMEOUT).await?;
|
||||
assert_eq!(payload["events"].as_array().expect("events array").len(), 1);
|
||||
let event = thread_initialized_event(&payload);
|
||||
let event = thread_initialized_event(&payload)?;
|
||||
assert_basic_thread_initialized_event(event, &thread.id, "new");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user