use std::path::PathBuf;
fn yaml_is_group_config(yaml: &str) -> bool {
let Ok(value) = serde_yaml::from_str::<serde_yaml::Value>(yaml) else {
return false;
};
let Some(map) = value.as_mapping() else {
return false;
};
map.contains_key(serde_yaml::Value::String(
"presentation_currency".to_string(),
)) && map.contains_key(serde_yaml::Value::String("ownership".to_string()))
}
fn template_path(name: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join("..")
.join("templates")
.join(name)
}
#[test]
fn legacy_configs_dispatch_to_single_entity_flow() {
let cases = [
"fraud-detection-basic.yaml",
"process-mining-full.yaml",
"ml-training-balanced.yaml",
];
for name in cases {
let path = template_path(name);
let yaml = std::fs::read_to_string(&path)
.unwrap_or_else(|e| panic!("read {}: {e}", path.display()));
assert!(
!yaml_is_group_config(&yaml),
"{}: legacy single-entity config must NOT be classified as a GroupConfig",
path.display(),
);
}
}
#[test]
fn mini_acme_dispatches_to_group_flow() {
let yaml = include_str!("fixtures/mini_acme.yaml");
assert!(
yaml_is_group_config(yaml),
"Mini-Acme fixture must be classified as a GroupConfig",
);
}
#[test]
fn mini_acme_minimal_dispatches_to_group_flow() {
let yaml = include_str!("fixtures/mini_acme_minimal.yaml");
assert!(
yaml_is_group_config(yaml),
"Mini-Acme minimal fixture must be classified as a GroupConfig",
);
}
#[test]
fn ambiguous_inputs_dispatch_to_legacy() {
assert!(!yaml_is_group_config("---\nhello: world"));
assert!(!yaml_is_group_config("just-a-string"));
assert!(!yaml_is_group_config(""));
assert!(!yaml_is_group_config(
"presentation_currency: CHF\nfoo: bar\n"
));
assert!(!yaml_is_group_config(
"ownership:\n parent_entity_code: X\n"
));
assert!(!yaml_is_group_config(
"this: is\n not: valid: yaml: at all"
));
}