From 91854d95f3c30e1cbceb194d4954c113c8adaaf0 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 11:54:03 +0000 Subject: [PATCH 1/4] Carried approvals: a rebased branch's CI build carries its earlier approval of identical content; approved_elsewhere finds the branch's own (DocSpring PR #1487) Added snapshots never found an earlier approval on their own branch: approved_elsewhere excluded the build's own branch (bl.branch <> b.branch), and after a rebase the anchor is main's newer build, so the branch's older approval rows no longer count as baselines. Changed pages passed only through compare's exact-image check, which needs a base. - approved_elsewhere: any other build of the suite, this branch included; an approval a later build of its branch rejected for the same content is no longer shown. - domain::carried_approvals: in the conclusion's transaction, a CI build carries an earlier approval on the same branch, suite and environment for added snapshots with the same fingerprint, and changed ones with the same head and base fingerprints. Rows have approval 'carried' with the original approver and review id. Rejections, withdrawn approvals and approvals superseded by a later rejection don't carry. - conclude: a build whose every change carried concludes approved. - Docs (agents.md, design.md), changelog, skill regenerated, plugin 0.1.73. --- app/src/domain/baselines.rs | 18 +- app/src/domain/carried_approvals.rs | 156 +++++ app/src/domain/mod.rs | 1 + app/src/domain/processing.rs | 5 +- app/src/forge/checks.rs | 4 + app/src/mcp/mod.rs | 4 +- app/tests/baselines.rs | 558 ++++++++++++++++-- .../tools-list-project-token.json | 2 +- .../tools-list-user-token.json | 2 +- docs/design.md | 14 + frontend/content/docs/agents.md | 3 +- frontend/src/api/types.ts | 2 +- frontend/src/styles.css | 2 +- plugin/skills/visualci-review/SKILL.md | 3 +- 14 files changed, 706 insertions(+), 68 deletions(-) create mode 100644 app/src/domain/carried_approvals.rs diff --git a/app/src/domain/baselines.rs b/app/src/domain/baselines.rs index 1934c5215..dcc634bf1 100644 --- a/app/src/domain/baselines.rs +++ b/app/src/domain/baselines.rs @@ -612,7 +612,10 @@ pub async fn local_notes(ids: &[i64]) -> laravel::Result> { } /// Where a snapshot's new version was already approved: the same name and platform, the same content (its -/// fingerprint), approved in a review on another branch. A hint for the reviewer: it approves nothing. +/// fingerprint), approved in a review in another build of the suite, on another branch or on this one (an earlier run +/// before a rebase), and not rejected since in a later build of that branch. A hint for the reviewer: it approves +/// nothing. On its own branch a CI build carries such an approval itself when the reviewer saw exactly that change +/// (`super::carried_approvals`); the hint covers the rest. #[derive(Clone, Debug, PartialEq, serde::Serialize)] pub struct ApprovedElsewhere { pub branch: String, @@ -626,7 +629,8 @@ pub struct ApprovedElsewhere { } /// For a build's changed and added snapshots, and those that passed by matching an approval elsewhere, the newest -/// matching approval on another branch, by snapshot id. Changes are always the build's own rows. +/// matching approval in another build of the suite (any branch, this one included), by snapshot id. Changes are always +/// the build's own rows. /// /// # Errors /// On a database error. @@ -638,7 +642,7 @@ pub async fn approved_elsewhere(build_id: i64) -> laravel::Result b.branch AND bl.snapshot_id IS NOT NULL \ + AND bl.approval = 'review' AND bl.build_id <> b.id AND bl.snapshot_id IS NOT NULL \ JOIN snapshots s2 ON s2.id = bl.snapshot_id AND s2.source_fingerprint = s.source_fingerprint \ AND s.source_fingerprint <> '' \ JOIN builds b2 ON b2.id = bl.build_id \ @@ -646,6 +650,14 @@ pub async fn approved_elsewhere(build_id: i64) -> laravel::Result jsonb_build_array(s3.id) \ + WHERE b3.project_id = b.project_id AND b3.name = b.name AND b3.branch = bl.branch \ + AND s3.name = s.name AND s3.platform = s.platform \ + AND s3.source_fingerprint = s.source_fingerprint AND s3.review = 'rejected' \ + AND r3.created_at > bl.created_at) \ ORDER BY s.id, bl.created_at DESC" ) .select() diff --git a/app/src/domain/carried_approvals.rs b/app/src/domain/carried_approvals.rs new file mode 100644 index 000000000..753fb4e77 --- /dev/null +++ b/app/src/domain/carried_approvals.rs @@ -0,0 +1,156 @@ +//! Approvals a branch's CI build carries from an earlier build of the same branch (DocSpring PR #1487): after a rebase, +//! the anchor moves to a newer default-branch build and the branch's own earlier approvals stop counting as baselines +//! (`baselines::resolve` takes only those newer than the anchor), so the same change would wait for the same review +//! again. When the reviewer already saw exactly this content, its approval carries: +//! +//! - an added snapshot, when its content (the fingerprint: a PDF's, or an image's pixels) is identical to a snapshot +//! approved in an earlier build; +//! - a changed snapshot, only when both its content and its base's are identical to an approved changed snapshot's: the +//! reviewer saw this very diff. +//! +//! Only within one suite of one project, on one branch and environment, in CI mode, and only an approval that still +//! stands: +//! +//! - it's still the branch's newest approved version of that snapshot: once the branch approved something else for it +//! (a fix of a change approved by mistake), going back is a regression, and waits for review; +//! - it wasn't withdrawn (rejected later in its own build, which deletes its baseline rows), nor, for a carried +//! approval, the review it came from; +//! - nobody rejected that content on the branch after it was approved (by when the review was made, not which +//! build it was in: an older pending build can be rejected after a newer one was approved). +//! +//! A snapshot with an open comment thread on the branch isn't carried (a review couldn't approve it either), and a +//! build with a failed snapshot carries nothing. A rejection doesn't carry: the snapshot waits for review as usual. +//! Other branches' approvals stay a hint (`baselines::approved_elsewhere`). +//! +//! A carried approval is a baseline row with approval `carried`, the original approver and the original review's id, +//! and the snapshot reads as approved. When every change in the build carried, the build concludes approved. + +use std::collections::BTreeMap; + +use laravel::db; + +use crate::models::{Build, Snapshot}; + +/// Carry earlier approvals on the build's branch to its matching added and changed snapshots. Runs once, in the +/// conclusion's transaction, before the build concludes. Returns how many snapshots it approved. +/// +/// # Errors +/// On a database error. +pub async fn apply(build: &Build) -> laravel::Result { + if build.mode != "ci" { + return Ok(0); + } + let id = build.id; + // A build that concludes failed is reviewed for nothing. + let failed: Option = + db::query!("SELECT 1 FROM snapshots WHERE build_id = {id} AND state = 'failed' LIMIT 1").scalar().await?; + if failed.is_some() { + return Ok(0); + } + let rows = db::query!( + "SELECT DISTINCT ON (s.id) s.id AS snapshot_id, s.name, s.platform, bl.approved_by, bl.review_id \ + FROM snapshots s \ + JOIN builds b ON b.id = s.build_id \ + JOIN builds b2 ON b2.project_id = b.project_id AND b2.name = b.name AND b2.branch = b.branch \ + AND b2.environment = b.environment AND b2.mode = 'ci' AND b2.id < b.id \ + JOIN snapshots s2 ON s2.build_id = b2.id AND s2.name = s.name AND s2.platform = s.platform \ + AND s2.environment = s.environment AND s2.source_fingerprint = s.source_fingerprint \ + AND s2.state IN ('added', 'changed') AND s2.review = 'approved' \ + JOIN baselines bl ON bl.build_id = b2.id AND bl.snapshot_id = s2.id AND bl.approval IN ('review', 'carried') \ + LEFT JOIN snapshots base ON base.id = s.base_snapshot_id \ + LEFT JOIN snapshots base2 ON base2.id = s2.base_snapshot_id \ + WHERE s.build_id = {id} AND s.platform <> 'visualci' AND s.review IS NULL AND NOT s.sourced \ + AND s.source_fingerprint <> '' \ + AND (s.state = 'added' \ + OR (s.state = 'changed' AND s2.state = 'changed' AND base.source_fingerprint <> '' \ + AND base.source_fingerprint = base2.source_fingerprint)) \ + AND (bl.approval = 'review' OR (bl.review_id IS NOT NULL AND EXISTS ( \ + SELECT 1 FROM baselines o WHERE o.project_id = bl.project_id AND o.build_name = bl.build_name \ + AND o.name = bl.name AND o.platform = bl.platform AND o.environment = bl.environment \ + AND o.branch = bl.branch AND o.review_id = bl.review_id AND o.approval = 'review'))) \ + AND NOT EXISTS ( \ + SELECT 1 FROM baselines later LEFT JOIN snapshots ls ON ls.id = later.snapshot_id \ + WHERE later.project_id = b.project_id AND later.build_name = b.name AND later.branch = b.branch \ + AND later.name = bl.name AND later.platform = bl.platform AND later.environment = bl.environment \ + AND later.id > bl.id AND later.build_id <> b.id \ + AND (ls.id IS NULL OR ls.source_fingerprint <> s.source_fingerprint)) \ + AND NOT EXISTS ( \ + SELECT 1 FROM snapshots s3 JOIN builds b3 ON b3.id = s3.build_id \ + JOIN reviews r3 ON r3.build_id = b3.id AND r3.action = 'reject' \ + AND r3.snapshot_ids @> jsonb_build_array(s3.id) \ + WHERE b3.project_id = b.project_id AND b3.name = b.name AND b3.branch = b.branch \ + AND b3.environment = b.environment AND b3.mode = 'ci' AND b3.id <> b.id \ + AND s3.name = s.name AND s3.platform = s.platform AND s3.source_fingerprint = s.source_fingerprint \ + AND s3.review = 'rejected' AND r3.created_at > bl.created_at) \ + ORDER BY s.id, b2.id DESC, bl.id DESC" + ) + .select() + .await?; + let mut found = Vec::new(); + for r in rows { + let key = (r.try_get::("name")?, r.try_get::("platform")?); + let approval = (r.try_get::>("approved_by")?, r.try_get::>("review_id")?); + found.push((key, approval, r.try_get::("snapshot_id")?)); + } + // An open comment thread blocks approving its snapshot (`reviews::review`): it needs an answer first. + let keys: Vec<(String, String)> = found.iter().map(|(k, _, _)| k.clone()).collect(); + let open = super::comments::open_on(build.project_id, &build.branch, &keys).await?; + let blocked = |k: &(String, String)| open.iter().any(|t| t.snapshot_name == k.0 && t.platform == k.1); + // Grouped by the approval they carry: its approver and review. + let mut by_approval: BTreeMap<(Option, Option), Vec> = BTreeMap::new(); + for (key, approval, snapshot_id) in found { + if !blocked(&key) { + by_approval.entry(approval).or_default().push(snapshot_id); + } + } + let mut carried = 0; + for ((approved_by, review_id), ids) in by_approval { + db::query!("UPDATE snapshots SET review = 'approved', updated_at = now() WHERE id IN ({...ids})") + .update() + .await?; + let snapshots = Snapshot::query().filter(Snapshot::id.is_in(ids)).get().await?; + let refs: Vec<&Snapshot> = snapshots.iter().collect(); + super::baselines::record(build, &refs, approved_by, review_id, "carried").await?; + carried += snapshots.len(); + } + Ok(carried) +} + +/// What a build carried, for its check: "Approved earlier on this branch by Ada Lovelace (build #12)", one line per +/// approval it carried, or `None` when it carried nothing. +/// +/// # Errors +/// On a database error. +pub async fn summary(build_id: i64) -> laravel::Result> { + let rows = db::query!( + "SELECT DISTINCT ON (o.number, r.id) o.number, COUNT(*) OVER (PARTITION BY o.number, r.id) AS n, \ + u.name AS approver, r.source, r.client_name, r.agent, r.token_name \ + FROM baselines bl \ + LEFT JOIN reviews r ON r.id = bl.review_id \ + LEFT JOIN builds o ON o.id = r.build_id \ + LEFT JOIN users u ON u.id = bl.approved_by \ + WHERE bl.build_id = {build_id} AND bl.approval = 'carried' \ + ORDER BY o.number, r.id" + ) + .select() + .await?; + let mut lines = Vec::new(); + for r in rows { + let person: Option = r.try_get("approver")?; + let who = match r.try_get::>("source")? { + Some(source) => super::reviews::by( + &source, + r.try_get::>("client_name")?.as_deref(), + r.try_get::>("agent")?.as_deref(), + r.try_get::>("token_name")?.as_deref(), + person.as_deref(), + ), + None => person.unwrap_or_else(|| "someone".to_string()), + }; + let n: i64 = r.try_get("n")?; + let changes = if n == 1 { "1 change".to_string() } else { format!("{n} changes") }; + let build = r.try_get::>("number")?.map(|n| format!(" (build #{n})")).unwrap_or_default(); + lines.push(format!("{changes} approved earlier on this branch by {who}{build}.")); + } + Ok((!lines.is_empty()).then(|| lines.join(" "))) +} diff --git a/app/src/domain/mod.rs b/app/src/domain/mod.rs index f2cc02e6a..8c2acc96d 100644 --- a/app/src/domain/mod.rs +++ b/app/src/domain/mod.rs @@ -6,6 +6,7 @@ pub mod blobs; pub mod build_settings; pub mod builds; pub mod bundles; +pub mod carried_approvals; pub mod changeset; pub mod comments; pub mod compare; diff --git a/app/src/domain/processing.rs b/app/src/domain/processing.rs index aa5da92ba..5d30a284a 100644 --- a/app/src/domain/processing.rs +++ b/app/src/domain/processing.rs @@ -1160,6 +1160,8 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) -> .await? .unwrap_or(0); groups::source_unchanged(&build).await?; + // Changes this branch already approved in an earlier build, content for content (after a rebase). + super::carried_approvals::apply(&build).await?; let warnings = warnings.clone(); update!(build { warnings }).await?; @@ -1295,7 +1297,8 @@ async fn conclude( // 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")); - // Every change already approved: a merged pull request's version it approved (`approve_merged`). + // Every change already approved: a merged pull request's version it approved (`approve_merged`), or an earlier + // approval on the branch carried (`carried_approvals`). Approved as it stands. let approved = all.iter().filter(|s| is_change(s)).all(|s| s.review.as_deref() == Some("approved")); let review_state = match conclusion { "failed" => "none", diff --git a/app/src/forge/checks.rs b/app/src/forge/checks.rs index d3f40ad6e..2c17f045b 100644 --- a/app/src/forge/checks.rs +++ b/app/src/forge/checks.rs @@ -134,6 +134,10 @@ async fn own_check(build: &Build, project: &Project, org: &Organization) -> lara summary.push_str(&format!(" {note}")); } } + // Changes approved by carrying an approval from an earlier build of the branch (after a rebase) + if let Some(carried) = crate::domain::carried_approvals::summary(build.id).await? { + summary.push_str(&format!("\n\n{carried}")); + } // What changed, from the comparison if let Some(line) = crate::domain::summary::summary_line(build).await? { summary = format!("{line}\n\n{summary}"); diff --git a/app/src/mcp/mod.rs b/app/src/mcp/mod.rs index 2e34be81c..ee4ab6b1b 100644 --- a/app/src/mcp/mod.rs +++ b/app/src/mcp/mod.rs @@ -1159,7 +1159,7 @@ impl VisualCi { } #[tool( - description = "A build's status and its snapshots that need attention, 30 at a time (offset and limit page through; longer lists also come grouped by state and name prefix) (changed, added, removed, failed), with how many pages changed in each, the largest change first (order: name to sort by name), and approved_elsewhere when the same new version was already approved on another branch (a hint: it approves nothing). Unchanged snapshots are only counted unless include_unchanged is set. `config` is the visualci.yml the build was sent (null when it had none: the project's settings applied). `flaky: true` marks a change whose content flipped back and forth over the branch's recent builds: often something that differs between runs (the time, an animation, a late font) rather than a real change, so check it before approving, and make the test deterministic. On a pull request's build, `on_main_unreviewed: true` marks a change that's the default branch's own unreviewed change (its newest build, still waiting for review, has it too), and `inherited` counts them: review those on main's build. `matches` marks a change made only of changes a merged pull request approved (two PRs that changed the same screen and merged separately): approve those with `review` and `only: \"matching\"`.", + description = "A build's status and its snapshots that need attention, 30 at a time (offset and limit page through; longer lists also come grouped by state and name prefix) (changed, added, removed, failed), with how many pages changed in each, the largest change first (order: name to sort by name), and approved_elsewhere when the same new version was already approved in another build, on another branch or earlier on this one (a hint: it approves nothing; on its own branch a CI build carries an earlier approval of the same added content, or of the same change over the same base, by itself). Unchanged snapshots are only counted unless include_unchanged is set. `config` is the visualci.yml the build was sent (null when it had none: the project's settings applied). `flaky: true` marks a change whose content flipped back and forth over the branch's recent builds: often something that differs between runs (the time, an animation, a late font) rather than a real change, so check it before approving, and make the test deterministic. On a pull request's build, `on_main_unreviewed: true` marks a change that's the default branch's own unreviewed change (its newest build, still waiting for review, has it too), and `inherited` counts them: review those on main's build. `matches` marks a change made only of changes a merged pull request approved (two PRs that changed the same screen and merged separately): approve those with `review` and `only: \"matching\"`.", annotations(title = "Get build", read_only_hint = true, idempotent_hint = true, open_world_hint = false) )] async fn get_build( @@ -1220,7 +1220,7 @@ impl VisualCi { // How big the change is: the largest share of a page (or of the lines) that changed, and how many // pixels (or lines). The list puts the biggest first. "change": sizes.get(&s.id), - // The same new version was already approved on another branch: a hint, it approves nothing here. + // The same new version was already approved in another build (another branch, or earlier on this one): a hint. "approved_elsewhere": elsewhere.get(&s.id).map(|e| { let mut v = json!(e); v["url"] = json!(snapshot_url(e)); diff --git a/app/tests/baselines.rs b/app/tests/baselines.rs index 8a5a5c373..21925f006 100644 --- a/app/tests/baselines.rs +++ b/app/tests/baselines.rs @@ -115,6 +115,22 @@ impl World { Box::pin(self.build_inner(app, commit, branch, None, parents, files, &[])).await } + /// [`World::build_into`] with more fields for the build (`environment`, `config`). + #[allow(clippy::too_many_arguments)] + async fn build_with( + &self, + app: &Application, + commit: &str, + branch: &str, + base: &str, + parents: &[&str], + files: &[(&str, [u8; 3])], + extra: serde_json::Value, + ) -> Build { + let id = Box::pin(self.start(app, commit, branch, Some((base, Some(1))), parents, files, extra)).await; + Box::pin(self.finish(app, &id)).await + } + /// [`World::build`] for a pull request into `base`. async fn build_into( &self, @@ -184,37 +200,7 @@ impl World { /// Send these images to a build that's receiving (by its API id), and finalize it. async fn send(&self, app: &Application, id: &str, files: &[(&str, [u8; 3])], missing: &[&str]) -> Build { let auth = format!("Bearer {}", self.token); - if files.is_empty() { - let done = app.post(format!("/api/v1/builds/{id}/finalize")).header("authorization", &auth).await; - assert_eq!(done.json()["state"], "completed", "{}", done.text()); - let pid: laravel::str::Uuid = id.parse().unwrap(); - return Build::query().filter(Build::pid.eq(pid)).first().await.unwrap().unwrap(); - } - let mut list = Vec::new(); - let mut bodies = Vec::new(); - for (name, rgb) in files { - let bytes = png(*rgb, &self.nonce); - let sha = visualci_core::sha256_hex(&bytes); - list.push(json!({ - "name": name, "kind": "image", "sha256": sha, "size": bytes.len(), "content_type": "image/png", - "fingerprint": visualci_core::image_hash::fingerprint_bytes(&bytes).unwrap(), - })); - bodies.push(bytes); - } - let registered = app - .post(format!("/api/v1/builds/{id}/snapshots")) - .header("authorization", &auth) - .json(json!({ "snapshots": list })) - .await; - registered.assert_ok(); - for (s, bytes) in registered.json()["snapshots"].as_array().unwrap().iter().zip(bodies) { - if missing.iter().any(|m| s["name"] == *m) { - continue; - } - if let Some(url) = s["upload_url"].as_str() { - upload(url, bytes).await; - } - } + Box::pin(self.upload_all(app, id, files, missing)).await; let done = app.post(format!("/api/v1/builds/{id}/finalize")).header("authorization", &auth).await; assert_eq!(done.json()["state"], "completed", "{}", done.text()); let pid: laravel::str::Uuid = id.parse().unwrap(); @@ -324,36 +310,20 @@ impl World { created.json()["id"].as_str().unwrap().to_string() } - /// A jest suite's build as DocSpring's CI sends it: text snapshots split out of Jest `.snap` files - /// (`visualci upload --from jest`), into a subset build named "jest". For a pull request into `base`. - async fn jest( - &self, - app: &Application, - commit: &str, - branch: &str, - base: Option<&str>, - parents: &[&str], - files: &[(&str, &str)], - ) -> Build { - let auth = format!("Bearer {}", self.token); - let mut body = - json!({ "commit": commit, "branch": branch, "parent_commits": parents, "subset": true, "name": "jest" }); - if let Some(base) = base { - body["base_branch"] = json!(base); - body["pr_number"] = json!(7); + /// Register these images with a receiving build and upload them, all but the `missing` ones. + async fn upload_all(&self, app: &Application, id: &str, files: &[(&str, [u8; 3])], missing: &[&str]) { + if files.is_empty() { + return; } - let created = app.post("/api/v1/builds").header("authorization", &auth).json(body).await; - created.assert_ok(); - let id = created.json()["id"].as_str().unwrap().to_string(); + let auth = format!("Bearer {}", self.token); let mut list = Vec::new(); let mut bodies = Vec::new(); - for (name, text) in files { - // The test's own bytes, as with images ([`png`]). - let bytes = format!("{text}\n// {}\n", self.nonce).into_bytes(); + for (name, rgb) in files { + let bytes = png(*rgb, &self.nonce); let sha = visualci_core::sha256_hex(&bytes); list.push(json!({ - "name": name, "platform": "", "kind": "text", "sha256": sha, "fingerprint": sha, "size": bytes.len(), - "content_type": "text/plain", + "name": name, "kind": "image", "sha256": sha, "size": bytes.len(), "content_type": "image/png", + "fingerprint": visualci_core::image_hash::fingerprint_bytes(&bytes).unwrap(), })); bodies.push(bytes); } @@ -364,10 +334,48 @@ impl World { .await; registered.assert_ok(); for (s, bytes) in registered.json()["snapshots"].as_array().unwrap().iter().zip(bodies) { + if missing.iter().any(|m| s["name"] == *m) { + continue; + } if let Some(url) = s["upload_url"].as_str() { upload(url, bytes).await; } } + } + + /// Create a build (with more fields from `extra`) and send its files, without finalizing it: its id. + #[allow(clippy::too_many_arguments)] + async fn start( + &self, + app: &Application, + commit: &str, + branch: &str, + base: Option<(&str, Option)>, + parents: &[&str], + files: &[(&str, [u8; 3])], + extra: serde_json::Value, + ) -> String { + let auth = format!("Bearer {}", self.token); + let mut body = json!({ "commit": commit, "branch": branch, "parent_commits": parents }); + for (k, v) in extra.as_object().into_iter().flatten() { + body[k] = v.clone(); + } + if let Some((base, pr)) = base { + body["base_branch"] = json!(base); + if let Some(pr) = pr { + body["pr_number"] = json!(pr); + } + } + let created = app.post("/api/v1/builds").header("authorization", &auth).json(body).await; + created.assert_ok(); + let id = created.json()["id"].as_str().unwrap().to_string(); + Box::pin(self.upload_all(app, &id, files, &[])).await; + id + } + + /// Finalize a build [`World::start`] made, and wait for it to complete. + async fn finish(&self, app: &Application, id: &str) -> Build { + let auth = format!("Bearer {}", self.token); let done = app.post(format!("/api/v1/builds/{id}/finalize")).header("authorization", &auth).await; assert_eq!(done.json()["state"], "completed", "{}", done.text()); let pid: laravel::str::Uuid = id.parse().unwrap(); @@ -1382,6 +1390,444 @@ async fn inherited_falls_back_to_the_default_branch_for_an_unbuilt_base(app: App Ok(()) } +/// A person to review as, with a name of this test's own. +async fn reviewer(w: &World) -> laravel::Result { + let email = format!("ada-{}@example.com", w.nonce); + laravel::model::create!(app::models::User { pid: laravel::str::uuid7(), name: "Ada", email: email, staff: false }) + .await +} + +/// Approve or reject some of a build's snapshots (by name; all its changes when `names` is empty) as `user`. +async fn review_as(build: Build, user: Option, action: &str, names: &[&str]) -> laravel::Result { + let ids = if names.is_empty() { + None + } else { + Some( + app::domain::snapshots::of_build(build.id) + .await? + .into_iter() + .filter(|s| names.contains(&s.name.as_str())) + .map(|s| s.id) + .collect(), + ) + }; + Ok(Box::pin(reviews::review(build, user, &reviews::Via::default(), action, ids, None)).await?.unwrap()) +} + +/// A build's snapshot by name. +async fn snapshot(build: &Build, name: &str) -> laravel::Result { + Ok(app::domain::snapshots::of_build(build.id).await?.into_iter().find(|s| s.name == name).unwrap()) +} + +/// The baseline rows a build recorded for a snapshot: (approval, approved_by, review_id). +async fn rows_of(build: &Build, name: &str) -> laravel::Result, Option)>> { + let id = build.id; + let rows = + db::query!("SELECT approval, approved_by, review_id FROM baselines WHERE build_id = {id} AND name = {name}") + .select() + .await?; + rows.iter().map(|r| Ok((r.try_get("approval")?, r.try_get("approved_by")?, r.try_get("review_id")?))).collect() +} + +/// The newest review's id on a build. +async fn last_review(build: &Build) -> laravel::Result { + let id = build.id; + Ok(db::query!("SELECT MAX(id) FROM reviews WHERE build_id = {id}").scalar().await?.unwrap_or_default()) +} + +/// DocSpring PR #1487: a pull request approves a new snapshot, main moves on, and the rebased pull request's build +/// sends the same file again. The anchor is now main's newer build, so the branch's earlier approval no longer counts +/// as a baseline and the snapshot is added again: it carries the earlier approval, attributed to its reviewer and +/// review, and the build is approved (its check passes). +#[laravel::test] +async fn a_rebased_branch_carries_its_approval_of_an_identical_added_snapshot(app: Application) -> laravel::Result<()> { + let w = world().await?; + let ada = reviewer(&w).await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let p1 = w.build_into(&app, "p1", "feature", "main", &["m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]).await; + let p1 = review_as(p1, Some(ada.id), "approve", &[]).await?; + assert_eq!(p1.review_state, "approved"); + let review = last_review(&p1).await?; + let m2 = w.build(&app, "m2", "main", &["m1", "m0"], &[("web/home", RED)]).await; + assert!(m2.id > p1.id); + + let p2 = w + .build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]) + .await; + assert_eq!(p2.base_build_id, Some(m2.id)); + let new = snapshot(&p2, "web/new").await?; + assert_eq!((new.state.as_str(), new.review.as_deref()), ("added", Some("approved"))); + assert_eq!(rows_of(&p2, "web/new").await?, vec![("carried".to_string(), Some(ada.id), Some(review))]); + assert_eq!((p2.conclusion.as_deref(), p2.review_state.as_str()), (Some("changes"), "approved")); + // The check says where the approval came from. + let org = app::models::Organization::find_or_fail(w.project.organization_id).await?; + let check = app::forge::checks::check_for(&p2, &w.project, &org).await?; + assert_eq!(check.conclusion.as_deref(), Some("success")); + let line = format!("1 change approved earlier on this branch by Ada (build #{}).", p1.number); + assert!(check.summary.contains(&line), "{}", check.summary); + Ok(()) +} + +/// Part 1 of the same report: `approved_elsewhere` finds an added snapshot's approval on its own branch's earlier +/// build, as it does on other branches. +#[laravel::test] +async fn approved_elsewhere_finds_an_added_snapshots_approval_earlier_on_its_branch( + app: Application, +) -> laravel::Result<()> { + let w = world().await?; + let ada = reviewer(&w).await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let p1 = w.build_into(&app, "p1", "feature", "main", &["m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]).await; + let p1 = review_as(p1, Some(ada.id), "approve", &[]).await?; + w.build(&app, "m2", "main", &["m1", "m0"], &[("web/home", RED)]).await; + let p2 = w + .build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]) + .await; + let new = snapshot(&p2, "web/new").await?; + assert_eq!(new.state, "added"); + let found = baselines::approved_elsewhere(p2.id).await?; + let hint = found.get(&new.id).expect("the earlier approval on the branch is found"); + assert_eq!((hint.branch.as_str(), hint.build), ("feature", p1.number)); + assert_eq!(hint.snapshot_id, snapshot(&p1, "web/new").await?.pid); + assert_eq!(hint.approved_by.as_deref(), Some("Ada")); + Ok(()) +} + +/// The same test's images with bytes of their own: the same pixels (and fingerprints) as `w`'s, another file. +fn reencoded(w: &World) -> World { + World { project: w.project.clone(), token: w.token.clone(), nonce: format!("{}-again", w.nonce) } +} + +/// A changed snapshot carries an approval when the reviewer saw this very diff: the same new version over the same base. +/// (The same file passes already when it's compared, as an image approved on the branch: here the new version is +/// another file with the same pixels, as a re-encoded screenshot or a PDF drawn by a newer renderer would be.) +#[laravel::test] +async fn a_rebased_branch_carries_its_approval_of_an_identical_change(app: Application) -> laravel::Result<()> { + let w = world().await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let p1 = w.build_into(&app, "p1", "feature", "main", &["m1", "m0"], &[("web/home", GREEN)]).await; + assert_eq!(states(&p1).await?, vec![("web/home".into(), "changed".into())]); + let p1 = w.approve(p1).await; + let review = last_review(&p1).await?; + w.build(&app, "m2", "main", &["m1", "m0"], &[("web/home", RED)]).await; + + let p2 = reencoded(&w).build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &[("web/home", GREEN)]).await; + let home = snapshot(&p2, "web/home").await?; + assert_ne!(home.source_blob, snapshot(&p1, "web/home").await?.source_blob, "another file"); + assert_eq!( + (home.state.as_str(), home.review.as_deref()), + ("changed", Some("approved")), + "red to green, as approved" + ); + assert_eq!(rows_of(&p2, "web/home").await?, vec![("carried".to_string(), None, Some(review))]); + assert_eq!(p2.review_state, "approved"); + Ok(()) +} + +/// Review of #289: once the branch approved another version, going back to an older approved one is a regression +/// (the fix of a change approved by mistake, undone): it waits for review. A pull request branch: green to blue +/// approved, blue to green approved, then green to blue again. +#[laravel::test] +async fn a_change_the_branch_moved_away_from_doesnt_carry(app: Application) -> laravel::Result<()> { + let w = world().await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let p1 = w.build_into(&app, "p1", "feature", "main", &["m1", "m0"], &[("web/home", GREEN)]).await; + w.approve(p1).await; + let p2 = w.build_into(&app, "p2", "feature", "main", &["p1", "m1", "m0"], &[("web/home", BLUE)]).await; + w.approve(p2).await; + let p3 = w.build_into(&app, "p3", "feature", "main", &["p2", "p1", "m1", "m0"], &[("web/home", GREEN)]).await; + assert_eq!(states(&p3).await?, vec![("web/home".into(), "changed".into())]); + w.approve(p3).await; + let p4 = w.build_into(&app, "p4", "feature", "main", &["p3", "p2", "p1", "m1", "m0"], &[("web/home", BLUE)]).await; + let home = snapshot(&p4, "web/home").await?; + assert_eq!((home.state.as_str(), home.review.as_deref()), ("changed", None), "the regression waits for review"); + assert_eq!(p4.review_state, "pending"); + Ok(()) +} + +/// The same on the default branch: a change approved by mistake, its fix approved, and the bug back. +#[laravel::test] +async fn a_regression_on_the_default_branch_doesnt_carry_the_mistaken_approval( + app: Application, +) -> laravel::Result<()> { + let w = world().await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let m2 = w.build(&app, "m2", "main", &["m1", "m0"], &[("web/home", GREEN)]).await; + w.approve(m2).await; + let m3 = w.build(&app, "m3", "main", &["m2", "m1", "m0"], &[("web/home", RED)]).await; + assert_eq!(states(&m3).await?, vec![("web/home".into(), "changed".into())]); + w.approve(m3).await; + let m4 = w.build(&app, "m4", "main", &["m3", "m2", "m1", "m0"], &[("web/home", GREEN)]).await; + let home = snapshot(&m4, "web/home").await?; + assert_eq!((home.state.as_str(), home.review.as_deref()), ("changed", None)); + assert_eq!(m4.review_state, "pending"); + Ok(()) +} + +/// The same new version over a different base is a different diff: it waits for review, with the earlier approval as +/// a hint. +#[laravel::test] +async fn a_change_over_a_different_base_waits_with_the_earlier_approval_as_a_hint( + app: Application, +) -> laravel::Result<()> { + let w = world().await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let p1 = w.build_into(&app, "p1", "feature", "main", &["m1", "m0"], &[("web/home", GREEN)]).await; + let p1 = w.approve(p1).await; + // main changes the page meanwhile, and that's approved. + let m2 = w.build(&app, "m2", "main", &["m1", "m0"], &[("web/home", BLUE)]).await; + assert_eq!(m2.review_state, "pending"); + w.approve(m2).await; + + let p2 = reencoded(&w).build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &[("web/home", GREEN)]).await; + let home = snapshot(&p2, "web/home").await?; + assert_eq!((home.state.as_str(), home.review.as_deref()), ("changed", None), "not carried: blue to green"); + assert_eq!(rows_of(&p2, "web/home").await?, vec![]); + assert_eq!(p2.review_state, "pending"); + let found = baselines::approved_elsewhere(p2.id).await?; + assert_eq!(found.get(&home.id).map(|h| h.build), Some(p1.number), "the earlier approval stays a hint"); + Ok(()) +} + +/// Another branch's approval of the same content is a hint only: it approves nothing. +#[laravel::test] +async fn another_branchs_approval_of_the_same_content_is_only_a_hint(app: Application) -> laravel::Result<()> { + let w = world().await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let x = + w.build_into(&app, "x1", "feature-x", "main", &["m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]).await; + let x = w.approve(x).await; + let y = + w.build_into(&app, "y1", "feature-y", "main", &["m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]).await; + let new = snapshot(&y, "web/new").await?; + assert_eq!((new.state.as_str(), new.review.as_deref()), ("added", None)); + assert_eq!(y.review_state, "pending"); + assert_eq!(recorded(&y).await?, 0); + let found = baselines::approved_elsewhere(y.id).await?; + assert_eq!(found.get(&new.id).map(|h| (h.branch.as_str(), h.build)), Some(("feature-x", x.number))); + Ok(()) +} + +/// An approval a later build of the branch rejected for the same content no longer carries (nor shows as a hint): the +/// newest verdict stands, and the snapshot waits for review. +#[laravel::test] +async fn an_approval_a_later_rejection_superseded_doesnt_carry(app: Application) -> laravel::Result<()> { + let w = world().await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let p1 = w.build_into(&app, "p1", "feature", "main", &["m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]).await; + w.approve(p1).await; + w.build(&app, "m2", "main", &["m1", "m0"], &[("web/home", RED)]).await; + let p2 = w + .build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]) + .await; + assert_eq!(snapshot(&p2, "web/new").await?.review.as_deref(), Some("approved"), "carried"); + // The reviewer looks again and rejects it after all. + let p2 = review_as(p2, None, "reject", &["web/new"]).await?; + assert_eq!(p2.review_state, "rejected"); + + w.build(&app, "m3", "main", &["m2", "m1", "m0"], &[("web/home", RED)]).await; + let p3 = w + .build_into(&app, "p3", "feature", "main", &["m3", "m2", "m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]) + .await; + let new = snapshot(&p3, "web/new").await?; + assert_eq!((new.state.as_str(), new.review.as_deref()), ("added", None), "the rejection isn't carried either"); + assert_eq!(p3.review_state, "pending"); + assert!(!baselines::approved_elsewhere(p3.id).await?.contains_key(&new.id), "no hint from a superseded approval"); + Ok(()) +} + +/// An approval withdrawn in its own build (rejected afterwards) doesn't carry. +#[laravel::test] +async fn a_withdrawn_approval_doesnt_carry(app: Application) -> laravel::Result<()> { + let w = world().await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let p1 = w.build_into(&app, "p1", "feature", "main", &["m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]).await; + let p1 = w.approve(p1).await; + let p1 = review_as(p1, None, "reject", &["web/new"]).await?; + assert_eq!(recorded(&p1).await?, 0, "the approval's baseline was withdrawn"); + w.build(&app, "m2", "main", &["m1", "m0"], &[("web/home", RED)]).await; + let p2 = w + .build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]) + .await; + let new = snapshot(&p2, "web/new").await?; + assert_eq!((new.state.as_str(), new.review.as_deref()), ("added", None)); + assert_eq!(p2.review_state, "pending"); + Ok(()) +} + +/// The pull request of the rebase tests: main at m1, the branch adds `web/new` (approved) at p1, main moves to m2. +async fn approved_then_rebased(w: &World, app: &Application) -> laravel::Result { + w.build(app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let p1 = w.build_into(app, "p1", "feature", "main", &["m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]).await; + let p1 = w.approve(p1).await; + w.build(app, "m2", "main", &["m1", "m0"], &[("web/home", RED)]).await; + Ok(p1) +} + +/// Review of #289: an open comment thread blocks approving a snapshot, so it blocks carrying an approval too. +#[laravel::test] +async fn an_open_comment_thread_keeps_a_snapshot_from_carrying(app: Application) -> laravel::Result<()> { + let w = world().await?; + let p1 = approved_then_rebased(&w, &app).await?; + let (project_id, pid, build_id) = (w.project.id, laravel::str::uuid7(), p1.id); + db::query!( + "INSERT INTO comment_threads (pid, project_id, branch, snapshot_name, build_id) \ + VALUES ({pid}, {project_id}, 'feature', 'web/new', {build_id})" + ) + .insert() + .await?; + let p2 = w + .build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]) + .await; + assert_eq!(snapshot(&p2, "web/new").await?.review, None); + assert_eq!(p2.review_state, "pending"); + Ok(()) +} + +/// Review of #289: a carried approval stands only while the approval it came from does. p1 approves, p2 carries it, +/// p1's approval is withdrawn: p3 doesn't carry it from p2. +#[laravel::test] +async fn a_withdrawn_approval_doesnt_carry_through_its_carried_copy(app: Application) -> laravel::Result<()> { + let w = world().await?; + let p1 = approved_then_rebased(&w, &app).await?; + let p2 = w + .build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]) + .await; + assert_eq!(snapshot(&p2, "web/new").await?.review.as_deref(), Some("approved"), "carried"); + review_as(p1, None, "reject", &["web/new"]).await?; + w.build(&app, "m3", "main", &["m2", "m1", "m0"], &[("web/home", RED)]).await; + let p3 = w + .build_into(&app, "p3", "feature", "main", &["m3", "m2", "m1", "m0"], &[("web/home", RED), ("web/new", GREEN)]) + .await; + assert_eq!(snapshot(&p3, "web/new").await?.review, None); + assert_eq!(p3.review_state, "pending"); + Ok(()) +} + +/// Review of #289: a build that concludes after a newer build of the branch rejected the content doesn't carry it. +#[laravel::test] +async fn a_build_concluding_late_doesnt_carry_what_a_newer_build_rejected(app: Application) -> laravel::Result<()> { + let w = world().await?; + approved_then_rebased(&w, &app).await?; + let files = [("web/home", RED), ("web/new", GREEN)]; + let slow = + Box::pin(w.start(&app, "p2", "feature", Some(("main", Some(1))), &["m2", "m1", "m0"], &files, json!({}))).await; + let p3 = w.build_into(&app, "p3", "feature", "main", &["m2", "m1", "m0"], &files).await; + assert_eq!(snapshot(&p3, "web/new").await?.review.as_deref(), Some("approved"), "carried"); + review_as(p3, None, "reject", &["web/new"]).await?; + let p2 = Box::pin(w.finish(&app, &slow)).await; + assert_eq!(snapshot(&p2, "web/new").await?.review, None); + assert_eq!(p2.review_state, "pending"); + Ok(()) +} + +/// Second review of #289: what counts is when the rejection was made, not which build it's in. A newer build's +/// approval, then the same content rejected on an older build still waiting: the approval doesn't carry. +#[laravel::test] +async fn a_rejection_on_an_older_build_made_after_the_approval_stops_it(app: Application) -> laravel::Result<()> { + let w = world().await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let files = [("web/home", RED), ("web/new", GREEN)]; + let older = w.build_into(&app, "p1", "feature", "main", &["m1", "m0"], &files).await; + let newer = w.build_into(&app, "p1", "feature", "main", &["m1", "m0"], &files).await; + assert!(older.id < newer.id); + assert_eq!(snapshot(&newer, "web/new").await?.state, "added"); + w.approve(newer).await; + review_as(older, None, "reject", &["web/new"]).await?; + w.build(&app, "m2", "main", &["m1", "m0"], &[("web/home", RED)]).await; + let p2 = w.build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &files).await; + let new = snapshot(&p2, "web/new").await?; + assert_eq!((new.state.as_str(), new.review.as_deref()), ("added", None)); + assert_eq!(p2.review_state, "pending"); + Ok(()) +} + +/// Review of #289: a build with a failed snapshot concludes failed, and carries nothing. +#[laravel::test] +async fn a_build_with_a_failure_carries_nothing(app: Application) -> laravel::Result<()> { + let w = world().await?; + approved_then_rebased(&w, &app).await?; + let p2 = w + .build_failing( + &app, + "p2", + "feature", + &["m2", "m1", "m0"], + &[("web/home", RED), ("web/new", GREEN), ("web/missing", [9, 9, 9])], + &["web/missing"], + ) + .await; + assert_eq!(snapshot(&p2, "web/missing").await?.state, "failed"); + assert_eq!(p2.conclusion.as_deref(), Some("failed")); + assert_eq!(snapshot(&p2, "web/new").await?.review, None); + assert_eq!(recorded(&p2).await?, 0); + Ok(()) +} + +/// A visualci.yml item waiting for review keeps the build pending, whatever carried. +#[laravel::test] +async fn a_pending_visualci_yml_item_keeps_a_carried_build_pending(app: Application) -> laravel::Result<()> { + let w = world().await?; + approved_then_rebased(&w, &app).await?; + let config = + json!({ "ignore": [{ "snapshots": "web/**", "rects": [{ "x": 0, "y": 0, "width": 8, "height": 4 }] }] }); + let p2 = w + .build_with( + &app, + "p2", + "feature", + "main", + &["m2", "m1", "m0"], + &[("web/home", RED), ("web/new", GREEN)], + json!({ "config": config }), + ) + .await; + assert_eq!(snapshot(&p2, "web/new").await?.review.as_deref(), Some("approved"), "carried"); + let all = app::domain::snapshots::of_build(p2.id).await?; + assert!(all.iter().any(|s| s.platform == "visualci" && s.review.is_none()), "a visualci.yml item waits"); + assert_eq!(p2.review_state, "pending"); + Ok(()) +} + +/// Only some changes carried: the rest wait, and so does the build. +#[laravel::test] +async fn a_partly_carried_build_waits_for_the_rest(app: Application) -> laravel::Result<()> { + let w = world().await?; + approved_then_rebased(&w, &app).await?; + let p2 = w + .build_into( + &app, + "p2", + "feature", + "main", + &["m2", "m1", "m0"], + &[("web/home", RED), ("web/new", GREEN), ("web/other", BLUE)], + ) + .await; + assert_eq!(snapshot(&p2, "web/new").await?.review.as_deref(), Some("approved")); + assert_eq!(snapshot(&p2, "web/other").await?.review, None); + assert_eq!(p2.review_state, "pending"); + Ok(()) +} + +/// An approval in another environment of the branch (a CI job that names its own) doesn't carry. +#[laravel::test] +async fn another_environments_approval_doesnt_carry(app: Application) -> laravel::Result<()> { + let w = world().await?; + w.build(&app, "m1", "main", &["m0"], &[("web/home", RED)]).await; + let files = [("web/home", RED), ("web/new", GREEN)]; + let staging = + w.build_with(&app, "p1", "feature", "main", &["m1", "m0"], &files, json!({ "environment": "staging" })).await; + assert_eq!(staging.environment, "staging"); + w.approve(staging).await; + w.build(&app, "m2", "main", &["m1", "m0"], &[("web/home", RED)]).await; + let p2 = w.build_into(&app, "p2", "feature", "main", &["m2", "m1", "m0"], &files).await; + let new = snapshot(&p2, "web/new").await?; + assert_eq!((new.state.as_str(), new.review.as_deref()), ("added", None)); + assert_eq!(p2.review_state, "pending"); + Ok(()) +} + #[test] fn each_tests_images_have_the_same_pixels_and_bytes_of_their_own() { let (a, b) = (png(RED, "one"), png(RED, "two")); diff --git a/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-project-token.json b/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-project-token.json index 32d255275..e3dcdbc62 100644 --- a/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-project-token.json +++ b/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-project-token.json @@ -497,7 +497,7 @@ "readOnlyHint": true, "title": "Get build" }, - "description": "A build's status and its snapshots that need attention, 30 at a time (offset and limit page through; longer lists also come grouped by state and name prefix) (changed, added, removed, failed), with how many pages changed in each, the largest change first (order: name to sort by name), and approved_elsewhere when the same new version was already approved on another branch (a hint: it approves nothing). Unchanged snapshots are only counted unless include_unchanged is set. `config` is the visualci.yml the build was sent (null when it had none: the project's settings applied). `flaky: true` marks a change whose content flipped back and forth over the branch's recent builds: often something that differs between runs (the time, an animation, a late font) rather than a real change, so check it before approving, and make the test deterministic. On a pull request's build, `on_main_unreviewed: true` marks a change that's the default branch's own unreviewed change (its newest build, still waiting for review, has it too), and `inherited` counts them: review those on main's build. `matches` marks a change made only of changes a merged pull request approved (two PRs that changed the same screen and merged separately): approve those with `review` and `only: \"matching\"`.", + "description": "A build's status and its snapshots that need attention, 30 at a time (offset and limit page through; longer lists also come grouped by state and name prefix) (changed, added, removed, failed), with how many pages changed in each, the largest change first (order: name to sort by name), and approved_elsewhere when the same new version was already approved in another build, on another branch or earlier on this one (a hint: it approves nothing; on its own branch a CI build carries an earlier approval of the same added content, or of the same change over the same base, by itself). Unchanged snapshots are only counted unless include_unchanged is set. `config` is the visualci.yml the build was sent (null when it had none: the project's settings applied). `flaky: true` marks a change whose content flipped back and forth over the branch's recent builds: often something that differs between runs (the time, an animation, a late font) rather than a real change, so check it before approving, and make the test deterministic. On a pull request's build, `on_main_unreviewed: true` marks a change that's the default branch's own unreviewed change (its newest build, still waiting for review, has it too), and `inherited` counts them: review those on main's build. `matches` marks a change made only of changes a merged pull request approved (two PRs that changed the same screen and merged separately): approve those with `review` and `only: \"matching\"`.", "inputSchema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": false, diff --git a/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-user-token.json b/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-user-token.json index 32d255275..e3dcdbc62 100644 --- a/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-user-token.json +++ b/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-user-token.json @@ -497,7 +497,7 @@ "readOnlyHint": true, "title": "Get build" }, - "description": "A build's status and its snapshots that need attention, 30 at a time (offset and limit page through; longer lists also come grouped by state and name prefix) (changed, added, removed, failed), with how many pages changed in each, the largest change first (order: name to sort by name), and approved_elsewhere when the same new version was already approved on another branch (a hint: it approves nothing). Unchanged snapshots are only counted unless include_unchanged is set. `config` is the visualci.yml the build was sent (null when it had none: the project's settings applied). `flaky: true` marks a change whose content flipped back and forth over the branch's recent builds: often something that differs between runs (the time, an animation, a late font) rather than a real change, so check it before approving, and make the test deterministic. On a pull request's build, `on_main_unreviewed: true` marks a change that's the default branch's own unreviewed change (its newest build, still waiting for review, has it too), and `inherited` counts them: review those on main's build. `matches` marks a change made only of changes a merged pull request approved (two PRs that changed the same screen and merged separately): approve those with `review` and `only: \"matching\"`.", + "description": "A build's status and its snapshots that need attention, 30 at a time (offset and limit page through; longer lists also come grouped by state and name prefix) (changed, added, removed, failed), with how many pages changed in each, the largest change first (order: name to sort by name), and approved_elsewhere when the same new version was already approved in another build, on another branch or earlier on this one (a hint: it approves nothing; on its own branch a CI build carries an earlier approval of the same added content, or of the same change over the same base, by itself). Unchanged snapshots are only counted unless include_unchanged is set. `config` is the visualci.yml the build was sent (null when it had none: the project's settings applied). `flaky: true` marks a change whose content flipped back and forth over the branch's recent builds: often something that differs between runs (the time, an animation, a late font) rather than a real change, so check it before approving, and make the test deterministic. On a pull request's build, `on_main_unreviewed: true` marks a change that's the default branch's own unreviewed change (its newest build, still waiting for review, has it too), and `inherited` counts them: review those on main's build. `matches` marks a change made only of changes a merged pull request approved (two PRs that changed the same screen and merged separately): approve those with `review` and `only: \"matching\"`.", "inputSchema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": false, diff --git a/docs/design.md b/docs/design.md index 202d4e9c5..1626235f2 100644 --- a/docs/design.md +++ b/docs/design.md @@ -262,6 +262,20 @@ the same way as a screenshot: a change keeps the GitHub check pending instead of again, and a later approval on the base branch wins. Installation events keep projects' installations current. This is the only way a pull request's approvals reach its base branch: a build never takes approvals from a branch outside its history. + 4. **Carried approvals** (`domain::carried_approvals`, in the conclusion's transaction): a rebase moves the anchor to + a newer default-branch build, so the branch's earlier approvals stop counting as rows "since" the anchor, and its + added snapshots would wait for the same review again (DocSpring PR #1487). A CI build carries an earlier build's + approval on the same branch, suite and environment when the reviewer saw exactly this: an added snapshot with the + same content (fingerprint), or a changed one whose content and base's content are both the approved change's. + The row has approval `carried`, the original approver and `review_id`; the snapshot reads approved, and a build + whose every change carried concludes approved, and its check says "approved earlier on this branch by …". Only + an approval that still stands carries: it's still the branch's newest approved version of that snapshot (a later + row with other content means the branch moved on, and going back is a regression to review: review of #289), it + wasn't withdrawn (its rows are gone; a carried row needs its original review's row), and nobody rejected that + content on the branch after it was approved (by the reviews' times, so an older pending build rejected later counts). Rejections don't carry; neither does + anything on a snapshot with an open comment thread, or in a build with a failed snapshot. Other branches' + approvals stay a hint (`approved_elsewhere`). A changed page whose image is the branch's newest approved one + already passes in comparison (the exact-match pass below), whatever its base. - **A pull request compares with its base branch.** A pull request into a release branch, a stacked pull request, or a fork whose default branch differs compares with what its base branch approved (the merge-base's approved build when the history reaches it, else the base branch's newest approved build), not the default branch's baseline; the diff --git a/frontend/content/docs/agents.md b/frontend/content/docs/agents.md index 0359bf485..41c835132 100644 --- a/frontend/content/docs/agents.md +++ b/frontend/content/docs/agents.md @@ -44,7 +44,8 @@ claude mcp add --transport http visualci https://mcp.visualci.com/mcp \ - **Intended:** it calls `review` with `approve`. The approved snapshots become the baseline, and the check turns green. No new commit or CI run is needed. - **A bug:** it fixes the code and pushes again. The next build is compared with the same baseline. 5. `snapshot_history` shows one snapshot across recent builds, which helps find when a page started changing. `get_build` marks a change `flaky: true` when its content flipped back and forth over the branch's recent builds: often a test that isn't deterministic rather than a real change (see [Deterministic screenshots](/docs/screenshots/deterministic/)). -6. Before asking for a merge, `get_pr_changeset` (the project and the pull request's number, or a branch) lists everything the pull request adds, changes or removes across all of its builds, against the baseline it forked from, with where review stands for each. A change approved in an earlier build still shows there, so nothing slips through; nothing should be pending or unexpected. The web app shows the same at `///pulls/`. +6. A change approved once isn't reviewed again on its own branch. After a rebase, the branch's build compares with the default branch's newer build, so what the branch approved before can show up again. A CI build carries the branch's earlier approval of an added snapshot with the same content, and of a changed snapshot whose new version and base are both the same as the approved one's (the same diff). It's recorded as carried, with the original reviewer, and when every change carried, the build is approved and the check passes. Only an approval that still stands carries: not one that was withdrawn, or that a build of the branch rejected for the same content, nor one the branch has moved on from (it approved another version of that snapshot since, so going back is a regression to review). A rejection doesn't carry, nor does anything on a snapshot with an open comment thread or in a build with a failed snapshot. The check says "approved earlier on this branch by …". Anything else approved before with the same content, on another branch or over another base, shows as `approved_elsewhere` in `get_build`: a hint, which approves nothing. +7. Before asking for a merge, `get_pr_changeset` (the project and the pull request's number, or a branch) lists everything the pull request adds, changes or removes across all of its builds, against the baseline it forked from, with where review stands for each. A change approved in an earlier build still shows there, so nothing slips through; nothing should be pending or unexpected. The web app shows the same at `///pulls/`. On GitHub, VisualCI keeps one comment on each pull request up to date when something changed: each suite's newest build, its counts and review state, the changed snapshots (each page with its changes boxed, a before and after close-up of its largest change, and links to the full images), and what was removed. A pull request where nothing changed gets only the passing check, unless the project's `comment_when_unchanged` setting is on; a comment that's already there keeps being updated. To show images in a comment of your own, use the `embed_url` links `get_snapshot` gives for each page: they work for a week. diff --git a/frontend/src/api/types.ts b/frontend/src/api/types.ts index 4df50c4d6..f4a5cc0f0 100644 --- a/frontend/src/api/types.ts +++ b/frontend/src/api/types.ts @@ -432,7 +432,7 @@ export type SnapshotRow = { /** How big the change is: the largest share of a page (or of the lines) that changed, and how many pixels (or * lines). The build lists the biggest first. */ change: { fraction: number; amount: number } | null - /** The same new version was already approved on another branch. A hint: it approves nothing here. */ + /** The same new version was already approved in another build, on another branch or earlier on this one. A hint. */ approved_elsewhere: ApprovedElsewhere | null /** Every changed region is exactly a change a merged pull request approved: "matches PR #8's approved change". */ matches?: { build: number; branch: string; pr_number: number | null; label: string } | null diff --git a/frontend/src/styles.css b/frontend/src/styles.css index 8a75305f8..ebcdc02ea 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -2273,7 +2273,7 @@ a.stat-cell:hover { font-size: var(--text-sm); } -/* A changed snapshot whose new version was already approved on another branch. */ +/* A changed snapshot whose new version was already approved in another build. */ .snap-elsewhere { color: var(--color-added); } diff --git a/plugin/skills/visualci-review/SKILL.md b/plugin/skills/visualci-review/SKILL.md index 09b0cf643..7379c1fb4 100644 --- a/plugin/skills/visualci-review/SKILL.md +++ b/plugin/skills/visualci-review/SKILL.md @@ -49,7 +49,8 @@ claude mcp add --transport http visualci https://mcp.visualci.com/mcp \ - **Intended:** it calls `review` with `approve`. The approved snapshots become the baseline, and the check turns green. No new commit or CI run is needed. - **A bug:** it fixes the code and pushes again. The next build is compared with the same baseline. 5. `snapshot_history` shows one snapshot across recent builds, which helps find when a page started changing. `get_build` marks a change `flaky: true` when its content flipped back and forth over the branch's recent builds: often a test that isn't deterministic rather than a real change (see [Deterministic screenshots](https://visualci.com/docs/screenshots/deterministic.md)). -6. Before asking for a merge, `get_pr_changeset` (the project and the pull request's number, or a branch) lists everything the pull request adds, changes or removes across all of its builds, against the baseline it forked from, with where review stands for each. A change approved in an earlier build still shows there, so nothing slips through; nothing should be pending or unexpected. The web app shows the same at `///pulls/`. +6. A change approved once isn't reviewed again on its own branch. After a rebase, the branch's build compares with the default branch's newer build, so what the branch approved before can show up again. A CI build carries the branch's earlier approval of an added snapshot with the same content, and of a changed snapshot whose new version and base are both the same as the approved one's (the same diff). It's recorded as carried, with the original reviewer, and when every change carried, the build is approved and the check passes. Only an approval that still stands carries: not one that was withdrawn, or that a build of the branch rejected for the same content, nor one the branch has moved on from (it approved another version of that snapshot since, so going back is a regression to review). A rejection doesn't carry, nor does anything on a snapshot with an open comment thread or in a build with a failed snapshot. The check says "approved earlier on this branch by …". Anything else approved before with the same content, on another branch or over another base, shows as `approved_elsewhere` in `get_build`: a hint, which approves nothing. +7. Before asking for a merge, `get_pr_changeset` (the project and the pull request's number, or a branch) lists everything the pull request adds, changes or removes across all of its builds, against the baseline it forked from, with where review stands for each. A change approved in an earlier build still shows there, so nothing slips through; nothing should be pending or unexpected. The web app shows the same at `///pulls/`. On GitHub, VisualCI keeps one comment on each pull request up to date when something changed: each suite's newest build, its counts and review state, the changed snapshots (each page with its changes boxed, a before and after close-up of its largest change, and links to the full images), and what was removed. A pull request where nothing changed gets only the passing check, unless the project's `comment_when_unchanged` setting is on; a comment that's already there keeps being updated. To show images in a comment of your own, use the `embed_url` links `get_snapshot` gives for each page: they work for a week. From d3f8fd80202ce0acda983462ef6e4866b5584495 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 11:57:20 +0000 Subject: [PATCH 2/4] Carried approvals after #280 and #290: kept rejections and carried approvals both decide the review; the changelog line is an entry file; no plugin version --- .../changelog/2026-12-06-0055-added-approved-elsewhere.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 frontend/content/changelog/2026-12-06-0055-added-approved-elsewhere.md diff --git a/frontend/content/changelog/2026-12-06-0055-added-approved-elsewhere.md b/frontend/content/changelog/2026-12-06-0055-added-approved-elsewhere.md new file mode 100644 index 000000000..c4faced91 --- /dev/null +++ b/frontend/content/changelog/2026-12-06-0055-added-approved-elsewhere.md @@ -0,0 +1 @@ +A rebased branch isn't asked to review the same change twice: its CI build carries the branch's earlier approval of an added snapshot with the same content, and of a changed snapshot with the same new version over the same base, and is approved when every change carried. A rejection doesn't carry, nor does an approval that was withdrawn, later rejected, or that the branch has since moved away from, and an open comment thread holds a snapshot back. `approved_elsewhere` now also finds approvals earlier on the build's own branch. [Coding agents](/docs/agents/#the-review-loop) From 50eb373e3c0c0f687c880644bbbd0fc87ad49e8e Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 12:03:10 +0000 Subject: [PATCH 3/4] Carried approvals: conclude's comment names them --- app/src/domain/processing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/domain/processing.rs b/app/src/domain/processing.rs index 5d30a284a..2543ce093 100644 --- a/app/src/domain/processing.rs +++ b/app/src/domain/processing.rs @@ -1295,7 +1295,7 @@ async fn conclude( // 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 (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. + // (`reruns::keep_rejections`): carried approvals are the only other review a build being concluded has. let rejected = all.iter().any(|s| is_change(s) && s.review.as_deref() == Some("rejected")); // Every change already approved: a merged pull request's version it approved (`approve_merged`), or an earlier // approval on the branch carried (`carried_approvals`). Approved as it stands. From c6f10588ea11fc4eec79079fcdd7ca525ac19799 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 12:07:51 +0000 Subject: [PATCH 4/4] Carried approvals after #279: one 'approved' rule for merged and carried approvals; the test helpers keep main's jest and missing-file builds beside start/finish --- app/tests/baselines.rs | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/app/tests/baselines.rs b/app/tests/baselines.rs index 21925f006..4ab05ca0b 100644 --- a/app/tests/baselines.rs +++ b/app/tests/baselines.rs @@ -310,6 +310,56 @@ impl World { created.json()["id"].as_str().unwrap().to_string() } + /// A jest suite's build as DocSpring's CI sends it: text snapshots split out of Jest `.snap` files + /// (`visualci upload --from jest`), into a subset build named "jest". For a pull request into `base`. + async fn jest( + &self, + app: &Application, + commit: &str, + branch: &str, + base: Option<&str>, + parents: &[&str], + files: &[(&str, &str)], + ) -> Build { + let auth = format!("Bearer {}", self.token); + let mut body = + json!({ "commit": commit, "branch": branch, "parent_commits": parents, "subset": true, "name": "jest" }); + if let Some(base) = base { + body["base_branch"] = json!(base); + body["pr_number"] = json!(7); + } + let created = app.post("/api/v1/builds").header("authorization", &auth).json(body).await; + created.assert_ok(); + let id = created.json()["id"].as_str().unwrap().to_string(); + let mut list = Vec::new(); + let mut bodies = Vec::new(); + for (name, text) in files { + // The test's own bytes, as with images ([`png`]). + let bytes = format!("{text}\n// {}\n", self.nonce).into_bytes(); + let sha = visualci_core::sha256_hex(&bytes); + list.push(json!({ + "name": name, "platform": "", "kind": "text", "sha256": sha, "fingerprint": sha, "size": bytes.len(), + "content_type": "text/plain", + })); + bodies.push(bytes); + } + let registered = app + .post(format!("/api/v1/builds/{id}/snapshots")) + .header("authorization", &auth) + .json(json!({ "snapshots": list })) + .await; + registered.assert_ok(); + for (s, bytes) in registered.json()["snapshots"].as_array().unwrap().iter().zip(bodies) { + if let Some(url) = s["upload_url"].as_str() { + upload(url, bytes).await; + } + } + let done = app.post(format!("/api/v1/builds/{id}/finalize")).header("authorization", &auth).await; + assert_eq!(done.json()["state"], "completed", "{}", done.text()); + let pid: laravel::str::Uuid = id.parse().unwrap(); + Build::query().filter(Build::pid.eq(pid)).first().await.unwrap().unwrap() + } + /// Register these images with a receiving build and upload them, all but the `missing` ones. async fn upload_all(&self, app: &Application, id: &str, files: &[(&str, [u8; 3])], missing: &[&str]) { if files.is_empty() {