core: require canonical context newlines

This commit is contained in:
fchen
2026-06-11 17:19:11 -07:00
parent 294b012b20
commit 172f8a2c51
2 changed files with 32 additions and 2 deletions

View File

@@ -84,6 +84,36 @@ fn parses_canonical_internal_model_context_fragment() {
);
}
#[test]
fn rejects_internal_model_context_without_leading_wrapper_newline() {
assert_eq!(
InternalModelContextFragment::parse_canonical(
"<codex_internal_context source=\"goal\">body\n</codex_internal_context>"
),
None
);
}
#[test]
fn rejects_internal_model_context_without_trailing_wrapper_newline() {
assert_eq!(
InternalModelContextFragment::parse_canonical(
"<codex_internal_context source=\"extension\">\nbody</codex_internal_context>"
),
None
);
}
#[test]
fn rejects_internal_model_context_without_wrapper_newlines() {
assert_eq!(
InternalModelContextFragment::parse_canonical(
"<codex_internal_context source=\"goal\">body</codex_internal_context>"
),
None
);
}
#[test]
fn detects_legacy_goal_context_fragment() {
assert!(is_contextual_user_fragment(&ContentItem::InputText {

View File

@@ -83,8 +83,8 @@ impl InternalModelContextFragment {
}
let body = body_and_close.strip_suffix(CONTEXT_END_MARKER)?;
let body = body.strip_prefix('\n').unwrap_or(body);
let body = body.strip_suffix('\n').unwrap_or(body);
let body = body.strip_prefix('\n')?;
let body = body.strip_suffix('\n')?;
Some(Self::new(
InternalContextSource(source.to_string()),