Something went wrong. Try again.
Exploring the idea of generated web rendering engine.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123//! [`bin/transform_generation_loop.rs`](../transform_generation_loop.rs)'s counterpart//! for the inline-atomic function: compiles the hand-written candidates in//! `crates/generation/fixtures/inline-atomic-candidates` into one batch crate, runs every//! candidate over the cached corpus, and gates each against the permanent regression set//! (`generation::inline_atomic_runner::evaluate`). Requires//! `inline_atomic_ground_truth_cache` to have already populated//! `corpus/inline-atomic-ground-truth/`.//!//! Like the transform loop, this one never admits anything: `specs/inline-atomic.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 here either).
use anyhow::{bail, Result};use generation::candidate_crate;use generation::groundtruth::load_all;use generation::inline_atomic_runner::passing_case_ids;use generation::model::{CandidateSource, DirectoryCandidateSource};use generation::orchestrate::{repo_root, run_candidates, write_regression_set};use layout::inline_atomic::{resolve_baseline, InlineAtomicResolver};
fn main() -> Result<()> { let repo_root = repo_root(); let cache_dir = repo_root.join("corpus/inline-atomic-ground-truth"); let cases = load_all(&cache_dir)?; if cases.is_empty() { bail!( "no cached cases under {}; run the inline_atomic_ground_truth_cache binary first", cache_dir.display() ); }
let fixtures_dir = repo_root.join("crates/generation/fixtures/inline-atomic-candidates"); let candidates = DirectoryCandidateSource { dir: fixtures_dir }.candidates()?; println!( "candidates: {}", candidates.iter().map(|c| c.name.as_str()).collect::<Vec<_>>().join(", ") );
let crate_dir = repo_root.join("corpus/candidates/inline-atomic-generated"); candidate_crate::write_for(candidate_crate::Seam::InlineAtomic, &crate_dir, &repo_root, &candidates)?; let binary = candidate_crate::compile(&crate_dir, &crate_dir.join("target"))?;
let regression_set_path = repo_root.join("corpus/inline-atomic-regression-set.json"); let report_out = repo_root.join("corpus/candidates/inline-atomic-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/transform_generation_loop.rs` and // `bin/float_generation_loop.rs` already seed, 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 anywhere: it puts every atomic inline // on a line of its own at the container's left edge, which is the wrong answer for // every case in this corpus except a container holding exactly one box wider than // half its content width -- so a gate seeded from the baseline would have almost // nothing to catch a wrong candidate on, and `never_breaks_a_line` (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 mut seed: Vec<String> = passing_case_ids(resolve_baseline as InlineAtomicResolver, &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/inline-atomic.md`). let get = |name: &str| gated.candidates.iter().find(|c| c.name == name); let wrong_names = ["aligns_every_bottom_edge", "never_breaks_a_line"]; 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(())}