use datasynth_output::OutputRootConfig;
use datasynth_runtime::enhanced_orchestrator::EnhancedGenerationResult;
use datasynth_runtime::output_writer::write_all_output_with_root;
use tempfile::TempDir;
fn minimal_result() -> EnhancedGenerationResult {
EnhancedGenerationResult::default()
}
#[test]
fn flat_layout_writes_at_root() {
let tmp = TempDir::new().expect("tempdir");
let root = OutputRootConfig::flat(tmp.path());
let result = minimal_result();
write_all_output_with_root(
&result,
&root,
datasynth_config::ExportLayout::Nested,
&[datasynth_config::FileFormat::Json],
)
.expect("flat layout should succeed");
assert!(tmp.path().exists());
assert!(tmp.path().is_dir());
assert!(
!tmp.path().join("entities").exists(),
"flat mode must not create entities/ subdir"
);
}
#[test]
fn per_entity_layout_routes_under_entities_code() {
let tmp = TempDir::new().expect("tempdir");
let root = OutputRootConfig::per_entity(tmp.path(), "ACME_SA");
let result = minimal_result();
write_all_output_with_root(
&result,
&root,
datasynth_config::ExportLayout::Nested,
&[datasynth_config::FileFormat::Json],
)
.expect("per-entity layout should succeed");
let expected = tmp.path().join("entities").join("ACME_SA");
assert!(expected.exists(), "{expected:?} must exist");
assert!(expected.is_dir());
let root_entries: Vec<String> = std::fs::read_dir(tmp.path())
.expect("read_dir tmp")
.map(|e| {
e.expect("dir entry")
.file_name()
.to_string_lossy()
.into_owned()
})
.collect();
assert_eq!(
root_entries,
vec!["entities".to_string()],
"only entities/ should be at root in per-entity mode, found {root_entries:?}"
);
}
#[test]
fn per_entity_without_code_falls_back_to_flat_layout() {
let tmp = TempDir::new().expect("tempdir");
let root = OutputRootConfig {
root_dir: tmp.path().to_path_buf(),
per_entity_subtree: true,
entity_code: None,
};
let result = minimal_result();
write_all_output_with_root(
&result,
&root,
datasynth_config::ExportLayout::Nested,
&[datasynth_config::FileFormat::Json],
)
.expect("fallback routing should succeed");
assert!(tmp.path().exists());
assert!(
!tmp.path().join("entities").exists(),
"no entities/ subdir when entity_code is None"
);
}