tests: remove prefix parsing from context snapshots

This commit is contained in:
Charles Cunningham
2026-02-11 18:17:00 -08:00
parent 0bd8ea1997
commit dc7ec6e201
10 changed files with 28 additions and 60 deletions

View File

@@ -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<ContextSnapshotPrefixCapture>,
cwd_contains_replacements: Vec<(String, String)>,
tool_name_replacements: Vec<(String, String)>,
}
@@ -43,7 +35,6 @@ impl Default for ContextSnapshotOptions {
"<permissions instructions>".to_string(),
"<PERMISSIONS_INSTRUCTIONS>".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<String>,
marker_prefix: impl Into<String>,
marker_suffix: impl Into<String>,
) -> 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<String>,
@@ -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("<environment_context>") {
let cwd = text.lines().find_map(|line| {
let trimmed = line.trim();

View File

@@ -194,7 +194,6 @@ async fn assert_compaction_uses_turn_lifecycle_id(codex: &std::sync::Arc<codex_c
fn context_snapshot_options() -> ContextSnapshotOptions {
ContextSnapshotOptions::default()
.replace_exact_text(SUMMARIZATION_PROMPT, "<SUMMARIZATION_PROMPT>")
.capture_text_suffix_after_prefix(format!("{SUMMARY_PREFIX}\n"), "<SUMMARY:", ">")
.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, "<TOOL_CALL>")
}
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("<SUMMARY:PRE_TURN_SUMMARY>"),
"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("<SUMMARY:MID_TURN_SUMMARY>"),
"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("<SUMMARY:MANUAL_SUMMARY>"),
"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"),

View File

@@ -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"), "<SUMMARY:", ">")
.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, "<TOOL_CALL>")
}
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("<SUMMARY:REMOTE_PRE_TURN_SUMMARY>"),
"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("<SUMMARY:REMOTE_MID_TURN_SUMMARY>"),
"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("<SUMMARY:REMOTE_MANUAL_EMPTY_SUMMARY>"),
!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("<SUMMARY:REMOTE_MANUAL_WITH_HISTORY_SUMMARY>"),
"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(())

View File

@@ -17,5 +17,5 @@ Scenario: Manual /compact with prior user history compacts existing history and
01:message/user:<AGENTS_MD>
02:message/user:<ENVIRONMENT_CONTEXT:cwd=<CWD>>
03:message/user:USER_ONE
04:message/user:<SUMMARY:MANUAL_SUMMARY>
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

View File

@@ -14,5 +14,5 @@ Scenario: Manual /compact with no prior user turn currently still issues a compa
00:message/developer:<PERMISSIONS_INSTRUCTIONS>
01:message/user:<AGENTS_MD>
02:message/user:<ENVIRONMENT_CONTEXT:cwd=<CWD>>
03:message/user:<SUMMARY:MANUAL_EMPTY_SUMMARY>
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

View File

@@ -18,4 +18,4 @@ Scenario: Mid-turn continuation compaction after tool output: compact request in
01:message/user:<AGENTS_MD>
02:message/user:<ENVIRONMENT_CONTEXT:cwd=<CWD>>
03:message/user:USER_ONE
04:message/user:<SUMMARY:MID_TURN_SUMMARY>
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

View File

@@ -21,5 +21,5 @@ Scenario: Pre-turn auto-compaction with a context override emits the context dif
02:message/user:<ENVIRONMENT_CONTEXT:cwd=PRETURN_CONTEXT_DIFF_CWD>
03:message/user:USER_ONE
04:message/user:USER_TWO
05:message/user:<SUMMARY:PRE_TURN_SUMMARY>
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:<image> | </image> | USER_THREE

View File

@@ -16,5 +16,5 @@ Scenario: Remote manual /compact with prior user history compacts existing histo
01:message/developer:<PERMISSIONS_INSTRUCTIONS>
02:message/user:<AGENTS_MD>
03:message/user:<ENVIRONMENT_CONTEXT:cwd=<CWD>>
04:message/user:<SUMMARY:REMOTE_MANUAL_WITH_HISTORY_SUMMARY>
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

View File

@@ -17,4 +17,4 @@ Scenario: Remote mid-turn continuation compaction after tool output: compact req
01:message/developer:<PERMISSIONS_INSTRUCTIONS>
02:message/user:<AGENTS_MD>
03:message/user:<ENVIRONMENT_CONTEXT:cwd=<CWD>>
04:message/user:<SUMMARY:REMOTE_MID_TURN_SUMMARY>
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

View File

@@ -20,5 +20,5 @@ Scenario: Remote pre-turn auto-compaction with a context override emits the cont
02:message/developer:<PERMISSIONS_INSTRUCTIONS>
03:message/user:<AGENTS_MD>
04:message/user:<ENVIRONMENT_CONTEXT:cwd=PRETURN_CONTEXT_DIFF_CWD>
05:message/user:<SUMMARY:REMOTE_PRE_TURN_SUMMARY>
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