use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use fs2::FileExt;
use tokio::sync::Mutex;
pub const CAPTURE_LOCK_FILE: &str = ".serial-mcp-captures.lock";
pub const CAPTURE_TEMP_PREFIX: &str = ".serial-mcp-capture-";
pub const CAPTURE_RESERVED_PREFIX: &str = ".serial-mcp-";
pub const MAX_CAPTURE_FILENAME_LEN: usize = 120;
pub const CAPTURE_FILENAME_SUFFIX: &str = ".jsonl";
pub const CAPTURE_DISABLED_ERROR: &str =
"Persistent capture is disabled; start serial-mcp with --capture-dir <absolute-directory>";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CaptureLimits {
pub max_file_bytes: u64,
pub max_total_bytes: u64,
pub max_files: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CaptureWriteResult {
pub path: PathBuf,
pub bytes_written: u64,
pub files_used: usize,
pub total_bytes_used: u64,
pub durability_warning: Option<String>,
}
#[derive(Debug)]
pub struct CaptureStore {
root: Option<PathBuf>,
limits: CaptureLimits,
lock: Mutex<()>,
}
impl CaptureStore {
pub fn disabled() -> Self {
Self {
root: None,
limits: CaptureLimits {
max_file_bytes: 0,
max_total_bytes: 0,
max_files: 0,
},
lock: Mutex::new(()),
}
}
pub fn open(root: PathBuf, limits: CaptureLimits) -> Result<Self, String> {
if !root.is_absolute() {
return Err(format!(
"capture dir must be an absolute path: {}",
root.display()
));
}
if limits.max_file_bytes == 0 || limits.max_total_bytes == 0 || limits.max_files == 0 {
return Err("capture limits must all be > 0".to_string());
}
if limits.max_file_bytes > limits.max_total_bytes {
return Err(format!(
"capture per-file limit ({}) must be <= total limit ({})",
limits.max_file_bytes, limits.max_total_bytes
));
}
let meta = std::fs::symlink_metadata(&root)
.map_err(|e| format!("capture dir {}: {e}", root.display()))?;
if meta.file_type().is_symlink() {
return Err(format!(
"capture dir must not be a symlink: {}",
root.display()
));
}
if !meta.is_dir() {
return Err(format!(
"capture dir is not a directory: {}",
root.display()
));
}
let canonical = root
.canonicalize()
.map_err(|e| format!("cannot canonicalize capture dir {}: {e}", root.display()))?;
let lock_file = acquire_root_lock(&canonical)?;
fs2::FileExt::unlock(&lock_file)
.map_err(|e| format!("cannot release capture lock: {e}"))?;
Ok(Self {
root: Some(canonical),
limits,
lock: Mutex::new(()),
})
}
pub fn is_enabled(&self) -> bool {
self.root.is_some()
}
pub fn max_file_bytes(&self) -> u64 {
self.limits.max_file_bytes
}
pub fn root(&self) -> Option<&Path> {
self.root.as_deref()
}
pub async fn write_new(
&self,
requested_name: String,
bytes: Vec<u8>,
) -> Result<CaptureWriteResult, String> {
let Some(root) = self.root.clone() else {
return Err(CAPTURE_DISABLED_ERROR.to_string());
};
validate_capture_filename(&requested_name)?;
let bytes_len = u64::try_from(bytes.len())
.map_err(|_| "capture file size does not fit a u64 counter".to_string())?;
if bytes_len > self.limits.max_file_bytes {
return Err(format!(
"capture file exceeds per-file quota: {bytes_len} bytes > --capture-max-file-bytes {}",
self.limits.max_file_bytes
));
}
let limits = self.limits;
let _guard = self.lock.lock().await;
tokio::task::spawn_blocking(move || commit_new_file(&root, &requested_name, &bytes, limits))
.await
.map_err(|e| format!("capture commit task failed: {e}"))?
}
}
pub fn validate_capture_filename(name: &str) -> Result<(), String> {
if name.is_empty() {
return Err("capture filename is empty".to_string());
}
if name.len() > MAX_CAPTURE_FILENAME_LEN {
return Err(format!(
"capture filename exceeds {MAX_CAPTURE_FILENAME_LEN} characters (including '.jsonl')"
));
}
if !name.is_ascii() {
return Err("capture filename must be ASCII".to_string());
}
if name == "." || name == ".." {
return Err("capture filename must not be '.' or '..'".to_string());
}
if name.contains('/') || name.contains('\\') {
return Err("capture filename must not contain path separators".to_string());
}
if !name.ends_with(CAPTURE_FILENAME_SUFFIX) {
return Err(format!(
"capture filename must end with '{CAPTURE_FILENAME_SUFFIX}'"
));
}
if name.contains(CAPTURE_RESERVED_PREFIX) {
return Err(format!(
"capture filename must not contain the reserved internal prefix '{CAPTURE_RESERVED_PREFIX}'"
));
}
let bytes = name.as_bytes();
if !bytes[0].is_ascii_alphanumeric() {
return Err("capture filename must start with an alphanumeric character".to_string());
}
for &b in &bytes[1..] {
if !(b.is_ascii_alphanumeric() || b == b'.' || b == b'_' || b == b'-') {
return Err(
"capture filename may only contain alphanumeric, '.', '_', and '-'".to_string(),
);
}
}
let stem = name.split('.').next().unwrap_or(name);
if is_windows_reserved_stem(stem) {
return Err(format!(
"capture filename uses reserved stem '{stem}' (Windows device names are rejected)"
));
}
Ok(())
}
fn is_windows_reserved_stem(stem: &str) -> bool {
let upper = stem.to_ascii_uppercase();
if matches!(upper.as_str(), "CON" | "PRN" | "AUX" | "NUL") {
return true;
}
let reserved_numeric = |prefix: &str| {
let Some(tail) = upper.strip_prefix(prefix) else {
return false;
};
tail.len() == 1 && tail.as_bytes()[0].is_ascii_digit() && tail.as_bytes()[0] != b'0'
};
reserved_numeric("COM") || reserved_numeric("LPT")
}
fn is_managed_capture_filename(name: &str) -> bool {
validate_capture_filename(name).is_ok()
}
fn acquire_root_lock(root: &Path) -> Result<File, String> {
let lock_path = root.join(CAPTURE_LOCK_FILE);
match std::fs::symlink_metadata(&lock_path) {
Ok(meta) => {
if meta.file_type().is_symlink() {
return Err(format!(
"capture lock path is a symlink: {}",
lock_path.display()
));
}
if !meta.is_file() {
return Err(format!(
"capture lock path is not a regular file: {}",
lock_path.display()
));
}
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
Err(e) => {
return Err(format!(
"cannot stat capture lock path {}: {e}",
lock_path.display()
))
}
}
let file = std::fs::OpenOptions::new()
.create(true)
.truncate(false)
.read(true)
.write(true)
.open(&lock_path)
.map_err(|e| format!("cannot open capture lock file {}: {e}", lock_path.display()))?;
file.lock_exclusive()
.map_err(|e| format!("cannot lock capture root {}: {e}", lock_path.display()))?;
Ok(file)
}
#[derive(Debug)]
struct RootUsage {
files: usize,
total_bytes: u64,
}
fn scan_managed_usage(root: &Path) -> Result<RootUsage, String> {
let entries = std::fs::read_dir(root)
.map_err(|e| format!("cannot scan capture dir {}: {e}", root.display()))?;
let mut files: usize = 0;
let mut total_bytes: u64 = 0;
for entry in entries {
let entry = entry.map_err(|e| format!("cannot read capture dir entry: {e}"))?;
let Some(name) = entry.file_name().to_str().map(str::to_owned) else {
continue;
};
if name == CAPTURE_LOCK_FILE || name.starts_with(CAPTURE_TEMP_PREFIX) {
continue;
}
if !is_managed_capture_filename(&name) {
continue;
}
let meta = std::fs::symlink_metadata(entry.path())
.map_err(|e| format!("cannot stat capture entry {}: {e}", entry.path().display()))?;
if meta.file_type().is_symlink() {
return Err(format!(
"symlink entry with a managed capture name is rejected: {}",
entry.path().display()
));
}
if !meta.is_file() {
continue;
}
files = files
.checked_add(1)
.ok_or_else(|| "capture file count overflow".to_string())?;
total_bytes = total_bytes
.checked_add(meta.len())
.ok_or_else(|| "capture total byte count overflow".to_string())?;
}
Ok(RootUsage { files, total_bytes })
}
fn commit_new_file(
root: &Path,
name: &str,
bytes: &[u8],
limits: CaptureLimits,
) -> Result<CaptureWriteResult, String> {
validate_capture_filename(name)?;
let bytes_len = u64::try_from(bytes.len())
.map_err(|_| "capture file size does not fit a u64 counter".to_string())?;
if bytes_len > limits.max_file_bytes {
return Err(format!(
"capture file exceeds per-file quota: {bytes_len} bytes > --capture-max-file-bytes {}",
limits.max_file_bytes
));
}
let _lock_file = acquire_root_lock(root)?;
let usage = scan_managed_usage(root)?;
let dest = root.join(name);
match std::fs::symlink_metadata(&dest) {
Ok(_) => {
return Err(format!(
"capture destination already exists (no overwrite): {}",
dest.display()
))
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
Err(e) => {
return Err(format!(
"cannot stat capture destination {}: {e}",
dest.display()
))
}
}
let new_files = usage
.files
.checked_add(1)
.ok_or_else(|| "capture file count overflow".to_string())?;
if new_files > limits.max_files {
return Err(format!(
"capture file-count quota exceeded: {new_files} files > --capture-max-files {}",
limits.max_files
));
}
let new_total = usage
.total_bytes
.checked_add(bytes_len)
.ok_or_else(|| "capture total byte quota overflow".to_string())?;
if new_total > limits.max_total_bytes {
return Err(format!(
"capture total-byte quota exceeded: {new_total} bytes > --capture-max-total-bytes {}",
limits.max_total_bytes
));
}
let mut tmp = tempfile::Builder::new()
.prefix(CAPTURE_TEMP_PREFIX)
.tempfile_in(root)
.map_err(|e| format!("cannot create capture temp file in {}: {e}", root.display()))?;
tmp.write_all(bytes)
.map_err(|e| format!("cannot write capture temp file: {e}"))?;
tmp.as_file()
.sync_all()
.map_err(|e| format!("cannot sync capture temp file: {e}"))?;
let committed = tmp
.persist_noclobber(&dest)
.map_err(|e| format!("capture commit failed: {}", e.error))?;
drop(committed);
let durability_warning = sync_root_dir(root).err();
Ok(CaptureWriteResult {
path: dest,
bytes_written: bytes_len,
files_used: new_files,
total_bytes_used: new_total,
durability_warning,
})
}
#[cfg(unix)]
fn sync_root_dir(root: &Path) -> Result<(), String> {
#[cfg(test)]
if FAIL_ROOT_SYNC.load(std::sync::atomic::Ordering::Relaxed) {
return Err("injected root directory sync failure".to_string());
}
File::open(root)
.and_then(|f| f.sync_all())
.map_err(|e| format!("cannot sync capture dir {}: {e}", root.display()))
}
#[cfg(not(unix))]
fn sync_root_dir(_root: &Path) -> Result<(), String> {
Ok(())
}
#[cfg(all(test, unix))]
static FAIL_ROOT_SYNC: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
#[cfg(test)]
mod tests {
use super::*;
use std::sync::Arc as StdArc;
fn limits() -> CaptureLimits {
CaptureLimits {
max_file_bytes: 1024,
max_total_bytes: 4096,
max_files: 8,
}
}
#[test]
fn validate_accepts_portable_names() {
for name in [
"boot.log.jsonl",
"a.jsonl",
"session-2026-08-01.jsonl",
"LOG_01.jsonl",
"x.jsonl",
] {
assert!(
validate_capture_filename(name).is_ok(),
"expected {name:?} to be valid"
);
}
}
#[test]
fn validate_rejects_traversal_and_paths() {
for name in [
"",
"..",
".",
"a/b.jsonl",
"a\\b.jsonl",
"/abs.jsonl",
"sub/name.jsonl",
"name.jsonl/",
"con.jsonl",
"CON.jsonl",
"Prn",
"prn.jsonl",
"aux.jsonl",
"NUL.jsonl",
"com1.jsonl",
"COM9.jsonl",
"lpt1.jsonl",
"LPT9.jsonl",
"com10.jsonl", ] {
let expected_ok = name == "com10.jsonl";
assert_eq!(
validate_capture_filename(name).is_ok(),
expected_ok,
"unexpected verdict for {name:?}"
);
}
}
#[test]
fn validate_rejects_bad_shape() {
for name in [
"name.txt",
"name.json",
"name.JSONL", ".jsonl", "-a.jsonl", "_a.jsonl", "a b.jsonl", "a$b.jsonl", "a😀b.jsonl", ".serial-mcp-capture-foo.jsonl", "a.serial-mcp-b.jsonl", &format!(
"{}.jsonl",
"a".repeat(MAX_CAPTURE_FILENAME_LEN + 1 - CAPTURE_FILENAME_SUFFIX.len())
), ] {
assert!(
validate_capture_filename(name).is_err(),
"expected {name:?} to be rejected"
);
}
let max_len = MAX_CAPTURE_FILENAME_LEN - CAPTURE_FILENAME_SUFFIX.len();
let at_limit = format!("{}.jsonl", "a".repeat(max_len));
assert!(validate_capture_filename(&at_limit).is_ok());
let over_limit = format!("{}.jsonl", "a".repeat(max_len + 1));
assert!(validate_capture_filename(&over_limit).is_err());
}
#[test]
fn open_rejects_invalid_roots() {
assert!(CaptureStore::open("relative".into(), limits()).is_err());
let missing = tempfile::tempdir().unwrap();
let missing = missing.path().join("nope");
assert!(CaptureStore::open(missing, limits()).is_err());
let file_dir = tempfile::tempdir().unwrap();
let file_path = file_dir.path().join("not-a-dir");
std::fs::write(&file_path, b"x").unwrap();
assert!(CaptureStore::open(file_path, limits()).is_err());
let dir = tempfile::tempdir().unwrap();
let zero = CaptureLimits {
max_file_bytes: 0,
..limits()
};
assert!(CaptureStore::open(dir.path().to_path_buf(), zero).is_err());
let bad_rel = CaptureLimits {
max_file_bytes: 2048,
max_total_bytes: 1024,
max_files: 8,
};
assert!(CaptureStore::open(dir.path().to_path_buf(), bad_rel).is_err());
}
#[cfg(unix)]
#[test]
fn open_rejects_symlink_root() {
let dir = tempfile::tempdir().unwrap();
let target = dir.path().join("real");
std::fs::create_dir(&target).unwrap();
let link = dir.path().join("link");
std::os::unix::fs::symlink(&target, &link).unwrap();
assert!(CaptureStore::open(link, limits()).is_err());
}
#[cfg(unix)]
#[test]
fn open_rejects_symlink_lock_file() {
let dir = tempfile::tempdir().unwrap();
let outside = tempfile::tempdir().unwrap();
let target = outside.path().join("victim");
std::fs::write(&target, b"lock").unwrap();
std::os::unix::fs::symlink(&target, dir.path().join(CAPTURE_LOCK_FILE)).unwrap();
let err = CaptureStore::open(dir.path().to_path_buf(), limits()).unwrap_err();
assert!(err.contains("symlink"), "got: {err}");
}
#[test]
fn scan_classifies_managed_files() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join("a.jsonl"), b"12345").unwrap();
std::fs::write(dir.path().join("b.jsonl"), b"123").unwrap();
std::fs::write(dir.path().join("notes.txt"), b"xx").unwrap();
std::fs::write(dir.path().join("CON.jsonl"), b"xx").unwrap();
std::fs::create_dir(dir.path().join("d.jsonl")).unwrap();
std::fs::write(dir.path().join(CAPTURE_LOCK_FILE), b"").unwrap();
std::fs::write(
dir.path().join(format!("{CAPTURE_TEMP_PREFIX}abc")),
b"temp",
)
.unwrap();
let usage = scan_managed_usage(dir.path()).unwrap();
assert_eq!(usage.files, 2);
assert_eq!(usage.total_bytes, 8);
}
#[cfg(unix)]
#[test]
fn scan_rejects_managed_name_symlink() {
let dir = tempfile::tempdir().unwrap();
let outside = tempfile::tempdir().unwrap();
std::fs::write(outside.path().join("victim"), b"data").unwrap();
std::os::unix::fs::symlink(outside.path().join("victim"), dir.path().join("a.jsonl"))
.unwrap();
let err = scan_managed_usage(dir.path()).unwrap_err();
assert!(err.contains("symlink"), "got: {err}");
assert_eq!(
std::fs::read(outside.path().join("victim")).unwrap(),
b"data"
);
}
#[tokio::test]
async fn write_new_commits_and_reports_usage() {
let dir = tempfile::tempdir().unwrap();
let store = CaptureStore::open(dir.path().to_path_buf(), limits()).unwrap();
let canonical_root = std::fs::canonicalize(dir.path()).unwrap();
assert_eq!(store.root(), Some(canonical_root.as_path()));
let res = store
.write_new("boot.jsonl".into(), b"line1\n".to_vec())
.await
.unwrap();
assert_eq!(res.path.parent(), Some(canonical_root.as_path()));
assert!(res.path.starts_with(&canonical_root));
assert_eq!(res.path.file_name().unwrap(), "boot.jsonl");
assert_eq!(res.bytes_written, 6);
assert_eq!(res.files_used, 1);
assert_eq!(res.total_bytes_used, 6);
assert_eq!(std::fs::read(&res.path).unwrap(), b"line1\n");
let leftovers: Vec<_> = std::fs::read_dir(dir.path())
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| {
e.file_name()
.to_string_lossy()
.starts_with(CAPTURE_TEMP_PREFIX)
})
.collect();
assert!(leftovers.is_empty());
}
#[tokio::test]
async fn write_new_no_clobber_keeps_original_byte_identical() {
let dir = tempfile::tempdir().unwrap();
let store = CaptureStore::open(dir.path().to_path_buf(), limits()).unwrap();
let first = store
.write_new("a.jsonl".into(), b"one".to_vec())
.await
.unwrap();
let err = store
.write_new("a.jsonl".into(), b"two".to_vec())
.await
.unwrap_err();
assert!(
err.contains("no overwrite") || err.contains("already exists"),
"got: {err}"
);
assert_eq!(std::fs::read(&first.path).unwrap(), b"one");
assert_eq!(store.max_file_bytes(), 1024);
}
#[tokio::test]
async fn write_new_disabled_errors_before_any_file_work() {
let store = CaptureStore::disabled();
let err = store
.write_new("a.jsonl".into(), b"x".to_vec())
.await
.unwrap_err();
assert_eq!(err, CAPTURE_DISABLED_ERROR);
assert!(!store.is_enabled());
}
#[tokio::test]
async fn write_new_rejects_invalid_name_and_oversize_bytes() {
let dir = tempfile::tempdir().unwrap();
let store = CaptureStore::open(dir.path().to_path_buf(), limits()).unwrap();
let err = store
.write_new("../escape.jsonl".into(), vec![])
.await
.unwrap_err();
assert!(err.contains("separators"), "got: {err}");
let err = store
.write_new("big.jsonl".into(), vec![0u8; 2048])
.await
.unwrap_err();
assert!(err.contains("per-file quota"), "got: {err}");
assert!(!dir.path().join("big.jsonl").exists());
}
#[tokio::test]
async fn zero_byte_commit_consumes_one_file_slot() {
let dir = tempfile::tempdir().unwrap();
let l = CaptureLimits {
max_file_bytes: 1,
max_total_bytes: 1, max_files: 1,
};
let store = CaptureStore::open(dir.path().to_path_buf(), l).unwrap();
let res = store.write_new("empty.jsonl".into(), vec![]).await.unwrap();
assert_eq!(res.bytes_written, 0);
assert_eq!(res.files_used, 1);
let err = store
.write_new("empty2.jsonl".into(), vec![])
.await
.unwrap_err();
assert!(err.contains("file-count quota"), "got: {err}");
}
#[tokio::test]
async fn post_commit_root_sync_failure_is_a_warning_not_a_failed_commit() {
#[cfg(unix)]
{
let dir = tempfile::tempdir().unwrap();
let store = CaptureStore::open(dir.path().to_path_buf(), limits()).unwrap();
FAIL_ROOT_SYNC.store(true, std::sync::atomic::Ordering::Relaxed);
let res = store
.write_new("sync.jsonl".into(), b"durable?\n".to_vec())
.await
.unwrap();
FAIL_ROOT_SYNC.store(false, std::sync::atomic::Ordering::Relaxed);
assert!(res.path.is_file(), "the committed file must exist");
assert_eq!(res.files_used, 1);
assert_eq!(res.total_bytes_used, 9);
let warning = res
.durability_warning
.expect("root-sync failure must be reported as a warning");
assert!(warning.contains("sync"), "got: {warning}");
assert_eq!(std::fs::read(&res.path).unwrap(), b"durable?\n");
let res2 = store
.write_new("after.jsonl".into(), b"ok\n".to_vec())
.await
.unwrap();
assert_eq!(res2.files_used, 2);
assert!(res2.durability_warning.is_none());
}
#[cfg(not(unix))]
{
let dir = tempfile::tempdir().unwrap();
let store = CaptureStore::open(dir.path().to_path_buf(), limits()).unwrap();
let res = store
.write_new("sync.jsonl".into(), b"ok\n".to_vec())
.await
.unwrap();
assert!(res.durability_warning.is_none());
}
}
#[tokio::test]
async fn quotas_persist_across_fresh_store_instances() {
let dir = tempfile::tempdir().unwrap();
let l = CaptureLimits {
max_file_bytes: 64,
max_total_bytes: 64,
max_files: 4,
};
let s1 = CaptureStore::open(dir.path().to_path_buf(), l).unwrap();
let r1 = s1
.write_new("one.jsonl".into(), b"0123456789".repeat(4))
.await
.unwrap();
assert_eq!(r1.total_bytes_used, 40);
drop(s1);
let s2 = CaptureStore::open(dir.path().to_path_buf(), l).unwrap();
let err = s2
.write_new("two.jsonl".into(), b"0123456789".repeat(4))
.await
.unwrap_err();
assert!(err.contains("total-byte quota"), "got: {err}");
let r2 = s2
.write_new("two.jsonl".into(), b"0123456789".repeat(2))
.await
.unwrap();
assert_eq!(r2.files_used, 2);
assert_eq!(r2.total_bytes_used, 60);
}
#[tokio::test]
async fn concurrent_independent_stores_cannot_exceed_quota() {
let dir = StdArc::new(tempfile::tempdir().unwrap());
let l = CaptureLimits {
max_file_bytes: 10,
max_total_bytes: 10,
max_files: 2,
};
let s1 = StdArc::new(CaptureStore::open(dir.path().to_path_buf(), l).unwrap());
let s2 = StdArc::new(CaptureStore::open(dir.path().to_path_buf(), l).unwrap());
let barrier = StdArc::new(tokio::sync::Barrier::new(2));
let t1 = {
let s1 = StdArc::clone(&s1);
let b = StdArc::clone(&barrier);
tokio::spawn(async move {
b.wait().await;
s1.write_new("a.jsonl".into(), vec![0u8; 10]).await
})
};
let t2 = {
let s2 = StdArc::clone(&s2);
let b = StdArc::clone(&barrier);
tokio::spawn(async move {
b.wait().await;
s2.write_new("b.jsonl".into(), vec![0u8; 10]).await
})
};
let (r1, r2) = tokio::join!(t1, t2);
let outcomes = [r1.unwrap(), r2.unwrap()];
let ok: Vec<_> = outcomes.iter().filter(|o| o.is_ok()).collect();
let err: Vec<_> = outcomes.iter().filter(|o| o.is_err()).collect();
assert_eq!(ok.len(), 1, "exactly one concurrent commit may succeed");
assert_eq!(err.len(), 1);
assert!(
err[0].as_ref().unwrap_err().contains("quota"),
"got: {err:?}"
);
let usage = scan_managed_usage(dir.path()).unwrap();
assert_eq!(usage.files, 1);
assert_eq!(usage.total_bytes, 10);
}
#[tokio::test]
async fn file_count_quota_includes_prior_committed_files() {
let dir = tempfile::tempdir().unwrap();
let mut l = limits();
l.max_files = 2;
let store = CaptureStore::open(dir.path().to_path_buf(), l).unwrap();
store
.write_new("one.jsonl".into(), b"1".to_vec())
.await
.unwrap();
store
.write_new("two.jsonl".into(), b"2".to_vec())
.await
.unwrap();
let err = store
.write_new("three.jsonl".into(), b"3".to_vec())
.await
.unwrap_err();
assert!(err.contains("file-count quota"), "got: {err}");
assert!(!dir.path().join("three.jsonl").exists());
}
}