Skip to main content

zeph_tools/compression/
identity.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! No-op compressor used when `[tools.compression] enabled = false`.
5
6use std::future::Future;
7use std::pin::Pin;
8
9use zeph_common::ToolName;
10
11use super::{CompressionError, OutputCompressor};
12
13/// Pass-through compressor that never modifies tool output.
14///
15/// Used as the default compressor when `[tools.compression] enabled = false`.
16/// The `compress` method always returns `Ok(None)`.
17///
18/// # Examples
19///
20/// ```rust
21/// # let rt = tokio::runtime::Runtime::new().unwrap();
22/// # rt.block_on(async {
23/// use zeph_tools::compression::{IdentityCompressor, OutputCompressor};
24/// use zeph_common::ToolName;
25/// let c = IdentityCompressor;
26/// let name = ToolName::new("shell");
27/// let result = c.compress(&name, "some output").await;
28/// assert!(result.unwrap().is_none());
29/// # });
30/// ```
31#[derive(Debug, Default, Clone)]
32pub struct IdentityCompressor;
33
34impl OutputCompressor for IdentityCompressor {
35    fn compress<'a>(
36        &'a self,
37        _tool_name: &'a ToolName,
38        _output: &'a str,
39    ) -> Pin<Box<dyn Future<Output = Result<Option<String>, CompressionError>> + Send + 'a>> {
40        Box::pin(std::future::ready(Ok(None)))
41    }
42
43    fn name(&self) -> &'static str {
44        "identity"
45    }
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[tokio::test]
53    async fn identity_always_passes_through() {
54        let c = IdentityCompressor;
55        let name = ToolName::new("shell");
56        let result = c.compress(&name, "hello world").await.unwrap();
57        assert!(result.is_none());
58    }
59}