Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(verify): TOML strict-xfail expectations with failure classes, bless mode, main baseline
Richie McIlroy240816dd2e0f
diff --git a/Cargo.lock b/Cargo.lockindex 1728a2195..c4fa7253a 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -2173,6 +2173,7 @@ dependencies = ["serde_json","tempfile","tokio",+ "toml 0.8.2","workspace-hack",]diff --git a/crates/verify/Cargo.toml b/crates/verify/Cargo.tomlindex de97a2b66..b0da67135 100644--- a/crates/verify/Cargo.toml+++ b/crates/verify/Cargo.toml@@ -22,6 +22,7 @@ rustfft = "6.4.1"serde = { workspace = true }serde_json = "1"tokio = { workspace = true }+toml = "0.8"workspace-hack = { version = "0.1", path = "../workspace-hack" }[target.'cfg(target_os = "macos")'.dependencies]diff --git a/crates/verify/expectations.toml b/crates/verify/expectations.tomlnew file mode 100644index 000000000..75634fa0a--- /dev/null+++ b/crates/verify/expectations.toml@@ -0,0 +1,97 @@+# Strict expected failures for the engine verification suite+# (`cargo test -p cap-verify`), same shape as the decoder model's+# crates/rendering/src/decoder/model/expectations.toml:+#+# [[xfail]]+# case = "<case id as printed by the suite, * globs allowed>"+# class = "<stale | future | wrong-segment | unreadable | missing | unexpected+# | frame-count | timestamps | nondeterministic | error>"+# reason = "<what is wrong>"+# link = "<PR or issue that fixes it; empty when no fix exists yet>"+# platforms = ["macos"] (optional; absent = every platform)+# flaky = true (optional; timing-dependent, may pass. State the+# measured rate in the reason.)+#+# A listed class that no longer occurs fails the run with "remove this+# xfail", so fixes stay locked in. A class that occurs and is not listed+# fails the run. CAP_VERIFY_BLESS=<dir> writes draft entries for every+# failing case instead of failing; review them before pasting here.+#+# Recorded on origin/main 5705ee851. "NEW:" marks bugs the suite found that+# no open PR fixes.++[[xfail]]+case = "export/jitter-camera-*/full/mp460/avf"+class = "future"+platforms = ["macos"]+reason = "Camera runaway: with a jittery ~12 fps camera at 30 fps nominal exported at 60 fps, the pts-hole map evicts the hole it just recorded once 64 wider ones are tracked, and the reader drifts ahead (40 s fixture: 531 camera frames ahead, up to 298 source frames)"+link = "https://github.com/CapSoftware/Cap/pull/2595"++[[xfail]]+case = "export/backward-hold/backward-jumps/mp460/avf"+class = "stale"+platforms = ["macos"]+reason = "AVAssetReader serves one camera frame 1 source frame stale after the timeline jumps backward (output frame 2579)"+link = "https://github.com/CapSoftware/Cap/pull/2595"++[[xfail]]+case = "export/early-camera/full/*"+class = "future"+reason = "NEW: the auto-calculated clip camera offset repeats the decoder's start-time alignment, so a camera that started before the latest track plays (latest - camera.start) ahead (1.0 s here). Real when the mic is slow to start"+link = ""++[[xfail]]+case = "export/camera-pts-late/full/mp430/avf"+class = "future"+platforms = ["macos"]+reason = "A camera file whose pts start 2 s in runs ahead from the first output frame instead of holding its first frame"+link = "https://github.com/CapSoftware/Cap/pull/2603"++[[xfail]]+case = "export/camera-pts-late/full/mp430/ffmpeg"+class = "future"+reason = "NEW: FFmpeg decoder, same as the AVAssetReader case: a camera file whose pts start 2 s in runs ahead from the first output frame (178 of 179 frames)"+link = ""++[[xfail]]+case = "seek/seek-*/keyframes60/avf"+class = "stale"+platforms = ["macos"]+reason = "Wrong-GOP seek: the reader starts on the keyframe time rounded to 10 ms, decodes the previous GOP and shows its last frame under the keyframe's number (requests between the keyframe pts and the next slot show keyframe - 1)"+link = "https://github.com/CapSoftware/Cap/pull/2603"++[[xfail]]+case = "seek/seek-*/storm30/avf"+class = "stale"+platforms = ["macos"]+reason = "A reused AVAssetReader answers from a frame cached by an earlier, unrelated seek (frame 349 shows 237)"+link = "https://github.com/CapSoftware/Cap/pull/2603"++[[xfail]]+case = "seek/vfr-holds/storm60/avf"+class = "future"+platforms = ["macos"]+reason = "Seek storm over long VFR holds: AVAssetReader shows a frame from the far side of a hold (expected 60, got 217)"+link = "https://github.com/CapSoftware/Cap/pull/2603"++[[xfail]]+case = "seek/vfr-holds/storm60/avf"+class = "stale"+platforms = ["macos"]+flaky = true+reason = "Same storm, an additional stale answer in 3 of 4 runs on main (timing-dependent reader reuse)"+link = "https://github.com/CapSoftware/Cap/pull/2603"++[[xfail]]+case = "seek/vfr-holds/into-holds60/avf"+class = "stale"+platforms = ["macos"]+flaky = true+reason = "Camera one frame stale after a seek into a hold, 3 of 4 runs on main"+link = "https://github.com/CapSoftware/Cap/pull/2603"++[[xfail]]+case = "seek/*/storm*/ffmpeg"+class = "stale"+reason = "NEW: FFmpeg decoder seeks answer stale frames: the backward-seek lookback tolerance serves a cached frame 1-4 source frames old, and seeks near the start show frame 0 (up to 67 source frames stale)"+link = ""diff --git a/crates/verify/expectations.txt b/crates/verify/expectations.txtdeleted file mode 100644index e69de29bb..000000000diff --git a/crates/verify/src/report.rs b/crates/verify/src/report.rsindex b4b1bfb87..92b57b74d 100644--- a/crates/verify/src/report.rs+++ b/crates/verify/src/report.rs@@ -56,6 +56,8 @@ pub struct Case {started: Instant,pub streams: Vec<StreamReport>,pub problems: Vec<String>,+ /// Failure classes seen (see `expectations.toml`).+ pub classes: std::collections::BTreeSet<String>,pub notes: Vec<String>,}@@ -68,11 +70,15 @@ impl Case {started: Instant::now(),streams: Vec::new(),problems: Vec::new(),+ classes: Default::default(),notes: Vec::new(),}}- pub fn problem(&mut self, text: impl Into<String>) {+ /// Records a failure of the given class (`error`, `frame-count`,+ /// `nondeterministic`, ...).+ pub fn problem(&mut self, class: &str, text: impl Into<String>) {+ self.classes.insert(class.to_string());self.problems.push(text.into());}@@ -82,6 +88,18 @@ impl Case {pub fn stream(&mut self, report: StreamReport) {if !report.passed() {+ for (class, n) in [+ ("stale", report.stale),+ ("future", report.ahead),+ ("wrong-segment", report.wrong_segment),+ ("unreadable", report.unreadable),+ ("missing", report.missing),+ ("unexpected", report.unexpected),+ ] {+ if n > 0 {+ self.classes.insert(class.to_string());+ }+ }self.problems.push(report.summary());}self.streams.push(report);@@ -92,12 +110,31 @@ impl Case {}}-#[derive(Clone, Debug)]+/// One `[[xfail]]` entry of `crates/verify/expectations.toml` (the same+/// shape as the decoder model's expectations file).+#[derive(Clone, Debug, Deserialize, Serialize)]pub struct Xfail {- pub line: usize,- pub pattern: String,- pub platforms: Vec<String>,+ /// Case id, `*` globs allowed.+ pub case: String,+ /// Failure class that must still occur.+ pub class: String,pub reason: String,+ #[serde(default)]+ pub link: String,+ /// Platforms the entry applies to (`macos`, `linux`, `windows`); empty+ /// means all.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub platforms: Vec<String>,+ /// Timing-dependent: the case may pass or fail with this class. Use only+ /// with a measured flake rate in the reason.+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]+ pub flaky: bool,+}++#[derive(Deserialize)]+struct ExpectationsFile {+ #[serde(default)]+ xfail: Vec<Xfail>,}fn glob_match(pattern: &str, text: &str) -> bool {@@ -125,38 +162,27 @@ fn glob_match(pattern: &str, text: &str) -> bool {}pub fn expectations_path() -> PathBuf {- PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("expectations.txt")+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("expectations.toml")}-/// Parses `expectations.txt`: `<case glob> <platforms|all> <reason...>`.pub fn load_expectations() -> Vec<Xfail> {let text = std::fs::read_to_string(expectations_path()).unwrap_or_default();- text.lines()- .enumerate()- .filter_map(|(i, line)| {- let line = line.trim();- if line.is_empty() || line.starts_with('#') {- return None;- }- let mut fields = line.split_whitespace();- let pattern = fields.next()?.to_string();- let platforms = fields.next()?.split(',').map(str::to_string).collect();- let reason = fields.collect::<Vec<_>>().join(" ");- Some(Xfail {- line: i + 1,- pattern,- platforms,- reason,- })- })- .collect()+ match toml::from_str::<ExpectationsFile>(&text) {+ Ok(file) => file.xfail,+ Err(error) => panic!("{}: {error}", expectations_path().display()),+ }}-pub fn lookup_xfail(id: &str) -> Option<Xfail> {+/// Entries that apply to `id` on this platform.+pub fn xfails_for(id: &str) -> Vec<Xfail> {let platform = platform();- load_expectations().into_iter().find(|x| {- glob_match(&x.pattern, id) && x.platforms.iter().any(|p| p == "all" || p == platform)- })+ load_expectations()+ .into_iter()+ .filter(|x| {+ glob_match(&x.case, id)+ && (x.platforms.is_empty() || x.platforms.iter().any(|p| p == platform))+ })+ .collect()}fn repro_command(id: &str) -> String {@@ -198,8 +224,27 @@ fn write_result(result: &CaseResult) {/// Settles a case against the expectations file. Returns an error message/// when the test must fail.pub fn settle(case: Case) -> Result<CaseResult, String> {- let xfail = lookup_xfail(&case.id);+ let xfails = xfails_for(&case.id);let failed = case.failed();+ let repro = repro_command(&case.id);+ let unexpected: Vec<&String> = case+ .classes+ .iter()+ .filter(|class| !xfails.iter().any(|x| &x.class == *class))+ .collect();+ let fixed: Vec<&Xfail> = xfails+ .iter()+ .filter(|x| !x.flaky && !case.classes.contains(&x.class))+ .collect();+ let outcome = if !unexpected.is_empty() {+ "FAIL"+ } else if !fixed.is_empty() {+ "XPASS"+ } else if failed {+ "xfail"+ } else {+ "pass"+ };let mut summary = if failed {case.problems.join("\n ")} else {@@ -210,24 +255,24 @@ pub fn settle(case: Case) -> Result<CaseResult, String> {.collect();format!("all checks passed: {}", streams.join(", "))};- let repro = repro_command(&case.id);- let outcome = match (&xfail, failed) {- (None, false) => "pass",- (Some(_), true) => "xfail",- (None, true) => "FAIL",- (Some(_), false) => "XPASS",- };- if let Some(x) = &xfail {- summary = format!(- "{summary}\n (expected failure, expectations.txt:{}: {})",- x.line, x.reason- );+ for x in &xfails {+ summary.push_str(&format!(+ "\n (expected {}{}: {} {})",+ x.class,+ if x.flaky { ", flaky" } else { "" },+ x.reason,+ x.link+ ));+ }+ let blessing = std::env::var_os("CAP_VERIFY_BLESS").is_some();+ if blessing && failed {+ bless(&case);}let result = CaseResult {id: case.id.clone(),platform: platform().to_string(),tier: tier(),- passed: matches!(outcome, "pass" | "xfail"),+ passed: blessing || matches!(outcome, "pass" | "xfail"),summary: summary.clone(),streams: case.streams,notes: case.notes,@@ -240,21 +285,65 @@ pub fn settle(case: Case) -> Result<CaseResult, String> {"[cap-verify] {outcome} {} in {:.1}s\n {summary}",result.id, result.seconds);+ if blessing {+ return Ok(result);+ }match outcome {"FAIL" => Err(format!(- "case {} failed:\n {summary}\n repro: {repro}",- result.id+ "case {} failed ({}):\n {summary}\n repro: {repro}",+ result.id,+ unexpected+ .iter()+ .map(|c| c.as_str())+ .collect::<Vec<_>>()+ .join(", "))),"XPASS" => Err(format!(- "case {} now passes: remove its xfail ({}:{})\n repro: {repro}",+ "case {} no longer fails with {}: remove that xfail from {}\n repro: {repro}",result.id,- expectations_path().display(),- xfail.map_or(0, |x| x.line)+ fixed+ .iter()+ .map(|x| x.class.as_str())+ .collect::<Vec<_>>()+ .join(", "),+ expectations_path().display())),_ => Ok(result),}}+/// `CAP_VERIFY_BLESS=<dir>`: record every failing case's classes as draft+/// `[[xfail]]` entries (one file per process) instead of failing.+fn bless(case: &Case) {+ let Some(dir) = std::env::var_os("CAP_VERIFY_BLESS") else {+ return;+ };+ let dir = PathBuf::from(dir);+ let _ = std::fs::create_dir_all(&dir);+ let file = dir.join(format!("bless-{}-{}.toml", platform(), std::process::id()));+ let Ok(mut f) = std::fs::OpenOptions::new()+ .create(true)+ .append(true)+ .open(file)+ else {+ return;+ };+ let reason = case.problems.first().cloned().unwrap_or_default();+ for class in &case.classes {+ let entry = Xfail {+ case: case.id.clone(),+ class: class.clone(),+ reason: reason.clone(),+ link: String::new(),+ platforms: vec![platform().to_string()],+ flaky: false,+ };+ if let Ok(text) = toml::to_string(&entry) {+ let _ = writeln!(f, "[[xfail]]\n{text}");+ }+ }+}+#[cfg(test)]mod tests {use super::glob_match;diff --git a/crates/verify/tests/common/mod.rs b/crates/verify/tests/common/mod.rsindex 9aba10e4c..d56c0e5c6 100644--- a/crates/verify/tests/common/mod.rs+++ b/crates/verify/tests/common/mod.rs@@ -217,11 +217,14 @@ pub fn check_sequence() {let expected_count = model.output_frames(fps);if frames.len() as u32 != expected_count {- case.problem(format!(- "output has {} frames, the model expects {expected_count} ({:.3}s at {fps} fps)",- frames.len(),- model.duration()- ));+ case.problem(+ "frame-count",+ format!(+ "output has {} frames, the model expects {expected_count} ({:.3}s at {fps} fps)",+ frames.len(),+ model.duration()+ ),+ );}if check_timestamps {let off_grid: Vec<(usize, f64)> = frames@@ -232,9 +235,10 @@ pub fn check_sequence(.take(5).collect();if !off_grid.is_empty() {- case.problem(format!(- "output timestamps off the {fps} fps grid: {off_grid:?}"- ));+ case.problem(+ "timestamps",+ format!("output timestamps off the {fps} fps grid: {off_grid:?}"),+ );}}let n = frames.len().min(expected_count as usize);diff --git a/crates/verify/tests/export.rs b/crates/verify/tests/export.rsindex b06799b18..2fa2c5eec 100644--- a/crates/verify/tests/export.rs+++ b/crates/verify/tests/export.rs@@ -61,7 +61,7 @@ fn run(};let first = dir.path().join(format!("a.{ext}"));match rt.block_on(common::export(&project, config.clone(), &run, &first)) {- Err(e) => case.problem(format!("export failed: {e}")),+ Err(e) => case.problem("error", format!("export failed: {e}")),Ok(path) => {let frames = common::read_output(&path);common::check_sequence(@@ -74,7 +74,9 @@ fn run(if determinism {let second = dir.path().join(format!("b.{ext}"));match rt.block_on(common::export(&project, config, &run, &second)) {- Err(e) => case.problem(format!("second export failed: {e}")),+ Err(e) => {+ case.problem("error", format!("second export failed: {e}"))+ }Ok(path) => {let again = common::read_output(&path);let differing: Vec<usize> = frames@@ -85,7 +87,9 @@ fn run(.map(|(i, _)| i).collect();if !differing.is_empty() || frames.len() != again.len() {- case.problem(format!(+ case.problem(+ "nondeterministic",+ format!("nondeterministic: {} of {} frames differ between two exports (first {:?})",differing.len(),frames.len(),diff --git a/crates/verify/tests/playback.rs b/crates/verify/tests/playback.rsindex 72c52ca05..e7e471c6d 100644--- a/crates/verify/tests/playback.rs+++ b/crates/verify/tests/playback.rs@@ -74,7 +74,7 @@ fn sequential(});match result {Ok(readouts) => common::check_requests(&mut case, &model, &frames, &readouts, fps),- Err(e) => case.problem(e),+ Err(e) => case.problem("error", e),}if let Err(message) = report::settle(case) {failures.push(message);diff --git a/crates/verify/tests/seek.rs b/crates/verify/tests/seek.rsindex 8e749823b..607081137 100644--- a/crates/verify/tests/seek.rs+++ b/crates/verify/tests/seek.rs@@ -51,7 +51,7 @@ fn run(let frames: Vec<u32> = requests.iter().map(|r| r.0).collect();match result {Ok(readouts) => common::check_requests(&mut case, &model, &frames, &readouts, fps),- Err(e) => case.problem(e),+ Err(e) => case.problem("error", e),}if let Err(message) = report::settle(case) {failures.push(message);@@ -237,7 +237,7 @@ fn cold_open() {});match result {Ok(readout) => readouts.push(readout),- Err(e) => case.problem(e),+ Err(e) => case.problem("error", e),}}if readouts.len() == frames.len() {