There is one coordinate unit, the window. Every box in the tree is a region in window units and a widget's frame is a length in the same units, which is only what fractions resolve against, so the box need not be the frame and padding can take from both without either becoming the other. A region node's entry is a translation -- a rel 1 region anchored where its box starts -- rather than a box, so nothing composes a frame back up a chain and a node that moves is one entry write. Padding is then an inset of both: its pixels come off the frame, so rel(1.0) under it fills the padded widget rather than overflowing it, and off the box, so what is drawn sits inside. A length a container decides for a child's frame is a length of the window like everything else here -- a row's slot, padding's frame less its pixels, or the box a stack's sizing child decided, which arrives as Part::Sized -- because a slot of a row is not a fraction of anything the row can name, the same reason a node entry is a translation. A declaration is a fraction of whichever of those reached it, and is the only one that also places the box. Frame validity is a pin beside the box's, not a range: a range of window pixels cannot say which frame an answer is a fraction of, since two frames are different lengths at the same window size. A widget pins its frame by reading it or by being answered with it under a fractional rule, and the pin composes up wherever a length of this frame is what reached the child. Also here, because the diagnosis needed them: the shrinker reports the shrunk tree's own divergence with each level's frame, ask, box and size warm against cold, and there is a size-resize case -- a change and then a resize, the order that shows an answer kept as a fraction of the wrong length, which every other case compares at the window it was made at. Three defects the reports found, each pinned: a rule changed over two pads relocated the column under them instead of dividing it again (seed 59, depth 5, resize-size), a share inside padding had the padding taken off twice, and a root resolved its own rule twice. fmt and clippy clean with and without layout-diagnostics, 121 suite, 20 core, 11 generated, the 400-seed depth-5 shrinker over all sixteen cases. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
104 lines
3.7 KiB
Rust
104 lines
3.7 KiB
Rust
//! A fuzzer that reduces its own counterexample.
|
|
//!
|
|
//! A seed is not a lead anybody can read: the tree is hundreds of widgets,
|
|
//! and reconstructing the part that matters by hand has failed every time it
|
|
//! has been tried. This grows the trees `iris::random` describes, takes them
|
|
//! apart, and prints the smallest one that still fails as something to write
|
|
//! a fast test from.
|
|
//!
|
|
//! cargo test --release --test shrink -- --ignored --nocapture
|
|
//!
|
|
//! `SHRINK_SEEDS` how many trees to try, `SHRINK_DEPTH` how deep to grow
|
|
//! them, `SHRINK_CASE` which scenario or `all` for every one. `SHRINK_SEED`
|
|
//! takes a single seed, which is how a failure `generated` printed is handed
|
|
//! straight here: the two run the same cases over the same trees, so a seed
|
|
//! that fails there fails here and is reduced.
|
|
//!
|
|
//! It is a fuzzer: run it once the ordinary tests pass, and turn what it
|
|
//! finds into a test of its own rather than leaving a seed as the record.
|
|
|
|
#[path = "scenario/mod.rs"]
|
|
mod scenario;
|
|
|
|
use iris::random::{Edits, Plan, plan};
|
|
use scenario::{ALL, Case, diverges, env, over_seeds};
|
|
|
|
/// Takes the first simplification that still fails, until none does. The
|
|
/// simplifications come biggest first, so this walks down rather than
|
|
/// nibbling: a six-hundred-widget tree reaches single figures in a few
|
|
/// hundred builds.
|
|
fn shrink(mut node: Plan, case: Case, seed: u64) -> Plan {
|
|
loop {
|
|
let Some(next) = node
|
|
.smaller()
|
|
.into_iter()
|
|
.find(|small| diverges(small, case, seed).is_some())
|
|
else {
|
|
return node;
|
|
};
|
|
node = next;
|
|
}
|
|
}
|
|
|
|
fn cases() -> Vec<Case> {
|
|
match env("SHRINK_CASE", String::from("all")).as_str() {
|
|
"all" => ALL.to_vec(),
|
|
name => match Case::named(name) {
|
|
Some(case) => vec![case],
|
|
None => panic!(
|
|
"unknown SHRINK_CASE {name:?}; one of all, {}",
|
|
ALL.map(Case::name).join(", ")
|
|
),
|
|
},
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
#[ignore = "a fuzzer; run it once the ordinary tests pass"]
|
|
fn no_grown_tree_lays_out_differently_warm_than_cold() {
|
|
let depth: usize = env("SHRINK_DEPTH", 5);
|
|
let cases = cases();
|
|
let seeds: Vec<u64> = match std::env::var("SHRINK_SEED")
|
|
.ok()
|
|
.and_then(|v| v.parse().ok())
|
|
{
|
|
Some(seed) => vec![seed],
|
|
None => (1..=env("SHRINK_SEEDS", 400_u64)).collect(),
|
|
};
|
|
let count = seeds.len();
|
|
|
|
over_seeds(seeds, |seed| {
|
|
let grown = plan(seed, depth, &Edits::default());
|
|
for &case in &cases {
|
|
if diverges(&grown, case, seed).is_none() {
|
|
continue;
|
|
}
|
|
let small = shrink(grown.clone(), case, seed);
|
|
// Described from the shrunk tree: the grown tree's chain names
|
|
// widgets that are no longer there, and the ancestry of the
|
|
// failure is what a test is written from.
|
|
let how = diverges(&small, case, seed).unwrap_or_default();
|
|
println!(
|
|
"seed {seed} case {}: {how}\ngrown {} widgets, shrank to {}\n{small:#?}",
|
|
case.name(),
|
|
grown.size(),
|
|
small.size()
|
|
);
|
|
panic!(
|
|
"seed {seed} lays out differently warm than cold after {}",
|
|
case.name()
|
|
);
|
|
}
|
|
});
|
|
|
|
let sizes: Vec<usize> = (1..=count as u64)
|
|
.map(|seed| plan(seed, depth, &Edits::default()).size())
|
|
.collect();
|
|
println!(
|
|
"{count} trees at depth {depth} agree over {} case(s): {} widgets total, largest {}",
|
|
cases.len(),
|
|
sizes.iter().sum::<usize>(),
|
|
sizes.iter().max().copied().unwrap_or(0)
|
|
);
|
|
}
|