Skip to main content

synwire_agent/session/
mounted_repos.rs

1//! Session state for repositories that have been cloned and mounted into the VFS.
2
3use std::path::PathBuf;
4
5/// Records a repository that was cloned and mounted during a session.
6///
7/// Stored in session state so that cloned repositories can be re-mounted
8/// automatically when a session is resumed.
9#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
10#[non_exhaustive]
11pub struct MountedRepo {
12    /// Remote URL the repository was cloned from.
13    pub url: String,
14    /// Local path to the cloned repository on disk.
15    pub local_path: PathBuf,
16    /// Whether the repository has been semantically indexed.
17    pub indexed: bool,
18}
19
20impl MountedRepo {
21    /// Construct a new `MountedRepo` record.
22    #[must_use]
23    pub fn new(url: impl Into<String>, local_path: impl Into<PathBuf>) -> Self {
24        Self {
25            url: url.into(),
26            local_path: local_path.into(),
27            indexed: false,
28        }
29    }
30}
31
32#[cfg(test)]
33#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn mounted_repo_round_trips_through_json() {
39        let repo = MountedRepo::new(
40            "https://github.com/example/repo.git",
41            "/home/user/.cache/synwire/repos/example/repo",
42        );
43        let json = serde_json::to_string(&repo).expect("serialize");
44        let de: MountedRepo = serde_json::from_str(&json).expect("deserialize");
45        assert_eq!(de.url, repo.url);
46        assert_eq!(de.local_path, repo.local_path);
47        assert!(!de.indexed);
48    }
49}