mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge approved PhotoCraft PR #9019: fix(xtask): reject unknown performance benchmark selections
Port behavior and regression coverage into current modules; preserve current upstream behavior. Validate benchmark names before both measurement and baseline-from-files paths, retaining newer baseline modes.
This commit is contained in:
commit
32722ffcbf
2 files changed
+27
No files matched your search
@@ -487,6 +487,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 <name>` 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
|
||||
|
||||
@@ -869,6 +869,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 baseline_value: Option<Value> = std::fs::read_to_string(root.join(BASELINE)).ok().and_then(|t| serde_json::from_str(&t).ok());
|
||||
if !o.from.is_empty() {
|
||||
return baseline_from_files(root, &budgets, baseline_value.as_ref(), &o);
|
||||
@@ -1556,6 +1561,26 @@ row = "r99"
|
||||
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());
|
||||
|
||||
Reference in new issue
Block a user