use std::fs;
use std::path::{Path, PathBuf};
use warble_cli::compile_project_to_ir;
fn jaffle_wren_abs() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join("examples/jaffle-wren")
.canonicalize()
.expect("examples/jaffle-wren must exist in this checkout")
}
fn write_monitor_fixture(dir: &Path, wren_abs: &Path, model: &str) {
fs::create_dir_all(dir.join("context")).unwrap();
fs::write(
dir.join("profile.yml"),
format!(
"profile: fixture-multi-model\ncontext:\n project: ./context/binding.yml\ncomponents:\n - use: monitor_freshness\n bind:\n model: {model}\n"
),
)
.unwrap();
fs::write(
dir.join("context/binding.yml"),
format!(
"kind: prepared\nproject: {}\ndocument: context/context.json\n",
wren_abs.display()
),
)
.unwrap();
fs::write(
dir.join("context/context.json"),
fs::read_to_string(
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../examples/monitor-agent/context/context.json"),
)
.expect("the committed jaffle-wren prepared document must exist in this checkout"),
)
.unwrap();
}
#[test]
fn monitoring_a_timestampless_model_in_a_multi_model_project_fails_to_compile() {
let wren_abs = jaffle_wren_abs();
let project = tempfile::tempdir().unwrap();
write_monitor_fixture(project.path(), &wren_abs, "raw_payments");
let err = compile_project_to_ir(project.path()).expect_err(
"binding monitor_freshness to raw_payments (no timestamp column) must be refused, even \
though this SAME jaffle-wren project has other models (orders, customers) that DO carry \
one -- proving the check is pinned to the named model, not existential over the project",
);
assert!(
err.contains("model_has_timestamp") && err.contains("not satisfied"),
"expected a model_has_timestamp rejection, got: {err}"
);
assert!(
err.contains("monitor_freshness"),
"the message must name the offending component so the failure is actionable: {err}"
);
}