mirror of
https://github.com/openai/codex.git
synced 2026-05-19 02:33:10 +00:00
## Why `pr17088` adds typed server-originated request/response plumbing, but successful client responses are still erased into bare JSON-RPC `result` values before app-server can make any typed decision about them. This precursor PR keeps successful client responses typed until the outgoing response seam. It is intentionally limited to protocol/app-server plumbing so the analytics behavior change can review separately on top. ## What changed - Add `ClientResponsePayload` as the pre-serialization client response body type. - Route app-server successful response paths through the typed payload seam while preserving existing handler-local analytics behavior. - Keep `InterruptConversation` JSON-RPC-only because it has no `ClientResponse` variant. - Move the new payload conversion tests into a dedicated protocol test module. ## Verification - `cargo check -p codex-app-server` - `cargo test -p codex-app-server-protocol`
45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use super::*;
|
|
use anyhow::Result;
|
|
use codex_protocol::protocol::TurnAbortReason;
|
|
use pretty_assertions::assert_eq;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn client_response_payload_returns_jsonrpc_parts_and_client_response() -> Result<()> {
|
|
let (request_id, result, payload) =
|
|
ClientResponsePayload::ThreadArchive(v2::ThreadArchiveResponse {})
|
|
.into_jsonrpc_parts_and_payload(RequestId::Integer(7))?;
|
|
|
|
assert_eq!(request_id, RequestId::Integer(7));
|
|
assert_eq!(result, json!({}));
|
|
|
|
let Some(ClientResponse::ThreadArchive {
|
|
request_id,
|
|
response: _,
|
|
}) = payload.and_then(|payload| payload.into_client_response(RequestId::Integer(7)))
|
|
else {
|
|
panic!("expected thread/archive client response");
|
|
};
|
|
assert_eq!(request_id, RequestId::Integer(7));
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn interrupt_conversation_payload_stays_jsonrpc_only() -> Result<()> {
|
|
let (request_id, result, payload) =
|
|
ClientResponsePayload::InterruptConversation(v1::InterruptConversationResponse {
|
|
abort_reason: TurnAbortReason::Interrupted,
|
|
})
|
|
.into_jsonrpc_parts_and_payload(RequestId::Integer(8))?;
|
|
|
|
assert_eq!(request_id, RequestId::Integer(8));
|
|
assert_eq!(
|
|
result,
|
|
json!({
|
|
"abortReason": "interrupted",
|
|
})
|
|
);
|
|
assert!(payload.is_none());
|
|
Ok(())
|
|
}
|