From a5d92c231c1f4507a7265fe654086098f39b3c4e Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:42:10 +0200 Subject: [PATCH 1/2] fix(xtask): corpus --all --update-manifest refetches and rewrites every manifest (#948) --- xtask/src/corpus.rs | 62 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/xtask/src/corpus.rs b/xtask/src/corpus.rs index c47778731b..d655cc3a7c 100644 --- a/xtask/src/corpus.rs +++ b/xtask/src/corpus.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use std::process::Command; use crate::corpus_pins::{self, AG_PSD_COMMIT, HEIC_RS_COMMIT, OPENEXR_COMMIT, PHOTOCRAFT_CORPUS_COMMIT, PILLOW_HEIF_COMMIT, PNGSUITE_URL, PSD_TOOLS_COMMIT}; -use crate::pinned::USER_AGENT; +use crate::pinned::{PinnedCorpus, USER_AGENT}; use crate::{cargo, root, run}; /// Crates with corpus tests (behind their `corpus` feature). @@ -22,7 +22,7 @@ pub fn cmd(args: &[&str]) -> Result<(), String> { let update = args.contains(&"--update-manifest"); let mut did = false; if args.contains(&"--all") { - return fetch_all(args.contains(&"--local")); + return fetch_all(args.contains(&"--local"), update); } if args.contains(&"--pngsuite") || args.contains(&"--download") { fetch_pngsuite()?; @@ -70,20 +70,28 @@ fn local_clone() -> Result { } /// Fetches every corpus that is missing or stale (verified ones are left alone). With `local`, -/// `corpus/photoshop` is copied from the authoring clone of photocraft-corpus instead. -pub fn fetch_all(local: bool) -> Result<(), String> { +/// `corpus/photoshop` is copied from the authoring clone of photocraft-corpus instead. With +/// `update`, every pinned corpus is refetched and its manifest rewritten (`--update-manifest`). +pub fn fetch_all(local: bool, update: bool) -> Result<(), String> { fetch_pngsuite()?; - for c in corpus_pins::ALL { - if local && std::ptr::eq(*c, &corpus_pins::PHOTOSHOP) { - c.fetch_local(&local_clone()?, false)?; - } else { - c.fetch(false)?; - } - } + fetch_pinned(local, update, fetch_one)?; println!("all corpora present and verified under {}", root().join("corpus").display()); Ok(()) } +/// Calls `fetch(corpus, from_clone, update)` for every pinned corpus; `from_clone` is set for +/// `corpus/photoshop` when `local`. +fn fetch_pinned(local: bool, update: bool, mut fetch: impl FnMut(&PinnedCorpus, bool, bool) -> Result<(), String>) -> Result<(), String> { + for c in corpus_pins::ALL { + fetch(*c, local && std::ptr::eq(*c, &corpus_pins::PHOTOSHOP), update)?; + } + Ok(()) +} + +fn fetch_one(c: &PinnedCorpus, from_clone: bool, update: bool) -> Result<(), String> { + if from_clone { c.fetch_local(&local_clone()?, update) } else { c.fetch(update) } +} + fn status(present: bool) -> &'static str { if present { "present" } else { "missing" } } @@ -200,7 +208,7 @@ pub fn test_cmd(args: &[&str]) -> Result<(), String> { if crates.is_empty() { crates = CORPUS_CRATES.iter().map(|s| (*s).to_string()).collect(); } - fetch_all(ours.contains(&"--local"))?; + fetch_all(ours.contains(&"--local"), false)?; let mut c = cargo(); c.args(["test", "--release", "--lib", "--tests"]); for k in &crates { @@ -214,3 +222,33 @@ pub fn test_cmd(args: &[&str]) -> Result<(), String> { } run(c, &format!("cargo test --release --features corpus,heif ({})", crates.join(", "))) } + +#[cfg(test)] +mod tests { + use super::*; + + /// The flags each pinned corpus is fetched with by `fetch_all(local, update)`. + fn calls(local: bool, update: bool) -> Vec<(&'static str, bool)> { + let mut seen = Vec::new(); + let r = fetch_pinned(local, update, |c, _, u| { + seen.push((c.name, u)); + Ok(()) + }); + assert_eq!(r, Ok(())); + seen + } + + #[test] + fn all_with_update_manifest_updates_every_pinned_corpus() { + for local in [false, true] { + let seen = calls(local, true); + assert_eq!(seen.len(), corpus_pins::ALL.len()); + assert!(seen.iter().all(|(_, u)| *u), "--all --update-manifest dropped the flag: {seen:?}"); + } + } + + #[test] + fn all_without_update_manifest_only_verifies() { + assert!(calls(false, false).iter().all(|(_, u)| !*u)); + } +} From fee28f3a1b33873336ebae3d7e93c87dd6c7da76 Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Fri, 9 Oct 2026 11:34:11 +0200 Subject: [PATCH 2/2] xtask corpus: pass the pinned corpus without an explicit deref (clippy) (#948) --- xtask/src/corpus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/corpus.rs b/xtask/src/corpus.rs index d655cc3a7c..be62e6fa6f 100644 --- a/xtask/src/corpus.rs +++ b/xtask/src/corpus.rs @@ -83,7 +83,7 @@ pub fn fetch_all(local: bool, update: bool) -> Result<(), String> { /// `corpus/photoshop` when `local`. fn fetch_pinned(local: bool, update: bool, mut fetch: impl FnMut(&PinnedCorpus, bool, bool) -> Result<(), String>) -> Result<(), String> { for c in corpus_pins::ALL { - fetch(*c, local && std::ptr::eq(*c, &corpus_pins::PHOTOSHOP), update)?; + fetch(c, local && std::ptr::eq(*c, &corpus_pins::PHOTOSHOP), update)?; } Ok(()) }