diff --git a/codex-rs/core/tests/common/context_snapshot.rs b/codex-rs/core/tests/common/context_snapshot.rs index 4a8f1d6d5f..0b160dfbe2 100644 --- a/codex-rs/core/tests/common/context_snapshot.rs +++ b/codex-rs/core/tests/common/context_snapshot.rs @@ -10,13 +10,6 @@ pub enum ContextSnapshotRenderMode { KindOnly, } -#[derive(Debug, Clone)] -struct ContextSnapshotPrefixCapture { - prefix: String, - marker_prefix: String, - marker_suffix: String, -} - #[derive(Debug, Clone)] pub struct ContextSnapshotOptions { render_mode: ContextSnapshotRenderMode, @@ -24,7 +17,6 @@ pub struct ContextSnapshotOptions { text_exact_replacements: Vec<(String, String)>, text_prefix_replacements: Vec<(String, String)>, text_contains_replacements: Vec<(String, String)>, - text_prefix_captures: Vec, cwd_contains_replacements: Vec<(String, String)>, tool_name_replacements: Vec<(String, String)>, } @@ -43,7 +35,6 @@ impl Default for ContextSnapshotOptions { "".to_string(), "".to_string(), )], - text_prefix_captures: Vec::new(), cwd_contains_replacements: Vec::new(), tool_name_replacements: Vec::new(), } @@ -91,21 +82,6 @@ impl ContextSnapshotOptions { self } - pub fn capture_text_suffix_after_prefix( - mut self, - prefix: impl Into, - marker_prefix: impl Into, - marker_suffix: impl Into, - ) -> Self { - self.text_prefix_captures - .push(ContextSnapshotPrefixCapture { - prefix: prefix.into(), - marker_prefix: marker_prefix.into(), - marker_suffix: marker_suffix.into(), - }); - self - } - pub fn replace_cwd_when_contains( mut self, cwd_substring: impl Into, @@ -293,20 +269,6 @@ fn normalize_shape_text(text: &str, options: &ContextSnapshotOptions) -> String return replacement.clone(); } - if let Some(capture) = options - .text_prefix_captures - .iter() - .find(|capture| text.starts_with(capture.prefix.as_str())) - { - let suffix = text - .strip_prefix(capture.prefix.as_str()) - .unwrap_or_default(); - return format!( - "{}{}{}", - capture.marker_prefix, suffix, capture.marker_suffix - ); - } - if options.normalize_environment_context && text.starts_with("") { let cwd = text.lines().find_map(|line| { let trimmed = line.trim(); diff --git a/codex-rs/core/tests/suite/compact.rs b/codex-rs/core/tests/suite/compact.rs index 31d07ef214..1c2ae99d96 100644 --- a/codex-rs/core/tests/suite/compact.rs +++ b/codex-rs/core/tests/suite/compact.rs @@ -194,7 +194,6 @@ async fn assert_compaction_uses_turn_lifecycle_id(codex: &std::sync::Arc ContextSnapshotOptions { ContextSnapshotOptions::default() .replace_exact_text(SUMMARIZATION_PROMPT, "") - .capture_text_suffix_after_prefix(format!("{SUMMARY_PREFIX}\n"), "") .replace_cwd_when_contains( PRETURN_CONTEXT_DIFF_CWD_MARKER, PRETURN_CONTEXT_DIFF_CWD_MARKER, @@ -202,6 +201,10 @@ fn context_snapshot_options() -> ContextSnapshotOptions { .replace_tool_name(DUMMY_FUNCTION_NAME, "") } +fn summary_snapshot_text(summary: &str) -> String { + summary_with_prefix(summary).replace('\n', "\\n") +} + fn request_input_shape(request: &core_test_support::responses::ResponsesRequest) -> String { context_snapshot::request_input_shape(request, &context_snapshot_options()) } @@ -3098,8 +3101,8 @@ async fn snapshot_request_shape_pre_turn_compaction_including_incoming_user_mess "expected post-compaction follow-up request to keep incoming user image content" ); assert!( - follow_up_shape.contains(""), - "expected post-compaction request to include prefixed summary" + follow_up_shape.contains(&summary_snapshot_text("PRE_TURN_SUMMARY")), + "expected post-compaction request to include summary text" ); } @@ -3269,8 +3272,8 @@ async fn snapshot_request_shape_mid_turn_continuation_compaction() { "mid-turn compaction request should include summarization prompt" ); assert!( - follow_up_shape.contains(""), - "post-mid-turn compaction request should include summary" + follow_up_shape.contains(&summary_snapshot_text("MID_TURN_SUMMARY")), + "post-mid-turn compaction request should include summary text" ); } @@ -3428,8 +3431,8 @@ async fn snapshot_request_shape_manual_compact_with_previous_user_messages() { "manual compact request should include summarization prompt" ); assert!( - follow_up_shape.contains(""), - "post-compact request should include compact summary" + follow_up_shape.contains(&summary_snapshot_text("MANUAL_SUMMARY")), + "post-compact request should include compact summary text" ); assert!( follow_up_shape.contains("USER_TWO"), diff --git a/codex-rs/core/tests/suite/compact_remote.rs b/codex-rs/core/tests/suite/compact_remote.rs index d415ffbd18..d1cc704f46 100644 --- a/codex-rs/core/tests/suite/compact_remote.rs +++ b/codex-rs/core/tests/suite/compact_remote.rs @@ -66,7 +66,6 @@ fn user_message_item(text: &str) -> ResponseItem { fn context_snapshot_options() -> ContextSnapshotOptions { ContextSnapshotOptions::default() - .capture_text_suffix_after_prefix(format!("{SUMMARY_PREFIX}\n"), "") .replace_cwd_when_contains( PRETURN_CONTEXT_DIFF_CWD_MARKER, PRETURN_CONTEXT_DIFF_CWD_MARKER, @@ -74,6 +73,10 @@ fn context_snapshot_options() -> ContextSnapshotOptions { .replace_tool_name(DUMMY_FUNCTION_NAME, "") } +fn summary_snapshot_text(summary: &str) -> String { + summary_with_prefix(summary).replace('\n', "\\n") +} + fn request_input_shape(request: &responses::ResponsesRequest) -> String { context_snapshot::request_input_shape(request, &context_snapshot_options()) } @@ -1470,8 +1473,8 @@ async fn snapshot_request_shape_remote_pre_turn_compaction_including_incoming_us "current behavior excludes incoming user message from remote pre-turn compaction input" ); assert!( - follow_up_shape.contains(""), - "post-compaction request should include remote summary" + follow_up_shape.contains(&summary_snapshot_text("REMOTE_PRE_TURN_SUMMARY")), + "post-compaction request should include remote summary text" ); assert_eq!( follow_up_shape.matches("USER_THREE").count(), @@ -1769,8 +1772,8 @@ async fn snapshot_request_shape_remote_mid_turn_continuation_compaction() -> Res "remote mid-turn compaction request should include function call output" ); assert!( - follow_up_shape.contains(""), - "post-mid-turn request should include remote compaction summary" + follow_up_shape.contains(&summary_snapshot_text("REMOTE_MID_TURN_SUMMARY")), + "post-mid-turn request should include remote compaction summary text" ); Ok(()) @@ -1834,7 +1837,7 @@ async fn snapshot_request_shape_remote_manual_compact_without_previous_user_mess ) ); assert!( - !follow_up_shape.contains(""), + !follow_up_shape.contains(&summary_snapshot_text("REMOTE_MANUAL_EMPTY_SUMMARY")), "post-compact request should not include compact summary when remote compaction is skipped" ); assert!( @@ -1931,8 +1934,8 @@ async fn snapshot_request_shape_remote_manual_compact_with_previous_user_message "post-compact request should include latest user message" ); assert!( - follow_up_shape.contains(""), - "post-compact request should include remote compact summary" + follow_up_shape.contains(&summary_snapshot_text("REMOTE_MANUAL_WITH_HISTORY_SUMMARY")), + "post-compact request should include remote compact summary text" ); Ok(()) diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__compact__manual_compact_with_history_shapes.snap b/codex-rs/core/tests/suite/snapshots/all__suite__compact__manual_compact_with_history_shapes.snap index e507b79ecc..a2fe457390 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__compact__manual_compact_with_history_shapes.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__compact__manual_compact_with_history_shapes.snap @@ -17,5 +17,5 @@ Scenario: Manual /compact with prior user history compacts existing history and 01:message/user: 02:message/user:> 03:message/user:USER_ONE -04:message/user: +04:message/user:Another language model started to solve this problem and produced a summary of its thinking process. You also have access to the state of the tools that were used by that language model. Use this to build on the work that has already been done and avoid duplicating work. Here is the summary produced by the other language model, use the information in this summary to assist with your own analysis:\nMANUAL_SUMMARY 05:message/user:USER_TWO diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__compact__manual_compact_without_prev_user_shapes.snap b/codex-rs/core/tests/suite/snapshots/all__suite__compact__manual_compact_without_prev_user_shapes.snap index 7989f8df9b..76587e4aab 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__compact__manual_compact_without_prev_user_shapes.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__compact__manual_compact_without_prev_user_shapes.snap @@ -14,5 +14,5 @@ Scenario: Manual /compact with no prior user turn currently still issues a compa 00:message/developer: 01:message/user: 02:message/user:> -03:message/user: +03:message/user:Another language model started to solve this problem and produced a summary of its thinking process. You also have access to the state of the tools that were used by that language model. Use this to build on the work that has already been done and avoid duplicating work. Here is the summary produced by the other language model, use the information in this summary to assist with your own analysis:\nMANUAL_EMPTY_SUMMARY 04:message/user:AFTER_MANUAL_EMPTY_COMPACT diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__compact__mid_turn_compaction_shapes.snap b/codex-rs/core/tests/suite/snapshots/all__suite__compact__mid_turn_compaction_shapes.snap index 4472ea863d..a53b74a126 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__compact__mid_turn_compaction_shapes.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__compact__mid_turn_compaction_shapes.snap @@ -18,4 +18,4 @@ Scenario: Mid-turn continuation compaction after tool output: compact request in 01:message/user: 02:message/user:> 03:message/user:USER_ONE -04:message/user: +04:message/user:Another language model started to solve this problem and produced a summary of its thinking process. You also have access to the state of the tools that were used by that language model. Use this to build on the work that has already been done and avoid duplicating work. Here is the summary produced by the other language model, use the information in this summary to assist with your own analysis:\nMID_TURN_SUMMARY diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__compact__pre_turn_compaction_including_incoming_shapes.snap b/codex-rs/core/tests/suite/snapshots/all__suite__compact__pre_turn_compaction_including_incoming_shapes.snap index e6d462ed3f..49cc8872d3 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__compact__pre_turn_compaction_including_incoming_shapes.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__compact__pre_turn_compaction_including_incoming_shapes.snap @@ -21,5 +21,5 @@ Scenario: Pre-turn auto-compaction with a context override emits the context dif 02:message/user: 03:message/user:USER_ONE 04:message/user:USER_TWO -05:message/user: +05:message/user:Another language model started to solve this problem and produced a summary of its thinking process. You also have access to the state of the tools that were used by that language model. Use this to build on the work that has already been done and avoid duplicating work. Here is the summary produced by the other language model, use the information in this summary to assist with your own analysis:\nPRE_TURN_SUMMARY 06:message/user: | | USER_THREE diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_manual_compact_with_history_shapes.snap b/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_manual_compact_with_history_shapes.snap index 5814c71c3a..608f1b8256 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_manual_compact_with_history_shapes.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_manual_compact_with_history_shapes.snap @@ -16,5 +16,5 @@ Scenario: Remote manual /compact with prior user history compacts existing histo 01:message/developer: 02:message/user: 03:message/user:> -04:message/user: +04:message/user:Another language model started to solve this problem and produced a summary of its thinking process. You also have access to the state of the tools that were used by that language model. Use this to build on the work that has already been done and avoid duplicating work. Here is the summary produced by the other language model, use the information in this summary to assist with your own analysis:\nREMOTE_MANUAL_WITH_HISTORY_SUMMARY 05:message/user:USER_TWO diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_mid_turn_compaction_shapes.snap b/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_mid_turn_compaction_shapes.snap index 979c122b15..3a7c37779e 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_mid_turn_compaction_shapes.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_mid_turn_compaction_shapes.snap @@ -17,4 +17,4 @@ Scenario: Remote mid-turn continuation compaction after tool output: compact req 01:message/developer: 02:message/user: 03:message/user:> -04:message/user: +04:message/user:Another language model started to solve this problem and produced a summary of its thinking process. You also have access to the state of the tools that were used by that language model. Use this to build on the work that has already been done and avoid duplicating work. Here is the summary produced by the other language model, use the information in this summary to assist with your own analysis:\nREMOTE_MID_TURN_SUMMARY diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_pre_turn_compaction_including_incoming_shapes.snap b/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_pre_turn_compaction_including_incoming_shapes.snap index 9a1b23d725..702c36c799 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_pre_turn_compaction_including_incoming_shapes.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__compact_remote__remote_pre_turn_compaction_including_incoming_shapes.snap @@ -20,5 +20,5 @@ Scenario: Remote pre-turn auto-compaction with a context override emits the cont 02:message/developer: 03:message/user: 04:message/user: -05:message/user: +05:message/user:Another language model started to solve this problem and produced a summary of its thinking process. You also have access to the state of the tools that were used by that language model. Use this to build on the work that has already been done and avoid duplicating work. Here is the summary produced by the other language model, use the information in this summary to assist with your own analysis:\nREMOTE_PRE_TURN_SUMMARY 06:message/user:USER_THREE