open-standards/wai/wai-rs/tests/corpus_provenance.rs
Transaction Science 3fac029a71 wai: every corpus states the provenance of its content
Each *-conformance/README.md now has a line that begins **Provenance.**:
the generator that writes the corpus and its input, and for an input not
generated here its source and licence. OER/2's corpus is settled and left
as it is. byte-exact-conformance and quantum-ops-conformance get a README.
wai-rs/tests/vectors/README.md gives a row per vector directory. Where the
staged-delivery, staged-measurement and telemetry READMEs called their
content "synthetic", that sentence is now their provenance line.

Two vectors are recorded as not generated, from the provenance audit:
int_video's video_real (a pan over a third-party picture) and
neural-conformance's photo (a third-party picture, with a decoder trained on
unrecorded images). Their lines say so and that they are to be replaced;
the photo bullet no longer names the picture's source product.

tests/corpus_provenance.rs requires the line in every corpus and a row for
every vector directory; CI runs it with the carriage tests. CONTRIBUTING
states the rule: corpus content is generated here, or recorded with a
licence that permits redistribution, and a word like "synthetic" is not a
provenance line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-07 10:09:21 -04:00

73 lines
2.9 KiB
Rust

//! Every corpus states where its content comes from (CONTRIBUTING, *Corpus content*).
//!
//! Each `wai/*-conformance/` directory has a `README.md` with a line that begins
//! `**Provenance.**`, and `tests/vectors/README.md` has a row for every directory under
//! `tests/vectors/` whose provenance cell is not empty. A provenance line names the
//! generator that writes the content and the generator's input; an input not generated
//! in this repository is named with its source and its licence. The test holds the
//! line's presence, not its truth: that is a reviewer's, and for audio also
//! `tools/wai_audio_provenance_check.py`'s.
use std::path::PathBuf;
fn wai() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..")
}
/// The line a README states its provenance in, if it has one with text after the label.
fn provenance_line(readme: &str) -> Option<&str> {
readme
.lines()
.map(str::trim_start)
.find(|l| l.starts_with("**Provenance.**") && l.len() > "**Provenance.**".len() + 1)
}
#[test]
fn every_conformance_corpus_states_its_provenance() {
// OER/2 is settled: no change edits its documents or its corpus.
let settled = ["oer-conformance"];
let mut dirs: Vec<String> = std::fs::read_dir(wai())
.unwrap()
.flatten()
.filter(|e| e.path().is_dir())
.map(|e| e.file_name().to_string_lossy().into_owned())
.filter(|n| n.ends_with("-conformance"))
.collect();
dirs.sort();
assert!(dirs.len() > 10, "found {} corpora", dirs.len());
let mut missing = Vec::new();
for d in &dirs {
if settled.contains(&d.as_str()) {
continue;
}
match std::fs::read_to_string(wai().join(d).join("README.md")) {
Ok(text) if provenance_line(&text).is_some() => {}
Ok(_) => missing.push(format!("{d}/README.md has no `**Provenance.**` line")),
Err(_) => missing.push(format!("{d} has no README.md")),
}
}
assert!(missing.is_empty(), "corpora without a provenance line:\n {}", missing.join("\n "));
}
#[test]
fn every_vector_directory_states_its_provenance() {
let root = wai().join("wai-rs/tests/vectors");
let index = std::fs::read_to_string(root.join("README.md")).expect("tests/vectors/README.md");
let mut dirs: Vec<String> = std::fs::read_dir(&root)
.unwrap()
.flatten()
.filter(|e| e.path().is_dir())
.map(|e| e.file_name().to_string_lossy().into_owned())
.collect();
dirs.sort();
let mut missing = Vec::new();
for d in &dirs {
// A row: | `<dir>/` | <provenance> | …
let row = index.lines().find(|l| l.trim_start().starts_with(&format!("| `{d}/` |")));
let cell = row.and_then(|r| r.split('|').nth(2)).map(str::trim).unwrap_or("");
if cell.is_empty() {
missing.push(d.clone());
}
}
assert!(missing.is_empty(), "tests/vectors/README.md states no provenance for: {missing:?}");
}