From f12f76a5bd9351b47682930198ee3bea41fd8335 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:05:56 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20runner=20tests=20merge=20in?= =?UTF-8?q?to=20tables=20and=20share=20fixtures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test count in forge-runner src went from 167 to 160. Merged into tables with labelled asserts: resync cases in logs.rs (4 to 2), whiteouts and setid/flatten modes in oci/unpack.rs (4 to 2), clone URL checks in workspace.rs (2 to 1), env rejection in sandbox/spec.rs (2 to 1), and the cache cap and auto update config checks (2 to 1). No test was deleted. Sandbox skip logic is unchanged. --- crates/forge-runner/src/config.rs | 21 +++--------- crates/forge-runner/src/logs.rs | 43 ++++++++++------------- crates/forge-runner/src/oci/unpack.rs | 45 ++++++++++--------------- crates/forge-runner/src/sandbox/spec.rs | 21 ++++++------ crates/forge-runner/src/workspace.rs | 28 +++++++-------- 5 files changed, 64 insertions(+), 94 deletions(-) diff --git a/crates/forge-runner/src/config.rs b/crates/forge-runner/src/config.rs index 2b631e8..9635ced 100644 --- a/crates/forge-runner/src/config.rs +++ b/crates/forge-runner/src/config.rs @@ -696,29 +696,18 @@ mod tests { } #[test] - fn cache_cap_can_be_set_and_turned_off() { + fn cache_cap_and_auto_update_can_be_turned_off() { let dir = tempfile::tempdir().expect("tempdir"); let path = dir.path().join("runner.toml"); std::fs::write( &path, "url = \"https://f\"\nrunner_id = \"r\"\nrunner_secret = \"s\"\nname = \"n\"\n\ - work_dir = \"/w\"\ncache_max_gib = 0\n", + work_dir = \"/w\"\ncache_max_gib = 0\nauto_update = false\n", ) .expect("write"); - assert_eq!(load(&path).expect("load").cache_max_gib, 0); - } - - #[test] - fn auto_update_can_be_turned_off() { - let dir = tempfile::tempdir().expect("tempdir"); - let path = dir.path().join("runner.toml"); - std::fs::write( - &path, - "url = \"https://f\"\nrunner_id = \"r\"\nrunner_secret = \"s\"\nname = \"n\"\n\ - work_dir = \"/w\"\nauto_update = false\n", - ) - .expect("write"); - assert!(!load(&path).expect("load").auto_update); + let config = load(&path).expect("load"); + assert_eq!(config.cache_max_gib, 0, "cache cap"); + assert!(!config.auto_update, "auto update"); } #[test] diff --git a/crates/forge-runner/src/logs.rs b/crates/forge-runner/src/logs.rs index dfd78e0..fbb9169 100644 --- a/crates/forge-runner/src/logs.rs +++ b/crates/forge-runner/src/logs.rs @@ -330,22 +330,24 @@ mod tests { } #[test] - fn resync_drops_bytes_the_forge_already_has() { - // We sent "abcdef" at offset 0 and the response was lost. The forge stored it. - let mut buf = LogBuffer::new(); - buf.take(b"abcdef"); - assert!(buf.resync(6)); - assert_eq!(buf.offset(), 6); - assert!(buf.batch().is_empty()); - } - - #[test] - fn resync_resends_the_uncovered_tail() { - let mut buf = LogBuffer::new(); - buf.take(b"abcdef"); - assert!(!buf.resync(2)); - assert_eq!(buf.offset(), 2); - assert_eq!(buf.batch(), b"cdef"); + fn resync_to_the_forge_offset() { + // (bytes sent, size the forge reports, resync result, offset after, batch after) + type Case = (&'static [u8], u64, bool, u64, &'static [u8]); + let cases: &[Case] = &[ + // The response to "abcdef" was lost and the forge stored it, so nothing is resent. + (b"abcdef", 6, true, 6, b""), + // The forge holds 2 bytes, so the uncovered tail is resent. + (b"abcdef", 2, false, 2, b"cdef"), + // The forge is ahead of everything we hold, which marks a gap. + (b"ab", 10, false, 10, GAP_MARKER), + ]; + for (sent, held, want_ok, want_offset, want_batch) in cases { + let mut buf = LogBuffer::new(); + buf.take(sent); + assert_eq!(buf.resync(*held), *want_ok, "held {held}"); + assert_eq!(buf.offset(), *want_offset, "held {held}"); + assert_eq!(buf.batch(), *want_batch, "held {held}"); + } } #[test] @@ -361,15 +363,6 @@ mod tests { assert_eq!(buf.end(), 6); } - #[test] - fn resync_ahead_of_everything_we_hold_marks_a_gap() { - let mut buf = LogBuffer::new(); - buf.take(b"ab"); - assert!(!buf.resync(10)); - assert_eq!(buf.offset(), 10); - assert_eq!(buf.batch(), GAP_MARKER); - } - #[test] fn resync_below_the_window_marks_a_gap_and_keeps_the_rest() { // Two full batches are acknowledged. A one-batch cap trims the first. diff --git a/crates/forge-runner/src/oci/unpack.rs b/crates/forge-runner/src/oci/unpack.rs index 5d5054e..00950f9 100644 --- a/crates/forge-runner/src/oci/unpack.rs +++ b/crates/forge-runner/src/oci/unpack.rs @@ -687,33 +687,30 @@ mod tests { } #[test] - fn whiteout_deletes_earlier_file() { + fn whiteouts_delete_a_file_and_a_directory_tree() { let c = case(); let first = tar_of(|b| { dir(b, "etc/"); file(b, "etc/old", b"1"); file(b, "etc/keep", b"2"); - }); - let second = tar_of(|b| file(b, "etc/.wh.old", b"")); - let stats = run(&c, &[first, second]).expect("unpack"); - assert!(!c.rootfs.join("etc/old").exists()); - assert!(c.rootfs.join("etc/keep").is_file()); - assert_eq!(stats.whiteouts, 1); - // The whiteout marker itself is never written. - assert!(!c.rootfs.join("etc/.wh.old").exists()); - } - - #[test] - fn whiteout_deletes_directory_tree() { - let c = case(); - let first = tar_of(|b| { dir(b, "opt/"); dir(b, "opt/app/"); file(b, "opt/app/bin", b"x"); }); - let second = tar_of(|b| file(b, "opt/.wh.app", b"")); - run(&c, &[first, second]).expect("unpack"); + let second = tar_of(|b| { + file(b, "etc/.wh.old", b""); + file(b, "opt/.wh.app", b""); + }); + let stats = run(&c, &[first, second]).expect("unpack"); + // Earlier file removed, sibling kept. + assert!(!c.rootfs.join("etc/old").exists()); + assert!(c.rootfs.join("etc/keep").is_file()); + // Earlier directory tree removed. assert!(!c.rootfs.join("opt/app").exists()); + assert_eq!(stats.whiteouts, 2); + // The whiteout markers themselves are never written. + assert!(!c.rootfs.join("etc/.wh.old").exists()); + assert!(!c.rootfs.join("opt/.wh.app").exists()); } #[test] @@ -738,17 +735,19 @@ mod tests { } #[test] - fn setuid_and_setgid_are_stripped() { + fn flatten_strips_setid_bits_and_keeps_directories_owner_writable() { let c = case(); let layer = tar_of(|b| { put(b, EntryType::Regular, "su", None, 0o4755, b"x"); put(b, EntryType::Regular, "sg", None, 0o2750, b"x"); put(b, EntryType::Directory, "d/", None, 0o6777, b""); + put(b, EntryType::Directory, "ro/", None, 0o550, b""); }); run(&c, &[layer]).expect("unpack"); assert_eq!(mode_of(&c.rootfs.join("su")), 0o755); assert_eq!(mode_of(&c.rootfs.join("sg")), 0o750); assert_eq!(mode_of(&c.rootfs.join("d")) & 0o6000, 0); + assert_eq!(mode_of(&c.rootfs.join("ro")), 0o750); } #[test] @@ -865,16 +864,6 @@ mod tests { ); } - #[test] - fn flatten_keeps_directories_owner_writable() { - let c = case(); - let layer = tar_of(|b| { - put(b, EntryType::Directory, "d/", None, 0o550, b""); - }); - run(&c, &[layer]).expect("unpack"); - assert_eq!(mode_of(&c.rootfs.join("d")), 0o750); - } - #[test] fn later_layer_replaces_file_with_directory() { let c = case(); diff --git a/crates/forge-runner/src/sandbox/spec.rs b/crates/forge-runner/src/sandbox/spec.rs index 87614f3..836fb07 100644 --- a/crates/forge-runner/src/sandbox/spec.rs +++ b/crates/forge-runner/src/sandbox/spec.rs @@ -748,16 +748,15 @@ mod tests { } #[test] - fn bad_env_names_are_rejected() { - let mut req = request(false); - req.env.push(("A=B".to_owned(), "x".to_owned())); - assert!(build_spec(&req, Path::new("/rootfs")).is_err()); - } - - #[test] - fn nul_in_env_value_is_rejected() { - let mut req = request(false); - req.env.push(("OK".to_owned(), "a\0b".to_owned())); - assert!(build_spec(&req, Path::new("/rootfs")).is_err()); + fn bad_env_entries_are_rejected() { + let cases: &[(&str, &str)] = &[("A=B", "x"), ("OK", "a\0b")]; + for (name, value) in cases { + let mut req = request(false); + req.env.push(((*name).to_owned(), (*value).to_owned())); + assert!( + build_spec(&req, Path::new("/rootfs")).is_err(), + "case {name:?}={value:?}" + ); + } } } diff --git a/crates/forge-runner/src/workspace.rs b/crates/forge-runner/src/workspace.rs index 4d11815..4d32844 100644 --- a/crates/forge-runner/src/workspace.rs +++ b/crates/forge-runner/src/workspace.rs @@ -208,20 +208,20 @@ mod tests { } #[test] - fn clone_urls_cannot_look_like_options() { - let https = "https://forge.example"; - assert!(validate_clone_url("https://forge.example/o/r.git", https).is_ok()); - assert!(validate_clone_url("--upload-pack=sh", https).is_err()); - assert!(validate_clone_url("ext::sh -c id", https).is_err()); - assert!(validate_clone_url("https://a b/x", https).is_err()); - } - - #[test] - fn http_clone_urls_need_an_http_forge() { - assert!(validate_clone_url("http://forge.example/o/r.git", "http://forge.example").is_ok()); - assert!( - validate_clone_url("http://forge.example/o/r.git", "https://forge.example").is_err() - ); + fn clone_urls_are_checked_against_the_forge_scheme() { + // (clone url, forge url, accepted) + let cases: &[(&str, &str, bool)] = &[ + ("https://forge.example/o/r.git", "https://forge.example", true), + ("--upload-pack=sh", "https://forge.example", false), + ("ext::sh -c id", "https://forge.example", false), + ("https://a b/x", "https://forge.example", false), + // Plain http is only accepted when the forge itself is http. + ("http://forge.example/o/r.git", "http://forge.example", true), + ("http://forge.example/o/r.git", "https://forge.example", false), + ]; + for (url, forge, ok) in cases { + assert_eq!(validate_clone_url(url, forge).is_ok(), *ok, "case {url}"); + } } #[test]