11use anyhow:: Result ;
22use codex_protocol:: models:: ContentItem ;
3+ use codex_protocol:: models:: PermissionProfile ;
34use codex_protocol:: models:: ResponseItem ;
45use codex_protocol:: protocol:: AskForApproval ;
56use codex_protocol:: protocol:: CodexErrorInfo ;
67use codex_protocol:: protocol:: EventMsg ;
78use codex_protocol:: protocol:: ModelRerouteReason ;
89use codex_protocol:: protocol:: ModelVerification ;
910use codex_protocol:: protocol:: Op ;
10- use codex_protocol:: protocol:: SandboxPolicy ;
1111use codex_protocol:: user_input:: UserInput ;
1212use core_test_support:: responses:: ev_assistant_message;
1313use core_test_support:: responses:: ev_function_call;
@@ -20,7 +20,9 @@ use core_test_support::responses::sse_completed;
2020use core_test_support:: responses:: sse_response;
2121use core_test_support:: responses:: start_mock_server;
2222use core_test_support:: skip_if_no_network;
23+ use core_test_support:: test_codex:: TestCodex ;
2324use core_test_support:: test_codex:: test_codex;
25+ use core_test_support:: test_codex:: turn_permission_fields;
2426use core_test_support:: wait_for_event;
2527use pretty_assertions:: assert_eq;
2628use wiremock:: ResponseTemplate ;
@@ -32,6 +34,30 @@ const TRUSTED_ACCESS_FOR_CYBER_VERIFICATION: &str = "trusted_access_for_cyber";
3234const CYBER_POLICY_MESSAGE : & str =
3335 "This request has been flagged for potentially high-risk cyber activity." ;
3436
37+ fn disabled_text_turn ( test : & TestCodex , text : & str ) -> Op {
38+ let ( sandbox_policy, permission_profile) =
39+ turn_permission_fields ( PermissionProfile :: Disabled , test. cwd_path ( ) ) ;
40+ Op :: UserTurn {
41+ environments : None ,
42+ items : vec ! [ UserInput :: Text {
43+ text: text. to_string( ) ,
44+ text_elements: Vec :: new( ) ,
45+ } ] ,
46+ final_output_json_schema : None ,
47+ cwd : test. cwd_path ( ) . to_path_buf ( ) ,
48+ approval_policy : AskForApproval :: Never ,
49+ approvals_reviewer : None ,
50+ sandbox_policy,
51+ permission_profile,
52+ model : REQUESTED_MODEL . to_string ( ) ,
53+ effort : test. config . model_reasoning_effort ,
54+ summary : None ,
55+ service_tier : None ,
56+ collaboration_mode : None ,
57+ personality : None ,
58+ }
59+ }
60+
3561#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
3662async fn openai_model_header_mismatch_emits_warning_event_and_warning_item ( ) -> Result < ( ) > {
3763 skip_if_no_network ! ( Ok ( ( ) ) ) ;
@@ -45,25 +71,7 @@ async fn openai_model_header_mismatch_emits_warning_event_and_warning_item() ->
4571 let test = builder. build ( & server) . await ?;
4672
4773 test. codex
48- . submit ( Op :: UserTurn {
49- environments : None ,
50- items : vec ! [ UserInput :: Text {
51- text: "trigger safety check" . to_string( ) ,
52- text_elements: Vec :: new( ) ,
53- } ] ,
54- final_output_json_schema : None ,
55- cwd : test. cwd_path ( ) . to_path_buf ( ) ,
56- approval_policy : AskForApproval :: Never ,
57- approvals_reviewer : None ,
58- sandbox_policy : SandboxPolicy :: DangerFullAccess ,
59- permission_profile : None ,
60- model : REQUESTED_MODEL . to_string ( ) ,
61- effort : test. config . model_reasoning_effort ,
62- summary : None ,
63- service_tier : None ,
64- collaboration_mode : None ,
65- personality : None ,
66- } )
74+ . submit ( disabled_text_turn ( & test, "trigger safety check" ) )
6775 . await ?;
6876
6977 let reroute = wait_for_event ( & test. codex , |event| {
@@ -141,25 +149,7 @@ async fn cyber_policy_response_emits_typed_error_without_retry() -> Result<()> {
141149 let test = builder. build ( & server) . await ?;
142150
143151 test. codex
144- . submit ( Op :: UserTurn {
145- environments : None ,
146- items : vec ! [ UserInput :: Text {
147- text: "trigger cyber policy error" . to_string( ) ,
148- text_elements: Vec :: new( ) ,
149- } ] ,
150- final_output_json_schema : None ,
151- cwd : test. cwd_path ( ) . to_path_buf ( ) ,
152- approval_policy : AskForApproval :: Never ,
153- approvals_reviewer : None ,
154- sandbox_policy : SandboxPolicy :: DangerFullAccess ,
155- permission_profile : None ,
156- model : REQUESTED_MODEL . to_string ( ) ,
157- effort : test. config . model_reasoning_effort ,
158- summary : None ,
159- service_tier : None ,
160- collaboration_mode : None ,
161- personality : None ,
162- } )
152+ . submit ( disabled_text_turn ( & test, "trigger cyber policy error" ) )
163153 . await ?;
164154
165155 let error = wait_for_event ( & test. codex , |event| matches ! ( event, EventMsg :: Error ( _) ) ) . await ;
@@ -198,25 +188,7 @@ async fn response_model_field_mismatch_emits_warning_when_header_matches_request
198188 let test = builder. build ( & server) . await ?;
199189
200190 test. codex
201- . submit ( Op :: UserTurn {
202- environments : None ,
203- items : vec ! [ UserInput :: Text {
204- text: "trigger response model check" . to_string( ) ,
205- text_elements: Vec :: new( ) ,
206- } ] ,
207- final_output_json_schema : None ,
208- cwd : test. cwd_path ( ) . to_path_buf ( ) ,
209- approval_policy : AskForApproval :: Never ,
210- approvals_reviewer : None ,
211- sandbox_policy : SandboxPolicy :: DangerFullAccess ,
212- permission_profile : None ,
213- model : REQUESTED_MODEL . to_string ( ) ,
214- effort : test. config . model_reasoning_effort ,
215- summary : None ,
216- service_tier : None ,
217- collaboration_mode : None ,
218- personality : None ,
219- } )
191+ . submit ( disabled_text_turn ( & test, "trigger response model check" ) )
220192 . await ?;
221193
222194 let reroute = wait_for_event ( & test. codex , |event| {
@@ -286,25 +258,7 @@ async fn openai_model_header_mismatch_only_emits_one_warning_per_turn() -> Resul
286258 let test = builder. build ( & server) . await ?;
287259
288260 test. codex
289- . submit ( Op :: UserTurn {
290- environments : None ,
291- items : vec ! [ UserInput :: Text {
292- text: "trigger follow-up turn" . to_string( ) ,
293- text_elements: Vec :: new( ) ,
294- } ] ,
295- final_output_json_schema : None ,
296- cwd : test. cwd_path ( ) . to_path_buf ( ) ,
297- approval_policy : AskForApproval :: Never ,
298- approvals_reviewer : None ,
299- sandbox_policy : SandboxPolicy :: DangerFullAccess ,
300- permission_profile : None ,
301- model : REQUESTED_MODEL . to_string ( ) ,
302- effort : test. config . model_reasoning_effort ,
303- summary : None ,
304- service_tier : None ,
305- collaboration_mode : None ,
306- personality : None ,
307- } )
261+ . submit ( disabled_text_turn ( & test, "trigger follow-up turn" ) )
308262 . await ?;
309263
310264 let mut warning_count = 0 ;
@@ -338,25 +292,7 @@ async fn openai_model_header_casing_only_mismatch_does_not_warn() -> Result<()>
338292 let test = builder. build ( & server) . await ?;
339293
340294 test. codex
341- . submit ( Op :: UserTurn {
342- environments : None ,
343- items : vec ! [ UserInput :: Text {
344- text: "trigger casing check" . to_string( ) ,
345- text_elements: Vec :: new( ) ,
346- } ] ,
347- final_output_json_schema : None ,
348- cwd : test. cwd_path ( ) . to_path_buf ( ) ,
349- approval_policy : AskForApproval :: Never ,
350- approvals_reviewer : None ,
351- sandbox_policy : SandboxPolicy :: DangerFullAccess ,
352- permission_profile : None ,
353- model : REQUESTED_MODEL . to_string ( ) ,
354- effort : test. config . model_reasoning_effort ,
355- summary : None ,
356- service_tier : None ,
357- collaboration_mode : None ,
358- personality : None ,
359- } )
295+ . submit ( disabled_text_turn ( & test, "trigger casing check" ) )
360296 . await ?;
361297
362298 let mut reroute_count = 0 ;
@@ -399,25 +335,7 @@ async fn model_verification_emits_structured_event_without_reroute_or_warning()
399335 let test = builder. build ( & server) . await ?;
400336
401337 test. codex
402- . submit ( Op :: UserTurn {
403- environments : None ,
404- items : vec ! [ UserInput :: Text {
405- text: "trigger model verification" . to_string( ) ,
406- text_elements: Vec :: new( ) ,
407- } ] ,
408- final_output_json_schema : None ,
409- cwd : test. cwd_path ( ) . to_path_buf ( ) ,
410- approval_policy : AskForApproval :: Never ,
411- approvals_reviewer : None ,
412- sandbox_policy : SandboxPolicy :: DangerFullAccess ,
413- permission_profile : None ,
414- model : REQUESTED_MODEL . to_string ( ) ,
415- effort : test. config . model_reasoning_effort ,
416- summary : None ,
417- service_tier : None ,
418- collaboration_mode : None ,
419- personality : None ,
420- } )
338+ . submit ( disabled_text_turn ( & test, "trigger model verification" ) )
421339 . await ?;
422340
423341 let mut verification_count = 0 ;
@@ -493,25 +411,10 @@ async fn model_verification_only_emits_once_per_turn() -> Result<()> {
493411 let test = builder. build ( & server) . await ?;
494412
495413 test. codex
496- . submit ( Op :: UserTurn {
497- environments : None ,
498- items : vec ! [ UserInput :: Text {
499- text: "trigger follow-up model verification" . to_string( ) ,
500- text_elements: Vec :: new( ) ,
501- } ] ,
502- final_output_json_schema : None ,
503- cwd : test. cwd_path ( ) . to_path_buf ( ) ,
504- approval_policy : AskForApproval :: Never ,
505- approvals_reviewer : None ,
506- sandbox_policy : SandboxPolicy :: DangerFullAccess ,
507- permission_profile : None ,
508- model : REQUESTED_MODEL . to_string ( ) ,
509- effort : test. config . model_reasoning_effort ,
510- summary : None ,
511- service_tier : None ,
512- collaboration_mode : None ,
513- personality : None ,
514- } )
414+ . submit ( disabled_text_turn (
415+ & test,
416+ "trigger follow-up model verification" ,
417+ ) )
515418 . await ?;
516419
517420 let mut verification_count = 0 ;
0 commit comments