refactor(shell): split web_surface_live_site_tests under 500-line audit
`web_surface_live_site_tests.rs` (648, behind the `live-site-smoke` feature) was the last file over the audit ceiling. Its helpers split cleanly one-directionally: drivers/waiters call the leaf validators/builders, never the reverse. Keep imports, consts, the 6 tests, `run_isolated_live_site_test`, the `assert_*` drivers, `render_web_surface_frame`, and the `wait_for_*` helpers in the parent; move the leaf validators + pure fixtures (`ExpectedCssViewport`, `validate_prd_frame*`, `log_prd_frame`, `require*`, `*_bounds`, `live_scroll_point`, `web_tab`, `normalized_url`) into `web_surface_live_site_support.rs` as `pub(super)` items, opened with `use super::*;`. Parent pulls them back via `use ...support::*`. 470 / 184 lines. `cargo build/clippy -p ely_app --tests --features live-site-smoke -- -D warnings` clean. scripts/audit_source_lines.sh now exits 0 (every source file <= 500). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(super) struct ExpectedCssViewport {
|
||||
pub(super) physical_width: u32,
|
||||
pub(super) physical_height: u32,
|
||||
pub(super) css_width: u32,
|
||||
pub(super) css_height: u32,
|
||||
pub(super) dpr_percent: u16,
|
||||
}
|
||||
|
||||
pub(super) fn validate_prd_frame(
|
||||
frame: &WebSurfaceFrame,
|
||||
case: &LiveSiteCase,
|
||||
expected_scroll_y: i32,
|
||||
) -> Result<(), String> {
|
||||
require(
|
||||
frame.size()
|
||||
== WebSurfaceSize {
|
||||
width: LIVE_SURFACE_WIDTH,
|
||||
height: LIVE_SURFACE_HEIGHT,
|
||||
device_pixel_ratio_percent: 100,
|
||||
},
|
||||
format!("{} size: {:?}", case.url, frame.size()),
|
||||
)?;
|
||||
require(
|
||||
frame.scroll_offset().y() == expected_scroll_y,
|
||||
format!("{} scroll: {:?}", case.url, frame.scroll_offset()),
|
||||
)?;
|
||||
require(
|
||||
frame.css_viewport_size() == (LIVE_SURFACE_WIDTH, LIVE_SURFACE_HEIGHT),
|
||||
format!("{} CSS viewport: {:?}", case.url, frame.css_viewport_size()),
|
||||
)?;
|
||||
require_render_state_is_open(frame.render_state(), case.url)?;
|
||||
require(
|
||||
frame.url_label().contains(normalized_url(case.url)),
|
||||
format!("url: {}", frame.url_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.title_label().contains(case.title_fragment),
|
||||
format!("title: {}", frame.title_label()),
|
||||
)?;
|
||||
let expected_detail = if expected_scroll_y == 0 {
|
||||
format!("{} {}x{}", frame.render_state(), LIVE_SURFACE_WIDTH, LIVE_SURFACE_HEIGHT)
|
||||
} else {
|
||||
format!(
|
||||
"{} {}x{} y={expected_scroll_y}",
|
||||
frame.render_state(),
|
||||
LIVE_SURFACE_WIDTH,
|
||||
LIVE_SURFACE_HEIGHT,
|
||||
)
|
||||
};
|
||||
require(
|
||||
frame.detail_label() == expected_detail,
|
||||
format!("{} detail: {}", case.url, frame.detail_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.non_white_pixel_count() > 0,
|
||||
format!("{} non-white pixels: {}", case.url, frame.non_white_pixel_count()),
|
||||
)?;
|
||||
require(
|
||||
frame.content_pixel_count() >= MINIMUM_CONTENT_PIXELS,
|
||||
format!("{} content pixels: {}", case.url, frame.content_pixel_count()),
|
||||
)?;
|
||||
require(frame.sample_hash() > 0, format!("{} sample hash: {}", case.url, frame.sample_hash()))
|
||||
}
|
||||
|
||||
pub(super) fn validate_prd_frame_at_size(
|
||||
frame: &WebSurfaceFrame,
|
||||
case: &LiveSiteCase,
|
||||
expected_width: u32,
|
||||
expected_height: u32,
|
||||
) -> Result<(), String> {
|
||||
require(
|
||||
frame.size()
|
||||
== WebSurfaceSize {
|
||||
width: expected_width,
|
||||
height: expected_height,
|
||||
device_pixel_ratio_percent: 100,
|
||||
},
|
||||
format!("{} size: {:?}", case.url, frame.size()),
|
||||
)?;
|
||||
require_render_state_is_open(frame.render_state(), case.url)?;
|
||||
require(
|
||||
frame.css_viewport_size() == (expected_width, expected_height),
|
||||
format!("{} CSS viewport: {:?}", case.url, frame.css_viewport_size()),
|
||||
)?;
|
||||
require(
|
||||
frame.url_label().contains(normalized_url(case.url)),
|
||||
format!("url: {}", frame.url_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.title_label().contains(case.title_fragment),
|
||||
format!("title: {}", frame.title_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.non_white_pixel_count() > 0,
|
||||
format!("{} non-white pixels: {}", case.url, frame.non_white_pixel_count()),
|
||||
)?;
|
||||
require(
|
||||
frame.content_pixel_count() >= MINIMUM_CONTENT_PIXELS,
|
||||
format!("{} content pixels: {}", case.url, frame.content_pixel_count()),
|
||||
)?;
|
||||
require(frame.sample_hash() > 0, format!("{} sample hash: {}", case.url, frame.sample_hash()))
|
||||
}
|
||||
|
||||
pub(super) fn validate_prd_frame_at_css_size(
|
||||
frame: &WebSurfaceFrame,
|
||||
case: &LiveSiteCase,
|
||||
expected: ExpectedCssViewport,
|
||||
) -> Result<(), String> {
|
||||
require(
|
||||
frame.size()
|
||||
== WebSurfaceSize {
|
||||
width: expected.physical_width,
|
||||
height: expected.physical_height,
|
||||
device_pixel_ratio_percent: expected.dpr_percent,
|
||||
},
|
||||
format!("{} size: {:?}", case.url, frame.size()),
|
||||
)?;
|
||||
require_render_state_is_open(frame.render_state(), case.url)?;
|
||||
require(
|
||||
frame.css_viewport_size() == (expected.css_width, expected.css_height),
|
||||
format!("{} CSS viewport: {:?}", case.url, frame.css_viewport_size()),
|
||||
)?;
|
||||
require(
|
||||
frame.url_label().contains(normalized_url(case.url)),
|
||||
format!("url: {}", frame.url_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.title_label().contains(case.title_fragment),
|
||||
format!("title: {}", frame.title_label()),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn log_prd_frame(label: &str, frame: &WebSurfaceFrame, case: &LiveSiteCase) {
|
||||
eprintln!(
|
||||
"prd-live-site {label} url={} loaded={} title={} state={} size={}x{} content_pixels={} non_white_pixels={} sample_hash={}",
|
||||
case.url,
|
||||
frame.url_label(),
|
||||
frame.title_label(),
|
||||
frame.render_state(),
|
||||
frame.size().width,
|
||||
frame.size().height,
|
||||
frame.content_pixel_count(),
|
||||
frame.non_white_pixel_count(),
|
||||
frame.sample_hash()
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn require_render_state_is_open(state: &str, url: &str) -> Result<(), String> {
|
||||
require(matches!(state, "complete" | "loading"), format!("{url} state: {state}"))
|
||||
}
|
||||
|
||||
pub(super) fn require(condition: bool, message: String) -> Result<(), String> {
|
||||
if condition { Ok(()) } else { Err(message) }
|
||||
}
|
||||
|
||||
pub(super) fn live_surface_bounds() -> Bounds<gpui::Pixels> {
|
||||
Bounds::new(
|
||||
point(px(0.0), px(0.0)),
|
||||
size(px(LIVE_SURFACE_WIDTH as f32), px(LIVE_SURFACE_HEIGHT as f32)),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn resized_live_surface_bounds() -> Bounds<gpui::Pixels> {
|
||||
Bounds::new(
|
||||
point(px(0.0), px(0.0)),
|
||||
size(px(RESIZED_LIVE_SURFACE_WIDTH as f32), px(RESIZED_LIVE_SURFACE_HEIGHT as f32)),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn live_scroll_point() -> gpui::Point<gpui::Pixels> {
|
||||
point(px(LIVE_SITE_SCROLL_POINT_X), px(LIVE_SITE_SCROLL_POINT_Y))
|
||||
}
|
||||
|
||||
pub(super) fn web_tab(profile_id: ProfileId, url: &str) -> Result<BrowserTab, Box<dyn Error>> {
|
||||
Ok(BrowserTab::new(TabId::new(), SpaceId::new(), profile_id, "Web", UrlText::parse(url)?))
|
||||
}
|
||||
|
||||
pub(super) fn normalized_url(url: &str) -> &str {
|
||||
url.trim_end_matches('/')
|
||||
}
|
||||
@@ -464,185 +464,7 @@ fn wait_for_ready_frame_at_css_size(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct ExpectedCssViewport {
|
||||
physical_width: u32,
|
||||
physical_height: u32,
|
||||
css_width: u32,
|
||||
css_height: u32,
|
||||
dpr_percent: u16,
|
||||
}
|
||||
|
||||
fn validate_prd_frame(
|
||||
frame: &WebSurfaceFrame,
|
||||
case: &LiveSiteCase,
|
||||
expected_scroll_y: i32,
|
||||
) -> Result<(), String> {
|
||||
require(
|
||||
frame.size()
|
||||
== WebSurfaceSize {
|
||||
width: LIVE_SURFACE_WIDTH,
|
||||
height: LIVE_SURFACE_HEIGHT,
|
||||
device_pixel_ratio_percent: 100,
|
||||
},
|
||||
format!("{} size: {:?}", case.url, frame.size()),
|
||||
)?;
|
||||
require(
|
||||
frame.scroll_offset().y() == expected_scroll_y,
|
||||
format!("{} scroll: {:?}", case.url, frame.scroll_offset()),
|
||||
)?;
|
||||
require(
|
||||
frame.css_viewport_size() == (LIVE_SURFACE_WIDTH, LIVE_SURFACE_HEIGHT),
|
||||
format!("{} CSS viewport: {:?}", case.url, frame.css_viewport_size()),
|
||||
)?;
|
||||
require_render_state_is_open(frame.render_state(), case.url)?;
|
||||
require(
|
||||
frame.url_label().contains(normalized_url(case.url)),
|
||||
format!("url: {}", frame.url_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.title_label().contains(case.title_fragment),
|
||||
format!("title: {}", frame.title_label()),
|
||||
)?;
|
||||
let expected_detail = if expected_scroll_y == 0 {
|
||||
format!("{} {}x{}", frame.render_state(), LIVE_SURFACE_WIDTH, LIVE_SURFACE_HEIGHT)
|
||||
} else {
|
||||
format!(
|
||||
"{} {}x{} y={expected_scroll_y}",
|
||||
frame.render_state(),
|
||||
LIVE_SURFACE_WIDTH,
|
||||
LIVE_SURFACE_HEIGHT,
|
||||
)
|
||||
};
|
||||
require(
|
||||
frame.detail_label() == expected_detail,
|
||||
format!("{} detail: {}", case.url, frame.detail_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.non_white_pixel_count() > 0,
|
||||
format!("{} non-white pixels: {}", case.url, frame.non_white_pixel_count()),
|
||||
)?;
|
||||
require(
|
||||
frame.content_pixel_count() >= MINIMUM_CONTENT_PIXELS,
|
||||
format!("{} content pixels: {}", case.url, frame.content_pixel_count()),
|
||||
)?;
|
||||
require(frame.sample_hash() > 0, format!("{} sample hash: {}", case.url, frame.sample_hash()))
|
||||
}
|
||||
|
||||
fn validate_prd_frame_at_size(
|
||||
frame: &WebSurfaceFrame,
|
||||
case: &LiveSiteCase,
|
||||
expected_width: u32,
|
||||
expected_height: u32,
|
||||
) -> Result<(), String> {
|
||||
require(
|
||||
frame.size()
|
||||
== WebSurfaceSize {
|
||||
width: expected_width,
|
||||
height: expected_height,
|
||||
device_pixel_ratio_percent: 100,
|
||||
},
|
||||
format!("{} size: {:?}", case.url, frame.size()),
|
||||
)?;
|
||||
require_render_state_is_open(frame.render_state(), case.url)?;
|
||||
require(
|
||||
frame.css_viewport_size() == (expected_width, expected_height),
|
||||
format!("{} CSS viewport: {:?}", case.url, frame.css_viewport_size()),
|
||||
)?;
|
||||
require(
|
||||
frame.url_label().contains(normalized_url(case.url)),
|
||||
format!("url: {}", frame.url_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.title_label().contains(case.title_fragment),
|
||||
format!("title: {}", frame.title_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.non_white_pixel_count() > 0,
|
||||
format!("{} non-white pixels: {}", case.url, frame.non_white_pixel_count()),
|
||||
)?;
|
||||
require(
|
||||
frame.content_pixel_count() >= MINIMUM_CONTENT_PIXELS,
|
||||
format!("{} content pixels: {}", case.url, frame.content_pixel_count()),
|
||||
)?;
|
||||
require(frame.sample_hash() > 0, format!("{} sample hash: {}", case.url, frame.sample_hash()))
|
||||
}
|
||||
|
||||
fn validate_prd_frame_at_css_size(
|
||||
frame: &WebSurfaceFrame,
|
||||
case: &LiveSiteCase,
|
||||
expected: ExpectedCssViewport,
|
||||
) -> Result<(), String> {
|
||||
require(
|
||||
frame.size()
|
||||
== WebSurfaceSize {
|
||||
width: expected.physical_width,
|
||||
height: expected.physical_height,
|
||||
device_pixel_ratio_percent: expected.dpr_percent,
|
||||
},
|
||||
format!("{} size: {:?}", case.url, frame.size()),
|
||||
)?;
|
||||
require_render_state_is_open(frame.render_state(), case.url)?;
|
||||
require(
|
||||
frame.css_viewport_size() == (expected.css_width, expected.css_height),
|
||||
format!("{} CSS viewport: {:?}", case.url, frame.css_viewport_size()),
|
||||
)?;
|
||||
require(
|
||||
frame.url_label().contains(normalized_url(case.url)),
|
||||
format!("url: {}", frame.url_label()),
|
||||
)?;
|
||||
require(
|
||||
frame.title_label().contains(case.title_fragment),
|
||||
format!("title: {}", frame.title_label()),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn log_prd_frame(label: &str, frame: &WebSurfaceFrame, case: &LiveSiteCase) {
|
||||
eprintln!(
|
||||
"prd-live-site {label} url={} loaded={} title={} state={} size={}x{} content_pixels={} non_white_pixels={} sample_hash={}",
|
||||
case.url,
|
||||
frame.url_label(),
|
||||
frame.title_label(),
|
||||
frame.render_state(),
|
||||
frame.size().width,
|
||||
frame.size().height,
|
||||
frame.content_pixel_count(),
|
||||
frame.non_white_pixel_count(),
|
||||
frame.sample_hash()
|
||||
);
|
||||
}
|
||||
|
||||
fn require_render_state_is_open(state: &str, url: &str) -> Result<(), String> {
|
||||
require(matches!(state, "complete" | "loading"), format!("{url} state: {state}"))
|
||||
}
|
||||
|
||||
fn require(condition: bool, message: String) -> Result<(), String> {
|
||||
if condition { Ok(()) } else { Err(message) }
|
||||
}
|
||||
|
||||
fn live_surface_bounds() -> Bounds<gpui::Pixels> {
|
||||
Bounds::new(
|
||||
point(px(0.0), px(0.0)),
|
||||
size(px(LIVE_SURFACE_WIDTH as f32), px(LIVE_SURFACE_HEIGHT as f32)),
|
||||
)
|
||||
}
|
||||
|
||||
fn resized_live_surface_bounds() -> Bounds<gpui::Pixels> {
|
||||
Bounds::new(
|
||||
point(px(0.0), px(0.0)),
|
||||
size(px(RESIZED_LIVE_SURFACE_WIDTH as f32), px(RESIZED_LIVE_SURFACE_HEIGHT as f32)),
|
||||
)
|
||||
}
|
||||
|
||||
fn live_scroll_point() -> gpui::Point<gpui::Pixels> {
|
||||
point(px(LIVE_SITE_SCROLL_POINT_X), px(LIVE_SITE_SCROLL_POINT_Y))
|
||||
}
|
||||
|
||||
fn web_tab(profile_id: ProfileId, url: &str) -> Result<BrowserTab, Box<dyn Error>> {
|
||||
Ok(BrowserTab::new(TabId::new(), SpaceId::new(), profile_id, "Web", UrlText::parse(url)?))
|
||||
}
|
||||
|
||||
fn normalized_url(url: &str) -> &str {
|
||||
url.trim_end_matches('/')
|
||||
}
|
||||
#[path = "web_surface_live_site_support.rs"]
|
||||
mod web_surface_live_site_support;
|
||||
use web_surface_live_site_support::*;
|
||||
|
||||
Reference in New Issue
Block a user