diff --git a/crates/omnigraph-config/src/lib.rs b/crates/omnigraph-config/src/lib.rs index b308b72..3f9e444 100644 --- a/crates/omnigraph-config/src/lib.rs +++ b/crates/omnigraph-config/src/lib.rs @@ -538,7 +538,9 @@ fn load_config_in(cwd: &Path, config_path: Option<&PathBuf>) -> Result(&fs::read_to_string(path)?)? + let text = fs::read_to_string(path)?; + check_config_version(&text)?; + serde_yaml::from_str::(&text)? } else { OmnigraphConfig::default() }; @@ -552,6 +554,24 @@ fn load_config_in(cwd: &Path, config_path: Option<&PathBuf>) -> Result Result<()> { + let value: serde_yaml::Value = serde_yaml::from_str(text)?; + if let Some(version) = value.get("version").and_then(serde_yaml::Value::as_u64) { + if version != 1 { + bail!( + "unsupported config version {version}; this build supports version 1 \ + (omit `version:` for the legacy schema)" + ); + } + } + Ok(()) +} + fn absolute_base_dir(cwd: &Path, path: &Path) -> Result { let path = if path.is_absolute() { path.to_path_buf() @@ -945,4 +965,39 @@ cli: Some("DEMO_TOKEN") ); } + + #[test] + fn version_one_parses_like_legacy() { + let temp = tempdir().unwrap(); + fs::write( + temp.path().join("omnigraph.yaml"), + "version: 1\ngraphs:\n local:\n uri: ./demo.omni\ncli:\n graph: local\n", + ) + .unwrap(); + let config = load_config_in(temp.path(), None).unwrap(); + assert_eq!(config.cli_graph_name(), Some("local")); + assert_eq!( + PathBuf::from( + config + .resolve_target_uri(None, None, config.cli_graph_name()) + .unwrap() + ), + temp.path().join("./demo.omni") + ); + } + + #[test] + fn unsupported_config_version_errors() { + let temp = tempdir().unwrap(); + fs::write( + temp.path().join("omnigraph.yaml"), + "version: 2\ngraphs:\n local:\n uri: ./demo.omni\n", + ) + .unwrap(); + let err = load_config_in(temp.path(), None).unwrap_err().to_string(); + assert!( + err.contains("unsupported config version 2"), + "config version > 1 must be rejected: {err}" + ); + } }