Something went wrong. Try again.
Exploring the idea of generated web rendering engine.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889//! The generation loop for `docs/feature-cost-experiment.md`'s two seams, run over//! hand-written fixture candidates (`crates/generation/fixtures/feature-candidates/`)://! write each seam's batch as one crate, compile it once, run it as a subprocess against//! the cached ground truth, and check the gate admits `correct` and rejects every other//! (seeded-wrong) fixture. The regression set is seeded from what the spec-literal//! baseline passes, the way `generation_loop` seeds the width equation's.//!//! A model-driven batch replaces `DirectoryCandidateSource` with a model source; nothing//! else in this path changes.
use std::path::Path;
use anyhow::{bail, Result};use dom::mutable::apply_mutation_baseline;use dom::reflect::{reflect_get_baseline, reflect_set_baseline};use generation::candidate_crate::{self, Seam};use generation::feature_corpus::{mutation_cases, reflect_cases};use generation::feature_groundtruth::{load_all, CachedMutationCase, CachedReflectCase, MUTATION_DIR, REFLECT_DIR};use generation::feature_runner::{evaluate_mutation, evaluate_reflect, ReflectCandidate};use generation::model::{CandidateSource, DirectoryCandidateSource};use generation::orchestrate::{repo_root, run_candidates, write_regression_set};use generation::runner::Report;
fn run_seam(repo_root: &Path, seam: Seam, name: &str, cache_dir: &Path, baseline_passing: Vec<String>) -> Result<bool> { let candidates = DirectoryCandidateSource { dir: repo_root.join("crates/generation/fixtures/feature-candidates").join(name) } .candidates()?; println!("\n== {name}: {} ==", candidates.iter().map(|c| c.name.as_str()).collect::<Vec<_>>().join(", "));
let work_dir = repo_root.join("corpus/feature-candidates").join(name); let crate_dir = work_dir.join("generated"); candidate_crate::write_for(seam, &crate_dir, repo_root, &candidates)?; let binary = candidate_crate::compile(&crate_dir, &crate_dir.join("target"))?;
let regression_set = work_dir.join("regression-set.json"); write_regression_set(®ression_set, &baseline_passing)?; let report: Report = run_candidates(&binary, cache_dir, Some(®ression_set), &work_dir.join("report.json"))?;
let mut discriminates = true; for c in &report.candidates { println!( "{:<24} {}/{} passed, admitted={}, regressed={}", c.name, c.cases_passed, c.cases_run, c.admitted, c.regressed_cases.len() ); for (category, t) in &c.per_category { println!(" {category:<22} {}/{}", t.passed, t.total); } if c.admitted != (c.name == "correct") { eprintln!("{name}: gate got {} wrong", c.name); discriminates = false; } } Ok(discriminates)}
fn main() -> Result<()> { let repo_root = repo_root();
let reflect_dir = repo_root.join(REFLECT_DIR); let reflect_cached: Vec<CachedReflectCase> = load_all(&reflect_dir)?; let mutation_dir = repo_root.join(MUTATION_DIR); let mutation_cached: Vec<CachedMutationCase> = load_all(&mutation_dir)?; if reflect_cached.is_empty() || mutation_cached.is_empty() { bail!("no cached cases; run the feature_ground_truth_cache binary first"); }
let baseline = ReflectCandidate { name: "baseline", get: reflect_get_baseline, set: reflect_set_baseline }; let reflect_passing = evaluate_reflect(&[baseline], &reflect_cases(), &reflect_cached, None).candidates[0] .passed_case_ids .clone(); let mutation_passing = evaluate_mutation(&[("baseline", apply_mutation_baseline)], &mutation_cases(), &mutation_cached, None) .candidates[0] .passed_case_ids .clone();
let reflect_ok = run_seam(&repo_root, Seam::Reflect, "reflect", &reflect_dir, reflect_passing)?; let mutation_ok = run_seam(&repo_root, Seam::Mutation, "mutation", &mutation_dir, mutation_passing)?; if !(reflect_ok && mutation_ok) { bail!("the loop did not discriminate correctly between candidates"); } println!("\ngate admitted \"correct\" and rejected every seeded-wrong candidate, both seams"); Ok(())}