From abbc73caf8b59b2389bc5d084b8cbacfc1fac6af Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 13:49:20 +1300 Subject: [PATCH] app/: an empty CI build on a commit its suite already compared follows that build, so reruns of failed jobs pass (sc-9044) --- .claude-plugin/marketplace.json | 2 +- .claude-plugin/plugin.json | 2 +- .cursor-plugin/plugin.json | 2 +- .../2026_12_06_000000_covered_builds.rs | 15 + app/src/domain/builds.rs | 3 +- app/src/domain/mod.rs | 1 + app/src/domain/processing.rs | 5 + app/src/domain/reruns.rs | 192 ++++++++++++ app/src/domain/reviews.rs | 4 + app/src/forge/checks.rs | 24 +- app/src/forge/pr_comment.rs | 2 +- app/src/listeners/mod.rs | 7 + app/src/models/builds.rs | 3 + app/tests/reruns.rs | 273 ++++++++++++++++++ frontend/content/docs/ci/circleci.md | 6 + frontend/content/docs/ci/github-actions.md | 4 + frontend/content/docs/ci/other.md | 2 + frontend/content/docs/reference/cli.md | 2 + gemini-extension.json | 2 +- skills/visualci-circleci/SKILL.md | 6 + skills/visualci-github-actions/SKILL.md | 4 + 21 files changed, 554 insertions(+), 7 deletions(-) create mode 100644 app/database/migrations/2026_12_06_000000_covered_builds.rs create mode 100644 app/src/domain/reruns.rs create mode 100644 app/tests/reruns.rs diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 33a9c495..81dc2053 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -5,7 +5,7 @@ "plugins": [ { "name": "visualci", - "version": "0.1.55", + "version": "0.1.56", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 485ee845..34e3d713 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.55", + "version": "0.1.56", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index 411a8753..838b09ee 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "visualci", "displayName": "VisualCI", - "version": "0.1.55", + "version": "0.1.56", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring" diff --git a/app/database/migrations/2026_12_06_000000_covered_builds.rs b/app/database/migrations/2026_12_06_000000_covered_builds.rs new file mode 100644 index 00000000..4e739b9d --- /dev/null +++ b/app/database/migrations/2026_12_06_000000_covered_builds.rs @@ -0,0 +1,15 @@ +//! A CI build finalized with no snapshots, on a commit an earlier build of its suite already compared (a rerun of only +//! the failed jobs: sc-9044), follows that build: `covered_by_build_id` names it, and the empty build shows its result. + +use laravel::db::AnyTransaction; + +pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { + tx.query( + "ALTER TABLE builds ADD COLUMN covered_by_build_id bigint REFERENCES builds(id) ON DELETE SET NULL; \ + CREATE INDEX builds_covered_by_idx ON builds USING btree (covered_by_build_id) \ + WHERE covered_by_build_id IS NOT NULL", + ) + .unprepared() + .await?; + Ok(()) +} diff --git a/app/src/domain/builds.rs b/app/src/domain/builds.rs index bf6a5081..fb622008 100644 --- a/app/src/domain/builds.rs +++ b/app/src/domain/builds.rs @@ -227,6 +227,7 @@ pub async fn create(project: &Project, params: &CreateParams, creator: Option laravel::Result let id = build.id; // The "visualci.yml" item is worked out again below. db::query!("DELETE FROM snapshots WHERE build_id = {id} AND platform = 'visualci'").delete().await?; + // A CI build sent nothing, on a commit an earlier build of its suite compared (a rerun of only the failed jobs): + // it shows that build's result rather than failing as empty. + if let Some(done) = Box::pin(super::reruns::follow(&build)).await? { + return Ok(done); + } let mut snapshots: Vec = Snapshot::query() .filter(Snapshot::build_id.eq(id)) .order_by(Snapshot::name.asc()) diff --git a/app/src/domain/reruns.rs b/app/src/domain/reruns.rs new file mode 100644 index 00000000..77904424 --- /dev/null +++ b/app/src/domain/reruns.rs @@ -0,0 +1,192 @@ +//! Reruns of only the failed jobs (sc-9044). CircleCI's "rerun from failed" starts a new workflow, and GitHub Actions' +//! "re-run failed jobs" a new run attempt, in which only the failed jobs run again. A CI that keys its builds on the +//! workflow or the attempt creates a new build for every suite, and a suite whose jobs passed the first time sends it +//! nothing. Such a build mustn't fail with "No snapshots were sent": an earlier build of its suite already compared this +//! commit. It follows that build instead (`covered_by_build_id`): it concludes with its conclusion and review state, its +//! check shows that build's result, and a later review of that build reaches it. +//! +//! A build follows only when it's a CI build that was sent no snapshots (`--allow-empty` or not), and an earlier CI build +//! of the same project, suite (`name`), environment, commit and branch has been finalized and wasn't itself empty. While +//! that build is still processing, the empty one waits, processing, and concludes when it does. + +use laravel::db; +use laravel::model::update; + +use super::builds::EMPTY_BUILD; +use crate::models::Build; + +/// The warning on a build that follows an earlier one. +#[must_use] +pub fn covered_warning(number: i32) -> String { + format!( + "No snapshots were sent in this run; build #{number} already covers this commit (a rerun of failed jobs?), so \ + this build shows its result." + ) +} + +/// How many snapshots the build was sent itself (not carried forward, not counted as removed, not the visualci.yml +/// item). +async fn sent(build_id: i64) -> laravel::Result { + let id = build_id; + Ok(db::query!( + "SELECT COUNT(*) FROM snapshots WHERE build_id = {id} AND NOT carried_forward AND state <> 'removed' \ + AND platform <> 'visualci'" + ) + .scalar() + .await? + .unwrap_or(0)) +} + +/// The earlier build this empty CI build would follow: the newest earlier CI build of the same project, suite, +/// environment, commit and branch that was finalized (processing or completed), wasn't empty itself, and follows no +/// build itself. The branch counts: the same commit on another branch compares with other baselines and has its own +/// review rules, so its result isn't this build's. +/// +/// # Errors +/// On a database error. +pub async fn covering(build: &Build) -> laravel::Result> { + if build.mode != "ci" { + return Ok(None); + } + let (id, project_id, name, environment, sha, branch) = ( + build.id, + build.project_id, + build.name.as_str(), + build.environment.as_str(), + build.commit_sha.as_str(), + build.branch.as_str(), + ); + let found: Vec = db::query!( + "SELECT * FROM builds WHERE project_id = {project_id} AND name = {name} AND environment = {environment} \ + AND commit_sha = {sha} AND branch = {branch} AND mode = 'ci' AND id < {id} \ + AND covered_by_build_id IS NULL AND state IN ('processing', 'completed') \ + AND error IS DISTINCT FROM {EMPTY_BUILD} \ + ORDER BY id DESC LIMIT 1" + ) + .select_as() + .await?; + Ok(found.into_iter().next()) +} + +/// Processing's first step for a CI build: when it was sent no snapshots and an earlier build covers its commit, it +/// follows that build. `None`: it doesn't, so it's processed as usual. `Some(false)`: the earlier build is still +/// processing, and this one waits for it. `Some(true)`: it concluded with the earlier build's result. +/// +/// # Errors +/// On a database error. +pub async fn follow(build: &Build) -> laravel::Result> { + if build.mode != "ci" { + return Ok(None); + } + let earlier = match build.covered_by_build_id { + Some(id) => Build::find(id).await?, + None if sent(build.id).await? == 0 => covering(build).await?, + None => None, + }; + let Some(earlier) = earlier else { return Ok(None) }; + if !matches!(earlier.state.as_str(), "completed" | "failed") { + if build.covered_by_build_id.is_none() { + let mut build = build.clone(); + let warnings = with_warning(&build, earlier.number); + update!(build { covered_by_build_id: Some(earlier.id), warnings }).await?; + } + return Ok(Some(false)); + } + mirror(build.id, &earlier).await?; + Ok(Some(true)) +} + +fn with_warning(build: &Build, number: i32) -> serde_json::Value { + let mut warnings: Vec = serde_json::from_value(build.warnings.clone()).unwrap_or_default(); + let warning = covered_warning(number); + if !warnings.contains(&warning) { + warnings.push(warning); + } + serde_json::json!(warnings) +} + +/// Give the build the earlier build's result: completed, with its conclusion, review state and superseding build (a +/// failed earlier build fails it). Under the build's advisory lock; only a build still processing, or one that already +/// follows `earlier`. Returns whether anything changed. +/// +/// # Errors +/// On a database error. +pub async fn mirror(build_id: i64, earlier: &Build) -> laravel::Result { + Box::pin(db::transaction(async |_| { + super::processing::lock(build_id).await?; + let mut build = Build::find_or_fail(build_id).await?; + let follows = build.state == "processing" || build.covered_by_build_id == Some(earlier.id); + if !follows || build.mode != "ci" { + return Ok(false); + } + let failed = earlier.state == "failed" || earlier.conclusion.as_deref() == Some("failed"); + let conclusion = if failed { Some("failed".to_string()) } else { earlier.conclusion.clone() }; + let review_state = if failed { "none".to_string() } else { earlier.review_state.clone() }; + let error = failed.then(|| match &earlier.error { + Some(e) => format!("Build #{} failed: {e}", earlier.number), + None => format!("Build #{} failed: see that build", earlier.number), + }); + let superseded_by_build_id = earlier.superseded_by_build_id; + let covered_by_build_id = Some(earlier.id); + let warnings = with_warning(&build, earlier.number); + let unchanged = build.state == "completed" + && build.conclusion == conclusion + && build.review_state == review_state + && build.error == error + && build.superseded_by_build_id == superseded_by_build_id + && build.covered_by_build_id == covered_by_build_id + && build.warnings == warnings; + if unchanged { + return Ok(false); + } + let completed_at = build.completed_at.or_else(|| Some(laravel::now().timestamp())); + update!(build { + state: "completed", + conclusion, + review_state, + error, + superseded_by_build_id, + covered_by_build_id, + warnings, + completed_at + }) + .await?; + Ok(true) + })) + .await +} + +/// A build changed (it concluded, was reviewed, superseded, closed or reopened): the builds that follow it take its +/// result, and their checks, comments and pages follow (`BuildChanged`). +/// +/// # Errors +/// On a database or queue error. +pub async fn update_followers(build_id: i64) -> laravel::Result { + let id = build_id; + let followers: Vec = + db::query!("SELECT id FROM builds WHERE covered_by_build_id = {id} ORDER BY id").select_as().await?; + if followers.is_empty() { + return Ok(0); + } + let Some(earlier) = Build::find(id).await? else { return Ok(0) }; + if !matches!(earlier.state.as_str(), "completed" | "failed") { + return Ok(0); + } + let mut changed = 0; + for follower in followers { + if mirror(follower, &earlier).await? { + changed += 1; + crate::events::BuildChanged { build_id: follower }.dispatch().await?; + } + } + Ok(changed) +} + +/// Why a build that follows another can't be reviewed itself. +#[must_use] +pub fn not_reviewable(number: i32) -> String { + format!( + "This build was sent no snapshots: it shows the result of build #{number}, which covers the same commit. Review \ + build #{number} instead." + ) +} diff --git a/app/src/domain/reviews.rs b/app/src/domain/reviews.rs index 71391576..2c804d77 100644 --- a/app/src/domain/reviews.rs +++ b/app/src/domain/reviews.rs @@ -124,6 +124,10 @@ pub async fn review( if build.state != "completed" { return Ok(Err("only completed builds can be reviewed".into())); } + if let Some(id) = build.covered_by_build_id { + let number = Build::find(id).await?.map(|b| b.number).unwrap_or_default(); + return Ok(Err(super::reruns::not_reviewable(number))); + } let verdict = match action { "approve" => "approved", "reject" => "rejected", diff --git a/app/src/forge/checks.rs b/app/src/forge/checks.rs index 456420df..f8961d83 100644 --- a/app/src/forge/checks.rs +++ b/app/src/forge/checks.rs @@ -65,11 +65,33 @@ pub fn check_state(build: &Build, project: &Project, superseded_by: Option) } } -/// The whole check for a CI build: its state, the counts, who reviewed it, what changed, and how to review it. +/// The whole check for a CI build: its state, the counts, who reviewed it, what changed, and how to review it. A build +/// that follows an earlier one (it was sent no snapshots in a rerun of only the failed jobs: `domain::reruns`) shows +/// that build's check, so the suite's newest check on the commit is that build's result, not "No snapshots were sent". /// /// # Errors /// On a database error. pub async fn check_for(build: &Build, project: &Project, org: &Organization) -> laravel::Result { + let earlier = match build.covered_by_build_id { + Some(id) => Build::find(id).await?, + None => None, + }; + let shown = earlier.as_ref().unwrap_or(build); + let mut check = Box::pin(own_check(shown, project, org)).await?; + if let Some(earlier) = &earlier { + check.title = format!("{} (build #{})", check.title, earlier.number).chars().take(120).collect(); + check.summary = format!( + "No snapshots were sent in build #{} (a rerun of failed jobs?). Build #{} already covers this commit, so \ + this check shows its result.\n\n{}", + build.number, earlier.number, check.summary + ); + } + check.name = check_name(&build.name); + check.head_sha.clone_from(&build.commit_sha); + Ok(check) +} + +async fn own_check(build: &Build, project: &Project, org: &Organization) -> laravel::Result { let superseded_by = match build.superseded_by_build_id { Some(id) => Build::find(id).await?.map(|b| b.number), None => None, diff --git a/app/src/forge/pr_comment.rs b/app/src/forge/pr_comment.rs index d1429937..88cfdfda 100644 --- a/app/src/forge/pr_comment.rs +++ b/app/src/forge/pr_comment.rs @@ -219,7 +219,7 @@ pub async fn suites(project: &Project, org: &Organization, pr_number: i32) -> la let project_id = project.id; let all: Vec = db::query!( "SELECT * FROM builds WHERE project_id = {project_id} AND pr_number = {pr_number} AND mode = 'ci' \ - ORDER BY id DESC" + AND covered_by_build_id IS NULL ORDER BY id DESC" ) .select_as() .await?; diff --git a/app/src/listeners/mod.rs b/app/src/listeners/mod.rs index 1b5dbe14..61c23b81 100644 --- a/app/src/listeners/mod.rs +++ b/app/src/listeners/mod.rs @@ -26,6 +26,13 @@ pub async fn tell_the_live_streams(event: Event) -> Ok(()) } +/// A build changed: the empty builds that follow it (reruns of only the failed jobs, `domain::reruns`) take its result. +#[listener] +pub async fn update_the_builds_that_follow_it(event: Event) -> laravel::Result<()> { + crate::domain::reruns::update_followers(event.build_id).await?; + Ok(()) +} + /// A default-branch CI build changed: Cloudflare's copies of the gallery URLs it touches are purged in the background, /// when purges are configured. #[listener] diff --git a/app/src/models/builds.rs b/app/src/models/builds.rs index 1ff79561..94d887c2 100644 --- a/app/src/models/builds.rs +++ b/app/src/models/builds.rs @@ -58,4 +58,7 @@ pub struct Build { pub group_depth: Option, pub manifest_same_as_build_id: Option, pub empty_reason: Option, + /// The earlier build of the same suite and commit whose result this one shows: it was finalized with no + /// snapshots (a rerun of only the failed jobs), see `domain::reruns`. + pub covered_by_build_id: Option, } diff --git a/app/tests/reruns.rs b/app/tests/reruns.rs new file mode 100644 index 00000000..343dff69 --- /dev/null +++ b/app/tests/reruns.rs @@ -0,0 +1,273 @@ +//! Reruns of only the failed jobs (sc-9044): a CI build of a suite that was sent no snapshots, on a commit an earlier +//! build of that suite already compared, shows that build's result instead of failing as empty. + +use app::domain::builds::EMPTY_BUILD; +use app::domain::reruns::covered_warning; +use app::models::{Build, Organization, Project}; +use app::testing::fixtures; +use laravel::db; +use laravel::testing::prelude::*; +use serde_json::{Value, json}; + +async fn project_token() -> laravel::Result { + let org = fixtures::organization(&format!("org-{}", &laravel::str::uuid7().simple().to_string()[24..])).await?; + let project = fixtures::project(&org, "web").await?; + let token = format!("vci_{}", laravel::str::uuid7().simple()); + let (hash, project_id) = (app::models::token_hash(&token), project.id); + db::query!( + "INSERT INTO project_tokens (project_id, name, token_hash, token_prefix, created_at, updated_at) \ + VALUES ({project_id}, 'CI', {hash}, 'vci_ab', now(), now())" + ) + .insert() + .await?; + Ok(token) +} + +fn png(rgb: [u8; 3]) -> Vec { + let image = image::RgbaImage::from_pixel(16, 16, image::Rgba([rgb[0], rgb[1], rgb[2], 255])); + let mut bytes = Vec::new(); + image.write_to(&mut std::io::Cursor::new(&mut bytes), image::ImageFormat::Png).expect("a PNG encodes"); + bytes +} + +/// Which CI run a build comes from: its suite, commit, branch and nonce (the workflow). +struct Run<'a> { + name: &'a str, + commit: &'a str, + branch: &'a str, + nonce: &'a str, +} + +/// Create the run's build and send it these screenshots (uploading new files), without finalizing it. Returns its id. +async fn send(app: &Application, token: &str, run: &Run<'_>, shots: &[(&str, [u8; 3])]) -> String { + let auth = format!("Bearer {token}"); + let build = app + .post("/api/v1/builds") + .header("authorization", &auth) + .json(json!({ + "commit": run.commit, "branch": run.branch, "parent_commits": ["c0"], "name": run.name, "nonce": run.nonce + })) + .await; + build.assert_ok(); + let id = build.json()["id"].as_str().unwrap().to_string(); + if shots.is_empty() { + return id; + } + let mut files = Vec::new(); + let mut snapshots = Vec::new(); + for (name, rgb) in shots { + let bytes = png(*rgb); + let sha = visualci_core::sha256_hex(&bytes); + let image = image::load_from_memory(&bytes).unwrap().to_rgba8(); + snapshots.push(json!({ + "name": name, "kind": "image", "fingerprint": visualci_core::image_hash::fingerprint_rgba(&image), + "sha256": sha, "size": bytes.len(), "content_type": "image/png" + })); + files.push(bytes); + } + let registered = app + .post(format!("/api/v1/builds/{id}/snapshots")) + .header("authorization", &auth) + .json(json!({ "snapshots": snapshots })) + .await; + registered.assert_ok(); + let client = reqwest::Client::new(); + for (answer, bytes) in registered.json()["snapshots"].as_array().unwrap().iter().zip(files) { + if let Some(url) = answer["upload_url"].as_str() { + let put = client.put(url).header("content-type", "image/png").body(bytes).send().await.expect("an upload"); + assert!(put.status().is_success(), "uploading: {}", put.status()); + } + } + id +} + +async fn finalize(app: &Application, token: &str, id: &str, allow_empty: bool) -> Value { + let done = app + .post(format!("/api/v1/builds/{id}/finalize")) + .header("authorization", format!("Bearer {token}")) + .json(json!({ "allow_empty": allow_empty })) + .await; + done.assert_ok(); + done.json().clone() +} + +async fn run(app: &Application, token: &str, run: &Run<'_>, shots: &[(&str, [u8; 3])]) -> Value { + let id = send(app, token, run, shots).await; + finalize(app, token, &id, false).await +} + +/// The build as the API answers it now. +async fn fetch(app: &Application, token: &str, id: &Value) -> Value { + let id = id.as_str().unwrap(); + let got = app.get(format!("/api/v1/builds/{id}")).header("authorization", format!("Bearer {token}")).await; + got.assert_ok(); + got.json().clone() +} + +async fn build(number: i64) -> laravel::Result { + let number = i32::try_from(number).unwrap(); + Ok(Build::query().filter(Build::number.eq(number)).first().await?.expect("the build")) +} + +/// The build's check: status, conclusion, title. +async fn check(number: i64) -> laravel::Result<(String, Option, String)> { + let build = build(number).await?; + let project = Project::find_or_fail(build.project_id).await?; + let org = Organization::find_or_fail(project.organization_id).await?; + let check = app::forge::checks::check_for(&build, &project, &org).await?; + assert_eq!(check.name, app::forge::checks::check_name(&build.name)); + Ok((check.status, check.conclusion, check.title)) +} + +fn warnings(build: &Value) -> Vec { + serde_json::from_value(build["warnings"].clone()).unwrap_or_default() +} + +const RED: [u8; 3] = [255, 0, 0]; + +#[laravel::test] +async fn an_empty_rerun_shows_the_result_of_the_build_that_covers_its_commit(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + let pdf = |nonce| Run { name: "pdf", commit: "c1", branch: "main", nonce }; + + // #1: the first workflow's pdf suite (the default branch's first build: approved on its own). + let first = run(&app, &token, &pdf("workflow-1-pdf"), &[("invoice.png", RED)]).await; + assert_eq!(first["state"], "completed", "{first}"); + assert_eq!(first["passed"], true, "{first}"); + + // #2: the rerun of the failed jobs sends the pdf suite nothing. + let rerun = run(&app, &token, &pdf("workflow-2-pdf"), &[]).await; + assert_eq!(rerun["number"], 2); + assert_eq!( + (&rerun["state"], &rerun["conclusion"], &rerun["review_state"], &rerun["passed"], &rerun["error"]), + (&first["state"], &first["conclusion"], &first["review_state"], &json!(true), &Value::Null), + "{rerun}" + ); + assert!(warnings(&rerun).contains(&covered_warning(1)), "{rerun}"); + assert_eq!(build(2).await?.covered_by_build_id, Some(build(1).await?.id)); + // No snapshot rows of its own: nothing counts as removed. + assert!(app::domain::snapshots::of_build(build(2).await?.id).await?.is_empty()); + + let (status, conclusion, title) = check(2).await?; + assert_eq!((status.as_str(), conclusion.as_deref()), ("completed", Some("success")), "{title}"); + assert!(title.ends_with("(build #1)"), "{title}"); + assert_eq!(check(1).await?.1, conclusion); + + // A second rerun follows #1 too, not #2. + let again = run(&app, &token, &pdf("workflow-3-pdf"), &[]).await; + assert_eq!(again["passed"], true, "{again}"); + assert!(warnings(&again).contains(&covered_warning(1)), "{again}"); + + // --allow-empty doesn't change it: the earlier build's result is the better answer for this commit. + let id = send(&app, &token, &pdf("workflow-4-pdf"), &[]).await; + let allowed = finalize(&app, &token, &id, true).await; + assert!(warnings(&allowed).contains(&covered_warning(1)), "{allowed}"); + assert_eq!(allowed["conclusion"], first["conclusion"], "{allowed}"); + Ok(()) +} + +#[laravel::test] +async fn an_empty_rerun_waits_for_the_review_of_the_build_that_covers_it(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + let pdf = |nonce| Run { name: "pdf", commit: "f1", branch: "feature", nonce }; + + // #1: a feature branch's build adds a screenshot, which waits for review. + let first = run(&app, &token, &pdf("workflow-1-pdf"), &[("invoice.png", RED)]).await; + assert_eq!((&first["conclusion"], &first["review_state"]), (&json!("changes"), &json!("pending")), "{first}"); + + // #2: the rerun's empty build waits for that review too. + let rerun = run(&app, &token, &pdf("workflow-2-pdf"), &[]).await; + assert_eq!( + (&rerun["state"], &rerun["conclusion"], &rerun["review_state"], &rerun["passed"]), + (&json!("completed"), &json!("changes"), &json!("pending"), &first["passed"]), + "{rerun}" + ); + let (status, conclusion, title) = check(2).await?; + assert_eq!((status.as_str(), conclusion), ("in_progress", None), "{title}"); + assert!(title.starts_with("1 changes waiting for review"), "{title}"); + + // It can't be reviewed itself: the review belongs to #1. + let via = app::domain::reviews::Via::default(); + let refused = app::domain::reviews::review(build(2).await?, None, &via, "approve", None, None).await?; + assert!(refused.as_ref().is_err_and(|e| e.contains("Review build #1 instead")), "{refused:?}"); + + // Approving #1 approves #2 as well, and #2's check passes. + let approved = app::domain::reviews::review(build(1).await?, None, &via, "approve", None, None).await?; + let approved = approved.expect("#1 is approved"); + app::events::BuildChanged { build_id: approved.id }.dispatch().await?; + let rerun = fetch(&app, &token, &rerun["id"]).await; + assert_eq!((&rerun["review_state"], &rerun["passed"]), (&json!("approved"), &json!(true)), "{rerun}"); + let (status, conclusion, title) = check(2).await?; + assert_eq!((status.as_str(), conclusion.as_deref()), ("completed", Some("success")), "{title}"); + Ok(()) +} + +#[laravel::test] +async fn an_empty_rerun_of_a_build_still_processing_concludes_when_it_does(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + let pdf = |nonce| Run { name: "pdf", commit: "c1", branch: "main", nonce }; + + // #1 is finalized, and its processing hasn't run yet. + let first = send(&app, &token, &pdf("workflow-1-pdf"), &[("invoice.png", RED)]).await; + let first_id = build(1).await?.id; + db::query!("UPDATE builds SET state = 'processing', finalized_at = now() WHERE id = {first_id}").update().await?; + + // #2 waits for it, processing. + let rerun = run(&app, &token, &pdf("workflow-2-pdf"), &[]).await; + assert_eq!(rerun["state"], "processing", "{rerun}"); + assert!(warnings(&rerun).contains(&covered_warning(1)), "{rerun}"); + let (status, _, title) = check(2).await?; + assert_eq!(status, "in_progress", "{title}"); + + // #1 concludes, and #2 with it. + let store = app::storage::BlobStore::current().await?; + app::domain::processing::run(first_id, &store, &app::http::api::builds::renderer_version()).await?; + let first = fetch(&app, &token, &json!(first)).await; + assert_eq!(first["state"], "completed", "{first}"); + let rerun = fetch(&app, &token, &rerun["id"]).await; + assert_eq!( + (&rerun["state"], &rerun["conclusion"], &rerun["passed"]), + (&json!("completed"), &first["conclusion"], &json!(true)), + "{rerun}" + ); + Ok(()) +} + +#[laravel::test] +async fn an_empty_build_with_no_earlier_build_of_its_suite_and_commit_still_fails( + app: Application, +) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + let run_of = |name, commit, branch, nonce| Run { name, commit, branch, nonce }; + + // #1: the pdf suite on c1, on main. + let first = run(&app, &token, &run_of("pdf", "c1", "main", "w1-pdf"), &[("invoice.png", RED)]).await; + assert_eq!(first["passed"], true, "{first}"); + + // Nothing earlier at all, another suite, another commit, another branch: each fails as empty. + for (number, name, commit, branch) in + [(2, "browser", "c1", "main"), (3, "pdf", "c2", "main"), (4, "pdf", "c1", "feature")] + { + let nonce = format!("w{number}"); + let empty = run(&app, &token, &Run { name, commit, branch, nonce: &nonce }, &[]).await; + assert_eq!(empty["number"], number); + assert_eq!( + (&empty["state"], &empty["conclusion"], &empty["passed"], &empty["error"]), + (&json!("completed"), &json!("failed"), &json!(false), &json!(EMPTY_BUILD)), + "{name} {commit} {branch}: {empty}" + ); + assert_eq!(build(number).await?.covered_by_build_id, None); + let (status, conclusion, title) = check(number).await?; + assert_eq!((status.as_str(), conclusion.as_deref()), ("completed", Some("failure")), "{title}"); + assert!(title.starts_with("No snapshots were sent"), "{title}"); + } + + // An empty build never covers a later one: #5 (pdf on c2) fails too, rather than following #3. + let empty = run(&app, &token, &run_of("pdf", "c2", "main", "w5"), &[]).await; + assert_eq!(empty["error"], json!(EMPTY_BUILD), "{empty}"); + Ok(()) +} diff --git a/frontend/content/docs/ci/circleci.md b/frontend/content/docs/ci/circleci.md index 86c9a453..17c84e7a 100644 --- a/frontend/content/docs/ci/circleci.md +++ b/frontend/content/docs/ci/circleci.md @@ -47,6 +47,12 @@ If some containers can be skipped (for example, tests split by changed files), a When a pipeline skips every job that sends a build's snapshots (a cached job whose inputs didn't change, or a docs-only push), the job that finalizes it still runs, and a build that was sent nothing fails. Finalize that build with `--allow-empty` instead: its snapshots are carried forward from the nearest ancestor, its check passes, and the check and the build's page read "No snapshots this run: baseline from #N". Only do this for jobs the pipeline really skipped: a job that ran and sent nothing should still fail. +## Rerunning failed jobs + +"Rerun workflow from failed" starts a new workflow with a new `$CIRCLE_WORKFLOW_ID`, and only the failed jobs run in it. A suite whose jobs passed the first time gets a new build that is sent nothing. That build doesn't fail: VisualCI sees that an earlier build of the same suite (the same `--name`) already compared this commit on this branch, and gives the new build that build's result. Its check shows the earlier build's result, and a review of the earlier build reaches it too. The new build has a warning naming the earlier build. If the earlier build is still being compared, the new one waits for it. You don't need to change anything for reruns, and you don't need `--allow-empty` for them. + +A suite with no earlier build of the commit still fails when it's sent nothing. + Snapshot names must be unique across the build's jobs and containers. Sending the same file under a name again is fine (a job that's run again does it), but two containers sending different content under one name is refused with a 409 that names the snapshot: give each test's snapshot a name of its own. ## Orb diff --git a/frontend/content/docs/ci/github-actions.md b/frontend/content/docs/ci/github-actions.md index f7b5ddad..cdf0f8d7 100644 --- a/frontend/content/docs/ci/github-actions.md +++ b/frontend/content/docs/ci/github-actions.md @@ -242,6 +242,10 @@ visualci build finalize --shard "$SHARD_INDEX" # 0 to 3 See [Other CI providers](/docs/ci/other/#parallel-jobs). +### Re-running failed jobs + +"Re-run failed jobs" starts a new attempt (`$GITHUB_RUN_ATTEMPT`), and only the failed jobs run in it. A suite whose jobs passed the first time gets a new build that is sent nothing. That build doesn't fail: VisualCI sees that an earlier build of the same suite (the same `--name`) already compared this commit on this branch, and gives the new build that build's result. Its check shows the earlier build's result, and a review of the earlier build reaches it too. The new build has a warning naming the earlier build. If the earlier build is still being compared, the new one waits for it. Re-runs need no changes to the workflow. + ### Forks and missing secrets Pull requests from forks don't get the repository's secrets, so `VISUALCI_TOKEN` is empty there. Decide at the job level, not in a step: a step's `if` can't read the `env` that same step sets, so `if: env.VISUALCI_TOKEN != ''` on a step that sets it never sees the token. Either set `env` on the job and test it in each VisualCI step, or skip the steps for forks: diff --git a/frontend/content/docs/ci/other.md b/frontend/content/docs/ci/other.md index 1f40d443..c1f211f8 100644 --- a/frontend/content/docs/ci/other.md +++ b/frontend/content/docs/ci/other.md @@ -52,6 +52,8 @@ Parallel jobs can share one build: Add `--subset` when some jobs may not run. Snapshots that weren't sent are then carried forward instead of counted as removed. +A rerun of only the failed jobs, under a new nonce, can leave a suite whose jobs passed with a new build that is sent nothing. When an earlier build of the same suite already compared the commit on the same branch, the empty build gets that build's result (and follows its review) rather than failing. Its warning names the earlier build. + ## Several suites in one project Use one VisualCI project per repository, and give each test suite a build name: `visualci build create --name pdf`, `--name browser`, `--name jest`. Each name keeps its own builds and baselines, and gets its own GitHub check, named `VisualCI: pdf` and so on (`VisualCI` for builds without a name). Branch protection can require each check by name. diff --git a/frontend/content/docs/reference/cli.md b/frontend/content/docs/reference/cli.md index ac547b75..d61a7b23 100644 --- a/frontend/content/docs/reference/cli.md +++ b/frontend/content/docs/reference/cli.md @@ -77,6 +77,8 @@ Finishes the build, or one shard of it with `--shard ` (numbered from 0). Vis A build that was sent no snapshots fails, with an error that says so, so an upload that found nothing never passes as "unchanged". Pass `--allow-empty` when a build is empty on purpose, such as a CI run that skipped the tests. +The exception is a rerun of only the failed jobs. A CI build that was sent nothing, when an earlier CI build of the same suite (`--name`) already compared the commit on the same branch, gets that build's result, with or without `--allow-empty`. Its check shows that build's result and follows its review, and the build has a warning naming it. + With `--wait`, it waits for the result (up to `--timeout` seconds, default 900), prints what changed and exits 0 when CI should pass, 1 when it should fail, or 3 when it timed out. A build that can't be compared because the organization is out of credits exits 4, with a line saying what fixes it. Under the project's default `review` mode, a build with changes passes. ## visualci build status diff --git a/gemini-extension.json b/gemini-extension.json index f7255ffb..92ca0765 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.55", + "version": "0.1.56", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "mcpServers": { "visualci": { diff --git a/skills/visualci-circleci/SKILL.md b/skills/visualci-circleci/SKILL.md index 1cdf178d..8bc78cdd 100644 --- a/skills/visualci-circleci/SKILL.md +++ b/skills/visualci-circleci/SKILL.md @@ -52,6 +52,12 @@ If some containers can be skipped (for example, tests split by changed files), a When a pipeline skips every job that sends a build's snapshots (a cached job whose inputs didn't change, or a docs-only push), the job that finalizes it still runs, and a build that was sent nothing fails. Finalize that build with `--allow-empty` instead: its snapshots are carried forward from the nearest ancestor, its check passes, and the check and the build's page read "No snapshots this run: baseline from #N". Only do this for jobs the pipeline really skipped: a job that ran and sent nothing should still fail. +## Rerunning failed jobs + +"Rerun workflow from failed" starts a new workflow with a new `$CIRCLE_WORKFLOW_ID`, and only the failed jobs run in it. A suite whose jobs passed the first time gets a new build that is sent nothing. That build doesn't fail: VisualCI sees that an earlier build of the same suite (the same `--name`) already compared this commit on this branch, and gives the new build that build's result. Its check shows the earlier build's result, and a review of the earlier build reaches it too. The new build has a warning naming the earlier build. If the earlier build is still being compared, the new one waits for it. You don't need to change anything for reruns, and you don't need `--allow-empty` for them. + +A suite with no earlier build of the commit still fails when it's sent nothing. + Snapshot names must be unique across the build's jobs and containers. Sending the same file under a name again is fine (a job that's run again does it), but two containers sending different content under one name is refused with a 409 that names the snapshot: give each test's snapshot a name of its own. ## Orb diff --git a/skills/visualci-github-actions/SKILL.md b/skills/visualci-github-actions/SKILL.md index d3e7cb14..9db823a2 100644 --- a/skills/visualci-github-actions/SKILL.md +++ b/skills/visualci-github-actions/SKILL.md @@ -247,6 +247,10 @@ visualci build finalize --shard "$SHARD_INDEX" # 0 to 3 See [Other CI providers](https://visualci.com/docs/ci/other.md#parallel-jobs). +### Re-running failed jobs + +"Re-run failed jobs" starts a new attempt (`$GITHUB_RUN_ATTEMPT`), and only the failed jobs run in it. A suite whose jobs passed the first time gets a new build that is sent nothing. That build doesn't fail: VisualCI sees that an earlier build of the same suite (the same `--name`) already compared this commit on this branch, and gives the new build that build's result. Its check shows the earlier build's result, and a review of the earlier build reaches it too. The new build has a warning naming the earlier build. If the earlier build is still being compared, the new one waits for it. Re-runs need no changes to the workflow. + ### Forks and missing secrets Pull requests from forks don't get the repository's secrets, so `VISUALCI_TOKEN` is empty there. Decide at the job level, not in a step: a step's `if` can't read the `env` that same step sets, so `if: env.VISUALCI_TOKEN != ''` on a step that sets it never sees the token. Either set `env` on the job and test it in each VisualCI step, or skip the steps for forks: