use std::fs;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicUsize, Ordering};
use std::time::{Duration, Instant, SystemTime};
use chrono::Utc;
use second_brain_api::backfill::{Backfill, BackfillStats, LiveIngest, transcripts_newest_first};
use second_brain_api::clock_gate::{ClockGate, TimeSignals};
use second_brain_api::health::{BackfillState, Health};
use second_brain_api::ingest::{FileOutcome, capture_transcript, ingest_file, ingest_memory_file};
use second_brain_core::sqlite_store::{SCHEMA_VERSION, SqliteStore, WallClock};
use second_brain_core::store::{Store, StoreAdmin};
use second_brain_core::transcript_archive::TranscriptArchive;
use serde_json::json;
const TURNS: [&str; 2] = [
"The watcher waits ten seconds for a transcript to settle before it ingests it, because Claude Code writes each turn in several appends.",
"We store the session key in ingest_log so a copied transcript is recognised by its content and session instead of by its absolute path.",
];
const TOPICS: [&str; 4] = ["parser", "scheduler", "exporter", "indexer"];
fn transcript(session: &str, turns: &[String]) -> String {
let mut lines = vec![json!({"type": "summary", "summary": "s"}).to_string()];
for (i, turn) in turns.iter().enumerate() {
lines.push(
json!({"type": "user", "sessionId": session, "message": {"content": format!("question {i}")}})
.to_string(),
);
lines.push(
json!({"type": "assistant", "sessionId": session,
"message": {"content": [{"type": "text", "text": turn}]}})
.to_string(),
);
}
lines.join("\n") + "\n"
}
fn turns_about(topic: &str) -> Vec<String> {
TURNS
.iter()
.map(|t| format!("In the {topic} module: {t}"))
.collect()
}
fn at(secs: u64) -> SystemTime {
SystemTime::UNIX_EPOCH + Duration::from_secs(secs)
}
fn set_mtime(path: &Path, secs: u64) {
fs::File::options()
.append(true)
.open(path)
.unwrap()
.set_modified(at(secs))
.unwrap();
}
fn write_file(path: &Path, content: &str, mtime_secs: u64) -> PathBuf {
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, content).unwrap();
set_mtime(path, mtime_secs);
path.to_path_buf()
}
struct Setup {
dir: tempfile::TempDir,
archive: Arc<TranscriptArchive>,
live: Arc<LiveIngest>,
health: Arc<Health>,
}
impl Setup {
fn new() -> Self {
let dir = tempfile::tempdir().unwrap();
let archive = Arc::new(TranscriptArchive::open(dir.path().join("archive")).unwrap());
Self {
dir,
archive,
live: Arc::new(LiveIngest::default()),
health: Arc::new(Health::new(Utc::now(), None)),
}
}
fn projects(&self) -> PathBuf {
self.dir.path().join("projects")
}
fn db_path(&self) -> PathBuf {
self.dir.path().join("brain.db")
}
fn open_store(&self) -> Arc<SqliteStore> {
Arc::new(SqliteStore::open(&self.db_path(), "m".to_string()).unwrap())
}
fn write(&self, rel: &str, session: &str, topic: &str, mtime_secs: u64) -> PathBuf {
write_file(
&self.projects().join(rel),
&transcript(session, &turns_about(topic)),
mtime_secs,
)
}
fn write_sessions(&self, n: usize) -> Vec<PathBuf> {
(0..n)
.map(|i| {
self.write(
&format!("-home-a-proj/s{i}.jsonl"),
&format!("sess-{i}"),
TOPICS[i],
1_000 + i as u64 * 100,
)
})
.collect()
}
fn backfill(&self, store: Arc<SqliteStore>, pause: Duration) -> Backfill {
Backfill {
store,
embedder: None,
machine_id: "m".to_string(),
projects_dir: self.projects(),
archive: Some(self.archive.clone()),
live: self.live.clone(),
health: self.health.clone(),
pause,
clock: ClockGate::open_for_tests(),
}
}
}
fn dyn_store(store: &Arc<SqliteStore>) -> Arc<dyn StoreAdmin> {
store.clone()
}
fn control_count(paths: &[PathBuf]) -> usize {
let store: Arc<dyn StoreAdmin> = Arc::new(SqliteStore::in_memory("m".to_string()).unwrap());
for path in paths {
ingest_file(&store, None, path, "m").unwrap();
}
let count = store.memory_count().unwrap();
assert!(count > 0, "the fixture transcripts must yield memories");
count
}
fn archive_blobs(dir: &Path) -> usize {
let mut blobs = 0;
let mut dirs = vec![dir.to_path_buf()];
while let Some(d) = dirs.pop() {
for entry in fs::read_dir(&d).unwrap().flatten() {
let path = entry.path();
if path.is_dir() {
dirs.push(path);
} else if path.to_string_lossy().ends_with(".jsonl.zst") {
blobs += 1;
}
}
}
blobs
}
fn github_token() -> String {
const ALPHABET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let body: String = (0..36)
.map(|i| ALPHABET[(i * 17 + 5) % ALPHABET.len()] as char)
.collect();
["gh", "p_"].concat() + &body
}
#[test]
fn transcripts_are_listed_newest_first_across_nested_dirs() {
let setup = Setup::new();
let p = setup.projects();
let old = write_file(&p.join("-home-a-proj/old.jsonl"), "{}\n", 1_000);
let agent = write_file(
&p.join("-home-a-proj/sess/subagents/agent.jsonl"),
"{}\n",
3_000,
);
let mid = write_file(&p.join("-home-b-proj/mid.jsonl"), "{}\n", 2_000);
let tie_b = write_file(&p.join("-home-b-proj/tie-b.jsonl"), "{}\n", 1_500);
let tie_a = write_file(&p.join("-home-b-proj/tie-a.jsonl"), "{}\n", 1_500);
write_file(&p.join("-home-a-proj/notes.md"), "notes\n", 9_000);
write_file(&p.join("-home-a-proj/memory/fact.md"), "fact\n", 9_000);
write_file(&p.join("-home-a-proj/s.jsonl.bak"), "{}\n", 9_000);
assert_eq!(
transcripts_newest_first(&p),
vec![agent, mid, tie_a, tie_b, old]
);
assert!(transcripts_newest_first(&setup.dir.path().join("missing")).is_empty());
}
#[test]
fn a_run_ingests_and_archives_every_transcript_once_and_marks_the_store_done() {
let setup = Setup::new();
let paths = setup.write_sessions(3);
let store = setup.open_store();
let stats = setup.backfill(store.clone(), Duration::ZERO).run().unwrap();
assert_eq!(
stats,
BackfillStats {
captured: 3,
skipped: 0,
failed: 0
}
);
assert_eq!(store.memory_count().unwrap(), control_count(&paths));
assert_eq!(setup.archive.len(), 3);
for path in &paths {
assert!(setup.archive.entry(path).is_some(), "{}", path.display());
}
assert!(store.transcript_backfill_done().unwrap());
let report = setup.health.report().backfill;
assert_eq!(report.state, BackfillState::Done);
assert_eq!((report.total, report.done, report.failed), (3, 3, 0));
assert!(report.updated_at.is_some());
assert_eq!(
setup.backfill(store.clone(), Duration::ZERO).run().unwrap(),
BackfillStats::default()
);
}
#[test]
fn a_missing_projects_dir_marks_the_backfill_done() {
let setup = Setup::new();
let store = setup.open_store();
let stats = setup.backfill(store.clone(), Duration::ZERO).run().unwrap();
assert_eq!(stats, BackfillStats::default());
assert!(store.transcript_backfill_done().unwrap());
assert_eq!(setup.health.report().backfill.state, BackfillState::Done);
}
#[test]
fn the_pause_is_slept_between_files() {
let setup = Setup::new();
setup.write_sessions(3);
let started = Instant::now();
setup
.backfill(setup.open_store(), Duration::from_millis(150))
.run()
.unwrap();
assert!(started.elapsed() >= Duration::from_millis(300));
}
#[test]
fn the_pause_is_not_slept_before_the_first_file() {
let setup = Setup::new();
setup.write_sessions(1);
let started = Instant::now();
setup
.backfill(setup.open_store(), Duration::from_secs(2))
.run()
.unwrap();
assert!(
started.elapsed() < Duration::from_millis(1_500),
"{:?}",
started.elapsed()
);
}
#[test]
fn a_restarted_backfill_resumes_without_duplicates() {
let setup = Setup::new();
let paths = setup.write_sessions(3);
let listed = transcripts_newest_first(&setup.projects());
let newest_two = &listed[..2];
let store = setup.open_store();
for path in newest_two {
let outcome =
capture_transcript(&dyn_store(&store), None, Some(&*setup.archive), path, "m").unwrap();
assert_eq!(outcome, FileOutcome::Captured);
}
drop(store);
let reopened = setup.open_store();
assert!(!reopened.transcript_backfill_done().unwrap());
setup
.backfill(reopened.clone(), Duration::ZERO)
.run()
.unwrap();
assert_eq!(reopened.memory_count().unwrap(), control_count(&paths));
assert!(reopened.transcript_backfill_done().unwrap());
}
#[test]
fn a_copy_under_another_path_adds_nothing() {
let setup = Setup::new();
let original = setup.write("p/s.jsonl", "sess-1", "parser", 1_000);
setup.write("q/copy.jsonl", "sess-1", "parser", 2_000);
let store = setup.open_store();
setup.backfill(store.clone(), Duration::ZERO).run().unwrap();
assert_eq!(store.memory_count().unwrap(), control_count(&[original]));
assert_eq!(archive_blobs(setup.archive.dir()), 1);
}
#[test]
fn the_archive_is_redacted_and_outlives_its_source() {
let setup = Setup::new();
let token = github_token();
let turns = vec![
format!(
"We rotated the deploy token {token} after the release pipeline leaked it into a build log on the shared runner."
),
TURNS[1].to_string(),
];
let path = write_file(
&setup.projects().join("p/secret.jsonl"),
&transcript("sess-secret", &turns),
1_000,
);
let store = setup.open_store();
setup.backfill(store, Duration::ZERO).run().unwrap();
fs::remove_file(&path).unwrap();
let archived = setup.archive.read(&path).unwrap().expect("archived text");
assert!(!archived.contains(&token));
assert!(archived.contains("We rotated the deploy token"));
assert!(archived.contains("the release pipeline leaked it"));
}
#[test]
fn the_backfill_yields_while_live_ingest_is_busy() {
let setup = Setup::new();
let paths = setup.write_sessions(2);
let store = setup.open_store();
let busy = setup.live.ingesting(1);
assert!(setup.live.busy());
let handle = setup.backfill(store.clone(), Duration::ZERO).spawn();
std::thread::sleep(Duration::from_millis(300));
assert_eq!(store.memory_count().unwrap(), 0);
assert_eq!(setup.health.report().backfill.state, BackfillState::Running);
drop(busy);
assert!(!setup.live.busy());
handle.join().unwrap();
assert_eq!(store.memory_count().unwrap(), control_count(&paths));
assert!(store.transcript_backfill_done().unwrap());
}
#[derive(Default)]
struct Unsynced {
synced: AtomicBool,
}
impl TimeSignals for Unsynced {
fn now_micros(&self) -> i64 {
Utc::now().timestamp_micros()
}
fn ntp_synced(&self) -> bool {
self.synced.load(Ordering::SeqCst)
}
fn rtc_secs(&self) -> Option<i64> {
None
}
}
#[test]
fn the_backfill_waits_while_the_clock_gate_is_closed() {
let setup = Setup::new();
let paths = setup.write_sessions(2);
let store = setup.open_store();
let signals = Arc::new(Unsynced::default());
let mut backfill = setup.backfill(store.clone(), Duration::ZERO);
backfill.clock = ClockGate::new(setup.dir.path(), signals.clone(), i64::MAX);
let handle = backfill.spawn();
std::thread::sleep(Duration::from_millis(1500));
assert!(!handle.is_finished());
assert_eq!(store.memory_count().unwrap(), 0);
assert!(!store.transcript_backfill_done().unwrap());
assert!(setup.archive.entry(&paths[0]).is_none());
signals.synced.store(true, Ordering::SeqCst);
let deadline = Instant::now() + Duration::from_secs(60);
while !handle.is_finished() {
assert!(Instant::now() < deadline, "the backfill never resumed");
std::thread::sleep(Duration::from_millis(50));
}
handle.join().unwrap();
assert_eq!(store.memory_count().unwrap(), control_count(&paths));
assert!(store.transcript_backfill_done().unwrap());
}
#[test]
fn the_backfill_needs_no_schema_change() {
assert_eq!(SCHEMA_VERSION, 14);
let setup = Setup::new();
setup.write_sessions(1);
let store = setup.open_store();
setup.backfill(store.clone(), Duration::ZERO).run().unwrap();
assert_eq!(store.schema_version().unwrap(), SCHEMA_VERSION);
}
#[test]
fn capture_transcript_archives_on_the_watcher_path_and_skips_a_missing_file() {
let setup = Setup::new();
let path = setup.write("p/live.jsonl", "sess-live", "parser", 1_000);
let store = setup.open_store();
let outcome =
capture_transcript(&dyn_store(&store), None, Some(&*setup.archive), &path, "m").unwrap();
assert_eq!(outcome, FileOutcome::Captured);
assert!(setup.archive.entry(&path).is_some());
assert!(store.memory_count().unwrap() > 0);
let missing = setup.projects().join("p/gone.jsonl");
let outcome = capture_transcript(
&dyn_store(&store),
None,
Some(&*setup.archive),
&missing,
"m",
)
.unwrap();
assert_eq!(outcome, FileOutcome::Skipped);
assert!(setup.archive.entry(&missing).is_none());
assert_eq!(setup.archive.len(), 1);
}
#[test]
fn a_failed_file_leaves_the_backfill_to_retry_without_touching_live_health() {
use std::os::unix::fs::PermissionsExt;
let setup = Setup::new();
let paths = setup.write_sessions(2);
let store = setup.open_store();
let archive_dir = setup.archive.dir().to_path_buf();
fs::set_permissions(&archive_dir, fs::Permissions::from_mode(0o500)).unwrap();
let first = setup.backfill(store.clone(), Duration::ZERO).run();
fs::set_permissions(&archive_dir, fs::Permissions::from_mode(0o700)).unwrap();
let stats = first.unwrap();
assert_eq!(stats.failed, 2);
assert!(!store.transcript_backfill_done().unwrap());
assert_eq!(setup.health.report().backfill.failed, 2);
assert!(setup.health.report().last_error.is_none());
let second = setup.backfill(store.clone(), Duration::ZERO).run().unwrap();
assert_eq!(second.failed, 0);
assert!(store.transcript_backfill_done().unwrap());
for path in &paths {
assert!(setup.archive.entry(path).is_some());
}
}
#[test]
fn the_run_captures_transcripts_newest_first() {
let setup = Setup::new();
let paths = setup.write_sessions(4);
let store = setup.open_store();
setup.backfill(store, Duration::ZERO).run().unwrap();
let mut by_archive_time = paths.clone();
by_archive_time.sort_by_key(|p| setup.archive.entry(p).unwrap().archived_at);
let mut newest_first = paths;
newest_first.reverse();
assert_eq!(by_archive_time, newest_first);
}
#[test]
fn a_later_start_reports_done_and_catches_up_only_on_changed_transcripts() {
let setup = Setup::new();
setup.write_sessions(2);
let store = setup.open_store();
setup.backfill(store.clone(), Duration::ZERO).run().unwrap();
let written_while_down = setup.write("-home-b-proj/new.jsonl", "sess-new", "indexer", 5_000);
let resumed = setup.write("-home-a-proj/s0.jsonl", "sess-0", "exporter", 0);
fs::File::options()
.append(true)
.open(&resumed)
.unwrap()
.set_modified(SystemTime::now() + Duration::from_secs(60))
.unwrap();
let restarted = Setup {
dir: setup.dir,
archive: Arc::new(TranscriptArchive::open(setup.archive.dir()).unwrap()),
live: Arc::new(LiveIngest::default()),
health: Arc::new(Health::new(Utc::now(), None)),
};
let stats = restarted
.backfill(restarted.open_store(), Duration::ZERO)
.run()
.unwrap();
assert_eq!(
stats,
BackfillStats {
captured: 2,
skipped: 0,
failed: 0
}
);
assert!(restarted.archive.entry(&written_while_down).is_some());
let refreshed = restarted.archive.read(&resumed).unwrap().unwrap();
assert!(refreshed.contains("In the exporter module"));
let report = restarted.health.report().backfill;
assert_eq!(report.state, BackfillState::Done);
assert_eq!((report.total, report.done), (2, 2));
}
#[test]
fn a_watcher_that_panics_mid_ingest_leaves_live_ingest_idle() {
let live = LiveIngest::default();
let outcome = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let _ingesting = live.ingesting(2);
assert!(live.busy());
panic!("watcher died mid-ingest");
}));
assert!(outcome.is_err());
assert!(!live.busy());
}
struct Trust(AtomicBool);
impl WallClock for Trust {
fn now_micros(&self) -> Option<i64> {
self.0
.load(Ordering::SeqCst)
.then(|| Utc::now().timestamp_micros())
}
}
#[test]
fn an_ingest_whose_writes_fail_is_not_recorded_and_the_next_pass_stores_its_memories() {
let setup = Setup::new();
let path = setup.write("p/held.jsonl", "sess-held", "parser", 1_000);
let trust = Arc::new(Trust(AtomicBool::new(false)));
let store = Arc::new(
SqliteStore::open(&setup.db_path(), "m".to_string())
.unwrap()
.with_wall_clock(trust.clone()),
);
assert!(ingest_file(&dyn_store(&store), None, &path, "m").is_err());
assert_eq!(store.memory_count().unwrap(), 0);
trust.0.store(true, Ordering::SeqCst);
assert_eq!(
ingest_file(&dyn_store(&store), None, &path, "m").unwrap(),
FileOutcome::Captured
);
assert_eq!(
store.memory_count().unwrap(),
control_count(std::slice::from_ref(&path))
);
}
struct SteppingSignals {
offset: AtomicI64,
synced: AtomicBool,
}
impl TimeSignals for SteppingSignals {
fn now_micros(&self) -> i64 {
Utc::now().timestamp_micros() + self.offset.load(Ordering::SeqCst)
}
fn ntp_synced(&self) -> bool {
self.synced.load(Ordering::SeqCst)
}
fn rtc_secs(&self) -> Option<i64> {
None
}
}
struct StepsBackOnSecondWrite {
gate: Arc<ClockGate>,
signals: Arc<SteppingSignals>,
calls: AtomicUsize,
}
impl WallClock for StepsBackOnSecondWrite {
fn now_micros(&self) -> Option<i64> {
if self.calls.fetch_add(1, Ordering::SeqCst) == 1 {
self.signals.synced.store(false, Ordering::SeqCst);
self.signals.offset.store(-10_000_000, Ordering::SeqCst);
}
WallClock::now_micros(self.gate.as_ref())
}
}
#[test]
fn the_backfill_retries_a_transcript_whose_ingest_failed_as_the_gate_closed() {
let setup = Setup::new();
let paths = setup.write_sessions(1);
let signals = Arc::new(SteppingSignals {
offset: AtomicI64::new(0),
synced: AtomicBool::new(true),
});
let gate = ClockGate::new(setup.dir.path(), signals.clone(), 0);
assert!(gate.is_open());
let store = Arc::new(
SqliteStore::open(&setup.db_path(), "m".to_string())
.unwrap()
.with_wall_clock(Arc::new(StepsBackOnSecondWrite {
gate: gate.clone(),
signals: signals.clone(),
calls: AtomicUsize::new(0),
})),
);
let mut backfill = setup.backfill(store.clone(), Duration::ZERO);
backfill.clock = gate.clone();
let handle = std::thread::spawn(move || backfill.run());
let deadline = Instant::now() + Duration::from_secs(30);
while signals.offset.load(Ordering::SeqCst) == 0 || gate.is_open() {
assert!(
Instant::now() < deadline,
"the gate never closed mid-ingest"
);
std::thread::sleep(Duration::from_millis(20));
}
signals.synced.store(true, Ordering::SeqCst);
let deadline = Instant::now() + Duration::from_secs(60);
while !handle.is_finished() {
assert!(Instant::now() < deadline, "the backfill never finished");
std::thread::sleep(Duration::from_millis(50));
}
let stats = handle.join().unwrap().unwrap();
assert_eq!(
stats,
BackfillStats {
captured: 1,
skipped: 0,
failed: 0
}
);
assert_eq!(store.memory_count().unwrap(), control_count(&paths));
assert!(store.transcript_backfill_done().unwrap());
}
fn restart(setup: Setup) -> Setup {
Setup {
dir: setup.dir,
archive: Arc::new(TranscriptArchive::open(setup.archive.dir()).unwrap()),
live: Arc::new(LiveIngest::default()),
health: Arc::new(Health::new(Utc::now(), None)),
}
}
fn gated_store(setup: &Setup) -> Arc<SqliteStore> {
Arc::new(
SqliteStore::open(&setup.db_path(), "m".to_string())
.unwrap()
.with_wall_clock(Arc::new(Trust(AtomicBool::new(false)))),
)
}
#[test]
fn a_catch_up_ingests_a_transcript_whose_gated_ingest_failed_before_a_restart() {
let setup = Setup::new();
let mut paths = setup.write_sessions(1);
setup
.backfill(setup.open_store(), Duration::ZERO)
.run()
.unwrap();
let held = setup.write("-home-a-proj/held.jsonl", "sess-held", "scheduler", 2_000);
{
let store = gated_store(&setup);
let ingest = capture_transcript(&dyn_store(&store), None, Some(&setup.archive), &held, "m");
assert!(ingest.is_err());
assert!(setup.archive.entry(&held).is_some());
assert_eq!(store.memory_count().unwrap(), control_count(&paths));
}
paths.push(held);
let restarted = restart(setup);
let store = restarted.open_store();
let stats = restarted
.backfill(store.clone(), Duration::ZERO)
.run()
.unwrap();
assert_eq!(
stats,
BackfillStats {
captured: 1,
skipped: 0,
failed: 0
}
);
assert_eq!(store.memory_count().unwrap(), control_count(&paths));
let again = restart(restarted)
.backfill(store.clone(), Duration::ZERO)
.run()
.unwrap();
assert_eq!(
again,
BackfillStats::default(),
"an ingested file is not taken again"
);
}
#[test]
fn a_catch_up_ingests_a_memory_file_whose_gated_ingest_failed_before_a_restart() {
let setup = Setup::new();
setup.write_sessions(1);
setup
.backfill(setup.open_store(), Duration::ZERO)
.run()
.unwrap();
let note = write_file(
&setup.projects().join("-home-a-proj/memory/testing.md"),
"---\nname: testing\ndescription: how tests run\ntype: feedback\n---\n\nRun the crate's tests through the wrapper so builds share the lock and never reach the live daemon.\n",
2_000,
);
let before = {
let store = gated_store(&setup);
assert!(ingest_memory_file(&dyn_store(&store), None, ¬e, "m").is_err());
store.memory_count().unwrap()
};
let restarted = restart(setup);
let store = restarted.open_store();
let stats = restarted
.backfill(store.clone(), Duration::ZERO)
.run()
.unwrap();
assert_eq!(
stats,
BackfillStats {
captured: 1,
skipped: 0,
failed: 0
}
);
assert_eq!(store.memory_count().unwrap(), before + 1);
let again = restart(restarted)
.backfill(store.clone(), Duration::ZERO)
.run()
.unwrap();
assert_eq!(
again,
BackfillStats::default(),
"an ingested file is not taken again"
);
}
#[test]
fn a_file_that_cannot_parse_is_not_taken_again_by_every_catch_up() {
let setup = Setup::new();
setup.write_sessions(1);
let mut cut = b"{\"type\":\"user\",\"message\":{\"content\":\"caf".to_vec();
cut.push(0xC3);
for path in [
setup.projects().join("-home-a-proj/cut.jsonl"),
setup.projects().join("-home-a-proj/memory/cut.md"),
] {
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, &cut).unwrap();
set_mtime(&path, 2_000);
}
let store = setup.open_store();
setup.backfill(store.clone(), Duration::ZERO).run().unwrap();
let restarted = restart(setup);
let again = restarted
.backfill(store.clone(), Duration::ZERO)
.run()
.unwrap();
assert_eq!(again, BackfillStats::default());
let note = restarted.projects().join("-home-a-proj/memory/cut.md");
write_file(
¬e,
"---\nname: cut\ndescription: a note that became readable\ntype: feedback\n---\n\nThe note was rewritten as valid text after a killed write left it cut.\n",
3_000,
);
let regrown = restart(restarted)
.backfill(store.clone(), Duration::ZERO)
.run()
.unwrap();
assert_eq!(regrown.captured, 1, "{regrown:?}");
}