codex_app_server_client/protocol.rs
1//! Generated types for the Codex app-server v2 JSON-RPC protocol.
2//!
3//! Everything in this module is generated at build time by `build.rs` (via
4//! `typify`) from `schema/protocol.schema.json`. See the crate README for how
5//! that schema was derived and how to regenerate it against a newer `codex`
6//! CLI version.
7#![allow(
8 clippy::all,
9 dead_code,
10 non_camel_case_types,
11 non_snake_case,
12 missing_docs,
13 rustdoc::broken_intra_doc_links,
14 rustdoc::bare_urls
15)]
16
17include!(concat!(env!("OUT_DIR"), "/protocol_generated.rs"));
18
19#[cfg(test)]
20mod tests {
21 use super::RequestId;
22 use std::collections::HashMap;
23
24 #[test]
25 fn request_id_is_eq_and_hash() {
26 assert_eq!(RequestId::Int64(5), RequestId::Int64(5));
27 assert_ne!(RequestId::Int64(5), RequestId::Int64(6));
28 // Different variants are never equal, even when their string forms
29 // coincide - `RequestId` is untagged, but the derived `PartialEq`
30 // still discriminates by variant.
31 assert_ne!(RequestId::Int64(5), RequestId::String("5".to_string()));
32
33 // The real motivating use case: keying a map by `RequestId` to
34 // correlate in-flight server->client requests (e.g. tracking
35 // pending approval/elicitation requests by their app-server-assigned
36 // id in a UI layer, or a multiplexing wrapper keying per-connection
37 // state) without a caller-side newtype wrapper.
38 let mut pending: HashMap<RequestId, &'static str> = HashMap::new();
39 pending.insert(RequestId::Int64(1), "first");
40 pending.insert(RequestId::String("abc".to_string()), "second");
41
42 assert_eq!(pending.get(&RequestId::Int64(1)), Some(&"first"));
43 assert_eq!(
44 pending.get(&RequestId::String("abc".to_string())),
45 Some(&"second")
46 );
47 assert_eq!(pending.get(&RequestId::Int64(2)), None);
48 }
49}