From 7c31a1ea9f87d03f7d98f3190a082fc9de09a413 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 24 Nov 2026 19:45:55 +0000 Subject: [PATCH] craft-docx, craft-drawingml: smaller sizes and nightly-only boundary tests --- crates/docx/Cargo.toml | 1 + crates/docx/src/read/chart/tests.rs | 9 +++++---- crates/docx/tests/it/comment_save_cost.rs | 6 +++--- crates/docx/tests/it/content_control_save_cost.rs | 10 +++++----- crates/docx/tests/it/element_budget.rs | 5 +++++ crates/docx/tests/it/malformed.rs | 6 ++++-- crates/docx/tests/it/word_xml.rs | 4 ++++ crates/drawingml/src/chart.rs | 13 +++++++------ 8 files changed, 34 insertions(+), 20 deletions(-) diff --git a/crates/docx/Cargo.toml b/crates/docx/Cargo.toml index ed84356e0..0ffedf2aa 100644 --- a/crates/docx/Cargo.toml +++ b/crates/docx/Cargo.toml @@ -28,6 +28,7 @@ zeroize = "1" [dev-dependencies] craft-cfb = { workspace = true } +craft-testkit = { workspace = true } craft-opc = { workspace = true, features = ["test-support"] } craft-wordmodel = { workspace = true, features = ["test-support"] } image = { version = "0.25", default-features = false, features = ["png"] } diff --git a/crates/docx/src/read/chart/tests.rs b/crates/docx/src/read/chart/tests.rs index 1aeab5235..ea338016e 100644 --- a/crates/docx/src/read/chart/tests.rs +++ b/crates/docx/src/read/chart/tests.rs @@ -230,11 +230,12 @@ fn hostile_radar_charts_never_panic() { let small = chart_items(&space(&format!("{}", ser(0, "S", None, &["a", "b", "c"], &["1", "2", "3"]))), &theme(), 20.0, 20.0); let _ = small; - // Caps: thousands of categories and series stay bounded. - let cats: Vec = (0..5000).map(|i| format!("c{i}")).collect(); + // Caps: three times as many categories and series as are drawn stay bounded. + let n = 3 * MAX_SPOKES; + let cats: Vec = (0..n).map(|i| format!("c{i}")).collect(); let refs: Vec<&str> = cats.iter().map(String::as_str).collect(); - let vals = vec!["1"; 5000]; - let many: Vec = (0..300).map(|i| ser(i, "S", None, &refs, &vals)).collect(); + let vals = vec!["1"; n]; + let many: Vec = (0..3 * MAX_RADAR_SERIES).map(|i| ser(i, "S", None, &refs, &vals)).collect(); let items = radar_chart("marker", &many); let polygons = items.iter().filter(|it| matches!(it, GraphicItem::Path { stroke: Some(c), .. } if *c != GRID)).count(); assert!(polygons <= MAX_RADAR_SERIES, "{polygons}"); diff --git a/crates/docx/tests/it/comment_save_cost.rs b/crates/docx/tests/it/comment_save_cost.rs index 2bcd5fb86..88902400b 100644 --- a/crates/docx/tests/it/comment_save_cost.rs +++ b/crates/docx/tests/it/comment_save_cost.rs @@ -29,8 +29,8 @@ fn cpu_cost(mut f: impl FnMut()) -> f64 { #[test] fn many_comments_save_without_quadratic_id_searches() { for imported in [true, false] { - let small = comments(4_000, imported); - let big = comments(32_000, imported); + let small = comments(1_000, imported); + let big = comments(8_000, imported); let save = |d: &Document| drop(std::hint::black_box(craft_docx::write(d).unwrap())); save(&small); save(&big); @@ -39,7 +39,7 @@ fn many_comments_save_without_quadratic_id_searches() { // use elapsed time; retry ratios far from linear before declaring a regression. for _ in 0..3 { let (mut s, mut b) = (f64::INFINITY, f64::INFINITY); - for _ in 0..3 { + for _ in 0..2 { s = s.min(cpu_cost(|| (0..8).for_each(|_| save(&small))) / 8.0); b = b.min(cpu_cost(|| save(&big))); } diff --git a/crates/docx/tests/it/content_control_save_cost.rs b/crates/docx/tests/it/content_control_save_cost.rs index 9b96aeb7b..768f00ede 100644 --- a/crates/docx/tests/it/content_control_save_cost.rs +++ b/crates/docx/tests/it/content_control_save_cost.rs @@ -59,7 +59,7 @@ fn cost_ratio(scale: usize, mut small: impl FnMut(), mut big: impl FnMut()) -> ( big(); let mut small_scaled = || (0..scale).for_each(|_| small()); let (mut t1, mut tk) = (f64::INFINITY, f64::INFINITY); - for _ in 0..5 { + for _ in 0..3 { let a = Instant::now(); small_scaled(); t1 = t1.min(a.elapsed().as_secs_f64() / scale as f64); @@ -76,8 +76,8 @@ fn cost_ratio(scale: usize, mut small: impl FnMut(), mut big: impl FnMut()) -> ( #[test] fn a_document_with_many_inline_content_controls_saves_in_linear_time() { let scale = 4; - let small = inline_controls(8_000); - let big = inline_controls(8_000 * scale); + let small = inline_controls(2_000); + let big = inline_controls(2_000 * scale); let (t1, tk, ratio) = cost_ratio( scale, || { @@ -96,8 +96,8 @@ fn a_document_with_many_inline_content_controls_saves_in_linear_time() { #[test] fn a_document_with_many_block_content_controls_saves_in_linear_time() { let scale = 4; - let small = block_controls(8_000); - let big = block_controls(8_000 * scale); + let small = block_controls(2_000); + let big = block_controls(2_000 * scale); let (t1, tk, ratio) = cost_ratio( scale, || { diff --git a/crates/docx/tests/it/element_budget.rs b/crates/docx/tests/it/element_budget.rs index 6b220ae7c..d18e2762a 100644 --- a/crates/docx/tests/it/element_budget.rs +++ b/crates/docx/tests/it/element_budget.rs @@ -9,6 +9,11 @@ const W_NS: &str = r#"xmlns:w="http://schemas.openxmlformats.org/wordprocessingm #[test] fn a_file_of_element_budget_parts_still_reads() { + // 18M elements: nightly only. `the_xml_element_budget_is_package_wide` (in `package.rs`) proves + // the package-wide budget with a small one at the gate. + if craft_testkit::hostile::divisor() > 1 { + return; + } // Nine chart parts of 2M elements each: 18M over the package's 16M budget. The later // parts are skipped with a warning instead of built, and the file still reads. Before // the budget, every part's whole tree was parsed and the chart trees stayed cached for diff --git a/crates/docx/tests/it/malformed.rs b/crates/docx/tests/it/malformed.rs index b1c5b8f17..d8cdb1045 100644 --- a/crates/docx/tests/it/malformed.rs +++ b/crates/docx/tests/it/malformed.rs @@ -313,11 +313,13 @@ fn compound(info: &[u8], package: &[u8]) -> Vec { proptest! { // Each case that parses runs the 50,000-spin key derivation, so fewer cases. - #![proptest_config(ProptestConfig { cases: 48, ..ProptestConfig::default() })] + #![proptest_config(ProptestConfig { cases: (48 / craft_testkit::hostile::divisor() as u32).max(6), ..ProptestConfig::default() })] #[test] fn mutated_standard_encryption_never_panics(ops in proptest::collection::vec((0u8..3, any::(), any::(), any::()), 1..8)) { - let (mut info, mut package) = standard_streams(); + // Encrypting runs the key derivation too: once for every case. + static STREAMS: std::sync::OnceLock<(Vec, Vec)> = std::sync::OnceLock::new(); + let (mut info, mut package) = STREAMS.get_or_init(standard_streams).clone(); for (k, idx, byte, in_package) in ops { let x = if in_package { &mut package } else { &mut info }; let at = idx.index(x.len() + 1); diff --git a/crates/docx/tests/it/word_xml.rs b/crates/docx/tests/it/word_xml.rs index 31c022aa0..2571facb2 100644 --- a/crates/docx/tests/it/word_xml.rs +++ b/crates/docx/tests/it/word_xml.rs @@ -268,6 +268,10 @@ fn flat_opc_limits_count_what_is_not_kept() { assert!(limited(&r#"AA=="#.repeat(20_000))); assert!(limited(&"".repeat(20_000))); // A part nothing reads, one element over what the XML tree reader takes in a part (8 000 000). + // Millions of elements: nightly only; the checks above prove the same counting at the gate. + if craft_testkit::hostile::divisor() > 1 { + return; + } assert!(limited(&format!(r#"{}"#, "".repeat(8_000_000)))); } diff --git a/crates/drawingml/src/chart.rs b/crates/drawingml/src/chart.rs index 1dd92177a..91321e351 100644 --- a/crates/drawingml/src/chart.rs +++ b/crates/drawingml/src/chart.rs @@ -1762,8 +1762,8 @@ mod chartex_tests { #[test] fn large_box_hierarchy_and_stacked_charts_take_linear_work() { - // 50,000 distinct categories in one series: grouped through a map, one pass. - let n = 50_000; + // 5,000 distinct categories in one series: grouped through a map, one pass. + let n = 5_000; let mut c = Chart::sample(ChartType::BoxWhisker); c.series.truncate(1); c.categories = (0..n).map(|i| format!("g{i}")).collect(); @@ -1771,12 +1771,13 @@ mod chartex_tests { let (groups, stats) = c.box_groups(); assert_eq!((groups.len(), stats[0].len()), (n, n)); assert!(stats[0].iter().all(Option::is_some)); - // 2,000 series cap the groups so the result stays within MAX_BOX_CELLS. - c.series = vec![c.series[0].clone(); 2000]; + // Enough series to cap the groups so the result stays within MAX_BOX_CELLS. + let series = MAX_BOX_CELLS / n * 2; + c.series = vec![c.series[0].clone(); series]; let (groups, stats) = c.box_groups(); - assert_eq!(groups.len(), MAX_BOX_CELLS / 2000); + assert_eq!(groups.len(), MAX_BOX_CELLS / series); assert!(stats.iter().all(|s| s.len() == groups.len())); - // One long outer label over 50,000 leaves is shared, not copied per leaf. + // One long outer label over 5,000 leaves is shared, not copied per leaf. let mut t = Chart::sample(ChartType::Treemap); t.series.truncate(1); t.categories = (0..n).map(|i| format!("c{i}")).collect();