diff --git a/crates/omnigraph-cli/tests/cli.rs b/crates/omnigraph-cli/tests/cli.rs index e6caea9..6666cd4 100644 --- a/crates/omnigraph-cli/tests/cli.rs +++ b/crates/omnigraph-cli/tests/cli.rs @@ -417,6 +417,26 @@ fn use_sets_active_graph_targeted_by_bare_commands() { assert!(parse_stdout_json(&output).is_object()); } +#[test] +fn explicit_omnigraph_config_pointing_at_missing_file_errors() { + // A typo'd OMNIGRAPH_CONFIG must fail loudly naming the file, not silently + // load no global layer. + let empty_cwd = tempdir().unwrap(); + let missing = empty_cwd.path().join("does-not-exist.yaml"); + let output = output_failure( + cli() + .current_dir(empty_cwd.path()) + .env("OMNIGRAPH_CONFIG", &missing) + .arg("config") + .arg("view"), + ); + let stderr = String::from_utf8_lossy(&output.stderr); + assert!( + stderr.contains("OMNIGRAPH_CONFIG") && stderr.contains("does-not-exist.yaml"), + "missing OMNIGRAPH_CONFIG must error naming the file: {stderr}" + ); +} + #[test] fn schema_plan_json_reports_supported_additive_change() { let temp = tempdir().unwrap(); diff --git a/crates/omnigraph-config/src/lib.rs b/crates/omnigraph-config/src/lib.rs index 2a6dc99..3613e37 100644 --- a/crates/omnigraph-config/src/lib.rs +++ b/crates/omnigraph-config/src/lib.rs @@ -1158,6 +1158,19 @@ pub struct LayeredConfig { pub fn load_layered_config(project_config_path: Option<&PathBuf>) -> Result { let cwd = env::current_dir()?; let global = global_config_file(); + // An explicitly-named global file (via `OMNIGRAPH_CONFIG`) is *required*: a + // typo must error loudly, not silently load no global layer. A missing + // default-location file (`~/.omnigraph/config.yaml`) stays optional. + if env::var_os("OMNIGRAPH_CONFIG").is_some() { + if let Some(path) = &global { + if !path.exists() { + bail!( + "OMNIGRAPH_CONFIG points at a missing file: {}", + path.display() + ); + } + } + } let active = active_context_file(); load_layered_config_in( &cwd,