From 364c4be1c19728aefa601ee924bc7a0cd6a09789 Mon Sep 17 00:00:00 2001 From: Lucenx9 <185146821+Lucenx9@users.noreply.github.com> Date: Sat, 24 Oct 2026 01:48:25 +0200 Subject: [PATCH] fix(xtask): reject unknown performance benchmark selections --- docs/development.md | 2 ++ xtask/src/perf.rs | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/docs/development.md b/docs/development.md index 40b044fdd5..59ca988943 100644 --- a/docs/development.md +++ b/docs/development.md @@ -429,6 +429,8 @@ cargo run --release -p photocraft-ui-egui --example perf_scenarios -- \ That writes the row's own report and stops there: it does **not** evaluate the budget, so read `p50_ms`/`p95_ms`/`max_ms` out of the JSON yourself. Use `cargo xtask perf --bench ` when you want the verdict, the merged `results.json`/`summary.md` and the regression check. +Every `--bench` name must match a `[[bench]]` name in `perf/budgets.toml`; an unknown name +is rejected before any benchmark runs or any report or baseline is written. Read the sample count before quoting a percentile. `--reps` defaults to 7 in `--quick` and 15 otherwise, it is per bench, and some rows cap it themselves (the `#211` algorithm rows use diff --git a/xtask/src/perf.rs b/xtask/src/perf.rs index c1890d1cbd..f1aa016714 100644 --- a/xtask/src/perf.rs +++ b/xtask/src/perf.rs @@ -670,6 +670,11 @@ pub fn run(root: &Path, rest: &[&str]) -> Result<(), String> { let o = parse_opts(rest)?; let text = std::fs::read_to_string(root.join(BUDGETS)).map_err(|e| format!("read {BUDGETS}: {e}"))?; let budgets = parse_budgets(&text)?; + for name in &o.benches { + if !budgets.bench.iter().any(|b| &b.name == name) { + return Err(format!("perf: unknown bench `{name}` (see {BUDGETS})")); + } + } let mode = if o.quick { "quick" } else { "full" }; let threshold = o.threshold.unwrap_or(budgets.settings.regression_pct); let target = target_dir()?; @@ -1118,6 +1123,26 @@ not_measurable = "needs a frame harness" assert_eq!(counts(&evaluate(&b, &reports, None, 15.0, true)), (1, 1, 0, 1), "the row the bench lacks counts as failing"); } + #[test] + fn unknown_bench_is_rejected_before_updating_the_baseline() { + let root = std::env::temp_dir().join(format!("photocraft-perf-unknown-bench-{}", std::process::id())); + std::fs::create_dir(&root).unwrap(); + std::fs::create_dir(root.join("perf")).unwrap(); + std::fs::write(root.join(BUDGETS), "[[bench]]\nname = \"known\"\npackage = \"unused\"\nrequires = \"missing.rs\"\n").unwrap(); + let baseline = "{\"schema\":1,\"sentinel\":true}"; + std::fs::write(root.join(BASELINE), baseline).unwrap(); + let results = [ + run(&root, &["--bench", "unknown", "--reuse", "--update-baseline"]), + run(&root, &["--bench", "known", "--bench", "unknown", "--quick", "--reuse", "--update-baseline"]), + ]; + let after = std::fs::read_to_string(root.join(BASELINE)).unwrap(); + std::fs::remove_dir_all(root).unwrap(); + for result in results { + assert_eq!(result, Err(format!("perf: unknown bench `unknown` (see {BUDGETS})"))); + } + assert_eq!(after, baseline, "an unknown bench must not update the baseline"); + } + #[test] fn options() { assert!(parse_opts(&["--bogus"]).is_err());