Skip to main content

strixonomy_core/
paths.rs

1//! Workspace configuration directory resolution (`.strixonomy`).
2
3use std::path::{Path, PathBuf};
4
5/// Workspace config directory.
6pub const CONFIG_DIR: &str = ".strixonomy";
7
8/// Relative cache directory under the config dir.
9pub const CACHE_SUBDIR: &str = "cache";
10
11/// Relative plugins directory under the config dir.
12pub const PLUGINS_SUBDIR: &str = "plugins";
13
14/// Diagnostics config filename under the config dir.
15pub const DIAGNOSTICS_FILE: &str = "diagnostics.toml";
16
17/// Default plugin export directory (relative to workspace).
18pub const PLUGIN_OUT_REL: &str = ".strixonomy/plugin-out";
19
20/// Disabled-plugins state file (relative to workspace).
21pub const PLUGIN_DISABLED_REL: &str = ".strixonomy/plugin-disabled.json";
22
23/// Resolve `{workspace}/.strixonomy/{leaf}`.
24pub fn resolve_config_path(workspace: &Path, leaf: &str) -> PathBuf {
25    workspace.join(CONFIG_DIR).join(leaf)
26}
27
28/// Resolve a workspace-relative dotted path (e.g. `.strixonomy/cache`).
29pub fn resolve_dotted_config_path(workspace: &Path, rel: &str) -> PathBuf {
30    workspace.join(rel)
31}
32
33/// Primary plugins directory path (may not exist yet).
34pub fn plugins_dir(workspace: &Path) -> PathBuf {
35    resolve_config_path(workspace, PLUGINS_SUBDIR)
36}
37
38/// Plugin directories to scan (primary only).
39pub fn plugin_search_dirs(workspace: &Path) -> Vec<PathBuf> {
40    vec![plugins_dir(workspace)]
41}
42
43/// Cache root under the workspace.
44pub fn cache_dir(workspace: &Path) -> PathBuf {
45    resolve_config_path(workspace, CACHE_SUBDIR)
46}
47
48/// Diagnostics.toml path.
49pub fn diagnostics_config_path(workspace: &Path) -> PathBuf {
50    resolve_config_path(workspace, DIAGNOSTICS_FILE)
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56    use std::fs;
57
58    #[test]
59    fn uses_primary_config_dir() {
60        let dir = tempfile::tempdir().unwrap();
61        fs::create_dir_all(dir.path().join(".strixonomy/cache")).unwrap();
62        assert_eq!(cache_dir(dir.path()), dir.path().join(".strixonomy/cache"));
63    }
64
65    #[test]
66    fn defaults_to_primary_when_missing() {
67        let dir = tempfile::tempdir().unwrap();
68        assert_eq!(
69            diagnostics_config_path(dir.path()),
70            dir.path().join(".strixonomy/diagnostics.toml")
71        );
72        assert_eq!(plugins_dir(dir.path()), dir.path().join(".strixonomy/plugins"));
73    }
74}