Skip to main content

ConfigEnvironment

Trait ConfigEnvironment 

Source
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§

Source

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).

Source

fn file_exists(&self, path: &Path) -> bool

Check if a file exists at the given path.

Source

fn read_file(&self, path: &Path) -> Result<String>

Read the contents of a file.

§Errors

Returns error if the operation fails.

Source

fn write_file(&self, path: &Path, content: &str) -> Result<()>

Write content to a file, creating parent directories if needed.

§Errors

Returns error if the operation fails.

Source

fn create_dir_all(&self, path: &Path) -> Result<()>

Create directories recursively.

§Errors

Returns error if the operation fails.

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

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.

Implementors§