artifactize-core 0.27.2

The library behind artifactize: Artifacts, evals, reviews, the monitor and review models, and the shared operations every interface calls.
Documentation
use super::Receipts;
use std::path::Path;

/// A test writer closes its SQLite worker before the caller's temporary state is removed.
pub struct OwnedReceipts(Receipts);

impl OwnedReceipts {
    pub async fn open(state: &Path, repo: &Path) -> Result<Self, String> {
        Receipts::open(state, repo).await.map(Self)
    }
}

impl std::ops::Deref for OwnedReceipts {
    type Target = Receipts;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Drop for OwnedReceipts {
    fn drop(&mut self) {
        let connection = self.0.connection.inner.clone();
        // Drop can run on a current-thread Tokio test runtime, including during unwinding.
        // A separate joined thread avoids nesting runtimes or detaching SQLite teardown.
        let closed = std::thread::spawn(move || {
            tokio::runtime::Builder::new_current_thread()
                .build()
                .expect("create the test writer's teardown runtime")
                .block_on(connection.close())
        })
        .join();
        if !std::thread::panicking() {
            closed
                .expect("join the test writer's teardown")
                .expect("close the test writer's SQLite connection");
        }
    }
}