interpreter: tests for the API's optional-property limit and for an all-empty answer

This commit is contained in:
Meta Vens 2026-12-01 20:11:02 +01:00
commit 95ce1f016d

View file

@ -70,3 +70,36 @@ fn an_answer_that_is_not_the_contract_is_a_failure_with_its_cost() {
let nothing = Answers("{}", RefCell::default());
assert_eq!(super::deltas(&nothing, "claude-haiku-5-5", "r1", &state(), &heard(), "n", "p").unwrap().0, Deltas::default());
}
/// Every property that is not in its object's `required`, summed over every nested object: what the API grammar compiler counts.
fn optional_properties(schema: &Value) -> usize {
match schema {
Value::Object(map) => {
let required: Vec<&str> = map.get("required").and_then(Value::as_array).into_iter().flatten().filter_map(Value::as_str).collect();
let own = map.get("properties").and_then(Value::as_object).map_or(0, |properties| properties.keys().filter(|name| !required.contains(&name.as_str())).count());
own + map.values().map(optional_properties).sum::<usize>()
}
Value::Array(items) => items.iter().map(optional_properties).sum(),
_ => 0,
}
}
#[test]
fn the_schema_stays_under_the_api_limit_of_optional_properties() {
let schema: Value = serde_json::from_str(&schema()).unwrap();
let optional = optional_properties(&schema);
assert!(optional <= 24, "the API refuses more than 24 optional properties in a schema; this one has {optional}");
}
#[test]
fn an_answer_with_every_container_empty_moves_nothing() {
let empty = r#"{"notes":{"remember":[],"settle":[],"wonder":[]},"people":{"bonds":[],"reads":[]},"feeling":{"feelings":[],"mood":{}},"drives":{"needs":[],"pressures":[]},"self":{"stances":[],"identity":{"presentation":{},"values":[]}},"intend":{"add":[],"ready":[],"drop":[]}}"#;
let model = Answers(empty, RefCell::default());
let (deltas, _) = super::deltas(&model, "claude-haiku-5-5", "r1", &state(), &heard(), "n", "p").unwrap();
assert_eq!(deltas, Deltas::default());
let now = "2026-12-01T19:00:00Z".parse().unwrap();
let (next, applied) = apply_commit(&state(), &deltas, &heard(), "k", now);
let (absent, none) = apply_commit(&state(), &serde_json::from_str::<Deltas>("{}").unwrap(), &heard(), "k", now);
assert!(applied.changes.is_empty() && applied.refused.is_empty() && applied.identity.is_empty(), "{:?}", applied.changes);
assert_eq!((next, applied.changes.len()), (absent, none.changes.len()), "empty containers mean what absent ones meant");
}