//! [`bin/inline_atomic_generation_loop.rs`](../inline_atomic_generation_loop.rs)'s //! counterpart for the fixed-table-layout function: compiles the hand-written candidates in //! `crates/generation/fixtures/table-candidates` into one batch crate, runs every candidate //! over the cached corpus, and gates each against the permanent regression set //! (`generation::table_runner::evaluate`). Requires `table_ground_truth_cache` to have //! already populated `corpus/table-ground-truth/`. //! //! Like the inline-atomic loop, this one never admits anything: //! `specs/tables-fixed-layout.md` is explicit that a correct implementation is not written //! by hand before every model batch has failed, so there is no `correct` fixture here, only //! `baseline` and two deliberately wrong candidates this binary proves the gate rejects. All //! three seed the regression set (the comment at the seeding site says why the baseline alone //! is not enough). use anyhow::{bail, Result}; use generation::candidate_crate; use generation::groundtruth::load_all; use generation::model::{CandidateSource, DirectoryCandidateSource}; use generation::orchestrate::{repo_root, run_candidates, write_regression_set}; use generation::table_runner::{passing_case_ids, TableCandidate}; fn main() -> Result<()> { let repo_root = repo_root(); let cache_dir = repo_root.join("corpus/table-ground-truth"); let cases = load_all(&cache_dir)?; if cases.is_empty() { bail!("no cached cases under {}; run the table_ground_truth_cache binary first", cache_dir.display()); } let fixtures_dir = repo_root.join("crates/generation/fixtures/table-candidates"); let candidates = DirectoryCandidateSource { dir: fixtures_dir }.candidates()?; println!("candidates: {}", candidates.iter().map(|c| c.name.as_str()).collect::>().join(", ")); let crate_dir = repo_root.join("corpus/candidates/table-generated"); candidate_crate::write_for(candidate_crate::Seam::TableFixedLayout, &crate_dir, &repo_root, &candidates)?; let binary = candidate_crate::compile(&crate_dir, &crate_dir.join("target"))?; let regression_set_path = repo_root.join("corpus/table-regression-set.json"); let report_out = repo_root.join("corpus/candidates/table-report.json"); // Seeded from every case any hand-written fixture passes -- the shipped (deliberately // wrong) baseline's own and both seeded-wrong candidates' -- not the baseline's alone, the // way `bin/inline_atomic_generation_loop.rs` already seeds, and for the same reason. Each // seeded-wrong fixture is wrong in one respect and right in the others, so the union is // the set of cases known to be achievable, and a candidate wrong in any one of those // respects loses some of it. // // The baseline alone would be worse here than almost anywhere: it gives every column the // whole table width and stacks a row's cells, which is the wrong answer for every case in // this corpus with more than one cell in a row -- so a gate seeded from the baseline would // have almost nothing to catch a wrong candidate on, and `ignores_a_rows_own_height` // (which is right about everything else) would sail through it. if !regression_set_path.exists() { let ungated = run_candidates(&binary, &cache_dir, None, &report_out)?; let baseline = TableCandidate { name: "baseline", columns: layout::table::columns_baseline, rows: layout::table::rows_baseline, }; let mut seed: Vec = passing_case_ids(baseline, &cases); for candidate in &ungated.candidates { for id in &candidate.passed_case_ids { if !seed.contains(id) { seed.push(id.clone()); } } } write_regression_set(®ression_set_path, &seed)?; println!( "seeded the permanent regression set with {} case(s) at least one fixture already passes", seed.len() ); } let gated = run_candidates(&binary, &cache_dir, Some(®ression_set_path), &report_out)?; println!("\n== per-candidate results =="); for candidate in &gated.candidates { println!( "{:<28} {}/{} passed, admitted={}, regressed={}", candidate.name, candidate.cases_passed, candidate.cases_run, candidate.admitted, candidate.regressed_cases.len(), ); let mut categories: Vec<_> = candidate.per_category.iter().collect(); categories.sort_by_key(|(name, _)| (*name).clone()); for (category, tally) in categories { println!(" {category:<32} {}/{}", tally.passed, tally.total); } } // Prove the gate discriminates: every seeded-wrong candidate must not be admitted, given // this fixture set. No `correct` candidate exists yet to also check the positive case with // (this binary's own module doc). If one is admitted, the loop or the corpus is wrong, not // the fixture (`specs/tables-fixed-layout.md`). let get = |name: &str| gated.candidates.iter().find(|c| c.name == name); let wrong_names = ["ignores_border_spacing", "ignores_a_rows_own_height"]; let mut discrimination_ok = true; for name in wrong_names { match get(name) { Some(wrong) if wrong.admitted => { discrimination_ok = false; eprintln!("gate did not reject seeded-wrong candidate {name}"); } Some(_) => {} None => bail!("no candidate named {name:?} in the batch"), } } if !discrimination_ok { bail!("the generation loop did not reject every seeded-wrong candidate"); } println!("\ngate rejected every seeded-wrong candidate"); Ok(()) }