Eight closed tasks for epochs and compaction, then ten for the scheduler, ToolSummary, and tiers. Given tests first. Gate 1456 → 1507 → 1572. Co-Authored-By: Grok 4.6 <noreply@x.ai>
80 lines
2.2 KiB
Rust
80 lines
2.2 KiB
Rust
//! Tests for when compaction is due and for the fallback summary. Do not edit.
|
|
|
|
use bxcore::{Epoch, Hash32, LogRecord, SessionId, Timestamp, Usage};
|
|
use loopd::compact::{due, fallback_summary};
|
|
|
|
fn usage(cache_n: u64, prompt_n: u64) -> Usage {
|
|
Usage {
|
|
cache_n,
|
|
prompt_n,
|
|
predicted_n: 0,
|
|
reasoning_tokens: 0,
|
|
thinking_capped: false,
|
|
}
|
|
}
|
|
|
|
fn user(content: &str) -> LogRecord {
|
|
LogRecord::User {
|
|
time: Timestamp::parse("2026-09-18T08:00:00.000Z").unwrap(),
|
|
content: content.to_string(),
|
|
speaker: None,
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn due_at_the_threshold_and_not_below() {
|
|
assert!(!due(&usage(400, 449), 0.85, 1_000), "849 < 850");
|
|
assert!(due(&usage(400, 450), 0.85, 1_000), "850 == 0.85 * 1000");
|
|
assert!(due(&usage(0, 851), 0.85, 1_000));
|
|
assert!(!due(&usage(0, 0), 0.85, 1_000));
|
|
}
|
|
|
|
#[test]
|
|
fn due_uses_this_agents_n_ctx() {
|
|
// 0.85 * 262144 = 222822.4, so 222823 is the first integer at or above.
|
|
assert!(!due(&usage(0, 222_822), 0.85, 262_144));
|
|
assert!(due(&usage(0, 222_823), 0.85, 262_144));
|
|
assert!(due(&usage(200_000, 22_823), 0.85, 262_144));
|
|
}
|
|
|
|
#[test]
|
|
fn a_threshold_of_one_is_the_full_window() {
|
|
assert!(!due(&usage(99, 0), 1.0, 100));
|
|
assert!(due(&usage(100, 0), 1.0, 100));
|
|
}
|
|
|
|
#[test]
|
|
fn fallback_is_user_texts_newest_last() {
|
|
let records = vec![
|
|
LogRecord::SessionStart {
|
|
time: Timestamp::parse("2026-09-18T08:00:00.000Z").unwrap(),
|
|
session: SessionId::new("a").unwrap(),
|
|
epoch: Epoch(0),
|
|
slot: 0,
|
|
baseline: Hash32::ZERO,
|
|
},
|
|
user("first"),
|
|
user("second"),
|
|
user("third"),
|
|
];
|
|
assert_eq!(
|
|
fallback_summary(&records, 4_000),
|
|
"third\n\nsecond\n\nfirst"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn fallback_is_cut_to_summary_chars_on_a_character_boundary() {
|
|
let records = vec![user("café"), user("ab")];
|
|
assert_eq!(fallback_summary(&records, 3), "ab\n");
|
|
assert_eq!(fallback_summary(&records, 1), "a");
|
|
assert_eq!(fallback_summary(&records, 0), "");
|
|
let long = user("ååå");
|
|
assert_eq!(fallback_summary(&[long], 2), "åå");
|
|
}
|
|
|
|
#[test]
|
|
fn fallback_with_no_users_is_empty() {
|
|
assert_eq!(fallback_summary(&[], 100), "");
|
|
}
|