Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(verify): audio failure classes for the TOML expectations

Richie McIlroy362f2cf23fcc
diff --git a/crates/verify/src/audio_model.rs b/crates/verify/src/audio_model.rs
index da48dc6b9..264835b21 100644
--- a/crates/verify/src/audio_model.rs
+++ b/crates/verify/src/audio_model.rs
@@ -639,6 +639,22 @@ impl AudioReport {
&& self.damaged.is_empty()
}
+ /// Failure classes for `expectations.toml` (empty when passed).
+ pub fn classes(&self) -> Vec<&'static str> {
+ [
+ ("audio-missing", &self.missing),
+ ("audio-doubled", &self.doubled),
+ ("audio-unexpected", &self.unexpected),
+ ("audio-timing", &self.mistimed),
+ ("audio-level", &self.level),
+ ("audio-undecodable", &self.damaged),
+ ]
+ .into_iter()
+ .filter(|(_, list)| !list.is_empty())
+ .map(|(class, _)| class)
+ .collect()
+ }
+
pub fn summary(&self) -> String {
let mut parts = vec![format!(
"audio {}/{} required markers matched, max time error {:.3} ms, max level error {:.0}%, min correlation {:.2}",
diff --git a/crates/verify/src/lib.rs b/crates/verify/src/lib.rs
index 2de87cb49..a3f2407dc 100644
--- a/crates/verify/src/lib.rs
+++ b/crates/verify/src/lib.rs
@@ -2,6 +2,8 @@
//! timeline model and oracle checkers. See `crates/verify/README.md`.
pub mod audio_code;
+pub mod audio_fixture;
+pub mod audio_model;
pub mod catalog;
pub mod fixture;
#[cfg(target_os = "macos")]
@@ -11,5 +13,3 @@ pub mod model;
pub mod oracle;
pub mod report;
pub mod video_code;
-pub mod audio_fixture;
-pub mod audio_model;
diff --git a/crates/verify/tests/audio.rs b/crates/verify/tests/audio.rs
index 0746dc5c1..2e95997c7 100644
--- a/crates/verify/tests/audio.rs
+++ b/crates/verify/tests/audio.rs
@@ -156,11 +156,11 @@ fn export_case(spec: &FixtureSpec, variant: &Variant, path: ExportPath) -> Optio
RES,
dir.path(),
)) {
- Err(e) => case.problem(format!("export failed: {e}")),
+ Err(e) => case.problem("error", format!("export failed: {e}")),
Ok(out) => match path {
ExportPath::Gif => {
if audio_support::has_audio_stream(&out) {
- case.problem("GIF export has an audio stream");
+ case.problem("audio-unexpected", "GIF export has an audio stream");
}
}
ExportPath::Mov if !audio_support::has_audio_stream(&out) => {
@@ -171,7 +171,7 @@ fn export_case(spec: &FixtureSpec, variant: &Variant, path: ExportPath) -> Optio
_ => {
let model = audio_support::audio_model(&project, &config);
match audio_support::exported_mono(&out) {
- Err(e) => case.problem(e),
+ Err(e) => case.problem("error", e),
Ok(mono) => {
let report = audio_support::check_pcm(&mut case, "export", &model, &mono);
let frames = common::read_output(&out);
@@ -260,10 +260,10 @@ fn playback_case(spec: &FixtureSpec, variant: &Variant) -> Option<String> {
&audio_support::mono(&pcm),
);
if player.starved > 0 {
- case.problem(format!(
- "{} pulls starved (samples never rendered)",
- player.starved
- ));
+ case.problem(
+ "audio-starved",
+ format!("{} pulls starved (samples never rendered)", player.starved),
+ );
}
report::settle(case).err()
}
@@ -423,14 +423,14 @@ fn transport_case(
};
match audio_model::pcm_difference(pcm, &reference) {
None => case.note(format!("{label}: PCM identical to a fresh output")),
- Some((db, at)) => case.problem(format!(
+ Some((db, at)) => case.problem("pcm-mismatch", format!(
"{label}: PCM differs from a fresh output (peak difference {db:.1} dBFS, first at {:.4}s into the span)",
(at / audio_support::CHANNELS) as f64 / f64::from(audio_support::RATE)
)),
}
}
if player.starved > 0 {
- case.problem(format!("{} pulls starved", player.starved));
+ case.problem("audio-starved", format!("{} pulls starved", player.starved));
}
report::settle(case).err()
}
diff --git a/crates/verify/tests/audio_support/mod.rs b/crates/verify/tests/audio_support/mod.rs
index c87cb10c7..98636abbe 100644
--- a/crates/verify/tests/audio_support/mod.rs
+++ b/crates/verify/tests/audio_support/mod.rs
@@ -47,7 +47,11 @@ pub fn judge(case: &mut Case, label: &str, report: &AudioReport) {
if report.passed() {
case.note(format!("{label}: {}", report.summary()));
} else {
- case.problem(format!("{label}: {}", report.summary()));
+ let classes = report.classes();
+ for class in &classes[1..] {
+ case.classes.insert((*class).to_string());
+ }
+ case.problem(classes[0], format!("{label}: {}", report.summary()));
}
}
@@ -391,10 +395,13 @@ pub fn check_av(
if bad.is_empty() {
case.note(summary);
} else {
- case.problem(format!(
- "{summary}, {} out of sync (first: {})",
- bad.len(),
- bad.iter().take(3).cloned().collect::<Vec<_>>().join("; ")
- ));
+ case.problem(
+ "av-sync",
+ format!(
+ "{summary}, {} out of sync (first: {})",
+ bad.len(),
+ bad.iter().take(3).cloned().collect::<Vec<_>>().join("; ")
+ ),
+ );
}
}