From 95ce1f016de28a00fd41091366b8c4e35243a8b3 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 1 Dec 2026 20:11:02 +0100 Subject: [PATCH] interpreter: tests for the API's optional-property limit and for an all-empty answer --- .../src/projection/interpret/tests.rs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 489825f..a767be5 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -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(¬hing, "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::() + } + 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::("{}").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"); +}