mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-02 18:13:39 +00:00
fix(xtask): derive scorecard corpus counts from pinned manifests
This commit is contained in:
+35
-2
@@ -5,6 +5,7 @@
|
||||
//! numbers against the budgets). A fresh `cargo xtask perf` result in `target/` is not used:
|
||||
//! publish it with `cargo xtask perf --update-baseline`.
|
||||
//! - `crates/io/tests/corpus.rs`: the corpus floors (`Source { .. }` constants).
|
||||
//! - `xtask/*-corpus.sha256`: file counts for the pinned corpora.
|
||||
//! - `scorecard/*.toml`: per-area checklists (id, target, status, issue, note).
|
||||
//! - the prefs audit: `Preferences` fields that no code outside `prefs.rs` / `prefs_ui.rs` reads.
|
||||
//! - counted from the tree: never-crash attribute coverage, `docs/parity-checklist.md`'s live count.
|
||||
@@ -474,7 +475,15 @@ pub fn gather(root: &Path) -> Result<Inputs, String> {
|
||||
Ok(t) => Some(serde_json::from_str(&t).map_err(|e| format!("{}: {e}", perf::BASELINE))?),
|
||||
Err(_) => None,
|
||||
};
|
||||
let corpora = parse_corpus(&std::fs::read_to_string(root.join(CORPUS_RS)).map_err(|e| format!("read {CORPUS_RS}: {e}"))?);
|
||||
let mut corpora = parse_corpus(&std::fs::read_to_string(root.join(CORPUS_RS)).map_err(|e| format!("read {CORPUS_RS}: {e}"))?);
|
||||
for corpus in &mut corpora {
|
||||
let Some(pinned) = crate::corpus_pins::ALL.iter().find(|p| corpus.dir == format!("corpus/{}", p.dest)) else { continue };
|
||||
let manifest = std::fs::read_to_string(root.join(pinned.manifest)).map_err(|e| format!("read {}: {e}", pinned.manifest))?;
|
||||
corpus.files = Some(
|
||||
u32::try_from(manifest.lines().filter(|line| !line.trim().is_empty()).count())
|
||||
.map_err(|_| format!("{}: corpus file count exceeds u32", pinned.manifest))?,
|
||||
);
|
||||
}
|
||||
Ok(Inputs {
|
||||
budgets,
|
||||
baseline,
|
||||
@@ -522,7 +531,7 @@ pub fn render(inp: &Inputs) -> String {
|
||||
|
||||
let mut s = String::from(
|
||||
"# PhotoCraft scorecard\n\nGenerated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.json`, \
|
||||
`crates/io/tests/corpus.rs`, `scorecard/*.toml` and the source tree. Do not edit by hand: change the sources and \
|
||||
`crates/io/tests/corpus.rs`, `xtask/*-corpus.sha256`, `scorecard/*.toml` and the source tree. Do not edit by hand: change the sources and \
|
||||
regenerate (CI runs `cargo xtask scorecard --check`). Checklist statuses are verified against the code; numbers \
|
||||
here supersede estimates elsewhere.\n\n## Summary\n\n| Area | Done | Partial | Missing | Key numbers |\n|---|---:|---:|---:|---|\n",
|
||||
);
|
||||
@@ -791,6 +800,30 @@ const PHOTOSHOP: Source = Source { label: "photoshop oracles", dir: "corpus/phot
|
||||
assert!(parse_corpus("const X: u32 = 1;").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scorecard_uses_pinned_corpus_file_counts() {
|
||||
let root = crate::root();
|
||||
let inp = gather(&root).unwrap();
|
||||
let rendered = render(&inp);
|
||||
for corpus in &inp.corpora {
|
||||
let pinned = crate::corpus_pins::ALL.iter().find(|p| corpus.dir == format!("corpus/{}", p.dest)).unwrap();
|
||||
let manifest = std::fs::read_to_string(root.join(pinned.manifest)).unwrap();
|
||||
let files = manifest.lines().filter(|line| !line.trim().is_empty()).count();
|
||||
assert!(
|
||||
rendered.contains(&format!(
|
||||
"{}: oracle ≥ {}/{files}, round trip ≥ {}/{files}",
|
||||
corpus.label,
|
||||
corpus.pass_floor.unwrap(),
|
||||
corpus.roundtrip_floor.unwrap()
|
||||
)),
|
||||
"{} must use the {files} files in {} instead of a count from a doc comment",
|
||||
corpus.label,
|
||||
pinned.manifest
|
||||
);
|
||||
assert!(rendered.contains(&format!("| {} | `{}` | {files} |", corpus.label, corpus.dir)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checklists_validate() {
|
||||
let ok = "area = \"tools\"\ntitle = \"Tools\"\norder = 3\n[[item]]\nid = \"T-1\"\ntarget = \"Pencil\"\nstatus = \"partial\"\nissue = 213\n";
|
||||
|
||||
Reference in New Issue
Block a user