Strengthen PRD site rendering checks

This commit is contained in:
2026-05-09 03:02:23 -04:00
parent 52b9783fea
commit 08951a7a1f
3 changed files with 55 additions and 0 deletions
@@ -22,6 +22,12 @@ pub(super) struct WebSurfaceFrame {
scroll_offset: WebSurfaceScrollOffset,
click_point: Option<WebSurfaceClickPoint>,
typed_text: Option<String>,
#[cfg(all(test, feature = "live-site-smoke"))]
non_white_pixel_count: u64,
#[cfg(all(test, feature = "live-site-smoke"))]
content_pixel_count: u64,
#[cfg(all(test, feature = "live-site-smoke"))]
sample_hash: u64,
pub(super) image: Arc<RenderImage>,
}
@@ -38,6 +44,12 @@ impl WebSurfaceFrame {
let loaded_url = snapshot.loaded_url().map(str::to_string);
let title = snapshot.title().map(str::to_string);
let render_state = snapshot.render_state().to_string();
#[cfg(all(test, feature = "live-site-smoke"))]
let non_white_pixel_count = snapshot.non_white_pixel_count();
#[cfg(all(test, feature = "live-site-smoke"))]
let content_pixel_count = snapshot.content_pixel_count();
#[cfg(all(test, feature = "live-site-smoke"))]
let sample_hash = snapshot.sample_hash();
let rgba_bytes = snapshot.into_rgba_bytes();
let Some(buffer) = ImageBuffer::<Rgba<u8>, _>::from_raw(width, height, rgba_bytes) else {
@@ -56,6 +68,12 @@ impl WebSurfaceFrame {
scroll_offset,
click_point,
typed_text,
#[cfg(all(test, feature = "live-site-smoke"))]
non_white_pixel_count,
#[cfg(all(test, feature = "live-site-smoke"))]
content_pixel_count,
#[cfg(all(test, feature = "live-site-smoke"))]
sample_hash,
image: Arc::new(RenderImage::new([image::Frame::new(image_buffer)])),
})
}
@@ -99,6 +117,21 @@ impl WebSurfaceFrame {
pub(super) fn typed_text(&self) -> Option<&str> {
self.typed_text.as_deref()
}
#[cfg(all(test, feature = "live-site-smoke"))]
pub(super) fn non_white_pixel_count(&self) -> u64 {
self.non_white_pixel_count
}
#[cfg(all(test, feature = "live-site-smoke"))]
pub(super) fn content_pixel_count(&self) -> u64 {
self.content_pixel_count
}
#[cfg(all(test, feature = "live-site-smoke"))]
pub(super) fn sample_hash(&self) -> u64 {
self.sample_hash
}
}
#[derive(Debug, Error)]
@@ -20,6 +20,7 @@ use super::WebSurfaceStore;
const LIVE_SURFACE_WIDTH: u32 = 934;
const LIVE_SURFACE_HEIGHT: u32 = 657;
const MINIMUM_CONTENT_PIXELS: u64 = 1_000;
#[test]
fn web_surface_cases_cover_prd_reference_urls() -> Result<(), Box<dyn Error>> {
@@ -78,6 +79,9 @@ fn assert_prd_frame_is_ready(frame: &WebSurfaceFrame, case: &LiveSiteCase) {
assert!(frame.url_label().contains(normalized_url(case.url)), "{}", frame.url_label());
assert!(frame.title_label().contains(case.title_fragment), "{}", frame.title_label());
assert_eq!(frame.detail_label(), format!("{} 934x657", frame.render_state()), "{}", case.url);
assert!(frame.non_white_pixel_count() > 0, "{}", case.url);
assert!(frame.content_pixel_count() >= MINIMUM_CONTENT_PIXELS, "{}", case.url);
assert!(frame.sample_hash() > 0, "{}", case.url);
}
fn assert_render_state_is_open(state: &str, url: &str) {