From 9cb3a7fcee46489c5e8320c68cc968394cd47931 Mon Sep 17 00:00:00 2001 From: Samit Basu Date: Thu, 12 Nov 2026 11:57:30 -0800 Subject: [PATCH 1/2] ci: run the goldens inside the one workspace test build The golden step ran `cargo test -p eggshell-ui --features snapshots`, which resolves shared dependencies' features differently from the `--workspace` build before it. Cargo rebuilt 65 crates (libc up through wgpu, winit, egui) every run, about 3m50s of compiling for about 22s of tests, on a warm cache and a cold one alike (reproduced locally in a fresh target dir). `ci` now runs `cargo test --workspace --all-targets --features eggshell-ui/snapshots` once, on lavapipe, with the same stray-image guard around it (`snapshots::guarded`, shared with `cargo xtask snapshots`), and the separate snapshots step is gone. Every check still runs: the golden tests, the stray `.new.png`/`.diff.png` failure, clippy, tests, doctests, rustdoc, wasm. The restored cache was a full key match, so rust-cache never saved the new build; the workflow gives it a key to start a fresh one. Behavior changes: the golden tests run in the same process as the rest of the `it` binary, not alone; `cargo xtask ci` no longer has a "snapshots" step name. `cargo xtask snapshots` is unchanged. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01AJYxo4YJZUXcPJ1bHdAHKy --- .github/workflows/ci.yml | 5 ++++ xtask/src/snapshots.rs | 53 ++++++++++++++++++++++++++++++++-------- xtask/src/steps.rs | 19 ++++++++------ 3 files changed, 60 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ec32581..8acceda2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,11 @@ jobs: components: rustfmt, clippy targets: wasm32-unknown-unknown - uses: Swatinem/rust-cache@v2 + with: + # The test build carries the golden feature; bump this when the + # features it builds with change, or the old cache is restored whole + # and never saved again. + key: workspace-goldens - name: Mesa lavapipe for the golden images run: sudo apt-get update && sudo apt-get install -y mesa-vulkan-drivers - run: cargo xtask ci diff --git a/xtask/src/snapshots.rs b/xtask/src/snapshots.rs index 9ea61a5a..e0d1a38e 100644 --- a/xtask/src/snapshots.rs +++ b/xtask/src/snapshots.rs @@ -30,16 +30,20 @@ pub struct Plan { pub filter: Option, } -/// The golden check with no filter, as a `cargo xtask ci` step. -pub fn check_goldens() -> Result<()> { - run(&Plan { - mode: Mode::Check, - filter: None, - }) +/// The workspace's whole test run with the goldens in it, as `cargo xtask ci` +/// runs it. `-p eggshell-ui --features snapshots` resolves the shared +/// dependencies' features differently from `--workspace` and rebuilds sixty-odd +/// crates, so the goldens ride in the one workspace build instead. +pub fn test_with_goldens() -> Result<()> { + guarded(&golden_dir(), workspace_step) +} + +fn golden_dir() -> PathBuf { + process::workspace_root().join(GOLDEN_DIR) } pub fn run(plan: &Plan) -> Result<()> { - let golden_dir = process::workspace_root().join(GOLDEN_DIR); + let golden_dir = golden_dir(); match plan.mode { Mode::Clean => { let removed = clean(&golden_dir)?; @@ -52,10 +56,15 @@ pub fn run(plan: &Plan) -> Result<()> { } fn check(plan: &Plan, golden_dir: &Path) -> Result<()> { + guarded(golden_dir, |icd| renderer_step(plan, icd)) +} + +/// Runs the step `renderer` makes and fails on any stray image it leaves. +fn guarded(golden_dir: &Path, renderer: impl FnOnce(&Path) -> Step) -> Result<()> { let icd = lavapipe_icd()?; // Strays from an earlier failed run would otherwise read as mismatches now. clean(golden_dir)?; - let result = renderer_step(plan, &icd).run(); + let result = renderer(&icd).run(); let strays = strays(golden_dir)?; for stray in &strays { println!("mismatch: {}", stray.display()); @@ -106,8 +115,7 @@ fn renderer_step(plan: &Plan, icd: &Path) -> Step { "--nocapture", ], ) - .with_env("VK_ICD_FILENAMES", icd.display().to_string()) - .with_env("VK_DRIVER_FILES", icd.display().to_string()); + .on_lavapipe(icd); if plan.mode == Mode::Update { step = step.with_env("UPDATE_SNAPSHOTS", "1"); } @@ -115,6 +123,22 @@ fn renderer_step(plan: &Plan, icd: &Path) -> Step { step } +/// Every test of the workspace, the goldens among them, with the software +/// renderer selected for the child only. +fn workspace_step(icd: &Path) -> Step { + Step::cargo( + "test", + &[ + "test", + "--workspace", + "--all-targets", + "--features", + "eggshell-ui/snapshots", + ], + ) + .on_lavapipe(icd) +} + /// The libtest filter selecting the `snapshots` module of the `it` binary, /// narrowed to the golden whose name starts with `name`. fn snapshot_filter(name: Option<&str>) -> String { @@ -261,6 +285,15 @@ mod tests { ); } + #[test] + fn the_workspace_run_carries_the_goldens_and_selects_lavapipe() { + assert_eq!( + workspace_step(Path::new("/icd/lvp.json")).to_string(), + "VK_ICD_FILENAMES=\"/icd/lvp.json\" VK_DRIVER_FILES=\"/icd/lvp.json\" \ + cargo test --workspace --all-targets --features eggshell-ui/snapshots" + ); + } + #[test] fn update_sets_the_variable_for_the_child_and_filter_follows_the_separator() { let step = renderer_step( diff --git a/xtask/src/steps.rs b/xtask/src/steps.rs index bbb09d0f..b27fdd35 100644 --- a/xtask/src/steps.rs +++ b/xtask/src/steps.rs @@ -1,5 +1,5 @@ use std::fmt; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use anyhow::{Context, Result, bail}; @@ -53,6 +53,13 @@ impl Step { } } + /// Points Vulkan at the lavapipe driver whose manifest is `icd`. + pub fn on_lavapipe(self, icd: &Path) -> Self { + let icd = icd.display().to_string(); + self.with_env("VK_ICD_FILENAMES", icd.clone()) + .with_env("VK_DRIVER_FILES", icd) + } + pub fn with_env(mut self, key: &'static str, value: impl Into) -> Self { self.env.push((key, value.into())); self @@ -137,8 +144,8 @@ pub fn wasm() -> Step { pub const WASM_TARGET: &str = "wasm32-unknown-unknown"; -/// What CI runs, in order. The golden check needs Mesa lavapipe, locally and -/// on the runner alike. +/// What CI runs, in order. The test step carries the golden check, which needs +/// Mesa lavapipe, locally and on the runner alike. pub fn ci_steps() -> Vec { vec![ fmt(FmtMode::Check), @@ -154,12 +161,11 @@ pub fn ci_steps() -> Vec { "warnings", ], ), - Step::cargo("test", &["test", "--workspace", "--all-targets"]), + Step::internal("test", snapshots::test_with_goldens), Step::cargo("doctest", &["test", "--workspace", "--doc"]), Step::cargo("rustdoc", &["doc", "--workspace", "--no-deps"]) .with_env("RUSTDOCFLAGS", "-D warnings"), wasm(), - Step::internal("snapshots", snapshots::check_goldens), ] } @@ -220,11 +226,10 @@ mod tests { "cargo fmt --all --check", "built-in clock check", "cargo clippy --workspace --all-targets -- -D warnings", - "cargo test --workspace --all-targets", + "built-in test check", "cargo test --workspace --doc", "RUSTDOCFLAGS=\"-D warnings\" cargo doc --workspace --no-deps", "cargo check --target wasm32-unknown-unknown --workspace --exclude xtask --lib --examples", - "built-in snapshots check", ] ); } From 82a88fc68ad3deb42c79e394461440e5dfd7dd58 Mon Sep 17 00:00:00 2001 From: Samit Basu Date: Thu, 12 Nov 2026 12:18:02 -0800 Subject: [PATCH 2/2] ci: lint with the golden feature on Clippy ran without `eggshell-ui/snapshots`, so the golden tests' code (tests/it/snapshots.rs) was never linted, and its dependency check artifacts did not match the test build's feature resolution. It now takes the same features as the test step. The cache key moves with it, since the saved cache holds no check artifacts for the wgpu tree. Behavior change: clippy now also lints the snapshots-gated test code (`cargo xtask ci` is clean with it). Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01AJYxo4YJZUXcPJ1bHdAHKy --- .github/workflows/ci.yml | 2 +- xtask/src/steps.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8acceda2..91f1009f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: # The test build carries the golden feature; bump this when the # features it builds with change, or the old cache is restored whole # and never saved again. - key: workspace-goldens + key: workspace-goldens-clippy - name: Mesa lavapipe for the golden images run: sudo apt-get update && sudo apt-get install -y mesa-vulkan-drivers - run: cargo xtask ci diff --git a/xtask/src/steps.rs b/xtask/src/steps.rs index b27fdd35..454d1f88 100644 --- a/xtask/src/steps.rs +++ b/xtask/src/steps.rs @@ -156,6 +156,8 @@ pub fn ci_steps() -> Vec { "clippy", "--workspace", "--all-targets", + "--features", + "eggshell-ui/snapshots", "--", "-D", "warnings", @@ -225,7 +227,7 @@ mod tests { [ "cargo fmt --all --check", "built-in clock check", - "cargo clippy --workspace --all-targets -- -D warnings", + "cargo clippy --workspace --all-targets --features eggshell-ui/snapshots -- -D warnings", "built-in test check", "cargo test --workspace --doc", "RUSTDOCFLAGS=\"-D warnings\" cargo doc --workspace --no-deps",