use crate::compaction::{
CompactionPrompt, citation_compaction_tail_directive,
citation_compaction_tail_directive_with_prompt,
};
#[test]
fn compaction_directive_is_the_full_replace_prompt() {
let prompt = citation_compaction_tail_directive(None);
assert!(prompt.contains("faithful, concise summary"));
assert!(prompt.contains("do NOT emit a separate analysis block"));
assert!(prompt.contains("language of the latest user message"));
assert!(prompt.contains("<summary>"));
assert!(prompt.contains("</summary>"));
assert!(
!prompt.contains("available_ref_ids"),
"the summary request must not require citation ids"
);
assert!(!prompt.contains("{user_context_section}"));
assert!(!prompt.contains("**User-provided context for this compaction:**"));
}
#[test]
fn compaction_directive_asks_for_sections_without_rejecting_prose() {
let prompt = citation_compaction_tail_directive(Some("focus on auth"));
for section in [
"1. Primary Request and Intent:",
"2. Key Technical Concepts:",
"3. Files and Code Sections:",
"4. Errors and Fixes:",
"5. Problem Solving:",
"6. All User Messages:",
"7. Pending Tasks:",
"8. Current Work:",
"9. Optional Next Step:",
] {
assert!(prompt.contains(section), "missing {section}");
}
assert!(prompt.contains("Do NOT call or use any tools"));
assert!(prompt.contains("**User-provided context for this compaction:**\nfocus on auth"));
assert!(prompt.contains("<summary>"));
}
#[test]
fn compaction_prompt_supports_persistent_user_context_and_custom_instructions() {
let default_with_persistent = CompactionPrompt::default()
.with_user_context("Always preserve auth invariants.")
.expect("valid persistent user context");
let auto_rendered =
citation_compaction_tail_directive_with_prompt(&default_with_persistent, None);
assert!(auto_rendered.contains("1. Primary Request and Intent:"));
assert!(auto_rendered.contains(
"**User-provided context for this compaction:**\nAlways preserve auth invariants."
));
assert!(!auto_rendered.contains("{user_context_section}"));
let merged_rendered = citation_compaction_tail_directive_with_prompt(
&default_with_persistent,
Some("preserve migrations"),
);
assert!(merged_rendered.contains(
"**User-provided context for this compaction:**\nAlways preserve auth invariants.\n\npreserve migrations"
));
let custom_only = CompactionPrompt::custom("Summarize endpoints and open risks.")
.expect("valid custom prompt");
let custom_without_focus = citation_compaction_tail_directive_with_prompt(&custom_only, None);
assert_eq!(custom_without_focus, "Summarize endpoints and open risks.");
let custom_with_manual_focus =
citation_compaction_tail_directive_with_prompt(&custom_only, Some("focus on billing"));
assert!(custom_with_manual_focus.starts_with("Summarize endpoints and open risks."));
assert!(
custom_with_manual_focus
.contains("**User-provided context for this compaction:**\nfocus on billing")
);
let custom_with_both = custom_only
.with_user_context("Keep API compatibility.")
.expect("valid user context");
let both_rendered =
citation_compaction_tail_directive_with_prompt(&custom_with_both, Some("focus on billing"));
assert!(both_rendered.starts_with("Summarize endpoints and open risks."));
assert!(both_rendered.contains(
"**User-provided context for this compaction:**\nKeep API compatibility.\n\nfocus on billing"
));
}