Fix target-aware prepare path and add regression test

Agent-Logs-Url: https://github.com/microsoft/regorus/sessions/f964122b-5af3-41a7-bc51-d87b7271a455

Co-authored-by: anakrish <35780660+anakrish@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-14 20:07:11 +00:00
committed by GitHub
parent c65e844f63
commit 196b6d68aa
2 changed files with 57 additions and 16 deletions

View File

@@ -142,6 +142,46 @@ fn prepare_then_clone_without_initial_eval() -> Result<()> {
Ok(())
}
#[test]
#[cfg(feature = "azure_policy")]
#[cfg_attr(docsrs, doc(cfg(feature = "azure_policy")))]
fn prepare_then_compile_for_target() -> Result<()> {
if !registry::targets::contains("target.tests.sample_test_target") {
let target = Target::from_json_str(include_str!(
"../interpreter/cases/target/definitions/sample_target.json"
))?;
registry::targets::register(Rc::new(target))?;
}
let mut engine = Engine::new();
engine.add_policy(
"test.rego".to_string(),
r#"package test
import rego.v1
__target__ := "target.tests.sample_test_target"
default allow := false
allow if {
input.type == "test_resource"
}
"#
.to_string(),
)?;
engine.prepare()?;
let compiled = engine.compile_for_target()?;
let info = compiled.get_policy_info()?;
assert_eq!(info.target_name.as_deref(), Some("target.tests.sample_test_target"));
let result = compiled.eval_with_input(Value::from_json_str(
r#"{"name":"resource-1","type":"test_resource"}"#,
)?)?;
assert_eq!(result, Value::from(true));
Ok(())
}
#[test]
#[cfg(feature = "azure_policy")]
#[cfg_attr(docsrs, doc(cfg(feature = "azure_policy")))]