use std::path::Path;
use mentra::agent::AutoCompactTrigger;
use super::*;
fn transcripts() -> PathBuf {
PathBuf::from("/store/transcripts")
}
#[test]
fn nothing_the_model_read_is_elided_by_default() {
let config = Compaction::default().into_mentra(transcripts());
assert_eq!(config.keep_recent_tool_results, usize::MAX);
assert_eq!(config.projected_tool_result_budget, None);
}
#[test]
fn the_summarizing_triggers_are_still_mentras() {
let config = Compaction::default().into_mentra(transcripts());
let mentra = mentra::agent::CompactionConfig::default();
assert_eq!(
config.auto_compact_threshold_tokens,
mentra.auto_compact_threshold_tokens
);
assert_eq!(config.auto_compact_threshold_tokens, Some(50_000));
assert_eq!(
config.auto_compact_threshold_percent,
mentra.auto_compact_threshold_percent
);
assert_eq!(config.auto_compact_threshold_percent, Some(75));
assert_eq!(
config.preserve_recent_user_tokens,
mentra.preserve_recent_user_tokens
);
}
#[test]
fn every_inherited_knob_stays_at_mentras_default() {
let config = Compaction::default().into_mentra(transcripts());
let mentra = mentra::agent::CompactionConfig::default();
assert_eq!(
config.summary_max_input_chars,
mentra.summary_max_input_chars
);
assert_eq!(
config.summary_max_output_tokens,
mentra.summary_max_output_tokens
);
assert_eq!(config.mode, mentra.mode);
assert_eq!(
config.preserve_recent_delegation_results,
mentra.preserve_recent_delegation_results
);
assert_eq!(
config.max_persisted_transcripts,
mentra.max_persisted_transcripts
);
assert_eq!(config.projected_tool_result_budget, None);
}
#[test]
fn a_host_that_asks_for_elision_by_number_gets_that_number() {
let config = Compaction::default()
.with_keep_recent_tool_results(Some(3))
.into_mentra(transcripts());
assert_eq!(config.keep_recent_tool_results, 3);
assert_eq!(config.projected_tool_result_budget, None);
}
#[test]
fn every_knob_reaches_the_config_mentra_reads() {
let config = Compaction::default()
.with_keep_recent_tool_results(Some(7))
.with_auto_threshold_tokens(Some(180_000))
.with_auto_threshold_percent(Some(90))
.with_preserve_recent_user_tokens(4_000)
.into_mentra(transcripts());
assert_eq!(config.keep_recent_tool_results, 7);
assert_eq!(config.auto_compact_threshold_tokens, Some(180_000));
assert_eq!(config.auto_compact_threshold_percent, Some(90));
assert_eq!(config.preserve_recent_user_tokens, 4_000);
}
#[test]
fn clearing_the_absolute_threshold_leaves_the_window_share_as_the_whole_trigger() {
let config = Compaction::default()
.with_auto_threshold_tokens(None)
.into_mentra(transcripts());
assert_eq!(
config.auto_compact_trigger,
AutoCompactTrigger::WindowShareOnly
);
assert_eq!(config.auto_compact_threshold_tokens, None);
assert_eq!(config.auto_compact_threshold_percent, Some(75));
assert_eq!(
config.auto_compact_threshold(Some(200_000)),
Some(150_000),
"a known window is now the whole trigger rather than a revived one"
);
assert_eq!(
config.auto_compact_threshold(None),
None,
"and an unknown window compacts at nothing, rather than at a guess"
);
assert!(config.auto_compact_enabled());
}
#[test]
fn clearing_both_numbers_is_the_only_spelling_of_off() {
let config = Compaction::default()
.with_auto_threshold_tokens(None)
.with_auto_threshold_percent(None)
.into_mentra(transcripts());
assert_eq!(config.auto_compact_trigger, AutoCompactTrigger::Off);
assert!(!config.auto_compact_enabled());
assert_eq!(config.auto_compact_threshold(Some(200_000)), None);
assert_eq!(config.auto_compact_threshold(None), None);
}
#[test]
fn a_known_window_is_what_the_percent_trigger_reads_when_both_are_set() {
let config = Compaction::default().into_mentra(transcripts());
assert_eq!(config.auto_compact_trigger, AutoCompactTrigger::Thresholds);
assert_eq!(config.auto_compact_threshold(Some(200_000)), Some(150_000));
assert_eq!(
config.auto_compact_threshold(None),
Some(50_000),
"and an unknown window falls back to the absolute number"
);
}
#[test]
fn an_unset_percent_pins_the_trigger_to_the_absolute_number() {
let config = Compaction::default()
.with_auto_threshold_percent(None)
.into_mentra(transcripts());
assert_eq!(config.auto_compact_trigger, AutoCompactTrigger::Thresholds);
assert_eq!(config.auto_compact_threshold_percent, None);
assert_eq!(config.auto_compact_threshold_tokens, Some(50_000));
assert_eq!(config.auto_compact_threshold(Some(200_000)), Some(50_000));
}
#[test]
fn setters_return_new_values() {
let base = Compaction::default();
let derived = base.with_keep_recent_tool_results(Some(1));
assert_eq!(base.keep_recent_tool_results, None, "the original moved");
assert_eq!(derived.keep_recent_tool_results, Some(1));
}
#[test]
fn the_snapshot_directory_is_the_one_it_was_given() {
let config = Compaction::default().into_mentra(PathBuf::from("/elsewhere/transcripts"));
assert_eq!(config.transcript_dir, Path::new("/elsewhere/transcripts"));
}