-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
141 lines (120 loc) · 4.54 KB
/
Copy pathlib.rs
File metadata and controls
141 lines (120 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! loust-llm-mempipe — public library surface.
//!
//! Re-exports the contract types that downstream tooling (MCP servers,
//! Claude Code plugins, RAG indexers) can consume without depending on
//! the binary CLI shape.
pub mod adapter;
pub mod config;
pub mod pipeline;
// Test-only fixtures. `#[doc(hidden)]` keeps this out of rustdoc;
// `pub` is required so integration tests under `tests/` can import it.
#[doc(hidden)]
pub mod test_fixtures;
pub use adapter::{Adapter, AdapterKind};
pub use config::{OutputFormat, PipelineConfig, SecretKind};
pub use pipeline::{NormalizedMessage, Pipeline, PipelineOutput, PipelineStats, Role};
#[cfg(test)]
mod tests {
use super::*;
// --- NormalizedMessage helpers ---
#[test]
fn compute_content_hash_is_deterministic() {
let a = NormalizedMessage::compute_content_hash("hello world");
let b = NormalizedMessage::compute_content_hash("hello world");
assert_eq!(a, b, "same input must produce same hash");
}
#[test]
fn compute_content_hash_differs_for_different_input() {
let a = NormalizedMessage::compute_content_hash("hello world");
let b = NormalizedMessage::compute_content_hash("hello, world");
assert_ne!(a, b);
}
#[test]
fn slugify_lowercases_and_replaces_non_alnum() {
assert_eq!(
NormalizedMessage::slugify("Project Alpha!"),
"project-alpha"
);
assert_eq!(
NormalizedMessage::slugify(" multi space "),
"multi-space"
);
assert_eq!(NormalizedMessage::slugify("___"), "untitled");
assert_eq!(NormalizedMessage::slugify("CamelCase42"), "camelcase42");
}
#[test]
fn slugify_caps_length_at_64() {
let long = "a".repeat(200);
let slug = NormalizedMessage::slugify(&long);
assert!(slug.len() <= 64, "slug should be capped at 64 chars");
}
// --- Role ---
#[test]
fn role_as_str_matches_serde_lowercase() {
assert_eq!(Role::User.as_str(), "user");
assert_eq!(Role::Assistant.as_str(), "assistant");
assert_eq!(Role::System.as_str(), "system");
assert_eq!(Role::Tool.as_str(), "tool");
}
#[test]
fn role_serializes_lowercase() {
let r = serde_json::to_string(&Role::Assistant).unwrap();
assert_eq!(r, "\"assistant\"");
}
// --- PipelineConfig defaults ---
#[test]
fn defaults_have_safe_thresholds() {
let cfg = PipelineConfig::with_safe_defaults();
assert!((cfg.dedup_threshold - 0.85).abs() < f64::EPSILON);
assert!((cfg.signal_min - 0.2).abs() < f64::EPSILON);
assert_eq!(cfg.max_thread_age_days, 1095);
assert_eq!(cfg.output_format, OutputFormat::Jsonl);
assert!(!cfg.dry_run);
}
#[test]
fn defaults_include_core_secret_patterns() {
let cfg = PipelineConfig::with_safe_defaults();
let labels: Vec<&str> = cfg.secret_patterns.iter().map(|(k, _)| k.label()).collect();
assert!(labels.contains(&"aws_key"));
assert!(labels.contains(&"github_token"));
assert!(labels.contains(&"anthropic_key"));
assert!(labels.contains(&"openai_key"));
assert!(labels.contains(&"private_ip"));
assert!(labels.contains(&"email"));
}
#[test]
fn scrubber_patterns_match_realistic_secrets() {
use crate::test_fixtures::{
FAKE_ANTHROPIC_API_KEY, FAKE_AWS_ACCESS_KEY, FAKE_EMAIL, FAKE_GITHUB_TOKEN,
};
let cfg = PipelineConfig::with_safe_defaults();
let sample = format!("key={} leaked", FAKE_AWS_ACCESS_KEY);
let aws_pat = cfg
.secret_patterns
.iter()
.find(|(k, _)| k == &SecretKind::AwsAccessKey)
.unwrap();
assert!(aws_pat.1.is_match(&sample));
let sample = format!("Authorization: {}", FAKE_ANTHROPIC_API_KEY);
let ant_pat = cfg
.secret_patterns
.iter()
.find(|(k, _)| k == &SecretKind::AnthropicApiKey)
.unwrap();
assert!(ant_pat.1.is_match(&sample));
let sample = FAKE_GITHUB_TOKEN;
let gh_pat = cfg
.secret_patterns
.iter()
.find(|(k, _)| k == &SecretKind::GitHubToken)
.unwrap();
assert!(gh_pat.1.is_match(sample));
let sample = format!("reach me at {}", FAKE_EMAIL);
let email_pat = cfg
.secret_patterns
.iter()
.find(|(k, _)| k == &SecretKind::EmailAddress)
.unwrap();
assert!(email_pat.1.is_match(&sample));
}
}