From 9b3e6a7b2a718fa6394d94b98ad7362069c0b0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 23 Oct 2026 06:13:45 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20page=20a-l=20tests=20merge?= =?UTF-8?q?=20into=20tables=20and=20drop=20checks=20that=20cannot=20fail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test count in crates/forge-web/src/pages (a-l files) goes from 294 to 288. Two access-check tests in ci_tests share one fixture now, the two badge label tests share one, the df and du parser tests merge, the admin mail stream check runs inside the admin-only test, and the signature badge checks fold into the commit list and commit page tests. --- crates/forge-web/src/pages/admin_health.rs | 16 ++++------ crates/forge-web/src/pages/admin_mail.rs | 10 ++----- crates/forge-web/src/pages/ci_tests.rs | 34 +++++----------------- crates/forge-web/src/pages/commit.rs | 14 +-------- crates/forge-web/src/pages/commits.rs | 14 +++------ 5 files changed, 22 insertions(+), 66 deletions(-) diff --git a/crates/forge-web/src/pages/admin_health.rs b/crates/forge-web/src/pages/admin_health.rs index 8f32579..e959ab4 100644 --- a/crates/forge-web/src/pages/admin_health.rs +++ b/crates/forge-web/src/pages/admin_health.rs @@ -409,15 +409,11 @@ mod tests { use super::*; #[test] - fn df_output_parses_to_bytes() { - let out = "Filesystem 1024-blocks Used Available Capacity Mounted on\n/dev/sda1 1000 400 600 40% /\n"; - assert_eq!(parse_df(out), Some((1000 * 1024, 600 * 1024))); - assert_eq!(parse_df("garbage"), None); - } - - #[test] - fn du_output_parses_to_bytes() { - assert_eq!(parse_du("12\t/data/repos\n"), Some(12 * 1024)); - assert_eq!(parse_du(""), None); + fn df_and_du_output_parse_to_bytes() { + let df = "Filesystem 1024-blocks Used Available Capacity Mounted on\n/dev/sda1 1000 400 600 40% /\n"; + assert_eq!(parse_df(df), Some((1000 * 1024, 600 * 1024)), "df"); + assert_eq!(parse_df("garbage"), None, "df garbage"); + assert_eq!(parse_du("12\t/data/repos\n"), Some(12 * 1024), "du"); + assert_eq!(parse_du(""), None, "du empty"); } } diff --git a/crates/forge-web/src/pages/admin_mail.rs b/crates/forge-web/src/pages/admin_mail.rs index 1f02c25..ab22d98 100644 --- a/crates/forge-web/src/pages/admin_mail.rs +++ b/crates/forge-web/src/pages/admin_mail.rs @@ -955,7 +955,7 @@ mod tests { } #[tokio::test] - async fn the_queue_events_and_its_actions_are_admin_only() { + async fn the_queue_events_and_its_actions_are_admin_only_and_admins_get_the_stream() { let fx = fixture().await; for (method, uri) in [ ("GET", "/admin/mail/events"), @@ -981,11 +981,7 @@ mod tests { .await; assert_eq!(user, 404, "{method} {uri} for a plain user"); } - } - - #[tokio::test] - async fn an_admin_gets_the_queue_event_stream() { - let fx = fixture().await; + // An admin gets the queue event stream. let request = Request::builder() .method("GET") .uri("/admin/mail/events") @@ -993,7 +989,7 @@ mod tests { .body(Body::empty()) .expect("request"); let res = fx.router.handle(request).await; - assert_eq!(res.status().as_u16(), 200); + assert_eq!(res.status().as_u16(), 200, "admin stream status"); let kind = res .headers() .get("content-type") diff --git a/crates/forge-web/src/pages/ci_tests.rs b/crates/forge-web/src/pages/ci_tests.rs index 66f6d3a..c4085ed 100644 --- a/crates/forge-web/src/pages/ci_tests.rs +++ b/crates/forge-web/src/pages/ci_tests.rs @@ -405,6 +405,7 @@ async fn live_events_need_the_same_access_as_the_page() { let urls = [ format!("{RUN_BASE}/runs/{}/events", run.number), format!("/tahinli/proj/ci/jobs/{}/events", job.id), + format!("{RUN_BASE}/events"), ]; for url in &urls { let anon = open(&fx.app, url, None).await; @@ -578,19 +579,6 @@ async fn split_view_draws_the_newest_run_or_the_one_named() { ); } -#[tokio::test] -async fn run_list_events_need_the_same_access_as_the_page() { - let dir = tempfile::tempdir().expect("tempdir"); - let fx = fixture(dir.path()).await; - let url = format!("{RUN_BASE}/events"); - let anon = open(&fx.app, &url, None).await; - assert_eq!(anon.status().as_u16(), 404, "anonymous"); - let outsider = open(&fx.app, &url, Some(&cookie_for("carol-token"))).await; - assert_eq!(outsider.status().as_u16(), 404, "outsider"); - let reader = open(&fx.app, &url, Some(&cookie_for("dave-token"))).await; - assert_eq!(reader.status().as_u16(), 200, "reader"); -} - /// The list stream sends nothing on connect, then one `changed` event per change of the repo. #[tokio::test] async fn run_list_events_follow_repo_changes() { @@ -1254,7 +1242,7 @@ async fn badge_label_comes_from_the_query_job_or_workflow_name() { } #[tokio::test] -async fn badge_label_is_trimmed_and_empty_means_absent() { +async fn badge_label_is_trimmed_escaped_and_empty_means_absent() { let dir = tempfile::tempdir().expect("tempdir"); let fx = fixture(dir.path()).await; run_with(&fx, &["build"], false).await; @@ -1283,24 +1271,18 @@ async fn badge_label_is_trimmed_and_empty_means_absent() { blank.contains(">build"), "blank label is absent: {blank}" ); -} - -#[tokio::test] -async fn badge_label_is_escaped() { - let dir = tempfile::tempdir().expect("tempdir"); - let fx = fixture(dir.path()).await; - run_with(&fx, &["build"], false).await; - finish_job(&fx).await; - let reader = Some(cookie_for("dave-token")); - let svg = get( + let escaped = get( &fx.app, "/tahinli/proj/badge.svg?label=%3Cb%3E%20a%20%26%20b%20%3E", reader.as_deref(), ) .await .text(); - assert!(svg.contains("<b> a & b >"), "{svg}"); - assert!(!svg.contains(""), "raw markup must not reach the SVG"); + assert!(escaped.contains("<b> a & b >"), "{escaped}"); + assert!( + !escaped.contains(""), + "raw markup must not reach the SVG" + ); } #[tokio::test] diff --git a/crates/forge-web/src/pages/commit.rs b/crates/forge-web/src/pages/commit.rs index 59a51d6..9d63b7f 100644 --- a/crates/forge-web/src/pages/commit.rs +++ b/crates/forge-web/src/pages/commit.rs @@ -299,6 +299,7 @@ mod tests { assert!(text.contains("Body line one.")); assert!(text.contains("class=\"mono\"")); assert!(text.contains("diff-file-body")); + assert!(!text.contains("sig-badge"), "unsigned commit has no badge"); } #[tokio::test] @@ -389,19 +390,6 @@ mod tests { assert_eq!(status, 404); } - #[tokio::test] - async fn unsigned_commit_page_has_no_signature_badge() { - let fx = Fixture::new(Visibility::Public).await; - let (status, _, body) = get( - &fx.router, - &format!("/{OWNER}/{REPO}/commit/{}", fx.modified), - ) - .await; - assert_eq!(status, 200); - let html = String::from_utf8(body).unwrap(); - assert!(!html.contains("sig-badge")); - } - #[tokio::test] async fn private_repo_is_404_for_anonymous() { let fx = Fixture::new(Visibility::Private).await; diff --git a/crates/forge-web/src/pages/commits.rs b/crates/forge-web/src/pages/commits.rs index 1fe4835..41299df 100644 --- a/crates/forge-web/src/pages/commits.rs +++ b/crates/forge-web/src/pages/commits.rs @@ -544,6 +544,10 @@ mod tests { assert!(!html.contains("root commit")); assert!(html.contains(">Older<")); assert!(!html.contains(">Newer<")); + assert!( + !html.contains("sig-badge"), + "unsigned commits have no badge" + ); let (status, _, body) = get(&fx.router, &format!("{base}?page=2")).await; assert_eq!(status, 200); @@ -672,16 +676,6 @@ mod tests { assert!(html.contains("Body with 🎉 and 12:30:45"), "{html}"); } - #[tokio::test] - async fn unsigned_commits_have_no_signature_badge() { - let fx = Fixture::new(Visibility::Public).await; - let (status, _, body) = get(&fx.router, &format!("/{OWNER}/{REPO}/commits/main")).await; - assert_eq!(status, 200); - let html = String::from_utf8(body).unwrap(); - assert!(html.contains("commit-row")); - assert!(!html.contains("sig-badge")); - } - #[tokio::test] async fn private_repo_is_404_for_anonymous() { let fx = Fixture::new(Visibility::Private).await;