From 54a88289d57b43b6ee32e437bd44e187295ca1ac Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 08:14:45 +0000 Subject: [PATCH 1/6] Skipped builds don't pass behind the branch's unapproved build (sc-9763); plugin 0.1.72 A CI subset build finished empty on purpose (allow_empty or empty_reason, no snapshots sent, no matched groups) follows the branch's newest earlier finalized build of its suite and environment, whatever its commit (default branch included), when that build isn't settled-good: processing or pending waits and turns green on approval, rejected stays rejected, failed fails (as reruns::mirror does). Approved, auto-approved, unchanged, superseded and closed keep today's baseline carry. Same-commit covering/adopt keep priority; accidental empty builds still fail. A partial subset build carries, per skipped key, the branch's previous build's unapproved changed/added row instead of the baseline (reruns::unreviewed_carry), compared with the baseline and reviewed here; a rejected row keeps its rejection. carry_forward takes a source and an optional base (same shape as PR #279). --- .claude-plugin/marketplace.json | 2 +- app/src/domain/processing.rs | 63 +++- app/src/domain/reruns.rs | 174 ++++++++- app/src/forge/checks.rs | 20 +- app/tests/reruns.rs | 344 +++++++++++++++++- frontend/content/changelog.md | 1 + frontend/content/docs/ci/circleci.md | 2 + frontend/content/docs/ci/github-actions.md | 6 + frontend/content/docs/ci/other.md | 2 +- frontend/content/docs/reference/api.md | 2 +- gemini-extension.json | 2 +- plugin/.claude-plugin/plugin.json | 2 +- plugin/.cursor-plugin/plugin.json | 2 +- plugin/skills/visualci-circleci/SKILL.md | 2 + .../skills/visualci-github-actions/SKILL.md | 6 + 15 files changed, 582 insertions(+), 48 deletions(-) diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 79e58beb..5d76f1fd 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -8,7 +8,7 @@ "plugins": [ { "name": "visualci", - "version": "0.1.71", + "version": "0.1.72", "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/src/domain/processing.rs b/app/src/domain/processing.rs index 64f001bb..8990fba1 100644 --- a/app/src/domain/processing.rs +++ b/app/src/domain/processing.rs @@ -688,11 +688,22 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> removed.push(key.clone()); } } + // A subset build's skipped snapshots that the branch's previous build changed or added without an approval carry + // that version, compared with the baseline, rather than the baseline itself: it still needs a review (sc-9763). + let unreviewed = super::reruns::unreviewed_carry(&build, &seen, &carry).await?; + let from_branch = unreviewed.as_ref().map(|u| &u.rows); + for key in from_branch.into_iter().flat_map(HashMap::keys) { + if !base_snapshots.contains_key(key) { + carried.entry(grouping.key(&key.0)).or_default().push(key.clone()); + } + } + let branch_groups: HashSet = + from_branch.into_iter().flat_map(HashMap::keys).map(|k| grouping.key(&k.0)).collect(); // A carried group the build sent nothing of, whose baselines one earlier build holds exactly, is read from that // build: no rows are written for it (docs/design-storage.md). let mut candidates = BTreeMap::new(); for (group, keys) in &carried { - if sent_keys.contains(group) || build.mode != "ci" { + if sent_keys.contains(group) || build.mode != "ci" || branch_groups.contains(group) { continue; } let bases: Vec<&Snapshot> = keys.iter().filter_map(|k| base_snapshots.get(k)).collect(); @@ -712,10 +723,14 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> continue; } for key in keys { - let Some(base) = base_snapshots.get(key) else { continue }; - Box::pin(carry_forward(&build, &settings, store, base)).await?; + let base = base_snapshots.get(key); + let Some(source) = from_branch.and_then(|rows| rows.get(key)).or(base) else { continue }; + Box::pin(carry_forward(&build, &settings, store, source, base)).await?; } } + if let Some(unreviewed) = &unreviewed { + super::reruns::keep_rejections(id, unreviewed).await?; + } for (name, platform) in &removed { let Some(base) = base_snapshots.get(&(name.clone(), platform.clone())) else { continue }; let pid = laravel::str::uuid7(); @@ -737,6 +752,9 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> // The file's settings: a loosening ci_mode it can't use, ignore rules that matched nothing, and whether they hide // more than the base build's (then the build gets a "visualci.yml" item to review). let mut warnings = settings.config_warnings(); + if let Some(u) = &unreviewed { + warnings.push(super::reruns::unreviewed_carry_warning(u.rows.len(), u.number)); + } let names: Vec = super::snapshots::of_build(id).await?.into_iter().map(|s| s.name).collect(); if settings.scoped_rules().0 == Source::File { for rule in settings.unmatched_rules(names.iter().map(String::as_str)) { @@ -840,29 +858,31 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> concluded } -/// Carry a base snapshot forward into a build as its own row, compared with the base (unchanged). +/// Carry a snapshot the build didn't send into it as its own row, compared with its base: the base itself (unchanged), +/// or the branch's previous build's unapproved version of it (changed, or added when there's no base). async fn carry_forward( build: &Build, settings: &BuildSettings<'_>, store: &BlobStore, - base: &Snapshot, + source: &Snapshot, + base: Option<&Snapshot>, ) -> laravel::Result<()> { let (id, pid) = (build.id, laravel::str::uuid7()); - let group_key = groups::grouping(build.group_depth).key(&base.name); + let group_key = groups::grouping(build.group_depth).key(&source.name); let (name, platform, kind, format, fingerprint, blob, render_id, engine, rules, environment, threshold, aa, meta) = ( - &base.name, - &base.platform, - &base.kind, - &base.format, - &base.source_fingerprint, - &base.source_blob, - base.render_id, - &base.engine, - &base.ignore_rules, - &base.environment, - base.threshold, - base.ignore_anti_aliasing, - &base.meta, + &source.name, + &source.platform, + &source.kind, + &source.format, + &source.source_fingerprint, + &source.source_blob, + source.render_id, + &source.engine, + &source.ignore_rules, + &source.environment, + source.threshold, + source.ignore_anti_aliasing, + &source.meta, ); // A second run of this processing (the job retried after a run that stopped part-way) finds the row there // already: it compares it again only when that run stopped before comparing it. @@ -884,7 +904,7 @@ async fn carry_forward( if inserted == 0 && !(carried.carried_forward && carried.state == "pending") { return Ok(()); } - if let Err(e) = compare(&mut carried, store, settings, Some(base)).await { + if let Err(e) = compare(&mut carried, store, settings, base).await { tracing::warn!(build = id, snapshot = carried.id, error = %e, "carrying a snapshot forward failed"); mark_failed(&mut carried, &format!("comparison failed: {e}")).await?; } @@ -938,8 +958,11 @@ async fn conclude( // the default branch only when its pull request merges (`baselines::record_merge`). A local run's changes always // wait for review: approving one sets the baseline for its branch and environment. let first_on_default = build.mode == "ci" && !has_base && build.branch == default_branch; + // A carried change the branch's previous build had rejected keeps its rejection (`reruns::keep_rejections`). + let rejected = all.iter().any(|s| s.carried_forward && is_change(s) && s.review.as_deref() == Some("rejected")); let review_state = match conclusion { "failed" => "none", + _ if rejected => "rejected", "unchanged" => "auto_approved", _ if first_on_default => "auto_approved", _ => "pending", diff --git a/app/src/domain/reruns.rs b/app/src/domain/reruns.rs index dde6c236..05bf2a79 100644 --- a/app/src/domain/reruns.rs +++ b/app/src/domain/reruns.rs @@ -23,13 +23,28 @@ //! and errors), the same visualci.yml, the same base branch and the same subset and shards, one build with a pull //! request and the other without, within the hour, with no settings change or other approval in between //! ([`twin`]). Anything else, and it's compared as usual. +//! +//! A CI build that skipped work on purpose mustn't pass on a baseline that leaves out its branch's unreviewed changes +//! (sc-9763). A CI that skips a suite's jobs when their inputs match a run that passed finishes that suite's subset +//! build empty on purpose (`--allow-empty`, or an `empty_reason`), and such a build would carry the approved baseline +//! forward and pass. When no build of its commit covers it (above), it follows the branch's newest earlier build of +//! the suite and environment, whatever its commit, if that build's result isn't settled-good ([`behind`]): still +//! processing, waiting for review, rejected or failed. It waits, is rejected or fails with it, and turns green when +//! that build is approved. A subset build that sent some groups and skipped others carries, for each skipped snapshot +//! the branch's previous build changed or added without an approval, that build's version instead of the baseline +//! ([`unreviewed_carry`]): it's compared with the baseline and waits for a review here, and a rejected one stays +//! rejected. + +use std::collections::{HashMap, HashSet}; use laravel::db; use laravel::model::update; use super::builds::EMPTY_BUILD; +use super::groups::Carry; use super::processing; -use crate::models::Build; +use super::snapshots::is_config_item; +use crate::models::{Build, Snapshot}; /// The warning on a build that was sent no snapshots and follows an earlier one. #[must_use] @@ -40,6 +55,29 @@ pub fn covered_warning(number: i32) -> String { ) } +/// The warning on a build that was finished empty on purpose and follows the branch's earlier build of its suite, +/// whose changes aren't approved. +#[must_use] +pub fn behind_warning(number: i32) -> String { + format!( + "No snapshots were sent in this run on purpose (its inputs unchanged?), but build #{number}, this branch's \ + last build of the suite, isn't approved (waiting for review, rejected or failed), so this build shows its \ + result rather than passing on the old baseline. Review build #{number}, or send this suite's snapshots again." + ) +} + +/// The warning on a subset build that carries the branch's previous build's unapproved changes for the snapshots it +/// didn't send. +#[must_use] +pub fn unreviewed_carry_warning(count: usize, number: i32) -> String { + let (snapshots, were) = if count == 1 { ("snapshot", "was") } else { ("snapshots", "were") }; + format!( + "{count} {snapshots} this run didn't send {were} changed in build #{number}, this branch's last build of the \ + suite, and not approved, so this build carries that version and compares it with the baseline: review it \ + here (a rejected change stays rejected)." + ) +} + /// How long nothing must have arrived for an unfinished earlier build before an empty rerun finalizes it. pub const ADOPT_AFTER_MINUTES: i32 = 5; @@ -159,6 +197,109 @@ fn run_ended_pattern() -> String { format!("{start} %") } +/// The branch's newest earlier CI build of the build's project, suite and environment that was finalized (processing, +/// completed or failed), whatever its commit; the build it follows, when it follows one. +async fn previous_on_branch(build: &Build, states: &[&str]) -> laravel::Result> { + let (id, project_id, name, environment, branch) = + (build.id, build.project_id, build.name.as_str(), build.environment.as_str(), build.branch.as_str()); + let states: Vec = states.iter().map(ToString::to_string).collect(); + let found: Option = db::query!( + "SELECT * FROM builds WHERE project_id = {project_id} AND name = {name} AND environment = {environment} \ + AND branch = {branch} AND mode = 'ci' AND id < {id} AND state IN ({...states}) \ + ORDER BY id DESC LIMIT 1" + ) + .select_one_as() + .await?; + match found { + Some(Build { covered_by_build_id: Some(root), .. }) => Build::find(root).await, + other => Ok(other), + } +} + +/// The earlier build a CI build finished empty on purpose follows, when no build of its commit covers it: a subset +/// build with `allow_empty` (or an `empty_reason`) that was sent no snapshots and matched no groups (a matched group's +/// contents are its baseline's, so carrying the baseline is right). It follows the branch's newest earlier finalized +/// build of the suite and environment ([`previous_on_branch`], whatever its commit, the default branch's included), +/// unless that build's result is settled-good: completed and unchanged, approved or auto-approved, or superseded or +/// closed (a later review covered its changes, or its pull request was closed). Anything else (still processing, +/// waiting for review, rejected or failed) and carrying the approved baseline forward would pass a change nobody +/// approved. +/// +/// # Errors +/// On a database error. +pub async fn behind(build: &Build) -> laravel::Result> { + if build.mode != "ci" || !build.subset || !build.allow_empty || build.covered_by_build_id.is_some() { + return Ok(None); + } + if !matches!(super::groups::carry(build).await?, Carry::Nothing) || sent(build.id).await? > 0 { + return Ok(None); + } + let Some(earlier) = previous_on_branch(build, &["processing", "completed", "failed"]).await? else { + return Ok(None); + }; + let unsettled = match earlier.state.as_str() { + "completed" => { + earlier.conclusion.as_deref() == Some("failed") + || matches!(earlier.review_state.as_str(), "pending" | "rejected") + } + _ => true, + }; + Ok(unsettled.then_some(earlier)) +} + +/// What a CI subset build carries instead of the baseline for the snapshots it didn't send (sc-9763). +pub struct UnreviewedCarry { + /// The branch's previous build those versions are from. + pub number: i32, + /// By (name, platform): the previous build's row, to carry and compare with the baseline. + pub rows: HashMap<(String, String), Snapshot>, +} + +/// For a CI subset build, the snapshots it didn't send (nor carries as a matched group, whose contents are its +/// baseline's) that the branch's previous build of the suite and environment (its newest earlier completed build, or +/// the build that one follows) changed or added without an approval, rejected ones included: that build's rows, to +/// carry instead of the baseline. `None` when there are none. +/// +/// # Errors +/// On a database error. +pub async fn unreviewed_carry( + build: &Build, + seen: &HashSet<(String, String)>, + carry: &Carry, +) -> laravel::Result> { + if build.mode != "ci" || !build.subset { + return Ok(None); + } + let Some(previous) = previous_on_branch(build, &["completed"]).await? else { return Ok(None) }; + let rows: HashMap<(String, String), Snapshot> = super::snapshots::of_build(previous.id) + .await? + .into_iter() + .filter(|s| matches!(s.state.as_str(), "changed" | "added") && !is_config_item(s)) + .filter(|s| s.review.as_deref() != Some("approved")) + .filter(|s| !carry.covers(&s.name)) + .map(|s| ((s.name.clone(), s.platform.clone()), s)) + .filter(|(key, _)| !seen.contains(key)) + .collect(); + Ok((!rows.is_empty()).then_some(UnreviewedCarry { number: previous.number, rows })) +} + +/// The carried rows whose previous version was rejected stay rejected while they're still a change. +/// +/// # Errors +/// On a database error. +pub async fn keep_rejections(build_id: i64, carried: &UnreviewedCarry) -> laravel::Result<()> { + for (name, platform) in carried.rows.iter().filter(|(_, s)| s.review.as_deref() == Some("rejected")).map(|(k, _)| k) + { + db::query!( + "UPDATE snapshots SET review = 'rejected', updated_at = now() WHERE build_id = {build_id} \ + AND name = {name} AND platform = {platform} AND carried_forward AND state IN ('changed', 'added')" + ) + .update() + .await?; + } + Ok(()) +} + /// When an empty CI build is finalized and no finalized build covers its commit, but an [`unfinished`] one does: it /// follows that build, which is finalized with [`adopted_warning`] and queued. Called on finalizing, before the empty /// build is processed, so [`follow`] finds it following and the two are processed one after the other. @@ -189,7 +330,7 @@ pub async fn adopt(build: &Build) -> laravel::Result<()> { return Ok(()); } let mut me = build.clone(); - let warnings = with_warning(&me, earlier.number, true); + let warnings = with_warning(&me, &earlier, true); update!(me { covered_by_build_id: Some(earlier.id), warnings }).await?; tracing::info!( build_id = id, @@ -269,14 +410,18 @@ pub async fn follow(build: &Build) -> laravel::Result> { let empty = sent(build.id).await? == 0; let earlier = match build.covered_by_build_id { Some(id) => Build::find(id).await?, - None if empty => covering(build).await?, + // Same commit first ([`covering`]; [`adopt`] set `covered_by_build_id` on finalizing), then the branch. + None if empty => match covering(build).await? { + Some(earlier) => Some(earlier), + None => behind(build).await?, + }, None => twin(build).await?, }; 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, empty); + let warnings = with_warning(&build, &earlier, empty); update!(build { covered_by_build_id: Some(earlier.id), warnings }).await?; } return Ok(Some(false)); @@ -285,9 +430,19 @@ pub async fn follow(build: &Build) -> laravel::Result> { Ok(Some(true)) } -fn with_warning(build: &Build, number: i32, empty: bool) -> serde_json::Value { +/// The build's warnings with the one that says which build it follows and why: the same snapshots ([`twin_warning`]), +/// none on the same commit ([`covered_warning`]), or none on purpose behind the branch's earlier build +/// ([`behind_warning`]). +fn with_warning(build: &Build, earlier: &Build, empty: bool) -> serde_json::Value { let mut warnings: Vec = serde_json::from_value(build.warnings.clone()).unwrap_or_default(); - let warning = if empty { covered_warning(number) } else { twin_warning(number) }; + let number = earlier.number; + let warning = if !empty { + twin_warning(number) + } else if earlier.commit_sha == build.commit_sha { + covered_warning(number) + } else { + behind_warning(number) + }; if !warnings.contains(&warning) { warnings.push(warning); } @@ -317,7 +472,7 @@ pub async fn mirror(build_id: i64, earlier: &Build) -> laravel::Result { }); 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, sent(build.id).await? == 0); + let warnings = with_warning(&build, earlier, sent(build.id).await? == 0); let unchanged = build.state == "completed" && build.conclusion == conclusion && build.review_state == review_state @@ -375,7 +530,8 @@ pub async fn update_followers(build_id: i64) -> laravel::Result { #[must_use] pub fn not_reviewable(number: i32) -> String { format!( - "This build shows the result of build #{number}, which already compared the same commit (this run sent no \ - snapshots, or the same ones). Review build #{number} instead." + "This build shows the result of build #{number} (this run sent no snapshots, or the same ones): it already \ + compared this commit, or it's this branch's last build of the suite and isn't approved yet. Review build \ + #{number} instead." ) } diff --git a/app/src/forge/checks.rs b/app/src/forge/checks.rs index e1918169..71feafc1 100644 --- a/app/src/forge/checks.rs +++ b/app/src/forge/checks.rs @@ -90,11 +90,21 @@ pub async fn check_for(build: &Build, project: &Project, org: &Organization) -> 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 - ); + let why = if earlier.commit_sha == build.commit_sha { + format!( + "No snapshots were sent in build #{} (a rerun of failed jobs?). Build #{} already covers this commit, \ + so this check shows its result.", + build.number, earlier.number + ) + } else { + format!( + "No snapshots were sent in build #{} on purpose (its inputs unchanged?), and build #{}, this branch's \ + last build of the suite, isn't approved, so this check shows its result. Review build #{} (or send \ + this suite's snapshots again).", + build.number, earlier.number, earlier.number + ) + }; + check.summary = format!("{why}\n\n{}", check.summary); } check.name = check_name(&build.name); check.head_sha.clone_from(&build.commit_sha); diff --git a/app/tests/reruns.rs b/app/tests/reruns.rs index 18d77408..b2de8ce6 100644 --- a/app/tests/reruns.rs +++ b/app/tests/reruns.rs @@ -2,7 +2,7 @@ //! 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, twin_warning}; +use app::domain::reruns::{behind_warning, covered_warning, twin_warning}; use app::models::{Build, Organization, Project}; use app::testing::fixtures; use laravel::db; @@ -40,14 +40,19 @@ struct Run<'a> { /// 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 { + send_with(app, token, run, shots, json!({})).await +} + +/// [`send`], with more fields for the new build (`subset`, `environment`). +async fn send_with(app: &Application, token: &str, run: &Run<'_>, shots: &[(&str, [u8; 3])], extra: Value) -> 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; + let mut params = json!({ + "commit": run.commit, "branch": run.branch, "parent_commits": ["c0"], "name": run.name, "nonce": run.nonce + }); + for (key, value) in extra.as_object().into_iter().flatten() { + params[key] = value.clone(); + } + let build = app.post("/api/v1/builds").header("authorization", &auth).json(params).await; build.assert_ok(); let id = build.json()["id"].as_str().unwrap().to_string(); if shots.is_empty() { @@ -444,3 +449,326 @@ async fn quiet(id: i64) -> laravel::Result<()> { db::query!("UPDATE snapshots SET updated_at = now() - interval '6 minutes' WHERE build_id = {id}").update().await?; Ok(()) } + +/// A CI run that skipped the suite's jobs, their inputs unchanged: a subset build finished empty on purpose. +async fn skip(app: &Application, token: &str, run: &Run<'_>) -> Value { + skip_with(app, token, run, json!({})).await +} + +async fn skip_with(app: &Application, token: &str, run: &Run<'_>, extra: Value) -> Value { + let mut extra = extra; + extra["subset"] = json!(true); + let id = send_with(app, token, run, &[], extra).await; + let done = app + .post(format!("/api/v1/builds/{id}/finalize")) + .header("authorization", format!("Bearer {token}")) + .json(json!({ "empty_reason": "inputs unchanged" })) + .await; + done.assert_ok(); + done.json().clone() +} + +/// A subset build that sent these screenshots and skipped the rest. +async fn subset(app: &Application, token: &str, run: &Run<'_>, shots: &[(&str, [u8; 3])]) -> Value { + let id = send_with(app, token, run, shots, json!({ "subset": true })).await; + finalize(app, token, &id, false).await +} + +/// Approve or reject build #number, and let what follows it take the result (as the review routes do). +async fn review(number: i64, action: &str) -> laravel::Result { + let via = app::domain::reviews::Via::default(); + let reviewed = app::domain::reviews::review(build(number).await?, None, &via, action, None, None).await?; + let reviewed = reviewed.expect("reviewed"); + app::events::BuildChanged { build_id: reviewed.id }.dispatch().await?; + Ok(reviewed) +} + +/// The main branch's first build of the pdf suite: its screenshots are the approved baseline. +async fn main_baseline(app: &Application, token: &str) -> Value { + let first = + run(app, token, &Run { name: "pdf", commit: "c1", branch: "main", nonce: "main-1" }, &[("invoice.png", RED)]) + .await; + assert_eq!(first["review_state"], "auto_approved", "{first}"); + first +} + +/// A branch's build has a change waiting for review. The next push changes nothing for the suite, so CI skips its jobs +/// and finishes its build empty on purpose: that build mustn't pass on the old baseline. It waits for the review, and +/// approving the earlier build turns it green (sc-9763). +#[laravel::test] +async fn a_skipped_build_waits_for_the_review_of_the_branchs_pending_build(app: Application) -> laravel::Result<()> { + Box::pin(skipped_behind_pending(app)).await +} + +async fn skipped_behind_pending(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + let pdf = |commit, nonce| Run { name: "pdf", commit, branch: "feature", nonce }; + main_baseline(&app, &token).await; + + // #2: the branch changes the invoice, which waits for review. + let changed = run(&app, &token, &pdf("f1", "w2"), &[("invoice.png", BLUE)]).await; + assert_eq!((&changed["conclusion"], &changed["review_state"]), (&json!("changes"), &json!("pending")), "{changed}"); + + // #3: the next push skips the suite. It shows #2's result: pending, its check not a success. + let skipped = skip(&app, &token, &pdf("f2", "w3")).await; + assert_eq!( + (&skipped["state"], &skipped["conclusion"], &skipped["review_state"]), + (&json!("completed"), &json!("changes"), &json!("pending")), + "{skipped}" + ); + assert!(warnings(&skipped).contains(&behind_warning(2)), "{skipped}"); + assert_eq!(build(3).await?.covered_by_build_id, Some(build(2).await?.id)); + let (status, conclusion, title) = check(3).await?; + assert_eq!((status.as_str(), conclusion), ("in_progress", None), "{title}"); + assert!(title.ends_with("(build #2)"), "{title}"); + + // #4: a rerun at yet another commit follows #2 too, not #3. + let again = skip(&app, &token, &pdf("f3", "w4")).await; + assert!(warnings(&again).contains(&behind_warning(2)), "{again}"); + assert_eq!(build(4).await?.covered_by_build_id, Some(build(2).await?.id)); + + // #3 can't be reviewed itself. Approving #2 turns #3 and #4 green, checks and all. + let via = app::domain::reviews::Via::default(); + let refused = app::domain::reviews::review(build(3).await?, None, &via, "approve", None, None).await?; + assert!(refused.as_ref().is_err_and(|e| e.contains("Review build #2 instead")), "{refused:?}"); + review(2, "approve").await?; + for (number, id) in [(3, &skipped["id"]), (4, &again["id"])] { + let shown = fetch(&app, &token, id).await; + assert_eq!((&shown["review_state"], &shown["passed"]), (&json!("approved"), &json!(true)), "{shown}"); + let (status, conclusion, title) = check(number).await?; + assert_eq!((status.as_str(), conclusion.as_deref()), ("completed", Some("success")), "{title}"); + } + + // #5: the next skip passes straight away, on the baseline #2's approval made. + let next = skip(&app, &token, &pdf("f4", "w5")).await; + assert_eq!((&next["conclusion"], &next["passed"]), (&json!("unchanged"), &json!(true)), "{next}"); + assert_eq!(build(5).await?.covered_by_build_id, None); + Ok(()) +} + +/// The branch's last build was rejected, or failed: a skipped build is rejected, or fails, with it. +#[laravel::test] +async fn a_skipped_build_behind_a_rejected_or_failed_build_doesnt_pass(app: Application) -> laravel::Result<()> { + Box::pin(skipped_behind_rejected(app)).await +} + +async fn skipped_behind_rejected(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + main_baseline(&app, &token).await; + + // #2 rejected; #3 skips. + run(&app, &token, &Run { name: "pdf", commit: "f1", branch: "feature", nonce: "w2" }, &[("invoice.png", BLUE)]) + .await; + review(2, "reject").await?; + let skipped = skip(&app, &token, &Run { name: "pdf", commit: "f2", branch: "feature", nonce: "w3" }).await; + assert_eq!((&skipped["review_state"], &skipped["passed"]), (&json!("rejected"), &json!(false)), "{skipped}"); + assert!(warnings(&skipped).contains(&behind_warning(2)), "{skipped}"); + let (status, conclusion, title) = check(3).await?; + assert_eq!((status.as_str(), conclusion.as_deref()), ("completed", Some("failure")), "{title}"); + + // #4 on another branch failed (as `mirror` fails a follower of a failed build); #5 skips and fails too. + run(&app, &token, &Run { name: "pdf", commit: "g1", branch: "other", nonce: "w4" }, &[("invoice.png", BLUE)]).await; + let id = build(4).await?.id; + db::query!("UPDATE builds SET state = 'failed', conclusion = 'failed', review_state = 'none', error = 'boom' WHERE id = {id}") + .update() + .await?; + let skipped = skip(&app, &token, &Run { name: "pdf", commit: "g2", branch: "other", nonce: "w5" }).await; + assert_eq!( + (&skipped["state"], &skipped["conclusion"], &skipped["passed"], &skipped["error"]), + (&json!("completed"), &json!("failed"), &json!(false), &json!("Build #4 failed: boom")), + "{skipped}" + ); + let (status, conclusion, title) = check(5).await?; + assert_eq!((status.as_str(), conclusion.as_deref()), ("completed", Some("failure")), "{title}"); + Ok(()) +} + +/// The branch's last build is approved, auto-approved or unchanged: a skipped build carries the baseline forward and +/// passes, as before. So does the default branch's. +#[laravel::test] +async fn a_skipped_build_behind_a_settled_build_carries_the_baseline(app: Application) -> laravel::Result<()> { + Box::pin(skipped_behind_settled(app)).await +} + +async fn skipped_behind_settled(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + let on = |branch, commit, nonce| Run { name: "pdf", commit, branch, nonce }; + main_baseline(&app, &token).await; + + // Behind main's auto-approved first build (#1): #2 passes, unchanged, following nothing. + let skipped = skip(&app, &token, &on("main", "c2", "w2")).await; + assert_eq!( + (&skipped["conclusion"], &skipped["review_state"], &skipped["passed"]), + (&json!("unchanged"), &json!("auto_approved"), &json!(true)), + "{skipped}" + ); + assert_eq!(build(2).await?.covered_by_build_id, None); + + // Behind a branch's unchanged build (#3): #4 passes. + let same = run(&app, &token, &on("feature", "f1", "w3"), &[("invoice.png", RED)]).await; + assert_eq!(same["conclusion"], "unchanged", "{same}"); + let skipped = skip(&app, &token, &on("feature", "f2", "w4")).await; + assert_eq!((&skipped["passed"], &skipped["conclusion"]), (&json!(true), &json!("unchanged")), "{skipped}"); + assert_eq!(build(4).await?.covered_by_build_id, None); + + // Behind a branch's approved build (#5): #6 passes straight away. + run(&app, &token, &on("approved", "a1", "w5"), &[("invoice.png", BLUE)]).await; + review(5, "approve").await?; + let skipped = skip(&app, &token, &on("approved", "a2", "w6")).await; + assert_eq!((&skipped["passed"], &skipped["conclusion"]), (&json!(true), &json!("unchanged")), "{skipped}"); + assert_eq!(build(6).await?.covered_by_build_id, None); + let (_, conclusion, title) = check(6).await?; + assert_eq!(conclusion.as_deref(), Some("success"), "{title}"); + Ok(()) +} + +/// The default branch too: a pending main build behind a skipped main build is the same hole. And only the same +/// branch, suite and environment count. +#[laravel::test] +async fn a_skipped_build_on_the_default_branch_waits_too_and_only_its_own_suite_counts( + app: Application, +) -> laravel::Result<()> { + Box::pin(skipped_on_main(app)).await +} + +async fn skipped_on_main(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + main_baseline(&app, &token).await; + + // #2: main changes the invoice, pending. #3: main skips, and waits. + let changed = + run(&app, &token, &Run { name: "pdf", commit: "c2", branch: "main", nonce: "w2" }, &[("invoice.png", BLUE)]) + .await; + assert_eq!(changed["review_state"], "pending", "{changed}"); + let skipped = skip(&app, &token, &Run { name: "pdf", commit: "c3", branch: "main", nonce: "w3" }).await; + assert_eq!(skipped["review_state"], "pending", "{skipped}"); + assert_eq!(build(3).await?.covered_by_build_id, Some(build(2).await?.id)); + let (status, conclusion, title) = check(3).await?; + assert_eq!((status.as_str(), conclusion), ("in_progress", None), "{title}"); + + // Another branch, another suite, another environment: #2 doesn't count, and each passes on its baseline. + for (number, name, branch, environment) in + [(4, "pdf", "feature", "ci"), (5, "browser", "main", "ci"), (6, "pdf", "main", "linux-arm")] + { + let nonce = format!("w{number}"); + let run = Run { name, commit: "c4", branch, nonce: &nonce }; + let other = skip_with(&app, &token, &run, json!({ "environment": environment })).await; + assert_eq!(other["number"], number); + assert_eq!((&other["passed"], &other["error"]), (&json!(true), &Value::Null), "{name} {branch}: {other}"); + assert_eq!(build(number).await?.covered_by_build_id, None, "{name} {branch} {environment}"); + } + + review(2, "approve").await?; + let skipped = fetch(&app, &token, &skipped["id"]).await; + assert_eq!((&skipped["review_state"], &skipped["passed"]), (&json!("approved"), &json!(true)), "{skipped}"); + Ok(()) +} + +/// An empty build that isn't empty on purpose (no allow_empty) still fails as empty, behind a pending build too; a +/// build that sent snapshots is compared as usual; and a same-commit rerun still follows its commit's build (covering, +/// or the unfinished one it finalizes), not the branch's. +#[laravel::test] +async fn the_branch_rule_leaves_accidental_empty_builds_sent_builds_and_same_commit_reruns_alone( + app: Application, +) -> laravel::Result<()> { + Box::pin(branch_rule_precedence(app)).await +} + +async fn branch_rule_precedence(app: Application) -> laravel::Result<()> { + use app::domain::reruns::adopted_warning; + fixtures::blob_store().await?; + let token = project_token().await?; + let pdf = |commit, nonce| Run { name: "pdf", commit, branch: "feature", nonce }; + main_baseline(&app, &token).await; + + // #2 pending. #3: an accidental empty subset build at a new commit fails as empty. + run(&app, &token, &pdf("f1", "w2"), &[("invoice.png", BLUE)]).await; + let id = send_with(&app, &token, &pdf("f2", "w3"), &[], json!({ "subset": true })).await; + let empty = finalize(&app, &token, &id, false).await; + assert_eq!((&empty["error"], &empty["passed"]), (&json!(EMPTY_BUILD), &json!(false)), "{empty}"); + assert_eq!(build(3).await?.covered_by_build_id, None); + + // #4 sent snapshots at a new commit: compared as usual (the same change, pending on its own). + let sent = run(&app, &token, &pdf("f3", "w4"), &[("invoice.png", BLUE)]).await; + assert_eq!((&sent["conclusion"], &sent["review_state"]), (&json!("changes"), &json!("pending")), "{sent}"); + assert_eq!(build(4).await?.covered_by_build_id, None); + assert!(!warnings(&sent).iter().any(|w| w.contains("on purpose")), "{sent}"); + + // #5: a skipped rerun of #4's commit follows #4 as a covered rerun. + let rerun = skip(&app, &token, &pdf("f3", "w5")).await; + assert!(warnings(&rerun).contains(&covered_warning(4)), "{rerun}"); + assert!(!warnings(&rerun).contains(&behind_warning(4)), "{rerun}"); + assert_eq!(build(5).await?.covered_by_build_id, Some(build(4).await?.id)); + + // #6 sent but never finalized, quiet; #7, its skipped rerun, finalizes it and follows it. + send(&app, &token, &pdf("f4", "w6"), &[("invoice.png", RED)]).await; + quiet(build(6).await?.id).await?; + let rerun = skip(&app, &token, &pdf("f4", "w7")).await; + let adopted = build(6).await?; + let adopted_warnings: Vec = serde_json::from_value(adopted.warnings.clone()).unwrap_or_default(); + assert!(adopted_warnings.contains(&adopted_warning(7)), "{adopted_warnings:?}"); + assert_eq!(build(7).await?.covered_by_build_id, Some(adopted.id)); + assert!(warnings(&rerun).contains(&covered_warning(6)), "{rerun}"); + // #6 went back to the baseline: #7 passes with it. + assert_eq!(rerun["passed"], true, "{rerun}"); + Ok(()) +} + +/// A subset build that sent one group and skipped another: a skipped snapshot the branch's previous build changed +/// without an approval is carried from that build, not the baseline, and waits for a review here; a rejected one keeps +/// its rejection; an approved one carries the baseline as before. +#[laravel::test] +async fn a_partial_subset_build_carries_the_branchs_unreviewed_changes(app: Application) -> laravel::Result<()> { + Box::pin(partial_subset(app)).await +} + +async fn partial_subset(app: Application) -> laravel::Result<()> { + use app::domain::reruns::unreviewed_carry_warning; + fixtures::blob_store().await?; + let token = project_token().await?; + let (invoice, receipt) = ("invoices/a/invoice.png", "receipts/a/receipt.png"); + let on = |branch, commit, nonce| Run { name: "pdf", commit, branch, nonce }; + let first = run(&app, &token, &on("main", "c1", "w1"), &[(invoice, RED), (receipt, RED)]).await; + assert_eq!(first["review_state"], "auto_approved", "{first}"); + + // #2: the branch changes the invoice and adds a statement. #3 sends the receipts group only. + let statement = "statements/a/statement.png"; + run(&app, &token, &on("feature", "f1", "w2"), &[(invoice, BLUE), (receipt, RED), (statement, BLUE)]).await; + let partial = subset(&app, &token, &on("feature", "f2", "w3"), &[(receipt, RED)]).await; + assert_eq!((&partial["conclusion"], &partial["review_state"]), (&json!("changes"), &json!("pending")), "{partial}"); + assert!(warnings(&partial).contains(&unreviewed_carry_warning(2, 2)), "{partial}"); + let rows = app::domain::snapshots::of_build(build(3).await?.id).await?; + let state = |name: &str| rows.iter().find(|s| s.name == name).map(|s| s.state.clone()); + assert_eq!( + (state(invoice).as_deref(), state(receipt).as_deref(), state(statement).as_deref()), + (Some("changed"), Some("unchanged"), Some("added")) + ); + let (status, conclusion, title) = check(3).await?; + assert_eq!((status.as_str(), conclusion), ("in_progress", None), "{title}"); + // Approved here, it's green. + review(3, "approve").await?; + assert_eq!(fetch(&app, &token, &partial["id"]).await["passed"], true); + + // #4 changes the invoice again and is rejected; #5 skips it and comes out rejected. + run(&app, &token, &on("rejected", "r1", "w4"), &[(invoice, BLUE), (receipt, RED)]).await; + review(4, "reject").await?; + let partial = subset(&app, &token, &on("rejected", "r2", "w5"), &[(receipt, RED)]).await; + assert_eq!((&partial["review_state"], &partial["passed"]), (&json!("rejected"), &json!(false)), "{partial}"); + let (_, conclusion, title) = check(5).await?; + assert_eq!(conclusion.as_deref(), Some("failure"), "{title}"); + + // #6 changes the invoice and is approved; #7 skips it and passes, on the baseline the approval made. + run(&app, &token, &on("approved", "p1", "w6"), &[(invoice, BLUE), (receipt, BLUE)]).await; + review(6, "approve").await?; + let partial = subset(&app, &token, &on("approved", "p2", "w7"), &[(receipt, BLUE)]).await; + assert_eq!((&partial["conclusion"], &partial["passed"]), (&json!("unchanged"), &json!(true)), "{partial}"); + assert!( + !warnings(&partial).iter().any(|w| w.contains("this branch's last build of the suite, and not approved")), + "{partial}" + ); + Ok(()) +} diff --git a/frontend/content/changelog.md b/frontend/content/changelog.md index dabadd12..cd9a072f 100644 --- a/frontend/content/changelog.md +++ b/frontend/content/changelog.md @@ -9,6 +9,7 @@ What changed in VisualCI for the people and agents using it, newest first. Dates - **Gallery libraries 0.3.0:** dimensions. Theme and size become two of a gallery's dimensions, and the `dimensions` option adds your own (a language, a plan) or changes theirs (a high-contrast theme, a tablet size). The words in a screenshot's name pick its values, in any order. A switch with four values or more is a drop-down list that follows the WAI-ARIA select-only combobox pattern. A screen without the chosen language shows its first, a screen without the chosen size is hidden, and every screen needs every theme. The "Screenshots by VisualCI" line is off by default; `credit: true` shows it. The markup's attributes change (`data-vg-for`, `data-vg-shown`), so update the JS library with the server libraries. [Dimensions](/docs/gallery/options/#dimensions) - The sign-in page, the GitHub App setup pages ("Finding your GitHub repositories…" and the rest), the waitlist page and the 404 on VisualCI's other hosts are a card in the app's look, light and dark, with a progress bar while VisualCI lists your repositories. +- A CI build that skipped a suite's jobs (`--subset`, finalized with `--allow-empty` or `--empty-reason`) no longer passes on the old baseline while the branch's last build of that suite is waiting for review, rejected or failed: it shows that build's result and turns green when it's approved. A build that skipped some jobs carries the branch's unapproved changes for the snapshots it wasn't sent, for review there. [CircleCI](/docs/ci/circleci/#parallel-jobs) - Docs links to headings with an apostrophe work: a heading like "Choose what's public" is at `#choose-whats-public`, where the page used to give it `#choose-what-39-s-public`. The Ruby gem's documentation link goes to the RSpec screenshots page. - A rerun of only the failed jobs no longer fails a suite as empty when the first run's finalizing job never ran: the rerun's empty build finalizes the first run's build, once nothing has arrived for it for 5 minutes (or after VisualCI gave up on it), and shows its result. [CircleCI](/docs/ci/circleci/#rerunning-failed-jobs) - **Gallery libraries 0.2.2, for React, Next.js, Docusaurus, VitePress and MkDocs:** `visualci-gallery-react` (a server component for Next.js's app router), `visualci-gallery-docusaurus`, `visualci-gallery-vitepress`, and an MkDocs plugin in the `visualci-gallery` Python package. Each renders the gallery into the page when the site builds, and fails the build when the manifest can't be read. [Gallery guides](/docs/gallery/#show-it-on-your-site) diff --git a/frontend/content/docs/ci/circleci.md b/frontend/content/docs/ci/circleci.md index c81d6a79..ae0457a5 100644 --- a/frontend/content/docs/ci/circleci.md +++ b/frontend/content/docs/ci/circleci.md @@ -50,6 +50,8 @@ 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. +The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed or added without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. + ## 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. If the first run's finalizing job never ran (a job before it failed), its build was never finalized: the new build finalizes it and follows it, once nothing has arrived for it for 5 minutes, even after VisualCI gave up on it at the hour. You don't need to change anything for reruns, and you don't need `--allow-empty` for them. diff --git a/frontend/content/docs/ci/github-actions.md b/frontend/content/docs/ci/github-actions.md index b70add7e..569f4325 100644 --- a/frontend/content/docs/ci/github-actions.md +++ b/frontend/content/docs/ci/github-actions.md @@ -207,6 +207,12 @@ forward instead of counted as removed, and it's finalized with `--allow-empty`, Its check passes as unchanged. A run that does test sends every snapshot, so one that disappears still shows as removed, and an upload that finds nothing still fails. +The skipped build passes only when the branch's last build of the suite is approved (or had nothing to approve). If +that build is still being compared, waiting for review, rejected or failed, the skipped build shows its result +instead, with a warning naming it, and turns green when that build is approved: a skipped push can't pass on the old +baseline while the branch has a change nobody approved. A subset build that sent some snapshots carries the branch's +last unapproved version of each snapshot it wasn't sent, for review in this build (a rejected one stays rejected). + ## Blacksmith, Depot and other runners Blacksmith, Depot and other GitHub Actions runner providers run the same workflow with a different `runs-on`. Nothing else changes on x86_64 runners. On an arm64 runner, the action installs the arm64 CLI itself; the snippets that download the CLI directly need `visualci-aarch64-unknown-linux-musl.tar.gz` and that file's checksum from the [release](https://github.com/DocSpring/visualci/releases/tag/v{{cli_version}}). diff --git a/frontend/content/docs/ci/other.md b/frontend/content/docs/ci/other.md index 686f0930..f54e2401 100644 --- a/frontend/content/docs/ci/other.md +++ b/frontend/content/docs/ci/other.md @@ -51,7 +51,7 @@ Parallel jobs can share one build: - Each job uploads its files and runs `visualci build finalize --shard `, with shards numbered from 0. - VisualCI compares the build once all `n` shards have finalized. -Add `--subset` when some jobs may not run. Snapshots that weren't sent are then carried forward instead of counted as removed. +Add `--subset` when some jobs may not run. Snapshots that weren't sent are then carried forward instead of counted as removed. A snapshot the branch's last build of the suite changed or added without an approval is carried from that build, for review in this one, rather than from the baseline (a rejected one stays rejected). A build that skipped every job, finalized with `--allow-empty`, shows the result of the branch's last build of the suite when that build is still being compared, waiting for review, rejected or failed, and turns green when it's approved. 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. An earlier build that was sent snapshots but never finalized (its finalizing job didn't run) is finalized by the empty build and followed, once nothing has arrived for it for 5 minutes, even after VisualCI gave up on it at the hour. diff --git a/frontend/content/docs/reference/api.md b/frontend/content/docs/reference/api.md index a4c2839f..9a74ebe2 100644 --- a/frontend/content/docs/reference/api.md +++ b/frontend/content/docs/reference/api.md @@ -85,7 +85,7 @@ A bundle is a tar archive compressed with zstd (`.tar.zst`). It holds one regula ## Finalize -`POST /api/v1/builds/{id}/finalize`, with an empty body or `{"shard": 0}`. VisualCI compares the build once every shard has finalized. The response is the build. A build that was sent no snapshots fails; send `"allow_empty": true` when it's empty on purpose, or `"empty_reason": "inputs unchanged"`, which implies it and puts the reason in the build's summary with the build its baseline came from. +`POST /api/v1/builds/{id}/finalize`, with an empty body or `{"shard": 0}`. VisualCI compares the build once every shard has finalized. The response is the build. A build that was sent no snapshots fails; send `"allow_empty": true` when it's empty on purpose, or `"empty_reason": "inputs unchanged"`, which implies it and puts the reason in the build's summary with the build its baseline came from. A CI `subset` build finalized empty this way passes on its baseline only when the branch's last build of the suite is approved or had nothing to approve; while that build is being compared, waiting for review, rejected or failed, the empty build shows its result, with a warning naming it, and follows it. ## Read a build diff --git a/gemini-extension.json b/gemini-extension.json index a62b738b..dd7a2486 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.71", + "version": "0.1.72", "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/plugin/.claude-plugin/plugin.json b/plugin/.claude-plugin/plugin.json index f7592ba2..207bbbde 100644 --- a/plugin/.claude-plugin/plugin.json +++ b/plugin/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.71", + "version": "0.1.72", "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/plugin/.cursor-plugin/plugin.json b/plugin/.cursor-plugin/plugin.json index 766f5851..23a226b0 100644 --- a/plugin/.cursor-plugin/plugin.json +++ b/plugin/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "visualci", "displayName": "VisualCI", - "version": "0.1.71", + "version": "0.1.72", "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/plugin/skills/visualci-circleci/SKILL.md b/plugin/skills/visualci-circleci/SKILL.md index b3ee6868..e4f46c0d 100644 --- a/plugin/skills/visualci-circleci/SKILL.md +++ b/plugin/skills/visualci-circleci/SKILL.md @@ -57,6 +57,8 @@ 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. +The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed or added without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. + ## 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. If the first run's finalizing job never ran (a job before it failed), its build was never finalized: the new build finalizes it and follows it, once nothing has arrived for it for 5 minutes, even after VisualCI gave up on it at the hour. You don't need to change anything for reruns, and you don't need `--allow-empty` for them. diff --git a/plugin/skills/visualci-github-actions/SKILL.md b/plugin/skills/visualci-github-actions/SKILL.md index 5fe70eb1..74e2d91f 100644 --- a/plugin/skills/visualci-github-actions/SKILL.md +++ b/plugin/skills/visualci-github-actions/SKILL.md @@ -214,6 +214,12 @@ forward instead of counted as removed, and it's finalized with `--allow-empty`, Its check passes as unchanged. A run that does test sends every snapshot, so one that disappears still shows as removed, and an upload that finds nothing still fails. +The skipped build passes only when the branch's last build of the suite is approved (or had nothing to approve). If +that build is still being compared, waiting for review, rejected or failed, the skipped build shows its result +instead, with a warning naming it, and turns green when that build is approved: a skipped push can't pass on the old +baseline while the branch has a change nobody approved. A subset build that sent some snapshots carries the branch's +last unapproved version of each snapshot it wasn't sent, for review in this build (a rejected one stays rejected). + ## Blacksmith, Depot and other runners Blacksmith, Depot and other GitHub Actions runner providers run the same workflow with a different `runs-on`. Nothing else changes on x86_64 runners. On an arm64 runner, the action installs the arm64 CLI itself; the snippets that download the CLI directly need `visualci-aarch64-unknown-linux-musl.tar.gz` and that file's checksum from the [release](https://github.com/DocSpring/visualci/releases/tag/vx.y.z). From 5ea649970637d0de20cb208e07d8df0982cc08f5 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 08:21:34 +0000 Subject: [PATCH 2/6] Skipped builds: follow what superseded the branch's build; partial subsets wait for the branch's processing build (sc-9763) A superseded earlier build stands for the build whose review superseded it: only a superseding approval keeps the baseline carry; a rejection is followed (rejected), a superseding build still pending is followed (waits). A CI subset build whose branch's previous build of the suite is still processing waits, processing, until it concludes (woken by BuildChanged, restarted by the sweep), for WAIT_FOR_PREVIOUS_MINUTES (30). After that it carries what's known from the newest completed build and concludes pending with a warning, never auto_approved. --- app/src/domain/processing.rs | 19 ++- app/src/domain/reruns.rs | 127 +++++++++++++++-- app/src/listeners/mod.rs | 2 + app/tests/reruns.rs | 131 ++++++++++++++++++ frontend/content/changelog.md | 2 +- frontend/content/docs/ci/circleci.md | 2 +- frontend/content/docs/ci/github-actions.md | 4 +- frontend/content/docs/ci/other.md | 2 +- frontend/content/docs/reference/api.md | 2 +- plugin/skills/visualci-circleci/SKILL.md | 2 +- .../skills/visualci-github-actions/SKILL.md | 4 +- 11 files changed, 275 insertions(+), 22 deletions(-) diff --git a/app/src/domain/processing.rs b/app/src/domain/processing.rs index 8990fba1..108997d3 100644 --- a/app/src/domain/processing.rs +++ b/app/src/domain/processing.rs @@ -549,6 +549,11 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> if let Some(done) = Box::pin(super::reruns::follow(&build)).await? { return Ok(done); } + // A subset build waits for the branch's previous build of its suite to conclude: its rows say which snapshots this + // build didn't send still carry an unreviewed change (sc-9763). + if super::reruns::waits_for_previous(&build).await? { + return Ok(false); + } let mut snapshots: Vec = Snapshot::query() .filter(Snapshot::build_id.eq(id)) .order_by(Snapshot::name.asc()) @@ -752,9 +757,13 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> // The file's settings: a loosening ci_mode it can't use, ignore rules that matched nothing, and whether they hide // more than the base build's (then the build gets a "visualci.yml" item to review). let mut warnings = settings.config_warnings(); - if let Some(u) = &unreviewed { + if let Some(u) = unreviewed.as_ref().filter(|u| !u.rows.is_empty()) { warnings.push(super::reruns::unreviewed_carry_warning(u.rows.len(), u.number)); } + if let Some(number) = unreviewed.as_ref().and_then(|u| u.unfinished) { + warnings.push(super::reruns::unfinished_previous_warning(number)); + } + let hold = unreviewed.as_ref().is_some_and(|u| u.unfinished.is_some()); let names: Vec = super::snapshots::of_build(id).await?.into_iter().map(|s| s.name).collect(); if settings.scoped_rules().0 == Source::File { for rule in settings.unmatched_rules(names.iter().map(String::as_str)) { @@ -835,7 +844,7 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> let warnings = warnings.clone(); update!(build { warnings }).await?; - let build = conclude(build, &project.default_branch, base_build_id, has_base, sent).await?; + let build = conclude(build, &project.default_branch, base_build_id, has_base, sent, hold).await?; if build.review_state == "auto_approved" { // Nothing to review (or the default branch's first build): its changes are the baselines now. let all = super::snapshots::of_build(build.id).await?; @@ -936,19 +945,22 @@ pub fn stats_of(snapshots: &[Snapshot]) -> Stats { /// Count snapshot states, set the conclusion and review state, and mark the build completed. `sent` is how many /// snapshots the build was sent itself: none means the upload found nothing, which mustn't pass as "unchanged". +/// `hold`: the build can't be known to be clean (the branch's previous build was still processing, +/// `reruns::unfinished_previous_warning`), so it waits for a review rather than passing or being approved on its own. async fn conclude( mut build: Build, default_branch: &str, base_build_id: Option, has_base: bool, sent: i64, + hold: bool, ) -> laravel::Result { let all = super::snapshots::of_build(build.id).await?; let stats = stats_of(&all); let empty = sent == 0 && !build.allow_empty; let conclusion = if stats.failed > 0 || empty { "failed" - } else if stats.changes() > 0 { + } else if stats.changes() > 0 || hold { "changes" } else { "unchanged" @@ -963,6 +975,7 @@ async fn conclude( let review_state = match conclusion { "failed" => "none", _ if rejected => "rejected", + _ if hold => "pending", "unchanged" => "auto_approved", _ if first_on_default => "auto_approved", _ => "pending", diff --git a/app/src/domain/reruns.rs b/app/src/domain/reruns.rs index 05bf2a79..c149bfa1 100644 --- a/app/src/domain/reruns.rs +++ b/app/src/domain/reruns.rs @@ -29,11 +29,12 @@ //! build empty on purpose (`--allow-empty`, or an `empty_reason`), and such a build would carry the approved baseline //! forward and pass. When no build of its commit covers it (above), it follows the branch's newest earlier build of //! the suite and environment, whatever its commit, if that build's result isn't settled-good ([`behind`]): still -//! processing, waiting for review, rejected or failed. It waits, is rejected or fails with it, and turns green when -//! that build is approved. A subset build that sent some groups and skipped others carries, for each skipped snapshot +//! processing, waiting for review, rejected or failed; a superseded build stands for the review that superseded it +//! ([`superseder`]). It waits, is rejected or fails with it, and turns green when that build is approved. A subset build that sent some groups and skipped others carries, for each skipped snapshot //! the branch's previous build changed or added without an approval, that build's version instead of the baseline //! ([`unreviewed_carry`]): it's compared with the baseline and waits for a review here, and a rejected one stays -//! rejected. +//! rejected. While that build is still processing, the subset build waits for it ([`waits_for_previous`]), and past +//! [`WAIT_FOR_PREVIOUS_MINUTES`] it carries what's known and waits for a review rather than passing. use std::collections::{HashMap, HashSet}; @@ -60,8 +61,8 @@ pub fn covered_warning(number: i32) -> String { #[must_use] pub fn behind_warning(number: i32) -> String { format!( - "No snapshots were sent in this run on purpose (its inputs unchanged?), but build #{number}, this branch's \ - last build of the suite, isn't approved (waiting for review, rejected or failed), so this build shows its \ + "No snapshots were sent in this run on purpose (its inputs unchanged?), but build #{number} (this branch's \ + last build of the suite, or the build whose review superseded it) isn't approved (waiting for review, rejected or failed), so this build shows its \ result rather than passing on the old baseline. Review build #{number}, or send this suite's snapshots again." ) } @@ -220,10 +221,11 @@ async fn previous_on_branch(build: &Build, states: &[&str]) -> laravel::Result laravel::Result> { let Some(earlier) = previous_on_branch(build, &["processing", "completed", "failed"]).await? else { return Ok(None); }; + let earlier = superseder(earlier).await?; let unsettled = match earlier.state.as_str() { "completed" => { earlier.conclusion.as_deref() == Some("failed") @@ -247,18 +250,114 @@ pub async fn behind(build: &Build) -> laravel::Result> { Ok(unsettled.then_some(earlier)) } +/// The build whose review stands for this one: a superseded build's superseding build (or the build that one follows), +/// as far as the chain goes; any other build itself. +async fn superseder(mut build: Build) -> laravel::Result { + // A chain is short: each link is a later build's review. The bound only guards against a cycle in bad data. + for _ in 0..16 { + if build.review_state != "superseded" { + break; + } + let Some(by) = build.superseded_by_build_id else { break }; + let Some(next) = Build::find(by).await? else { break }; + build = match next.covered_by_build_id { + Some(root) => match Build::find(root).await? { + Some(root) => root, + None => next, + }, + None => next, + }; + } + Ok(build) +} + +/// How long a CI subset build waits for the branch's previous build of its suite to finish processing, so it knows +/// which of that build's changes are unreviewed ([`waits_for_previous`]). After that, it carries what's known and waits +/// for a review ([`UnreviewedCarry::unfinished`]). +pub const WAIT_FOR_PREVIOUS_MINUTES: i32 = 30; + +/// The warning on a subset build that stopped waiting for the branch's previous build of its suite. +#[must_use] +pub fn unfinished_previous_warning(number: i32) -> String { + format!( + "Build #{number}, this branch's last build of the suite, was still being compared after \ + {WAIT_FOR_PREVIOUS_MINUTES} minutes, so VisualCI couldn't tell whether the snapshots this run didn't send have \ + unreviewed changes there: this build waits for a review instead of passing on the old baseline." + ) +} + +/// Whether a CI subset build should wait, processing, for the branch's previous build of its suite (or the build that +/// one follows), which is still processing: its rows say which skipped snapshots carry an unreviewed change. Only for +/// [`WAIT_FOR_PREVIOUS_MINUTES`] after the build was finalized. The previous build's conclusion wakes it +/// ([`wake_waiting`]); the sweep restarts it too. +/// +/// # Errors +/// On a database error. +pub async fn waits_for_previous(build: &Build) -> laravel::Result { + let Some(previous) = unfinished_previous(build).await? else { return Ok(false) }; + let (id, minutes) = (build.id, WAIT_FOR_PREVIOUS_MINUTES); + let recent: Option = db::query!( + "SELECT COALESCE(finalized_at, created_at) > now() - make_interval(mins => {minutes}) FROM builds \ + WHERE id = {id}" + ) + .scalar() + .await?; + if recent == Some(true) { + tracing::info!(build_id = id, previous = previous.id, "waiting for the branch's previous build of the suite"); + } + Ok(recent == Some(true)) +} + +/// The branch's previous build of a CI subset build's suite (or the build it follows), when it's still processing. +async fn unfinished_previous(build: &Build) -> laravel::Result> { + if build.mode != "ci" || !build.subset { + return Ok(None); + } + let previous = previous_on_branch(build, &["processing", "completed"]).await?; + Ok(previous.filter(|p| p.state == "processing")) +} + +/// A build concluded: the later CI subset builds of its suite, environment and branch that are still processing +/// (waiting for it, [`waits_for_previous`]) are processed again. +/// +/// # Errors +/// On a database or queue error. +pub async fn wake_waiting(build_id: i64) -> laravel::Result { + let Some(build) = Build::find(build_id).await? else { return Ok(0) }; + if build.mode != "ci" || build.state != "completed" { + return Ok(0); + } + let (id, project_id, name, environment, branch) = + (build.id, build.project_id, build.name.as_str(), build.environment.as_str(), build.branch.as_str()); + let waiting: Vec = db::query!( + "SELECT id FROM builds WHERE project_id = {project_id} AND name = {name} AND environment = {environment} \ + AND branch = {branch} AND mode = 'ci' AND subset AND state = 'processing' AND id > {id} ORDER BY id" + ) + .select_as() + .await?; + for waiting in &waiting { + crate::jobs::process_build::ProcessBuild { build_id: *waiting }.dispatch().await?; + } + Ok(waiting.len()) +} + /// What a CI subset build carries instead of the baseline for the snapshots it didn't send (sc-9763). pub struct UnreviewedCarry { /// The branch's previous build those versions are from. pub number: i32, /// By (name, platform): the previous build's row, to carry and compare with the baseline. pub rows: HashMap<(String, String), Snapshot>, + /// The branch's newer previous build, still processing after [`WAIT_FOR_PREVIOUS_MINUTES`]: what it changed isn't + /// known, so the build waits for a review ([`unfinished_previous_warning`]), never approved on its own. + pub unfinished: Option, } /// For a CI subset build, the snapshots it didn't send (nor carries as a matched group, whose contents are its /// baseline's) that the branch's previous build of the suite and environment (its newest earlier completed build, or /// the build that one follows) changed or added without an approval, rejected ones included: that build's rows, to -/// carry instead of the baseline. `None` when there are none. +/// carry instead of the baseline. When the newest previous build is still processing (the build stopped waiting for +/// it, [`waits_for_previous`]), the rows are the newest completed one's, and `unfinished` names it. `None` when there +/// are none and nothing is unfinished. /// /// # Errors /// On a database error. @@ -270,7 +369,10 @@ pub async fn unreviewed_carry( if build.mode != "ci" || !build.subset { return Ok(None); } - let Some(previous) = previous_on_branch(build, &["completed"]).await? else { return Ok(None) }; + let unfinished = unfinished_previous(build).await?.map(|p| p.number); + let Some(previous) = previous_on_branch(build, &["completed"]).await? else { + return Ok(unfinished.map(|_| UnreviewedCarry { number: 0, rows: HashMap::new(), unfinished })); + }; let rows: HashMap<(String, String), Snapshot> = super::snapshots::of_build(previous.id) .await? .into_iter() @@ -280,7 +382,8 @@ pub async fn unreviewed_carry( .map(|s| ((s.name.clone(), s.platform.clone()), s)) .filter(|(key, _)| !seen.contains(key)) .collect(); - Ok((!rows.is_empty()).then_some(UnreviewedCarry { number: previous.number, rows })) + let carried = !rows.is_empty() || unfinished.is_some(); + Ok(carried.then_some(UnreviewedCarry { number: previous.number, rows, unfinished })) } /// The carried rows whose previous version was rejected stay rejected while they're still a change. diff --git a/app/src/listeners/mod.rs b/app/src/listeners/mod.rs index 51d5f04c..f586ad37 100644 --- a/app/src/listeners/mod.rs +++ b/app/src/listeners/mod.rs @@ -30,6 +30,8 @@ pub async fn tell_the_live_streams(event: Event) -> #[listener] pub async fn update_the_builds_that_follow_it(event: Event) -> laravel::Result<()> { crate::domain::reruns::update_followers(event.build_id).await?; + // And the later subset builds of its branch waiting for it to conclude (sc-9763). + crate::domain::reruns::wake_waiting(event.build_id).await?; Ok(()) } diff --git a/app/tests/reruns.rs b/app/tests/reruns.rs index b2de8ce6..e77b7f9a 100644 --- a/app/tests/reruns.rs +++ b/app/tests/reruns.rs @@ -772,3 +772,134 @@ async fn partial_subset(app: Application) -> laravel::Result<()> { ); Ok(()) } + +/// Main's last build was superseded by another branch's review: a skipped main build stands on that review. A +/// rejection keeps it rejected and a superseding build still waiting keeps it waiting; only an approval lets it carry +/// the baseline. +#[laravel::test] +async fn a_skipped_build_behind_a_superseded_build_follows_what_superseded_it(app: Application) -> laravel::Result<()> { + Box::pin(skipped_behind_superseded(app)).await +} + +/// Build #number (a PR build whose history has `parent`) was reviewed: the older pending builds it covers are +/// superseded, as the review routes do, and what follows them hears it. +async fn supersede(number: i64, parent: &str) -> laravel::Result<()> { + let id = build(number).await?.id; + let parents = json!([parent]); + db::query!("UPDATE builds SET parent_commits = {parents} WHERE id = {id}").update().await?; + for superseded in app::domain::reviews::supersede_older(&build(number).await?).await? { + app::events::BuildChanged { build_id: superseded }.dispatch().await?; + } + Ok(()) +} + +async fn skipped_behind_superseded(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + let on = |branch, commit, nonce| Run { name: "pdf", commit, branch, nonce }; + main_baseline(&app, &token).await; + + // #2: main changes the invoice, pending. #3, a PR build on top of it, is rejected and supersedes #2. + run(&app, &token, &on("main", "c2", "w2"), &[("invoice.png", BLUE)]).await; + run(&app, &token, &on("feature", "f1", "w3"), &[("invoice.png", BLUE)]).await; + review(3, "reject").await?; + supersede(3, "c2").await?; + assert_eq!(build(2).await?.review_state, "superseded"); + // #4: main skips. It follows #3, rejected. + let skipped = skip(&app, &token, &on("main", "c3", "w4")).await; + assert_eq!((&skipped["review_state"], &skipped["passed"]), (&json!("rejected"), &json!(false)), "{skipped}"); + assert!(warnings(&skipped).contains(&behind_warning(3)), "{skipped}"); + assert_eq!(build(4).await?.covered_by_build_id, Some(build(3).await?.id)); + let (_, conclusion, title) = check(4).await?; + assert_eq!(conclusion.as_deref(), Some("failure"), "{title}"); + + // The browser suite: #5 is main's first build, #6 changes it on main (pending) and is superseded by #7, a PR build + // that's pending again (its review undone). The skipped #8 waits for #7, and #7's approval turns it green. + let browser = |branch, commit, nonce| Run { name: "browser", commit, branch, nonce }; + run(&app, &token, &browser("main", "c1", "w5a"), &[("home.png", RED)]).await; + run(&app, &token, &browser("main", "c2", "w5"), &[("home.png", BLUE)]).await; + run(&app, &token, &browser("feature", "f1", "w6"), &[("home.png", BLUE)]).await; + review(7, "reject").await?; + supersede(7, "c2").await?; + let id = build(7).await?.id; + db::query!("UPDATE builds SET review_state = 'pending' WHERE id = {id}").update().await?; + db::query!("UPDATE snapshots SET review = NULL WHERE build_id = {id}").update().await?; + assert_eq!(build(6).await?.review_state, "superseded"); + let skipped = skip(&app, &token, &browser("main", "c3", "w7")).await; + assert_eq!(skipped["review_state"], "pending", "{skipped}"); + assert_eq!(build(8).await?.covered_by_build_id, Some(id)); + let (status, conclusion, title) = check(8).await?; + assert_eq!((status.as_str(), conclusion), ("in_progress", None), "{title}"); + review(7, "approve").await?; + let skipped = fetch(&app, &token, &skipped["id"]).await; + assert_eq!((&skipped["review_state"], &skipped["passed"]), (&json!("approved"), &json!(true)), "{skipped}"); + + // A superseding approval settles it: main's next skip carries the baseline and passes on its own. + let next = skip(&app, &token, &browser("main", "c4", "w9")).await; + assert_eq!((&next["conclusion"], &next["passed"]), (&json!("unchanged"), &json!(true)), "{next}"); + assert_eq!(build(9).await?.covered_by_build_id, None); + Ok(()) +} + +/// A partial subset build whose branch's previous build is still being compared waits for it, then carries its +/// unreviewed changes. If it's still being compared after the wait, the build carries what's known and waits for a +/// review, never passing on its own. +#[laravel::test] +async fn a_partial_subset_build_waits_for_the_branchs_previous_build(app: Application) -> laravel::Result<()> { + Box::pin(partial_subset_waits(app)).await +} + +async fn partial_subset_waits(app: Application) -> laravel::Result<()> { + use app::domain::reruns::{WAIT_FOR_PREVIOUS_MINUTES, unfinished_previous_warning, unreviewed_carry_warning}; + fixtures::blob_store().await?; + let token = project_token().await?; + let (invoice, receipt) = ("invoices/a/invoice.png", "receipts/a/receipt.png"); + let on = |branch, commit, nonce| Run { name: "pdf", commit, branch, nonce }; + let store = app::storage::BlobStore::current().await?; + let renderer = app::http::api::builds::renderer_version(); + run(&app, &token, &on("main", "c1", "w1"), &[(invoice, RED), (receipt, RED)]).await; + + // #2 changes the invoice, finalized, its processing not run yet. #3 sends only the receipts group: it waits. + send(&app, &token, &on("feature", "f1", "w2"), &[(invoice, BLUE), (receipt, RED)]).await; + let second = build(2).await?.id; + db::query!("UPDATE builds SET state = 'processing', finalized_at = now() WHERE id = {second}").update().await?; + let waiting = subset(&app, &token, &on("feature", "f2", "w3"), &[(receipt, RED)]).await; + assert_eq!(waiting["state"], "processing", "{waiting}"); + // #2 concludes, and #3 with it, carrying #2's unreviewed invoice. + app::domain::processing::run(second, &store, &renderer).await?; + let done = fetch(&app, &token, &waiting["id"]).await; + assert_eq!( + (&done["state"], &done["conclusion"], &done["review_state"]), + (&json!("completed"), &json!("changes"), &json!("pending")), + "{done}" + ); + assert!(warnings(&done).contains(&unreviewed_carry_warning(1, 2)), "{done}"); + + // #4 on another branch, unchanged and settled; #5 still processing. #6 waits, and after the wait carries what's + // known (nothing unreviewed) and still waits for a review, its check not a success. + run(&app, &token, &on("other", "g1", "w4"), &[(invoice, RED), (receipt, RED)]).await; + send(&app, &token, &on("other", "g2", "w5"), &[(invoice, BLUE), (receipt, RED)]).await; + let fifth = build(5).await?.id; + db::query!("UPDATE builds SET state = 'processing', finalized_at = now() WHERE id = {fifth}").update().await?; + let waiting = subset(&app, &token, &on("other", "g3", "w6"), &[(receipt, RED)]).await; + assert_eq!(waiting["state"], "processing", "{waiting}"); + let sixth = build(6).await?.id; + let minutes = WAIT_FOR_PREVIOUS_MINUTES + 1; + db::query!( + "UPDATE builds SET finalized_at = now() - make_interval(mins => {minutes}), \ + created_at = now() - make_interval(mins => {minutes}) WHERE id = {sixth}" + ) + .update() + .await?; + app::domain::processing::run(sixth, &store, &renderer).await?; + let held = fetch(&app, &token, &waiting["id"]).await; + assert_eq!( + (&held["state"], &held["conclusion"], &held["review_state"]), + (&json!("completed"), &json!("changes"), &json!("pending")), + "{held}" + ); + assert!(warnings(&held).contains(&unfinished_previous_warning(5)), "{held}"); + let (status, conclusion, title) = check(6).await?; + assert_eq!((status.as_str(), conclusion), ("in_progress", None), "{title}"); + Ok(()) +} diff --git a/frontend/content/changelog.md b/frontend/content/changelog.md index cd9a072f..cc498c7b 100644 --- a/frontend/content/changelog.md +++ b/frontend/content/changelog.md @@ -9,7 +9,7 @@ What changed in VisualCI for the people and agents using it, newest first. Dates - **Gallery libraries 0.3.0:** dimensions. Theme and size become two of a gallery's dimensions, and the `dimensions` option adds your own (a language, a plan) or changes theirs (a high-contrast theme, a tablet size). The words in a screenshot's name pick its values, in any order. A switch with four values or more is a drop-down list that follows the WAI-ARIA select-only combobox pattern. A screen without the chosen language shows its first, a screen without the chosen size is hidden, and every screen needs every theme. The "Screenshots by VisualCI" line is off by default; `credit: true` shows it. The markup's attributes change (`data-vg-for`, `data-vg-shown`), so update the JS library with the server libraries. [Dimensions](/docs/gallery/options/#dimensions) - The sign-in page, the GitHub App setup pages ("Finding your GitHub repositories…" and the rest), the waitlist page and the 404 on VisualCI's other hosts are a card in the app's look, light and dark, with a progress bar while VisualCI lists your repositories. -- A CI build that skipped a suite's jobs (`--subset`, finalized with `--allow-empty` or `--empty-reason`) no longer passes on the old baseline while the branch's last build of that suite is waiting for review, rejected or failed: it shows that build's result and turns green when it's approved. A build that skipped some jobs carries the branch's unapproved changes for the snapshots it wasn't sent, for review there. [CircleCI](/docs/ci/circleci/#parallel-jobs) +- A CI build that skipped a suite's jobs (`--subset`, finalized with `--allow-empty` or `--empty-reason`) no longer passes on the old baseline while the branch's last build of that suite is waiting for review, rejected or failed: it shows that build's result and turns green when it's approved. A build superseded by a pull request's review counts as that review. A build that skipped some jobs carries the branch's unapproved changes for the snapshots it wasn't sent, for review there, waiting up to 30 minutes for the branch's last build to finish comparing. [CircleCI](/docs/ci/circleci/#parallel-jobs) - Docs links to headings with an apostrophe work: a heading like "Choose what's public" is at `#choose-whats-public`, where the page used to give it `#choose-what-39-s-public`. The Ruby gem's documentation link goes to the RSpec screenshots page. - A rerun of only the failed jobs no longer fails a suite as empty when the first run's finalizing job never ran: the rerun's empty build finalizes the first run's build, once nothing has arrived for it for 5 minutes (or after VisualCI gave up on it), and shows its result. [CircleCI](/docs/ci/circleci/#rerunning-failed-jobs) - **Gallery libraries 0.2.2, for React, Next.js, Docusaurus, VitePress and MkDocs:** `visualci-gallery-react` (a server component for Next.js's app router), `visualci-gallery-docusaurus`, `visualci-gallery-vitepress`, and an MkDocs plugin in the `visualci-gallery` Python package. Each renders the gallery into the page when the site builds, and fails the build when the manifest can't be read. [Gallery guides](/docs/gallery/#show-it-on-your-site) diff --git a/frontend/content/docs/ci/circleci.md b/frontend/content/docs/ci/circleci.md index ae0457a5..cd1d7549 100644 --- a/frontend/content/docs/ci/circleci.md +++ b/frontend/content/docs/ci/circleci.md @@ -50,7 +50,7 @@ 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. -The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed or added without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. +The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. If that build was superseded by a later review (a pull request's build on top of it), the skipped build goes by that review: an approval lets it pass, a rejection keeps it rejected, and a review still waiting keeps it waiting. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed or added without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. While the branch's last build is still being compared, such a build waits for it (up to 30 minutes; after that it waits for a review instead of passing). ## Rerunning failed jobs diff --git a/frontend/content/docs/ci/github-actions.md b/frontend/content/docs/ci/github-actions.md index 569f4325..d2fc7a7e 100644 --- a/frontend/content/docs/ci/github-actions.md +++ b/frontend/content/docs/ci/github-actions.md @@ -211,7 +211,9 @@ The skipped build passes only when the branch's last build of the suite is appro that build is still being compared, waiting for review, rejected or failed, the skipped build shows its result instead, with a warning naming it, and turns green when that build is approved: a skipped push can't pass on the old baseline while the branch has a change nobody approved. A subset build that sent some snapshots carries the branch's -last unapproved version of each snapshot it wasn't sent, for review in this build (a rejected one stays rejected). +last unapproved version of each snapshot it wasn't sent, for review in this build (a rejected one stays rejected), +waiting up to 30 minutes for that build to finish comparing. A last build superseded by a pull request's review goes by +that review: only an approval lets the skipped build pass. ## Blacksmith, Depot and other runners diff --git a/frontend/content/docs/ci/other.md b/frontend/content/docs/ci/other.md index f54e2401..8af772be 100644 --- a/frontend/content/docs/ci/other.md +++ b/frontend/content/docs/ci/other.md @@ -51,7 +51,7 @@ Parallel jobs can share one build: - Each job uploads its files and runs `visualci build finalize --shard `, with shards numbered from 0. - VisualCI compares the build once all `n` shards have finalized. -Add `--subset` when some jobs may not run. Snapshots that weren't sent are then carried forward instead of counted as removed. A snapshot the branch's last build of the suite changed or added without an approval is carried from that build, for review in this one, rather than from the baseline (a rejected one stays rejected). A build that skipped every job, finalized with `--allow-empty`, shows the result of the branch's last build of the suite when that build is still being compared, waiting for review, rejected or failed, and turns green when it's approved. +Add `--subset` when some jobs may not run. Snapshots that weren't sent are then carried forward instead of counted as removed. A snapshot the branch's last build of the suite changed or added without an approval is carried from that build, for review in this one, rather than from the baseline (a rejected one stays rejected); while that build is still being compared, the subset build waits for it, up to 30 minutes, and after that waits for a review instead of passing. A build that skipped every job, finalized with `--allow-empty`, shows the result of the branch's last build of the suite when that build is still being compared, waiting for review, rejected or failed (or superseded by a review that wasn't an approval), and turns green when it's approved. 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. An earlier build that was sent snapshots but never finalized (its finalizing job didn't run) is finalized by the empty build and followed, once nothing has arrived for it for 5 minutes, even after VisualCI gave up on it at the hour. diff --git a/frontend/content/docs/reference/api.md b/frontend/content/docs/reference/api.md index 9a74ebe2..62c9fbab 100644 --- a/frontend/content/docs/reference/api.md +++ b/frontend/content/docs/reference/api.md @@ -85,7 +85,7 @@ A bundle is a tar archive compressed with zstd (`.tar.zst`). It holds one regula ## Finalize -`POST /api/v1/builds/{id}/finalize`, with an empty body or `{"shard": 0}`. VisualCI compares the build once every shard has finalized. The response is the build. A build that was sent no snapshots fails; send `"allow_empty": true` when it's empty on purpose, or `"empty_reason": "inputs unchanged"`, which implies it and puts the reason in the build's summary with the build its baseline came from. A CI `subset` build finalized empty this way passes on its baseline only when the branch's last build of the suite is approved or had nothing to approve; while that build is being compared, waiting for review, rejected or failed, the empty build shows its result, with a warning naming it, and follows it. +`POST /api/v1/builds/{id}/finalize`, with an empty body or `{"shard": 0}`. VisualCI compares the build once every shard has finalized. The response is the build. A build that was sent no snapshots fails; send `"allow_empty": true` when it's empty on purpose, or `"empty_reason": "inputs unchanged"`, which implies it and puts the reason in the build's summary with the build its baseline came from. A CI `subset` build finalized empty this way passes on its baseline only when the branch's last build of the suite is approved or had nothing to approve; while that build is being compared, waiting for review, rejected or failed (or superseded by a review that wasn't an approval), the empty build shows its result, with a warning naming it, and follows it. ## Read a build diff --git a/plugin/skills/visualci-circleci/SKILL.md b/plugin/skills/visualci-circleci/SKILL.md index e4f46c0d..1732a967 100644 --- a/plugin/skills/visualci-circleci/SKILL.md +++ b/plugin/skills/visualci-circleci/SKILL.md @@ -57,7 +57,7 @@ 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. -The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed or added without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. +The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. If that build was superseded by a later review (a pull request's build on top of it), the skipped build goes by that review: an approval lets it pass, a rejection keeps it rejected, and a review still waiting keeps it waiting. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed or added without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. While the branch's last build is still being compared, such a build waits for it (up to 30 minutes; after that it waits for a review instead of passing). ## Rerunning failed jobs diff --git a/plugin/skills/visualci-github-actions/SKILL.md b/plugin/skills/visualci-github-actions/SKILL.md index 74e2d91f..0daab75b 100644 --- a/plugin/skills/visualci-github-actions/SKILL.md +++ b/plugin/skills/visualci-github-actions/SKILL.md @@ -218,7 +218,9 @@ The skipped build passes only when the branch's last build of the suite is appro that build is still being compared, waiting for review, rejected or failed, the skipped build shows its result instead, with a warning naming it, and turns green when that build is approved: a skipped push can't pass on the old baseline while the branch has a change nobody approved. A subset build that sent some snapshots carries the branch's -last unapproved version of each snapshot it wasn't sent, for review in this build (a rejected one stays rejected). +last unapproved version of each snapshot it wasn't sent, for review in this build (a rejected one stays rejected), +waiting up to 30 minutes for that build to finish comparing. A last build superseded by a pull request's review goes by +that review: only an approval lets the skipped build pass. ## Blacksmith, Depot and other runners From aeac192861369744d3026616488bff69575aa78c Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 08:24:28 +0000 Subject: [PATCH 3/6] Reruns: wrap long lines in the skipped-build warnings and tests --- app/src/domain/reruns.rs | 12 +++++++----- app/tests/reruns.rs | 9 ++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/src/domain/reruns.rs b/app/src/domain/reruns.rs index c149bfa1..84195d0e 100644 --- a/app/src/domain/reruns.rs +++ b/app/src/domain/reruns.rs @@ -30,7 +30,8 @@ //! forward and pass. When no build of its commit covers it (above), it follows the branch's newest earlier build of //! the suite and environment, whatever its commit, if that build's result isn't settled-good ([`behind`]): still //! processing, waiting for review, rejected or failed; a superseded build stands for the review that superseded it -//! ([`superseder`]). It waits, is rejected or fails with it, and turns green when that build is approved. A subset build that sent some groups and skipped others carries, for each skipped snapshot +//! ([`superseder`]). It waits, is rejected or fails with it, and turns green when that build is approved. A subset +//! build that sent some groups and skipped others carries, for each skipped snapshot //! the branch's previous build changed or added without an approval, that build's version instead of the baseline //! ([`unreviewed_carry`]): it's compared with the baseline and waits for a review here, and a rejected one stays //! rejected. While that build is still processing, the subset build waits for it ([`waits_for_previous`]), and past @@ -62,8 +63,9 @@ pub fn covered_warning(number: i32) -> String { pub fn behind_warning(number: i32) -> String { format!( "No snapshots were sent in this run on purpose (its inputs unchanged?), but build #{number} (this branch's \ - last build of the suite, or the build whose review superseded it) isn't approved (waiting for review, rejected or failed), so this build shows its \ - result rather than passing on the old baseline. Review build #{number}, or send this suite's snapshots again." + last build of the suite, or the build whose review superseded it) isn't approved (waiting for review, \ + rejected or failed), so this build shows its result rather than passing on the old baseline. Review build \ + #{number}, or send this suite's snapshots again." ) } @@ -281,8 +283,8 @@ pub const WAIT_FOR_PREVIOUS_MINUTES: i32 = 30; pub fn unfinished_previous_warning(number: i32) -> String { format!( "Build #{number}, this branch's last build of the suite, was still being compared after \ - {WAIT_FOR_PREVIOUS_MINUTES} minutes, so VisualCI couldn't tell whether the snapshots this run didn't send have \ - unreviewed changes there: this build waits for a review instead of passing on the old baseline." + {WAIT_FOR_PREVIOUS_MINUTES} minutes, so VisualCI couldn't tell whether the snapshots this run didn't send \ + have unreviewed changes there: this build waits for a review instead of passing on the old baseline." ) } diff --git a/app/tests/reruns.rs b/app/tests/reruns.rs index e77b7f9a..34b58aeb 100644 --- a/app/tests/reruns.rs +++ b/app/tests/reruns.rs @@ -571,9 +571,12 @@ async fn skipped_behind_rejected(app: Application) -> laravel::Result<()> { // #4 on another branch failed (as `mirror` fails a follower of a failed build); #5 skips and fails too. run(&app, &token, &Run { name: "pdf", commit: "g1", branch: "other", nonce: "w4" }, &[("invoice.png", BLUE)]).await; let id = build(4).await?.id; - db::query!("UPDATE builds SET state = 'failed', conclusion = 'failed', review_state = 'none', error = 'boom' WHERE id = {id}") - .update() - .await?; + db::query!( + "UPDATE builds SET state = 'failed', conclusion = 'failed', review_state = 'none', error = 'boom' \ + WHERE id = {id}" + ) + .update() + .await?; let skipped = skip(&app, &token, &Run { name: "pdf", commit: "g2", branch: "other", nonce: "w5" }).await; assert_eq!( (&skipped["state"], &skipped["conclusion"], &skipped["passed"], &skipped["error"]), From 9ca9c3ad682a57a35bd2101ce209d369ed3d28a7 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 08:57:05 +0000 Subject: [PATCH 4/6] Skipped builds: finalize and follow the branch's unfinished build; followers follow what superseded; unreviewed removals carry (sc-9763) - The branch's previous build may be one sent snapshots but never finalized (receiving, or failed unfinished): a CI subset build finalizes it like reruns::adopt (quiet for ADOPT_AFTER_MINUTES, or given up on) and stands on its review; while it's still receiving, it waits. Adopted on finalizing (the API and MCP handlers queue it first, so a synchronous queue processes it no deeper than the build itself), or before a later run of a build that waited. A follower of a build given up on unfinished runs again rather than failing with it. - mirror resolves a superseded earlier build to the build that superseded it and re-points covered_by_build_id at it: only a superseding approval passes. - unreviewed_carry carries a pending or rejected removal as removed, and applies superseder (superseded by an approval: the baseline stands). --- app/src/domain/builds.rs | 10 +- app/src/domain/processing.rs | 42 ++++- app/src/domain/reruns.rs | 292 +++++++++++++++++++++++++++++------ app/src/http/api/builds.rs | 8 + app/src/listeners/mod.rs | 4 +- app/src/mcp/mod.rs | 10 ++ app/tests/reruns.rs | 167 +++++++++++++++++++- 7 files changed, 460 insertions(+), 73 deletions(-) diff --git a/app/src/domain/builds.rs b/app/src/domain/builds.rs index 9456a8ff..042a8beb 100644 --- a/app/src/domain/builds.rs +++ b/app/src/domain/builds.rs @@ -372,19 +372,13 @@ pub async fn finalize_shard(build: Build, shard: Option, allow_empty: bool) ) .update() .await?; - let finalized = db::query!( + db::query!( "UPDATE builds SET state = 'processing', finalized_at = now(), updated_at = now() \ WHERE id = {id} AND state = 'receiving' AND jsonb_array_length(shards_finalized) >= shard_total" ) .update() .await?; - let build = Build::find_or_fail(id).await?; - // An empty rerun whose suite's earlier build was never finalized finalizes and follows that build. - if finalized > 0 { - super::reruns::adopt(&build).await?; - return Build::find_or_fail(id).await; - } - Ok(build) + Build::find_or_fail(id).await } .await; result.or_else(server) diff --git a/app/src/domain/processing.rs b/app/src/domain/processing.rs index 108997d3..8d041d58 100644 --- a/app/src/domain/processing.rs +++ b/app/src/domain/processing.rs @@ -132,6 +132,14 @@ fn processing_lock_name(build_id: i64) -> String { format!("builds.process:{build_id}") } +/// Whether a run holds the build now ([`exclusive`]). +/// +/// # Errors +/// On a cache error. +pub async fn is_running(build_id: i64) -> laravel::Result { + processing_lock(build_id)?.is_locked().await +} + /// A build's processing lock, to see whether a run holds it. fn processing_lock(build_id: i64) -> laravel::Result { use laravel::time::ToSpan; @@ -205,6 +213,11 @@ pub async fn run(build_id: i64, store: &BlobStore, renderer_version: &str) -> la drop_unneeded_renders(id).await?; return finished(id, build.project_id).await; } + // A subset build whose branch's previous build of the suite went quiet while this one waited finalizes it now + // (sc-9763), outside the build's lock: that build's processing may run at once, and its result reaches this one. + if let Some(adopted) = Box::pin(super::reruns::adopt_on_branch(&build)).await? { + Box::pin(super::reruns::start(id, adopted)).await?; + } let work = move || async move { let build = Build::find_or_fail(id).await?; if build.state != "processing" { @@ -697,11 +710,20 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> // that version, compared with the baseline, rather than the baseline itself: it still needs a review (sc-9763). let unreviewed = super::reruns::unreviewed_carry(&build, &seen, &carry).await?; let from_branch = unreviewed.as_ref().map(|u| &u.rows); - for key in from_branch.into_iter().flat_map(HashMap::keys) { - if !base_snapshots.contains_key(key) { + for (key, row) in from_branch.into_iter().flatten() { + if row.state == "removed" { + // Removed there without an approval: removed here too, not carried. + for keys in carried.values_mut() { + keys.retain(|k| k != key); + } + if base_snapshots.contains_key(key) && !removed.contains(key) { + removed.push(key.clone()); + } + } else if !base_snapshots.contains_key(key) { carried.entry(grouping.key(&key.0)).or_default().push(key.clone()); } } + carried.retain(|_, keys| !keys.is_empty()); let branch_groups: HashSet = from_branch.into_iter().flat_map(HashMap::keys).map(|k| grouping.key(&k.0)).collect(); // A carried group the build sent nothing of, whose baselines one earlier build holds exactly, is read from that @@ -729,13 +751,11 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> } for key in keys { let base = base_snapshots.get(key); - let Some(source) = from_branch.and_then(|rows| rows.get(key)).or(base) else { continue }; + let theirs = from_branch.and_then(|rows| rows.get(key)).filter(|s| s.state != "removed"); + let Some(source) = theirs.or(base) else { continue }; Box::pin(carry_forward(&build, &settings, store, source, base)).await?; } } - if let Some(unreviewed) = &unreviewed { - super::reruns::keep_rejections(id, unreviewed).await?; - } for (name, platform) in &removed { let Some(base) = base_snapshots.get(&(name.clone(), platform.clone())) else { continue }; let pid = laravel::str::uuid7(); @@ -754,6 +774,11 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> .await?; } + // A change the branch's previous build had rejected stays rejected, carried or removed. + if let Some(unreviewed) = &unreviewed { + super::reruns::keep_rejections(id, unreviewed).await?; + } + // The file's settings: a loosening ci_mode it can't use, ignore rules that matched nothing, and whether they hide // more than the base build's (then the build gets a "visualci.yml" item to review). let mut warnings = settings.config_warnings(); @@ -970,8 +995,9 @@ async fn conclude( // the default branch only when its pull request merges (`baselines::record_merge`). A local run's changes always // wait for review: approving one sets the baseline for its branch and environment. let first_on_default = build.mode == "ci" && !has_base && build.branch == default_branch; - // A carried change the branch's previous build had rejected keeps its rejection (`reruns::keep_rejections`). - let rejected = all.iter().any(|s| s.carried_forward && is_change(s) && s.review.as_deref() == Some("rejected")); + // A carried (or removed) change the branch's previous build had rejected keeps its rejection + // (`reruns::keep_rejections`): nothing else in a build being concluded has been reviewed. + let rejected = all.iter().any(|s| is_change(s) && s.review.as_deref() == Some("rejected")); let review_state = match conclusion { "failed" => "none", _ if rejected => "rejected", diff --git a/app/src/domain/reruns.rs b/app/src/domain/reruns.rs index 84195d0e..916551f4 100644 --- a/app/src/domain/reruns.rs +++ b/app/src/domain/reruns.rs @@ -75,9 +75,9 @@ pub fn behind_warning(number: i32) -> String { pub fn unreviewed_carry_warning(count: usize, number: i32) -> String { let (snapshots, were) = if count == 1 { ("snapshot", "was") } else { ("snapshots", "were") }; format!( - "{count} {snapshots} this run didn't send {were} changed in build #{number}, this branch's last build of the \ - suite, and not approved, so this build carries that version and compares it with the baseline: review it \ - here (a rejected change stays rejected)." + "{count} {snapshots} this run didn't send {were} changed, added or removed in build #{number}, this branch's \ + last build of the suite, and not approved, so this build carries that change and compares it with the \ + baseline: review it here (a rejected change stays rejected)." ) } @@ -219,15 +219,39 @@ async fn previous_on_branch(build: &Build, states: &[&str]) -> laravel::Result laravel::Result> { + let (id, project_id, name, environment, branch) = + (build.id, build.project_id, build.name.as_str(), build.environment.as_str(), build.branch.as_str()); + let found: Option = db::query!( + "SELECT b.* FROM builds b WHERE b.project_id = {project_id} AND b.name = {name} \ + AND b.environment = {environment} AND b.branch = {branch} AND b.mode = 'ci' AND b.id < {id} \ + AND (b.state IN ('processing', 'completed') OR (b.state = 'failed' AND b.finalized_at IS NOT NULL) \ + OR (b.state IN ('receiving', 'failed') \ + AND EXISTS (SELECT 1 FROM snapshots s WHERE s.build_id = b.id AND NOT s.carried_forward \ + AND s.state <> 'removed' AND s.platform <> 'visualci'))) \ + ORDER BY b.id DESC LIMIT 1" + ) + .select_one_as() + .await?; + match found { + Some(Build { covered_by_build_id: Some(root), .. }) => Build::find(root).await, + other => Ok(other), + } +} + /// The earlier build a CI build finished empty on purpose follows, when no build of its commit covers it: a subset /// build with `allow_empty` (or an `empty_reason`) that was sent no snapshots and matched no groups (a matched group's /// contents are its baseline's, so carrying the baseline is right). It follows the branch's newest earlier finalized -/// build of the suite and environment ([`previous_on_branch`], whatever its commit, the default branch's included), +/// build of the suite and environment ([`branch_previous`], whatever its commit, the default branch's included), /// unless that build's result is settled-good: completed and unchanged, approved or auto-approved, or closed (its pull /// request was closed). A superseded build stands for the build whose review superseded it ([`superseder`]): only a /// superseding approval is settled-good; a rejection, or a superseding build still waiting, is followed. Anything else -/// (still processing, waiting for review, rejected or failed) and carrying the approved baseline forward would pass a -/// change nobody approved. +/// (still processing, waiting for review, rejected or failed, or left unfinished with snapshots in it: it waits while +/// [`adopt_on_branch`] finalizes it) and carrying the approved baseline forward would pass a change nobody approved. /// /// # Errors /// On a database error. @@ -238,10 +262,8 @@ pub async fn behind(build: &Build) -> laravel::Result> { if !matches!(super::groups::carry(build).await?, Carry::Nothing) || sent(build.id).await? > 0 { return Ok(None); } - let Some(earlier) = previous_on_branch(build, &["processing", "completed", "failed"]).await? else { - return Ok(None); - }; - let earlier = superseder(earlier).await?; + let Some(earlier) = Box::pin(branch_previous(build)).await? else { return Ok(None) }; + let earlier = Box::pin(superseder(earlier)).await?; let unsettled = match earlier.state.as_str() { "completed" => { earlier.conclusion.as_deref() == Some("failed") @@ -283,13 +305,14 @@ pub const WAIT_FOR_PREVIOUS_MINUTES: i32 = 30; pub fn unfinished_previous_warning(number: i32) -> String { format!( "Build #{number}, this branch's last build of the suite, was still being compared after \ - {WAIT_FOR_PREVIOUS_MINUTES} minutes, so VisualCI couldn't tell whether the snapshots this run didn't send \ + {WAIT_FOR_PREVIOUS_MINUTES} minutes (or never finalized), so VisualCI couldn't tell whether the snapshots this run didn't send \ have unreviewed changes there: this build waits for a review instead of passing on the old baseline." ) } /// Whether a CI subset build should wait, processing, for the branch's previous build of its suite (or the build that -/// one follows), which is still processing: its rows say which skipped snapshots carry an unreviewed change. Only for +/// one follows), which hasn't concluded ([`unfinished_previous`]): its rows say which skipped snapshots carry an +/// unreviewed change. Only for /// [`WAIT_FOR_PREVIOUS_MINUTES`] after the build was finalized. The previous build's conclusion wakes it /// ([`wake_waiting`]); the sweep restarts it too. /// @@ -310,13 +333,20 @@ pub async fn waits_for_previous(build: &Build) -> laravel::Result { Ok(recent == Some(true)) } -/// The branch's previous build of a CI subset build's suite (or the build it follows), when it's still processing. +/// The branch's previous build of a CI subset build's suite ([`branch_previous`]), when it hasn't concluded: still +/// processing, still receiving, or failed before it was finalized with snapshots in it (until [`adopt_on_branch`] +/// finalizes it). async fn unfinished_previous(build: &Build) -> laravel::Result> { if build.mode != "ci" || !build.subset { return Ok(None); } - let previous = previous_on_branch(build, &["processing", "completed"]).await?; - Ok(previous.filter(|p| p.state == "processing")) + let Some(previous) = branch_previous(build).await? else { return Ok(None) }; + let unfinished = match previous.state.as_str() { + "processing" | "receiving" => true, + "failed" => previous.finalized_at.is_none(), + _ => false, + }; + Ok(unfinished.then_some(previous)) } /// A build concluded: the later CI subset builds of its suite, environment and branch that are still processing @@ -337,17 +367,26 @@ pub async fn wake_waiting(build_id: i64) -> laravel::Result { ) .select_as() .await?; - for waiting in &waiting { - crate::jobs::process_build::ProcessBuild { build_id: *waiting }.dispatch().await?; + let mut woken = 0; + for waiting in waiting { + // A run holding it now (the one that finalized this build) goes on to process it. + if processing::is_running(waiting).await? + || laravel::cache::get::(&adopting_key(waiting)).await?.is_some() + { + continue; + } + Box::pin(crate::jobs::process_build::ProcessBuild { build_id: waiting }.dispatch().into_future()).await?; + woken += 1; } - Ok(waiting.len()) + Ok(woken) } /// What a CI subset build carries instead of the baseline for the snapshots it didn't send (sc-9763). pub struct UnreviewedCarry { /// The branch's previous build those versions are from. pub number: i32, - /// By (name, platform): the previous build's row, to carry and compare with the baseline. + /// By (name, platform): the previous build's row, to carry and compare with the baseline (a `removed` one is + /// removed here too). pub rows: HashMap<(String, String), Snapshot>, /// The branch's newer previous build, still processing after [`WAIT_FOR_PREVIOUS_MINUTES`]: what it changed isn't /// known, so the build waits for a review ([`unfinished_previous_warning`]), never approved on its own. @@ -356,8 +395,8 @@ pub struct UnreviewedCarry { /// For a CI subset build, the snapshots it didn't send (nor carries as a matched group, whose contents are its /// baseline's) that the branch's previous build of the suite and environment (its newest earlier completed build, or -/// the build that one follows) changed or added without an approval, rejected ones included: that build's rows, to -/// carry instead of the baseline. When the newest previous build is still processing (the build stopped waiting for +/// the build that one follows) changed, added or removed without an approval, rejected ones included: that build's +/// rows, to carry (or remove) instead of carrying the baseline. A previous build superseded by an approval has none. When the newest previous build is still processing (the build stopped waiting for /// it, [`waits_for_previous`]), the rows are the newest completed one's, and `unfinished` names it. `None` when there /// are none and nothing is unfinished. /// @@ -375,10 +414,15 @@ pub async fn unreviewed_carry( let Some(previous) = previous_on_branch(build, &["completed"]).await? else { return Ok(unfinished.map(|_| UnreviewedCarry { number: 0, rows: HashMap::new(), unfinished })); }; + // Superseded by an approval: a later review covered its changes, and the baseline stands. + let settled = superseder(previous.clone()).await?; + if settled.id != previous.id && matches!(settled.review_state.as_str(), "approved" | "auto_approved") { + return Ok(unfinished.map(|_| UnreviewedCarry { number: previous.number, rows: HashMap::new(), unfinished })); + } let rows: HashMap<(String, String), Snapshot> = super::snapshots::of_build(previous.id) .await? .into_iter() - .filter(|s| matches!(s.state.as_str(), "changed" | "added") && !is_config_item(s)) + .filter(|s| matches!(s.state.as_str(), "changed" | "added" | "removed") && !is_config_item(s)) .filter(|s| s.review.as_deref() != Some("approved")) .filter(|s| !carry.covers(&s.name)) .map(|s| ((s.name.clone(), s.platform.clone()), s)) @@ -397,7 +441,8 @@ pub async fn keep_rejections(build_id: i64, carried: &UnreviewedCarry) -> larave { db::query!( "UPDATE snapshots SET review = 'rejected', updated_at = now() WHERE build_id = {build_id} \ - AND name = {name} AND platform = {platform} AND carried_forward AND state IN ('changed', 'added')" + AND name = {name} AND platform = {platform} AND (carried_forward OR state = 'removed') \ + AND state IN ('changed', 'added', 'removed')" ) .update() .await?; @@ -406,21 +451,43 @@ pub async fn keep_rejections(build_id: i64, carried: &UnreviewedCarry) -> larave } /// When an empty CI build is finalized and no finalized build covers its commit, but an [`unfinished`] one does: it -/// follows that build, which is finalized with [`adopted_warning`] and queued. Called on finalizing, before the empty -/// build is processed, so [`follow`] finds it following and the two are processed one after the other. +/// follows that build, which is finalized with [`adopted_warning`]. Otherwise the branch's unfinished build, if any +/// ([`adopt_on_branch`]). Called on finalizing, before the build is processed: returns the build it finalized, for the +/// caller to [`start`] before it processes this one, so [`follow`] finds it following and the two are processed one +/// after the other. /// /// # Errors /// On a database or queue error. -pub async fn adopt(build: &Build) -> laravel::Result<()> { +pub async fn adopt(build: &Build) -> laravel::Result> { if build.mode != "ci" || build.state != "processing" || build.covered_by_build_id.is_some() { - return Ok(()); + return Ok(None); } if sent(build.id).await? > 0 || covering(build).await?.is_some() { - return Ok(()); + // Not a rerun of this commit: the branch's unfinished build, if any (sc-9763). + return Box::pin(adopt_on_branch(build)).await; + } + let Some(earlier) = unfinished(build).await? else { return Box::pin(adopt_on_branch(build)).await }; + if !Box::pin(claim(&earlier, &adopted_warning(build.number))).await? { + // Finalized, expired or adopted meanwhile: processing decides what the empty build does. + return Ok(None); } - let Some(earlier) = unfinished(build).await? else { return Ok(()) }; - // A failed build is reopened: its error, conclusion and review state are processing's to set again. - let (id, state, warning) = (earlier.id, earlier.state.as_str(), adopted_warning(build.number)); + let mut me = build.clone(); + let warnings = with_warning(&me, &earlier, true); + update!(me { covered_by_build_id: Some(earlier.id), warnings }).await?; + tracing::info!( + build_id = earlier.id, + by = build.id, + from = earlier.state.as_str(), + "an empty rerun finalized the unfinished build of its commit" + ); + Ok(Some(earlier.id)) +} + +/// Finalize an unfinished build for a later one, with `warning`: one still receiving is finalized, one that failed +/// unfinished is reopened (its error, conclusion and review state are processing's to set again). Only while it's as +/// `earlier` says, follows no build and was never finalized. Returns whether it was. +async fn claim(earlier: &Build, warning: &str) -> laravel::Result { + let (id, state) = (earlier.id, earlier.state.as_str()); let finalized = db::query!( "UPDATE builds SET state = 'processing', finalized_at = now(), updated_at = now(), \ error = NULL, error_code = NULL, conclusion = NULL, review_state = 'none', completed_at = NULL, \ @@ -430,29 +497,128 @@ pub async fn adopt(build: &Build) -> laravel::Result<()> { ) .select() .await?; - if finalized.is_empty() { - // Finalized, expired or adopted meanwhile: processing decides what the empty build does. - return Ok(()); + Ok(!finalized.is_empty()) +} + +/// Process a build [`adopt`] or [`adopt_on_branch`] finalized for build `by`, unless its organization is out of +/// credits. Its conclusion doesn't run `by` from within (a synchronous queue: [`wake_waiting`] skips it meanwhile): +/// the caller processes `by` next. +/// +/// # Errors +/// On a database, cache or queue error. +pub async fn start(by: i64, id: i64) -> laravel::Result<()> { + if Box::pin(ready(by, id)).await? { + Box::pin(crate::jobs::process_build::ProcessBuild { build_id: id }.dispatch().into_future()).await?; } - let mut me = build.clone(); - let warnings = with_warning(&me, &earlier, true); - update!(me { covered_by_build_id: Some(earlier.id), warnings }).await?; - tracing::info!( - build_id = id, - by = build.id, - from = state, - "an empty rerun finalized the unfinished build of its commit" - ); - // Within a request (finalizing through the API or MCP): never wait on Stripe for an automatic reload (sc-9146). + started(by).await +} + +/// [`start`] in two halves, for a caller that queues the build itself (a request handler, so a synchronous queue +/// processes it no deeper than the build it finalized): whether to queue `id` now (out of credits, it's stopped +/// instead), and `by` is marked as finalizing it. Call [`started`] after queueing. +/// +/// # Errors +/// On a database, cache or queue error. +pub async fn ready(by: i64, id: i64) -> laravel::Result { + use laravel::time::ToSpan; + laravel::cache::put(&adopting_key(by), true, 10.minutes()).await?; + // Possibly within a request (finalizing through the API or MCP): never wait on Stripe for an automatic reload + // (sc-9146). let earlier = processing::stop_if_out_of_credits_without_reloading(Build::find_or_fail(id).await?).await?; if earlier.state == "processing" { - crate::jobs::process_build::ProcessBuild { build_id: id }.dispatch().await?; - } else { - crate::events::BuildChanged { build_id: id }.dispatch().await?; + return Ok(true); } + Box::pin(crate::events::BuildChanged { build_id: id }.dispatch().into_future()).await?; + Ok(false) +} + +/// The end of [`start`]: `by` is no longer finalizing another build. +/// +/// # Errors +/// On a cache error. +pub async fn started(by: i64) -> laravel::Result<()> { + laravel::cache::forget(&adopting_key(by)).await?; Ok(()) } +/// The warning on an unfinished branch build that a later skipped build of the branch finalized ([`adopt_on_branch`]). +#[must_use] +pub fn adopted_on_branch_warning(number: i32) -> String { + format!( + "{ADOPTED_PREFIX}{number}: this run's jobs sent their snapshots but the job that finalizes never ran (a \ + failed job before it?), and build #{number}, a later run on this branch that skipped this suite, stands on \ + its review." + ) +} + +/// Whether a build was left unfinished with snapshots in it, so a later build may finalize it: it follows no build, +/// was sent at least one snapshot, and either is still receiving with nothing arriving for [`ADOPT_AFTER_MINUTES`] (no +/// snapshot or bundle upload, and no bundle still being sent or unpacked), or failed only because it was never +/// finalized ([`processing::ABANDONED`], [`processing::run_ended_error`]). [`unfinished`]'s test, for one build. +async fn adoptable(build_id: i64) -> laravel::Result { + let (id, minutes, abandoned, run_ended) = + (build_id, ADOPT_AFTER_MINUTES, processing::ABANDONED, run_ended_pattern()); + let found: Option = db::query!( + "SELECT EXISTS (SELECT 1 FROM builds b WHERE b.id = {id} AND b.mode = 'ci' AND b.covered_by_build_id IS NULL \ + AND EXISTS (SELECT 1 FROM snapshots s WHERE s.build_id = b.id AND NOT s.carried_forward \ + AND s.state <> 'removed' AND s.platform <> 'visualci') \ + AND ((b.state = 'receiving' \ + AND NOT EXISTS (SELECT 1 FROM bundle_uploads u WHERE u.build_id = b.id \ + AND u.state IN ('pending', 'uploaded', 'unpacking')) \ + AND GREATEST(b.updated_at, \ + COALESCE((SELECT MAX(s.updated_at) FROM snapshots s WHERE s.build_id = b.id), b.created_at), \ + COALESCE((SELECT MAX(u.updated_at) FROM bundle_uploads u WHERE u.build_id = b.id), b.created_at)) \ + < now() - make_interval(mins => {minutes})) \ + OR (b.state = 'failed' AND b.finalized_at IS NULL \ + AND (b.error = {abandoned} OR b.error LIKE {run_ended}))))" + ) + .scalar() + .await?; + Ok(found == Some(true)) +} + +/// Before a CI subset build is processed: when the branch's previous build of its suite ([`branch_previous`]) was +/// left unfinished with snapshots in it ([`adoptable`]: quiet while receiving, or failed because it was never +/// finalized), finalize it and process it, so this build can stand on its result ([`behind`], [`waits_for_previous`]) +/// rather than pass on a baseline that leaves its snapshots out. Its snapshots are an earlier commit's, but this build +/// skipped those jobs because their inputs hadn't changed since. A build of its own commit keeps priority: one that +/// already follows another build, or an empty one an earlier build of its commit covers, is left alone. Called on +/// finalizing ([`adopt`]), and before each processing run outside the build's lock (`processing::run`), for a build +/// that waited while that build was still receiving. Returns the build it finalized, for the caller to [`start`]. +/// +/// # Errors +/// On a database or queue error. +pub async fn adopt_on_branch(build: &Build) -> laravel::Result> { + if build.mode != "ci" || !build.subset || build.state != "processing" { + return Ok(None); + } + let Some(previous) = Box::pin(branch_previous(build)).await? else { return Ok(None) }; + if build.covered_by_build_id.is_some_and(|id| id != previous.id) { + return Ok(None); + } + if build.covered_by_build_id.is_none() && sent(build.id).await? == 0 && covering(build).await?.is_some() { + return Ok(None); + } + if !matches!(previous.state.as_str(), "receiving" | "failed") || !adoptable(previous.id).await? { + return Ok(None); + } + if !Box::pin(claim(&previous, &adopted_on_branch_warning(build.number))).await? { + return Ok(None); + } + tracing::info!( + build_id = previous.id, + by = build.id, + from = previous.state.as_str(), + "a skipped build finalized the unfinished build of its branch" + ); + Ok(Some(previous.id)) +} + +/// Set while a build is finalizing the branch's unfinished build ([`adopt_on_branch`]). +fn adopting_key(build_id: i64) -> String { + format!("builds.adopting-on-branch:{build_id}") +} + /// The earlier build this CI build is the other half of, when a workflow runs on both `push` and `pull_request`: the /// newest earlier CI build of the same project, suite, environment, commit, branch, visualci.yml, base branch, subset /// and shards that was finalized, wasn't empty and follows no build itself, whose sent snapshots are this build's, @@ -518,7 +684,7 @@ pub async fn follow(build: &Build) -> laravel::Result> { // Same commit first ([`covering`]; [`adopt`] set `covered_by_build_id` on finalizing), then the branch. None if empty => match covering(build).await? { Some(earlier) => Some(earlier), - None => behind(build).await?, + None => Box::pin(behind(build)).await?, }, None => twin(build).await?, }; @@ -555,16 +721,24 @@ fn with_warning(build: &Build, earlier: &Build, empty: bool) -> serde_json::Valu } /// 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 +/// failed earlier build fails it). A superseded earlier build gives the result of the build that superseded it +/// ([`superseder`]), which the build follows from then on. 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 { + // A superseded build stands for the review that superseded it: the follower follows that build from now on, so + // only a superseding approval passes it (a neutral "Superseded" check would pass a gate). + let followed = earlier.id; + let resolved = Box::pin(superseder(earlier.clone())).await?; + let earlier = &resolved; 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); + let follows = build.state == "processing" + || build.covered_by_build_id == Some(followed) + || build.covered_by_build_id == Some(earlier.id); if !follows || build.mode != "ci" { return Ok(false); } @@ -621,9 +795,25 @@ pub async fn update_followers(build_id: i64) -> laravel::Result { if !matches!(earlier.state.as_str(), "completed" | "failed") { return Ok(0); } + // Given up on before it was finalized (no finalizing job ran): its failure isn't a result. The followers still + // processing run again, and finalize it ([`adopt_on_branch`]) rather than fail with it. + if earlier.state == "failed" && earlier.finalized_at.is_none() && Box::pin(adoptable(earlier.id)).await? { + let waiting: Vec = db::query!( + "SELECT id FROM builds WHERE covered_by_build_id = {id} AND state = 'processing' AND subset ORDER BY id" + ) + .select_as() + .await?; + if !waiting.is_empty() { + for follower in &waiting { + Box::pin(crate::jobs::process_build::ProcessBuild { build_id: *follower }.dispatch().into_future()) + .await?; + } + return Ok(0); + } + } let mut changed = 0; for follower in followers { - if mirror(follower, &earlier).await? { + if Box::pin(mirror(follower, &earlier)).await? { changed += 1; crate::events::BuildChanged { build_id: follower }.dispatch().await?; } diff --git a/app/src/http/api/builds.rs b/app/src/http/api/builds.rs index efd06202..039d16ac 100644 --- a/app/src/http/api/builds.rs +++ b/app/src/http/api/builds.rs @@ -355,6 +355,14 @@ pub async fn finalize( build }; if was_receiving && build.state == "processing" { + // An empty rerun whose suite's earlier build was never finalized, or a skipped build whose branch's + // previous build was left unfinished, finalizes that build: it's processed first (`reruns::adopt`). + if let Some(adopted) = Box::pin(crate::domain::reruns::adopt(&build)).await? { + if crate::domain::reruns::ready(build.id, adopted).await? { + crate::jobs::process_build::ProcessBuild { build_id: adopted }.dispatch().await?; + } + crate::domain::reruns::started(build.id).await?; + } crate::live::tell(project.id, Some(build.id)).await; crate::jobs::process_build::ProcessBuild { build_id: build.id }.dispatch().await?; } else if was_receiving && build.state == "failed" { diff --git a/app/src/listeners/mod.rs b/app/src/listeners/mod.rs index f586ad37..8dee2f85 100644 --- a/app/src/listeners/mod.rs +++ b/app/src/listeners/mod.rs @@ -29,9 +29,9 @@ pub async fn tell_the_live_streams(event: Event) -> /// 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?; + Box::pin(crate::domain::reruns::update_followers(event.build_id)).await?; // And the later subset builds of its branch waiting for it to conclude (sc-9763). - crate::domain::reruns::wake_waiting(event.build_id).await?; + Box::pin(crate::domain::reruns::wake_waiting(event.build_id)).await?; Ok(()) } diff --git a/app/src/mcp/mod.rs b/app/src/mcp/mod.rs index 17653b90..eeb8c5fe 100644 --- a/app/src/mcp/mod.rs +++ b/app/src/mcp/mod.rs @@ -2045,6 +2045,16 @@ impl VisualCi { build }; if was_receiving && build.state == "processing" { + // The unfinished build an empty rerun or a skipped build finalizes is processed first (`reruns::adopt`). + if let Some(adopted) = Box::pin(domain::reruns::adopt(&build)).await.map_err(internal)? { + if domain::reruns::ready(build.id, adopted).await.map_err(internal)? { + crate::jobs::process_build::ProcessBuild { build_id: adopted } + .dispatch() + .await + .map_err(internal)?; + } + domain::reruns::started(build.id).await.map_err(internal)?; + } crate::jobs::process_build::ProcessBuild { build_id: build.id }.dispatch().await.map_err(internal)?; } else if was_receiving && build.state == "failed" { crate::events::BuildChanged { build_id: build.id }.dispatch().await.map_err(internal)?; diff --git a/app/tests/reruns.rs b/app/tests/reruns.rs index 34b58aeb..8adf73b5 100644 --- a/app/tests/reruns.rs +++ b/app/tests/reruns.rs @@ -769,10 +769,7 @@ async fn partial_subset(app: Application) -> laravel::Result<()> { review(6, "approve").await?; let partial = subset(&app, &token, &on("approved", "p2", "w7"), &[(receipt, BLUE)]).await; assert_eq!((&partial["conclusion"], &partial["passed"]), (&json!("unchanged"), &json!(true)), "{partial}"); - assert!( - !warnings(&partial).iter().any(|w| w.contains("this branch's last build of the suite, and not approved")), - "{partial}" - ); + assert!(!warnings(&partial).iter().any(|w| w.contains("last build of the suite, and not approved")), "{partial}"); Ok(()) } @@ -906,3 +903,165 @@ async fn partial_subset_waits(app: Application) -> laravel::Result<()> { assert_eq!((status.as_str(), conclusion), ("in_progress", None), "{title}"); Ok(()) } + +/// The branch's previous build was sent its snapshots but never finalized (another job failed before the finalizing +/// one), and the next push skips the suite. The skipped build mustn't pass on the older baseline: it finalizes that +/// build (quiet) or reopens it (given up on), and stands on its review; while it's still receiving, it waits. A partial +/// subset build carries from it once it's finalized. +#[laravel::test] +async fn a_skipped_build_finalizes_and_follows_the_branchs_unfinished_build(app: Application) -> laravel::Result<()> { + Box::pin(behind_unfinished(app)).await +} + +async fn behind_unfinished(app: Application) -> laravel::Result<()> { + use app::domain::reruns::{adopted_on_branch_warning, unreviewed_carry_warning}; + fixtures::blob_store().await?; + let token = project_token().await?; + let on = |branch, commit, nonce| Run { name: "pdf", commit, branch, nonce }; + main_baseline(&app, &token).await; + let pending = |build: &Value| (build["state"].clone(), build["review_state"].clone()); + let waiting = (json!("completed"), json!("pending")); + + // Quiet: #2 sent, never finalized. #3 skips: it finalizes #2 and follows it, waiting for its review. + send(&app, &token, &on("feature", "f1", "w2"), &[("invoice.png", BLUE)]).await; + quiet(build(2).await?.id).await?; + let skipped = skip(&app, &token, &on("feature", "f2", "w3")).await; + let adopted = build(2).await?; + assert_eq!((adopted.state.as_str(), adopted.review_state.as_str()), ("completed", "pending"), "{adopted:?}"); + let adopted_warnings: Vec = serde_json::from_value(adopted.warnings.clone()).unwrap_or_default(); + assert!(adopted_warnings.contains(&adopted_on_branch_warning(3)), "{adopted_warnings:?}"); + assert_eq!(pending(&skipped), waiting, "{skipped}"); + assert_eq!(build(3).await?.covered_by_build_id, Some(adopted.id)); + let (status, conclusion, title) = check(3).await?; + assert_eq!((status.as_str(), conclusion), ("in_progress", None), "{title}"); + + // Still receiving: #5 waits, processing. Once #4 is quiet, #5's next run finalizes it and follows it. + send(&app, &token, &on("active", "a1", "w4"), &[("invoice.png", BLUE)]).await; + let skipped = skip(&app, &token, &on("active", "a2", "w5")).await; + assert_eq!(skipped["state"], "processing", "{skipped}"); + assert_eq!(build(4).await?.state, "receiving"); + let (status, _, title) = check(5).await?; + assert_eq!(status, "in_progress", "{title}"); + quiet(build(4).await?.id).await?; + let store = app::storage::BlobStore::current().await?; + let renderer = app::http::api::builds::renderer_version(); + app::domain::processing::run(build(5).await?.id, &store, &renderer).await?; + assert_eq!(build(4).await?.state, "completed"); + let skipped = fetch(&app, &token, &skipped["id"]).await; + assert_eq!(pending(&skipped), waiting, "{skipped}"); + assert_eq!(build(5).await?.covered_by_build_id, Some(build(4).await?.id)); + + // Given up on at the hour: #7 reopens #6 and follows it, rather than failing with "Nothing arrived". + send(&app, &token, &on("gone", "g1", "w6"), &[("invoice.png", BLUE)]).await; + let id = build(6).await?.id; + db::query!( + "UPDATE builds SET updated_at = now() - interval '61 minutes', created_at = now() - interval '62 minutes' \ + WHERE id = {id}" + ) + .update() + .await?; + db::query!("UPDATE snapshots SET updated_at = now() - interval '61 minutes' WHERE build_id = {id}") + .update() + .await?; + app::domain::processing::expire_abandoned(Some(build(6).await?.project_id)).await?; + assert_eq!(build(6).await?.state, "failed"); + let skipped = skip(&app, &token, &on("gone", "g2", "w7")).await; + assert_eq!(build(6).await?.state, "completed"); + assert_eq!(pending(&skipped), waiting, "{skipped}"); + assert_eq!(skipped["error"], Value::Null, "{skipped}"); + assert_eq!(build(7).await?.covered_by_build_id, Some(id)); + + // A partial subset build behind an unfinished build: it finalizes it, then carries its unreviewed invoice. + let (invoice, receipt) = ("invoices/a/invoice.png", "receipts/a/receipt.png"); + let docs = |branch, commit, nonce| Run { name: "docs", commit, branch, nonce }; + run(&app, &token, &docs("main", "c1", "w8"), &[(invoice, RED), (receipt, RED)]).await; + send(&app, &token, &docs("feature", "f1", "w9"), &[(invoice, BLUE), (receipt, RED)]).await; + quiet(build(9).await?.id).await?; + let partial = subset(&app, &token, &docs("feature", "f2", "w10"), &[(receipt, RED)]).await; + let partial = fetch(&app, &token, &partial["id"]).await; + assert_eq!(build(9).await?.state, "completed"); + assert_eq!( + (&partial["state"], &partial["conclusion"], &partial["review_state"]), + (&json!("completed"), &json!("changes"), &json!("pending")), + "{partial}" + ); + assert!(warnings(&partial).contains(&unreviewed_carry_warning(1, 9)), "{partial}"); + Ok(()) +} + +/// A skipped build already follows the branch's pending build when a pull request's review supersedes that build: it +/// follows the superseding build from then on. A rejection keeps it rejected (never a neutral "Superseded" check), and +/// only an approval passes it. +#[laravel::test] +async fn a_follower_of_a_build_superseded_later_follows_the_superseding_build(app: Application) -> laravel::Result<()> { + Box::pin(follower_superseded_later(app)).await +} + +async fn follower_superseded_later(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + main_baseline(&app, &token).await; + let pdf = |branch, commit, nonce| Run { name: "pdf", commit, branch, nonce }; + + // #2 main pending; #3 skips and follows it; then #4, a PR build on top of c2, is rejected and supersedes #2. + run(&app, &token, &pdf("main", "c2", "w2"), &[("invoice.png", BLUE)]).await; + let skipped = skip(&app, &token, &pdf("main", "c3", "w3")).await; + assert_eq!(skipped["review_state"], "pending", "{skipped}"); + assert_eq!(build(3).await?.covered_by_build_id, Some(build(2).await?.id)); + run(&app, &token, &pdf("feature", "f1", "w4"), &[("invoice.png", BLUE)]).await; + review(4, "reject").await?; + supersede(4, "c2").await?; + assert_eq!(build(2).await?.review_state, "superseded"); + let skipped = fetch(&app, &token, &skipped["id"]).await; + assert_eq!((&skipped["review_state"], &skipped["passed"]), (&json!("rejected"), &json!(false)), "{skipped}"); + assert_eq!(build(3).await?.covered_by_build_id, Some(build(4).await?.id)); + let (status, conclusion, title) = check(3).await?; + assert_eq!((status.as_str(), conclusion.as_deref()), ("completed", Some("failure")), "{title}"); + + // The same order with an approval: the follower passes. + let browser = |branch, commit, nonce| Run { name: "browser", commit, branch, nonce }; + run(&app, &token, &browser("main", "c1", "w5"), &[("home.png", RED)]).await; + run(&app, &token, &browser("main", "c2", "w6"), &[("home.png", BLUE)]).await; + let skipped = skip(&app, &token, &browser("main", "c3", "w7")).await; + assert_eq!(build(7).await?.covered_by_build_id, Some(build(6).await?.id)); + run(&app, &token, &browser("feature", "f1", "w8"), &[("home.png", BLUE)]).await; + review(8, "approve").await?; + supersede(8, "c2").await?; + let skipped = fetch(&app, &token, &skipped["id"]).await; + assert_eq!((&skipped["review_state"], &skipped["passed"]), (&json!("approved"), &json!(true)), "{skipped}"); + let (status, conclusion, title) = check(7).await?; + assert_eq!((status.as_str(), conclusion.as_deref()), ("completed", Some("success")), "{title}"); + Ok(()) +} + +/// The branch's previous build removed a snapshot, and the removal isn't approved: a partial subset build that skipped +/// it shows it removed too, waiting for a review, rather than carrying the baseline as unchanged. +#[laravel::test] +async fn a_partial_subset_build_keeps_the_branchs_unreviewed_removal(app: Application) -> laravel::Result<()> { + Box::pin(partial_subset_removal(app)).await +} + +async fn partial_subset_removal(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + let (invoice, receipt) = ("invoices/a/invoice.png", "receipts/a/receipt.png"); + let on = |branch, commit, nonce| Run { name: "pdf", commit, branch, nonce }; + run(&app, &token, &on("main", "c1", "w1"), &[(invoice, RED), (receipt, RED)]).await; + + // #2 sends everything but the invoice: removed, waiting for review. #3 sends only the receipts group. + let removing = run(&app, &token, &on("feature", "f1", "w2"), &[(receipt, RED)]).await; + assert_eq!(removing["review_state"], "pending", "{removing}"); + let partial = subset(&app, &token, &on("feature", "f2", "w3"), &[(receipt, RED)]).await; + assert_eq!((&partial["conclusion"], &partial["review_state"]), (&json!("changes"), &json!("pending")), "{partial}"); + let rows = app::domain::snapshots::of_build(build(3).await?.id).await?; + let state = |name: &str| rows.iter().find(|s| s.name == name).map(|s| s.state.clone()); + assert_eq!((state(invoice).as_deref(), state(receipt).as_deref()), (Some("removed"), Some("unchanged"))); + let (status, conclusion, title) = check(3).await?; + assert_eq!((status.as_str(), conclusion), ("in_progress", None), "{title}"); + + // Rejected there (#3, the branch's last build), it stays rejected here. + review(3, "reject").await?; + let partial = subset(&app, &token, &on("feature", "f3", "w4"), &[(receipt, RED)]).await; + assert_eq!(partial["review_state"], "rejected", "{partial}"); + Ok(()) +} From 6a7d33f8f19639621d64cf51f7f71fa49518e5a7 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 08:57:13 +0000 Subject: [PATCH 5/6] Skipped builds: docs for unfinished, superseded-after and removed cases; wrap long doc lines (sc-9763) --- app/src/domain/reruns.rs | 25 ++++++++++--------- frontend/content/changelog.md | 2 +- frontend/content/docs/ci/circleci.md | 2 +- frontend/content/docs/ci/github-actions.md | 3 ++- frontend/content/docs/ci/other.md | 2 +- plugin/skills/visualci-circleci/SKILL.md | 2 +- .../skills/visualci-github-actions/SKILL.md | 3 ++- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/src/domain/reruns.rs b/app/src/domain/reruns.rs index 916551f4..a50b1725 100644 --- a/app/src/domain/reruns.rs +++ b/app/src/domain/reruns.rs @@ -219,10 +219,10 @@ async fn previous_on_branch(build: &Build, states: &[&str]) -> laravel::Result laravel::Result> { let (id, project_id, name, environment, branch) = (build.id, build.project_id, build.name.as_str(), build.environment.as_str(), build.branch.as_str()); @@ -304,9 +304,9 @@ pub const WAIT_FOR_PREVIOUS_MINUTES: i32 = 30; #[must_use] pub fn unfinished_previous_warning(number: i32) -> String { format!( - "Build #{number}, this branch's last build of the suite, was still being compared after \ - {WAIT_FOR_PREVIOUS_MINUTES} minutes (or never finalized), so VisualCI couldn't tell whether the snapshots this run didn't send \ - have unreviewed changes there: this build waits for a review instead of passing on the old baseline." + "Build #{number}, this branch's last build of the suite, was still being compared (or was never finalized) \ + after {WAIT_FOR_PREVIOUS_MINUTES} minutes, so VisualCI couldn't tell whether the snapshots this run didn't \ + send have unreviewed changes there: this build waits for a review instead of passing on the old baseline." ) } @@ -396,9 +396,9 @@ pub struct UnreviewedCarry { /// For a CI subset build, the snapshots it didn't send (nor carries as a matched group, whose contents are its /// baseline's) that the branch's previous build of the suite and environment (its newest earlier completed build, or /// the build that one follows) changed, added or removed without an approval, rejected ones included: that build's -/// rows, to carry (or remove) instead of carrying the baseline. A previous build superseded by an approval has none. When the newest previous build is still processing (the build stopped waiting for -/// it, [`waits_for_previous`]), the rows are the newest completed one's, and `unfinished` names it. `None` when there -/// are none and nothing is unfinished. +/// rows, to carry (or remove) instead of carrying the baseline. A previous build superseded by an approval has none. +/// When the newest previous build hasn't concluded (the build stopped waiting for it, [`waits_for_previous`]), the rows +/// are the newest completed one's, and `unfinished` names it. `None` when there are none and nothing is unfinished. /// /// # Errors /// On a database error. @@ -722,8 +722,9 @@ fn with_warning(build: &Build, earlier: &Build, empty: bool) -> serde_json::Valu /// Give the build the earlier build's result: completed, with its conclusion, review state and superseding build (a /// failed earlier build fails it). A superseded earlier build gives the result of the build that superseded it -/// ([`superseder`]), which the build follows from then on. Under the build's advisory lock; only a build still processing, or one that already -/// follows `earlier`. Returns whether anything changed. +/// ([`superseder`]), which the build follows from then on. Under the build's advisory lock; only a build still +/// processing, or one that already follows `earlier` (or the build that superseded it). Returns whether anything +/// changed. /// /// # Errors /// On a database error. diff --git a/frontend/content/changelog.md b/frontend/content/changelog.md index cc498c7b..2bbcd469 100644 --- a/frontend/content/changelog.md +++ b/frontend/content/changelog.md @@ -9,7 +9,7 @@ What changed in VisualCI for the people and agents using it, newest first. Dates - **Gallery libraries 0.3.0:** dimensions. Theme and size become two of a gallery's dimensions, and the `dimensions` option adds your own (a language, a plan) or changes theirs (a high-contrast theme, a tablet size). The words in a screenshot's name pick its values, in any order. A switch with four values or more is a drop-down list that follows the WAI-ARIA select-only combobox pattern. A screen without the chosen language shows its first, a screen without the chosen size is hidden, and every screen needs every theme. The "Screenshots by VisualCI" line is off by default; `credit: true` shows it. The markup's attributes change (`data-vg-for`, `data-vg-shown`), so update the JS library with the server libraries. [Dimensions](/docs/gallery/options/#dimensions) - The sign-in page, the GitHub App setup pages ("Finding your GitHub repositories…" and the rest), the waitlist page and the 404 on VisualCI's other hosts are a card in the app's look, light and dark, with a progress bar while VisualCI lists your repositories. -- A CI build that skipped a suite's jobs (`--subset`, finalized with `--allow-empty` or `--empty-reason`) no longer passes on the old baseline while the branch's last build of that suite is waiting for review, rejected or failed: it shows that build's result and turns green when it's approved. A build superseded by a pull request's review counts as that review. A build that skipped some jobs carries the branch's unapproved changes for the snapshots it wasn't sent, for review there, waiting up to 30 minutes for the branch's last build to finish comparing. [CircleCI](/docs/ci/circleci/#parallel-jobs) +- A CI build that skipped a suite's jobs (`--subset`, finalized with `--allow-empty` or `--empty-reason`) no longer passes on the old baseline while the branch's last build of that suite is waiting for review, rejected or failed: it shows that build's result and turns green when it's approved. A build superseded by a pull request's review counts as that review, and a last build that was never finalized is finalized and followed. A build that skipped some jobs carries the branch's unapproved changes for the snapshots it wasn't sent, for review there, waiting up to 30 minutes for the branch's last build to finish comparing. [CircleCI](/docs/ci/circleci/#parallel-jobs) - Docs links to headings with an apostrophe work: a heading like "Choose what's public" is at `#choose-whats-public`, where the page used to give it `#choose-what-39-s-public`. The Ruby gem's documentation link goes to the RSpec screenshots page. - A rerun of only the failed jobs no longer fails a suite as empty when the first run's finalizing job never ran: the rerun's empty build finalizes the first run's build, once nothing has arrived for it for 5 minutes (or after VisualCI gave up on it), and shows its result. [CircleCI](/docs/ci/circleci/#rerunning-failed-jobs) - **Gallery libraries 0.2.2, for React, Next.js, Docusaurus, VitePress and MkDocs:** `visualci-gallery-react` (a server component for Next.js's app router), `visualci-gallery-docusaurus`, `visualci-gallery-vitepress`, and an MkDocs plugin in the `visualci-gallery` Python package. Each renders the gallery into the page when the site builds, and fails the build when the manifest can't be read. [Gallery guides](/docs/gallery/#show-it-on-your-site) diff --git a/frontend/content/docs/ci/circleci.md b/frontend/content/docs/ci/circleci.md index cd1d7549..0457c16d 100644 --- a/frontend/content/docs/ci/circleci.md +++ b/frontend/content/docs/ci/circleci.md @@ -50,7 +50,7 @@ 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. -The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. If that build was superseded by a later review (a pull request's build on top of it), the skipped build goes by that review: an approval lets it pass, a rejection keeps it rejected, and a review still waiting keeps it waiting. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed or added without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. While the branch's last build is still being compared, such a build waits for it (up to 30 minutes; after that it waits for a review instead of passing). +The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. If that build was superseded by a later review (a pull request's build on top of it), the skipped build goes by that review: an approval lets it pass, a rejection keeps it rejected, and a review still waiting keeps it waiting. If the branch's last build was sent its snapshots but never finalized (a job before the finalizing one failed), the skipped build finalizes it (once nothing has arrived for it for 5 minutes, or after VisualCI gave up on it) and stands on its review; until then it waits. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed, added or removed without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. While the branch's last build is still being compared, such a build waits for it (up to 30 minutes; after that it waits for a review instead of passing). ## Rerunning failed jobs diff --git a/frontend/content/docs/ci/github-actions.md b/frontend/content/docs/ci/github-actions.md index d2fc7a7e..42364e67 100644 --- a/frontend/content/docs/ci/github-actions.md +++ b/frontend/content/docs/ci/github-actions.md @@ -213,7 +213,8 @@ instead, with a warning naming it, and turns green when that build is approved: baseline while the branch has a change nobody approved. A subset build that sent some snapshots carries the branch's last unapproved version of each snapshot it wasn't sent, for review in this build (a rejected one stays rejected), waiting up to 30 minutes for that build to finish comparing. A last build superseded by a pull request's review goes by -that review: only an approval lets the skipped build pass. +that review: only an approval lets the skipped build pass. A last build that was sent its snapshots but never +finalized is finalized by the skipped build (once it's been quiet for 5 minutes), which then stands on its review. ## Blacksmith, Depot and other runners diff --git a/frontend/content/docs/ci/other.md b/frontend/content/docs/ci/other.md index 8af772be..38b66e82 100644 --- a/frontend/content/docs/ci/other.md +++ b/frontend/content/docs/ci/other.md @@ -51,7 +51,7 @@ Parallel jobs can share one build: - Each job uploads its files and runs `visualci build finalize --shard `, with shards numbered from 0. - VisualCI compares the build once all `n` shards have finalized. -Add `--subset` when some jobs may not run. Snapshots that weren't sent are then carried forward instead of counted as removed. A snapshot the branch's last build of the suite changed or added without an approval is carried from that build, for review in this one, rather than from the baseline (a rejected one stays rejected); while that build is still being compared, the subset build waits for it, up to 30 minutes, and after that waits for a review instead of passing. A build that skipped every job, finalized with `--allow-empty`, shows the result of the branch's last build of the suite when that build is still being compared, waiting for review, rejected or failed (or superseded by a review that wasn't an approval), and turns green when it's approved. +Add `--subset` when some jobs may not run. Snapshots that weren't sent are then carried forward instead of counted as removed. A snapshot the branch's last build of the suite changed, added or removed without an approval is carried from that build, for review in this one, rather than from the baseline (a rejected one stays rejected); while that build is still being compared, the subset build waits for it, up to 30 minutes, and after that waits for a review instead of passing. A build that skipped every job, finalized with `--allow-empty`, shows the result of the branch's last build of the suite when that build is still being compared, waiting for review, rejected or failed (or superseded by a review that wasn't an approval), and turns green when it's approved. A last build that was sent snapshots but never finalized is finalized by the later build once nothing has arrived for it for 5 minutes, and the later build stands on its review. 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. An earlier build that was sent snapshots but never finalized (its finalizing job didn't run) is finalized by the empty build and followed, once nothing has arrived for it for 5 minutes, even after VisualCI gave up on it at the hour. diff --git a/plugin/skills/visualci-circleci/SKILL.md b/plugin/skills/visualci-circleci/SKILL.md index 1732a967..4b2b2863 100644 --- a/plugin/skills/visualci-circleci/SKILL.md +++ b/plugin/skills/visualci-circleci/SKILL.md @@ -57,7 +57,7 @@ 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. -The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. If that build was superseded by a later review (a pull request's build on top of it), the skipped build goes by that review: an approval lets it pass, a rejection keeps it rejected, and a review still waiting keeps it waiting. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed or added without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. While the branch's last build is still being compared, such a build waits for it (up to 30 minutes; after that it waits for a review instead of passing). +The baseline only holds approved snapshots, so a skipped build can't pass on it while the branch still has a change nobody approved. When the branch's last build of the suite (same `--name`, environment and branch, any commit, the default branch included) is still being compared, waiting for review, rejected or failed, a build created with `--subset` and finalized with `--allow-empty` (or `--empty-reason`) shows that build's result instead, with a warning naming it: it waits for that review and turns green when the earlier build is approved, stays rejected while it's rejected, and fails while it failed. If that build was superseded by a later review (a pull request's build on top of it), the skipped build goes by that review: an approval lets it pass, a rejection keeps it rejected, and a review still waiting keeps it waiting. If the branch's last build was sent its snapshots but never finalized (a job before the finalizing one failed), the skipped build finalizes it (once nothing has arrived for it for 5 minutes, or after VisualCI gave up on it) and stands on its review; until then it waits. A build that skipped some of the suite's jobs and ran others does the same per snapshot: a snapshot it wasn't sent that the branch's last build changed, added or removed without an approval is carried from that build, compared with the baseline and reviewed in this build, and a rejected one keeps its rejection. While the branch's last build is still being compared, such a build waits for it (up to 30 minutes; after that it waits for a review instead of passing). ## Rerunning failed jobs diff --git a/plugin/skills/visualci-github-actions/SKILL.md b/plugin/skills/visualci-github-actions/SKILL.md index 0daab75b..5a94b3d0 100644 --- a/plugin/skills/visualci-github-actions/SKILL.md +++ b/plugin/skills/visualci-github-actions/SKILL.md @@ -220,7 +220,8 @@ instead, with a warning naming it, and turns green when that build is approved: baseline while the branch has a change nobody approved. A subset build that sent some snapshots carries the branch's last unapproved version of each snapshot it wasn't sent, for review in this build (a rejected one stays rejected), waiting up to 30 minutes for that build to finish comparing. A last build superseded by a pull request's review goes by -that review: only an approval lets the skipped build pass. +that review: only an approval lets the skipped build pass. A last build that was sent its snapshots but never +finalized is finalized by the skipped build (once it's been quiet for 5 minutes), which then stands on its review. ## Blacksmith, Depot and other runners From 2d608abdf5500bc9fd93d968cd98e938e050c799 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 09:07:22 +0000 Subject: [PATCH 6/6] Reruns: wake a waiting build even while a run holds it (exclusive leaves a note to run it again); only the adopting build is skipped (sc-9763) --- app/src/domain/processing.rs | 8 -------- app/src/domain/reruns.rs | 8 ++++---- app/tests/reruns.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/src/domain/processing.rs b/app/src/domain/processing.rs index 8d041d58..676117fd 100644 --- a/app/src/domain/processing.rs +++ b/app/src/domain/processing.rs @@ -132,14 +132,6 @@ fn processing_lock_name(build_id: i64) -> String { format!("builds.process:{build_id}") } -/// Whether a run holds the build now ([`exclusive`]). -/// -/// # Errors -/// On a cache error. -pub async fn is_running(build_id: i64) -> laravel::Result { - processing_lock(build_id)?.is_locked().await -} - /// A build's processing lock, to see whether a run holds it. fn processing_lock(build_id: i64) -> laravel::Result { use laravel::time::ToSpan; diff --git a/app/src/domain/reruns.rs b/app/src/domain/reruns.rs index a50b1725..26bf05dd 100644 --- a/app/src/domain/reruns.rs +++ b/app/src/domain/reruns.rs @@ -369,10 +369,10 @@ pub async fn wake_waiting(build_id: i64) -> laravel::Result { .await?; let mut woken = 0; for waiting in waiting { - // A run holding it now (the one that finalized this build) goes on to process it. - if processing::is_running(waiting).await? - || laravel::cache::get::(&adopting_key(waiting)).await?.is_some() - { + // The build that finalized this one ([`start`]) processes itself next: running it from within this build's + // conclusion (a synchronous queue) would nest one run in the other. A build a run holds now is queued anyway: + // that run leaves a note to run it again (`processing::exclusive`), so the wake isn't lost. + if laravel::cache::get::(&adopting_key(waiting)).await?.is_some() { continue; } Box::pin(crate::jobs::process_build::ProcessBuild { build_id: waiting }.dispatch().into_future()).await?; diff --git a/app/tests/reruns.rs b/app/tests/reruns.rs index 8adf73b5..f784076b 100644 --- a/app/tests/reruns.rs +++ b/app/tests/reruns.rs @@ -1065,3 +1065,37 @@ async fn partial_subset_removal(app: Application) -> laravel::Result<()> { assert_eq!(partial["review_state"], "rejected", "{partial}"); Ok(()) } + +/// A build concluding wakes the later subset builds of its branch that wait for it, except the one finalizing it right +/// now: that one processes itself next, rather than inside the other's conclusion. +#[laravel::test] +async fn a_concluded_build_wakes_the_builds_waiting_for_it_but_not_the_one_adopting_it( + app: Application, +) -> laravel::Result<()> { + Box::pin(waking(app)).await +} + +async fn waking(app: Application) -> laravel::Result<()> { + use app::domain::reruns::{ready, started, wake_waiting}; + fixtures::blob_store().await?; + let token = project_token().await?; + let on = |commit, nonce| Run { name: "pdf", commit, branch: "feature", nonce }; + main_baseline(&app, &token).await; + + // #2 concluded, pending. #3, a subset build, is finalized and waits (its job hasn't run). + run(&app, &token, &on("f1", "w2"), &[("invoice.png", BLUE)]).await; + send_with(&app, &token, &on("f2", "w3"), &[("invoice.png", BLUE)], json!({ "subset": true })).await; + let (second, third) = (build(2).await?.id, build(3).await?.id); + db::query!("UPDATE builds SET state = 'processing', finalized_at = now() WHERE id = {third}").update().await?; + + // While #3 is finalizing #2 (`ready`, before `started`), #2's conclusion doesn't run #3. + assert!(!ready(third, second).await?, "#2 has concluded: nothing to queue"); + assert_eq!(wake_waiting(second).await?, 0); + assert_eq!(build(3).await?.state, "processing"); + + // Afterwards it does, and #3 is processed. + started(third).await?; + assert_eq!(wake_waiting(second).await?, 1); + assert_eq!(build(3).await?.state, "completed"); + Ok(()) +}