@@ -9,6 +9,48 @@ use tokio::{
99
1010const TURN_STATE_HEADER : & str = "x-codex-turn-state" ;
1111
12+ #[ tokio:: test]
13+ async fn https_requests_advertise_supported_codex_compatibility_version ( ) -> Result < ( ) > {
14+ let listener = TcpListener :: bind ( "127.0.0.1:0" ) . await ?;
15+ let api_base_url = format ! ( "http://{}" , listener. local_addr( ) ?) ;
16+ let server = tokio:: spawn ( async move {
17+ let request = read_http_json ( & listener) . await ?;
18+ assert ! (
19+ request. headers. contains( "\r \n originator: codex_cli_rs\r \n " ) ,
20+ "HTTPS requests must identify as the supported Codex client"
21+ ) ;
22+ assert ! (
23+ request. headers. contains( "\r \n version: 0.1337.0\r \n " ) ,
24+ "HTTPS requests must advertise the supported Codex compatibility version"
25+ ) ;
26+ let expected_user_agent = format ! (
27+ "\r \n user-agent: codex_cli_rs/0.1337.0 (nanocodex/{})\r \n " ,
28+ env!( "CARGO_PKG_VERSION" )
29+ ) ;
30+ assert ! (
31+ request. headers. contains( & expected_user_agent) ,
32+ "HTTPS requests must retain Nanocodex provenance in the Codex user agent"
33+ ) ;
34+ send_http_events (
35+ request. stream ,
36+ None ,
37+ [ completed_response ( "resp-version" , "ok" ) ] ,
38+ )
39+ . await
40+ } ) ;
41+
42+ let openai = OpenAi :: builder ( "test-key" )
43+ . transport ( ResponsesTransport :: Https )
44+ . api_base_url ( api_base_url)
45+ . build ( ) ?;
46+ let mut session = openai. instructions ( "Respond with one word." ) . build ( ) ?;
47+ assert_eq ! ( session. turn( ) . create( "test" ) . await ?. output_text( ) , "ok" ) ;
48+ timeout ( std:: time:: Duration :: from_secs ( 5 ) , server)
49+ . await
50+ . map_err ( |_| eyre ! ( "mock HTTPS compatibility server did not finish" ) ) ???;
51+ Ok ( ( ) )
52+ }
53+
1254#[ tokio:: test]
1355async fn https_turn_state_is_scoped_to_one_logical_turn_and_survives_retry ( ) -> Result < ( ) > {
1456 let listener = TcpListener :: bind ( "127.0.0.1:0" ) . await ?;
0 commit comments