From 46224721523ce0e65f5f122e7aeda6860c12a304 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 2 Dec 2026 19:09:11 +1300 Subject: [PATCH] A merge's approvals don't leak into older builds of its base branch (sc-8806): baselines::resolve counted a merged pull request's approvals (record_merge, on the base branch at the merge commit) for any newer-than-anchor build on that branch, whatever its commit, so a main build of a commit from before the merge, built late, showed the merge's new snapshots as removed, and pull request builds on top of it inherited the removal (main #122 and PR 27's #123 with PR 25's slider screenshots). Merged approvals now count only through their merge commit's place in the build's history; a branch's own reviews count as before. Request test with exactly that shape --- server/src/models/baselines.rs | 7 ++++-- server/tests/requests/comments.rs | 39 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/server/src/models/baselines.rs b/server/src/models/baselines.rs index 5f8936a1..3b7d735b 100644 --- a/server/src/models/baselines.rs +++ b/server/src/models/baselines.rs @@ -236,14 +236,17 @@ pub async fn resolve( }; let after = anchor.as_ref().map_or(0, |a| a.id); - // Approvals newer than the anchor: CI ones on the ancestry, and any on this branch. For local environments also + // Approvals newer than the anchor: CI ones on the ancestry, and any on this branch. A merged pull request's + // approvals (`record_merge`) count only through their merge commit's place in this build's history: on the base + // branch they'd otherwise reach builds of commits from before the merge, which then show the merge's new snapshots + // as removed (sc-8806: main's #122, built late, showed PR 25's slider screenshots removed). For local environments also // older ones, since the anchor (a CI build) doesn't carry their screenshots. Local approvals apply only to their // own branch; on the default branch only CI approvals count for other branches. let rows = Entity::find() .from_raw_sql(Statement::from_sql_and_values( DbBackend::Postgres, "SELECT * FROM baselines WHERE project_id = $1 AND build_name = $2 AND build_id <> $3 AND ( \ - (build_id > $4 AND ((mode = 'ci' AND commit_sha = ANY($5)) OR branch = $6)) \ + (build_id > $4 AND approval <> 'merged' AND ((mode = 'ci' AND commit_sha = ANY($5)) OR branch = $6)) \ OR (approval = 'merged' AND commit_sha = ANY($5)) \ OR (environment NOT IN ('', 'ci') AND (branch = $6 OR (branch = $7 AND mode = 'ci'))) \ ) ORDER BY id", diff --git a/server/tests/requests/comments.rs b/server/tests/requests/comments.rs index bdb96974..e17f633f 100644 --- a/server/tests/requests/comments.rs +++ b/server/tests/requests/comments.rs @@ -579,6 +579,45 @@ async fn a_pr_build_says_which_changes_are_mains_unreviewed_ones() { .await; } +/// A merged pull request's approvals count only for builds whose history has the merge. A main build of an older +/// commit, built after the merge (main's CI runs late), and a pull request built on top of it, don't show the merge's +/// new snapshot as removed; the merge commit's own build finds it approved (sc-8806: main's #122 and PR 27's #123 +/// showed PR 25's slider screenshots removed). +#[tokio::test] +#[serial] +async fn a_merge_does_not_leak_into_older_builds_of_its_base_branch() { + request::(|_request, ctx| async move { + let Some(w) = world(&ctx).await else { return }; + let a = w.build("A", "main", None, &[], &[("x", png(RED))]).await; + a.review(w.db, None, &builds::Via::default(), "approve", None, None).await.unwrap(); + // PR 1 adds y; it's approved and merged at M1. + let p1 = w.build("P1", "one", Some(1), &["A"], &[("x", png(RED)), ("y", png(BLUE))]).await; + p1.review(w.db, None, &builds::Via::default(), "approve", None, None).await.unwrap(); + visualci_server::models::baselines::record_merge(w.db, w.project.id, "one", "main", "M1").await.unwrap(); + + let states = |b: builds::Model| async move { + snapshots::Model::for_build(w.db, b.id) + .await + .unwrap() + .into_iter() + .map(|s| (s.name, s.state)) + .collect::>() + }; + // Main's build of an older commit, B (before the merge), processed after it. + let b = w.build("B", "main", None, &["A"], &[("x", png(RED))]).await; + assert_eq!(states(b).await, vec![("x".to_string(), "unchanged".to_string())], "y isn't B's to remove"); + // A pull request on top of B. + let q = w.build("Q", "two", Some(2), &["B", "A"], &[("x", png(RED))]).await; + assert_eq!(states(q).await, vec![("x".to_string(), "unchanged".to_string())]); + // The merge commit's own build: y as PR 1 approved it. + let m = w.build("M1", "main", None, &["B", "A"], &[("x", png(RED)), ("y", png(BLUE))]).await; + let mut got = states(m).await; + got.sort(); + assert_eq!(got, vec![("x".to_string(), "unchanged".to_string()), ("y".to_string(), "unchanged".to_string())]); + }) + .await; +} + fn png_color(v: u8) -> [u8; 3] { [v, v, v] }