From 61d24bff5fba9332f4279f3d5079aa58a067927e Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 22 Aug 2026 23:10:17 +0530 Subject: [PATCH 1/4] ci: add nightly NFS and Docker lock tests (#324) Tiers 2 and 3 from the kernel file-locking design, deferred from #317/#332: the per-PR suite covers PID namespaces but cannot reach how std::fs::File::try_lock behaves on a network filesystem or in real containers. tests/nfs_lock_test.rs asserts the core #324 property on a loopback NFSv4 mount and an NFSv3 mount without lockd: a lock held by one process must never let a second process also believe it holds it. It also proves allow_unlocked is consulted only on a mount that cannot lock at all, never to bypass a live lock. tests/docker_lock_test.rs runs the same #317 regression shape (a killed holder's replacement must still be able to open) across two containers sharing a Docker volume, matching the original report literally. Both reuse examples/pid_ns_helper.rs, which gains an explicit mode match (an unrecognized mode now fails loudly instead of silently behaving like "open") and a new open-unlocked mode. Locally verifiable pieces (mode validation, open-unlocked on an ordinary filesystem, docker_available() reflecting a sandbox with no Docker) are covered by TDD here. The NFS- and Docker-gated assertions need root and a container runtime this sandbox doesn't have; they skip cleanly without their environment and are exercised for real by the new .github/workflows/nfs-lock.yml nightly workflow, which also records failures as tracking issues, matching fuzz.yml/property-tests.yml. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YMWSutMLJJ7Y5b8hs9ZaCU --- .github/workflows/nfs-lock.yml | 159 ++++++++++++++++++++++ examples/pid_ns_helper.rs | 19 ++- tests/docker_lock_test.rs | 241 +++++++++++++++++++++++++++++++++ tests/nfs_lock_test.rs | 194 ++++++++++++++++++++++++++ 4 files changed, 612 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/nfs-lock.yml create mode 100644 tests/docker_lock_test.rs create mode 100644 tests/nfs_lock_test.rs diff --git a/.github/workflows/nfs-lock.yml b/.github/workflows/nfs-lock.yml new file mode 100644 index 0000000000..517cd8289f --- /dev/null +++ b/.github/workflows/nfs-lock.yml @@ -0,0 +1,159 @@ +name: NFS/Docker lock tests (nightly) + +# Tiers 2 and 3 of the kernel file-locking design +# (docs/superpowers/specs/2026-08-22-kernel-file-locking-design.md): the +# per-PR suite (tests/pid_namespace_test.rs) covers PID namespaces but cannot +# reach how `std::fs::File::try_lock` behaves on a network filesystem or in +# real containers. See #324. + +on: + schedule: + - cron: "41 2 * * *" + workflow_dispatch: + +permissions: + contents: read + issues: write + +jobs: + nfs: + name: NFS lock suite + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust stable + uses: dtolnay/rust-toolchain@stable + + - name: Install and start a loopback NFS server + run: | + sudo apt-get update -y + sudo apt-get install -y nfs-kernel-server nfs-common + sudo modprobe nfsd || true + + sudo mkdir -p /srv/nfs/export + sudo chown "$(id -u)":"$(id -g)" /srv/nfs/export + echo "/srv/nfs/export 127.0.0.1(rw,sync,no_subtree_check,no_root_squash,insecure)" \ + | sudo tee -a /etc/exports + sudo exportfs -ra + sudo systemctl restart nfs-kernel-server + + - name: Mount the export as NFSv4 and as NFSv3 without lockd + run: | + sudo mkdir -p /mnt/nfs-v4 /mnt/nfs-v3-nolock + sudo mount -t nfs -o vers=4,proto=tcp 127.0.0.1:/srv/nfs/export /mnt/nfs-v4 + sudo mount -t nfs -o vers=3,nolock 127.0.0.1:/srv/nfs/export /mnt/nfs-v3-nolock + sudo chown "$(id -u)":"$(id -g)" /mnt/nfs-v4 /mnt/nfs-v3-nolock + + - name: Build the PID-namespace helper binary + run: cargo build --examples + + - name: Run the NFS lock suite + shell: bash + env: + MINIGRAF_NFS_TEST_DIR_V4: /mnt/nfs-v4 + MINIGRAF_NFS_TEST_DIR_V3_NOLOCK: /mnt/nfs-v3-nolock + RUST_BACKTRACE: 1 + run: | + set -o pipefail + cargo test --test nfs_lock_test -- --nocapture 2>&1 | tee nfs-lock-output.txt + + - name: Record NFS lock-suite failure + if: ${{ failure() }} + shell: bash + env: + GH_TOKEN: ${{ github.token }} + ISSUE_TITLE: "Nightly NFS lock-suite failure" + run: | + report_file="nfs-lock-failure.md" + { + echo "The nightly NFS lock suite failed." + echo + echo "- Run: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + echo "- Commit: $GITHUB_SHA" + echo "- Reproduce: needs a loopback NFS export mounted as vers=4 and as" + echo " vers=3,nolock; see the \"nfs\" job in .github/workflows/nfs-lock.yml" + echo + echo "## Test output" + echo + echo '```text' + tail -n 1000 nfs-lock-output.txt + echo '```' + } > "$report_file" + + existing_issue="$(gh issue list \ + --repo "$GITHUB_REPOSITORY" \ + --state open \ + --search "$ISSUE_TITLE in:title" \ + --json number,title \ + --limit 100 \ + --jq '.[] | select(.title == "Nightly NFS lock-suite failure") | .number' \ + | head -n 1)" + + if [ -n "$existing_issue" ]; then + gh issue comment "$existing_issue" --repo "$GITHUB_REPOSITORY" --body-file "$report_file" + else + gh issue create --repo "$GITHUB_REPOSITORY" --title "$ISSUE_TITLE" --body-file "$report_file" + fi + + docker: + name: Docker lock suite + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust stable + uses: dtolnay/rust-toolchain@stable + + - name: Build the PID-namespace helper binary + run: cargo build --examples + + - name: Run the Docker lock suite + shell: bash + env: + RUST_BACKTRACE: 1 + run: | + set -o pipefail + cargo test --test docker_lock_test -- --nocapture 2>&1 | tee docker-lock-output.txt + + - name: Record Docker lock-suite failure + if: ${{ failure() }} + shell: bash + env: + GH_TOKEN: ${{ github.token }} + ISSUE_TITLE: "Nightly Docker lock-suite failure" + run: | + report_file="docker-lock-failure.md" + { + echo "The nightly Docker lock suite failed." + echo + echo "- Run: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + echo "- Commit: $GITHUB_SHA" + echo "- Reproduce: needs a reachable Docker daemon; see the \"docker\" job" + echo " in .github/workflows/nfs-lock.yml" + echo + echo "## Test output" + echo + echo '```text' + tail -n 1000 docker-lock-output.txt + echo '```' + } > "$report_file" + + existing_issue="$(gh issue list \ + --repo "$GITHUB_REPOSITORY" \ + --state open \ + --search "$ISSUE_TITLE in:title" \ + --json number,title \ + --limit 100 \ + --jq '.[] | select(.title == "Nightly Docker lock-suite failure") | .number' \ + | head -n 1)" + + if [ -n "$existing_issue" ]; then + gh issue comment "$existing_issue" --repo "$GITHUB_REPOSITORY" --body-file "$report_file" + else + gh issue create --repo "$GITHUB_REPOSITORY" --title "$ISSUE_TITLE" --body-file "$report_file" + fi diff --git a/examples/pid_ns_helper.rs b/examples/pid_ns_helper.rs index 6fc018e910..567b3aaa73 100644 --- a/examples/pid_ns_helper.rs +++ b/examples/pid_ns_helper.rs @@ -42,7 +42,24 @@ fn main() { // than an env var so it survives `sudo` -- see the note above. let release_marker = args.get(3).map(std::path::PathBuf::from); - match minigraf::Minigraf::open(path) { + // Validate the mode up front rather than falling through to a plain open + // for anything unrecognized: a typo'd or not-yet-implemented mode must + // fail loudly, not silently behave like "open". + if !["hold", "open", "open-unlocked"].contains(&mode.as_str()) { + eprintln!("unknown mode: {mode}"); + std::process::exit(2); + } + + let open_result = if mode == "open-unlocked" { + minigraf::OpenOptions::default() + .allow_unlocked(true) + .path(path) + .open() + } else { + minigraf::Minigraf::open(path) + }; + + match open_result { Ok(db) => { db.execute(r#"(transact [[:a :name "A"]])"#).ok(); println!("OPEN_OK"); diff --git a/tests/docker_lock_test.rs b/tests/docker_lock_test.rs new file mode 100644 index 0000000000..a95bdfd5ab --- /dev/null +++ b/tests/docker_lock_test.rs @@ -0,0 +1,241 @@ +//! #324: kernel file locking, tier 3 — two containers sharing a Docker +//! volume, matching the deployment shape in the #317 report literally. +//! +//! Mechanically the same path as `tests/pid_namespace_test.rs` (tier 1): a +//! holder dies without running `Drop`, and a replacement sharing the same +//! storage must still be able to open the database. Docker gives it a real +//! `SIGKILL` and a genuinely separate PID namespace per container, rather +//! than `unshare` simulating one. +//! +//! Needs a working Docker daemon, which this sandbox does not have and which +//! `.github/workflows/nfs-lock.yml` provisions on its runner. Skips cleanly +//! when `docker` is unavailable, so plain `cargo test` never touches it. +#![cfg(target_os = "linux")] + +use std::path::{Path, PathBuf}; +use std::process::{Command, Output, Stdio}; +use std::time::{SystemTime, UNIX_EPOCH}; + +const IMAGE: &str = "ubuntu:24.04"; + +/// Whether a Docker daemon is actually reachable, not just whether the CLI +/// exists. `docker info` fails fast (and without hanging) when there is no +/// daemon to talk to. +fn docker_available() -> bool { + Command::new("docker") + .arg("info") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .map(|s| s.success()) + .unwrap_or(false) +} + +/// Path to `examples/pid_ns_helper`, resolved relative to the test binary. +/// Shared shape with `tests/pid_namespace_test.rs::helper_binary`. +fn helper_binary() -> PathBuf { + let mut dir = std::env::current_exe().expect("test binary path"); + dir.pop(); // deps/ + dir.pop(); // debug/ (or release/) + dir.join("examples").join("pid_ns_helper") +} + +fn require_helper_built(helper: &Path) { + assert!( + helper.exists(), + "helper binary not found at {}; run `cargo build --examples` first", + helper.display() + ); +} + +/// A name unlikely to collide with a concurrently running test or a prior +/// run's leftovers. Rust runs `#[test]` functions in parallel by default, and +/// this file has two tests that each create a container and a volume. +fn unique_name(label: &str) -> String { + let nanos = SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("system clock") + .as_nanos(); + format!("minigraf-{label}-{}-{nanos}", std::process::id()) +} + +/// Removes the container and volume on drop, so a failed assertion mid-test +/// does not leak Docker resources on the runner. +struct DockerCleanup { + container: String, + volume: String, +} + +impl Drop for DockerCleanup { + fn drop(&mut self) { + let _ = Command::new("docker") + .args(["rm", "-f", &self.container]) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status(); + let _ = Command::new("docker") + .args(["volume", "rm", "-f", &self.volume]) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status(); + } +} + +/// Starts a container that shares `volume` and the helper binary, running +/// detached so the caller can poll it and kill it while it is alive. +fn start_holder(container: &str, volume: &str, helper: &Path) { + let status = Command::new("docker") + .args([ + "run", + "-d", + "--name", + container, + "-v", + &format!("{volume}:/data"), + "-v", + &format!("{}:/helper:ro", helper.display()), + IMAGE, + "/helper", + "/data/shared.graph", + "hold", + "/data/release", + ]) + .status() + .expect("start holder container"); + assert!(status.success(), "docker run -d for the holder failed"); +} + +/// Blocks until `docker logs` on the holder shows it opened the database, or +/// panics after a generous timeout. +fn wait_for_holder_to_open(container: &str) { + for _ in 0..200 { + let logs = Command::new("docker") + .args(["logs", container]) + .output() + .expect("docker logs"); + if String::from_utf8_lossy(&logs.stdout).contains("OPEN_OK") { + return; + } + std::thread::sleep(std::time::Duration::from_millis(100)); + } + panic!("holder container never reported opening the database"); +} + +/// Runs a fresh, short-lived container against the shared volume in `open` +/// mode and returns its output. +fn run_opener(volume: &str, helper: &Path) -> Output { + Command::new("docker") + .args([ + "run", + "--rm", + "-v", + &format!("{volume}:/data"), + "-v", + &format!("{}:/helper:ro", helper.display()), + IMAGE, + "/helper", + "/data/shared.graph", + "open", + ]) + .output() + .expect("run opener container") +} + +/// Not a gated integration test: proof that `docker_available()` reflects +/// reality instead of hardcoding `true`, which would make every gated test +/// below a silent no-op forever. This sandbox has neither the Docker CLI nor +/// a daemon, so the expected answer here is `false`. +#[test] +fn test_docker_availability_check_reflects_this_sandbox() { + assert!( + !docker_available(), + "expected no reachable Docker daemon in this sandbox; if this now \ + fails, docker_available() may not be checking the right thing" + ); +} + +#[test] +fn test_lock_survives_holder_container_being_killed() { + if !docker_available() { + eprintln!("SKIP: no reachable Docker daemon"); + return; + } + let helper = helper_binary(); + require_helper_built(&helper); + + let container = unique_name("holder"); + let volume = unique_name("vol"); + Command::new("docker") + .args(["volume", "create", &volume]) + .status() + .expect("create volume"); + let _cleanup = DockerCleanup { + container: container.clone(), + volume: volume.clone(), + }; + + start_holder(&container, &volume, &helper); + wait_for_holder_to_open(&container); + + // Kill it the way a Kubernetes pod eviction does: no graceful shutdown, + // no Drop. + let status = Command::new("docker") + .args(["kill", &container]) + .status() + .expect("docker kill"); + assert!(status.success(), "docker kill failed"); + let _ = Command::new("docker").args(["wait", &container]).output(); + + let b = run_opener(&volume, &helper); + let out = String::from_utf8_lossy(&b.stdout); + assert!( + out.contains("OPEN_OK"), + "a replacement container sharing the volume must be able to open the \ + database after its predecessor was killed; this is #317's shape \ + with real containers.\nstdout: {out}\nstderr: {}", + String::from_utf8_lossy(&b.stderr) + ); +} + +#[test] +fn test_two_live_containers_are_still_refused() { + if !docker_available() { + eprintln!("SKIP: no reachable Docker daemon"); + return; + } + let helper = helper_binary(); + require_helper_built(&helper); + + let container = unique_name("holder2"); + let volume = unique_name("vol2"); + Command::new("docker") + .args(["volume", "create", &volume]) + .status() + .expect("create volume"); + let _cleanup = DockerCleanup { + container: container.clone(), + volume: volume.clone(), + }; + + start_holder(&container, &volume, &helper); + wait_for_holder_to_open(&container); + + // A is still alive. A second, independent container sharing the volume + // must be refused -- the guarantee PR #318's start-time comparison would + // have broken by admitting two live writers. + let b = run_opener(&volume, &helper); + let out = String::from_utf8_lossy(&b.stdout); + + // Release A now that B's attempt is recorded, then let it exit. + let _ = Command::new("docker") + .args(["exec", &container, "/bin/touch", "/data/release"]) + .status(); + let _ = Command::new("docker").args(["wait", &container]).output(); + + assert!( + !out.contains("OPEN_OK"), + "a second live container sharing the volume must be refused.\n\ + stdout: {out}\nstderr: {}", + String::from_utf8_lossy(&b.stderr) + ); +} diff --git a/tests/nfs_lock_test.rs b/tests/nfs_lock_test.rs new file mode 100644 index 0000000000..45ddef989a --- /dev/null +++ b/tests/nfs_lock_test.rs @@ -0,0 +1,194 @@ +//! #324: kernel file locking must behave correctly on network filesystems. +//! +//! `flock` over NFS is emulated by `fcntl` on Linux since 2.6.37, which works +//! on NFSv4 but needs `lockd` on NFSv3. The failure mode that matters is a +//! lock that silently no-ops rather than erroring: the new code would believe +//! it holds an exclusive lock while a second process holds the same file. +//! +//! The NFS-mount tests below need a loopback NFS export, which needs root and +//! is provisioned by `.github/workflows/nfs-lock.yml`, not by this file. They +//! skip cleanly when the environment variables they need are unset, so plain +//! `cargo test` never touches them. +#![cfg(target_os = "linux")] + +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; + +/// Path to `examples/pid_ns_helper`, resolved relative to the test binary at +/// `target/debug/deps/nfs_lock_test-`. Shared shape with +/// `tests/pid_namespace_test.rs::helper_binary`. +fn helper_binary() -> PathBuf { + let mut dir = std::env::current_exe().expect("test binary path"); + dir.pop(); // deps/ + dir.pop(); // debug/ + dir.join("examples").join("pid_ns_helper") +} + +fn require_helper_built(helper: &Path) { + assert!( + helper.exists(), + "helper binary not found at {}; run `cargo build --examples` first", + helper.display() + ); +} + +fn run_helper(helper: &Path, db: &Path, mode: &str) -> Output { + Command::new(helper) + .arg(db) + .arg(mode) + .output() + .expect("run helper") +} + +/// The helper must reject an unrecognized mode string rather than silently +/// falling through to a plain open. Without this, a typo'd or unimplemented +/// mode (like `open-unlocked` before it exists) is indistinguishable from +/// `open` — exactly the false-green trap this guards against. +#[test] +fn test_unrecognized_mode_fails_loudly_instead_of_falling_through() { + let helper = helper_binary(); + require_helper_built(&helper); + + let dir = tempfile::tempdir().unwrap(); + let db = dir.path().join("bogus-mode.graph"); + + let out = run_helper(&helper, &db, "not-a-real-mode"); + assert!( + out.status.code().unwrap_or(0) != 0, + "an unrecognized mode must not exit successfully" + ); +} + +/// The `open-unlocked` mode must work on an ordinary filesystem, independent +/// of any NFS provisioning. This is the part of #324 this sandbox can +/// actually verify: that `allow_unlocked` opts in correctly when asked, on a +/// mount where locking works fine. The NFS tests below cover the fail-closed +/// side, which needs a mount where locking does NOT work. +#[test] +fn test_open_unlocked_mode_succeeds_on_an_ordinary_filesystem() { + let helper = helper_binary(); + require_helper_built(&helper); + + let dir = tempfile::tempdir().unwrap(); + let db = dir.path().join("plain.graph"); + + let out = run_helper(&helper, &db, "open-unlocked"); + let stdout = String::from_utf8_lossy(&out.stdout); + assert!( + stdout.contains("OPEN_OK"), + "open-unlocked must succeed on a filesystem that can lock.\n\ + stdout: {stdout}\nstderr: {}", + String::from_utf8_lossy(&out.stderr) + ); +} + +/// Directory holding a loopback NFSv4 export, provisioned by +/// `.github/workflows/nfs-lock.yml`. `None` outside that workflow. +fn nfsv4_dir() -> Option { + std::env::var("MINIGRAF_NFS_TEST_DIR_V4") + .ok() + .map(PathBuf::from) +} + +/// Directory holding a loopback NFSv3 export mounted with `nolock` (no +/// `lockd`), provisioned by the same workflow. `None` outside it. +fn nfsv3_nolock_dir() -> Option { + std::env::var("MINIGRAF_NFS_TEST_DIR_V3_NOLOCK") + .ok() + .map(PathBuf::from) +} + +/// While a holder is alive on the mount, a second open must never report +/// success. This is the core #324 assertion: genuinely exclusive, or +/// refused — a silent no-op (both processes believing they hold the lock) is +/// the one outcome that must never happen. +fn assert_lock_excludes_second_holder(mount: &Path, label: &str) { + let helper = helper_binary(); + require_helper_built(&helper); + + let db = mount.join(format!("{label}.graph")); + let release = mount.join(format!("{label}-release")); + + let mut holder = Command::new(&helper) + .arg(&db) + .arg("hold") + .arg(&release) + .spawn() + .expect("spawn holder"); + + // Wait for the holder to actually open the database before racing the + // second opener against it. + let mut opened = false; + for _ in 0..200 { + if db.exists() { + opened = true; + break; + } + std::thread::sleep(std::time::Duration::from_millis(50)); + } + assert!(opened, "[{label}] holder never created the database file"); + + let second = run_helper(&helper, &db, "open"); + let second_out = String::from_utf8_lossy(&second.stdout); + + std::fs::write(&release, b"").expect("write release marker"); + let _ = holder.wait(); + + assert!( + !second_out.contains("OPEN_OK"), + "[{label}] a second open must not succeed while a holder is alive on \ + this mount; a silent no-op here means the mount let two processes \ + both believe they hold the lock.\nsecond open stdout: {second_out}" + ); +} + +#[test] +fn test_lock_is_exclusive_over_nfsv4() { + let Some(mount) = nfsv4_dir() else { + eprintln!("SKIP: MINIGRAF_NFS_TEST_DIR_V4 not set"); + return; + }; + assert_lock_excludes_second_holder(&mount, "nfsv4"); +} + +#[test] +fn test_lock_is_exclusive_or_refused_over_nfsv3_without_lockd() { + let Some(mount) = nfsv3_nolock_dir() else { + eprintln!("SKIP: MINIGRAF_NFS_TEST_DIR_V3_NOLOCK not set"); + return; + }; + assert_lock_excludes_second_holder(&mount, "nfsv3-nolock"); +} + +/// On a mount where locking is unsupported, the default (`allow_unlocked = +/// false`) must fail closed, and `open-unlocked` must proceed. Proves +/// `allow_unlocked` is consulted only where it should be. +#[test] +fn test_allow_unlocked_gates_the_unsupported_nfsv3_mount() { + let Some(mount) = nfsv3_nolock_dir() else { + eprintln!("SKIP: MINIGRAF_NFS_TEST_DIR_V3_NOLOCK not set"); + return; + }; + let helper = helper_binary(); + require_helper_built(&helper); + + let db = mount.join("allow-unlocked-gate.graph"); + + let default_open = run_helper(&helper, &db, "open"); + let default_out = String::from_utf8_lossy(&default_open.stdout); + assert!( + !default_out.contains("OPEN_OK"), + "default open must fail closed on a mount that cannot lock.\n\ + stdout: {default_out}" + ); + + let db2 = mount.join("allow-unlocked-gate-2.graph"); + let unlocked_open = run_helper(&helper, &db2, "open-unlocked"); + let unlocked_out = String::from_utf8_lossy(&unlocked_open.stdout); + assert!( + unlocked_out.contains("OPEN_OK"), + "open-unlocked must proceed on a mount that cannot lock.\n\ + stdout: {unlocked_out}\nstderr: {}", + String::from_utf8_lossy(&unlocked_open.stderr) + ); +} From 8d23f4643b28a75a1edd4e3340107e4dece3d43a Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sun, 23 Aug 2026 08:49:43 +0530 Subject: [PATCH 2/4] fix(test): remove environment-specific docker_available() assertion test_docker_availability_check_reflects_this_sandbox asserted docker was never reachable, true only in the local sandbox this branch was written in. GitHub's ubuntu-latest runners have Docker preinstalled and running, so the assertion failed there -- while, in the same run, the two real gated tests it was meant to backstop actually exercised Docker for real and passed. Those two are the genuine proof; this one just encoded an environment assumption as a hard failure. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YMWSutMLJJ7Y5b8hs9ZaCU --- tests/docker_lock_test.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/docker_lock_test.rs b/tests/docker_lock_test.rs index a95bdfd5ab..974f12b103 100644 --- a/tests/docker_lock_test.rs +++ b/tests/docker_lock_test.rs @@ -141,19 +141,6 @@ fn run_opener(volume: &str, helper: &Path) -> Output { .expect("run opener container") } -/// Not a gated integration test: proof that `docker_available()` reflects -/// reality instead of hardcoding `true`, which would make every gated test -/// below a silent no-op forever. This sandbox has neither the Docker CLI nor -/// a daemon, so the expected answer here is `false`. -#[test] -fn test_docker_availability_check_reflects_this_sandbox() { - assert!( - !docker_available(), - "expected no reachable Docker daemon in this sandbox; if this now \ - fails, docker_available() may not be checking the right thing" - ); -} - #[test] fn test_lock_survives_holder_container_being_killed() { if !docker_available() { From 735554cfc0c6ccf8f527a38a57ce3498adba79a3 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sun, 23 Aug 2026 09:02:35 +0530 Subject: [PATCH 3/4] fix(ci): build examples before tarpaulin so lock tests find the helper cargo tarpaulin does not build examples/ before running tests, unlike plain cargo test. tests/nfs_lock_test.rs and tests/docker_lock_test.rs resolve examples/pid_ns_helper relative to the test binary's own target dir, so it must already be built. tests/pid_namespace_test.rs never hit this because it skips before reaching that check when unshare isn't available in tarpaulin's environment; the new tests don't have an equivalent early-out. Reproduced and verified the fix locally with cargo tarpaulin directly. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YMWSutMLJJ7Y5b8hs9ZaCU --- .github/workflows/coverage.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 5a3c65c87b..ff48e2bfa2 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -23,6 +23,13 @@ jobs: - name: Install tarpaulin run: cargo install cargo-tarpaulin + - name: Build example binaries used by lock tests + # tarpaulin does not build `examples/` before running tests, unlike + # plain `cargo test`. tests/nfs_lock_test.rs and + # tests/docker_lock_test.rs resolve examples/pid_ns_helper relative + # to the test binary's own target dir, so it must already be built. + run: cargo build --examples + - name: Generate coverage run: cargo tarpaulin --out Xml --timeout 300 --fail-under 75 --exclude-files "src/main.rs" From 085f91f82763266e43b8c9cb6ef6a9e4fc6fdec3 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sun, 23 Aug 2026 09:21:14 +0530 Subject: [PATCH 4/4] fix(ci): give lock tests an env-var override for the helper path cargo tarpaulin deletes target/debug/examples/ as part of its own instrumented build, regardless of when it was built -- a plain `cargo build --examples` step before the tarpaulin run doesn't survive it. Reproduced locally against cargo-tarpaulin 0.35.2 from a clean checkout: the previous fix (build-examples-first) still failed with "helper binary not found", and target/debug/examples/ was empty after tarpaulin ran. nfs_lock_test.rs and docker_lock_test.rs now check MINIGRAF_PID_NS_HELPER before falling back to the current_exe()-derived path. coverage.yml builds the helper into an isolated --target-dir tarpaulin never touches and points the variable at it. Verified against a clean checkout with cargo tarpaulin directly: both suites pass. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YMWSutMLJJ7Y5b8hs9ZaCU --- .github/workflows/coverage.yml | 14 ++++++++------ tests/docker_lock_test.rs | 13 +++++++++++-- tests/nfs_lock_test.rs | 13 +++++++++++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index ff48e2bfa2..ecebd02019 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -23,14 +23,16 @@ jobs: - name: Install tarpaulin run: cargo install cargo-tarpaulin - - name: Build example binaries used by lock tests - # tarpaulin does not build `examples/` before running tests, unlike - # plain `cargo test`. tests/nfs_lock_test.rs and - # tests/docker_lock_test.rs resolve examples/pid_ns_helper relative - # to the test binary's own target dir, so it must already be built. - run: cargo build --examples + - name: Build the pid_ns_helper example used by lock tests + # tarpaulin deletes target/debug/examples/ as part of its own + # instrumented build, regardless of when it was built, so this has to + # live in a target dir tarpaulin never touches. nfs_lock_test.rs and + # docker_lock_test.rs read MINIGRAF_PID_NS_HELPER for exactly this. + run: cargo build --examples --target-dir /tmp/minigraf-lock-test-examples - name: Generate coverage + env: + MINIGRAF_PID_NS_HELPER: /tmp/minigraf-lock-test-examples/debug/examples/pid_ns_helper run: cargo tarpaulin --out Xml --timeout 300 --fail-under 75 --exclude-files "src/main.rs" - name: Upload coverage to Codecov diff --git a/tests/docker_lock_test.rs b/tests/docker_lock_test.rs index 974f12b103..611bf9e6c4 100644 --- a/tests/docker_lock_test.rs +++ b/tests/docker_lock_test.rs @@ -31,9 +31,18 @@ fn docker_available() -> bool { .unwrap_or(false) } -/// Path to `examples/pid_ns_helper`, resolved relative to the test binary. -/// Shared shape with `tests/pid_namespace_test.rs::helper_binary`. +/// Path to `examples/pid_ns_helper`. +/// +/// `MINIGRAF_PID_NS_HELPER`, if set, is used as-is. Needed under `cargo +/// tarpaulin`, which deletes `target/debug/examples/` as part of its own +/// instrumented build regardless of when it was built, so the helper has to +/// live in a target dir tarpaulin never touches; `.github/workflows/coverage.yml` +/// builds it there and sets this variable. Otherwise resolved relative to the +/// test binary, the same shape as `tests/pid_namespace_test.rs::helper_binary`. fn helper_binary() -> PathBuf { + if let Ok(path) = std::env::var("MINIGRAF_PID_NS_HELPER") { + return PathBuf::from(path); + } let mut dir = std::env::current_exe().expect("test binary path"); dir.pop(); // deps/ dir.pop(); // debug/ (or release/) diff --git a/tests/nfs_lock_test.rs b/tests/nfs_lock_test.rs index 45ddef989a..3ce075e40a 100644 --- a/tests/nfs_lock_test.rs +++ b/tests/nfs_lock_test.rs @@ -14,10 +14,19 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Output}; -/// Path to `examples/pid_ns_helper`, resolved relative to the test binary at -/// `target/debug/deps/nfs_lock_test-`. Shared shape with +/// Path to `examples/pid_ns_helper`. +/// +/// `MINIGRAF_PID_NS_HELPER`, if set, is used as-is. Needed under `cargo +/// tarpaulin`, which deletes `target/debug/examples/` as part of its own +/// instrumented build regardless of when it was built, so the helper has to +/// live in a target dir tarpaulin never touches; `.github/workflows/coverage.yml` +/// builds it there and sets this variable. Otherwise resolved relative to the +/// test binary at `target/debug/deps/nfs_lock_test-`, the same shape as /// `tests/pid_namespace_test.rs::helper_binary`. fn helper_binary() -> PathBuf { + if let Ok(path) = std::env::var("MINIGRAF_PID_NS_HELPER") { + return PathBuf::from(path); + } let mut dir = std::env::current_exe().expect("test binary path"); dir.pop(); // deps/ dir.pop(); // debug/