pub trait ConfigEnvironment: Send + Sync {
// Required methods
fn unified_config_path(&self) -> Option<PathBuf>;
fn file_exists(&self, path: &Path) -> bool;
fn read_file(&self, path: &Path) -> Result<String>;
fn write_file(&self, path: &Path, content: &str) -> Result<()>;
fn create_dir_all(&self, path: &Path) -> Result<()>;
// Provided methods
fn local_config_path(&self) -> Option<PathBuf> { ... }
fn prompt_path(&self) -> PathBuf { ... }
fn worktree_root(&self) -> Option<PathBuf> { ... }
fn get_env_var(&self, _key: &str) -> Option<String> { ... }
}Expand description
Trait for configuration environment access.
This trait abstracts all external side effects needed for configuration:
- Path resolution (which may depend on environment variables)
- File existence checks
- File reading and writing
- Directory creation
By injecting this trait, configuration code becomes pure and testable.
Required Methods§
Sourcefn unified_config_path(&self) -> Option<PathBuf>
fn unified_config_path(&self) -> Option<PathBuf>
Get the path to the unified config file.
In production, this returns ~/.config/ralph-workflow.toml or
$XDG_CONFIG_HOME/ralph-workflow.toml if the env var is set.
Returns None if the path cannot be determined (e.g., no home directory).
Sourcefn file_exists(&self, path: &Path) -> bool
fn file_exists(&self, path: &Path) -> bool
Check if a file exists at the given path.
Provided Methods§
Sourcefn local_config_path(&self) -> Option<PathBuf>
fn local_config_path(&self) -> Option<PathBuf>
Get the path to the local config file.
In production, this returns .agent/ralph-workflow.toml relative to CWD.
Tests may override this to use a different path.
Returns None if local config is not supported or path cannot be determined.
Sourcefn prompt_path(&self) -> PathBuf
fn prompt_path(&self) -> PathBuf
Get the path to the PROMPT.md file.
In production, this returns ./PROMPT.md (relative to current directory).
Tests may override this to use a different path.
Sourcefn worktree_root(&self) -> Option<PathBuf>
fn worktree_root(&self) -> Option<PathBuf>
Get the canonical root of the git repository, even from a worktree.
When running inside a git worktree, this returns the main repository root (not the ephemeral worktree working directory). This ensures local config paths remain valid after worktree deletion.
Returns None if not in a git repository or in a bare repository.
Sourcefn get_env_var(&self, _key: &str) -> Option<String>
fn get_env_var(&self, _key: &str) -> Option<String>
Get a single environment variable by name.
In production (RealConfigEnvironment), reads from the real process environment.
In tests (MemoryConfigEnvironment), returns None by default (no env vars set),
providing complete isolation from the real process environment.
Used to thread env-var access through config loading so production code is
fully testable without #[serial] or global env mutation.