pub(crate) mod apply;
pub(crate) mod compactor;
pub(crate) mod runtime;
pub(crate) mod summary_event;
pub(crate) mod tail_retention;
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
pub(crate) mod test_support;
pub(crate) mod window;
use gadk_session::compaction::Config;
pub(crate) type BoxError = Box<dyn std::error::Error + Send + Sync>;
#[derive(Debug)]
struct Wrapped {
context: String,
source: BoxError,
}
impl std::fmt::Display for Wrapped {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}: {}", self.context, self.source)
}
}
impl std::error::Error for Wrapped {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&*self.source)
}
}
pub(crate) fn wrap_err(context: impl Into<String>, err: BoxError) -> BoxError {
Box::new(Wrapped {
context: context.into(),
source: err,
})
}
pub(crate) fn err_text(text: impl Into<String>) -> BoxError {
text.into().into()
}
pub(crate) fn has_sliding_window(cfg: Option<&Config>) -> bool {
cfg.is_some_and(|c| c.compaction_interval > 0)
}
pub(crate) fn has_tail_retention(cfg: Option<&Config>) -> bool {
cfg.is_some_and(|c| c.token_threshold > 0)
}
pub(crate) trait ProgressGate: Send + Sync {
fn allow_at(&self) -> bool;
fn record_at(&self, tokens: i64);
fn recovered(&self);
fn failed(&self);
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod tests {
use super::*;
#[test]
fn wrap_err_formats_and_chains_like_go() {
let e = wrap_err("sliding-window summarization failed", err_text("boom"));
assert_eq!(e.to_string(), "sliding-window summarization failed: boom");
assert_eq!(e.source().unwrap().to_string(), "boom");
}
#[test]
fn strategy_predicates_follow_go() {
assert!(!has_sliding_window(None));
assert!(!has_tail_retention(None));
let c = Config {
compaction_interval: 1,
token_threshold: 1,
..Default::default()
};
assert!(has_sliding_window(Some(&c)) && has_tail_retention(Some(&c)));
assert!(!has_sliding_window(Some(&Config::default())));
assert!(!has_tail_retention(Some(&Config::default())));
}
}