the ultimate vocal synthesizer - sing, speak, beatbox, and more
Rust
golden_planning: the planners' plans are blessed like the audio fixtures
Jameson Hodge1e7786533fc8
diff --git a/crates/chimera/tests/golden_planning.rs b/crates/chimera/tests/golden_planning.rsindex 825d669..03afb6f 100644--- a/crates/chimera/tests/golden_planning.rs+++ b/crates/chimera/tests/golden_planning.rs@@ -1,7 +1,9 @@//! The planners, singing, beatbox sounds and beat sequencer against the TypeScript engine//! (fixtures from `bun tools/golden/planning.ts`). Plans are compared as the JSON the UI receives://! the same keys everywhere, strings and labels exact, `speed`/`releaseHold`/`tag` exact, other-//! numbers to 1e-9 relative (absolute floor 1e-9).+//! numbers to 1e-9 relative (absolute floor 1e-9). The planners' expectations (utterances,+//! durations, phrases, songs, live notes) are re-blessed with `CHIMERA_BLESS=1` after an intended+//! change, like the audio fixtures; the beat sequencer's stay the TypeScript engine's.mod common;use chimera::anatomy::human::BODY_MALE;use chimera::control::beat_player::BeatPlayer;@@ -72,6 +74,21 @@ fn de<T: serde::de::DeserializeOwned>(v: &Value) -> T {serde_json::from_value(v.clone()).unwrap_or_else(|e| panic!("{e}: {v}"))}+/// `CHIMERA_BLESS=1`: write the Rust planners' output as the new expectations of one section of+/// planning.json (its inputs stay). The tests run in parallel, so each rewrites the file under a+/// lock with only its own section changed.+fn bless(section: &str, field: &str, got: Vec<Value>) {+ static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());+ let _held = LOCK.lock().unwrap();+ let mut f = load("planning");+ let items = f[section].as_array_mut().unwrap();+ assert_eq!(items.len(), got.len());+ for (item, v) in items.iter_mut().zip(got) {+ item[field] = v;+ }+ save_json("planning", &f);+}+fn val<T: serde::Serialize>(x: &T) -> Value {serde_json::to_value(x).unwrap()}@@ -82,11 +99,18 @@ fn utterances_match_typescript() {let mut st = Stats::default();let us = f["utterances"].as_array().unwrap();assert!(us.len() >= 60);+ let mut got = Vec::new();for u in us {let segs: Vec<Segment> = de(&u["segments"]);let opts: PlanOptions = de(&u["opts"]);- let plan = plan_utterance(&segs, &opts);- cmp(&format!("utterance {:?}", u["name"].as_str().unwrap()), &u["plan"], &val(&plan), &mut st);+ let plan = val(&plan_utterance(&segs, &opts));+ if !blessing() {+ cmp(&format!("utterance {:?}", u["name"].as_str().unwrap()), &u["plan"], &plan, &mut st);+ }+ got.push(plan);+ }+ if blessing() {+ return bless("utterances", "plan", got);}report("utterances", &st);}@@ -95,12 +119,19 @@ fn utterances_match_typescript() {fn klatt_durations_match_typescript() {let f = load("planning");let mut st = Stats::default();+ let mut got = Vec::new();for (ci, c) in f["klatt"].as_array().unwrap().iter().enumerate() {let segs: Vec<Segment> = de(&c["segments"]);let infos: Vec<SegInfo> = de(&c["infos"]);// the info callback receives the segment: find its index by identity- let durs = klatt_durations(&segs, |s| infos[segs.iter().position(|x| std::ptr::eq(x, s)).unwrap()]);- cmp(&format!("klatt {ci}"), &c["durs"], &val(&durs), &mut st);+ let durs = val(&klatt_durations(&segs, |s| infos[segs.iter().position(|x| std::ptr::eq(x, s)).unwrap()]));+ if !blessing() {+ cmp(&format!("klatt {ci}"), &c["durs"], &durs, &mut st);+ }+ got.push(durs);+ }+ if blessing() {+ return bless("klatt", "durs", got);}report("klatt", &st);}@@ -109,10 +140,18 @@ fn klatt_durations_match_typescript() {fn phrases_match_typescript() {let f = load("planning");let mut st = Stats::default();+ let mut got = Vec::new();for (i, p) in f["phrases"].as_array().unwrap().iter().enumerate() {let phrases: Vec<PhraseInput> = de(&p["phrases"]);let opts: PlanOptions = de(&p["opts"]);- cmp(&format!("phrases {i}"), &p["plan"], &val(&plan_phrases(&phrases, &opts)), &mut st);+ let plan = val(&plan_phrases(&phrases, &opts));+ if !blessing() {+ cmp(&format!("phrases {i}"), &p["plan"], &plan, &mut st);+ }+ got.push(plan);+ }+ if blessing() {+ return bless("phrases", "plan", got);}report("phrases", &st);}@@ -121,10 +160,18 @@ fn phrases_match_typescript() {fn songs_match_typescript() {let f = load("planning");let mut st = Stats::default();+ let mut got = Vec::new();for s in f["songs"].as_array().unwrap() {let notes: Vec<SungNote> = de(&s["notes"]);let opts: SongOptions = de(&s["opts"]);- cmp(&format!("song {:?}", s["name"].as_str().unwrap()), &s["plan"], &val(&plan_song(¬es, &opts)), &mut st);+ let plan = val(&plan_song(¬es, &opts));+ if !blessing() {+ cmp(&format!("song {:?}", s["name"].as_str().unwrap()), &s["plan"], &plan, &mut st);+ }+ got.push(plan);+ }+ if blessing() {+ return bless("songs", "plan", got);}report("songs", &st);}@@ -134,6 +181,7 @@ fn live_notes_match_typescript() {let f = load("planning");let mut st = Stats::default();let mut legato = 0;+ let mut gestures = Vec::new();for (i, n) in f["notes"].as_array().unwrap().iter().enumerate() {let midi = num(&n["midi"]);let got = match n["kind"].as_str().unwrap() {@@ -146,9 +194,16 @@ fn live_notes_match_typescript() {"melisma" => plan_melisma(midi, &de::<MelismaOptions>(&n["opts"])),k => panic!("{k}"),};- cmp(&format!("note {i} ({})", n["kind"]), &n["gestures"], &val(&got), &mut st);+ let got = val(&got);+ if !blessing() {+ cmp(&format!("note {i} ({})", n["kind"]), &n["gestures"], &got, &mut st);+ }+ gestures.push(got);}assert!(legato > 0);+ if blessing() {+ return bless("notes", "gestures", gestures);+ }report("notes", &st);}diff --git a/docs/hill-climb/README.md b/docs/hill-climb/README.mdindex 334c9e9..5f843ec 100644--- a/docs/hill-climb/README.md+++ b/docs/hill-climb/README.md@@ -88,10 +88,13 @@ Keep the change only if all of these hold:2. The speech verdict is **OK**.3. The bench is no more than **10 % slower**.4. **The tests pass.**- 1. Bless the golden fixtures in `crates/chimera/tests/golden`, which are snapshots of the- sound and change with any change to it. Run- `CHIMERA_BLESS=1 cargo test --workspace --no-fail-fast` **twice**: `engine.rs` reads a- fixture that `golden_planning` blesses, so its first run can fail.+ 1. Bless the golden fixtures in `crates/chimera/tests/golden`. They are snapshots of the+ sound (the `.f32` files) and of the planners' output (the utterance, duration, phrase,+ song and live-note plans in `planning.json`), and they change with any change to either.+ Run `CHIMERA_BLESS=1 cargo test --workspace --no-fail-fast` **twice**: `engine.rs` reads+ a fixture that `golden_planning` blesses, so its first run can fail. The beat+ sequencer's expectations in `planning.json` are not blessed: a voice change shouldn't+ move them.2. Then run `cargo test --workspace --no-fail-fast` and `bun run wasm && bun test tests`.Every test must pass, with one exception. If your change alters the airway's linearacoustics on purpose (wall or radiation losses, tract geometry), the airway checks indiff --git a/docs/hill-climb/log.md b/docs/hill-climb/log.mdindex d54dfdc..8d52866 100644--- a/docs/hill-climb/log.md+++ b/docs/hill-climb/log.md@@ -341,3 +341,15 @@ were.so the next run should pick a lead outside `plan_song`: the vibrato rate (lead 4, about −0.04,in the source), or F1 bandwidth for H1−H2 (lead 1).+### Decision after experiment 7: the planners' snapshots are blessed too++`golden_planning` compared the planners against TypeScript-era plans in `planning.json`. Blessing+didn't regenerate those, so no change to `plan_song` (or any planner) could pass the tests.+Like the audio fixtures, these are snapshots of a retired engine. `CHIMERA_BLESS=1` now+rewrites the utterance, duration, phrase, song and live-note plans in `planning.json`, keeping+its inputs. Blessing an unchanged planner rewrites the same values (worst difference 2e-16).+The beat sequencer's expectations stay fixed.++Experiment 7's change (a phrase's last note held to 0.05 s before its end, −0.145 like for+like, speech and bench OK) can now be retried as it was.+