diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8ac8fe7e0..bb6732a503 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,9 +81,17 @@ jobs: # differs by platform: the build (with resources) and the tests. Clippy runs on Linux in # `cargo xtask ci`; lints don't differ by platform. timeout-minutes: 120 - command: cargo test --workspace --locked + # Windows tests what only Windows can show: the crates with Windows-specific code or tests + # (`cfg(windows)` paths, the Windows spooler, winres, the native UI), through nextest as Linux + # does. The crates left out have no `cfg(windows)` code and run the same tests on Linux in + # `cargo xtask ci`; so do pdfcraft-web (wasm) and the OCR worker. A new crate is tested here + # until it is added to the list, so the list can only be too short, not make a test vanish. + command: | + cargo nextest run --workspace --lib --bins --tests --no-fail-fast --locked --exclude pdfcraft-web --exclude pdfcraft-ocr-worker --exclude pdfcraft-a11y --exclude pdfcraft-annot --exclude pdfcraft-audit --exclude pdfcraft-compare --exclude pdfcraft-content --exclude pdfcraft-cos --exclude pdfcraft-crypt --exclude pdfcraft-edit --exclude pdfcraft-export --exclude pdfcraft-filters --exclude pdfcraft-fonts --exclude pdfcraft-forms --exclude pdfcraft-geom --exclude pdfcraft-measure --exclude pdfcraft-model --exclude pdfcraft-oracle --exclude pdfcraft-organize --exclude pdfcraft-prc-render --exclude pdfcraft-preflight --exclude pdfcraft-redact --exclude pdfcraft-testkit --exclude pdfcraft-xfa --exclude pdfcraft-xfdf --exclude xtask + cargo test --workspace --doc --locked --exclude pdfcraft-web --exclude pdfcraft-ocr-worker --exclude pdfcraft-a11y --exclude pdfcraft-annot --exclude pdfcraft-audit --exclude pdfcraft-compare --exclude pdfcraft-content --exclude pdfcraft-cos --exclude pdfcraft-crypt --exclude pdfcraft-edit --exclude pdfcraft-export --exclude pdfcraft-filters --exclude pdfcraft-fonts --exclude pdfcraft-forms --exclude pdfcraft-geom --exclude pdfcraft-measure --exclude pdfcraft-model --exclude pdfcraft-oracle --exclude pdfcraft-organize --exclude pdfcraft-prc-render --exclude pdfcraft-preflight --exclude pdfcraft-redact --exclude pdfcraft-testkit --exclude pdfcraft-xfa --exclude pdfcraft-xfdf --exclude xtask # On main and manual runs a `cache warm (windows-latest)` leg builds the tests (the build # `command` does, without running them) and saves the dependency cache as soon as that # succeeds. Without it the cache is saved only at the end of a green gate, and a main whose # Windows tests fail never saves it, so every full-ci pull request compiled cold (#9054). - warm-command: cargo test --workspace --no-run --locked + # The same build as `command`, flag for flag, so the warm leg saves what the gate restores. + warm-command: cargo nextest run --workspace --lib --bins --tests --no-run --locked --exclude pdfcraft-web --exclude pdfcraft-ocr-worker --exclude pdfcraft-a11y --exclude pdfcraft-annot --exclude pdfcraft-audit --exclude pdfcraft-compare --exclude pdfcraft-content --exclude pdfcraft-cos --exclude pdfcraft-crypt --exclude pdfcraft-edit --exclude pdfcraft-export --exclude pdfcraft-filters --exclude pdfcraft-fonts --exclude pdfcraft-forms --exclude pdfcraft-geom --exclude pdfcraft-measure --exclude pdfcraft-model --exclude pdfcraft-oracle --exclude pdfcraft-organize --exclude pdfcraft-prc-render --exclude pdfcraft-preflight --exclude pdfcraft-redact --exclude pdfcraft-testkit --exclude pdfcraft-xfa --exclude pdfcraft-xfdf --exclude xtask diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 7c17bcfb48..d6d4a5fb57 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -677,6 +677,21 @@ impl PdfCraftApp { self.views.iter().any(|v| v.render_pending()) } + /// `true` until the installed fonts have been found and catalogued, which the Format text + /// font field starts when it first shows. The field is shut ("Loading fonts…") while the + /// catalogue is built, and a list opened before that closes when it arrives, so a headless + /// test waits for this to be `false` before it opens the field. + pub fn installed_fonts_pending(&self) -> bool { + #[cfg(not(target_arch = "wasm32"))] + { + self.document_fonts.as_ref().is_none_or(|fonts| !fonts.catalog.is_ready()) + } + #[cfg(target_arch = "wasm32")] + { + false + } + } + /// Check whether a tool group is pinned to Home. pub fn is_tool_pinned(&self, id: &str) -> bool { self.pinned_tools.iter().any(|t| t == id) diff --git a/crates/ui-egui/tests/it/edit.rs b/crates/ui-egui/tests/it/edit.rs index e6b9dd910b..e7ae037ec3 100644 --- a/crates/ui-egui/tests/it/edit.rs +++ b/crates/ui-egui/tests/it/edit.rs @@ -191,6 +191,10 @@ fn format_text_font_picker_applies_document_font_to_added_text() { assert!(h.execute("edit.edit_text")); h.state_mut().views[0].session.content.selected = Some((0, 0)); h.run_steps(4); + // The font field is shut ("Loading fonts…") while the installed fonts are catalogued on a + // worker thread, and a list opened before then closes when the catalogue arrives. A runner + // that reads many fonts (Windows) is still at it after these frames. + crate::support::wait_until(&mut h, "the installed fonts", |app| !app.installed_fonts_pending()); let font_node = h.get_by_role_and_label(Role::ComboBox, "Font family"); font_node.click(); diff --git a/crates/ui-egui/tests/it/editing.rs b/crates/ui-egui/tests/it/editing.rs index aa290c7678..fe16d127f3 100644 --- a/crates/ui-egui/tests/it/editing.rs +++ b/crates/ui-egui/tests/it/editing.rs @@ -911,11 +911,12 @@ fn opening_the_same_path_again_focuses_its_tab() { fn opening_a_missing_file_fails_and_tells_the_user() { let mut h = session_harness(|_| {}); let missing = std::env::temp_dir().join(format!("pdfcraft-no-such-file-{}.pdf", std::process::id())); - // The open is queued; its failure is reported once the read fails. + // The open is queued; its failure is reported once the read fails, which is not a fixed number + // of frames away on a loaded runner, so wait for the notice. assert_eq!(h.state_mut().open_path(&missing.to_string_lossy()), OpenOutcome::Pending); - h.run_steps(4); + let reported = support::step_until(&mut h, |h| support::shown_notice(h).is_some()); + assert!(reported, "the failure is still reported to the user"); assert!(h.state().views.is_empty()); - assert!(support::shown_notice(&h).is_some(), "the failure is still reported to the user"); } #[test] @@ -10578,6 +10579,9 @@ fn format_panel_shows_selection_size_and_updates_after_font_applied() { let size_node = h.get_by_role_and_label(Role::SpinButton, "Font size"); assert_eq!(size_node.value().as_deref(), Some("12"), "size text input value is 12"); + // The font field reads "Loading fonts…" and is shut while the installed fonts are catalogued + // on a worker thread; a runner that reads many fonts (Windows) is still at it after the frames above. + crate::support::wait_until(&mut h, "the installed fonts", |app| !app.installed_fonts_pending()); let font_node = h.get_by_role_and_label(Role::ComboBox, "Font family"); assert_eq!(font_node.value().as_deref(), Some("Helvetica"), "initial font is Helvetica"); diff --git a/crates/ui-egui/tests/page_shadows.rs b/crates/ui-egui/tests/page_shadows.rs index 0e419d2631..20fc65bb54 100644 --- a/crates/ui-egui/tests/page_shadows.rs +++ b/crates/ui-egui/tests/page_shadows.rs @@ -112,6 +112,7 @@ fn rendered_page_content_is_identical_with_and_without_decoration() { std::thread::sleep(std::time::Duration::from_millis(5)); } assert!(!h.state().render_pending(), "the actual PDF raster must be ready"); + settle_sidebar(&mut h); let rects = h.state().views[0].visible_page_rects().to_vec(); let enabled = h.render().unwrap(); h.set_option("show_page_edge_shadows", "false").unwrap(); @@ -145,6 +146,35 @@ fn rendered_page_content_is_identical_with_and_without_decoration() { } } +/// Step until the pixels outside the viewport (the Pages sidebar) have not changed for a while. The +/// sidebar fills its thumbnails in on its own schedule and `render_pending` does not cover them: a +/// thumbnail that arrived between the two renders made them differ outside the pages. +fn settle_sidebar(h: &mut Harness<'static, PdfCraftApp>) { + let outside = |h: &mut Harness<'static, PdfCraftApp>| { + let viewport = h.state().views[0].viewport_rect(); + let image = h.render().unwrap(); + let (left, right) = (viewport.left().floor() as u32, viewport.right().ceil() as u32); + let mut pixels = Vec::new(); + for y in 0..image.height() { + pixels.extend((0..left).chain(right..image.width()).map(|x| *image.get_pixel(x, y))); + } + pixels + }; + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30); + let mut last = outside(h); + let mut unchanged_since = std::time::Instant::now(); + while unchanged_since.elapsed() < std::time::Duration::from_millis(300) { + assert!(std::time::Instant::now() < deadline, "the Pages sidebar never stopped changing"); + h.run_steps(2); + std::thread::sleep(std::time::Duration::from_millis(10)); + let now = outside(h); + if now != last { + last = now; + unchanged_since = std::time::Instant::now(); + } + } +} + fn harness(theme: &str) -> Harness<'static, PdfCraftApp> { let theme = theme.to_string(); let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |cc| {