codewhale_core/engine/thread/
store.rs1use codewhale_protocol::ids::ThreadId;
12use codewhale_state::StateStore;
13
14#[derive(Debug, Clone)]
18pub struct ThreadStore {
19 inner: StateStore,
20 root: std::path::PathBuf,
21}
22
23impl ThreadStore {
24 #[must_use]
25 pub fn new(inner: StateStore, root: std::path::PathBuf) -> Self {
26 Self { inner, root }
27 }
28
29 #[must_use]
30 pub fn state(&self) -> &StateStore {
31 &self.inner
32 }
33
34 #[must_use]
35 pub fn root(&self) -> &std::path::Path {
36 &self.root
37 }
38
39 pub fn thread_exists(&self, id: &ThreadId) -> anyhow::Result<bool> {
40 Ok(self.inner.get_thread(id.as_str())?.is_some())
41 }
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47 use tempfile::tempdir;
48
49 #[test]
50 fn store_wraps_state() {
51 let dir = tempdir().unwrap();
52 let state = StateStore::open(Some(dir.path().join("state.db"))).unwrap();
53 let store = ThreadStore::new(state, dir.path().to_path_buf());
54 assert!(!store.thread_exists(&ThreadId::new()).unwrap());
55 }
56}