@@ -574,11 +574,12 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
574574fn guardian_truncate_text_keeps_prefix_suffix_and_xml_marker ( ) {
575575 let content = "prefix " . repeat ( 200 ) + & " suffix" . repeat ( 200 ) ;
576576
577- let truncated = guardian_truncate_text ( & content, /*token_cap*/ 20 ) ;
577+ let ( truncated, was_truncated ) = guardian_truncate_text ( & content, /*token_cap*/ 20 ) ;
578578
579579 assert ! ( truncated. starts_with( "prefix" ) ) ;
580580 assert ! ( truncated. contains( "<truncated omitted_approx_tokens=\" " ) ) ;
581581 assert ! ( truncated. ends_with( "suffix" ) ) ;
582+ assert ! ( was_truncated) ;
582583}
583584
584585#[ test]
@@ -593,9 +594,27 @@ fn format_guardian_action_pretty_truncates_large_string_fields() -> serde_json::
593594
594595 let rendered = format_guardian_action_pretty ( & action) ?;
595596
596- assert ! ( rendered. contains( "\" tool\" : \" apply_patch\" " ) ) ;
597- assert ! ( rendered. contains( "<truncated omitted_approx_tokens=" ) ) ;
598- assert ! ( rendered. len( ) < patch. len( ) ) ;
597+ assert ! ( rendered. text. contains( "\" tool\" : \" apply_patch\" " ) ) ;
598+ assert ! ( rendered. text. contains( "<truncated omitted_approx_tokens=" ) ) ;
599+ assert ! ( rendered. text. len( ) < patch. len( ) ) ;
600+ assert ! ( rendered. truncated) ;
601+ Ok ( ( ) )
602+ }
603+
604+ #[ test]
605+ fn format_guardian_action_pretty_reports_no_truncation_for_small_payload ( ) -> serde_json:: Result < ( ) >
606+ {
607+ let action = GuardianApprovalRequest :: ApplyPatch {
608+ id : "patch-1" . to_string ( ) ,
609+ cwd : test_path_buf ( "/tmp" ) . abs ( ) ,
610+ files : Vec :: new ( ) ,
611+ patch : "line\n " . to_string ( ) ,
612+ } ;
613+
614+ let rendered = format_guardian_action_pretty ( & action) ?;
615+
616+ assert ! ( rendered. text. contains( "\" tool\" : \" apply_patch\" " ) ) ;
617+ assert ! ( !rendered. truncated) ;
599618 Ok ( ( ) )
600619}
601620
@@ -996,11 +1015,20 @@ async fn guardian_review_request_layout_matches_model_visible_request_snapshot()
9961015 /*external_cancel*/ None ,
9971016 )
9981017 . await ;
999- let ( GuardianReviewOutcome :: Completed ( assessment) , _ ) = outcome else {
1018+ let ( GuardianReviewOutcome :: Completed ( assessment) , metadata ) = outcome else {
10001019 panic ! ( "expected guardian assessment" ) ;
10011020 } ;
1021+ let guardian_thread_id = metadata
1022+ . guardian_thread_id
1023+ . as_deref ( )
1024+ . expect ( "guardian thread id" ) ;
10021025 assert_eq ! ( assessment. outcome, GuardianAssessmentOutcome :: Allow ) ;
1003-
1026+ assert_ne ! ( guardian_thread_id, session. conversation_id. to_string( ) ) ;
1027+ ThreadId :: from_string ( guardian_thread_id) . expect ( "guardian thread id should be a valid UUID" ) ;
1028+ assert ! ( matches!(
1029+ metadata. guardian_session_kind,
1030+ Some ( codex_analytics:: GuardianReviewSessionKind :: TrunkNew )
1031+ ) ) ;
10041032 let request = request_log. single_request ( ) ;
10051033 let request_body = request. body_json ( ) ;
10061034 assert_eq ! (
@@ -1032,6 +1060,21 @@ async fn guardian_review_request_layout_matches_model_visible_request_snapshot()
10321060 "required" : [ "outcome" ]
10331061 } ) )
10341062 ) ;
1063+ let request_model = request_body
1064+ . get ( "model" )
1065+ . and_then ( |value| value. as_str ( ) )
1066+ . expect ( "guardian request should include a model" ) ;
1067+ let request_reasoning_effort = request_body
1068+ . get ( "reasoning" )
1069+ . and_then ( |reasoning| reasoning. get ( "effort" ) )
1070+ . and_then ( |value| value. as_str ( ) ) ;
1071+ assert_eq ! ( metadata. guardian_model. as_deref( ) , Some ( request_model) ) ;
1072+ assert_eq ! (
1073+ metadata. guardian_reasoning_effort. as_deref( ) ,
1074+ request_reasoning_effort
1075+ ) ;
1076+ assert_eq ! ( metadata. had_prior_review_context, Some ( false ) ) ;
1077+
10351078 let mut settings = Settings :: clone_current ( ) ;
10361079 settings. set_snapshot_path ( "snapshots" ) ;
10371080 settings. set_prepend_module_to_snapshot ( false ) ;
@@ -1235,18 +1278,63 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
12351278 )
12361279 . await ;
12371280
1238- let ( GuardianReviewOutcome :: Completed ( first_assessment) , _ ) = first_outcome else {
1281+ let ( GuardianReviewOutcome :: Completed ( first_assessment) , first_metadata ) = first_outcome else {
12391282 panic ! ( "expected first guardian assessment" ) ;
12401283 } ;
1241- let ( GuardianReviewOutcome :: Completed ( second_assessment) , _) = second_outcome else {
1284+ let ( GuardianReviewOutcome :: Completed ( second_assessment) , second_metadata) = second_outcome
1285+ else {
12421286 panic ! ( "expected second guardian assessment" ) ;
12431287 } ;
1244- let ( GuardianReviewOutcome :: Completed ( third_assessment) , _ ) = third_outcome else {
1288+ let ( GuardianReviewOutcome :: Completed ( third_assessment) , third_metadata ) = third_outcome else {
12451289 panic ! ( "expected third guardian assessment" ) ;
12461290 } ;
12471291 assert_eq ! ( first_assessment. outcome, GuardianAssessmentOutcome :: Allow ) ;
12481292 assert_eq ! ( second_assessment. outcome, GuardianAssessmentOutcome :: Allow ) ;
12491293 assert_eq ! ( third_assessment. outcome, GuardianAssessmentOutcome :: Allow ) ;
1294+ assert ! ( matches!(
1295+ first_metadata. guardian_session_kind,
1296+ Some ( codex_analytics:: GuardianReviewSessionKind :: TrunkNew )
1297+ ) ) ;
1298+ assert ! ( matches!(
1299+ second_metadata. guardian_session_kind,
1300+ Some ( codex_analytics:: GuardianReviewSessionKind :: TrunkReused )
1301+ ) ) ;
1302+ assert ! ( matches!(
1303+ third_metadata. guardian_session_kind,
1304+ Some ( codex_analytics:: GuardianReviewSessionKind :: TrunkReused )
1305+ ) ) ;
1306+ ThreadId :: from_string (
1307+ first_metadata
1308+ . guardian_thread_id
1309+ . as_deref ( )
1310+ . expect ( "first guardian thread id" ) ,
1311+ )
1312+ . expect ( "first guardian thread id should be a valid UUID" ) ;
1313+ ThreadId :: from_string (
1314+ second_metadata
1315+ . guardian_thread_id
1316+ . as_deref ( )
1317+ . expect ( "second guardian thread id" ) ,
1318+ )
1319+ . expect ( "second guardian thread id should be a valid UUID" ) ;
1320+ ThreadId :: from_string (
1321+ third_metadata
1322+ . guardian_thread_id
1323+ . as_deref ( )
1324+ . expect ( "third guardian thread id" ) ,
1325+ )
1326+ . expect ( "third guardian thread id should be a valid UUID" ) ;
1327+ assert_eq ! ( first_metadata. had_prior_review_context, Some ( false ) ) ;
1328+ assert_eq ! ( second_metadata. had_prior_review_context, Some ( true ) ) ;
1329+ assert_eq ! ( third_metadata. had_prior_review_context, Some ( true ) ) ;
1330+ assert_eq ! (
1331+ first_metadata. guardian_thread_id,
1332+ second_metadata. guardian_thread_id
1333+ ) ;
1334+ assert_eq ! (
1335+ second_metadata. guardian_thread_id,
1336+ third_metadata. guardian_thread_id
1337+ ) ;
12501338
12511339 let requests = request_log. requests ( ) ;
12521340 assert_eq ! ( requests. len( ) , 3 ) ;
0 commit comments